Exemple #1
0
//--------------------------------------------------------------------------------------------------
static _ClientThreadData_t* InitClientThreadData
(
    const char* serviceInstanceName
)
{
    // Open a session.
    le_msg_ProtocolRef_t protocolRef;
    le_msg_SessionRef_t sessionRef;

    // The instance name must not be an empty string
    if ( serviceInstanceName[0] == '\0' )
    {
        LE_FATAL("Undefined client service instance name (Was StartClient() called?)");
    }

    protocolRef = le_msg_GetProtocolRef(PROTOCOL_ID_STR, sizeof(_Message_t));
    sessionRef = le_msg_CreateSession(protocolRef, serviceInstanceName);
    le_msg_SetSessionRecvHandler(sessionRef, ClientIndicationRecvHandler, NULL);
    le_msg_OpenSessionSync(sessionRef);

    // Store the client sessionRef in thread-local storage, since each thread requires
    // its own sessionRef.
    _ClientThreadData_t* clientThreadPtr = le_mem_ForceAlloc(_ClientThreadDataPool);
    clientThreadPtr->sessionRef = sessionRef;
    if (pthread_setspecific(_ThreadDataKey, clientThreadPtr) != 0)
    {
        LE_FATAL("pthread_setspecific() failed!");
    }

    return clientThreadPtr;
}
Exemple #2
0
//--------------------------------------------------------------------------------------------------
static le_msg_SessionRef_t ConnectToLogControlDaemon
(
    void
)
{
    le_msg_ProtocolRef_t protocolRef = le_msg_GetProtocolRef(LOG_CONTROL_PROTOCOL_ID,
                                                             LOG_MAX_CMD_PACKET_BYTES);
    le_msg_SessionRef_t sessionRef = le_msg_CreateSession(protocolRef, LOG_CONTROL_SERVICE_NAME);

    le_msg_SetSessionRecvHandler(sessionRef, MsgReceiveHandler, NULL);
    le_msg_SetSessionCloseHandler(sessionRef, SessionCloseHandler, NULL);

    le_result_t result = msgSession_TryOpenSessionSync(sessionRef);
    if (result != LE_OK)
    {
        printf("***ERROR: Can't communicate with the Log Control Daemon.\n");
        printf("Service Directory is unreachable.\n"
               "Perhaps the Service Directory is not running?\n");

        exit(EXIT_FAILURE);
    }

    return sessionRef;
}