ClRcT clPubsAppInitialize(ClUint32T argc, ClCharT *argv[])
{

    ClRcT rc = CL_OK;
    ClEoExecutionObjT* pEvtPubsEoObj;

    rc = clEoMyEoObjectGet(&pEvtPubsEoObj);
    if( rc != CL_OK )
    {
        clOsalPrintf("EO Object Get failed [%#X]\n",rc);
    }
                                                                                
    rc = clEoClientInstall(pEvtPubsEoObj, CL_EO_NATIVE_COMPONENT_TABLE_ID,gClEvtPubsTestFuncList, 0,
                                          (int)(sizeof(gClEvtPubsTestFuncList)/sizeof (ClEoPayloadWithReplyCallbackT)));
    if( rc != CL_OK )
    {
        clOsalPrintf("Installing Native table failed [%#X]\n",rc);
    }
    
    clEvtPubsCpmInit(); 

    clPubsEventLibrayInitialize();
    
    return CL_OK;
}
void clEvtContTestDbInit()
{
    ClRcT rc = CL_OK;
    ClUint32T noOfApp;

    rc = clCntLlistCreate(clEvtContSubKeyCompare, clEvtContSubDataDelete,
                          clEvtContSubDataDelete, CL_CNT_NON_UNIQUE_KEY,
                          &gEvtContSubInfo);
    if (CL_OK != rc)
    {
        clOsalPrintf("Creating linked list failed for sub \r\n");
        exit(-1);
    }

    rc = clCntLlistCreate(clEvtContPubKeyCompare, clEvtContPubDataDelete,
                          clEvtContPubDataDelete, CL_CNT_UNIQUE_KEY,
                          &gEvtContPubInfo);
    if (CL_OK != rc)
    {
        clOsalPrintf("Creating linked list failed for pub \r\n");
        exit(-1);
    }

    clEvtContGetApp(&noOfApp);
    clHeapAllocate(noOfApp * sizeof(ClEvtContSubInfoStorageT));

    return;
}
ClRcT clCpmEventPayLoadExtract(ClEventHandleT eventHandle,
                               ClSizeT eventDataSize,
                               ClCpmEventTypeT cpmEventType,
                               void *payLoad)
{
    ClRcT rc = CL_OK;
    ClBufferHandleT payLoadMsg = 0;
    void *eventData = NULL;

    eventData = clHeapAllocate(eventDataSize);
    if (eventData == NULL)
    {
        clLogWrite(CL_LOG_HANDLE_APP, CL_LOG_SEV_DEBUG, CL_CPM_CLIENT_LIB,
                   CL_LOG_MESSAGE_0_MEMORY_ALLOCATION_FAILED);
        CPM_CLIENT_CHECK(CL_LOG_SEV_ERROR, ("Unable to malloc \n"),
                         CL_CPM_RC(CL_ERR_NO_MEMORY));
    }
    rc = clEventDataGet (eventHandle, eventData,  &eventDataSize);
    if (rc != CL_OK)
    {
        clOsalPrintf("Event Data Get failed. rc=[0x%x]\n", rc);
        goto failure;
    }

    rc = clBufferCreate(&payLoadMsg);
    CL_CPM_CHECK_1(CL_LOG_SEV_ERROR, CL_CPM_LOG_1_BUF_CREATE_ERR, rc, rc,
                   CL_LOG_HANDLE_APP);
    rc = clBufferNBytesWrite(payLoadMsg, (ClUint8T *)eventData,
                             eventDataSize);
    CL_CPM_CHECK_1(CL_LOG_SEV_ERROR, CL_CPM_LOG_1_BUF_WRITE_ERR, rc, rc,
                   CL_LOG_HANDLE_APP);

    switch(cpmEventType)
    {
    case CL_CPM_COMP_EVENT:
        rc = VDECL_VER(clXdrUnmarshallClCpmEventPayLoadT, 4, 0, 0)(payLoadMsg, payLoad);
        CL_CPM_CHECK_0(CL_LOG_SEV_ERROR, CL_LOG_MESSAGE_0_INVALID_BUFFER, rc,
                       CL_LOG_HANDLE_APP);
        break;
    case CL_CPM_NODE_EVENT:
        rc = VDECL_VER(clXdrUnmarshallClCpmEventNodePayLoadT, 4, 0, 0)(payLoadMsg, payLoad);
        CL_CPM_CHECK_0(CL_LOG_SEV_ERROR, CL_LOG_MESSAGE_0_INVALID_BUFFER, rc,
                       CL_LOG_HANDLE_APP);
        break;
    default:
        clOsalPrintf("Invalid event type received.\n");
        goto failure;
        break;
    }

failure:
    clBufferDelete(&payLoadMsg);
    clHeapFree(eventData);
    return rc;
}
ClRcT
clDataTapInit(ClUint32T initFlags, ClUint32T appNum)
{
    char *env = 0;
    char buf[200];
    in_addr_t           addr_val;

    if (gDataTapObj.inited)
    {
        return CL_ERR_INITIALIZED;
    }
    // Should we have some consistency checking on the initFlags?
    // Probably, but I don't know yet what checking to do.
    gDataTapObj.package.version = CL_INST_VERSION;
    gDataTapObj.package.magic = htonl(DATA_TAP_MAGIC_NUMBER);
    gDataTapObj.package.flags = htonl(initFlags);
    gDataTapObj.package.data = 0;
    gDataTapObj.broked = 0;
    gDataTapObj.inited = 1;
    memset(&gDataTapObj.tapaddr, 0, sizeof gDataTapObj.tapaddr);

    // Get the port number from the environment
    sprintf(buf, "CSA%d_DEST_PORT", appNum);
    env = getenv(buf);
    if (env == 0)
    {
        clOsalPrintf("NO value for %s environment variable\n", buf);
        gDataTapObj.broked = 1;
        return CL_ERR_INVALID_PARAMETER;
    }
    gDataTapObj.tapaddr.sin_port = htons(atoi(env));
    printf("sin_port = %u (%u)\n", gDataTapObj.tapaddr.sin_port, (unsigned)atoi(env));

    // Now get the IP address fromthe environment
    sprintf(buf, "CSA%d_DEST_ADDR", appNum);
    env = getenv(buf);
    if (env == 0)
    {
        clOsalPrintf("NO value for %s environment variable\n", buf);
        gDataTapObj.broked = 1;
        return CL_ERR_INVALID_PARAMETER;
    }

    addr_val = inet_addr(env);
    gDataTapObj.tapaddr.sin_addr.s_addr = addr_val;

    gDataTapObj.sock = socket(PF_INET, SOCK_DGRAM, 0);
    if (gDataTapObj.sock == -1)
    {
        clOsalPrintf("Failed to open socket");
        return CL_OSAL_ERR_OS_ERROR;
    }

    return CL_OK;
}
ClRcT clEvtTestAppInitialize(ClUint32T argc, ClCharT *argv[])
{
    ClRcT rc = CL_OK;
    ClEoExecutionObjT *pEoObj;

#if 0
    ClSvcHandleT svcHandle = { 0 };
    ClOsalTaskIdT taskId = 0;
#endif

    /*
     * Create the list to hold the mapping b/n Init Name & evtHandle 
     */
    rc = clCntLlistCreate(clEvtContInitKeyCompare, clEvtContInitDataDelete,
                          clEvtContInitDataDelete, CL_CNT_UNIQUE_KEY,
                          &gEvtTestInitInfo);
    if (CL_OK != rc)
    {
        clOsalPrintf("Creating linked list for Init Failed, rc[0x%X]\r\n", rc);
        return rc;
    }

    rc = clCntLlistCreate(clChanContainerKeyCompare, clChanContainerDataDelete,
                          clChanContainerDataDelete, CL_CNT_UNIQUE_KEY,
                          &gChanHandleInitInfo);
    if(rc!=CL_OK)
    {
        clOsalPrintf("Creating Linked List for Channel handles failed\n\r");
        return rc;
    }
    /*
     * Create a Mutex to lock the containers before accessing them 
     */
    rc = clOsalMutexCreate(&gEvtTestInitMutex);
    if (CL_OK != rc)
    {
        clOsalPrintf("Creating Mutex for Init Failed, rc[0x%X]\r\n", rc);
        return rc;
    }

    rc = clEoMyEoObjectGet(&pEoObj);
    rc = clEoClientInstall(pEoObj, CL_EO_NATIVE_COMPONENT_TABLE_ID,
                           gClEvtTestAppFuncList, (ClEoDataT) NULL,
                           (int) sizeof(gClEvtTestAppFuncList) /
                           (int) sizeof(ClEoPayloadWithReplyCallbackT));
    rc = clEvtCpmInit();

#if 0
    svcHandle.cpmHandle = &gEvtTestAppCpmHandle;
    rc = clDispatchThreadCreate(pEoObj, &taskId, svcHandle);
#endif

    return CL_OK;
}
/******************************************************************************
 * Application Life Cycle Management Functions
 *****************************************************************************/
ClRcT clCompAlarmEvtCallbackFunc(const ClAlarmHandleInfoT* pAlarmInfo)
{
    ClRcT rc = CL_OK;
    ClNameT moIdName = {0};
    ClCorMOIdT moId ;
    ClIocAddressT iocAddress = {{0}};

    memcpy(&moId, &pAlarmInfo->alarmInfo.moId, sizeof(ClCorMOIdT));

    rc = clCorMoIdToMoIdNameGet(&moId, &moIdName);
    if(CL_OK == rc)
        clOsalPrintf(" The MSO for which the alarm is raised [%s]. ", moIdName.value);
    clOsalPrintf(" The component which has raised the alarm [%s] ", pAlarmInfo->alarmInfo.compName.value);
    clOsalPrintf("Probable Cause:%d\n",pAlarmInfo->alarmInfo.probCause);
    clOsalPrintf("Alarm Handle :%d\n",pAlarmInfo->alarmHandle);
    clOsalPrintf("Alarm State:%d\n",pAlarmInfo->alarmInfo.alarmState);
    if(pAlarmInfo->alarmInfo.len != 0)
        clOsalPrintf("Alarm payload :%s\n",pAlarmInfo->alarmInfo.buff);

    iocAddress.iocPhyAddress.nodeAddress = 2;
    clEoMyEoIocPortGet(&iocAddress.iocPhyAddress.portId);

    rc = clFaultRepairAction(iocAddress, pAlarmInfo->alarmHandle, SA_AMF_COMPONENT_RESTART);
    if (CL_OK != rc)
    {
        clOsalPrintf("Failed while reporting the alarm to the fault..... . rc[0x%x] \n", rc);
        return rc;
    }

    clOsalPrintf("################ Successfully reported the alarm to the fault. ..... \n");

    return rc;
}
static ClRcT
initSocket()
{
    char               *ipaddr;
    in_addr_t           addr_val;
    char               *port;
    uint16_t            port_num;

    CL_FUNC_ENTER();

    //
    // We'll want to get the address where we'll send instrumentation
    // information out of the environment.  Initialize the sockaddr
    // so after we create the socket we can connect it to the address.
    if ((ipaddr = getenv("CL_LOGGING_ADDR")) == 0)
    {
        clOsalPrintf("No value for CL_LOGGING_ADDR\n");
        CL_FUNC_EXIT();
        return CL_RC(0, CL_ERR_INVALID_PARAMETER);
    }
    if ((port = getenv("CL_LOGGING_PORT")) == 0)
    {
        clOsalPrintf("No value for CL_LOGGING_PORT\n");
        CL_FUNC_EXIT();
        return CL_RC(0, CL_ERR_INVALID_PARAMETER);
    }
    addr_val = inet_addr(ipaddr);
    port_num = atoi(port);
    memset(&instaddr, 0, sizeof instaddr);
    instaddr.sin_port = htons(port_num);
    instaddr.sin_addr.s_addr = addr_val;

    sock = socket(PF_INET, SOCK_DGRAM, 0);
    if (sock == -1)
    {
        clOsalPrintf("Failed to open socket");
        return CL_OSAL_ERR_OS_ERROR;
    }
//    if (connect(sock, &instaddr, sizeof addr) != 0)
//    {
//        clOsalPrintf("Failed to connect socket to %s/%s\n", ipaddr, port);
//        close(sock);
//        sock = -1;
//        CL_FUNC_EXIT();
//        return CL_OSAL_ERR_OS_ERROR;
//    }
    CL_FUNC_EXIT();
    return CL_OK;
}
static ClRcT clSubsEventLibrayInitialize(void)
{
    ClRcT rc = CL_OK;

    ClVersionT version = CL_EVENT_VERSION;    
    ClNameT channelName = {sizeof(CL_EO_EVENT_CHANNEL_NAME)-1, CL_EO_EVENT_CHANNEL_NAME};

    const ClEventCallbacksT evtCallbacks = 
    {
        NULL, // clSubsAsyncChannelOpenCb for Async Channel Open
        clSubEoEventWaterMarkCb,  // Event Delivery Callback
    };
    ClEventChannelOpenFlagsT evtFlags = CL_EVENT_CHANNEL_SUBSCRIBER | CL_EVENT_LOCAL_CHANNEL;

    rc = clEventInitialize(&gSubsEventInfo.initHandle, &evtCallbacks, &version);
    if(CL_OK != rc)
    {
        clOsalPrintf("clEventInitialize() failed [%#X]\n",rc);
        goto failure;
    }

    rc = clEventChannelOpen(gSubsEventInfo.initHandle, &channelName, 
            evtFlags, CL_RMD_DEFAULT_TIMEOUT, 
            &gSubsEventInfo.channelHandle);
    if(CL_OK != rc)
    {
        clOsalPrintf("clEventChannelOpen() failed [%#X]\n",rc);
        goto init_done;
    }

    rc = clEventSubscribe(gSubsEventInfo.channelHandle, CL_EVENT_DEFAULT_SUBS_FILTER, UNIQUE_SUBSCRIPTION_ID, 
            "User Specified Argument (cookie) for the event delivery callback");
    if(CL_OK != rc)
    {
        clOsalPrintf("clEventSubscribe() failed [%#X]\n",rc);
        goto channel_opened;
    }

    return CL_OK;

channel_opened:
    clEventChannelClose(gSubsEventInfo.channelHandle);

init_done:
    clEventFinalize(gSubsEventInfo.initHandle);

failure:
    return rc;
}
ClRcT
clComponentEventInit()
{
    ClRcT rc = CL_OK;

    rc = clAlarmEventSubscribe(clCompAlarmEvtCallbackFunc);
    if(CL_OK != rc)
    {
        clLogError("UT1","INT", "Subscribing for the event failed. rc[0x%x]", rc);
        return rc;
    }

    clOsalPrintf("################ Successfully subscribed for the alarm events ############## \n");

#if 0
    rc = clAlarmEventUnsubscribe();
    if(CL_OK != rc)
    {
        clLogError("UT1", "INT", "Unsubscribing the event failed. rc[0x%x]", rc);
        return rc;
    }    


    rc = clAlarmEventSubscribe(clCompAlarmEvtCallbackFunc);
    if(CL_OK != rc)
    {
        clLogError("UT1","INT", "Subscribing for the event failed. rc[0x%x]", rc);
        return rc;
    }

#endif 
    return rc;
}
void
tsAllActiveTimersPrint (void)
{
    ClRcT returnCode = CL_ERR_INVALID_HANDLE;
    ClUint32T count = 0;
    TsTimer_t* pUserTimer = NULL;

    returnCode = clOsalMutexLock (gActiveTimerQueue.timerMutex);

    if (returnCode != CL_OK) {
        return;
    }

    if (gActiveTimerQueue.pFirstTimer == NULL) {
        /* no elements to display */
        returnCode = clOsalMutexUnlock (gActiveTimerQueue.timerMutex);
        return;
    }

    for (pUserTimer = gActiveTimerQueue.pFirstTimer, count = 0;
            pUserTimer != NULL;
            pUserTimer = pUserTimer->pNextActiveTimer, count++) {
        clOsalPrintf ("(%d) Timer timeout = %us, timestamp->sec = %ld, timestamp->Microsec = %ld.\n",
                      (ClInt32T)count,
                      pUserTimer->timeOut.tsSec,
                      pUserTimer->timestamp/1000000ULL,
                      pUserTimer->timestamp%1000000ULL);
    }

    returnCode = clOsalMutexUnlock (gActiveTimerQueue.timerMutex);
}
void clSubsAsyncChannelOpenCb(ClInvocationT invocation,
        ClEventChannelHandleT channelHandle, ClRcT retCode)
{
    ClRcT rc = CL_OK;

    clOsalPrintf("*******************************************************\n");
    clOsalPrintf("************* Async Channel Open Callback *************\n");
    clOsalPrintf("*******************************************************\n");
    clOsalPrintf("             Invocation        : %#X\n", invocation);
    clOsalPrintf("             Channel Handle    : %#llX\n", channelHandle);
    clOsalPrintf("             API Return Code   : %#X\n", retCode);
    clOsalPrintf("*******************************************************\n");

    /*
     * Check if the Channel Open Asyn was successful
     */
    if(CL_OK != retCode)
    {
        goto failure;
    }

    rc = clEventSubscribe(channelHandle, CL_EVENT_DEFAULT_SUBS_FILTER, UNIQUE_SUBSCRIPTION_ID, 
            "User Specified Argument (cookie) for the event delivery callback");
    if(CL_OK != rc)
    {
        goto failure;
    }

failure:
    return;
}
static ClRcT clPubsEventLibrayFinalize(void)
{
    ClRcT rc = CL_OK;

    rc = clEventChannelClose(gPubsEventInfo.channelHandle);
    if(CL_OK != rc)
    {
        clOsalPrintf("clEventChannelClose() failed [%#X]\n",rc);
    }

    rc = clEventFinalize(gPubsEventInfo.initHandle);
    if(CL_OK != rc)
    {
        clOsalPrintf("clEventFinalize() failed [%#X]\n",rc);
    }

    return CL_OK;
}
示例#13
0
void
clOsalMemoryChecker(void) {
  if (CLIST_SIZE(_memory_logger_element)(g_memory_logger) != 0) {
    CLIST_ITER_TYPE(_memory_logger_element) iter =
      CLIST_BEGIN(_memory_logger_element)(g_memory_logger);
    while (iter != CLIST_END(_memory_logger_element)(g_memory_logger)) {
      _memory_logger_element *e = CLIST_ITER_GET_DATA(_memory_logger_element)(iter);
      clOsalPrintf("0x%p, at \"%s\":%d\n", e->ptr, e->filename, e->lineno);
      iter = CLIST_ITER_INCREMENT(_memory_logger_element)(iter);
    }
  }
}
ClRcT clDataTapSend(ClUint32T data)
{
    struct DataTapPackage package = gDataTapObj.package;
    package.data = htonl(data);
    
    if (!gDataTapObj.inited)
    {
        clOsalPrintf("Data Tap uninitialized\n");
        return CL_ERR_INITIALIZED;
    }
    if (gDataTapObj.broked)
    {
        return CL_ERR_INVALID_PARAMETER;
    }
    if (sendto(gDataTapObj.sock, &package, sizeof package, 0, &gDataTapObj.tapaddr, sizeof gDataTapObj.tapaddr) < 0)
    {
        clOsalPrintf("Failed to send message, sock = %d, errno = %d\n", sock, errno);
        return CL_OSAL_ERR_OS_ERROR;
    }
    return CL_OK;
}
static ClRcT clPubsEventLibrayInitialize(void)
{
    ClRcT rc = CL_OK;

    ClVersionT version = CL_EVENT_VERSION;    
    SaNameT channelName = {sizeof(CL_EO_EVENT_CHANNEL_NAME)-1, CL_EO_EVENT_CHANNEL_NAME};

    const ClEventCallbacksT evtCallbacks = 
    {
        clPubsAsyncChannelOpenCb, // Can be NULL if sync call is used
        NULL,   // Since it is not a subscriber  
    };
    ClEventChannelOpenFlagsT evtFlags = CL_EVENT_CHANNEL_PUBLISHER | CL_EVENT_LOCAL_CHANNEL;

    ClInvocationT invocation = UNIQUE_INVOCATION_ID; // To identify the callback

    rc = clEventInitialize(&gPubsEventInfo.initHandle, &evtCallbacks, &version);
    if(CL_OK != rc)
    {
        clOsalPrintf("clEventInitialize() failed [%#X]\n",rc);
        goto failure;
    }

    rc = clEventChannelOpenAsync(gPubsEventInfo.initHandle, invocation, 
            &channelName, evtFlags);
    if(CL_OK != rc)
    {
        clOsalPrintf("clEventChannelOpen() failed [%#X]\n",rc);
        goto init_done;
    }

    return CL_OK;

init_done:
    clEventFinalize(gPubsEventInfo.initHandle);

failure:
    return rc;
}
ClRcT clPubsAppFinalize()
{
    ClRcT rc = CL_OK;
    ClEoExecutionObjT* pEvtPubsEoObj;

    rc = clEoMyEoObjectGet(&pEvtPubsEoObj);
    {
        clOsalPrintf("EO Object Get failed [%#X]\n",rc);
    }

    rc = clEoClientUninstall(pEvtPubsEoObj,CL_EO_NATIVE_COMPONENT_TABLE_ID);
    if(CL_OK != rc)
    {
        clOsalPrintf("EO Client Uninstall failed [%#X]\n",rc);
    }

    rc = clPubsEventLibrayFinalize();
    if(CL_OK != rc)
    {
        clOsalPrintf("Event Library Finalize failed [%#X]\n",rc);
    }

    return CL_OK;
}
static ClRcT clSubsEventLibrayFinalize(void)
{
    ClRcT rc = CL_OK;

    rc = clEventUnsubscribe(gSubsEventInfo.channelHandle, UNIQUE_SUBSCRIPTION_ID);
    if(CL_OK != rc)
    {
        clOsalPrintf("clEventUnsubscribe() failed [%#X]\n",rc);
    }

    rc = clEventChannelClose(gSubsEventInfo.channelHandle);
    if(CL_OK != rc)
    {
        clOsalPrintf("clEventChannelClose() failed [%#X]\n",rc);
    }

    rc = clEventFinalize(gSubsEventInfo.initHandle);
    if(CL_OK != rc)
    {
        clOsalPrintf("clEventFinalize() failed [%#X]\n",rc);
    }

    return CL_OK;
}
/**
 *  Show Instance Details.
 *
 *  API to print the instance details.
 *
 *  @param smThis State Machine Object
 *
 *  @returns 
 *    void
 *
 *  @see #clEsmInstanceLogShow
 */
void
clEsmInstanceShow(ClExSmInstancePtrT smThis
                )
{
  if(smThis)
    {
      ClUint32T sz;

      SMQ_SIZE(smThis->q, sz);
      clOsalPrintf("\n[ESM] Instance: Lock [%d] Pause [%d] Q-Items [%d]", 
               smThis->lock,
               smThis->pause,
               sz);
      smInstanceShow(smThis->fsm);
    }

}
void clPubsAsyncChannelOpenCb(ClInvocationT invocation,
        ClEventChannelHandleT channelHandle, ClRcT retCode)
{
    ClRcT rc = CL_OK;

    clOsalPrintf("*******************************************************\n");
    clOsalPrintf("************* Async Channel Open Callback *************\n");
    clOsalPrintf("*******************************************************\n");
    clOsalPrintf("             Invocation        : %#X\n", invocation);
    clOsalPrintf("             Channel Handle    : %#llX\n", channelHandle);
    clOsalPrintf("             API Return Code   : %#X\n", retCode);
    clOsalPrintf("*******************************************************\n");

    /*
     * Check if the Channel Open Asyn was successful
     */
    if(CL_OK != retCode)
    {
        clOsalPrintf("clEventChannelOpenAsync() failed [%#X]\n",rc);
        goto failure;
    }

    gPubsEventInfo.channelHandle = channelHandle;

    rc = clPubsTriggerEvent(CL_EO_LIB_ID_HEAP, CL_WM_HIGH, CL_WM_HIGH_LIMIT, CL_WM_LOW_LIMIT);
    if(CL_OK != rc)
    {
        clOsalPrintf("Publish trigger failed [%#X]\n",rc);
        goto channel_opened;
    }

channel_opened:
    clEventChannelClose(gPubsEventInfo.channelHandle);

failure:
    return;
}
/**
 *  Show Log Details.
 *
 *  API to print the history of the state machine instance..
 *
 *  @param smThis State Machine Object
 *
 *  @returns 
 *    void
 *
 *  @see #clEsmInstanceLogShow
 */
void
clEsmInstanceLogShow(ClExSmInstancePtrT smThis,
                   ClUint16T  items
                   )
{
  if(smThis)
    {
      int i;
      ClSmLogInfoPtrT logBuf;

#ifdef DEBUG
      clOsalPrintf("\n[ESM] Instance: %s Last [%d] entries:",
               smThis->fsm->name,
               items);
#else
      clOsalPrintf("\n[ESM] Instance: Last [%d] entries:",
               (int)items);
#endif
      clOsalPrintf("\n------------------------------------------");
      clOsalPrintf("\n Event   From-State       To-State");
      clOsalPrintf("\n------------------------------------------");
      /* show last 'items' log information */
      for(i=1;i<= (int)items && i<=ESM_LOG_ENTRIES;i++)
        {
          logBuf = ESM_LOG_BACK_GET(smThis->log, i);
          if(logBuf && logBuf->from && logBuf->to)
            {
              clOsalPrintf("\n  %02d  %02d/%-15s %02d/%s",
                       logBuf->eventId,
#ifdef DEBUG
                       logBuf->from->type,
                       logBuf->from->name,
                       logBuf->to->type,
                       logBuf->to->name);
#else
                       logBuf->from->type,
                       "",
                       logBuf->to->type,
                       "");
#endif
            }
        }
      clOsalPrintf("\n------------------------------------------\n");
    }
ClRcT clEvtCpmReplyCb(ClUint32T data, ClBufferHandleT inMsgHandle,
                      ClBufferHandleT outMsgHandle)
{
    ClUint32T rc = CL_OK;

#if 0
    ClCpmLcmResponseT response = { {0, 0}, 0 };
    ClUint32T msgLength = 0;
    ClCharT logmsg[CL_MAX_NAME_LENGTH] = { 0 };
    ClCharT requesttype[CL_MAX_NAME_LENGTH] = { 0 };

    CL_FUNC_ENTER();
    rc = clBufferLengthGet(inMsgHandle, &msgLength);
    if (msgLength == sizeof(ClCpmLcmResponseT))
    {
        rc = clBufferNBytesRead(inMsgHandle, (ClUint8T *) &response,
                                &msgLength);
        if (rc != CL_OK)
        {
            clOsalPrintf("Unable to read the message. \n");
            goto failure;
        }
    }
    else
    {
        clOsalPrintf("Buffer read failure !\n");
        goto failure;
    }

    printf("Received reply for %s...\n", response.name);

    switch (response.requestType)
    {
    case CL_CPM_HEALTHCHECK:
        strcpy(requesttype, "CL_CPM_HEALTHCHECK");
        break;
    case CL_CPM_TERMINATE:
        strcpy(requesttype, "CL_CPM_TERMINATE");
        break;
    case CL_CPM_PROXIED_INSTANTIATE:
        strcpy(requesttype, "CL_CPM_PROXIED_INSTANTIATE");
        break;
    case CL_CPM_PROXIED_CLEANUP:
        strcpy(requesttype, "CL_CPM_PROXIED_CLEANUP");
        break;
    case CL_CPM_EXTN_HEALTHCHECK:
        strcpy(requesttype, "CL_CPM_EXTN_HEALTHCHECK");
        break;
    case CL_CPM_INSTANTIATE:
        strcpy(requesttype, "CL_CPM_INSTANTIATE");
        break;
    case CL_CPM_CLEANUP:
        strcpy(requesttype, "CL_CPM_CLEANUP");
        break;
    case CL_CPM_RESTART:
        strcpy(requesttype, "CL_CPM_RESTART");
        break;
    default:
        strcpy(requesttype, "Invalid request");
        break;
    }

    sprintf(logmsg, "%s %s request %s.\n", response.name, requesttype,
            response.returnCode == CL_OK ? "success" : "failure");
    printf(logmsg);

    CL_FUNC_EXIT();
    return CL_OK;

failure:
    CL_FUNC_EXIT();
#endif

    printf("Invoked the Callback for CPM API succesfully\n\r\n");

    return rc;
}
/**
 * This function is called by the provisioning library whenever the object 
 * modification operation is done on the resource being managed. For a single job 
 * request, this function is called if the validate function is failed. For a 
 * multiple job request, on encountering a validate failure, this function is 
 * called to rollback all the jobs before the one (including) on which the 
 * validation failure is reported.
 *
 * The pThis is a pointer to the provisioning class. 
 * The txnHandle is the unique handle for all the jobs which are part of same session. So for
 * a session containing multiple jobs, then it is unique of all the jobs and it can be used
 * to identify them.
 * 
 * The pProvTxnData is a pointer to the ClProvTxnDataT structure which contains 
 * the information about the job being performed on the managed resource. 
 * The pProvTxnData->provCmd stores the operation type which can be 
 * CL_COR_OP_CREATE_AND_SET, CL_COR_OP_CREATE, CL_COR_OP_SET or CL_COR_OP_DELETE
 * based on what is the operation happening on the resource.
 * In the case of set operation, the various fields of pProvTxnData provide the
 * the details about the operation which is happening on the resource. It contain 
 * MOID of the managed resource and information about the attribute on which set
 * operation is done. For a create, create-set and delete operation, the pProvTxnData 
 * contains the MOID of the resource on which the given operation is done.
 *
 * ** Note : This function is being deprecated, if clProvObjectRollback() callback 
 * is filled in the constructor, then that callback function will be called 
 * instead of this to group rollback all the requests.
 */
ClRcT clProvisioningTIMESETTABLEProvRollback(CL_OM_PROV_CLASS* pThis, ClHandleT txnHandle, ClProvTxnDataT* pProvTxnData)
{
    ClRcT rc = CL_OK;

    /*
     * ---BEGIN_APPLICATION_CODE---
     */
    ClNameT     moIdName = {0};

    clprintf(CL_LOG_SEV_INFO, "Inside the function %s", __FUNCTION__);

    if (pProvTxnData == NULL)
    {
        clOsalPrintf("[%s]: Null pointer detected for pProvTxnData. \n", appname);
        return CL_ERR_NULL_POINTER;
    }

    rc = clCorMoIdToMoIdNameGet((ClCorMOIdPtrT)pProvTxnData->pMoId, &moIdName);
    if (CL_OK != rc)
    {
        clOsalPrintf("[%s]: Failed while getting the name of the MO. rc[0x%x]", appname, rc);
        return rc;
    } 
    
    switch (pProvTxnData->provCmd)
    {
        case CL_COR_OP_CREATE :
        case CL_COR_OP_CREATE_AND_SET:

        break;
        case CL_COR_OP_SET:

        if (pProvTxnData->pProvData == NULL)
        {
            clOsalPrintf("[%s]: The value for the AttrId [0x%x], MO [%s] \n",
                    appname, pProvTxnData->attrId, moIdName.value);
            return CL_ERR_NULL_POINTER;
        }

	    switch (pProvTxnData->attrId)
        {
            case TIMESETTABLE_TIMESETHOUR :
            {
                clOsalPrintf("[%s]: Rolling back AttrId [TIMESETTABLE_TIMESETHOUR: 0x%x] of MO [%s] \n", 
                    appname, pProvTxnData->attrId, moIdName.value);
            }
            break;
            case TIMESETTABLE_TIMESETMINUTE:
            {
                clOsalPrintf("[%s]: Rolling back AttrId [TIMESETTABLE_TIMESETMINUTE: 0x%x] of MO [%s] \n", 
                    appname, pProvTxnData->attrId, moIdName.value);
            }
            break;
            case TIMESETTABLE_TIMESETSECOND:
            {
                clOsalPrintf("[%s]: Rolling back AttrId [TIMESETTABLE_TIMESETSECOND: 0x%x] of MO [%s] \n", 
                    appname, pProvTxnData->attrId, moIdName.value);
            }
            break;
            default:
                clOsalPrintf("[%s]: Do nothing. \n", appname);
        }
 
        break;
        default:
            clprintf (CL_LOG_SEV_ERROR, "Prov command is not proper");

    }
    /*
     * ---END_APPLICATION_CODE---
     */

    return rc;
}
ClRcT
clInstInitId()
{
    ClRcT           rc          = CL_OK;
    InstrumentedId *tmpPtr      = 0;

    CL_FUNC_ENTER();
    // check whether the id has been initialized
    if (myInstId != 0)
    {
        CL_FUNC_EXIT();
        return CL_OK;
    }

    if (sock == -1)
    {
        rc = initSocket();
        if (rc != CL_OK)
        {
            clOsalPrintf("failed to initialize instrumentation socket\n");
            return rc;
        }
    }


    // Nope, not initialized, so try to initialize it here.
    // First, try to lock a mutex so that only one thread
    // will be creating the id.
    // Then, try to get our component name, our local node name
    // and then allocate the id and set it from the component
    // and local node name.
    // Finally, unlock and delete the mutex.
    if (!id_mutex)
    {
        if ((rc = clOsalMutexCreateAndLock(&id_mutex)) != CL_OK)
        {
            clOsalPrintf("Failed [0x%x] to create and lock mutex\n", rc);
            CL_FUNC_EXIT();
            return rc;
        }
    }
    else
    {
        // Some other thread must have come through here and set
        // the mutex before us.  We're done.
        CL_FUNC_EXIT();
        return CL_OK;
    }

    if ((tmpPtr = clHeapCalloc(1, sizeof (InstrumentedId))) == 0)
    {
        clOsalPrintf("failed to allocate InstrumentedID\n");
        rc = CL_RC(0, CL_ERR_NO_MEMORY);
        goto breakdown;
    }
    memset(&tmpPtr->compName, 0, sizeof tmpPtr->compName);
    memset(&tmpPtr->nodeName, 0, sizeof tmpPtr->nodeName);
    rc = CL_OK;
    myInstId = tmpPtr;
    tmpPtr = 0;

breakdown:
    clOsalMutexUnlock(id_mutex);
    clOsalMutexDelete(id_mutex);
    id_mutex = 0;

    CL_FUNC_EXIT();
    return rc;
}
static void clSubEoEventWaterMarkCb( ClEventSubscriptionIdT subscriptionId,
        ClEventHandleT eventHandle, ClSizeT eventDataSize )
{
    ClRcT rc = CL_OK;

    ClEventPriorityT priority = 0;
    ClTimeT retentionTime = 0;
    ClNameT publisherName = { 0 };
    ClEventIdT eventId = 0;
    ClEventPatternArrayT patternArray = { 0 };
    ClTimeT publishTime = 0;
    ClPtrT pCookie = NULL;

    ClPtrT pEventData = NULL;

    ClUint8T *pEventPayload = NULL;

    /*
     * Allocate memory for the event payload.
     */
    pEventData = clHeapAllocate(eventDataSize);
    if (pEventData == NULL)
    {
        clOsalPrintf("Allocation for event data failed. rc[%#X]\n", rc);
        goto failure;
    }

    /*
     * Fetch the event payload. NOTE that there is a bug in the SAF spec B.01.01
     * allowing the application to pass a pointer and expecting the 
     * clEventDataGet() to return the allocated memory. This is not possible as
     * the parameter pEventData is a single pointer so the memory allocated by
     * the callee can't be returned to the caller.
     */
    rc = clEventDataGet (eventHandle, pEventData,  &eventDataSize);
    if (rc != CL_OK)
    {
        clOsalPrintf("Event Data Get failed. rc[%#X]\n", rc);
        goto failure;
    }

    pEventPayload = pEventData;

    /*
     * Fetch the cookie specified during subscribe.
     */
    rc = clEventCookieGet(eventHandle, &pCookie);
    if (rc != CL_OK)
    {
        clOsalPrintf("Event Cookie Get failed. rc[%#X]\n", rc);
        goto failure;
    }

    /*
     * Fetch the attributes of the event.
     */
    rc = clEventAttributesGet(eventHandle, &patternArray, &priority,
                              &retentionTime, &publisherName, &publishTime,
                              &eventId);
    if (rc != CL_OK)
    {
        clOsalPrintf("Event Attributes Get failed. rc[%#X]\n", rc);
        goto failure;
    }

    /*
     * Free the allocated Event 
     */
    rc = clEventFree(eventHandle);

    clOsalPrintf("-------------------------------------------------------\n");
    clOsalPrintf("!!!!!!!!!!!!!!! Event Delivery Callback !!!!!!!!!!!!!!!\n");
    clOsalPrintf("-------------------------------------------------------\n");
    clOsalPrintf("             Subscription ID   : %#X\n", subscriptionId);
    clOsalPrintf("             Event Priority    : %#X\n", priority);
    clOsalPrintf("             Publish Time      : 0x%llX\n",
                 publishTime);
    clOsalPrintf("             Retention Time    : 0x%llX\n",
                 retentionTime);
    clOsalPrintf("             Publisher Name    : %.*s\n",
                 publisherName.length, publisherName.value);
    clOsalPrintf("             EventID           : %#X\n", eventId);
    clOsalPrintf("             Event Payload     : %s\n", pEventPayload);
    clOsalPrintf("             Event Cookie      : %s\n", (ClUint8T*)pCookie);

    clHeapFree(pEventPayload); // Release the memory allocated for the payload.

    /*
     * Display the Water Mark Details and Free the patterns.
     * Note that each pattern needs to be freed and then the
     * pattern array in that order.
     */

    clOsalPrintf("             EO Name           : %.*s\n",
                (ClInt32T)patternArray.pPatterns[0].patternSize, 
                (ClCharT *)patternArray.pPatterns[0].pPattern);
    clHeapFree(patternArray.pPatterns[0].pPattern);

    clOsalPrintf("             Library ID        : %#X\n",
                *(ClEoLibIdT *)patternArray.pPatterns[1].pPattern);
    clHeapFree(patternArray.pPatterns[1].pPattern);

    clOsalPrintf("             Water Mark ID     : %#X\n",
                *(ClWaterMarkIdT *)patternArray.pPatterns[2].pPattern);
    clHeapFree(patternArray.pPatterns[2].pPattern);

    clOsalPrintf("             Water Mark Type   : %s\n",
                (*(ClEoWaterMarkFlagT *)patternArray.pPatterns[3].pPattern == CL_WM_HIGH_LIMIT)? "HIGH" : "LOW");
    clHeapFree(patternArray.pPatterns[3].pPattern);

    clOsalPrintf("             Water Mark Value  : %u\n",
                *(ClUint32T *)patternArray.pPatterns[4].pPattern);
    clHeapFree(patternArray.pPatterns[4].pPattern);

    clHeapFree(patternArray.pPatterns);

    clOsalPrintf("-------------------------------------------------------\n");

failure:
    return;
}
static ClRcT clPubsTriggerEvent(ClEoLibIdT libId, ClWaterMarkIdT wmId, ClUint32T wmValue, ClEoWaterMarkFlagT wmFlag)
{
    ClRcT rc = CL_OK;

    ClEventIdT eventId = 0;
    SaNameT publisherName = {sizeof(CL_EVENT_PUBLISHER_NAME)-1, CL_EVENT_PUBLISHER_NAME};

    ClEventPatternT patterns[5] = {{0}};

    ClEventPatternArrayT patternArray = {
        0,
        CL_SIZEOF_ARRAY(patterns),
        patterns 
    };

    rc = clEventAllocate(gPubsEventInfo.channelHandle, &gPubsEventInfo.eventHandle);
    if(CL_OK != rc)
    {
        clOsalPrintf("clEventAllocate() failed [%#X]\n",rc);
        goto failure;
    }

    patterns[0].patternSize = strlen(CL_EO_NAME);
    patterns[0].pPattern = (ClUint8T *)CL_EO_NAME;
    
    patterns[1].patternSize = sizeof(libId);
    patterns[1].pPattern = (ClUint8T *)&libId;
    
    patterns[2].patternSize = sizeof(wmId);
    patterns[2].pPattern = (ClUint8T *)&wmId;
    
    patterns[3].patternSize = sizeof(wmFlag);
    patterns[3].pPattern = (ClUint8T *)&wmFlag;
    
    patterns[4].patternSize = sizeof(wmValue);
    patterns[4].pPattern = (ClUint8T *)(&wmValue);
    
    rc = clEventAttributesSet(gPubsEventInfo.eventHandle, &patternArray, 
            CL_EVENT_HIGHEST_PRIORITY, 0, &publisherName);
    if(CL_OK != rc)
    {
        clOsalPrintf("clEventAttributesSet() failed [%#X]\n",rc);
        goto event_allocated;
    }

    rc = clEventPublish(gPubsEventInfo.eventHandle, "Event Payload passed in endian neutral way", 
            sizeof("Event Payload passed in endian neutral way."), &eventId);
    if(CL_OK != rc)
    {
        clOsalPrintf("clEventPublish() failed [%#X]\n",rc);
        goto event_allocated;
    }

event_allocated:
    rc = clEventFree(gPubsEventInfo.eventHandle);
    if(CL_OK != rc)
    {
        clOsalPrintf("clEventFree() failed [%#X]\n",rc);
    }

failure:
    return rc;
}
ClRcT
clInstSendMessage(int msgType, const char *msg)
{
    char        msgBuf[INST_BUF_SIZE];
    ClRcT       rc = CL_OK;
    int         space;
    char       *ptr = msgBuf;

    CL_FUNC_ENTER();
    if ((rc = clInstInitId()) != CL_OK)
    {
        clOsalPrintf("Failed [0x%x] to initialize Instrumentation id\n", rc);
        CL_FUNC_EXIT();
        return rc;
    }

    //
    // Fill in the msgBuf: msgType,nodeName,compName,msg
    // Check that we have room for the message, formatting it
    // as we go.  Finally, send it over the socket which should
    // already been connected in clInstInitId
    sprintf(msgBuf, "%d", CL_INST_VERSION);
    space = sizeof msgBuf - 1;
    sprintf(msgBuf+1, "%d,", msgType);
    space = sizeof msgBuf - 2;
    ptr += strlen(ptr);
    space = (sizeof msgBuf) - (ptr - msgBuf);
    if (myInstId->nodeName.length == 0)
    {
        strcpy(ptr, "unknown_node,");
    }
    else
    {
        if ((myInstId->nodeName.length + 1) >= space)
        {
            clOsalPrintf("nodeName (%s) too long for remaining space (%d)\n",
                        myInstId->nodeName.value, space);
        }
        else
        {
            strcpy(ptr, myInstId->nodeName.value);
            strcat(ptr, ",");
        }
    }
    ptr += strlen(ptr);
    space = (sizeof msgBuf) - (ptr - msgBuf);

    if (myInstId->compName.length == 0)
    {
        strcat(ptr, "unknown_component,");
    }
    else
    {
        if ((myInstId->compName.length + 1) >= space)
        {
            clOsalPrintf("compName (%s) too long for remaining space (%d)\n",
                        myInstId->compName.value, space);
            return CL_RC(0, CL_ERR_BUFFER_OVERRUN);
        }
        else
        {
            strcpy(ptr, myInstId->compName.value);
            strcat(ptr, ",");
        }
    }
    ptr += strlen(ptr);
    space = (sizeof msgBuf) - (ptr - msgBuf);

    // check that there's enough room for the message in our buffer
    // and if there is then copy it in.
    if (strlen(msg) >= space)
    {
        strncpy(ptr, msg, space - 4);   // room for "..."
        ptr += (space - 4);
        strcpy(ptr, "...");
    }
    else
    {
        strcpy(ptr, msg);
    }
    ptr += strlen(ptr);
    space = (sizeof msgBuf) - (ptr - msgBuf);

    if (sendto(sock, msgBuf, ptr - msgBuf, 0, &instaddr, sizeof instaddr) == -1)
    {
        clOsalPrintf("Failed to send message, sock = %d, errno = %d\n", sock, errno);
        return CL_OSAL_ERR_OS_ERROR;
    }
    CL_FUNC_EXIT();
    return rc;
}
ClRcT _cpmClusterConfigList(ClInt32T argc, ClCharT **retStr)
{
    ClCpmLT *cpmL = NULL;
    ClRcT rc = CL_OK;
    ClCntNodeHandleT hNode = 0;
    ClUint32T cpmLCount = 0;
    ClCharT tempStr[256];
    ClCharT *tmpStr = NULL;
    ClBufferHandleT message;

    rc = clBufferCreate(&message);
    CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to create message \n"), rc);

    if (argc != ONE_ARGUMENT)
    {
        sprintf(tempStr, "Usage: clusterList");
        rc = clBufferNBytesWrite(message, (ClUint8T *) tempStr,
                                        strlen(tempStr));
        CL_CPM_CHECK(CL_DEBUG_ERROR, ("Unable to write message %x\n", rc), rc);
        goto done;
    }

    /*
     * Print the local stuff first 
     */
    sprintf(tempStr, "%s\n", "nodeName | status | iocAddress | iocPort ");
    rc = clBufferNBytesWrite(message, (ClUint8T *) tempStr,
                                    strlen(tempStr));
    CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to write message \n"), rc);

    sprintf(tempStr, "%s\n",
            "-----------------------------------------------------------------------");
    rc = clBufferNBytesWrite(message, (ClUint8T *) tempStr,
                                    strlen(tempStr));
    CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to write message \n"), rc);

    /*
     * Now even the CPM/G information is stored in the list.
     * So no need of printing the above information.
     */
#if 0
    if (gpClCpm->pCpmLocalInfo->status == CL_CPM_EO_DEAD)
        sprintf(tempStr, "%10s | DEAD | %8d |   0x%x\n",
                gpClCpm->pCpmLocalInfo->nodeName,
                gpClCpm->pCpmLocalInfo->cpmAddress.nodeAddress,
                gpClCpm->pCpmLocalInfo->cpmAddress.portId);
    else
        sprintf(tempStr, "%10s | ALIVE | %8d |   0x%x\n",
                gpClCpm->pCpmLocalInfo->nodeName,
                gpClCpm->pCpmLocalInfo->cpmAddress.nodeAddress,
                gpClCpm->pCpmLocalInfo->cpmAddress.portId);
    rc = clBufferNBytesWrite(message, (ClUint8T *) tempStr,
                                    strlen(tempStr));
    CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to write message \n"), rc);
#endif
    /*_cpmListAllSU();*/
    /*
     * Get all the CPMs one by one and delete the stuff.
     */
    rc = clCntFirstNodeGet(gpClCpm->cpmTable, &hNode);
    CL_CPM_CHECK(CL_DEBUG_ERROR, ("Unable to get first cpmTable Node %x\n", rc),
                 rc);
    rc = clCntNodeUserDataGet(gpClCpm->cpmTable, hNode,
                              (ClCntDataHandleT *) &cpmL);
    CL_CPM_CHECK(CL_DEBUG_ERROR, ("Unable to get container Node data %x\n", rc),
                 rc);
    cpmLCount = gpClCpm->noOfCpm;

    while (cpmLCount)
    {
        if (cpmL->pCpmLocalInfo != NULL)
        {
            if (cpmL->pCpmLocalInfo->status == CL_CPM_EO_DEAD)
            {
                sprintf(tempStr, "%10s | DEAD  | %8d |   0x%x\n",
                        cpmL->nodeName,
                        cpmL->pCpmLocalInfo->cpmAddress.nodeAddress,
                        cpmL->pCpmLocalInfo->cpmAddress.portId);
            }
            else
            {
                sprintf(tempStr, "%10s | ALIVE | %8d |   0x%x\n",
                        cpmL->nodeName,
                        cpmL->pCpmLocalInfo->cpmAddress.nodeAddress,
                        cpmL->pCpmLocalInfo->cpmAddress.portId);
            }
            rc = clBufferNBytesWrite(message, (ClUint8T *) tempStr,
                                            strlen(tempStr));
            CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to write message \n"), rc);
        }
        else
        {
            sprintf(tempStr, "%10s \n", cpmL->nodeName);
            rc = clBufferNBytesWrite(message, (ClUint8T *) tempStr,
                                            strlen(tempStr));
            CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to write message \n"), rc);
        }
#if 0
        rc = clCntFirstNodeGet(cpmL->suTable, &hSU);
        CL_CPM_CHECK(CL_DEBUG_ERROR,
                     ("Unable to get first su Node in cpmL %x\n", rc), rc);
        if (cpmL->pCpmLocalInfo != NULL)
            clOsalPrintf("%10s | %8d | %8d | 0x%8x| 0x%8x \n",
                         cpmL->pCpmLocalInfo->nodeName,
                         cpmL->pCpmLocalInfo->status,
                         cpmL->pCpmLocalInfo->nodeId,
                         cpmL->pCpmLocalInfo->cpmAddress.nodeAddress,
                         cpmL->pCpmLocalInfo->cpmAddress.portId);
        else
            clOsalPrintf("%10s \n", cpmL->nodeName);

        suCount = cpmL->noOfsu;
        while (suCount)
        {
            rc = clCntNodeUserDataGet(cpmL->suTable, hSU,
                                      (ClCntDataHandleT *) &su);
            CL_CPM_CHECK(CL_DEBUG_ERROR,
                         ("Unable to get first container su Node data %x\n",
                          rc), rc);

            clOsalPrintf("\t %10s |%15s |%11s |%16s \n", su->suName,
                         _cpmPresenceStateNameGet(su->suPresenceState),
                         _cpmOperStateNameGet(su->suOperState),
                         _cpmReadinessStateNameGet(su->suReadinessState));
            tempCompRef = su->suCompList;
            while (tempCompRef != NULL)
            {
                clOsalPrintf
                    ("-----------------------------------------------------------------------\n");
                clOsalPrintf("\t\t%10s %14d |%15s |%11s |%16s \n",
                             tempCompRef->ref->compConfig->compName,
                             tempCompRef->ref->compRestartCount,
                             _cpmPresenceStateNameGet(tempCompRef->ref->
                                                      compPresenceState),
                             _cpmOperStateNameGet(tempCompRef->ref->
                                                  compOperState),
                             _cpmReadinessStateNameGet(tempCompRef->ref->
                                                       compReadinessState));
                tempCompRef = tempCompRef->pNext;
            }
            suCount--;
            if (suCount)
            {
                rc = clCntNextNodeGet(cpmL->suTable, hSU, &hSU);
                CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to Get Node  Data \n"),
                             rc);
            }
        }
#endif
        sprintf(tempStr, "%s",
                "-----------------------------------------------------------------------\n");
        rc = clBufferNBytesWrite(message, (ClUint8T *) tempStr,
                                        strlen(tempStr));
        CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to write message \n"), rc);
        cpmLCount--;
        if (cpmLCount)
        {
            rc = clCntNextNodeGet(gpClCpm->cpmTable, hNode, &hNode);
            CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to Get Node  Data \n"),
                         rc);
            rc = clCntNodeUserDataGet(gpClCpm->cpmTable, hNode,
                                      (ClCntDataHandleT *) &cpmL);
            CL_CPM_CHECK(CL_DEBUG_ERROR,
                         ("Unable to get container Node data %d\n", rc), rc);
        }
    }

    /*
     * Bug 4986 :
     * Moved the code to NULL terminate the string
     * below the done: label, so that the usage string
     * written to the buffer is also NULL terminated.
     */
  done:
    /*
     * NULL terminate the string 
     */
    sprintf(tempStr, "%s", "\0");
    rc = clBufferNBytesWrite(message, (ClUint8T *) tempStr, 1);
    CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to write message \n"), rc);

    rc = clBufferFlatten(message, (ClUint8T **) &tmpStr);
    CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to flatten message \n"), rc);

    *retStr = tmpStr;

    clBufferDelete(&message);
    return rc;

  failure:
    clBufferDelete(&message);
    return rc;
}
ClRcT clComponentCallBack(void *arg)
{

    ClRcT rc = CL_OK;
    struct timeval alarmTime;
    ClAlarmHandleT alarmHandle;
    ClNameT moidName = {strlen("\\Chassis:0\\GigeBlade:0"),
                        "\\Chassis:0\\GigeBlade:0"};
    ClNameT moidName2 = {strlen("\\Chassis:0\\GigeBlade:0\\GigePort:0"),
                        "\\Chassis:0\\GigeBlade:0\\GigePort:0"};

    ClAlarmInfoT *pAlarmInfo;
    ClCorMOIdT   moId;
    ClNameT      moIdName = {0};

    pAlarmInfo = clHeapAllocate(sizeof(ClAlarmInfoT)+strlen("HelloHelloHelloHelloHelloHelloHelloHello")+1);
    if(pAlarmInfo == NULL)
    {
        clOsalPrintf("Failed while allocating the memory for the alamr information.");
        return CL_ALARM_RC(CL_ERR_NO_MEMORY);
    }

    clCpmComponentNameGet(0,&(pAlarmInfo->compName));
    CL_DEBUG_PRINT(CL_DEBUG_ERROR, (" CompName : %s\n", pAlarmInfo->compName.value));
    clCorMoIdNameToMoIdGet(&moidName,&(pAlarmInfo->moId));

    pAlarmInfo->alarmState      = CL_ALARM_STATE_ASSERT;
    pAlarmInfo->category        = CL_ALARM_CATEGORY_QUALITY_OF_SERVICE;
    pAlarmInfo->specificProblem = 0;
    pAlarmInfo->severity        = CL_ALARM_SEVERITY_CRITICAL;
    gettimeofday(&alarmTime,NULL);
    pAlarmInfo->eventTime       = alarmTime.tv_sec;
    pAlarmInfo->len = strlen("HelloHelloHelloHelloHelloHelloHelloHello")+1;
    memcpy(pAlarmInfo->buff,"HelloHelloHelloHelloHelloHelloHelloHello",pAlarmInfo->len);

    ClEoExecutionObjT* peoObj=(ClEoExecutionObjT *)arg;
    if ( (rc = clEoMyEoObjectSet(peoObj)) != CL_OK)
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, (" clEoMyEoObjectSet failed, rc:0x%x \n", rc));
        return rc;
    }

	/**
	  * Raising alarm for :
	  * MOId -  /Chassis:0/GigeBlade:0
	  * Category - CL_ALARM_CATEGORY_QUALITY_OF_SERVICE
	  * Probable Cause - CL_ALARM_PROB_CAUSE_BANDWIDTH_REDUCED
	  */
    CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Raising alarm for [%s] and the probable cause\
			[%d]", moidName.value, CL_ALARM_PROB_CAUSE_LOSS_OF_FRAME));
    pAlarmInfo->probCause = CL_ALARM_PROB_CAUSE_BANDWIDTH_REDUCED;
    rc = clAlarmRaise(pAlarmInfo,&alarmHandle);

	/**
	  * Raising alarm for :
	  * MOId - /Chassis:0/GigeBlade:0
	  * Category -  CL_ALARM_CATEGORY_QUALITY_OF_SERVICE
	  * Probable Cause - CL_ALARM_PROB_CAUSE_RESPONSE_TIME_EXCESSIVE
	  */
    pAlarmInfo->probCause = CL_ALARM_PROB_CAUSE_RESPONSE_TIME_EXCESSIVE;
    CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Raising alarm for [%s] and the probable \
		cause [%d]", moidName.value, CL_ALARM_PROB_CAUSE_RESPONSE_TIME_EXCESSIVE));
    rc = clAlarmRaise(pAlarmInfo,&alarmHandle);
    CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Alarm Category : %d \n",pAlarmInfo->category ));
    CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Alarm severity: %d \n",pAlarmInfo->severity));

    rc = clAlarmClientResourceInfoGet(alarmHandle, &moId);
    if ( CL_OK != rc)
    {
        clOsalPrintf("Failed while asking the moid for the alarm handle [%d]. rc[0x%x] \n", alarmHandle, rc);
        return rc;
    }

    rc = clCorMoIdToMoIdNameGet(&moId, &moIdName);
    if(CL_OK != rc)
    {
        clOsalPrintf("Failed while getting the mOId name from moid . rc[0x%x]", rc) ;
        return rc;
    }

    clOsalPrintf("The MOID for the alarm handle is [%d] is [%s]\n", alarmHandle, moIdName.value);
	/**
	  * Raising alarm for :
	  * MOId - /Chassis:0/GigeBlade:0/GigePort:0
	  * Category - CL_ALARM_CATEGORY_QUALITY_OF_SERVICE
	  * Probable Cause - CL_ALARM_PROB_CAUSE_LOSS_OF_FRAME
	  */
    CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Raising alarm for [%s] and the probable \
				cause [%d]", moidName2.value, CL_ALARM_PROB_CAUSE_LOSS_OF_FRAME));
    pAlarmInfo->probCause = CL_ALARM_PROB_CAUSE_LOSS_OF_FRAME;
    clCorMoIdNameToMoIdGet(&moidName2,&(pAlarmInfo->moId));

    rc = clAlarmRaise(pAlarmInfo,&alarmHandle);
    CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Alarm Category : %d \n",pAlarmInfo->category ));
    CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Alarm severity: %d \n",pAlarmInfo->severity));

    rc = clAlarmClientResourceInfoGet(alarmHandle, &moId);
    if ( CL_OK != rc)
    {
        clOsalPrintf("Failed while asking the moid for the alarm handle [%d]. rc[0x%x] \n", alarmHandle, rc);
        return rc;
    }

    rc = clCorMoIdToMoIdNameGet(&moId, &moIdName);
    if(CL_OK != rc)
    {
        clOsalPrintf("Failed while getting the mOId name from moid . rc[0x%x]", rc) ;
        return rc;
    }

    clOsalPrintf("The MOID for the alarm handle is [%d] is [%s]\n", alarmHandle, moIdName.value);
	/**
	  * Raising alarm for :
	  * MOId -  /Chassis:0/GigeBlade:0/GigePort:0
	  * Category - CL_ALARM_CATEGORY_QUALITY_OF_SERVICE 
	  * Probable Cause - CL_ALARM_PROB_CAUSE_MULTIPLEXER_PROBLEM 
	  */
    CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Raising alarm for [%s] and the probable \
				cause [%d]", moidName2.value, CL_ALARM_PROB_CAUSE_MULTIPLEXER_PROBLEM));
    pAlarmInfo->probCause = CL_ALARM_PROB_CAUSE_MULTIPLEXER_PROBLEM;
    clCorMoIdNameToMoIdGet(&moidName2,&(pAlarmInfo->moId));
    rc = clAlarmRaise(pAlarmInfo,&alarmHandle);
    CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Alarm Category : %d \n",pAlarmInfo->category ));
    CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Alarm severity: %d \n",pAlarmInfo->severity));


	/**
	  * Clearing alarm for :
	  * MOId - /Chassis:0/GigeBlade:0/GigePort:0 
	  * Category - CL_ALARM_CATEGORY_QUALITY_OF_SERVICE
	  * Probable Cause - CL_ALARM_PROB_CAUSE_MULTIPLEXER_PROBLEM
	  */
    CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Clearing alarm for [%s] and the probable \
				cause [%d]", moidName.value, CL_ALARM_PROB_CAUSE_MULTIPLEXER_PROBLEM));
    pAlarmInfo->alarmState = CL_ALARM_STATE_CLEAR;
    clCorMoIdNameToMoIdGet(&moidName2,&(pAlarmInfo->moId));
    rc = clAlarmRaise(pAlarmInfo,&alarmHandle);
    CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Alarm Category : %d \n",pAlarmInfo->category ));
    CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Alarm severity: %d \n",pAlarmInfo->severity));

	/**
	  * Clearing alarm for :
	  * MOId - /Chassis:0/GigeBlade:0/GigePort:0 
	  * Category - CL_ALARM_CATEGORY_QUALITY_OF_SERVICE
	  * Probable Cause - CL_ALARM_PROB_CAUSE_LOSS_OF_FRAME
	  */
    CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Raising alarm for [%s] and the probable \
				cause [%d]", moidName.value, CL_ALARM_PROB_CAUSE_LOSS_OF_FRAME));
    pAlarmInfo->probCause = CL_ALARM_PROB_CAUSE_LOSS_OF_FRAME;
    rc = clAlarmRaise(pAlarmInfo,&alarmHandle);
    CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Alarm Category : %d \n",pAlarmInfo->category ));
    CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Alarm severity: %d \n",pAlarmInfo->severity));
    return rc;
}
ClParserPtrT clParserGet(ClParserPtrT xml, ...)
{
    /*return ezxml_get(xml, ...);*/
    clOsalPrintf("Not Implemanted ............\n");
    return NULL;
}
ClRcT
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
    idlClientInstall();
#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;
    if ( (rc = clComponentEventInit()) ) 
        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---
     */

	clOsalPrintf("Inside the Alarm Test App 1.............. ############### \n");
    /*
     * ---END_APPLICATION_CODE---
     */

    return rc;

errorexit:

    clprintf ("Component [%s] : PID [%d]. Initialization error [0x%x]\n",
              appName.value, mypid, rc);

    return rc;
}