Example #1
0
void CATerminateMessageHandler()
{
#ifndef SINGLE_THREAD
    CATransportAdapter_t connType;
    u_arraylist_t *list = CAGetSelectedNetworkList();
    uint32_t length = u_arraylist_length(list);

    uint32_t i = 0;
    for (i = 0; i < length; i++)
    {
        void* ptrType = u_arraylist_get(list, i);

        if (NULL == ptrType)
        {
            continue;
        }

        connType = *(CATransportAdapter_t *)ptrType;
        CAStopAdapter(connType);
    }

    // stop retransmission
    if (NULL != g_retransmissionContext.threadMutex)
    {
        CARetransmissionStop(&g_retransmissionContext);
    }

    // stop thread
    // delete thread data
    if (NULL != g_sendThread.threadMutex)
    {
        CAQueueingThreadStop(&g_sendThread);
    }

    // stop thread
    // delete thread data
    if (NULL != g_receiveThread.threadMutex)
    {
#ifndef SINGLE_HANDLE // This will be enabled when RI supports multi threading
        CAQueueingThreadStop(&g_receiveThread);
#endif /* SINGLE_HANDLE */
    }

    // destroy thread pool
    if (NULL != g_threadPoolHandle)
    {
        ca_thread_pool_free(g_threadPoolHandle);
        g_threadPoolHandle = NULL;
    }

#ifdef WITH_BWT
    CATerminateBlockWiseTransfer();
#endif
    CARetransmissionDestroy(&g_retransmissionContext);
    CAQueueingThreadDestroy(&g_sendThread);
    CAQueueingThreadDestroy(&g_receiveThread);

    // terminate interface adapters by controller
    CATerminateAdapters();
#else
    // terminate interface adapters by controller
    CATerminateAdapters();

    // stop retransmission
    CARetransmissionStop(&g_retransmissionContext);
    CARetransmissionDestroy(&g_retransmissionContext);
#endif
}
CAResult_t CARemoveNetworkType(CATransportAdapter_t transportType)
{
    OIC_LOG(DEBUG, TAG, "IN");

    if (NULL == g_selectedNetworkList)
    {
        OIC_LOG(ERROR, TAG, "SelectedNetwork list is NULL");

        return CA_STATUS_FAILED;
    }

    uint32_t selectedNetworkLength = u_arraylist_length(g_selectedNetworkList);
    for (uint32_t index = 0; index < selectedNetworkLength; index++)
    {
        void* ptrType = u_arraylist_get(g_selectedNetworkList, index);
        if (NULL == ptrType)
        {
            continue;
        }

        CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;

        if (transportType == connType)
        {
            switch (transportType)
            {
                case CA_ADAPTER_IP:
#ifndef IP_ADAPTER
                    OIC_LOG(DEBUG, TAG, "Remove network type(IP) - Not Supported");
                    return CA_NOT_SUPPORTED;
#else

                    OIC_LOG(DEBUG, TAG, "Remove network type(IP)");
                    u_arraylist_remove(g_selectedNetworkList, index);
#endif /* IP_ADAPTER */
                    break;

                case CA_ADAPTER_RFCOMM_BTEDR:
#ifndef EDR_ADAPTER
                    OIC_LOG(DEBUG, TAG, "Remove network type(EDR) - Not Supported");
                    return CA_NOT_SUPPORTED;
#else
                    OIC_LOG(DEBUG, TAG, "Remove network type(EDR)");
                    u_arraylist_remove(g_selectedNetworkList, index);
#endif /* EDR_ADAPTER */
                    break;

                case CA_ADAPTER_GATT_BTLE:
#ifndef LE_ADAPTER
                    OIC_LOG(DEBUG, TAG, "Remove network type(LE) - Not Supported");
                    return CA_NOT_SUPPORTED;
#else
                    OIC_LOG(DEBUG, TAG, "Remove network type(LE)");
                    u_arraylist_remove(g_selectedNetworkList, index);
#endif /* LE_ADAPTER */
                    break;

                default:
                    break;
            }

            // stop selected interface adapter
            CAStopAdapter(connType);
            return CA_STATUS_OK;
        }
    }

    return CA_STATUS_FAILED;
}
CAResult_t CARemoveNetworkType(CAConnectivityType_t connectivityType)
{
    OIC_LOG(DEBUG, TAG, "IN");

    if (g_selectedNetworkList == NULL)
    {
        OIC_LOG(DEBUG, TAG, "Selected network not found");

        return CA_STATUS_FAILED;
    }

    uint8_t index;
    for (index = 0; index < u_arraylist_length(g_selectedNetworkList); index++)
    {
        void* ptrType = u_arraylist_get(g_selectedNetworkList, index);
        if (NULL == ptrType)
        {
            continue;
        }

        CAConnectivityType_t connType = *(CAConnectivityType_t *) ptrType;

        if (connectivityType == connType)
        {
            switch (connectivityType)
            {
                case CA_ETHERNET:

#ifndef ETHERNET_ADAPTER
                    OIC_LOG(DEBUG, TAG, "Remove network type(ETHERNET) - Not Supported");
                    return CA_NOT_SUPPORTED;
#else

                    OIC_LOG(DEBUG, TAG, "Remove network type(ETHERNET)");
                    u_arraylist_remove(g_selectedNetworkList, index);
#endif /* ETHERNET_ADAPTER */
                    break;

                case CA_WIFI:

#ifndef WIFI_ADAPTER
                    OIC_LOG(DEBUG, TAG, "Remove network type(WIFI) - Not Supported");
                    return CA_NOT_SUPPORTED;
#else
                    OIC_LOG(DEBUG, TAG, "Remove network type(WIFI)");
                    u_arraylist_remove(g_selectedNetworkList, index);
#endif /* WIFI_ADAPTER */

                    break;

                case CA_EDR:

#ifndef EDR_ADAPTER
                    OIC_LOG(DEBUG, TAG, "Remove network type(EDR) - Not Supported");
                    return CA_NOT_SUPPORTED;
#else
                    OIC_LOG(DEBUG, TAG, "Remove network type(EDR)");
                    u_arraylist_remove(g_selectedNetworkList, index);
#endif /* EDR_ADAPTER */

                    break;

                case CA_LE:

#ifndef LE_ADAPTER
                    OIC_LOG(DEBUG, TAG, "Remove network type(LE) - Not Supported");
                    return CA_NOT_SUPPORTED;
#else
                    OIC_LOG(DEBUG, TAG, "Remove network type(LE)");
                    u_arraylist_remove(g_selectedNetworkList, index);
#endif /* LE_ADAPTER */

                    break;
            }

            // stop selected interface adapter
            CAStopAdapter(connType);
        }
    }

    return CA_STATUS_OK;
}