static ClRcT clAmsListHeadInit(ClAmsListHeadT *pList)
{
    ClRcT rc;

    clOsalMutexInit(&pList->mutex);
    rc = clOsalCondInit(&pList->cond);
    if(rc != CL_OK)
    {
        clLogError("AMS", "INIT", "Failed to create a condtional variable. error code [0x%x].", rc);
        clOsalMutexDestroy(&pList->mutex);
        return rc;
    }
    pList->numElements = 0;
    CL_LIST_HEAD_INIT(&pList->list);
    return CL_OK;
}
ClRcT 
clLogUtilLibInitialize(void)
{
    ClRcT  rc = CL_OK;
    ClCharT *pEOName = NULL;
    if( gUtilLibInitialized == CL_TRUE )
    {
        return CL_OK;
    }
    rc = clOsalMutexErrorCheckInit(&gLogMutex);
    if( CL_OK != rc )
    {
        fprintf(stderr, "Mutex init failed rc[0x %x]\n", rc);
        return rc;
    }
    rc = clOsalCondInit(&gLogCond);
    if( CL_OK != rc )
    {
        fprintf(stderr, "Cond init failed rc[0x %x]\n", rc);
        clOsalMutexDestroy(&gLogMutex);
        return rc;
    }
    pEOName = CL_EO_NAME;
    if(pEOName && !strncasecmp(pEOName, "LOG", 3))
    {
        gClLogServer = CL_TRUE;
    }

    clLogDebugFilterInitialize();

    gUtilLibInitialized = CL_TRUE;
    rc = clOsalTaskCreateAttached((ClCharT *)CL_LOG_UTIL_TASK_NAME, CL_OSAL_SCHED_OTHER,
            CL_OSAL_THREAD_PRI_NOT_APPLICABLE, CL_OSAL_MIN_STACK_SIZE,
            clLogDeferredHandler, NULL, &taskId);
    if( CL_OK != rc )
    {
        fprintf(stderr, "Thread creation failed rc[0x %x]", rc);
        clOsalCondDestroy(&gLogCond);
        clOsalMutexDestroy(&gLogMutex);
        return rc;
    }
    
    return CL_OK;
}
void clPyGlueInit(char* appModule,void (*init_extensions[])(void),int argc, char**argv)
{
  char buf[1024];
  ClRcT rc;
    Py_Initialize();
    PySys_SetArgv(argc, argv);
    PyEval_InitThreads();
    
    if (init_extensions) 
      {
        int i = 0;
        for(i=0; init_extensions[i]!=NULL; i++) (*init_extensions[i])();
      }
    thrdState = PyThreadState_Get();

    rc = clOsalMutexInit(&pyMutex);
    CL_ASSERT(rc==CL_OK); 

    rc = clOsalCondInit(&event);
    CL_ASSERT(rc==CL_OK); 

    rc = clOsalMutexLock(&pyMutex);
    CL_ASSERT(rc==CL_OK); 

    PyThreadState_Swap(thrdState);

    PyRun_SimpleString("import os, os.path, sys\n");
    snprintf(buf,1024,"sys.path.append(os.path.realpath('%s'))\n",CL_APP_BINDIR);
    clprintf(CL_LOG_SEV_INFO, buf);
    PyRun_SimpleString(buf);
    //PyRun_SimpleString("sys.path.append(os.path.realpath('../../bin'))\n");
    snprintf(buf,1024,"from %s import *\n",appModule);
    clprintf(CL_LOG_SEV_INFO, buf);
    PyRun_SimpleString(buf);

    PyThreadState_Swap(NULL);
    PyEval_ReleaseLock();

    rc=clOsalMutexUnlock(&pyMutex);
    CL_ASSERT(rc==CL_OK); 

}
예제 #4
0
static ClRcT initializeAmf(void)
{
    ClRcT         rc = CL_OK; 
    ClRcT         retCode;
    ClIocPhysicalAddressT notificationForComp = { CL_IOC_BROADCAST_ADDRESS, 0};
    
    clLogCompName = (ClCharT*) "MSG"; /* Override generated eo name with a short name for our server */
    clAppConfigure(&clEoConfig,clEoBasicLibs,clEoClientLibs);
  
    clMsgRegisterWithCpm();
     
    if(gClMsgInit == CL_TRUE)
    {
        rc = CL_MSG_RC(CL_ERR_INITIALIZED);
        clLogError("MSG", "INI", "The Message Service is already initialized. error code [0x%x].", rc);
        goto error_out;
    }
    
    gLocalAddress = clIocLocalAddressGet();
    gLocalPortId = CL_IOC_MSG_PORT;

    /* Initializing a database to maintain client information */
    rc = clHandleDatabaseCreate((void (*)(void*))NULL, &gMsgClientHandleDb);
     
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to initialize the handle database. error code [0x%x].", rc);
        goto error_out;
    }
    
    /* Initializing IDL for server to server and server to client communication. */
    rc = clMsgCommIdlInitialize();
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to initialize the IDL. error code [0x%x].", rc);
        goto error_out_2;
    }
    
    /* Initializing a database for maintaining queues. */
    rc = clMsgQueueInitialize();
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to initialize the queue databases. error code [0x%x].", rc);
        goto error_out_3;
    }
   
    rc = clMsgReceiverDatabaseInit();
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to initialize \"receiver database\". error code [0x%x].", rc);
        goto error_out_4;
    }

    rc = clOsalMutexInit(&gClMsgFinalizeLock);
    CL_ASSERT(rc == CL_OK);
    
    rc = clOsalCondInit(&gClMsgFinalizeCond);
    CL_ASSERT(rc == CL_OK);

    /* Initializing the Group-Information */
    rc = clOsalMutexInit(&gClGroupDbLock);
    CL_ASSERT(rc == CL_OK);

    rc = clCpmNotificationCallbackInstall(notificationForComp, &clMsgNotificationReceiveCallback, NULL, &gMsgNotificationHandle);
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to install the notification callback function. error code [0x%x].", rc);
        goto error_out_5;
    }
   
    /* Initializing the IDL generated code. */
    rc = clMsgIdlClientInstall();
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to install Server Table. error code [0x%x].", rc);
        goto error_out_6;
    }

    rc = clMsgIdlClientTableRegister(CL_IOC_MSG_PORT);
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to register Server Table. error code [0x%x].", rc);
        goto error_out_7;
    }

    rc = clMsgCltClientTableRegister(CL_IOC_MSG_PORT);
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to register Client Table. error code [0x%x].", rc);
        goto error_out_8;
    }

    rc = clMsgCltSrvClientInstall();
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to install Client Server Table. error code [0x%x].", rc);
        goto error_out_9;
    }
  
    rc = clMsgCltSrvClientTableRegister(CL_IOC_MSG_PORT);
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to register Client Server Table. error code [0x%x].", rc);
        goto error_out_10;
    }

    rc = clMsgFinalizeBlockInit();
    if(rc != CL_OK)
    {
        clLogError("MSG", "INI", "Failed to initialize the msg-finalize blocker. error code [0x%x].", rc);
        goto error_out_11;
    }
   
    clMsgDebugCliRegister();

    rc = clOsalTaskCreateDetached("MsgCkptInitAsync", CL_OSAL_SCHED_OTHER, CL_OSAL_THREAD_PRI_NOT_APPLICABLE, 0,
                                 clMsgCachedCkptInitAsync, NULL);
    CL_ASSERT(rc == CL_OK);

    goto out;
error_out_11:
    retCode = clMsgCltSrvClientTableDeregister();
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to deregister Client Table. error code [0x%x].", retCode);
error_out_10:
    retCode = clMsgCltSrvClientUninstall();
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to destroy the just opened handle database. error code [0x%x].", retCode);
error_out_9:
    retCode = clMsgCltClientTableDeregister();
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to deregister Client Table. error code [0x%x].", retCode);
error_out_8:
    retCode = clMsgIdlClientTableDeregister();
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to deregister Server Table. error code [0x%x].", retCode);
error_out_7:
    retCode = clMsgIdlClientUninstall();
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to destroy the just opened handle database. error code [0x%x].", retCode);
error_out_6:
    retCode = clCpmNotificationCallbackUninstall(&gMsgNotificationHandle);
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to uninstall the notification callback function. error code [0x%x].", retCode);
error_out_5:
    retCode = clOsalMutexDestroy(&gClGroupDbLock);
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to destroy the group db mutex. error code [0x%x].", retCode);

    retCode = clOsalCondDestroy(&gClMsgFinalizeCond);
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to destroy the finalization condition. error code [0x%x].", retCode);

    retCode = clOsalMutexDestroy(&gClMsgFinalizeLock);
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to destroy the finalization mutex. error code [0x%x].", retCode);

    clMsgReceiverDatabaseFin();

error_out_4:
    retCode = clMsgQueueFinalize();
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to finalize the queue databases. error code [0x%x].", retCode);
error_out_3:
    clMsgCommIdlFinalize();
error_out_2:
    retCode = clHandleDatabaseDestroy(gMsgClientHandleDb);
    if(retCode != CL_OK)
        clLogError("MSG", "INI", "Failed to destroy the handle database. error code [0x%x].", retCode);
error_out:
out:
    return rc;  
    
}//end of intializeAmf
ClRcT clEoQueueCreate(ClEoQueueHandleT *pHandle,
                      ClIocPriorityT priority,
                      ClThreadPoolModeT mode,
                      ClInt32T maxThreads,
                      ClInt32T threadPriority,
                      ClEoJobCallBackT pJobHandler,
                      ClPtrT pUserData
                      )
{
    ClEoQueueT *pQueue =NULL;
    ClThreadPoolHandleT threadPool=0;
    ClRcT rc = CL_EO_RC(CL_ERR_INVALID_PARAMETER);

    if(pHandle == NULL)
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Invalid parameter\n"));
        goto out;
    }

    if( priority >= CL_IOC_MAX_PRIORITIES )
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Invalid priority %d\n",priority));
        goto out;
    }

    rc = CL_EO_RC(CL_ERR_OP_NOT_PERMITTED);

    CL_EO_QUEUE_LOCK(&gClEoQueueMutex);
    if(gpClEoQueues[priority])
    {
        CL_EO_QUEUE_UNLOCK(&gClEoQueueMutex);
        CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Queue with priority:%d already active\n",priority));
        goto out;
    }
    CL_EO_QUEUE_UNLOCK(&gClEoQueueMutex);

    if(!threadPriority)
    {
        threadPriority = gClEoThreadPriorityMap[priority];
    }

    rc = CL_EO_RC(CL_ERR_NO_MEMORY);
#if 0
    pQueue = clHeapCalloc(1,sizeof(*pQueue));
    if(pQueue == NULL)
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Error allocating memory\n"));
        goto out;
    }
#endif

    CL_JOB_LIST_INIT(&pQueue->queue);
    rc = clOsalMutexInit(&pQueue->mutex);
    CL_ASSERT(rc == CL_OK);
    rc = clOsalCondInit(&pQueue->cond);
    CL_ASSERT(rc == CL_OK);

    if(pJobHandler == NULL)
    {
        /*Default handler for jobs*/
        pJobHandler = clEoJobHandler;
    }

#if 0 /* GAS */
    rc = clThreadPoolCreate(&threadPool,(ClEoQueueHandleT)pQueue,
                            mode,maxThreads,threadPriority,pJobHandler,
                            pUserData);
#endif

    rc = clJobQueueInit(&gEoJobQueue, 0, maxThreads);

    if(rc != CL_OK)
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Error in thread pool create.rc=0x%x\n",rc));
        goto out_free;
    }

#if 0
    pQueue->pThreadPool = (ClThreadPoolT*)threadPool;
    pQueue->priority = priority;
    CL_EO_QUEUE_LOCK(&gClEoQueueMutex);
    if(gpClEoQueues[priority])
    {
        /*Someone beat us. So back out*/
        CL_EO_QUEUE_UNLOCK(&gClEoQueueMutex);
        rc = CL_EO_RC(CL_ERR_OP_NOT_PERMITTED);
        clThreadPoolDelete((ClThreadPoolHandleT) threadPool);
        goto out_free;
    }
    pQueue->state = CL_EO_QUEUE_STATE_ACTIVE;
    gpClEoQueues[priority] = pQueue;
    CL_EO_QUEUE_UNLOCK(&gClEoQueueMutex);
    *pHandle = (ClEoQueueHandleT)pQueue;
#endif

    rc = CL_OK;
    goto out;

    out_free:
#if 0
    clOsalMutexDestroy(&pQueue->mutex);
    clOsalCondDestroy(&pQueue->cond);
    clHeapFree(pQueue);
#endif

    out:
    return rc;
}