Пример #1
0
CAResult_t CAStopLEGattServer()
{
    OIC_LOG(DEBUG, TAG, "IN");

    ca_mutex_lock(g_leServerStateMutex);

    if (false == g_isLEGattServerStarted)
    {
        OIC_LOG(ERROR, TAG, "Gatt Server is not running to stop");
        ca_mutex_unlock(g_leServerStateMutex);
        return CA_STATUS_OK;
    }

    g_isLEGattServerStarted = false;

    CAResult_t res = CALEStopAdvertise();
    {
        OIC_LOG_V(ERROR, TAG, "CALEStopAdvertise failed with ret[%d]", res);
    }

    res = CADeInitLEGattServer();
    if (CA_STATUS_OK != res)
    {
        OIC_LOG_V(ERROR, TAG, "CADeInitLEGattService failed with ret[%d]", res);
    }

    GMainContext  *context_event_loop = NULL;
    // Required for waking up the thread which is running in gmain loop
    if (NULL != g_eventLoop)
    {
        context_event_loop = g_main_loop_get_context(g_eventLoop);

        if (context_event_loop)
        {
            OIC_LOG_V(DEBUG,  TAG, "g_eventLoop context %x", context_event_loop);
            g_main_context_wakeup(context_event_loop);

            // Kill g main loops and kill threads
            g_main_loop_quit(g_eventLoop);
        }
    }
    else
    {
        OIC_LOG(ERROR, TAG, "g_eventLoop context is NULL");
    }

    ca_mutex_unlock(g_leServerStateMutex);

    OIC_LOG(DEBUG, TAG, "OUT");
    return CA_STATUS_OK;
}
Пример #2
0
CAResult_t CAStopLEGattServer()
{
    OIC_LOG(DEBUG, TAG, "IN");

    oc_mutex_lock(g_leServerStateMutex);

    if (false == g_isLEGattServerStarted)
    {
        OIC_LOG(ERROR, TAG, "Gatt Server is not running to stop");
        oc_mutex_unlock(g_leServerStateMutex);
        return CA_STATUS_OK;
    }

    g_isLEGattServerStarted = false;

    oc_mutex_lock(g_LEClientListMutex);
    CADisconnectAllClient(g_LEClientList);
    g_LEClientList = NULL;
    oc_mutex_unlock(g_LEClientListMutex);

    /*
     * TV Easysetup does not use IoTivity BLE advertisement.
     */

    // CAResult_t res = CALEStopAdvertise();
    // {
    //     OIC_LOG_V(ERROR, TAG, "CALEStopAdvertise failed with ret[%d]", res);
    // }

    CAResult_t res = CADeInitLEGattServer();
    if (CA_STATUS_OK != res)
    {
        OIC_LOG_V(ERROR, TAG, "CADeInitLEGattService failed with ret[%d]", res);
    }

    GMainContext  *context_event_loop = NULL;
    // Required for waking up the thread which is running in gmain loop
    if (NULL != g_eventLoop)
    {
        context_event_loop = g_main_loop_get_context(g_eventLoop);

        if (context_event_loop)
        {
            OIC_LOG_V(DEBUG,  TAG, "g_eventLoop context %x", context_event_loop);
            g_main_context_wakeup(context_event_loop);

            // Kill g main loops and kill threads
            g_main_loop_quit(g_eventLoop);
        }
        g_eventLoop = NULL;
    }
    else
    {
        OIC_LOG(ERROR, TAG, "g_eventLoop context is NULL");
    }

    oc_mutex_unlock(g_leServerStateMutex);

    OIC_LOG(DEBUG, TAG, "OUT");
    return CA_STATUS_OK;
}