Cotask and CotaskConstructor

Cotask and CotaskConstructor

These are the software objects that allow a user to work with a specific task of an ADN device. A Task, a Cotask, and a CotaskConstructor are closely interconnected and used together.

Cotask

A Cotask allows a user to receive information in a form that is understandable to them, meaning it converts Task's native data. A cotask provides an interface for working with a specific task, hiding the transfer and processing of data packets.

Each cotask interacts with only one corresponding task. In a way, it is a responsive part of this task. At the same time, a task can have several cotasks, depending on the way a user needs to transform source data. For example, an Alt's tracking task has two cotasks: ITrackingCotask and ITrackingDataCotask.

It is commonly agreed that when a cotask is returned it is ready to operate, therefore creating a cotask should occur together with the launch of a corresponding task. Meaning you need an object that creates a cotask and launches a bound task.

CotaskConstructor

A CotaskConstructor is a software object that creates a cotask and starts the corresponding task on the ADN Node. In addition, it can check the node for support of a required task and search for such nodes in a device tree using isSupported and findSupportedNodes methods.

A CotaskConstructor returns an instance of a cotask. To start a task, a CotaskConstructor usually only needs an instance of INetwork and the required NodeHandle, but some CotaskConstructors may require additional arguments. The low-level packet transfer from a device, the processing of source data, the work logic and the task identifier (GUID) are hidden inside the cotask and the CotaskConstructor. There usually is at least one cotask per task, and one CotaskConstructor per cotask. This allows you to make a more common API and a user-friendly interface for working with tasks.

Typical use case

To start a specific task on one or more devices (for example, tracking on all connected Alts), you need to:

Finishing work with a cotask

A cotask can be finished in two cases — when it’s user-initiated or if the task is completed on the device (including when the device is physically disconnected). A cotask instance is destroyed in accordance with the partial destroy principle.
In cases where finishing a cotask is user-initiated, you need to release the interface reference.