OpenClovis Logo

Code Examples.

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;
}
#define CL_FALSE
define the False
Definition: clCommon.h:61
#define CL_TRUE
define the Truth
Definition: clCommon.h:59
ClUint32T ClRcT
Clovis return code type.
Definition: clCommon.h:168
#define CL_OK
Every thing is OK.
Definition: clCommonErrors.h:68
ClRcT clCpmComponentNameGet(CL_IN ClCpmHandleT cpmHandle, CL_OUT ClNameT *pCompName)
Returns the component name.
ClRcT clCpmClientInitialize(CL_OUT ClCpmHandleT *pCpmHandle, CL_IN const ClCpmCallbacksT *pCallback, CL_INOUT ClVersionT *pVersion)
Initializes the client Component Manager library.
ClRcT clCpmClientFinalize(CL_IN ClCpmHandleT cpmHandle)
Cleans up the client Component Manager library.
ClRcT clCpmResponse(CL_IN ClCpmHandleT cpmHandle, CL_IN ClInvocationT invocation, CL_IN ClRcT rc)
Respond to AMF with the result of components execution of a particular request by AMF.
ClRcT clCpmComponentRegister(CL_IN ClCpmHandleT cpmHandle, CL_IN const ClNameT *pCompName, CL_IN const ClNameT *pProxyCompName)
Registers a component with CPM.
ClRcT clCpmComponentUnregister(CL_IN ClCpmHandleT cpmHandle, CL_IN const ClNameT *pCompName, CL_IN const ClNameT *pProxyCompName)
Un-registers a component.
ClRcT clEoMyEoIocPortGet(CL_OUT ClIocPortT *pIocPort)
Returns EO IocPort from task specific area.
ClIocNodeAddressT clIocLocalAddressGet(void)
Returns the local IOC node addrress.
ClUint32T ClIocPortT
The IOC communication port.
Definition: clIocApi.h:348
ClRcT clOsalTaskDelay(ClTimerTimeOutT timeOut)
Delays a task.
A name.
Definition: clCommon.h:197
ClCharT value[CL_MAX_NAME_LENGTH]
Actual name represented as a null terminated ASCII string.
Definition: clCommon.h:201
Version Information for various services.
Definition: clCommon.h:250
ClUint8T minorVersion
Minor Number in range of [01-255].
Definition: clCommon.h:256
ClUint8T releaseCode
single ASCII capitol letter "A-Z"
Definition: clCommon.h:252
ClUint8T majorVersion
Major Number in range of [01-255].
Definition: clCommon.h:254
The structure ClCpmCallbacksT contains the various callback functions that the Component Manager can ...
Definition: clCpmApi.h:474
ClCpmProtectionGroupTrackCallbackT appProtectionGroupTrack
Callback invoked when the component registers for tracking changes in protection group and protection...
Definition: clCpmApi.h:498
ClCpmTerminateCallbackT appTerminate
Callback for gracefully shutting down the component.
Definition: clCpmApi.h:482
ClCpmCSISetCallbackT appCSISet
Callback for assigning the component service instance to the component.
Definition: clCpmApi.h:487
ClCpmHealthCheckCallbackT appHealthCheck
Callback for checking the health of the component.
Definition: clCpmApi.h:478
ClCpmCSIRmvCallbackT appCSIRmv
Callback for removing the component service instance assigned to the component.
Definition: clCpmApi.h:492
The timeout value in seconds and milliseconds.
Definition: clTimerApi.h:87

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