OpenClovis Logo

API Usage Examples
Timer

Code Examples. More...

Code Examples.

//Initialize the timer library
//Timer library will be initialized by EO infrastructure,
//if the basic eo libs for timer is turned on.
rc = clTimerLibInitialize();
//Create a one shot timer which expires after 2 seconds.
//timer callback will be invoked from new thread.
ClTimerTimeOutT timeout = {.tsSec = 2, .tsMilliSec = 0};
ClTimeXXXT *pCookie = NULL;
pCookie = clHeapCalloc(sizeof(ClTimeXXXT), sizeof(ClCharT));
if( NULL == pCookie )
{
//no memory error should be returned and cleanup should be done.
}
*pCookie = YYYY;
rc = clTimerCreateAndStart(&timeout, timerType, timerContext,
clTstTimerCallback, &timerCookie,
&timerHandle);
// timer callback which will be invoked from timer library
ClRcT clTstTimerCallback(void *pCookie)
{
/*
Once the timer expired based on the context, this particular callback
will be invoked
*/
return CL_OK;
}
// Just creating repetitive timer for 2 seconds
ClTimerTimeOutT timeout = {.tsSec = 2, .tsMilliSec = 0};
ClTimeXXXT *pCookie = NULL;
pCookie = clHeapCalloc(sizeof(ClTimeXXXT), sizeof(ClCharT));
if( NULL == pCookie )
{
//no memory error should be returned and cleanup should be done.
}
*pCookie = YYYY;
rc = clTimerCreate(&timeout, timerType, timerContext,
clTstTimerCallback, &timerCookie,
&timerHandle);
if( CL_OK != rc )
{
//Error occured, proper action should be taken
}
// The above step has just created the timer, so need to start timer.
// Once the timer expires the callback will be invoked repetitively with span
// of 3 seconds.
rc = clTimerStart(&timerHandle);
if( CL_OK != rc )
{
// Error occcured, proper cleanup and action should be taken
}
//Updating the timer, while it is running.
ClTimerTypeT newTimeout = {.tsSec = 3, .tsMilliSec = 0};
rc = clTimerUpdate(timerHandle, &newTimeout);
if( CL_OK != rc )
{
//Error occured, please take apporiate action
}
//Stopping the timer
rc = clTimerStop(timerHandle);
if( CL_OK != rc )
{
//Error occured, please take appropriate action
}
//Deleting the timer
rc = clTimerDelete(timerHandle);
if( CL_OK != rc )
{
//Error occured, please take appropriate action
}
//Finalized again it will be done by EO infrastructure,if you have not explicitly
//initialized.
rc = clTimerLibFinalize();
if( CL_OK != rc )
{
//Error occured, please take appropriate again
}

Generated on Tue Jan 10 10:29:15 PST 2012 for OpenClovis SDK using Doxygen