/*Currently we are having another API clCorClassDelete for same purpose. However,
  it takes class handle as input. If we plan to remove it. This will be useful.*/
ClRcT
dmClassDelete(ClCorClassTypeT id)
{
    ClRcT ret = CL_OK;
    CORClass_h tmp = 0;
    
    CL_FUNC_ENTER();

    if((!dmGlobal))
      {
        CL_FUNC_EXIT();  
        return(CL_COR_SET_RC(CL_COR_ERR_NULL_PTR));
      }
    
    CL_DEBUG_PRINT(CL_DEBUG_TRACE, ( "ClassDelete (Class:%04x)", id));
    
    /* check if class already present 
     */
    HASH_GET(dmGlobal->classTable, id, tmp);
    if(tmp) 
      {
        ret = dmClassByHandleDelete(tmp);
      } 
    else 
      {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, ( "ClassDelete (Class:%04x) [Unknown class]", 
                              id));
        
        ret = CL_COR_SET_RC(CL_COR_ERR_CLASS_NOT_PRESENT);
      }
    
    CL_FUNC_EXIT();
    return (ret);
}
ClRcT
cosSysvShmAttach(ClOsalShmIdT shmId,void* pInMem, void** ppOutMem)
{
    ClRcT retCode = 0;
    void* pShared = NULL;

    CL_FUNC_ENTER();
    if(NULL == ppOutMem)
    {
        CL_DEBUG_PRINT (CL_DEBUG_INFO,("\nShared Memory Attach: FAILED"));
        retCode = CL_OSAL_RC(CL_ERR_NULL_POINTER);
        CL_FUNC_EXIT();
        return(retCode);
    }

    pShared = shmat ((int)shmId, pInMem, 0);

    if((void*)-1 == pShared)
    {
        CL_DEBUG_PRINT (CL_DEBUG_INFO,("\nShared Memory Attach: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_ATTACH);
        CL_FUNC_EXIT();
        return(retCode);
    }
    else
    {
        *ppOutMem = pShared;
    }

    CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory Attach: DONE"));
    CL_FUNC_EXIT();
    return (CL_OK);
}
ClRcT halDevObjCreate (ClUint32T deviceID, 
                        void *pdevCapability,
                        ClUint32T devCapLen ,
                        ClUint32T maxRspTime, 
                        ClUint32T bootUpPriority, 
                        ClHalDeviceObjectH *const phalDevObj)

{
    ClUint32T index=0 ;
    ClUint32T i=0 ;
    CL_FUNC_ENTER();
    
    if(deviceID<=0)
    {
        clLogCritical(CL_LOG_AREA_UNSPECIFIED,CL_LOG_CONTEXT_UNSPECIFIED,"\nhalDevObjCreate Error Invalid DeviceId\n");
        CL_FUNC_EXIT();
        return(CL_HAL_SET_RC( CL_ERR_INVALID_PARAMETER)) ;
    }

    if(NULL ==phalDevObj) 
    { 
        clLogCritical(CL_LOG_AREA_UNSPECIFIED,CL_LOG_CONTEXT_UNSPECIFIED,"\n halDevObjCreate Error NULL for Device \
                      Object Handle\n") ;
        CL_FUNC_EXIT();
        return(CL_HAL_SET_RC(CL_ERR_NULL_POINTER));
    }
ClRcT
cosSysvShmSizeGet(ClOsalShmIdT shmId,ClUint32T* pSize)
{
    struct shmid_ds shmSize ;
    ClInt32T retCode = CL_OK;

    CL_FUNC_ENTER();
    if(NULL == pSize)
    {
        CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory SecurityModeGet: FAILED"));
        retCode = CL_OSAL_RC(CL_ERR_NULL_POINTER);
        CL_FUNC_EXIT();
        return(retCode);
    }

    /* Get the current values set and modifiy it */
    retCode = shmctl ((int)shmId, IPC_STAT, &shmSize);

    if(0 != retCode)
    {
        CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory SecurityModeGet: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_SIZE);
        CL_FUNC_EXIT();
        return(retCode);
    }

    *pSize = (ClUint32T)shmSize.shm_segsz;

    CL_FUNC_EXIT();
    return (CL_OK);
}
ClRcT
clTimerTypeGet (ClTimerHandleT timerHandle,
                ClUint32T* pTimerType)
{
    /* make sure the timer actually exists */
    TsTimer_t* pUserTimer = NULL;
    ClRcT returnCode;

    CL_FUNC_ENTER();
    pUserTimer = (TsTimer_t*) timerHandle;
    if (pUserTimer == NULL) {
        /* debug message */
        returnCode = CL_TIMER_RC(CL_ERR_INVALID_HANDLE);
        clDbgCodeError(returnCode, ("Bad timer handle"));
        CL_FUNC_EXIT();
        return (returnCode);
    }

    if (pTimerType == NULL) {
        CL_FUNC_EXIT();
        return (CL_ERR_UNSPECIFIED);
    }

    /* extract the timer-type from the timer */
    *pTimerType = pUserTimer->type;

    CL_FUNC_EXIT();
    return (CL_OK);
}
static ClRcT
cdbGDBMRecordReplace(ClDBHandleT      dbHandle, /* Handle to the database */
                     ClDBKeyT         dbKey,    /* Handle to the key being added */
                     ClUint32T       keySize,  /* Size of the key being added */
                     ClDBRecordT      dbRec,    /* Handle to the record being added */
                     ClUint32T       recSize)  /* Size of the record being added */
{
  ClRcT errorCode = CL_OK;
  GDBMHandle_t* pGDBMHandle = (GDBMHandle_t*)dbHandle;
  ClUint32T returnCode = 0;
  datum key = {NULL, 0};
  datum data = {NULL, 0};
  
  CL_FUNC_ENTER();
  key.dsize = keySize;
  key.dptr = (ClCharT *)dbKey;

  data.dsize = recSize;
  data.dptr = (ClCharT *)dbRec;

  /* Replace the record in the database */
  returnCode = gdbm_store(pGDBMHandle->gdbmInstance, key, data, GDBM_REPLACE);

  if(0 != returnCode) {
    /* Some GDBM error occured. return DB error */
    errorCode = CL_DBAL_RC(CL_DBAL_ERR_DB_ERROR);
    CL_DEBUG_PRINT ( CL_DEBUG_TRACE,("\nGDBM replace failed"));
    CL_FUNC_EXIT();
    return(errorCode);
  }

  CL_FUNC_EXIT();
  return(CL_OK);
}
/**
 *  Continue the extended state machine instance.
 *
 *  This API to be called if the state machine is paused
 *  and events are just being queued and not being 
 *  processed.  This API puts the state machine instance
 *  back in regular processing mode.
 *
 *  @param smThis State Machine Object
 *
 *  @returns 
 *    CL_OK on CL_OK (successful start) <br/>
 *    CL_SM_RC(CL_ERR_NULL_POINTER) on invalid/null instance handle <br/>
 *
 *  @see #clEsmInstancePause
 */
ClRcT
clEsmInstanceContinue(ClExSmInstancePtrT smThis
                    )
{
  ClRcT ret = CL_OK;
  CL_FUNC_ENTER();

  CL_ASSERT(smThis);

  if(smThis && smThis->fsm)
    {
      if(!(ESM_IS_PAUSED(smThis)))
      {
        ret = SM_ERR_NOT_PAUSED;
        CL_FUNC_EXIT();
        return ret;
      }
#ifdef DEBUG
      clLogTrace(ESM_LOG_AREA,CL_LOG_CONTEXT_UNSPECIFIED,"Continue [%s]", smThis->fsm->name);
#endif
      ESM_CONTINUE(smThis);
    } else 
      {
        ret = CL_SM_RC(CL_ERR_NULL_POINTER);
      }
  
  CL_FUNC_EXIT();
  return ret;

}
ClRcT
cosSysvShmSecurityModeGet(ClOsalShmIdT shmId,ClUint32T* pMode)
{
    struct shmid_ds shmPerm ;
    ClInt32T retCode = CL_OK;

    CL_FUNC_ENTER();
    if(NULL == pMode)
    {
        CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory SecurityModeGet: FAILED"));
        retCode = CL_OSAL_RC(CL_ERR_NULL_POINTER);
        CL_FUNC_EXIT();
        return(retCode);
    }

    /* Get the current values set and modify it */
    retCode = shmctl ((int)shmId, IPC_STAT, &shmPerm);

    if(0 != retCode)
    {
        CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory SecurityModeGet: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_MODE_GET);
        CL_FUNC_EXIT();
        return(retCode);
    }

    *pMode = shmPerm.shm_perm.mode;

    CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory SecurityModeGet: DONE"));
    CL_FUNC_EXIT();
    return (CL_OK);
}
ClRcT
cosSysvShmDetach(void* pMem)
{
    ClInt32T retCode =  CL_OK;

    CL_FUNC_ENTER();
    if(NULL == pMem)
    {
        CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory Detach: FAILED"));
        retCode = CL_OSAL_RC(CL_ERR_NULL_POINTER);
        CL_FUNC_EXIT();
        return(retCode);
    }

    retCode = shmdt (pMem);

    if(0 != retCode)
    {
        CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory Detach: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_DETACH);
        CL_FUNC_EXIT();
        return(retCode);
    }

    CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory Detach: DONE"));
    CL_FUNC_EXIT();
    return (CL_OK);
}
/*
 * Insert the class tab entry into the class id table.
 */
static ClRcT 
omClassEntryReload (ClCharT *pClassName, ClOmClassTypeT classId)
{
	ClRcT		rc = CL_OK;
    ClOmClassControlBlockT *pClassTab = NULL;
    ClCntNodeHandleT nodeHandle = 0;

    CL_FUNC_ENTER();

    if(!pClassName)
    {
        rc = CL_OM_SET_RC(CL_OM_ERR_NULL_PTR);
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("NULL PTR PASSED"));
        CL_FUNC_EXIT();
        return rc;
    }

	CL_DEBUG_PRINT(CL_DEBUG_TRACE, ("OM entry reload for class = %s, class type %d", pClassName, classId));

    /*
     * First check if the class id entry is already present in the om class id table.
     */
    if(clCntNodeFind(ghOmClassHashTbl, (ClCntKeyHandleT)(ClWordT)classId, &nodeHandle) == CL_OK)
        return CL_OK;

	/* Add this class entry into the OM class lookup table */
	rc = clCntNodeFind(ghOmClassNameHashTbl, (ClCntKeyHandleT)pClassName, &nodeHandle);
	if (rc != CL_OK)
    {
		CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Unable to find OM Class name [%s] entry in om class table",
                                        pClassName));
		return (rc);
    }
    
    rc = clCntNodeUserDataGet(ghOmClassNameHashTbl, nodeHandle, (ClCntDataHandleT*)&pClassTab);
    if(rc != CL_OK)
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Unable to get data for OM Class [%s] from om class name table",
                                        pClassName));
        return rc;
    }

    /*
     * Insert this entry into the class id table.
     */
    pClassTab->eMyClassType = classId;

    rc = clCntNodeAdd(ghOmClassHashTbl, (ClCntKeyHandleT)(ClWordT)pClassTab->eMyClassType,
                      (ClCntDataHandleT)pClassTab, NULL);
    if(rc != CL_OK)
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Unable to add entry [%#x] for class [%s] to OM class id table",
                                        classId, pClassName));
        return rc;
    }

   	CL_FUNC_EXIT();
	return (rc);
}
/*
 * This function clean up the information which is it has 
 * 1. Deregister with CPM. 
 * 2. Deregister with debug. 
 * 3. Deregister with CKPT
 * 4. Release the resources like Handle Databases, etc.
 */
ClRcT clEvtFinalize()
{
    ClRcT rc = CL_OK;


    CL_FUNC_ENTER();

    CL_EVT_INIT_DONE_VALIDATION();

    rc = clEoClientUninstallTables(gEvtHead.evtEOId, CL_EO_SERVER_SYM_MOD(gAspFuncTable, EVT));  
    if (rc != CL_OK)
    {
        CL_DEBUG_PRINT(CL_DEBUG_CRITICAL,
                       ("Event: EO Client Uninstall failed [0x%X]\n\r", rc));
        CL_FUNC_EXIT();
        return rc;
    }

    rc = clEventDebugDeregister(gEvtHead.evtEOId);
    if (rc != CL_OK)
    {
        CL_DEBUG_PRINT(CL_DEBUG_CRITICAL,
                       ("Event: Debug Deregister failed [0x%X]\n\r", rc));
        CL_FUNC_EXIT();
        return rc;
    }

    /*
     ** Handle Database Cleanup.
     */
    rc = clEvtHandleDatabaseExit();
    if (rc != CL_OK)
    {
        CL_DEBUG_PRINT(CL_DEBUG_CRITICAL,
                       ("Event: Handle Database Cleanup failed [0x%X]\n\r",
                        rc));
        CL_FUNC_EXIT();
        return rc;
    }

#ifdef CKPT_ENABLED
    /*
     ** Check Pointing Related Cleanup.
     */
    clEvtCkptExit();
    if (rc != CL_OK)
    {
        CL_DEBUG_PRINT(CL_DEBUG_CRITICAL,
                       ("Event Ckpt Exit failed [0x%X]\n\r", rc));
        CL_FUNC_EXIT();
        return rc;
    }
#endif

    CL_FUNC_EXIT();
    return CL_OK;
}
示例#12
0
/**
 *  Event Handling Function.
 *
 *  Handles the event at current state. Handles message at the current
 *  state. If the message/event is not handled at current state, then
 *  its passed to the parent and passed till 'top'. If its not
 *  handled, till top, then this method returns ERROR. else, the
 *  transition is handled. Transition, involves all exit method from
 *  bottom till LCA and execution of transition object function, and
 *  entry methods from LCA till the next state.
 *
 *  @param smThis Instance Object
 *  @param msg  Event that needs to be handled
 *
 *  @returns 
 *    CL_OK on CL_OK (successful transition) <br/>
 *    CL_SM_RC(CL_ERR_NULL_POINTER) on invalid/null instance/msg handle <br/>
 *    SM_ERR_EXIT_FAILED if the exit handler returned failure
 *    CL_SM_RC(CL_ERR_INVALID_STATE) unable to handle event at current state
 *
 */
ClRcT 
clHsmInstanceOnEvent(ClSmInstancePtrT smThis, 
                   ClSmEventPtrT msg
                   )
{
    ClSmStatePtrT curr;
    ClSmTransitionPtrT tO=0;
    ClRcT ret = CL_OK;
    
    CL_FUNC_ENTER();
    
    CL_ASSERT(smThis);
    CL_ASSERT(msg);
    
    if(!smThis || !smThis->sm || !smThis->current || !msg) 
      {
        ret = CL_SM_RC(CL_ERR_NULL_POINTER);
        CL_FUNC_EXIT();
        return ret;
      }

    for(curr=smThis->current;curr && !tO;)
      {
        
        /* check if the event is in event handler table
         */
        if(msg->eventId < (ClSmEventIdT)curr->maxEventTransitions && msg->eventId >= 0)
          {
            tO = curr->eventTransitionTable[msg->eventId].transition;
            break;
          }
        curr=curr->parent;
      }

    if(curr && tO)
      {
#ifdef DEBUG
        clLogTrace(HSM_LOG_AREA,HSM_LOG_CTX_EVENT,"StateMachine [%s] OnEvent [%d] in State [%d:%s]", 
                              smThis->name,
                              msg->eventId,
                              curr->type,
                              curr->name);
#else
        clLogTrace(HSM_LOG_AREA,HSM_LOG_CTX_EVENT,"OnEvent %d in state %d", 
                              msg->eventId,
                              curr->type);
#endif
        IGNORE_RETURN(_transition(smThis, tO, smThis->current, tO->nextState, msg));
      } 
    else
      {
        ret = CL_SM_RC(CL_ERR_INVALID_STATE);
      }
    
    CL_FUNC_EXIT();
    return ret;
}
static ClRcT
cdbGDBMNextRecordGet(ClDBHandleT      dbHandle,         /* Handle to the database */
                     ClDBKeyT         currentKey,       /* Handle to the current key */
                     ClUint32T       currentKeySize,   /* Size of the current key */
                     ClDBKeyT*        pDBNextKey,       /* pointer to handle in which the next key is returned */
                     ClUint32T*      pNextKeySize,     /* pointer to size in which the next key's size is returned */
                     ClDBRecordT*     pDBNextRec,       /* pointer to handle in which the next record is returned */
                     ClUint32T*      pNextRecSize)     /* pointer to size in which the next record's size is returned */
{
  ClRcT errorCode = CL_OK;
  GDBMHandle_t* pGDBMHandle = (GDBMHandle_t*)dbHandle;
  datum key = {NULL, 0};
  datum nextKey = {NULL, 0};
  datum data = {NULL, 0};

  CL_FUNC_ENTER();
  NULL_CHECK(pDBNextKey);
  NULL_CHECK(pNextKeySize);

  NULL_CHECK(pDBNextRec);
  NULL_CHECK(pNextRecSize);

  key.dsize = currentKeySize;
  key.dptr = (ClCharT *)currentKey;

  /* Retrieve the next key */
  nextKey = gdbm_nextkey(pGDBMHandle->gdbmInstance, key);

  if(NULL == nextKey.dptr) {
    /* The next key does not exist. So return error */
    errorCode = CL_DBAL_RC(CL_ERR_NOT_EXIST);
    CL_DEBUG_PRINT ( CL_DEBUG_TRACE,("\nGDBM get next key failed"));
    CL_FUNC_EXIT();
    return(errorCode);
  }

  *pDBNextKey = (ClDBKeyT)nextKey.dptr;
  *pNextKeySize = nextKey.dsize;

  /* retrieve the associated record */
  data = gdbm_fetch(pGDBMHandle->gdbmInstance, nextKey);

  if(NULL == data.dptr) {
    errorCode = CL_DBAL_RC(CL_ERR_NOT_EXIST);
    CL_DEBUG_PRINT ( CL_DEBUG_TRACE,("\nGDBM fetch record failed"));
    CL_FUNC_EXIT();
    return(errorCode);
  }
  
  *pDBNextRec = (ClDBRecordT)data.dptr;
  *pNextRecSize = data.dsize;

  CL_FUNC_EXIT();
  return(CL_OK);  

}
ClRcT
cosSysvSemCreate (ClUint8T* pName, ClUint32T count, ClOsalSemIdT* pSemId)
{
    ClInt32T retCode = CL_OK;
    CosSemCtl_t semArg = {0};
    ClUint32T len = 0;
    ClUint32T key = 0;
    ClInt32T semId = -1;

    nullChkRet(pSemId);
    nullChkRet(pName);

    CL_FUNC_ENTER();
    if ((count == 0) || count > CL_SEM_MAX_VALUE)
    {
        retCode = CL_OSAL_RC(CL_ERR_INVALID_PARAMETER);
        clDbgCodeError(retCode, ("Number of semaphores to create (count) [%d] must be between [1] and [%d]", count,  CL_SEM_MAX_VALUE));
        CL_FUNC_EXIT();
        return(retCode);
    }

    len = (ClUint32T)strlen ((ClCharT*)pName);

#if 0 /* Stone: why this limitation? */
    if(len > 20)
        if(len > 256)
        {
            CL_DEBUG_PRINT (CL_DEBUG_INFO,("Sanity check, semaphore name length is suspiciously long"));
            retCode = CL_OSAL_RC(CL_OSAL_ERR_NAME_TOO_LONG);
            CL_FUNC_EXIT();
            return(retCode);
        }
#endif

    if(len > 256)
    {
        CL_DEBUG_PRINT (CL_DEBUG_INFO,("Sanity check, semaphore name [%s] is suspiciously long",pName));
    }

    retCode = (ClInt32T)clCrc32bitCompute (pName, len, &key, NULL);
    CL_ASSERT(retCode == CL_OK); /* There is no possible error except for pName == NULL, which I've already checked, so don't check the retCode */


    sysErrnoChkRet(semId = semget ((key_t)key, (int)count, IPC_CREAT|0666));

    semArg.val = (int)count;

    /* Initialize all the semaphores to 0.  This should never fail, because I just created the semaphores */
    sysErrnoChkRet(semctl (semId, 0, SETVAL, semArg));

    *pSemId = (ClOsalSemIdT)semId;

    CL_FUNC_EXIT();
    return (CL_OK);
}
ClRcT
cosSysvShmIdGet(ClUint8T* pName, ClOsalShmIdT* pShmId)
{
    ClUint32T key = 0;
    ClUint32T len = 0;
    ClUint32T size = 0;
    ClInt32T shmId = 0;
    ClRcT retCode = CL_OK;

    CL_FUNC_ENTER();
    if(NULL == pShmId)
    {
        CL_DEBUG_PRINT (CL_DEBUG_INFO,("\nShared Memory ID Get: FAILED"));
        retCode = CL_OSAL_RC(CL_ERR_NULL_POINTER);
        CL_FUNC_EXIT();
        return(retCode);
    }

    if(NULL == pName)
    {
        CL_DEBUG_PRINT (CL_DEBUG_INFO,("\nShared Memory ID Get: FAILED"));
        retCode = CL_OSAL_RC(CL_ERR_NULL_POINTER);
        CL_FUNC_EXIT();
        return(retCode);
    }

    len = (ClUint32T)strlen ((ClCharT*)pName);

    retCode = clCrc32bitCompute (pName, len, &key, NULL);

    if(CL_OK != retCode)
    {
        CL_DEBUG_PRINT (CL_DEBUG_INFO,("\nShared Memory ID Get: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_ID_GET);
        CL_FUNC_EXIT();
        return(retCode);
    }

    shmId = shmget ((key_t)key, size, (0666 | IPC_CREAT));

    if(shmId < 0)
    {
        CL_DEBUG_PRINT (CL_DEBUG_INFO,("\nShared Memory ID Get: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_ID_GET);
        CL_FUNC_EXIT();
        return(retCode);
    }

    *pShmId = (ClOsalShmIdT)shmId;

    CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory ID Get: DONE"));
    CL_FUNC_EXIT();
    return (CL_OK);
}
/**
 *  Add event to the event q.
 *
 *  API to add event to the state machine instance queue.  The
 *  event properties are copied (a new event is created and 
 *  the contents of the event passed a re copied to the new 
 *  event), but the payload is just referenced and not copied.
 *  
 *  @param smThis Extended State machine Instance handle
 *  @param msg  Event information
 *
 *  @returns 
 *    CL_OK on CL_OK <br/>
 *    CL_SM_RC(CL_ERR_NO_MEMORY) on memory allocation FAILURE <br/>
 *    CL_SM_RC(CL_ERR_NULL_POINTER) on invalid/null instance handle <br/>
 *
 *  @see #clEsmInstanceProcessEvent
 *  @see #clEsmInstanceProcessEvents
 *
 */
ClRcT
clEsmInstanceEventAdd(ClExSmInstancePtrT smThis, 
                    ClSmEventPtrT msg
                    )
{
  ClRcT ret = CL_OK;

  CL_FUNC_ENTER();

  CL_ASSERT(smThis);
  CL_ASSERT(msg);

  if(smThis && msg)
    {
      ClSmQueueItemPtrT item;

      item = (ClSmQueueItemPtrT) mALLOC(sizeof(ClSmQueueItemT)); 
      if(!item)
        {
          ret = CL_SM_RC(CL_ERR_NO_MEMORY);
        }
      else 
        {
          if(ESM_LOCK(smThis)!=CL_OK)
            {
              ret = SM_ERR_LOCKED;
              mFREE(item);
              CL_FUNC_EXIT();
              return ret;
            }
          item->event = *msg;
          if (ESM_IS_PAUSED(smThis) && ESM_IS_DROP_ON_PAUSE(smThis))
          {
              ret = CL_OK;
              mFREE(item);
              ESM_UNLOCK(smThis);
              CL_FUNC_EXIT();
              return ret;
          }
          ret = SMQ_ENQUEUE(smThis->q, item);
          clLogTrace(ESM_LOG_AREA,ESM_LOG_CTX_EVENT,"Event %d added => ret [%d]",
                                item->event.eventId,
                                ret);
          ESM_UNLOCK(smThis);
        }
    } else 
      {
        ret = CL_SM_RC(CL_ERR_NULL_POINTER);
      }

  CL_FUNC_EXIT();
  return ret;
}
ClRcT
clTimerDelete (ClTimerHandleT*  pTimerHandle)
{
    TsTimer_t* pUserTimer = NULL;
    ClRcT returnCode = CL_ERR_INVALID_HANDLE;

    CL_FUNC_ENTER();
    if (NULL == pTimerHandle) {
        returnCode = CL_TIMER_RC(CL_ERR_NULL_POINTER);
        clDbgCodeError(returnCode, ("Bad timer handle storage"));
        CL_FUNC_EXIT();
        return (returnCode);
    }

    pUserTimer = (TsTimer_t*) *pTimerHandle;
    if (pUserTimer == NULL) {
        returnCode = CL_TIMER_RC(CL_ERR_INVALID_HANDLE);
        clDbgCodeError(returnCode, ("Bad timer handle"));
        CL_FUNC_EXIT();
        return (returnCode);
    }
    if (pUserTimer->state == TIMER_FREE) {
        returnCode = CL_TIMER_RC(CL_TIMER_ERR_INVALID_TIMER);
        clDbgCodeError(returnCode, ("Double delete of a timer"));
        CL_FUNC_EXIT();
        return (returnCode);
    }

    /* if timer is active, remove it from the active-timers queue */
    returnCode = clTimerStop (*pTimerHandle);

    if (returnCode != CL_OK) {
        CL_DEBUG_PRINT (CL_DEBUG_WARN, ("\nTimer delete failed"));
        CL_FUNC_EXIT();
        return (returnCode);
    }

    /* null out all the values */
    pUserTimer->fpTimeOutAction = NULL;
    pUserTimer->pActionArgument = NULL;
    pUserTimer->state = TIMER_FREE;
    pUserTimer->pNextActiveTimer = NULL; /* valid only for active timers */
    pUserTimer->pPreviousActiveTimer = NULL; /* valid only for active timers */

    /* return timer to the free pool */
    tsFreeTimerReturn (pUserTimer);

    *pTimerHandle = NULL;

    CL_FUNC_EXIT();
    return (CL_OK);
}
static ClRcT
cdbGDBMFirstRecordGet(ClDBHandleT      dbHandle,    /* Handle to the database */
                      ClDBKeyT*        pDBKey,      /* Pointer to handle in which the key handle is returned */
                      ClUint32T*      pKeySize,    /* Pointer to size, in which the size of the key is returned */
                      ClDBRecordT*     pDBRec,      /* Pointer to handle in which the record handle is returned */
                      ClUint32T*      pRecSize)    /* Pointer to size, in which the size of the record is returned */
{
  ClRcT errorCode = CL_OK;
  GDBMHandle_t* pGDBMHandle = (GDBMHandle_t*)dbHandle;
  datum key = {NULL, 0};
  datum data = {NULL, 0};

  CL_FUNC_ENTER();
  NULL_CHECK(pDBKey);
  NULL_CHECK(pKeySize);

  NULL_CHECK(pDBRec);
  NULL_CHECK(pRecSize);

  /* Retrieve the first key in the database */  
  key = gdbm_firstkey(pGDBMHandle->gdbmInstance);

  if(NULL == key.dptr) {
    /* The first key does exist. So return error */
    errorCode = CL_DBAL_RC(CL_ERR_NOT_EXIST);
    CL_DEBUG_PRINT ( CL_DEBUG_TRACE,("\nGDBM record get failed"));
    CL_FUNC_EXIT();
    return(errorCode);
  }

  *pDBKey = (ClDBKeyT)key.dptr;
  *pKeySize = key.dsize;

  /* Retrieve the associated record in the database */
  data = gdbm_fetch(pGDBMHandle->gdbmInstance, key);

  if(NULL == data.dptr) {
    errorCode = CL_DBAL_RC(CL_ERR_NOT_EXIST);
    CL_DEBUG_PRINT ( CL_DEBUG_TRACE,("\nGDBM record fetch failed"));
    CL_FUNC_EXIT();
    return(errorCode);
  }
  
  *pDBRec = (ClDBRecordT)data.dptr;
  *pRecSize = data.dsize;

  CL_FUNC_EXIT();
  return(CL_OK);  

}
示例#19
0
ClRcT
cosPosixSemCreate (ClUint8T* pName, ClUint32T count, ClOsalSemIdT* pSemId)
{
    ClInt32T rc = CL_OK;
    sem_t *pSem = NULL;
    ClInt32T semValue = 0;
    ClInt32T i = 0;
    
    nullChkRet(pSemId);
    nullChkRet(pName);

    CL_FUNC_ENTER();
    if ((count == 0) || count > CL_SEM_MAX_VALUE)
    {
        rc = CL_OSAL_RC(CL_ERR_INVALID_PARAMETER);
        clDbgCodeError(rc, ("Number of semaphores to create (count) [%d] must be between [1] and [%d]", count,  CL_SEM_MAX_VALUE));
        CL_FUNC_EXIT();
        return(rc);
    }

    pSem = sem_open((ClCharT*)pName, O_CREAT, 0777, count);
    if(pSem == SEM_FAILED)
    {
        rc = CL_OSAL_RC(CL_ERR_LIBRARY); 
        clDbgCodeError(rc, ("Failed at sem_open. system error code %d.\n", errno));
        return rc;
    }

    sem_getvalue(pSem, &semValue);

    if (semValue < (ClInt32T)count)
    {
        for (i = semValue; i < (ClInt32T)count; ++i)
        {
            sem_post(pSem);
        }
    }
    else
    {
        for (i = count; i < semValue; ++i)
        {
            sem_wait(pSem);
        }
    }

    *pSemId = *(ClOsalSemIdT*)&pSem;

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

    CL_FUNC_ENTER();

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

    sock = socket(PF_INET, SOCK_DGRAM, 0);
    if (sock == -1)
    {
        clOsalPrintf("Failed to open socket");
        return CL_OSAL_ERR_OS_ERROR;
    }
//    if (connect(sock, &instaddr, sizeof addr) != 0)
//    {
//        clOsalPrintf("Failed to connect socket to %s/%s\n", ipaddr, port);
//        close(sock);
//        sock = -1;
//        CL_FUNC_EXIT();
//        return CL_OSAL_ERR_OS_ERROR;
//    }
    CL_FUNC_EXIT();
    return CL_OK;
}
ClRcT 
clCorDataFrequentSave(char *pFileName, ClTimerTimeOutT  frequency)
{
    ClRcT  rc = CL_OK;
    corPersisInfo_t corData;

	memset(&corData, 0, sizeof(corData));
    CL_FUNC_ENTER();
    CL_DEBUG_PRINT(CL_DEBUG_TRACE,("\n Inside clCorDataFrequentSave \n"));

    /* Validate input parameters */
    if (pFileName == NULL)
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, ( "clCorDataFrequentSave: NULL argument"));
        CL_FUNC_EXIT();
        return(CL_COR_SET_RC(CL_COR_ERR_NULL_PTR));
    }
    if (strlen(pFileName) >= COR_MAX_FILENAME_LEN)
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, ( "clCorDataFrequentSave: File name is too large"));
        CL_FUNC_EXIT();
        return(CL_COR_SET_RC(CL_COR_ERR_INVALID_PARAM));
    }


    /*memcpy(corData.fileName, (pFileName), sizeof(corData.fileName));*/
    memcpy(corData.fileName, (pFileName), strlen(pFileName)+1);
    /* corData.version   = CL_COR_VERSION_NO; */
	CL_COR_VERSION_SET(corData.version);
    corData.operation = COR_DATA_FREQ_SAVE;
    corData.frequency = frequency;
    
    COR_CALL_RMD(COR_EO_PERSISTENCY_OP,
                 VDECL_VER(clXdrMarshallcorPersisInfo_t, 4, 0, 0),
                 &corData,
                 sizeof(corData), 
                 VDECL_VER(clXdrUnmarshallcorPersisInfo_t, 4, 0, 0),
                 NULL,
                 NULL,
                 rc);
    if(rc != CL_OK)
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, ( "clCorDataFrequentSave returns error,rc=%x",rc));
    }

    
    CL_FUNC_EXIT();
    return rc;
}
ClRcT
cosSysvShmSecurityModeSet(ClOsalShmIdT shmId,ClUint32T mode)
{
    struct shmid_ds shmPerm ;
    ClInt32T retCode = CL_OK;

    CL_FUNC_ENTER();

    /* Basically we dont want to allow RWX on User,Group and others (Nothing
     * greater than 111 111 111 (0777). Eight is for calculating the number of
     * bytes.9 is the number of bits that will used for RWX RWX RWX for
     * User Group Others.
     */

    if(mode & (((~(1 << ((sizeof(int) *8)- 1))))<< 9))
    {
        CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory SecurityModeSet: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_MODE_SET);
        CL_FUNC_EXIT();
        return(retCode);
    }

    /* Get the current values set and modify it */
    retCode = shmctl ((int)shmId, IPC_STAT, &shmPerm);

    if(0 != retCode)
    {
        CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory SecurityModeSet: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_MODE_SET);
        CL_FUNC_EXIT();
        return(retCode);
    }

    shmPerm.shm_perm.mode = (unsigned short int)mode;

    retCode = shmctl ((int)shmId, IPC_SET, &shmPerm);

    if(0 != retCode)
    {
        CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory SecurityModeSet: FAILED"));
        retCode = CL_OSAL_RC(CL_OSAL_ERR_SHM_MODE_SET);
        CL_FUNC_EXIT();
        return(retCode);
    }

    CL_DEBUG_PRINT (CL_DEBUG_TRACE,("\nShared Memory SecurityModeSet: DONE"));
    CL_FUNC_EXIT();
    return (CL_OK);
}
ClRcT clHalLibInitialize()
{
    ClRcT rc= CL_OK ; 
    CL_FUNC_ENTER();
    if (CL_TRUE == halInitDone)
    {
        clLogCritical(CL_LOG_AREA_UNSPECIFIED,CL_LOG_CONTEXT_UNSPECIFIED,"\n clHalLibInitialize Called Again \n");
        CL_FUNC_EXIT();
        return (CL_HAL_SET_RC(CL_ERR_INVALID_STATE));
    }
#ifdef DEBUG
    rc= dbgAddComponent(COMP_PREFIX, COMP_NAME, COMP_DEBUG_VAR_PTR);
    if (CL_OK != rc)
    {
        clLogError(CL_LOG_AREA_UNSPECIFIED,CL_LOG_CONTEXT_UNSPECIFIED,"dbgAddComponent Failed \n ");
        CL_FUNC_EXIT();
        return rc;
    }
#endif
    
    memset(&halDevObjTable,0, sizeof(HalDeviceObjTableT));

    halDevObjTable.pphalDeviceObj=(HalDeviceObjectT **)clHeapAllocate((halConfig.
        halNumDevObject)*sizeof(HalDeviceObjectT *));

    if (NULL == halDevObjTable.pphalDeviceObj)
    {
        clLogCritical(CL_LOG_AREA_UNSPECIFIED,CL_LOG_CONTEXT_UNSPECIFIED,"\n clHalLibInitialize Error no memory HAL\n");
        CL_FUNC_EXIT();
        return(CL_HAL_SET_RC(CL_ERR_NO_MEMORY));
    }

    memset(halDevObjTable.pphalDeviceObj,0, ((halConfig.
        halNumDevObject)*sizeof(HalDeviceObjectT *)));
        
    halInitDone = CL_TRUE; 

    /* Create device object(s) from the Configuration Info */
    rc = halDevObjTableCreate ();
    if (rc != CL_OK)
    {
        clLogCritical(CL_LOG_AREA_UNSPECIFIED,CL_LOG_CONTEXT_UNSPECIFIED,"\n halDevObjTableCreate  Failed");
        CL_FUNC_EXIT();
        return rc ;
    }
    clLogTrace(CL_LOG_AREA_UNSPECIFIED,CL_LOG_CONTEXT_UNSPECIFIED,"\nclHalLibInitialize CL_OK\n");
    CL_FUNC_EXIT();
    return (CL_OK) ;
}
/**
 * get DM Handle from given ClCorMOId
 */
ClRcT
moId2DMHandle(ClCorMOIdPtrT path,
              DMObjHandle_h dmh)
{
    ObjTreeNode_h obj;
    CORObject_h dmObj;

    CL_FUNC_ENTER();
    
    if(!path || !dmh)
    {
        CL_FUNC_EXIT();
        return CL_COR_SET_RC(CL_COR_ERR_NULL_PTR);
    }
    memset(dmh,0,sizeof(DMObjHandle_t));
    obj = corMOObjGet(path);
    if(obj)
    {
        ClCorMOServiceIdT svcId=(path)->svcId;
        
        dmObj = obj->data;
        if(svcId!=CL_COR_INVALID_SRVC_ID)
        { 
            dmObj=corMSOObjGet(obj, svcId);
        } 

        if (dmObj != NULL && dmObj->dmObjH.classId != 0)
        {
            (dmh)->classId = dmObj->dmObjH.classId;
            (dmh)->instanceId = dmObj->dmObjH.instanceId;
        }
        else
        {
            clLogInfo("COR", "OBH", 
                    "The Dm object node doesn't exist. rc[0x%x]", CL_COR_SET_RC(CL_COR_INST_ERR_INVALID_MOID));
            return CL_COR_SET_RC(CL_COR_INST_ERR_INVALID_MOID);
        }
    } 
    else
    {
	    clLogInfo("COR", "OBJ", 
                "The object node doesn't exist in the object tree. rc [0x%x]", CL_COR_SET_RC(CL_COR_INST_ERR_INVALID_MOID));
	    return CL_COR_SET_RC(CL_COR_INST_ERR_INVALID_MOID);
    }

    CL_FUNC_EXIT();
    return CL_OK;
}
ClRcT 
clCorDataSave()
{
    ClRcT  rc = CL_OK;
    corPersisInfo_t corData;

	memset(&corData, 0, sizeof(corData));
    CL_FUNC_ENTER();
    CL_DEBUG_PRINT(CL_DEBUG_TRACE,("\n Inside clCorDataSave \n"));

    /* corData.version   = CL_COR_VERSION_NO; */
	CL_COR_VERSION_SET(corData.version);
    corData.operation = COR_DATA_SAVE;
    
    COR_CALL_RMD(COR_EO_PERSISTENCY_OP,
                 VDECL_VER(clXdrMarshallcorPersisInfo_t, 4, 0, 0),
                 &corData,
                 sizeof(corData), 
                 VDECL_VER(clXdrUnmarshallcorPersisInfo_t, 4, 0, 0),
                 NULL,
                 NULL,
                 rc);
    if(rc != CL_OK)
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR, ( "clCorDataSave returns error,rc=%x",rc));
    }

    
    CL_FUNC_EXIT();
    return rc;
}
/**
 * Delete the data-set created for a transaction
 */
ClRcT clTxnServiceCkptTxnDelete(
    CL_IN   ClTxnTransactionIdT     serverTxnId)
{
    ClRcT   rc  = CL_OK;
    if(!clTxnServiceCfg->dsblCkpt)
    {
        SaNameT     txnCkptName;

        CL_FUNC_ENTER();

        txnCkptName.length = strlen(CL_TXN_CKPT_NAME) + 1;
        memset(&(txnCkptName.value[0]), '\0', txnCkptName.length);
        strncpy(&(txnCkptName.value[0]), CL_TXN_CKPT_NAME, txnCkptName.length);

        CL_DEBUG_PRINT(CL_DEBUG_TRACE, ("Deleting transaction [0x%x:0x%x] from checkpoint",
                                        serverTxnId.txnMgrNodeAddress, serverTxnId.txnId));

        /* First initialize the data-set */
        rc = clCkptLibraryCkptDataSetDelete(clTxnServiceCfg->txnCkptHandle,
                                            &txnCkptName,
                                            serverTxnId.txnId + CL_TXN_CKPT_TXN_DATA_SET_ID_OFFSET);
    }

    CL_FUNC_EXIT();
    return (rc);
}
/**
 * API to restore recovery logs of previously active transactions
 * from check-point
 */
ClRcT clTxnServiceCkptRecoveryLogRestore()
{
    ClRcT       rc = CL_OK;
    if(!clTxnServiceCfg->dsblCkpt)
    {
        SaNameT     txnCkptName;

        CL_FUNC_ENTER();

        txnCkptName.length = strlen(CL_TXN_CKPT_NAME) + 1;
        memset(&(txnCkptName.value[0]), '\0', txnCkptName.length);
        strncpy(&(txnCkptName.value[0]), CL_TXN_CKPT_NAME, txnCkptName.length);

        CL_DEBUG_PRINT(CL_DEBUG_TRACE, ("Restoring transaction-recovery logs"));

        /* AD-1: To use the checkpoint exists api to check whether its recovery or
         * normal startup */
        clLogDebug("SER", NULL,
                   "Checkpoint exists, reading data for recovery");
        rc = clCkptLibraryCkptDataSetRead(clTxnServiceCfg->txnCkptHandle, &txnCkptName,
                                          CL_TXN_RECOVERY_DATA_SET, 0x0);

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

    CL_FUNC_EXIT();
    return (rc);
}
/**
 * API to delete checkpoint recovery-log details of a given transaction.
 */
ClRcT clTxnServiceCkptRecoveryLogCheckpointDelete(
    CL_IN   ClTxnTransactionIdT     txnId)
{
    ClRcT   rc  = CL_OK;
    if(!clTxnServiceCfg->dsblCkpt)
    {
        SaNameT     txnCkptName;
        ClCharT     elementName[200];

        CL_FUNC_ENTER();

        txnCkptName.length = strlen(CL_TXN_CKPT_NAME) + 1;
        memset(&(txnCkptName.value[0]), '\0', txnCkptName.length);
        strncpy(&(txnCkptName.value[0]), CL_TXN_CKPT_NAME, txnCkptName.length);

        elementName[0] = '\0';
        sprintf(elementName, "TXN_%x_%x", txnId.txnMgrNodeAddress, txnId.txnId);

        rc = clCkptLibraryCkptElementDelete (clTxnServiceCfg->txnCkptHandle,
                                             &txnCkptName, CL_TXN_RECOVERY_DATA_SET,
                                             elementName, (strlen(elementName) + 1));
        if (CL_OK != rc)
        {
            CL_DEBUG_PRINT(CL_DEBUG_ERROR,
                           ("Failed to delete element of txn-recovery data for txn 0x%x:0x%x, rc:0x%x",
                            txnId.txnMgrNodeAddress, txnId.txnId, rc));
            rc = CL_GET_ERROR_CODE(rc);
        }
    }

    CL_FUNC_EXIT();
    return (rc);
}
/**
 * API to restore status of transaction-service from check-point
 */
ClRcT clTxnServiceCkptAppStateRestore()
{
    ClRcT       rc = CL_OK;
    if(!clTxnServiceCfg->dsblCkpt)
    {
        SaNameT     txnCkptName;

        CL_FUNC_ENTER();

        txnCkptName.length = strlen(CL_TXN_CKPT_NAME) + 1;
        memset(&(txnCkptName.value[0]), '\0', txnCkptName.length);
        strncpy(&(txnCkptName.value[0]), CL_TXN_CKPT_NAME, txnCkptName.length);

        CL_DEBUG_PRINT(CL_DEBUG_TRACE, ("Restoring transaction-service state"));

        clLogDebug("SER", NULL,
                   "Ckpt exists, reading data");
        rc = clCkptLibraryCkptDataSetRead(clTxnServiceCfg->txnCkptHandle, &txnCkptName,
                                          CL_TXN_SERVICE_DATA_SET, 0x0);

        if (CL_OK != rc)
        {
            clLogError("SER", NULL,
                       "Failed to restore transaction-service state, rc [0x%x]", rc);
            rc = CL_GET_ERROR_CODE(rc);
        }
    }

    CL_FUNC_EXIT();
    return (rc);
}
/**
 * API to checkpoint current state of transaction-service
 */
ClRcT clTxnServiceCkptAppStateCheckpoint()
{
    ClRcT rc = CL_OK;
    if(!clTxnServiceCfg->dsblCkpt)
    {
        SaNameT     txnCkptName;

        CL_FUNC_ENTER();

        txnCkptName.length = strlen(CL_TXN_CKPT_NAME) + 1;
        memset(&(txnCkptName.value[0]), '\0', txnCkptName.length);
        strncpy(&(txnCkptName.value[0]), CL_TXN_CKPT_NAME, txnCkptName.length);

        rc = clCkptLibraryCkptDataSetWrite(clTxnServiceCfg->txnCkptHandle, &txnCkptName,
                                           CL_TXN_SERVICE_DATA_SET, 0x0);

        if (CL_OK != rc)
        {
            CL_DEBUG_PRINT(CL_DEBUG_ERROR, ("Failed to write data-set [0x%x], rc:0x%x",
                                            CL_TXN_SERVICE_DATA_SET, rc));
            rc = CL_GET_ERROR_CODE(rc);
        }
    }

    CL_FUNC_EXIT();
    return (rc);
}