Beispiel #1
0
//--------------------------------------------------------------------------------------------------
static le_result_t StartPDPConnection
(
    uint32_t profileIndex    ///< [IN] The profile identifier
)
{
    char atcommand[ATCOMMAND_SIZE] ;
    atcmd_Ref_t atReqRef=NULL;
    atcmdsync_ResultRef_t  atresRef;
    const char* finalRespOkPtr[] = { "CONNECT" , NULL };
    const char* finalRespKoPtr[] = { "NO CARRIER", "TIMEOUT", NULL};

    atcmdsync_PrepareString(atcommand,ATCOMMAND_SIZE,"ATD*99***%d#",profileIndex);

    atReqRef = atcmdsync_PrepareStandardCommand(atcommand,
                                                    NULL,
                                                    finalRespOkPtr,
                                                    finalRespKoPtr,
                                                    30000);
    atresRef = atcmdsync_SendCommand(atports_GetInterface(ATPORT_PPP),atReqRef);
    le_result_t result = atcmdsync_CheckCommandResult(atresRef,finalRespOkPtr,finalRespKoPtr);

    le_mem_Release(atReqRef);
    le_mem_Release(atresRef);

    return result;
}
Beispiel #2
0
//--------------------------------------------------------------------------------------------------
le_result_t pa_sim_EnterPUK
(
    pa_sim_PukType_t   type, ///< [IN] puk type
    const pa_sim_Puk_t puk,  ///< [IN] PUK code
    const pa_sim_Pin_t pin   ///< [IN] new PIN code
)
{
    atcmdsync_ResultRef_t  resRef = NULL;
    char atcommand[ATCOMMAND_SIZE] ;

    atcmdsync_PrepareString(atcommand,ATCOMMAND_SIZE,"at+cpin=%s,%s",puk,pin);

    le_result_t result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND),
                                                atcommand,
                                                &resRef,
                                                NULL,
                                                30000);

    if ( result != LE_OK ) {
        le_mem_Release(resRef);
        return result;
    }

    le_sim_States_t simState=LE_SIM_STATE_UNKNOWN;
    char* line = atcmdsync_GetLine(resRef,0);
    if (CheckStatus(line,&simState))
    {
        ReportStatus(NumCard,simState);
    }

    le_mem_Release(resRef); // release atcmdsync_SendCommandDefault
    return LE_OK;
}
Beispiel #3
0
//--------------------------------------------------------------------------------------------------
static le_result_t resetModem
(
    void
)
{
    atcmdsync_ResultRef_t  resRef=NULL;
    const char* finalRespOkPtr[] = {"+WIND: 4",NULL };
    const char* finalRespKoPtr[] = {"ERROR","+CME ERROR:","+CMS ERROR:","TIMEOUT",NULL};

    atcmd_Ref_t atReqRef = atcmd_Create();

    atcmd_AddCommand(atReqRef,"at+cfun=1",false);
    atcmd_AddData       (atReqRef,NULL,0);
    atcmd_SetTimer      (atReqRef,30000,atcmdsync_GetTimerExpiryHandler());
    atcmd_AddIntermediateResp    (atReqRef,atcmdsync_GetIntermediateEventId(),NULL);
    atcmd_AddFinalResp(atReqRef,atcmdsync_GetFinalEventId(),finalRespOkPtr);
    atcmd_AddFinalResp(atReqRef,atcmdsync_GetFinalEventId(),finalRespKoPtr);

    resRef = atcmdsync_SendCommand(atports_GetInterface(ATPORT_COMMAND),atReqRef);

    le_result_t result = atcmdsync_CheckCommandResult(resRef,finalRespOkPtr,finalRespKoPtr);

    le_mem_Release(atReqRef);   // Release e_atmgr_Object_CreateATCommand
    le_mem_Release(resRef);  // Release le_pa_at_SendSync

    return result;
}
Beispiel #4
0
//--------------------------------------------------------------------------------------------------
le_result_t pa_sim_GetIMSI
(
    pa_sim_Imsi_t imsi   ///< [OUT] IMSI value
)
{
    le_result_t result;
    atcmdsync_ResultRef_t  resRef = NULL;
    // IMSI start with 0|1|2|3|4|5|6|7|8|9
    const char* interRespPtr[] = {"0","1","2","3","4","5","6","7","8","9",NULL};

    if (!imsi)
    {
        LE_DEBUG("One parameter is NULL");
        return LE_BAD_PARAMETER;
    }

    result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND),
                                    "at+cimi",
                                    &resRef,
                                    interRespPtr,
                                    30000);

    if ( result != LE_OK ) {
        le_mem_Release(resRef);
        return result;
    }

    le_sim_States_t simState=LE_SIM_STATE_UNKNOWN;
    char* line = atcmdsync_GetLine(resRef,0);
    if (CheckStatus(line,&simState))
    {
        ReportStatus(NumCard,simState);
    }

    // If there is more than one line then it mean that the command is OK so the first line is
    // the intermediate one
    if (atcmdsync_GetNumLines(resRef) == 2)
    {
        line = atcmdsync_GetLine(resRef,0);
        // copy just the first line because of '\0'
        atcmd_CopyStringWithoutQuote(imsi,
                                   line,
                                   strlen(line));

        result = LE_OK;
    }
    // it is not expected
    else {
        LE_WARN("this pattern is not expected");
        result=LE_NOT_POSSIBLE;
    }

    le_mem_Release(resRef);     // Release atcmdsync_SendCommandDefaultExt

    return result;
}
Beispiel #5
0
//--------------------------------------------------------------------------------------------------
le_result_t pa_mrc_GetRadioPower
(
     le_onoff_t*    powerPtr   ///< [OUT] The power state.
)
{
    int32_t result=LE_NOT_POSSIBLE;
    atcmdsync_ResultRef_t  resRef = NULL;
    const char* interRespPtr[] = {"+CFUN:",NULL};

    result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND),
                                    "at+cfun?",
                                    &resRef,
                                    interRespPtr,
                                    30000);

    if ( result != LE_OK ) {
        le_mem_Release(resRef); // release atcmdsync_SendCommandDefaultExt
        return result;
    }
    // If there is more than one line then it mean that the command is OK so the first line is
    // the intermediate one
    if (atcmdsync_GetNumLines(resRef) == 2)
    {
        // it parse just the first line because of '\0'
        char* line = atcmdsync_GetLine(resRef,0);
        // it parse just the first line because of '\0'
        uint32_t numParam = atcmd_CountLineParameter(line);

        // Check is the +CREG intermediate response is in good format
        if (FIND_STRING("+CFUN:",atcmd_GetLineParameter(line,1)))
        {
            if (numParam==2)
            {
                if(atoi(atcmd_GetLineParameter(line,2)) != 0)
                {
                    *powerPtr = LE_ON;
                }
                else
                {
                    *powerPtr = LE_OFF;
                }
                result = LE_OK;
            } else {
                LE_WARN("this pattern is not expected");
                result=LE_NOT_POSSIBLE;
            }
        } else {
            LE_WARN("this pattern is not expected");
            result=LE_NOT_POSSIBLE;
        }
    }

    le_mem_Release(resRef);     // Release atcmdsync_SendCommand

    return result;
}
Beispiel #6
0
//--------------------------------------------------------------------------------------------------
le_result_t le_media_PlayDtmf
(
    le_audio_Stream_t*   streamPtr, ///< [IN] Stream object
    const char*          dtmfPtr,   ///< [IN] The DTMFs to play.
    uint32_t             duration,  ///< [IN] The DTMF duration in milliseconds.
    uint32_t             pause      ///< [IN] The pause duration between tones in milliseconds.
)
{
    le_result_t       res;
    DtmfThreadCtx_t*  threadCtxPtr = le_mem_ForceAlloc(DtmfThreadContextPool);

    memset(threadCtxPtr, 0, sizeof(DtmfThreadCtx_t));

    streamPtr->samplePcmConfig.sampleRate = 16000;
    streamPtr->samplePcmConfig.bitsPerSample = 16;
    streamPtr->samplePcmConfig.channelsCount = 1;
    streamPtr->samplePcmConfig.fileSize = -1;
    streamPtr->samplePcmConfig.pcmFormat = PCM_RAW;

    threadCtxPtr->duration = duration;
    threadCtxPtr->pause = pause;
    threadCtxPtr->sampleRate = 16000;
    threadCtxPtr->dtmfPtr = dtmfPtr;
    if (pipe(threadCtxPtr->pipefd) == -1)
    {
        LE_ERROR("Failed to create the pipe");
        le_mem_Release(threadCtxPtr);
        return LE_FAULT;
    }

    streamPtr->fd = threadCtxPtr->pipefd[0];

    if ((res=pa_audio_PlaySamples(streamPtr->audioInterface,
                                  streamPtr->fd,
                                  &streamPtr->samplePcmConfig)) == LE_OK)
    {
        LE_INFO("Spawn DTMF thread");
        if (DtmfTreadRef == NULL)
        {
            DtmfTreadRef = le_thread_Create("PlayDtmfs", PlayDtmfThread, threadCtxPtr);

            le_thread_AddChildDestructor(DtmfTreadRef,
                                        DestroyPlayDtmfThread,
                                        threadCtxPtr);

            le_thread_Start(DtmfTreadRef);
        }
    }
    else
    {
        le_mem_Release(threadCtxPtr);
        LE_ERROR("Cannot spawn DTMF thread!");
    }

    return res;
}
Beispiel #7
0
//--------------------------------------------------------------------------------------------------
static le_result_t pa_sim_GetRemainingAttempts
(
    uint32_t  idx,      ///< [IN] idx to read
    uint32_t* attemptsPtr  ///< [OUT] The number of attempts still possible
)
{
    le_result_t result=LE_NOT_POSSIBLE;
    atcmdsync_ResultRef_t  resRef = NULL;
    const char* interRespPtr[] = {"+CPINC:",NULL};

    if (!attemptsPtr)
    {
        LE_DEBUG("One parameter is NULL");
        return LE_BAD_PARAMETER;
    }

    result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND),
                                    "at+cpinc",
                                    &resRef,
                                    interRespPtr,
                                    30000);

    if ( result != LE_OK ) {
        le_mem_Release(resRef); // release atcmdsync_SendCommandDefaultExt
        return result;
    }

    // If there is more than one line then it mean that the command is OK so the first line is
    // the intermediate one
    if (atcmdsync_GetNumLines(resRef) == 2)
    {
        // it parse just the first line because of '\0'
        char* line = atcmdsync_GetLine(resRef,0);
        uint32_t numParam = atcmd_CountLineParameter(line);
        // it parse just the first line because of '\0'
        if ((numParam==5) && (FIND_STRING("+CPINC:",atcmd_GetLineParameter(line,1))))
        {
            *attemptsPtr = atoi(atcmd_GetLineParameter(line,idx));

            result = LE_OK;
        } else {
            LE_WARN("this pattern is not expected");
            result=LE_NOT_POSSIBLE;
        }

    } else {
        LE_WARN("this pattern is not expected");
        result=LE_NOT_POSSIBLE;
    }

    le_mem_Release(resRef);     // Release atcmdsync_SendCommandDefaultExt

    return result;
}
//--------------------------------------------------------------------------------------------------
static void DestroySessionInternal
(
    mqtt_Session* sessionPtr
)
{
    MQTTClient_destroy(&(sessionPtr->client));
    // It is necessary to cast to char* from const char* in order to free the memory
    // associated with the username and password.
    le_mem_Release((char*)sessionPtr->connectOptions.username);
    le_mem_Release((char*)sessionPtr->connectOptions.password);
    le_mem_Release(sessionPtr);
}
Beispiel #9
0
// -------------------------------------------------------------------------------------------------
static void ThreadDestructor
(
    void* destructorContext
)
// -------------------------------------------------------------------------------------------------
{
    Context_t* contextPtr = destructorContext;

    LE_INFO("Thread '%s' destructor running.", le_thread_GetMyName());

    le_mem_Release(contextPtr->completionObjPtr);
    le_mem_Release(contextPtr);
}
Beispiel #10
0
//--------------------------------------------------------------------------------------------------
le_result_t pa_sim_GetState
(
    le_sim_States_t* statePtr    ///< [OUT] SIM state
)
{
    int32_t result=LE_NOT_POSSIBLE;
    atcmd_Ref_t atReqRef;
    atcmdsync_ResultRef_t  resRef = NULL;

    const char* finalRespOkPtr[] = {"OK","+CPIN:",NULL};
    const char* finalRespKoPtr[] = {"ERROR","+CME ERROR:","+CMS ERROR:","TIMEOUT",NULL};

    if (!statePtr)
    {
        LE_DEBUG("One parameter is NULL");
        return LE_BAD_PARAMETER;
    }

    *statePtr=LE_SIM_STATE_UNKNOWN;

    atReqRef = atcmd_Create();
    atcmd_AddCommand(atReqRef,"at+cpin?",false);
    atcmd_AddData(atReqRef,NULL,0);
    atcmd_SetTimer(atReqRef,30000,atcmdsync_GetTimerExpiryHandler());
    atcmd_AddIntermediateResp    (atReqRef,atcmdsync_GetIntermediateEventId(),NULL);
    atcmd_AddFinalResp(atReqRef,atcmdsync_GetFinalEventId(),finalRespOkPtr);
    atcmd_AddFinalResp(atReqRef,atcmdsync_GetFinalEventId(),finalRespKoPtr);

    resRef    = atcmdsync_SendCommand(atports_GetInterface(ATPORT_COMMAND),atReqRef);

    char* line = atcmdsync_GetFinalLine(resRef);

    // Check timeout
    if (FIND_STRING("TIMEOUT",line)) {
        LE_WARN("Modem failed");
        le_mem_Release(atReqRef); le_mem_Release(resRef);
        return LE_TIMEOUT;
    }

    if (CheckStatus(line,statePtr))
    {
        ReportStatus(NumCard,*statePtr);
        result = LE_OK;
    }

    le_mem_Release(atReqRef);  // Release atcmdsync_SetCommand
    le_mem_Release(resRef);     // Release atcmdsync_SendCommand

    return result;
}
//--------------------------------------------------------------------------------------------------
static void* ThreadMain(void* completionObjPtr)
{
    le_thread_InitLegatoThreadData("externalApiTest");

    int i;

    for (i = 0; i < 10000; i++)
    {
        Lock();

        Counter++;

        Unlock();

        Lock();

        Counter--;

        Unlock();
    }

    le_thread_CleanupLegatoThreadData();

    le_mem_Release(completionObjPtr);   // Signal that I'm done.

    return NULL;
}
Beispiel #12
0
//--------------------------------------------------------------------------------------------------
void proc_Delete
(
    proc_Ref_t procRef              ///< [IN] The process to start.
)
{
    le_mem_Release(procRef);
}
Beispiel #13
0
//--------------------------------------------------------------------------------------------------
proc_Ref_t proc_Create
(
    const char* cfgPathRootPtr,     ///< [IN] The path in the config tree for this process.
    app_Ref_t appRef                ///< [IN] Reference to the app that we are part of.
)
{
    Process_t* procPtr = le_mem_ForceAlloc(ProcessPool);

    // Copy the config path.
    if (le_utf8_Copy(procPtr->cfgPathRoot,
                     cfgPathRootPtr,
                     sizeof(procPtr->cfgPathRoot),
                     NULL) == LE_OVERFLOW)
    {
        LE_ERROR("Config path '%s' is too long.", cfgPathRootPtr);

        le_mem_Release(procPtr);
        return NULL;
    }



    procPtr->name = le_path_GetBasenamePtr(procPtr->cfgPathRoot, "/");

    procPtr->appRef = appRef;
    procPtr->faultTime = 0;
    procPtr->paused = false;
    procPtr->pid = -1;  // Processes that are not running are assigned -1 as its pid.
    procPtr->cmdKill = false;

    return procPtr;
}
Beispiel #14
0
//--------------------------------------------------------------------------------------------------
le_result_t pa_common_GetWindIndicator
(
    uint32_t*  windPtr
)
{
    le_result_t result = LE_OK;
    atcmdsync_ResultRef_t  resRef = NULL;
    const char* interRespPtr[] = {"+WIND:",NULL};

    LE_ASSERT(windPtr);

    result = atcmdsync_SendStandard(atports_GetInterface(ATPORT_COMMAND),
                                    "AT+WIND?",
                                    &resRef,
                                    interRespPtr,
                                    30000);

    if ( result == LE_OK )
    {
        char* line = atcmdsync_GetLine(resRef,0);
        if ( sscanf(line,"+WIND: %d",windPtr) != 1)
        {
            LE_DEBUG("cannot qet wind indicator");
            result = LE_FAULT;
        }
    }

    le_mem_Release(resRef);
    return result;
}
Beispiel #15
0
//--------------------------------------------------------------------------------------------------
LE_SHARED le_result_t le_comm_Delete (void* handle)
{
    HandleRecord_t* connectionRecordPtr = (HandleRecord_t*) handle;

    LE_INFO("Deleting AF_INET socket, fd %d .........", connectionRecordPtr->fd);

    if (FdMonitorRef != NULL)
    {
        // Delete FD monitor
        le_fdMonitor_Delete(FdMonitorRef);
        FdMonitorRef = NULL;
    }

    // Remove the Handle record
    le_hashmap_Remove(HandleRecordByFileDescriptor, (void*)(intptr_t) connectionRecordPtr->fd);

    // Shut-down the open socket
    shutdown(connectionRecordPtr->fd, SHUT_RDWR);

    // Close Socket Handle
    close(connectionRecordPtr->fd);
    connectionRecordPtr->fd = -1;

    // Free the Handle Record memory
    le_mem_Release(connectionRecordPtr);
    connectionRecordPtr = NULL;

    // Reset the Network IP Address and TCP Port
    memset(NetworkSocketIpAddress, 0, sizeof(NetworkSocketIpAddress));
    NetworkSocketTCPListeningPort = 0;

    return LE_OK;
}
Beispiel #16
0
//--------------------------------------------------------------------------------------------------
void ni_Release
(
    ni_IteratorRef_t iteratorRef  ///< [IN] Free the resources used by this iterator.
)
//--------------------------------------------------------------------------------------------------
{
    LE_ASSERT(iteratorRef != NULL);

    // Make sure that the transaction timer isn't still running.
    if (iteratorRef->timerRef != NULL)
    {
        if (le_timer_GetExpiryCount(iteratorRef->timerRef) == 0)
        {
            le_timer_Stop(iteratorRef->timerRef);
        }

        le_timer_Delete(iteratorRef->timerRef);
        iteratorRef->timerRef = NULL;
    }

    // Release the rest of the iterator's resources.
    LE_DEBUG("Releasing iterator, <%p> with a lifetime of %d seconds.",
             iteratorRef,
             (uint32_t)(le_clk_GetRelativeTime().sec - iteratorRef->creationTime.sec));

    ni_Close(iteratorRef);
    tdb_UnregisterIterator(iteratorRef->treeRef, iteratorRef);

    le_pathIter_Delete(iteratorRef->pathIterRef);

    tdb_ReleaseTree(iteratorRef->treeRef);
    le_mem_Release(iteratorRef);
}
Beispiel #17
0
//--------------------------------------------------------------------------------------------------
void StopClient
(
    void
)
{
    _ClientThreadData_t* clientThreadPtr = pthread_getspecific(_ThreadDataKey);

    // If the thread specific data is NULL, then there is no current client session.
    if (clientThreadPtr == NULL)
    {
        LE_ERROR("Trying to stop non-existent client session for '%s' service",
                 GlobalServiceInstanceName);
    }
    else
    {
        le_msg_CloseSession( clientThreadPtr->sessionRef );

        // Need to delete the thread specific data, since it is no longer valid.  If a new
        // client session is started, new thread specific data will be allocated.
        le_mem_Release(clientThreadPtr);
        if (pthread_setspecific(_ThreadDataKey, NULL) != 0)
        {
            LE_FATAL("pthread_setspecific() failed!");
        }

        LE_DEBUG("======= Stopping Client %s ========", GlobalServiceInstanceName);
    }
}
Beispiel #18
0
//--------------------------------------------------------------------------------------------------
void le_mrc_DeleteCellularNetworkScan
(
    le_mrc_ScanInformation_ListRef_t  scanInformationListRef ///< [IN] The list of scan information.
)
{
    le_mrc_ScanInformationList_t* scanInformationListPtr = le_ref_Lookup(ScanInformationListRefMap,
                                                                         scanInformationListRef);

    if (scanInformationListPtr == NULL)
    {
        LE_KILL_CLIENT("Invalid reference (%p) provided!", scanInformationListRef);
        return;
    }

    scanInformationListPtr->currentLink = NULL;
    pa_mrc_DeleteScanInformation(&(scanInformationListPtr->paScanInformationList));

    // Delete the safe Reference list.
    DeleteSafeRefList(&(scanInformationListPtr->safeRefScanInformationList));

    // Invalidate the Safe Reference.
    le_ref_DeleteRef(ScanInformationListRefMap, scanInformationListRef);

    le_mem_Release(scanInformationListPtr);
}
Beispiel #19
0
//--------------------------------------------------------------------------------------------------
static void DeleteFdMonitor
(
    FdMonitor_t*            fdMonitorPtr        ///< [in] Pointer to the FD Monitor to be deleted.
)
//--------------------------------------------------------------------------------------------------
{
    event_PerThreadRec_t*   perThreadRecPtr = thread_GetEventRecPtr();

    LE_ASSERT(perThreadRecPtr == fdMonitorPtr->threadRecPtr);

    // Remove the FD Monitor from the thread's FD Monitor List.
    le_dls_Remove(&perThreadRecPtr->fdMonitorList, &fdMonitorPtr->link);

    LOCK

    // Delete the Safe References used for the FD Monitor and any of its Handler objects.
    le_ref_DeleteRef(FdMonitorRefMap, fdMonitorPtr->safeRef);

    UNLOCK

    // Tell epoll(7) to stop monitoring this fd.
    StopMonitoringFd(fdMonitorPtr);

    // Release the object back to it's pool.
    le_mem_Release(fdMonitorPtr);
}
//--------------------------------------------------------------------------------------------------
void le_msg_DeleteService
(
    le_msg_ServiceRef_t             serviceRef  ///< [in] Reference to the service.
)
//--------------------------------------------------------------------------------------------------
{
    LE_FATAL_IF(serviceRef->serverThread != le_thread_GetCurrent(),
                "Attempted to delete service (%s:%s) not owned by thread.",
                serviceRef->id.name,
                le_msg_GetProtocolIdStr(serviceRef->id.protocolRef));

    // If the service is still advertised, hide it.
    le_msg_HideService(serviceRef);

    // Close any remaining open sessions.
    CloseAllSessions(serviceRef);

    // NOTE: Lock the mutex here to prevent a race between this thread dropping ownership
    // of the service and another thread trying to offer the same service.  This is very
    // unlikely to ever happen, but just in case, make sure it fails with a sensible
    // ("duplicate") log message, instead of just quietly messing up the hashmap or something.
    LOCK

    // Clear out the server thread reference.
    serviceRef->serverThread = NULL;

    // Release the server's hold on the object.
    le_mem_Release(serviceRef);

    UNLOCK
}
//--------------------------------------------------------------------------------------------------
void le_msg_RemoveServiceHandler
(
    le_msg_SessionEventHandlerRef_t handlerRef   ///< [in] Reference to a previously call of
                                                 ///       le_msg_AddServiceCloseHandler()
)
//--------------------------------------------------------------------------------------------------
{
    le_dls_Link_t* linkPtr = le_ref_Lookup(HandlersRefMap, handlerRef);

    if ( linkPtr == NULL )
    {
        LE_ERROR("Invalid data request reference");
    }
    else
    {
        SessionEventHandler_t* eventPtr = CONTAINER_OF(linkPtr, SessionEventHandler_t, link);

        /* Remove the link from the close handlers dls */
        le_dls_Remove(eventPtr->listPtr, linkPtr);

        /* Release memory */
        le_mem_Release(eventPtr);

        /* Delete the reference */
        le_ref_DeleteRef(HandlersRefMap, handlerRef);
    }
}
Beispiel #22
0
//--------------------------------------------------------------------------------------------------
void le_mem_DeleteSubPool
(
    le_mem_PoolRef_t    subPool     ///< [IN] The sub-pool to be deleted.
)
{
    LE_ASSERT(subPool != NULL);

    Lock();

    // Make sure all sub-pool objects are free.
    le_mem_PoolRef_t superPool = subPool->superPoolPtr;

    LE_FATAL_IF(subPool->numBlocksInUse != 0,
                "Subpool '%s' deleted while %zu blocks remain allocated.",
                subPool->name,
                subPool->numBlocksInUse);

    size_t numBlocks = subPool->totalBlocks;

    // Move the blocks from the subPool back to the superpool.
    MoveBlocks(superPool, subPool, numBlocks);

    // Update the superPool's block use count.
    superPool->numBlocksInUse -= numBlocks;

    // Remove the sub-pool from the list of sub-pools.
    ListOfPoolsChgCnt++;
    le_dls_Remove(&ListOfPools, &(subPool->poolLink));

    Unlock();

    // Release the sub-pool.
    le_mem_Release(subPool);
}
Beispiel #23
0
//--------------------------------------------------------------------------------------------------
static void DeleteFdMonitor
(
    FdMonitor_t*            fdMonitorPtr        ///< [in] Pointer to the FD Monitor to be deleted.
)
//--------------------------------------------------------------------------------------------------
{
    int i;
    event_PerThreadRec_t*   perThreadRecPtr = thread_GetEventRecPtr();

    LE_ASSERT(perThreadRecPtr == fdMonitorPtr->threadRecPtr);

    // Remove the FD Monitor from the thread's FD Monitor List.
    le_dls_Remove(&perThreadRecPtr->fdMonitorList, &fdMonitorPtr->link);

    LOCK

    // Delete the Safe References used for the FD Monitor and any of its Handler objects.
    le_ref_DeleteRef(FdMonitorRefMap, fdMonitorPtr->safeRef);
    for (i = 0; i < LE_EVENT_NUM_FD_EVENT_TYPES; i++)
    {
        void* safeRef = fdMonitorPtr->handlerArray[i].safeRef;
        if (safeRef != NULL)
        {
            le_ref_DeleteRef(HandlerRefMap, safeRef);
        }
    }

    UNLOCK

    // Tell epoll(7) to stop monitoring this fd.
    StopMonitoringFd(fdMonitorPtr);

    // Release the object back to it's pool.
    le_mem_Release(fdMonitorPtr);
}
//--------------------------------------------------------------------------------------------------
static void ServiceDestructor
(
    void* objPtr
)
//--------------------------------------------------------------------------------------------------
{
    le_dls_Link_t* linkPtr = NULL;

    Service_t* servicePtr = objPtr;

    le_hashmap_Remove(ServiceMapRef, &servicePtr->id);

    /* Release the close handlers dls */
    do
    {
        linkPtr = le_dls_PopTail(&servicePtr->closeListPtr);

        if (linkPtr)
        {
            SessionEventHandler_t* closeEventPtr = CONTAINER_OF(linkPtr, SessionEventHandler_t, link);

            /* Delete the reference */
            le_ref_DeleteRef(HandlersRefMap, closeEventPtr->ref);

            /* Release the memory */
            le_mem_Release(closeEventPtr);
        }
    }
    while (linkPtr);

    /* Release the open handlers dls */
    do
    {
        linkPtr = le_dls_PopTail(&servicePtr->openListPtr);

        if (linkPtr)
        {
            SessionEventHandler_t* openEventPtr = CONTAINER_OF(linkPtr, SessionEventHandler_t, link);

            /* Delete the reference */
            le_ref_DeleteRef(HandlersRefMap, openEventPtr->ref);

            le_mem_Release(openEventPtr);
        }
    }
    while (linkPtr);
}
Beispiel #25
0
//--------------------------------------------------------------------------------------------------
static void PopContext
(
    Parser_t* parserPtr
)
//--------------------------------------------------------------------------------------------------
{
    // Don't do anything if a client handler has already stopped parsing.
    if (NotStopped(parserPtr))
    {
        // Pop the top one and release it.
        le_sls_Link_t* linkPtr = le_sls_Pop(&parserPtr->contextStack);
        le_mem_Release(CONTAINER_OF(linkPtr, Context_t, link));

        // Check the new context
        le_json_ContextType_t context = GetContext(parserPtr)->type;

        switch (context)
        {
            case LE_JSON_CONTEXT_DOC:

                // We've finished parsing the whole document.
                // Automatically stop parsing and report the document end to the client.
                StopParsing(parserPtr);
                Report(parserPtr, LE_JSON_DOC_END);
                break;

            case LE_JSON_CONTEXT_OBJECT:

                // We've finished parsing an object member.
                // Expect a comma separator or the end of the object next.
                parserPtr->next = EXPECT_COMMA_OR_OBJECT_END;
                break;

            case LE_JSON_CONTEXT_MEMBER:

                // We've finished parsing the value of an object member.
                // This is also the end of the member, so pop that context too.
                PopContext(parserPtr);
                break;

            case LE_JSON_CONTEXT_ARRAY:

                // We've finished parsing an array element value.
                // Expect a comma separator or the end of the array next.
                parserPtr->next = EXPECT_COMMA_OR_ARRAY_END;
                break;

            // These are all leaf contexts.  That is, we should never find one of these
            // contexts after popping another one off the stack.
            case LE_JSON_CONTEXT_STRING:
            case LE_JSON_CONTEXT_NUMBER:
            case LE_JSON_CONTEXT_TRUE:
            case LE_JSON_CONTEXT_FALSE:
            case LE_JSON_CONTEXT_NULL:

                LE_FATAL("Unexpected context after pop: %s", le_json_GetContextName(context));
        }
    }
}
Beispiel #26
0
//--------------------------------------------------------------------------------------------------
le_result_t le_mcc_Delete
(
    le_mcc_CallRef_t callRef   ///< [IN] The call object to free.
)
{
    le_mcc_Call_t* callPtr = le_ref_Lookup(MccCallRefMap, callRef);

    if (callPtr == NULL)
    {
        LE_ERROR("Invalid reference (%p) provided!", callRef);
        return LE_NOT_FOUND;
    }

    if (callPtr->inProgress)
    {
        return LE_FAULT;
    }
    else
    {
        SessionRefNode_t* sessionRefNodePtr;
        le_dls_Link_t* linkPtr;

        callPtr->refCount--;
        LE_DEBUG("refcount %d", callPtr->refCount);

        // Remove corresponding node from the sessionRefList
        linkPtr = le_dls_Peek(&(callPtr->sessionRefList));

        while (linkPtr != NULL)
        {
            sessionRefNodePtr = CONTAINER_OF(linkPtr, SessionRefNode_t, link);
            linkPtr = le_dls_PeekNext(&(callPtr->sessionRefList), linkPtr);

            if ( sessionRefNodePtr->sessionRef == le_mcc_GetClientSessionRef() )
            {
                le_dls_Remove(  &(callPtr->sessionRefList),
                                &(sessionRefNodePtr->link));

                le_mem_Release(sessionRefNodePtr);
            }
        }

        le_mem_Release(callPtr);
        return LE_OK;
    }
}
Beispiel #27
0
//--------------------------------------------------------------------------------------------------
static void ThreadDeathHandler
(
    void* parserPtr
)
//--------------------------------------------------------------------------------------------------
{
    // Release the client's reference to the parser object.
    le_mem_Release(parserPtr);
}
Beispiel #28
0
//--------------------------------------------------------------------------------------------------
void dstr_Release
(
    dstr_Ref_t strRef  ///< [IN] The dynamic string to free.
)
//--------------------------------------------------------------------------------------------------
{
    dstr_Ref_t segmentRef = FirstSegmentRef(strRef);

    while (segmentRef != NULL)
    {
        dstr_Ref_t nextSegmentRef = NextSegmentRef(strRef, segmentRef);

        le_mem_Release(segmentRef);
        segmentRef = nextSegmentRef;
    }

    le_mem_Release(strRef);
}
Beispiel #29
0
//--------------------------------------------------------------------------------------------------
LE_SHARED void appCfg_DeleteIter
(
    appCfg_Iter_t iter          ///< [IN] Iterator
)
{
    le_cfg_CancelTxn(iter->cfgIter);

    le_mem_Release(iter);
}
//--------------------------------------------------------------------------------------------------
static void MessageReceivedEventHandler
(
    void* reportPtr
)
{
    mqtt_Message* storedMsgPtr = *((mqtt_Message**)reportPtr);

    mqtt_Session* s = le_ref_Lookup(SessionRefMap, storedMsgPtr->sessionRef);
    if (s == NULL)
    {
        LE_WARN("Session lookup failed for session=0x%p", storedMsgPtr->sessionRef);
        return;
    }

    if (s->messageArrivedHandler != NULL)
    {
        if (storedMsgPtr->topicLength <= MQTT_MAX_TOPIC_LENGTH &&
            storedMsgPtr->payloadLength <= MQTT_MAX_PAYLOAD_LENGTH)
        {
            s->messageArrivedHandler(
                storedMsgPtr->topicPtr,
                storedMsgPtr->payloadPtr,
                storedMsgPtr->payloadLength,
                s->messageArrivedHandlerContextPtr);
        }
        else
        {
            LE_WARN(
                "Message arrived from broker, but it is too large to deliver using Legato IPC - "
                "topicLength=%zu, payloadLength=%zu",
                storedMsgPtr->topicLength,
                storedMsgPtr->payloadLength);
        }
    }
    else
    {
        LE_WARN(
            "Message has arrived, but no handler is registered to receive the notification");
    }

    le_mem_Release(storedMsgPtr->topicPtr);
    le_mem_Release(storedMsgPtr->payloadPtr);
    le_mem_Release(storedMsgPtr);
}