[tasklet] adding TaskletContext class (#3364)

This commit adds a new class `TaskletContext` which is a `Taskelt`
that also maintains a user context pointer.
This commit is contained in:
Abtin Keshavarzian
2018-12-14 12:20:59 -08:00
committed by Jonathan Hui
parent 1171a32a8c
commit 8d4b424418
+39 -1
View File
@@ -76,7 +76,7 @@ public:
/**
* This constructor creates a tasklet instance.
*
* @param[in] aInstance A reference to the instance object.
* @param[in] aInstance A reference to the OpenThread instance object.
* @param[in] aHandler A pointer to a function that is called when the tasklet is run.
* @param[in] aOwner A pointer to owner of this `Tasklet` object.
*
@@ -96,6 +96,44 @@ private:
Tasklet *mNext;
};
/**
* This class defines a tasklet that also maintains a user context pointer.
*
* In typical `Tasklet` use, in the handler callback, the owner of the tasklet is determined using `GetOwner<Type>`
* method. This method works if there is a single instance of `Type` within OpenThread instance hierarchy. The
* `TaskletContext` is intended for cases where there may be multiple instances of the same class/type using a `Tasklet`
* object. `TaskletContext` will store a context `void *` information.
*
*/
class TaskletContext : public Tasklet
{
public:
/**
* This constructor creates a tasklet instance.
*
* @param[in] aInstance A reference to the OpenThread instance.
* @param[in] aHandler A pointer to a function that is called when the tasklet is run.
* @param[in] aContext A pointer to an arbitrary context information.
*
*/
TaskletContext(Instance &aInstance, Handler aHandler, void *aContext)
: Tasklet(aInstance, aHandler, aContext)
, mContext(aContext)
{
}
/**
* This method returns the pointer to the arbitrary context information.
*
* @returns Pointer to the arbitrary context information.
*
*/
void *GetContext(void) { return mContext; }
private:
void *mContext;
};
/**
* This class implements the tasklet scheduler.
*