OpenClovis Logo

API Usage Examples

Code Examples.

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
}
ClUint32T ClRcT
Clovis return code type.
Definition: clCommon.h:168
#define CL_OK
Every thing is OK.
Definition: clCommonErrors.h:68
#define CL_HANDLE_INVALID_VALUE
Defines.
Definition: clHandleApi.h:95
ClPtrT clHeapCalloc(CL_IN ClUint32T numChunks, CL_IN ClUint32T chunkSize)
Allocates memory for an array and initializes it to zero.
ClPtrT ClTimerHandleT
The type of the handle identifying the timer.
Definition: clTimerApi.h:82
ClRcT clTimerCreateAndStart(ClTimerTimeOutT timeOut, ClTimerTypeT type, ClTimerContextT timerTaskSpawn, ClTimerCallBackT fpAction, void *pActionArgument, ClTimerHandleT *pTimerHandle)
Creates a new timer and activates it.
ClRcT clTimerDelete(ClTimerHandleT *pTimerHandle)
Deletes a timer.
ClTimerTypeT
type of action on timer expiry.
Definition: clTimerApi.h:117
ClRcT clTimerCreate(ClTimerTimeOutT timeOut, ClTimerTypeT type, ClTimerContextT timerTaskSpawn, ClTimerCallBackT fpAction, void *pActionArgument, ClTimerHandleT *pTimerHandle)
Creates a timer.
ClTimerContextT
When the timer expires, decides the method of invocation of the timer callback function.
Definition: clTimerApi.h:137
ClRcT clTimerStart(ClTimerHandleT timerHandle)
Starts a timer.
ClRcT clTimerUpdate(ClTimerHandleT timerHandle, ClTimerTimeOutT newTimeout)
Updates a timer.
ClRcT clTimerStop(ClTimerHandleT timerHandle)
\breif Stops a timer.
@ CL_TIMER_ONE_SHOT
Fire just once.
Definition: clTimerApi.h:119
@ CL_TIMER_REPETITIVE
Fire periodically.
Definition: clTimerApi.h:121
@ CL_TIMER_SEPARATE_CONTEXT
A new thread will be created to invoke the callback.
Definition: clTimerApi.h:141
The timeout value in seconds and milliseconds.
Definition: clTimerApi.h:87
ClUint32T tsSec
Number of seconds of the timeout.
Definition: clTimerApi.h:89

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