ClRcT
clLogClntStreamEntryGet(ClLogClntEoDataT  *pClntEoEntry,
                        SaNameT           *pStreamName,
                        SaNameT           *pNodeName,
                        ClStringT         *pShmName,
                        ClUint32T         shmSize,
                        ClCntNodeHandleT  *phStreamNode,
                        ClBoolT           *pAddedEntry)
{
    ClRcT             rc            = CL_OK;
    ClLogStreamKeyT   *pStreamKey   = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    *pAddedEntry = CL_FALSE;

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

    rc = clLogStreamKeyCreate(pStreamName, pNodeName,
                              pClntEoEntry->maxStreams, &pStreamKey);
    if( CL_OK != rc )
    {
        return rc;
    }

    rc = clCntNodeFind(pClntEoEntry->hClntStreamTable,
                       (ClCntKeyHandleT) pStreamKey,
                       phStreamNode);
    if( CL_ERR_NOT_EXIST == CL_GET_ERROR_CODE(rc) )
    {
        rc = clLogClntStreamEntryAdd(pClntEoEntry->hClntStreamTable,
                                     pStreamKey, pShmName, shmSize,
                                     phStreamNode);
        if( CL_OK != rc )
        {
            clLogStreamKeyDestroy(pStreamKey);
        }
        else
        {
            *pAddedEntry = CL_TRUE;
        }
        return rc;
    }
    clLogStreamKeyDestroy(pStreamKey);

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogInitHandleBitmapFileRemove(ClLogHandleT      hLog, 
                                ClLogFileHandleT  hFileHdlr)
{
    ClRcT                  rc            = CL_OK;
    ClLogInitHandleDataT  *pData         = NULL;
    ClLogClntEoDataT      *pClntEoEntry  = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));
        
    rc = clLogClntEoEntryGet(&pClntEoEntry);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clLogClntEoEntryGet(): rc[0x %x]", rc));
        return rc;
    }

    rc = clHandleCheckout(pClntEoEntry->hClntHandleDB, hLog,
                          (void **) (&pData)); 
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckout(): rc[0x %x]\n", rc));
        return rc;
    }

    rc = clBitmapBitClear(pData->hStreamBitmap, hFileHdlr);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clBitmapBitSet(): rc[0x %x]", rc));
        CL_LOG_CLEANUP(clHandleCheckin(pClntEoEntry->hClntHandleDB, hLog),
                       CL_OK);
        return rc;
    }

    rc = clHandleCheckin(pClntEoEntry->hClntHandleDB, hLog); 
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckin(): rc[0x %x]", rc));
        return rc;
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
} 
ClRcT
clLogFileHdlrHandleInfoGet(ClLogFileHandleT   hFileHdlr,
                           ClBoolT            *pIsDelete, 
                           ClUint32T          *pVersion, 
                           ClUint64T          *pStartRec, 
                           ClLogClntFileKeyT  **ppFileKey)
{
    ClRcT                   rc            = CL_OK;
    ClLogClntFileHdlrInfoT  *pData        = NULL;
    ClLogClntEoDataT        *pClntEoEntry = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogClntEoEntryGet(&pClntEoEntry);
    if( CL_OK != rc )
    {
        return rc;
    }

    rc = clHandleCheckout(pClntEoEntry->hClntHandleDB, hFileHdlr,
                          (void **) &pData);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckout(): rc[0x %x]", rc));
        return rc;
    }
    
    *ppFileKey = pData->pFileKey;
    *pIsDelete = pData->isDelete;
    *pStartRec = pData->startRead;
    *pVersion  = pData->operatingLvl;

    rc = clHandleCheckin(pClntEoEntry->hClntHandleDB, hFileHdlr);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckin(); rc[0x %x]", rc));
        return rc;
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogClntFileHdlrHandleUpdate(ClLogFileHandleT   hFileHdlr,
                              ClUint32T          version, 
                              ClUint64T          startRec)
{
    ClRcT               rc            = CL_OK;
    ClLogClntFileHdlrInfoT  *pData        = NULL;
    ClLogClntEoDataT    *pClntEoEntry = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogClntEoEntryGet(&pClntEoEntry);
    if( CL_OK != rc )
    {
        return rc;
    }

    rc = clHandleCheckout(pClntEoEntry->hClntHandleDB, hFileHdlr, 
                          (void **) &pData);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckout(): rc[0x %x]", rc));
        return rc;
    }
    
    pData->operatingLvl = version;
    pData->startRead    = startRec;
    
    rc = clHandleCheckin(pClntEoEntry->hClntHandleDB, hFileHdlr);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckin(); rc[0x %x]", rc));
        return rc;
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
static ClRcT
clLogFileHdlrFileHandleDelete(ClLogFileHandleT  hFileHdlr,
                              ClLogHandleT      *phLog)
{
    ClRcT               rc            = CL_OK;
    ClLogClntFileHdlrInfoT  *pData        = NULL;
    ClLogClntEoDataT    *pClntEoEntry = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogClntEoEntryGet(&pClntEoEntry);
    if( CL_OK != rc )
    {
        return rc;
    }

    rc = clHandleCheckout(pClntEoEntry->hClntHandleDB, hFileHdlr,
                          (void **) &pData);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckout(): rc[0x %x]", rc));
        return rc;
    }

    *phLog = pData->hLog;
    clLogClntFileKeyDestroy(pData->pFileKey); 

    rc = clHandleCheckin(pClntEoEntry->hClntHandleDB, hFileHdlr);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckin(); rc[0x %x]", rc));
    }
    CL_LOG_CLEANUP(clHandleDestroy(pClntEoEntry->hClntHandleDB, hFileHdlr), CL_OK);

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogHandlerHandleDataDisplay()
{
    ClRcT             rc            = CL_OK;
    ClLogClntEoDataT  *pClntEoEntry = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogClntEoEntryGet(&pClntEoEntry);
    if( CL_OK != rc )
    {
        return rc;
    }

    rc = clHandleWalk(pClntEoEntry->hClntHandleDB, clLogHandlerDataDump, NULL);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleWalk(): rc[0x %x]", rc));
        return rc;
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogStreamHandleDataDisplay(ClCharT  **ppRet)
{
    ClRcT             rc            = CL_OK;
    ClLogClntEoDataT  *pClntEoEntry = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogClntEoEntryGet(&pClntEoEntry);
    if( CL_OK != rc )
    {
        return rc;
    }
    
    rc = clHandleWalk(pClntEoEntry->hClntHandleDB, clLogStreamDataDump, (void *)ppRet);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleWalk(): rc[0x %x]", rc));
        return rc;
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogInitDataDump(ClHandleDatabaseHandleT  hDb,
                  ClLogHandleT             hLog,
                  ClPtrT                   pCookie)
{
    ClRcT                 rc            = CL_OK;
    ClUint32T             bitmapLen     = 0;
    ClUint32T             i             = 0;
    ClLogClntEoDataT      *pClntEoEntry = NULL;
    ClLogInitHandleDataT  *pData        = NULL;
    ClCharT               ret[MAX_DEBUG_DISPLAY];
    ClCharT               p[MAX_DEBUG_DISPLAY];
    ClCharT               **ppRet       = (ClCharT**) pCookie;
    
    CL_LOG_DEBUG_TRACE(("Enter"));

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

    rc = clHandleCheckout(pClntEoEntry->hClntHandleDB, hLog, (void **) (&pData));
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckout(): rc[0x %x]", rc));
        return rc;
    }

    memset(ret, '\0', MAX_DEBUG_DISPLAY);
    memset(p, '\0', MAX_DEBUG_DISPLAY);
    
    if( CL_LOG_INIT_HANDLE == pData->type )
    {
        snprintf(ret, MAX_DEBUG_DISPLAY, "Init handle: %#llX\nCallbacks: %p\nBitmap:%p\n",
                hLog, (void *) pData->pCallbacks,
                (void *) pData->hStreamBitmap);

        bitmapLen = clBitmapLen(pData->hStreamBitmap);
        if( CL_OK != rc )
        {
            CL_LOG_DEBUG_ERROR(("clBitmapLen(): rc[0x %x]", rc));
            return rc;
        }

        snprintf(p, MAX_DEBUG_DISPLAY, "hStreamBitmap:\n");
        strncat(ret, p, CL_MIN(strlen(p), (MAX_DEBUG_DISPLAY-strlen(ret)-1)));
        
        for( i = 0; i < bitmapLen; i++ )
        {
            if( clBitmapIsBitSet(pData->hStreamBitmap, i, &rc) )
            {
                snprintf(p, MAX_DEBUG_DISPLAY, "%d ", 1);
                strncat(ret, p, CL_MIN(strlen(p), (MAX_DEBUG_DISPLAY-strlen(ret)-1)));
            }
            else
            {
                snprintf(p, MAX_DEBUG_DISPLAY, "%d ", 0);
                strncat(ret, p, CL_MIN(strlen(p), (MAX_DEBUG_DISPLAY-strlen(ret)-1)));
            }
        }

        bitmapLen = clBitmapLen(pData->hFileBitmap);
        if( CL_OK != rc )
        {
            CL_LOG_DEBUG_ERROR(("clBitmapLen(): rc[0x %x]", rc));
            return rc;
        }

        snprintf(p, MAX_DEBUG_DISPLAY, "\nhFileBitmap:\n");
        strncat(ret, p, CL_MIN(strlen(p), (MAX_DEBUG_DISPLAY-strlen(ret)-1)));

        for( i = 0; i < bitmapLen; i++ )
        {
            if( clBitmapIsBitSet(pData->hFileBitmap, i, &rc) )
            {
                snprintf(p, MAX_DEBUG_DISPLAY, "%d ", 1);
                strncat(ret, p, CL_MIN(strlen(p), (MAX_DEBUG_DISPLAY-strlen(ret)-1)));
            }
            else
            {
                snprintf(p, MAX_DEBUG_DISPLAY, "%d ", 0);
                strncat(ret, p, CL_MIN(strlen(p), (MAX_DEBUG_DISPLAY-strlen(ret)-1)));
            }
        }
    }

    rc = clHandleCheckin(pClntEoEntry->hClntHandleDB, hLog);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckin(): rc[0x %x]", rc));
        return rc;
    }

    *ppRet = (ClCharT*) clHeapAllocate(strlen(ret) + 1);
    if( NULL == *ppRet )
    {
        CL_LOG_DEBUG_ERROR(("clHeapAllocate(): rc[0x %x]", rc));
        return rc;
    }

    snprintf(*ppRet, strlen(ret)+1, ret);
    
    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogHandlerDataDump(ClHandleDatabaseHandleT hDb, ClStreamHandleT hHandler,
                    void *pCookie)
{
    ClRcT                   rc            = CL_OK;
    ClLogHandlerHandleDataT *pData        = NULL;
    ClLogClntHandlerNodeT   *pHandlerInfo = NULL;
    ClLogClntEoDataT        *pClntEoEntry = NULL;
    ClUint32T               bitmapLen     = 0;
    ClCharT                 s[256];

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogClntEoEntryGet(&pClntEoEntry);
    if( CL_OK != rc )
    {
        return rc;
    }

    rc = clHandleCheckout(hDb, hHandler, (void **) (&pData));
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckout(): rc[0x %x]", rc));
        return rc;
    }

    if( CL_LOG_HANDLER_HANDLE == pData->type )
    {
        CL_LOG_DEBUG_TRACE(("Handler handle: %d\nInit handle: %d"
                            " Handler Flag%d\n" , hStream,
                            pData->hLog, pData->handlerFlags));


        rc = clCntNodeUserDataGet(pClntEoEntry->hStreamHandlerTable,
                                  pData->hClntHandlerNode,
                                  (ClCntDataHandleT *) &pHandlerInfo);
        if( CL_OK != rc )
        {
            CL_LOG_DEBUG_ERROR(("clCntNodeUserDataGet(): rc[0x %x]", rc));
            return rc;
        }

        sprintf(s, pHandlerInfo->streamName.length, "%s",
                pHandlerInfo->streamName.value);
        CL_LOG_DEBUG_TRACE(("Stream Name: %s\n", s));

        sprintf(s, pHandlerInfo->nodeName.length, "%s",
                pHandlerInfo->nodeName.value);
        CL_LOG_DEBUG_TRACE(("Node Name: %s\n", s));

        bitmapLen = clBitmapLen(pStreamInfo->hStreamBitmap);
        if( CL_OK != rc )
        {
            CL_LOG_DEBUG_ERROR(("clBitmapLen(): rc[0x %x]", rc));
            return rc;
        }

        CL_LOG_DEBUG_TRACE(("hStreamBitmap:\n"));

        for( i = 0; i < bitmapLen; i++ )
        {
            if( clBitmapIsBitSet(pData->hStreamBitmap, i, &rc) )
            {
                CL_LOG_DEBUG_TRACE(("%d ", 1));
            }
            else
            {
                CL_LOG_DEBUG_TRACE(("%d ", 0));
            }
        }

    }

    rc = clHandleCheckin(hDb, hStream);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckin(): rc[0x %x]", rc));
        return rc;
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogStreamDataDump(ClHandleDatabaseHandleT  hDb,
                    ClLogStreamHandleT       hStream,
                    ClPtrT                   pCookie)
{
    ClRcT                   rc            = CL_OK;
    ClLogStreamHandleDataT  *pData        = NULL;
    ClLogClntStreamDataT    *pStreamInfo  = NULL;
    ClLogClntEoDataT        *pClntEoEntry = NULL;
    ClCharT                 **ppRet       = (ClCharT**) pCookie;
    ClCharT                 ret[MAX_DEBUG_DISPLAY];
    ClCharT                 p[MAX_DEBUG_DISPLAY];


    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogClntEoEntryGet(&pClntEoEntry);
    if( CL_OK != rc )
    {
        return rc;
    }

    rc = clHandleCheckout(hDb, hStream, (void **) (&pData));
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckout(): rc[0x %x]", rc));
        return rc;
    }

    memset(ret, '\0', MAX_DEBUG_DISPLAY);
    memset(p, '\0', MAX_DEBUG_DISPLAY);
    
    if( CL_LOG_STREAM_HANDLE == pData->type )
    {
        snprintf(ret, MAX_DEBUG_DISPLAY, "Stream handle: %#llX\nStreamNode: %p\n",
                hStream, (ClPtrT) pData->hClntStreamNode);

        
        rc = clCntNodeUserDataGet(pClntEoEntry->hClntStreamTable,
                                  pData->hClntStreamNode,
                                  (ClCntDataHandleT *) &pStreamInfo);
        if( CL_OK != rc )
        {
            CL_LOG_DEBUG_ERROR(("clCntNodeUserDataGet(): rc[0x %x]", rc));
            return rc;
        }

        snprintf(p,MAX_DEBUG_DISPLAY, "Stream Header: %p\n",
                (ClCharT *) pStreamInfo->pStreamHeader);
        strncat(ret, p, CL_MIN(strlen(p), (MAX_DEBUG_DISPLAY-strlen(ret)-1)));

        snprintf(p,MAX_DEBUG_DISPLAY, "Shm Name: %.*s", pStreamInfo->shmName.length,
                pStreamInfo->shmName.pValue);
        strncat(ret, p, CL_MIN(strlen(p), (MAX_DEBUG_DISPLAY-strlen(ret)-1)));
        
        rc = clHandleCheckin(hDb, hStream);
        if( CL_OK != rc )
        {
            CL_LOG_DEBUG_ERROR(("clHandleCheckin(): rc[0x %x]", rc));
            return rc;
        }

        *ppRet = (ClCharT*) clHeapAllocate(strlen(ret) + 1);
        if( NULL == *ppRet )
        {
            CL_LOG_DEBUG_ERROR(("clHeapAllocate(): rc[0x %x]", rc));
            return rc;
        }

        snprintf(*ppRet, strlen(ret)+1, ret);
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
ClRcT
clLogClntStreamOpen(ClLogHandleT        hLog,
                    SaNameT             *pStreamName,
                    SaNameT             *pNodeName,
                    ClStringT           *pShmName,
                    ClUint32T           shmSize,
                    ClLogStreamHandleT  *phStream,
                    ClUint32T           recSize)
{
    ClRcT                 rc              = CL_OK;
    ClLogClntEoDataT      *pClntEoEntry   = NULL;
    ClBoolT               addedTable      = CL_FALSE;
    ClBoolT               addedEntry      = CL_FALSE;
    ClCntNodeHandleT      hClntStreamNode = CL_HANDLE_INVALID_VALUE;
    ClLogClntStreamDataT  *pUserData      = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    CL_LOG_PARAM_CHK((NULL == pStreamName), CL_LOG_RC(CL_ERR_NULL_POINTER));
    CL_LOG_PARAM_CHK((NULL == pNodeName), CL_LOG_RC(CL_ERR_NULL_POINTER));
    CL_LOG_PARAM_CHK((NULL == pShmName), CL_LOG_RC(CL_ERR_NULL_POINTER));
    CL_LOG_PARAM_CHK((sizeof(ClLogStreamHeaderT) > shmSize),
                      CL_LOG_RC(CL_ERR_INVALID_PARAMETER));
    CL_LOG_PARAM_CHK((NULL == phStream), CL_LOG_RC(CL_ERR_NULL_POINTER));

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

    rc = clOsalMutexLock_L(&(pClntEoEntry->clntStreamTblLock));
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clOsalMutexLock(): rc[0x %x]", rc));
        return rc;
    }

    if( CL_HANDLE_INVALID_VALUE == pClntEoEntry->hClntStreamTable )
    {
        rc = clCntHashtblCreate(pClntEoEntry->maxStreams,
                                clLogStreamKeyCompare,
                                clLogStreamHashFn,
                                clLogClntStreamDeleteCb,
                                clLogClntStreamDeleteCb,
                                CL_CNT_UNIQUE_KEY,
                                &(pClntEoEntry->hClntStreamTable));
        if( CL_OK != rc )
        {
            CL_LOG_DEBUG_ERROR(("clCntHashtblCreate(): rc[0x %x]", rc));
            CL_LOG_CLEANUP(
                clOsalMutexUnlock_L(&(pClntEoEntry->clntStreamTblLock)),CL_OK);
            return rc;
        }
        addedTable = CL_TRUE;
        CL_LOG_DEBUG_VERBOSE(("Created the HashTable"));
    }

    rc = clLogClntStreamEntryGet(pClntEoEntry, pStreamName, pNodeName,
                                 pShmName, shmSize, &hClntStreamNode,
                                 &addedEntry);
    if( CL_OK != rc)
    {
        if( CL_TRUE == addedTable )
        {
            CL_LOG_CLEANUP(clCntDelete(pClntEoEntry->hClntStreamTable), CL_OK);
        }
        CL_LOG_CLEANUP(clOsalMutexUnlock_L(&(pClntEoEntry->clntStreamTblLock)),
                       CL_OK);
        return rc;
    }
    CL_LOG_DEBUG_VERBOSE(("Got the stream entry"));

    rc = clLogHandleStreamHandleCreate(hLog, hClntStreamNode, phStream);
    if( CL_OK != rc)
    {
        if( CL_TRUE == addedEntry )
        {
            CL_LOG_CLEANUP(clCntNodeDelete(pClntEoEntry->hClntStreamTable,
                                           hClntStreamNode), CL_OK);
        }
        if( CL_TRUE == addedTable )
        {
            CL_LOG_CLEANUP(clCntDelete(pClntEoEntry->hClntStreamTable), CL_OK);
        }
        CL_LOG_CLEANUP(clOsalMutexUnlock_L(&(pClntEoEntry->clntStreamTblLock)),
                       CL_OK);
        return rc;
    }
    CL_LOG_DEBUG_VERBOSE(("Created the streamhandle"));

    rc = clCntNodeUserDataGet(pClntEoEntry->hClntStreamTable, hClntStreamNode,
                              (ClCntDataHandleT *) &pUserData);
    if( CL_OK != rc )
    {
        CL_LOG_CLEANUP(clHandleDestroy(pClntEoEntry->hClntHandleDB,
                                             *phStream), CL_OK);
        *phStream = CL_HANDLE_INVALID_VALUE;
        if( CL_TRUE == addedEntry )
        {
            CL_LOG_CLEANUP(clCntNodeDelete(pClntEoEntry->hClntStreamTable,
                                           hClntStreamNode), CL_OK);
        }

        if( CL_TRUE == addedTable )
        {
            CL_LOG_CLEANUP(clCntDelete(pClntEoEntry->hClntStreamTable), CL_OK);
        }
        CL_LOG_CLEANUP(clOsalMutexUnlock_L(&(pClntEoEntry->clntStreamTblLock)),
                       CL_OK);
        return rc;
    }
#ifdef NO_SAF
    pUserData->recSize=recSize;
#endif
    CL_LOG_DEBUG_VERBOSE(("Got stream entry"));
    rc = clBitmapBitSet(pUserData->hStreamBitmap, CL_HDL_IDX(*phStream));
    if( CL_OK != rc )
    {
        CL_LOG_CLEANUP(clHandleDestroy(pClntEoEntry->hClntHandleDB, *phStream),
                       CL_OK);
        *phStream = CL_HANDLE_INVALID_VALUE;
        if( CL_TRUE == addedEntry )
        {
            CL_LOG_CLEANUP(clCntNodeDelete(pClntEoEntry->hClntStreamTable,
                                           hClntStreamNode), CL_OK);
        }

        if( CL_TRUE == addedTable )
        {
            CL_LOG_CLEANUP(clCntDelete(pClntEoEntry->hClntStreamTable), CL_OK);
        }
        CL_LOG_CLEANUP(clOsalMutexUnlock_L(&(pClntEoEntry->clntStreamTblLock)),
                       CL_OK);
        return rc;
    }
    CL_LOG_DEBUG_VERBOSE(("Updated stream bitmap"));

    rc = clLogHandleInitHandleStreamAdd(hLog, *phStream);
    if( CL_OK != rc )
    {
        CL_LOG_CLEANUP(clBitmapBitClear(pUserData->hStreamBitmap, CL_HDL_IDX(*phStream)),
                       CL_OK);
        CL_LOG_CLEANUP(clHandleDestroy(pClntEoEntry->hClntHandleDB, *phStream),
                       CL_OK);
        *phStream = CL_HANDLE_INVALID_VALUE;
        if( CL_TRUE == addedEntry )
        {
            CL_LOG_CLEANUP(clCntNodeDelete(pClntEoEntry->hClntStreamTable,
                                           hClntStreamNode), CL_OK);
        }

        if( CL_TRUE == addedTable )
        {
            CL_LOG_CLEANUP(clCntDelete(pClntEoEntry->hClntStreamTable), CL_OK);
        }
        CL_LOG_CLEANUP(clOsalMutexUnlock_L(&(pClntEoEntry->clntStreamTblLock)),
                       CL_OK);
        return rc;
    }
    CL_LOG_DEBUG_VERBOSE(("Updated init handle"));

    rc = clOsalMutexUnlock_L(&(pClntEoEntry->clntStreamTblLock));
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clOsalMutexUnlock(): rc[0x %x]", rc));
        return rc;
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}
static ClRcT
clLogFileHdlrHandleCreate(ClLogHandleT       hLog,
                          ClBoolT            isDelete, 
                          ClUint32T          operatingLvl, 
                          ClLogClntFileKeyT  *pFileKey,
                          ClHandleT          *phFile)
{
    ClRcT                   rc            = CL_OK;
    ClBoolT                 entryAdd      = CL_FALSE;
    ClLogClntFileHdlrInfoT  *pData        = NULL;
    ClLogClntEoDataT        *pClntEoEntry = NULL;

    CL_LOG_DEBUG_TRACE(("Enter"));

    rc = clLogClntEoEntryGet(&pClntEoEntry);
    if( CL_OK != rc )
    {
        return rc;
    }

    rc = clHandleCreate(pClntEoEntry->hClntHandleDB, 
                        sizeof(ClLogClntFileHdlrInfoT), phFile);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCreate(); rc[0x %x]", rc));
        if( CL_TRUE == entryAdd )
        {
            CL_LOG_CLEANUP(clHandleDatabaseDestroy(pClntEoEntry->hClntHandleDB),
                           CL_OK);
        }
        return rc;
    }

    rc = clHandleCheckout(pClntEoEntry->hClntHandleDB, *phFile, 
                          (void **) &pData);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckout(): rc[0x %x]", rc));
        CL_LOG_CLEANUP(clHandleDestroy(pClntEoEntry->hClntHandleDB, *phFile),
                       CL_OK);
        if( CL_TRUE == entryAdd )
        {
            CL_LOG_CLEANUP(clHandleDatabaseDestroy(pClntEoEntry->hClntHandleDB),
                           CL_OK);
        }
        return rc;
    }
    pData->type         = CL_LOG_FILE_HANDLE;
    pData->isDelete     = isDelete;
    pData->startRead    = 0;
    pData->operatingLvl = operatingLvl;
    pData->hLog         = hLog;
    pData->pFileKey     = pFileKey; 

    rc = clHandleCheckin(pClntEoEntry->hClntHandleDB, *phFile);
    if( CL_OK != rc )
    {
        CL_LOG_DEBUG_ERROR(("clHandleCheckin(); rc[0x %x]", rc));
        CL_LOG_CLEANUP(clHandleDestroy(pClntEoEntry->hClntHandleDB, *phFile),
                       CL_OK);
        if( CL_TRUE == entryAdd )
        {
            CL_LOG_CLEANUP(clHandleDatabaseDestroy(pClntEoEntry->hClntHandleDB),
                           CL_OK);
        }
        return rc;
    }

    CL_LOG_DEBUG_TRACE(("Exit"));
    return rc;
}