static ClRcT clAmsMgmtOIMoIdGet(ClAmsMgmtHandleT handle,
                                ClAmsEntityT *pEntity,
                                ClCorMOIdT *pMoId)
{
    ClCharT *userData = NULL;
    ClUint32T dataSize = 0;
    ClRcT rc = CL_OK;

    if(!pEntity || !pMoId)
        return CL_AMS_RC(CL_ERR_INVALID_PARAMETER);

    rc = clAmsMgmtEntityUserDataGetKey(handle, pEntity, &pEntity->name,
                                       &userData, &dataSize);
    if(rc != CL_OK)
    {
        clLogError("AMF", "MGMT", "Entity user data get key for [%s] returned [%#x]",
                   pEntity->name.value, rc);
        return rc;
    }

    if(!userData || !dataSize)
        return CL_AMS_RC(CL_ERR_INVALID_STATE);

    rc = clCorMoIdUnpack(userData, dataSize, pMoId);
    clHeapFree(userData);
    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;
}