static ClRcT
clLogSvrDsIdMapRecreate(ClUint32T  dsId,
                        ClAddrT    pBuffer,
                        ClUint32T  buffSize,
                        ClPtrT     pCookie)
{
    ClRcT            rc           = CL_OK;
    ClLogSvrEoDataT  *pSvrEoEntry = NULL;
    ClBufferHandleT  inMsg        = CL_HANDLE_INVALID_VALUE;

    CL_LOG_DEBUG_TRACE(("Enter"));

    CL_LOG_PARAM_CHK((NULL == pBuffer), CL_LOG_RC(CL_ERR_NULL_POINTER));
    CL_LOG_PARAM_CHK((CL_LOG_DSID_START != dsId),
                     CL_LOG_RC(CL_ERR_INVALID_PARAMETER));

    rc = clLogSvrEoEntryGet(&pSvrEoEntry, NULL);
    if( CL_OK != rc )
    {
        return rc;
    }

    rc = clBufferCreate(&inMsg);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferCreate(): rc[0x %x]", rc));
        return rc;
    }
    rc = clBufferNBytesWrite(inMsg, (ClUint8T *) pBuffer, buffSize);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferNBytesWrite(): rc[0x %x]", rc));
        CL_LOG_CLEANUP(clBufferDelete(&inMsg), CL_OK);
        return rc;
    }

    rc = clXdrUnmarshallClUint32T(inMsg, &pSvrEoEntry->nextDsId);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clXdrUnmarshallClUint32T(): rc[0x %x]\n", rc));
        CL_LOG_CLEANUP(clBufferDelete(&inMsg), CL_OK);
        return rc;
    }
    CL_LOG_DEBUG_VERBOSE(("DsIdCnt: %d", pSvrEoEntry->nextDsId));

    rc = clLogBitmapUnpack(inMsg, pSvrEoEntry->hDsIdMap);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clLogBitmapUnpack(): rc[0x %x]", rc));
        CL_LOG_CLEANUP(clBufferDelete(&inMsg), CL_OK);
        return rc;
    }
    CL_LOG_CLEANUP(clBufferDelete(&inMsg), CL_OK);

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT clCorAmfMoIdGet(const ClCharT *name,
                      ClAmsEntityTypeT type,
                      ClCorMOIdT *pMoId)
{
    ClAmsEntityT entity = {0};
    ClBufferHandleT msg = 0;
    ClRcT rc = CL_OK;
    ClVersionT version = {'B', 0x1, 0x1};
    ClCharT *data = NULL;
    ClUint32T dataLen = 0;
    ClCorObjectHandleT objHandle;

    if(!name || !pMoId) return CL_COR_SET_RC(CL_ERR_INVALID_PARAMETER);

    if(!mgmtHandle)
    {
        rc = clAmsMgmtInitialize(&mgmtHandle, NULL, &version);
        if(rc != CL_OK) return rc;
    }

    entity.type = type;
    clNameSet(&entity.name, name);
    ++entity.name.length;
    rc = clAmsMgmtEntityUserDataGetKey(mgmtHandle, &entity, &entity.name, &data, &dataLen);
    if(rc != CL_OK)
    {
        clLogError("FLT", "REPAIR", "Entity data get for [%s] returned [%#x]",
                   entity.name.value, rc);
        goto out_free;
    }
    rc = clBufferCreate(&msg);
    CL_ASSERT(rc == CL_OK);
    rc = clBufferNBytesWrite(msg, (ClUint8T*)data, dataLen);
    CL_ASSERT(rc == CL_OK);
    
    rc = VDECL_VER(clXdrUnmarshallClCorMOIdT, 4, 0, 0)(msg, pMoId);
    CL_ASSERT(rc == CL_OK);
    
    clBufferDelete(&msg);

    clLogNotice("COR", "AMF", "MOID for faulty entity [%s] ", entity.name.value);
    clCorMoIdShow(pMoId);
    
    /*
     * Validating moid
     */
    rc = clCorObjectHandleGet(pMoId, &objHandle);
    CL_ASSERT(rc == CL_OK);

    out_free:
    if(msg) clBufferDelete(&msg);
    if(data) clHeapFree(data);

    return rc;
}
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;
}
static ClRcT
clLogMasterFileEntryRecover(ClLogMasterEoDataT      *pMasterEoEntry,
                            ClCkptIOVectorElementT  *pIoVector,
                            ClUint32T               *pErrIndex)
{
    ClRcT                rc            = CL_OK;
    ClBufferHandleT      hFileEntryBuf = CL_HANDLE_INVALID_VALUE;
    ClVersionT version = {0};

    CL_LOG_DEBUG_TRACE(("Enter: size %lld", pIoVector->readSize));

    rc = clBufferCreate(&hFileEntryBuf);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferCreate(): rc[0x %x]", rc));
        return rc;
    }

    rc = clBufferNBytesWrite(hFileEntryBuf, (ClUint8T*) pIoVector->dataBuffer, pIoVector->readSize);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferNBytesWrite(): rc[0x %x]", rc));
        CL_LOG_CLEANUP(clBufferDelete(&hFileEntryBuf), CL_OK);
        return rc;
    }

    rc = clXdrUnmarshallClVersionT(hFileEntryBuf, &version);

    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clXdrUnmarshallClVersionT(): rc[%#x]", rc));
        CL_LOG_CLEANUP(clBufferDelete(&hFileEntryBuf), CL_OK);
        return rc;
    }

    switch(CL_VERSION_CODE(version.releaseCode, version.majorVersion, version.minorVersion))
    {
    case CL_VERSION_CODE(CL_RELEASE_VERSION, CL_MAJOR_VERSION, CL_MINOR_VERSION):
    {
        rc = fileEntryRecoverBaseVersion(pMasterEoEntry, hFileEntryBuf);
    }
    break;
    default:
        rc = CL_LOG_RC(CL_ERR_VERSION_MISMATCH);
        clLogError("FILE", "RECOVER", "Version [%d.%d.%d] unsupported",
                   version.releaseCode, version.majorVersion, version.minorVersion);
        break;
    }

    CL_LOG_CLEANUP(clBufferDelete(&hFileEntryBuf), CL_OK);

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogMasterCompData2BufferGet(ClLogCompDataT  *pCompData,
                              ClUint8T        **ppBuffer,
                              ClUint32T       *pDataSize)
{
    ClRcT            rc  = CL_OK;
    ClBufferHandleT  msg = CL_HANDLE_INVALID_VALUE;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clBufferCreate(&msg);
    if(CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferCreate(): rc[0x %x]", rc));
        return rc;
    }

    rc = VDECL_VER(clXdrMarshallClLogCompDataT, 4, 0, 0)(pCompData, msg, 0);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clLogMarshallClLogCompDataT(): rc[0x %x]", rc));
        CL_LOG_CLEANUP(clBufferDelete(&msg), CL_OK);
        return rc;
    }

    rc = clBufferLengthGet(msg, pDataSize);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferLengthGet(): rc[0x %x]", rc));
        CL_LOG_CLEANUP(clBufferDelete(&msg), CL_OK);
        return rc;
    }

    *ppBuffer = (ClUint8T*) clHeapCalloc(*pDataSize, sizeof(ClUint8T));
    if( NULL == *ppBuffer )
    {
        CL_LOG_DEBUG_ERROR(("clHeapCalloc()"));
        CL_LOG_CLEANUP(clBufferDelete(&msg), CL_OK);
        return CL_LOG_RC(CL_ERR_NO_MEMORY);
    }

    rc = clBufferNBytesRead(msg, *ppBuffer, pDataSize);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferNBytesRead(): rc[0x %x]", rc));
        clHeapFree(*ppBuffer);
        CL_LOG_CLEANUP(clBufferDelete(&msg), CL_OK);
        return rc;
    }
    CL_LOG_CLEANUP(clBufferDelete(&msg), CL_OK);

    CL_LOG_DEBUG_TRACE(("Exit"));
    return CL_OK;
}
ClRcT
clLogSODsIdMapRecreate(ClUint32T  dsId,
                       ClAddrT    pBuffer,
                       ClUint32T  size,
                           ClPtrT      cookie)
{
    ClRcT                   rc        = CL_OK;
    ClBufferHandleT        msg            = CL_HANDLE_INVALID_VALUE;
    ClLogSOEoDataT         *pSoEoEntry    = NULL; 
    ClLogSvrCommonEoDataT  *pCommonEoData = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    CL_LOG_PARAM_CHK((CL_LOG_SO_DSID_START != dsId),
                     CL_LOG_RC(CL_ERR_INVALID_PARAMETER));
    CL_LOG_PARAM_CHK((NULL == pBuffer), CL_LOG_RC(CL_ERR_NULL_POINTER));

    rc = clLogStreamOwnerEoEntryGet(&pSoEoEntry, &pCommonEoData);
    if( CL_OK != rc )
    {
        return rc;
    }    

    rc = clBufferCreate(&msg);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferCreate(): rc[0x %x]", rc));
        return rc;
    }
    rc = clBufferNBytesWrite(msg, (ClUint8T *) pBuffer, size); 
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferNBytesRead(): rc[0x %x]", rc));
        CL_LOG_CLEANUP(clBufferDelete(&msg), CL_OK);
        return rc;
    }

    rc = clXdrUnmarshallClUint32T(msg, &pSoEoEntry->dsIdCnt);
    if( CL_OK != rc )
    {
       CL_LOG_DEBUG_ERROR(("clXdrUnmarshallClUint32T(): rc[0x %x]", rc));
       CL_LOG_CLEANUP(clBufferDelete(&msg), CL_OK);
        return rc;
    }    
    CL_LOG_DEBUG_VERBOSE(("dsIdCnt : %d", pSoEoEntry->dsIdCnt));

    rc = clLogBitmapUnpack(msg, pSoEoEntry->hDsIdMap);

    CL_LOG_CLEANUP(clBufferDelete(&msg), CL_OK);

    CL_LOG_DEBUG_TRACE(("Exit: rc[0x %x]", rc));
    return rc;
}    
ClRcT
clLogMasterCompTableStateRecover(ClLogMasterEoDataT  *pMasterEoEntry,
                                 ClUint8T            *pBuffer,
                                 ClUint32T           dataSize)
{
    ClRcT            rc       = CL_OK;
    ClBufferHandleT  msg      = CL_HANDLE_INVALID_VALUE;
    ClUint32T versionCode = 0;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clBufferCreate(&msg);
    if(CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferCreate(): rc[0x %x]", rc));
        return rc;
    }
    rc = clBufferNBytesWrite(msg, pBuffer, dataSize);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferNBytesWrite(): rc[0x %x]", rc));
        CL_LOG_CLEANUP(clBufferDelete(&msg), CL_OK);
        return rc;
    }

    rc = clXdrUnmarshallClUint32T(msg, &versionCode);
    if( CL_OK != rc)
    {
        CL_LOG_DEBUG_ERROR(("clXdrUnmarshallClUint32T(): rc[%#x]", rc));
        CL_LOG_CLEANUP(clBufferDelete(&msg), CL_OK);
        return rc;
    }
    switch(versionCode)
    {

    case CL_VERSION_CODE(CL_RELEASE_VERSION, CL_MAJOR_VERSION, CL_MINOR_VERSION):
    {
        rc = compTableStateRecoverBaseVersion(msg);
    }
    break;

    default:
        clLogError("COMP", "TBL-RECOVER", "Version [%d.%d.%d] is not supported",
                   CL_VERSION_RELEASE(versionCode), CL_VERSION_MAJOR(versionCode),
                   CL_VERSION_MINOR(versionCode));
        rc = CL_LOG_RC(CL_ERR_VERSION_MISMATCH);
    }

    clBufferDelete(&msg);

    return rc;
}
ClRcT
clNameContextCkptDeserializer(ClUint32T   dsId,
                              ClAddrT     pBuffer,
                              ClUint32T   size,
                              ClPtrT cookie)
{
    ClRcT           rc    = CL_OK;
    ClBufferHandleT inMsg = 0;

    CL_NAME_DEBUG_TRACE(("Enter"));
    if( CL_NAME_CONTEXT_GBL_DSID != dsId )
    {        
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, 
                ("dsId is not proper\n"));
        return CL_NS_RC(CL_ERR_INVALID_PARAMETER);
    }    
    if( NULL == pBuffer )
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR,
                 ("Passed Value is NULL"));
        return CL_NS_RC(CL_ERR_NULL_POINTER);
    }    
    rc = clBufferCreate(&inMsg);
    if( CL_OK != rc )
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, 
                  ("clBufferCreate() : rc[0x %x]", rc));
        return rc;
    }    
    rc = clBufferNBytesWrite(inMsg, (ClUint8T *)pBuffer, size); 
    if( CL_OK != rc )
    {
        clBufferDelete(&inMsg);
        CL_DEBUG_PRINT(CL_DEBUG_ERROR,
                ("clBufferNBytesWrite(): rc[0x %x]", rc));
        return rc;
    }    
    rc = clNameContextCkptNameUnpack(inMsg);
    if( CL_OK != rc )
    {
        clBufferDelete(&inMsg);
        return rc;
    }    
    if( CL_OK != (rc = clBufferDelete(&inMsg)) ) 
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR,
                ("clBufferDelete(): rc[0x %x]", rc));
    }    

    CL_NAME_DEBUG_TRACE(("Exit"));
    return rc;
}    
ClRcT clNodeCacheLeaderIocSend(ClIocNodeAddressT currentLeader, ClIocAddressT *dstAddr)
{
    ClRcT rc = CL_OK;
    ClIocSendOptionT sendOption = {CL_IOC_HIGH_PRIORITY,0,0,CL_IOC_PERSISTENT_MSG,200 };
    ClIocPhysicalAddressT compAddr = { CL_IOC_BROADCAST_ADDRESS,  CL_IOC_CPM_PORT };
    ClTimerTimeOutT delay = {  0,  200 };
    ClUint32T i = 0;
    ClBufferHandleT message = 0;
    ClEoExecutionObjT *eoObj = NULL;
    ClIocNotificationT notification;
    
    memset(&notification,0,sizeof(ClIocNotificationT));
    notification.protoVersion = htonl(CL_IOC_NOTIFICATION_VERSION);
    notification.id = (ClIocNotificationIdT) htonl(CL_IOC_NODE_ARRIVAL_NOTIFICATION);
    notification.nodeAddress.iocPhyAddress.nodeAddress = htonl(clIocLocalAddressGet());
    notification.nodeAddress.iocPhyAddress.portId = htonl(CL_IOC_GMS_PORT);

    clEoMyEoObjectGet(&eoObj);

    while(!eoObj && i++ <= 3)
    {
        clEoMyEoObjectGet(&eoObj);
        clOsalTaskDelay(delay);
    }

    if(!eoObj)
    {
        clLogWarning("CAP", "ARP", "Could not send current leader update since EO still uninitialized.");
        return CL_ERR_NOT_INITIALIZED;
    }

    clBufferCreate(&message);

    currentLeader = htonl(currentLeader);
    rc = clBufferNBytesWrite(message, (ClUint8T *)&notification, sizeof(ClIocNotificationT));
    rc |= clBufferNBytesWrite(message, (ClUint8T*)&currentLeader, sizeof(currentLeader));
    if (rc != CL_OK)
    {
        clLogError("CAP", "ARP", "clBufferNBytesWrite failed with rc = %#x", rc);
        clBufferDelete(&message);
        return rc;
    }

    rc = clIocSend(eoObj->commObj, message, CL_IOC_PORT_NOTIFICATION_PROTO, dstAddr, &sendOption);

    clBufferDelete(&message);

    return rc;

}
/**
 * Internal function to unpack saved state of a transaction
 * from checkpoint
 */
static ClRcT _clTxnServiceCkptTxnUnpack(
    CL_IN   ClUint32T   dataSetId,
    CL_IN   ClAddrT     pData,
    CL_IN   ClUint32T   dataLen,
    CL_IN   ClPtrT      cookie)
{
    ClRcT                   rc = CL_OK;
    ClBufferHandleT  txnStateBuf;
    ClTxnDefnT              *pTxnDefn;

    CL_FUNC_ENTER();

    CL_DEBUG_PRINT(CL_DEBUG_TRACE, ("To unpack data-set 0x%x\n", dataSetId));
    rc = clBufferCreate(&txnStateBuf);

    if (CL_OK == rc)
    {
        rc = clBufferNBytesWrite(txnStateBuf, (ClUint8T *)pData, dataLen);

        if (CL_OK == rc)
        {
            rc = clTxnStreamTxnCfgInfoUnpack(txnStateBuf, &pTxnDefn);
        }

        if ( (CL_OK == rc) &&
                ((pTxnDefn->serverTxnId.txnId + CL_TXN_CKPT_TXN_DATA_SET_ID_OFFSET) == dataSetId) )
        {
            /* Add this definition into txnDefnDb */
            rc = clTxnRecoverySessionUpdate (pTxnDefn);
        }
        else
        {
            if (CL_OK == rc)
                rc = CL_ERR_INVALID_PARAMETER;
        }

        rc = clBufferDelete(&txnStateBuf);

    }
    if (CL_OK != rc)
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR,
                       ("Failed to extract transaction definition from data-set[0x%x], rc:0x%x", dataSetId, rc));
        rc = CL_GET_ERROR_CODE(rc);
    }

    CL_FUNC_EXIT();
    return (rc);
}
static ClRcT
clLogSvrStreamEntryRecreate(ClUint32T  dsId,
                            ClAddrT    pBuffer,
                            ClUint32T  buffSize,
                            ClPtrT     cookie)
{

    ClRcT                  rc                 = CL_OK;
    ClLogSvrEoDataT        *pSvrEoEntry       = NULL;
    ClBufferHandleT        inMsg              = CL_HANDLE_INVALID_VALUE;
    ClLogSvrCommonEoDataT  *pSvrCommonEoEntry = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    CL_LOG_PARAM_CHK((NULL == pBuffer), CL_LOG_RC(CL_ERR_NULL_POINTER));

    rc = clLogSvrEoEntryGet(&pSvrEoEntry, &pSvrCommonEoEntry);
    if( CL_OK != rc )
    {
        return rc;
    }

    rc = clBufferCreate(&inMsg);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferCreate(): rc[0x %x]", rc));
        return rc;
    }
    rc = clBufferNBytesWrite(inMsg, (ClUint8T *) pBuffer, buffSize);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferNBytesWrite(): rc[0x %x]", rc));
        CL_LOG_CLEANUP(clBufferDelete(&inMsg), CL_OK);
        return rc;
    }

    rc = clLogSvrStreamEntryUnpackNAdd(pSvrEoEntry, pSvrCommonEoEntry, inMsg, dsId);
    if( CL_OK != rc )
    {
        CL_LOG_CLEANUP(clBufferDelete(&inMsg), CL_OK);
        return rc;
    }

    CL_LOG_CLEANUP(clBufferDelete(&inMsg), CL_OK);

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogClntStreamListUnpack(ClUint32T         numStreams,
                          ClUint32T         buffLen,
                          ClUint8T          *pBuffer,
                          ClLogStreamInfoT  **ppLogStreams)
{
    ClRcT            rc  = CL_OK;
    ClBufferHandleT  msg = CL_HANDLE_INVALID_VALUE;

    CL_LOG_DEBUG_TRACE(("Enter"));

    *ppLogStreams = clHeapCalloc(numStreams, sizeof(ClLogStreamInfoT));
    if( NULL == *ppLogStreams )
    {
        CL_LOG_DEBUG_ERROR(("clHeapCalloc()"));
        return CL_LOG_RC(CL_ERR_NO_MEMORY);
    }

    rc = clBufferCreate(&msg);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferCreate(): rc[0x %x]", rc));
        clHeapFree(*ppLogStreams);
        return rc;
    }
    rc = clBufferNBytesWrite(msg, pBuffer, buffLen);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferNBytesWrite(): rc[0x %x]", rc));
        CL_LOG_CLEANUP(clBufferDelete(&msg), CL_OK);
        clHeapFree(*ppLogStreams);
        return rc;
    }

    rc = clLogClntStreamListGet(msg, *ppLogStreams);
    if( CL_OK != rc )
    {
        CL_LOG_CLEANUP(clBufferDelete(&msg), CL_OK);
        clHeapFree(*ppLogStreams);
        return rc;
    }

    CL_LOG_CLEANUP(clBufferDelete(&msg), CL_OK);
   
    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
/*
 * Function - clLogStreamOwnerLocalCheckpoint()
 * - Do Local Checkpointing.
 * - If the dataset is not yet created, create the dataSet
 * - Write onto it.
 */
ClRcT
clLogStreamOwnerLocalCheckpoint(ClLogSOEoDataT         *pSoEoEntry,
                                SaNameT                *pStreamName,
                                SaNameT                *pStreamScopeNode,
                                ClLogStreamOwnerDataT  *pStreamOwnerData)
{
    ClRcT                  rc              = CL_OK;
    ClBufferHandleT     msg               = CL_HANDLE_INVALID_VALUE;
    ClLogSvrCommonEoDataT  *pCommonEoData = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogStreamOwnerEoEntryGet(NULL, &pCommonEoData);
    if( CL_OK != rc )
    {
        return rc;
    }    
    rc = clBufferCreate(&msg);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferCreate(): rc[0x %x]", rc));
        return rc;
    }    
    rc = clLogStreamOwnerEntryPack(pStreamName, pStreamScopeNode, 
                                   pStreamOwnerData, msg);
    if( CL_OK != rc )
    {
        CL_LOG_CLEANUP(clBufferDelete(&msg), CL_OK);
        return rc;
    }    
    rc = clCkptLibraryCkptDataSetWrite(pCommonEoData->hLibCkpt,
                                        (SaNameT *) &gSOLocalCkptName, 
                                        pStreamOwnerData->dsId,
                                        msg);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(( "clCkptLibraryCkptDataSetWrite(): rc[0x %x]", rc));
    }    
    CL_LOG_CLEANUP(clBufferDelete(&msg), CL_OK);
        
    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}    
/**
 * Internal Function - extracts transaction-service state from checkpoint data-set
 */
static ClRcT _clTxnServiceCkptAppStateUnpack(
    CL_IN   ClUint32T   dataSetId,
    CL_IN   ClAddrT     pData,
    CL_IN   ClUint32T   dataLen,
    CL_IN   ClPtrT      cookie)
{
    ClRcT                   rc = CL_OK;
    ClBufferHandleT  txnStateMsgBuf;
    ClUint32T               txnIdCounter;

    CL_FUNC_ENTER();

    CL_DEBUG_PRINT(CL_DEBUG_TRACE, ("To restore state of transaction-service\n"));

    rc = clBufferCreate(&txnStateMsgBuf);
    if (CL_OK == rc)
    {
        rc = clBufferNBytesWrite(txnStateMsgBuf, (ClUint8T *) pData, dataLen);

        if (CL_OK == rc)
        {
            rc = clXdrUnmarshallClUint32T(txnStateMsgBuf, &txnIdCounter);
        }

        if (CL_OK == rc)
        {
            CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Updating txnId Counter to 0x%x", txnIdCounter));
            clTxnServiceCfg->txnIdCounter = txnIdCounter;
        }

        if (CL_OK != rc)
        {
            CL_DEBUG_PRINT(CL_DEBUG_ERROR,
                           ("Failed to restore transaction service state. Could result in inconsistent operation. rc:0x%x", rc));
            rc = CL_GET_ERROR_CODE(rc);
        }

        rc = clBufferDelete(&txnStateMsgBuf);

    }
    CL_FUNC_EXIT();
    return (rc);
}
static ClRcT amsMgmtCCBBatchBufferInitialize(ClAmsMgmtCCBBatchT *batch)
{
    ClRcT rc = CL_OK;

    if(batch->buffer)
    {
        rc |= clBufferDelete(&batch->buffer);
        if(rc != CL_OK)
            goto out;
        batch->buffer = 0;
    }
    rc |= clBufferCreate(&batch->buffer);
    if(rc != CL_OK)
        goto out;
    batch->items = 0;
    batch->version = CL_VERSION_CURRENT;
    clNodeCacheMinVersionGet(NULL, &batch->version);
    rc = clXdrMarshallClUint32T(&batch->version, batch->buffer, 0);
    if(rc != CL_OK)
    {
        goto out_free;
    }
    rc = clBufferWriteOffsetGet(batch->buffer, &batch->itemsOffset);
    if(rc != CL_OK)
    {
        goto out_free;
    }
    rc = clXdrMarshallClUint32T(&batch->items, batch->buffer, 0);
    if(rc != CL_OK)
    {
        goto out_free;
    }
    goto out;

    out_free:
    clBufferDelete(&batch->buffer);
    batch->buffer = 0;
 
    out:
    return rc;
}
ClRcT
clLogSOStreamEntryRecreate(ClUint32T  dsId,
                           ClAddrT    pBuffer,
                           ClUint32T  size,
                           ClPtrT     cookie)
{
    ClRcT                  rc              = CL_OK;
    ClBufferHandleT        msg            = CL_HANDLE_INVALID_VALUE;
    ClLogSvrCommonEoDataT  *pCommonEoData = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogStreamOwnerEoEntryGet(NULL, &pCommonEoData);
    if( CL_OK != rc )
    {
        return rc;
    }    

    rc = clBufferCreate(&msg);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferCreate()"));
        return rc;
    }    
    rc = clBufferNBytesWrite(msg, (ClUint8T *) pBuffer, size);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBufferNBytesWrite(): rc[0x %x]", rc));
        clBufferDelete(&msg);
        return rc;
    }    
    rc = clLogSOStreamEntryUnpackNAdd(pCommonEoData, msg);

    CL_LOG_CLEANUP(clBufferDelete(&msg), CL_OK);

    if(CL_GET_ERROR_CODE(rc) == CL_ERR_DUPLICATE)
        rc = CL_OK;

    CL_LOG_DEBUG_TRACE(("Exit: rc[0x %x]", rc));
    return rc;
}
/**
 * Deserializer function for transaction state
 */
static ClRcT _clTxnServiceCkptTxnStateUnpack(
    CL_IN   ClUint32T   dataSetId,
    CL_IN   ClAddrT     pData,
    CL_IN   ClUint32T   dataLen,
    CL_IN   ClPtrT      cookie)
{
    ClRcT                       rc  = CL_OK;
    ClBufferHandleT      msgHandle;

    CL_FUNC_ENTER();

    /*
       - If, from the restored txn-log, the txn is in intermediate state,
         add it to pending-recovery-list
         else, discard
     */
    rc = clBufferCreate (&msgHandle);

    if (CL_OK == rc)
    {
        rc = clBufferNBytesWrite(msgHandle, (ClUint8T *)pData, dataLen);

        if (CL_OK == rc)
        {
            rc = clTxnRecoveryLogUnpack(msgHandle);
        }

    }
    if (CL_OK != rc)
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Failed to extract transaction logs from ckpt. rc:0x%x", rc));
    }

    CL_FUNC_EXIT();
    return (rc);
}
ClRcT corAmfObjectCreate(ClUint32T entityId, ClAmsEntityT *entity, ClCorMOIdT *pMoId)
{
    ClRcT rc = CL_OK;
    ClBufferHandleT msg = 0;
    ClUint32T moIdBufferLen = 0;
    ClUint8T *moIdBuffer = NULL;
    ClCorMOIdT tempMoId;
    ClCorMOServiceIdT svcId = CL_COR_SVC_ID_PROVISIONING_MANAGEMENT;
    ClCorAttributeValueListT attrValueList = {0};

    if(!gClAmfMibLoaded) 
        svcId = CL_COR_SVC_ID_AMF_MANAGEMENT;

    /*
     *Faster than a clone
     */
    memcpy(&tempMoId, pMoId, sizeof(tempMoId));

    rc = clCorObjectCreate(&sessionId, &tempMoId, NULL);
    if(rc != CL_OK)
    {
        clLogError("COR", "AMF", "COR MO object create for entity [%s] returned [%#x]",
                   entity->name.value, rc);
        goto out;
    }

    rc = clCorMoIdServiceSet(&tempMoId, svcId);
    CL_ASSERT(rc == CL_OK);

    rc = corAmfEntityAttributeListGet(&entityId, entity, NULL, &attrValueList);
    if(rc != CL_OK) goto out;
    
    rc = clCorObjectCreateAndSet(&sessionId, &tempMoId, &attrValueList, NULL);
    if(rc != CL_OK)
    {
        clLogError("COR", "AMF", "COR MSO object create for entity [%s] returned [%#x]",
                   entity->name.value, rc);
        goto out;
    }

    rc = clBufferCreate(&msg);
    CL_ASSERT(rc == CL_OK);

    rc = VDECL_VER(clXdrMarshallClCorMOIdT, 4, 0, 0)((ClUint8T*)&tempMoId, msg, 0);
    CL_ASSERT(rc == CL_OK);

    rc = clBufferLengthGet(msg, &moIdBufferLen);
    CL_ASSERT(rc == CL_OK);

    rc = clBufferFlatten(msg, &moIdBuffer);
    CL_ASSERT(rc == CL_OK);

    /*
     * Now store this moid buffer into the entity user area for the entity key.
     */
    rc = clAmsMgmtEntityUserDataSetKey(mgmtHandle, entity, &entity->name, 
                                       (ClCharT*)moIdBuffer, moIdBufferLen);
    if(rc != CL_OK)
    {
        clLogError("COR", "AMF", "Entity user data set for [%s] returned [%#x]",
                   entity->name.value, rc);
        goto out;
    }

    out:
    if(attrValueList.pAttributeValue) clHeapFree(attrValueList.pAttributeValue);
    if(moIdBuffer) clHeapFree(moIdBuffer);
    if(msg) clBufferDelete(&msg);
    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 _clCpmComponentListAll(ClInt32T argc, ClCharT **retStr)
{
    ClCntNodeHandleT hNode = 0;
    ClCpmComponentT *comp = NULL;
    ClUint32T rc = CL_OK, count;
    ClCpmEOListNodeT *eoList = NULL;
    ClCharT state[10] = "\0";
    ClCharT status[10] = "\0";
    ClCharT tempStr[256];
    ClCharT *tmpStr = NULL;
    ClBufferHandleT message;
    ClCharT cpmCompName[CL_MAX_NAME_LENGTH] = {0};
    
    rc = clBufferCreate(&message);
    CL_CPM_CHECK(CL_DEBUG_ERROR, ("Unable to create message %x\n", rc), rc);

    if (argc != ONE_ARGUMENT)
    {
        rc = clBufferNBytesWrite(message, (ClUint8T *) STR_AND_SIZE("Usage: compList"));
        CL_CPM_CHECK(CL_DEBUG_ERROR, ("Unable to write message %x\n", rc), rc);
        rc = CL_CPM_RC(CL_ERR_INVALID_PARAMETER);
        goto done;
    }

    count = gpClCpm->noOfComponent;
    snprintf(cpmCompName,
             CL_MAX_NAME_LENGTH-1,
             "%s_%s",
             CL_CPM_COMPONENT_NAME,
             gpClCpm->pCpmLocalInfo->nodeName);

    rc = clCntFirstNodeGet(gpClCpm->compTable, &hNode);
    CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to Get First component \n"), rc);

    rc = clBufferNBytesWrite(message, (ClUint8T *) STR_AND_SIZE("################### List Of Components ########################\n"));
    CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to write message \n"), rc);

    rc = clCntNodeUserDataGet(gpClCpm->compTable, hNode,(ClCntDataHandleT *) &comp);
    CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to Get Node  Data \n"), rc);

    rc = clBufferNBytesWrite(message, STR_AND_SIZE("        CompName              | compId  |  eoPort  |   PID   | RestartCount  | PresenceState\n"));
    CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to write message \n"), rc);

    rc = clBufferNBytesWrite(message, STR_AND_SIZE("\t\t     ID |     Port |     Name  |    Health |Recv Threads \n"));   
    CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to write message \n"), rc);

    rc = clBufferNBytesWrite(message, STR_AND_SIZE("========================================================================================\n"));    
    CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to write message \n"), rc);

    while (count)
    {
        
        if (strcmp(comp->compConfig->compName, cpmCompName)!=0)  /* Skip if it is the CPM component */
        {
            
            eoList = comp->eoHandle;

            int len = sprintf(tempStr, "%30s| 0x%x | 0x%x |%8d |%14d |%15s\n",
                              comp->compConfig->compName, comp->compId,
                              comp->eoPort, comp->processId, comp->compRestartCount,
                              _cpmPresenceStateNameGet(comp->compPresenceState));
            
            if (comp->compConfig->compProperty != CL_AMS_COMP_PROPERTY_SA_AWARE)
            {

                if(!eoList || !eoList->eoptr)
                {
                    len += snprintf(tempStr + len, sizeof(tempStr) - len, 
                                    "\t\t   0x%x  |  0x%x   |%10s |%10s |%04d \n",
                                    0, 0, "-", "-", 0);
                }
            }

            rc = clBufferNBytesWrite(message, (ClUint8T *) tempStr,len);
            CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to write message \n"), rc);

            while (eoList != NULL && eoList->eoptr != NULL)
            {
                compMgrStateStatusGet(eoList->status, eoList->eoptr->state, status, sizeof(status),
                                      state, sizeof(state));
                int noOfThreads = (eoList->eoptr->appType == CL_EO_USE_THREAD_FOR_RECV) ? eoList->eoptr->noOfThreads + 1: eoList->eoptr->noOfThreads;

                int len = sprintf(tempStr, "\t\t   0x%llx  |  0x%x   |%10s |%10s |%04d \n",
                                  eoList->eoptr->eoID, eoList->eoptr->eoPort,
                                  eoList->eoptr->name, status,
                                  noOfThreads);
                rc = clBufferNBytesWrite(message, (ClUint8T *) tempStr, len);
                CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to write message \n"), rc);
                eoList = eoList->pNext;
            }
        
            rc = clBufferNBytesWrite(message, STR_AND_SIZE("-----------------------------------------------------------------------------------------\n"));
            CL_CPM_CHECK(CL_DEBUG_ERROR, ("\n Unable to write message \n"), rc);
        
        }
        
        count--;
        if (count)
        {
            rc = clCntNextNodeGet(gpClCpm->compTable, hNode, &hNode);
            CL_CPM_CHECK(CL_DEBUG_ERROR, ("Unable to Get Node  Data %x\n", rc), rc);

            rc = clCntNodeUserDataGet(gpClCpm->compTable, hNode, (ClCntDataHandleT *) &comp);
            CL_CPM_CHECK(CL_DEBUG_ERROR, ("Unable to Get Node user Data %x\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 
     */
    rc = clBufferNBytesWrite(message, (ClUint8T *) "\0", 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, ("Unable to flatten the message \n"), rc);

    *retStr = tmpStr;
    
    clBufferDelete(&message);
    return rc;

failure:
    clBufferDelete(&message);
    return rc;
}
ClRcT clCpmExecutionObjectListShow(ClInt32T argc,
                                   ClIocNodeAddressT compAddr,
                                   ClUint32T flag,
                                   ClEoIdT eoId,
                                   ClCharT **retStr)
{
    /*
     * ClCpmEOListNodeT* ptr = gpClCpm->eoList;
     */
    ClCpmEOListNodeT *ptr = NULL;
    ClCharT name[32] = "\0";
    ClCharT state[10] = "\0";
    ClCharT status[10] = "\0";
    ClUint32T compCount = 0;
    ClCntNodeHandleT hNode = 0;
    ClCpmComponentT *comp = NULL;
    ClRcT rc = CL_OK;
    ClCharT tempStr[256];
    ClCharT *tmpStr = NULL;
    ClBufferHandleT message = 0;

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

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


    sprintf(tempStr,
            "\n   ID  |   Port   |   Name    |   Health   |   EO State   | Recv Threads ");
    rc = clBufferNBytesWrite(message, (ClUint8T *) tempStr,
                                    strlen(tempStr));
    CL_CPM_CHECK(CL_DEBUG_ERROR, ("Unable to write message %x\n", rc), rc);

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

    /*
     * take the semaphore 
     */
    if ((rc = clOsalMutexLock(gpClCpm->eoListMutex)) != CL_OK)
        CL_DEBUG_PRINT(CL_DEBUG_ERROR,
                       ("Could not get Lock successfully------\n"));

    rc = clCntFirstNodeGet(gpClCpm->compTable, &hNode);
    CL_CPM_LOCK_CHECK(CL_DEBUG_ERROR, ("Unable to Get First component \n"), rc);

    rc = clCntNodeUserDataGet(gpClCpm->compTable, hNode,
                              (ClCntDataHandleT *) &comp);
    CL_CPM_LOCK_CHECK(CL_DEBUG_ERROR, ("Unable to Get Node  Data \n"), rc);

    compCount = gpClCpm->noOfComponent;
    while (compCount != 0)
    {
        ptr = comp->eoHandle;

        if (flag == 0)
        {
            while (ptr != NULL && ptr->eoptr != NULL)
            {
                strcpy(name, ptr->eoptr->name);
                /*
                 * Obtain the state and status in string format 
                 */
                compMgrStateStatusGet(ptr->status, ptr->eoptr->state, status, sizeof(status),
                                      state, sizeof(state));
                if (ptr->eoptr->appType == CL_EO_USE_THREAD_FOR_RECV)
                    sprintf(tempStr, "\n 0x%llx| 0x%x | %10s | %10s | %10s | %04d ",
                            ptr->eoptr->eoID, ptr->eoptr->eoPort, name, status,
                            state, (ptr->eoptr->noOfThreads + 1));
                else
                    sprintf(tempStr, "\n 0x%llx| 0x%x | %10s | %10s | %10s | %04d ",
                            ptr->eoptr->eoID, ptr->eoptr->eoPort, name, status,
                            state, ptr->eoptr->noOfThreads);
                rc = clBufferNBytesWrite(message, (ClUint8T *) tempStr,
                                                strlen(tempStr));
                CL_CPM_LOCK_CHECK(CL_DEBUG_ERROR,
                                  ("\n Unable to write message \n"), rc);
                ptr = ptr->pNext;
            }
        }
        else
        {
            while (ptr != NULL && ptr->eoptr != NULL)
            {
                if (ptr->eoptr->eoID == eoId)
                {
                    /*
                     * obtain the state and status in string format 
                     */
                    compMgrStateStatusGet(ptr->status, ptr->eoptr->state,
                                          status, sizeof(status), state, sizeof(state));
                    strcpy(name, ptr->eoptr->name);

                    if (ptr->eoptr->appType == CL_EO_USE_THREAD_FOR_RECV)
                        sprintf(tempStr, "\n 0x%llx| 0x%x | %10s | %10s | %10s | %04d | ",
                                ptr->eoptr->eoID, ptr->eoptr->eoPort, name,
                                status, state, ptr->eoptr->noOfThreads + 1);
                    else
                        sprintf(tempStr, "\n 0x%llx| 0x%x | %10s | %10s | %10s | %04d | ",
                                ptr->eoptr->eoID, ptr->eoptr->eoPort, name,
                                status, state, ptr->eoptr->noOfThreads);
                    rc = clBufferNBytesWrite(message,
                                                    (ClUint8T *) tempStr,
                                                    strlen(tempStr));
                    CL_CPM_LOCK_CHECK(CL_DEBUG_ERROR,
                                      ("\n Unable to write message \n"), rc);
                    break;
                }
                ptr = ptr->pNext;
            }
#if 0
            if (ptr == NULL)
                CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("EOID not found\n"));
#endif
        }
        compCount--;
        if (compCount)
        {
            rc = clCntNextNodeGet(gpClCpm->compTable, hNode, &hNode);
            CL_CPM_LOCK_CHECK(CL_DEBUG_ERROR,
                              ("\n Unable to Get Node  Data \n"), rc);
            rc = clCntNodeUserDataGet(gpClCpm->compTable, hNode,
                                      (ClCntDataHandleT *) &comp);
            CL_CPM_LOCK_CHECK(CL_DEBUG_ERROR,
                              ("\n Unable to Get Node  Data \n"), rc);
        }
    }
    /*
     * Release the semaphore 
     */
    rc = clOsalMutexUnlock(gpClCpm->eoListMutex);
    CL_CPM_CHECK(CL_DEBUG_ERROR,
                 ("COMP_MGR: Could not UnLock successfully------\n"), 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);

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

    *retStr = tmpStr;
    
    clBufferDelete(&message);

    return (CL_OK);

  withlock:
    /*
     * Release the semaphore 
     */
    rc = clOsalMutexUnlock(gpClCpm->eoListMutex);
    CL_CPM_CHECK(CL_DEBUG_ERROR,
                 ("COMP_MGR: Could not UnLock successfully------\n"), rc);
  failure:
    clBufferDelete(&message);
    return rc;
}
ClRcT _ckptClientInfoGetClientSync_6_0_0(CL_IN ClIdlHandleT handle, CL_IN ClHandleT ckptHdl, CL_OUT ClCkptClientInfoListT_4_0_0* pClientInfoList)
{
    ClRcT rc = CL_OK;
    ClVersionT funcVer = {6, 0, 0};
    ClUint32T funcNo = CL_EO_GET_FULL_FN_NUM(CL_EO_NATIVE_COMPONENT_TABLE_ID, 51);
    ClBufferHandleT inMsgHdl = 0;
    ClBufferHandleT outMsgHdl = 0;
    ClIocAddressT address = {{0}};
    ClIdlHandleObjT* pHandleObj = NULL;
    ClUint32T tempFlags = 0;

    rc = clHandleCheckout(gIdlClnt.idlDbHdl,handle,(void **)&pHandleObj);
    if( rc != CL_OK )
    {
        return rc ;
    }
    if (CL_IDL_ADDRESSTYPE_IOC == pHandleObj->address.addressType)
    {
        address = pHandleObj->address.address.iocAddress;
    }
    else if (CL_IDL_ADDRESSTYPE_NAME == pHandleObj->address.addressType)
    {
        rc = clNameToObjectReferenceGet(&(pHandleObj->address.address.nameAddress.name),
                                        pHandleObj->address.address.nameAddress.attrCount,
                                        pHandleObj->address.address.nameAddress.attr,
                                        pHandleObj->address.address.nameAddress.contextCookie,
                                        (ClUint64T*)&address);
        if (CL_OK != rc)
        {
            return rc;
        }
    }
    else
    {
        return CL_IDL_RC(CL_ERR_INVALID_PARAMETER);
    }

    rc = clBufferCreate(&inMsgHdl);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrMarshallClHandleT(&(ckptHdl), inMsgHdl, 0);
    if (CL_OK != rc)
    {
        return rc;
    }


    rc = clBufferCreate(&outMsgHdl);
    if (CL_OK != rc)
    {
        return rc;
    }

    tempFlags |= pHandleObj->flags |
                 (CL_RMD_CALL_NON_PERSISTENT | CL_RMD_CALL_NEED_REPLY);
    tempFlags &= ~CL_RMD_CALL_ASYNC;

    rc = clRmdWithMsgVer(address, &funcVer, funcNo, inMsgHdl, outMsgHdl, tempFlags, &(pHandleObj->options), NULL);
    if(CL_OK != rc)
    {
        clBufferDelete(&outMsgHdl);
    return rc;
    }


    rc = clXdrUnmarshallClCkptClientInfoListT_4_0_0( outMsgHdl, pClientInfoList);
    if (CL_OK != rc)
    {
        return rc;
    }

    clBufferDelete(&outMsgHdl);
    
    rc = clHandleCheckin(gIdlClnt.idlDbHdl,handle);
    return rc;
}
ClRcT clCkptDeputyMasterInfoSyncupClientSync_4_0_0(CL_IN ClIdlHandleT handle, CL_INOUT ClVersionT* pVersion, CL_OUT ClUint32T* numOfCkpts, CL_OUT CkptXlationDBEntryT_4_0_0** pXlationInfo, CL_OUT CkptMasterDBInfoIDLT_4_0_0* pMasterInfo, CL_OUT ClUint32T* mastHdlCount, CL_OUT CkptMasterDBEntryIDLT_4_0_0** pMasterDBInfo, CL_OUT ClUint32T* peerCount, CL_OUT CkptPeerListInfoT_4_0_0** pPeerListInfo, CL_OUT ClUint32T* clientHdlCount, CL_OUT CkptMasterDBClientInfoT_4_0_0** pClientDBInfo)
{
    ClRcT rc = CL_OK;
    ClVersionT funcVer = {4, 0, 0};
    ClUint32T funcNo = CL_EO_GET_FULL_FN_NUM(CL_EO_NATIVE_COMPONENT_TABLE_ID, 18);
    ClBufferHandleT inMsgHdl = 0;
    ClBufferHandleT outMsgHdl = 0;
    ClIocAddressT address = {{0}};
    ClIdlHandleObjT* pHandleObj = NULL;
    ClUint32T tempFlags = 0;

    rc = clHandleCheckout(gIdlClnt.idlDbHdl,handle,(void **)&pHandleObj);
    if( rc != CL_OK )
    {
        return rc ;
    }
    if (CL_IDL_ADDRESSTYPE_IOC == pHandleObj->address.addressType)
    {
        address = pHandleObj->address.address.iocAddress;
    }
    else if (CL_IDL_ADDRESSTYPE_NAME == pHandleObj->address.addressType)
    {
        rc = clNameToObjectReferenceGet(&(pHandleObj->address.address.nameAddress.name),
                                        pHandleObj->address.address.nameAddress.attrCount,
                                        pHandleObj->address.address.nameAddress.attr,
                                        pHandleObj->address.address.nameAddress.contextCookie,
                                        (ClUint64T*)&address);
        if (CL_OK != rc)
        {
            return rc;
        }
    }
    else
    {
        return CL_IDL_RC(CL_ERR_INVALID_PARAMETER);
    }

    rc = clBufferCreate(&inMsgHdl);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrMarshallClVersionT(pVersion, inMsgHdl, 1);
    if (CL_OK != rc)
    {
        return rc;
    }


    rc = clBufferCreate(&outMsgHdl);
    if (CL_OK != rc)
    {
        return rc;
    }

    tempFlags |= pHandleObj->flags |
                 (CL_RMD_CALL_NON_PERSISTENT | CL_RMD_CALL_NEED_REPLY);
    tempFlags &= ~CL_RMD_CALL_ASYNC;

    rc = clRmdWithMsgVer(address, &funcVer, funcNo, inMsgHdl, outMsgHdl, tempFlags, &(pHandleObj->options), NULL);
    if(CL_OK != rc)
    {
        clBufferDelete(&outMsgHdl);
    return rc;
    }


    rc = clXdrUnmarshallClVersionT( outMsgHdl, pVersion);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrUnmarshallClUint32T( outMsgHdl, numOfCkpts);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrUnmarshallCkptMasterDBInfoIDLT_4_0_0( outMsgHdl, pMasterInfo);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrUnmarshallClUint32T( outMsgHdl, mastHdlCount);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrUnmarshallClUint32T( outMsgHdl, peerCount);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrUnmarshallClUint32T( outMsgHdl, clientHdlCount);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrUnmarshallPtrCkptXlationDBEntryT_4_0_0( outMsgHdl, (void **)pXlationInfo, *numOfCkpts);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrUnmarshallPtrCkptMasterDBEntryIDLT_4_0_0( outMsgHdl, (void **)pMasterDBInfo, *mastHdlCount);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrUnmarshallPtrCkptPeerListInfoT_4_0_0( outMsgHdl, (void **)pPeerListInfo, *peerCount);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrUnmarshallPtrCkptMasterDBClientInfoT_4_0_0( outMsgHdl, (void **)pClientDBInfo, *clientHdlCount);
    if (CL_OK != rc)
    {
        return rc;
    }

    clBufferDelete(&outMsgHdl);
    
    rc = clHandleCheckin(gIdlClnt.idlDbHdl,handle);
    return rc;
}
/**
 * Serializer function for transaction state
 */
static ClRcT _clTxnServiceCkptTxnStatePack(
    CL_IN   ClUint32T   dataSetId,
    CL_OUT  ClAddrT     *ppData,
    CL_OUT  ClUint32T   *pDataLen,
    CL_IN   ClPtrT      cookie)
{
    ClRcT                   rc  = CL_OK;
    ClTxnTransactionIdT     *pTxnId;
    ClBufferHandleT  msgHandle;
    ClUint32T               msgLen;

    CL_FUNC_ENTER();

    pTxnId = (ClTxnTransactionIdT *) cookie;

    CL_DEBUG_PRINT(CL_DEBUG_TRACE, ("To checkpoint recovery-log of txn 0x%x:0x%x",
                                    pTxnId->txnMgrNodeAddress, pTxnId->txnId));

    rc = clBufferCreate(&msgHandle);

    if (CL_OK == rc)
    {
        rc = clTxnRecoveryLogPack(pTxnId, msgHandle);

        *ppData = NULL;
        *pDataLen = 0;
        if (CL_OK == rc)
        {
            /* Copy the state-information from message-buffer to ppData */
            rc = clBufferLengthGet(msgHandle, &msgLen);
        }

        if (CL_OK == rc)
        {
            *pDataLen = msgLen;
            *ppData = (ClInt8T *) clHeapAllocate(msgLen);
            if ( *ppData == NULL )
            {
                CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Failed to allocate memory"));
                rc = CL_ERR_NO_MEMORY;
            }
        }

        if (CL_OK == rc)
        {
            rc = clBufferNBytesRead(msgHandle, (ClUint8T *) *ppData, &msgLen);
            if (CL_OK != rc)
            {
                clHeapFree(*ppData);
                *pDataLen = 0x0;
                CL_DEBUG_PRINT(CL_DEBUG_ERROR,
                               ("Failed to pack/serialize txn-defn[0x%x:0x%x] for ckpt. rc:0x%x",
                                pTxnId->txnMgrNodeAddress, pTxnId->txnId, rc));
                rc = CL_GET_ERROR_CODE(rc);
            }
        }
        rc = clBufferDelete(&msgHandle);
    }
    CL_FUNC_EXIT();
    return (rc);
}
ClRcT clMsgGroupDatabaseUpdateClientSync_4_0_0(CL_IN ClIdlHandleT handle, CL_IN ClMsgSyncActionT_4_0_0 syncupType, CL_IN ClNameT* pGroupName, CL_IN SaMsgQueueGroupPolicyT_4_0_0 policy, CL_IN ClIocPhysicalAddressT_4_0_0 qGroupAddress, CL_IN ClUint16T updateCkpt)
{
    ClRcT rc = CL_OK;
    ClVersionT funcVer = {4, 0, 0};
    ClUint32T funcNo = CL_EO_GET_FULL_FN_NUM(CL_EO_NATIVE_COMPONENT_TABLE_ID, 13);
    ClBufferHandleT inMsgHdl = 0;
    ClBufferHandleT outMsgHdl = 0;
    ClIocAddressT address = {{0}};
    ClIdlHandleObjT* pHandleObj = NULL;
    ClUint32T tempFlags = 0;

    rc = clHandleCheckout(gIdlClnt.idlDbHdl,handle,(void **)&pHandleObj);
    if( rc != CL_OK )
    {
        return rc ;
    }
    if (CL_IDL_ADDRESSTYPE_IOC == pHandleObj->address.addressType)
    {
        address = pHandleObj->address.address.iocAddress;
    }
    else if (CL_IDL_ADDRESSTYPE_NAME == pHandleObj->address.addressType)
    {
        rc = clNameToObjectReferenceGet(&(pHandleObj->address.address.nameAddress.name),
                                        pHandleObj->address.address.nameAddress.attrCount,
                                        pHandleObj->address.address.nameAddress.attr,
                                        pHandleObj->address.address.nameAddress.contextCookie,
                                        (ClUint64T*)&address);
        if (CL_OK != rc)
        {
            return rc;
        }
    }
    else
    {
        return CL_IDL_RC(CL_ERR_INVALID_PARAMETER);
    }

    rc = clBufferCreate(&inMsgHdl);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrMarshallClMsgSyncActionT_4_0_0(&(syncupType), inMsgHdl, 0);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrMarshallClNameT(pGroupName, inMsgHdl, 0);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrMarshallSaMsgQueueGroupPolicyT_4_0_0(&(policy), inMsgHdl, 0);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrMarshallClIocPhysicalAddressT_4_0_0(&(qGroupAddress), inMsgHdl, 0);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrMarshallClUint16T(&(updateCkpt), inMsgHdl, 0);
    if (CL_OK != rc)
    {
        return rc;
    }


    tempFlags |= pHandleObj->flags |
                 (CL_RMD_CALL_NON_PERSISTENT);
    tempFlags &= ~CL_RMD_CALL_ASYNC;

    rc = clRmdWithMsgVer(address, &funcVer, funcNo, inMsgHdl, outMsgHdl, tempFlags, &(pHandleObj->options), NULL);
    if(CL_OK != rc)
    {
        return rc;
    }


    
    rc = clHandleCheckin(gIdlClnt.idlDbHdl,handle);
    return rc;
}
/**
 * Internal function to pack/prepare state oa given transaction
 */
static ClRcT _clTxnServiceCkptTxnPack(
    CL_IN   ClUint32T   dataSetId,
    CL_OUT  ClAddrT     *ppData,
    CL_OUT  ClUint32T   *pDataLen,
    CL_IN   ClPtrT      cookie)
{
    ClRcT                   rc = CL_OK;
    ClTxnDefnT              *pTxnDefn;
    ClBufferHandleT  txnStateBuf;
    ClUint32T               msgLen;

    CL_FUNC_ENTER();

    pTxnDefn = (ClTxnDefnT *) cookie;

    if (pTxnDefn == NULL)
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Null argument"));
        CL_FUNC_EXIT();
        return (CL_ERR_NULL_POINTER);
    }

    CL_DEBUG_PRINT(CL_DEBUG_TRACE,
                   ("Packing for data-set 0x%x for txn[0x%x:0x%x]", dataSetId,
                    pTxnDefn->serverTxnId.txnMgrNodeAddress, pTxnDefn->serverTxnId.txnId));

    /* Validate between dataSetId and txn-Id */
#if 0
    if ( (dataSetId  - CL_TXN_CKPT_TXN_DATA_SET_ID_OFFSET) != pTxnId->txnId)
    {
        CL_TXN_RETURN_RC(CL_ERR_INVALID_PARAMETER,
                         ("Invalid data-set(0x%x) for transaction-id(0x%x)\n",
                          dataSetId, pTxnId->txnId));
    }
#endif

    rc = clBufferCreate (&txnStateBuf);

    if (CL_OK == rc)
    {
        rc = clTxnStreamTxnCfgInfoPack (pTxnDefn, txnStateBuf);

        *ppData = NULL;
        *pDataLen = 0;

        if (CL_OK == rc)
        {
            /* Copy the state-information from message-buffer to ppData */
            rc = clBufferLengthGet(txnStateBuf, &msgLen);
        }

        if (CL_OK == rc)
        {
            *pDataLen = msgLen;
            *ppData = (ClInt8T *) clHeapAllocate(msgLen);
            if ( *ppData == NULL )
            {
                CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Failed to allocate memory"));
                rc = CL_ERR_NO_MEMORY;
            }
        }

        if (CL_OK == rc)
        {
            rc = clBufferNBytesRead(txnStateBuf, (ClUint8T *) *ppData, &msgLen);
            if (CL_OK != rc)
            {
                clHeapFree(*ppData);
                *pDataLen = 0x0;
                CL_DEBUG_PRINT(CL_DEBUG_ERROR,
                               ("Failed to pack/serialize txn-defn[0x%x:0x%x] for ckpt. rc:0x%x",
                                pTxnDefn->serverTxnId.txnMgrNodeAddress, pTxnDefn->serverTxnId.txnId, rc));
                rc = CL_GET_ERROR_CODE(rc);
            }


        }

        rc = clBufferDelete(&txnStateBuf);

    }
    CL_FUNC_EXIT();
    return (rc);
}
/**
 * Internal Function - used to pack/prepare data-set for checkpointing
 * transaction-service
 */
static ClRcT _clTxnServiceCkptAppStatePack(
    CL_IN   ClUint32T   dataSetId,
    CL_OUT  ClAddrT     *ppData,
    CL_OUT  ClUint32T   *pDataLen,
    CL_IN   ClPtrT      cookie)
{
    ClRcT                       rc = CL_OK;
    ClBufferHandleT      txnSrvcStateBuff;

    CL_FUNC_ENTER();
    /* Walk through the list of transactions available in activeTxnMap.
       For each transaction, call clTxnStreamTxnCfgInfoPack()
       For the received message-buffer, append it to the master message-buffer.
    */

    if ( (ppData == NULL) || (pDataLen == NULL) )
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Null arguements"));
        CL_FUNC_EXIT();
        return CL_ERR_NULL_POINTER;
    }

    rc = clBufferCreate (&txnSrvcStateBuff);

    if (CL_OK == rc)
    {
        clXdrMarshallClUint32T( &(clTxnServiceCfg->txnIdCounter), txnSrvcStateBuff, 0);

        /* Copy to buffer */
        *pDataLen = 0;
        *ppData = NULL;

        if (CL_OK == rc)
        {
            ClUint32T   ckptDataLen;

            rc = clBufferLengthGet(txnSrvcStateBuff, &ckptDataLen);

            if ( (CL_OK == rc) && ( ckptDataLen != 0) )
            {
                *ppData = (ClAddrT) clHeapAllocate(ckptDataLen);
                *pDataLen = ckptDataLen;
                if ( *ppData != NULL )
                {
                    rc = clBufferNBytesRead(txnSrvcStateBuff,
                                            (ClUint8T *) *ppData, &ckptDataLen);
                    if (CL_OK != rc)
                    {
                        *pDataLen = 0x0;
                        clHeapFree(*ppData);
                        CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Failed to create txn-service checkpoint. rc:0x%x", rc));
                        rc = CL_GET_ERROR_CODE(rc);
                    }


                }
                else
                {
                    rc = CL_ERR_NO_MEMORY;
                }
            }
            else
            {
                CL_DEBUG_PRINT(CL_DEBUG_ERROR,
                               ("Error while packing or no data rc:0x%x data-len:0%x", rc, ckptDataLen));
            }
        }

        rc = clBufferDelete(&txnSrvcStateBuff);

    }
    CL_FUNC_EXIT();
    return (rc);
}
ClRcT clCkptLeaderAddrUpdateClientAsync_4_0_0(CL_IN ClIdlHandleT handle, CL_IN ClUint32T  masterAddr, CL_IN ClUint32T  deputyAddr,CL_IN CkptEoClCkptLeaderAddrUpdateAsyncCallbackT_4_0_0 fpAsyncCallback, CL_IN void *cookie)
{
    ClRcT rc = CL_OK;
    ClVersionT funcVer = {4, 0, 0};
    ClUint32T funcNo = CL_EO_GET_FULL_FN_NUM(CL_EO_NATIVE_COMPONENT_TABLE_ID, 19);
    ClBufferHandleT inMsgHdl = 0;
    ClBufferHandleT outMsgHdl = 0;
    ClIocAddressT address = {{0}};
    ClIdlHandleObjT* pHandleObj = NULL;
    ClRmdAsyncOptionsT asyncOptions;
    ClUint32T tempFlags = 0;
    ClIdlCookieT* pCookie = NULL;

    rc = clHandleCheckout(gIdlClnt.idlDbHdl,handle,(void **)&pHandleObj);
    if(rc != CL_OK)
    {
        return rc;
    }
    if (CL_IDL_ADDRESSTYPE_IOC == pHandleObj->address.addressType)
    {
        address = pHandleObj->address.address.iocAddress;
    }
    else if (CL_IDL_ADDRESSTYPE_NAME == pHandleObj->address.addressType)
    {
        rc = clNameToObjectReferenceGet(&(pHandleObj->address.address.nameAddress.name),
                                        pHandleObj->address.address.nameAddress.attrCount,
                                        pHandleObj->address.address.nameAddress.attr,
                                        pHandleObj->address.address.nameAddress.contextCookie,
                                        (ClUint64T*)&address);
        if (CL_OK != rc)
        {
            goto L;
        }
    }
    else
    {
        rc = CL_IDL_RC(CL_ERR_INVALID_PARAMETER);
        goto L;
    }

    rc = clBufferCreate(&inMsgHdl);
    if (CL_OK != rc)
    {
        goto L;
    }

    rc = clXdrMarshallClUint32T(&(masterAddr), inMsgHdl, 0);
    if (CL_OK != rc)
    {
        goto L;
    }

    rc = clXdrMarshallClUint32T(&(deputyAddr), inMsgHdl, 0);
    if (CL_OK != rc)
    {
        goto L;
    }

    if(fpAsyncCallback != NULL)
    {
        

        pCookie = (ClIdlCookieT*) clHeapAllocate(sizeof(ClIdlCookieT));
        if (NULL == pCookie)
        {
            return CL_IDL_RC(CL_ERR_NO_MEMORY);
        }
        
        asyncOptions.pCookie = NULL;
        asyncOptions.fpCallback = NULL;
        
        rc = clBufferCreate(&outMsgHdl);
        if (CL_OK != rc)
        {
            goto L2;
        }

        tempFlags |= pHandleObj->flags |
                     (CL_RMD_CALL_ASYNC | CL_RMD_CALL_NON_PERSISTENT | CL_RMD_CALL_NEED_REPLY);
        
        pCookie->pCookie = cookie;
        pCookie->actualCallback = (void(*)())fpAsyncCallback;
        pCookie->handle = handle;
        asyncOptions.pCookie = pCookie;
        asyncOptions.fpCallback = clCkptLeaderAddrUpdateAsyncCallback_4_0_0;

        rc = clRmdWithMsgVer(address, &funcVer, funcNo, inMsgHdl, outMsgHdl, tempFlags, &(pHandleObj->options), &asyncOptions);
        if (CL_OK != rc)
        {
            goto LL;
         }
    }
    else
    {
        tempFlags |= pHandleObj->flags |
                         (CL_RMD_CALL_ASYNC | CL_RMD_CALL_NON_PERSISTENT);
        rc = clRmdWithMsgVer(address, &funcVer, funcNo, inMsgHdl, 0, tempFlags, &(pHandleObj->options),NULL);
        if(CL_OK != rc)
        {
               goto L;
        }
    }
    
    
    clHandleCheckin(gIdlClnt.idlDbHdl,handle);
    return rc;

LL: clBufferDelete(&outMsgHdl);
L2:  clHeapFree(pCookie);
L:
     clHandleCheckin(gIdlClnt.idlDbHdl,handle);
    return rc;
}
/* This function handles msg send request from clients */
static ClRcT clMsgIocRequestHandle(ClEoExecutionObjT *pThis,
                           ClBufferHandleT eoRecvMsg,
                           ClUint8T priority,
                           ClUint8T protoType,
                           ClUint32T length,
                           ClIocPhysicalAddressT srcAddr)
{
    ClRcT          rc = CL_OK;
    ClRcT          ret;
    ClUint32T      sendType;
    ClNameT        pDestination;
    SaMsgMessageT  pMessage;
    ClInt64T       sendTime;
    ClHandleT      senderHandle;
    ClInt64T       timeout;
    ClInt64T       msgId;
    ClUint8T       syncType;

    memset(&(pDestination), 0, sizeof(ClNameT));
    memset(&(pMessage), 0, sizeof(SaMsgMessageT));
    memset(&(senderHandle), 0, sizeof(ClHandleT));

    rc = clXdrUnmarshallClUint32T( eoRecvMsg,&(sendType));
    if (CL_OK != rc)
    {
        goto out1;
    }

    rc = clXdrUnmarshallClNameT( eoRecvMsg,&(pDestination));
    if (CL_OK != rc)
    {
        goto out1;
    }

    rc = clXdrUnmarshallSaMsgMessageT_4_0_0( eoRecvMsg,&(pMessage));
    if (CL_OK != rc)
    {
        goto out1;
    }

    rc = clXdrUnmarshallClInt64T( eoRecvMsg,&(sendTime));
    if (CL_OK != rc)
    {
        goto out1;
    }

    rc = clXdrUnmarshallClHandleT( eoRecvMsg,&(senderHandle));
    if (CL_OK != rc)
    {
        goto out1;
    }

    rc = clXdrUnmarshallClInt64T( eoRecvMsg,&(timeout));
    if (CL_OK != rc)
    {
        goto out1;
    }

    rc = clXdrUnmarshallClInt64T( eoRecvMsg,&(msgId));
    if (CL_OK != rc)
    {
        goto out1;
    }

    rc = clXdrUnmarshallClUint8T( eoRecvMsg,&(syncType));
    if (CL_OK != rc)
    {
        goto out1;
    }

    /* Call remote function */
    ret = VDECL_VER(clMsgMessageReceived, 4, 0, 0)(sendType, &(pDestination), &(pMessage), sendTime, senderHandle, timeout);

    /* Prepare to send return value to the caller */
    ClIocSendOptionT sendOption = { 0 };
    ClBufferHandleT replyMsg = NULL;    
    ClUint8T replyProto = CL_IOC_SAF_MSG_REPLY_PROTO;

    /* Set Ioc send option */
    sendOption.msgOption = CL_IOC_PERSISTENT_MSG;
    sendOption.priority = CL_IOC_DEFAULT_PRIORITY;
    sendOption.timeout = 10000;

    /* Create buffer for input message */
    rc = clBufferCreate(&replyMsg);
    if (CL_OK != rc)
    {
        clDbgResourceLimitExceeded(clDbgMemoryResource, 0, ("Out of memory"));
        goto out1;
    }

    /* Marshall reply data */
    rc = clMsgReplyDataMarshall(replyMsg, ret, msgId, syncType);
    if (CL_OK != rc)
    {
        clDbgCodeError(rc, ("Cannot marshal reply data."));
        goto out2;
    }

    /* Send return value to the caller */
    rc = clIocSend(pThis->commObj, replyMsg, replyProto,(ClIocAddressT *) &srcAddr, &sendOption);
    if (CL_OK != CL_GET_ERROR_CODE(rc))
    {
        clLogError("MSG", "REPLY", "clIocSend(): error code [0x%x].", rc);
    }

out2:
    clBufferDelete(&replyMsg);
out1:
    return rc;
}
ClRcT clMsgMessageReceivedClientSync_4_0_0(CL_IN ClIdlHandleT handle, CL_IN ClUint32T sendType, CL_IN ClNameT* pDestination, CL_IN SaMsgMessageT_4_0_0* pMessage, CL_IN ClInt64T sendTime, CL_IN ClHandleT senderHandle, CL_IN ClInt64T timeout)
{
    ClRcT rc = CL_OK;
    ClVersionT funcVer = {4, 0, 0};
    ClUint32T funcNo = CL_EO_GET_FULL_FN_NUM(CL_MSG_CLIENT_SERVER_TABLE_ID, 4);
    ClBufferHandleT inMsgHdl = 0;
    ClBufferHandleT outMsgHdl = 0;
    ClIocAddressT address = {{0}};
    ClIdlHandleObjT* pHandleObj = NULL;
    ClUint32T tempFlags = 0;

    rc = clHandleCheckout(gIdlClnt.idlDbHdl,handle,(void **)&pHandleObj);
    if( rc != CL_OK )
    {
        return rc ;
    }
    if (CL_IDL_ADDRESSTYPE_IOC == pHandleObj->address.addressType)
    {
        address = pHandleObj->address.address.iocAddress;
    }
    else if (CL_IDL_ADDRESSTYPE_NAME == pHandleObj->address.addressType)
    {
        rc = clNameToObjectReferenceGet(&(pHandleObj->address.address.nameAddress.name),
                                        pHandleObj->address.address.nameAddress.attrCount,
                                        pHandleObj->address.address.nameAddress.attr,
                                        pHandleObj->address.address.nameAddress.contextCookie,
                                        (ClUint64T*)&address);
        if (CL_OK != rc)
        {
            return rc;
        }
    }
    else
    {
        return CL_IDL_RC(CL_ERR_INVALID_PARAMETER);
    }

    rc = clBufferCreate(&inMsgHdl);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrMarshallClUint32T(&(sendType), inMsgHdl, 0);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrMarshallClNameT(pDestination, inMsgHdl, 0);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrMarshallSaMsgMessageT_4_0_0(pMessage, inMsgHdl, 0);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrMarshallClInt64T(&(sendTime), inMsgHdl, 0);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrMarshallClHandleT(&(senderHandle), inMsgHdl, 0);
    if (CL_OK != rc)
    {
        return rc;
    }

    rc = clXdrMarshallClInt64T(&(timeout), inMsgHdl, 0);
    if (CL_OK != rc)
    {
        return rc;
    }


    tempFlags |= pHandleObj->flags |
                 (CL_RMD_CALL_NON_PERSISTENT);
    tempFlags &= ~CL_RMD_CALL_ASYNC;

    rc = clRmdWithMsgVer(address, &funcVer, funcNo, inMsgHdl, outMsgHdl, tempFlags, &(pHandleObj->options), NULL);
    if(CL_OK != rc)
    {
        return rc;
    }


    
    rc = clHandleCheckin(gIdlClnt.idlDbHdl,handle);
    return rc;
}