The CK_Event class represents an event that can be set to expire after an amount of time has elapsed. When the event expires, it makes a callback to a CK_EventCallback object. The CK_Event can be either queued, or not queued. This implies that only one event can be queued per CK_Event object. When the event expires, it can be queued again. If the CK_Event is queued, it is possible to cancel it before the event expires.
The following code demonstrates how to create a CK_Event and queue it:
class MyEventCallback : public CK_EventCallback { public: // The pointer to the CK_Event is passed so the application can requeue the event // or delete it. void eventCallback(CK_Event *event, int param) { printf("The event has expired, param = %d\n",param); // Requeue the event to expire in 2 more seconds. event->queue(); } }; ... static MyEventCallback myCB; // Creates the event object and queues it to expire in 2 seconds. // The parameter passed to eventCallback() is 99. CK_Event *event = new CK_Event(2000, myCB, 99); event->queue();
The default constructor creates an event that is not queued. The callback object, the callback parameter, and the event timeout must be set before queueing.
Creates an unqueued CK_Event. The callback, the callback's parameter, and expiration time are preset so that when the event is queued, this information is not needed again.
Parameters
- millisec
- The number of milliseconds that must elapse before the event expires and the callback is called.
- cb
- The object that is called when the event expires.
- param
- The parameter passed to the callback object.
Cancels the event if it was queued. There is no harm done if the event was not queued and cancel() is called.
Returns TRUE if the event is queued.
Queues the event to expire after the set amount of time. The amount of time is set by calling setTimeout() before queueing, or is set in the constructor. The event can be requeued as many times as desired without needing to re-set the timeout value. If the event was already queued, it will first be canceled, and then queued again.
Sets the object that will be called back when the event expires. The object's eventCallback() member function is called. Typically, an application class will derive from CK_EventCallback and override the eventCallback() function to handle the event.
Parameters
- cb
- The object that is called when the event expires.
Sets the value of the parameter that is passed to the callback object's eventCallback() member function.
Parameters
- param
- The value of the parameter to pass to the callback function when the event expires.
Sets the time to expiration for the event.
Parameters
- ms
- The number of milliseconds until the event expires.