OpenClovis Logo

API Usage Examples
Execution Object (EO) Service

Code Examples. More...

Code Examples.

The code for EO is generated by the IDE (refer IDE User Guide). The users might want to be cautious when using the CL_EO_USE_THREAD_FOR_APP. The application take control of the main thread and has to hold the thread through it's lifetime. If the thread is released prematurely the behavior is undefined. The only way the application can be shutdown is through the invocation of clCpmComponentTerminate() which in turn invokes the callback clCompAppTerminate(). The logic to unblock the main thread should reside in this callback just before clCpmResponse().

The appropriate callbacks are as shown below:

ClBoolT unblockMainThread = CL_FALSE;
clCompAppInitialize(
ClUint32T argc,
ClCharT *argv[])
{
ClNameT appName;
ClCpmCallbacksT callbacks;
ClVersionT version;
ClIocPortT iocPort;
ClRcT rc = CL_OK;
/*
* Get the pid for the process and store it in global variable.
*/
mypid = getpid();
/*
* Initialize and register with CPM. 'version' specifies the
* version of AMF with which this application would like to
* interface. 'callbacks' is used to register the callbacks
* this component expects to receive.
*/
version.releaseCode = 'B';
version.majorVersion = 01;
version.minorVersion = 01;
callbacks.appHealthCheck = NULL;
callbacks.appTerminate = clCompAppTerminate;
callbacks.appCSISet = clCompAppAMFCSISet;
callbacks.appCSIRmv = clCompAppAMFCSIRemove;
callbacks.appProtectionGroupTrack = NULL;
/*
* Get IOC Address, Port and Name. Register with AMF.
*/
clEoMyEoIocPortGet(&iocPort);
if ( (rc = clCpmClientInitialize(&cpmHandle, &callbacks, &version)) )
goto errorexit;
/*
* If this component will provide a service, register it now.
*/
#if HAS_EO_SERVICES
rc = clSAFComponent1EO0ClientInstall();
#endif
/*
* Do the application specific initialization here.
*/
/*
* ---BEGIN_APPLICATION_CODE---
*/
// ...
/*
* ---END_APPLICATION_CODE---
*/
/*
* Now register the component with AMF. At this point it is
* ready to provide service, i.e. take work assignments.
*/
if ( (rc = clCpmComponentNameGet(cpmHandle, &appName)) )
goto errorexit;
if ( (rc = clCpmComponentRegister(cpmHandle, &appName, NULL)) )
goto errorexit;
/*
* Print out standard information for this component.
*/
clprintf ("Component [%s] : PID [%d]. Initializing\n",
appName.value, mypid);
clprintf (" IOC Address : 0x%x\n", clIocLocalAddressGet());
clprintf (" IOC Port : 0x%x\n", iocPort);
/*
* This is where the application code starts. If the main thread
* usage policy is CL_EO_USE_THREAD_FOR_APP, then return from this
* fn only after the application terminates. If the main thread
* usage policy is CL_EO_USE_THREAD_FOR_RECV, then return from
* this fn after doing the application specific initialization
* and registration.
*/
/*
* ---BEGIN_APPLICATION_CODE---
*/
ClTimerTimeOutT timeOut = { 1, 0 };
// Do some processing
while (unblockMainThread == CL_FALSE)
{
clOsalTaskDelay(timeOut);
}
// Release the main thread...
/*
* ---END_APPLICATION_CODE---
*/
return rc;
errorexit:
clprintf ("Component [%s] : PID [%d]. Initialization error [0x%x]\n",
appName.value, mypid, rc);
return rc;
}
clCompAppTerminate(
ClInvocationT invocation,
const ClNameT *compName)
{
ClRcT rc = CL_OK;
clprintf ("Component [%s] : PID [%d]. Terminating\n",
compName->value, mypid);
/*
* ---BEGIN_APPLICATION_CODE---
*/
// ...
/*
* ---END_APPLICATION_CODE---
*/
/*
* Unregister with AMF and send back a response
*/
if ( (rc = clCpmComponentUnregister(cpmHandle, compName, NULL)) )
goto errorexit;
if ( (rc = clCpmClientFinalize(cpmHandle)) )
goto errorexit;
unblockMainThread = CL_TRUE;
clCpmResponse(cpmHandle, invocation, CL_OK);
clprintf ("Component [%s] : PID [%d]. Terminated\n",
compName->value, mypid);
return rc;
errorexit:
clprintf ("Component [%s] : PID [%d]. Termination error [0x%x]\n",
compName->value, mypid, rc);
return rc;
}

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