24 / 30
iSense Ethernet Gateway User Guide
coalesenses
research to innovate
Once a class inherits the
isense::Task
interface and implements the corresponding method, it is a
task and can be registered at the operating system for later callback.
For tasks, the OS provides three methods for registering tasks to be executed as soon as possible, at a
certain time, or after a certain interval from now on.
//-----------------------------------------------------------------------
/** This method enqueues the given task into the queue of tasks
* Its execute method is called during the main control flow
*
* \param task object implementing the Task interface, whose execute
* method is called
* \param userdata an arbitrary pointer that is passed back again
* to the callback
*
* \return true if task was enqueued successfully, false otherwise (e.g.
* if the task queue is full)
*
*/
bool add_task(Task *task,
void
* userdata);
//-----------------------------------------------------------------------
/** This method enqueues the given task in the queue of lower priority
* tasks. Its execute method is called during the main control flow
*
* \param interval Point in time when the callback will be called
* \param task object implementing the Task interface, whose execute
* method is called
* \param userdata an arbitrary pointer that is passed back again
* to the callback
*
* \return true if task was enqueued successfully, false otherwise (e.g.
* if the task queue is full)
*/
bool add_task_at(Time time, Task *task,
void
* userdata);
//---------------------------------------------------------------------
/** This method enqueues the given task in the queue of lower priority
* tasks. Its execute method is called during the main control flow
*
* \param interval Time period after which the callback will be called
* \param task object implementing the Task interface, whose execute
* method is called
* \param userdata an arbitrary pointer that is passed back again
* to the callback
*
* \return true if task was enqueued successfully, false otherwise (e.g.
* if the task queue is full)
*/
bool add_task_in(Time interval, Task *task,
void
* userdata);
All methods for registering tasks at the OS feature a so called
userdata
parameter. It can be used to
attach additional information to a task, that is then passed to the
execute
method when it is called. If
you don’t use the feature, simply pass
NULL
.
The
execute
method of the NET10DemoApplication looks as follows: