Beispiel #1
0
CAResult_t CAStopIP()
{
    OIC_LOG(DEBUG, TAG, "IN");

#ifdef __WITH_DTLS__
    CAAdapterNetDtlsDeInit();
#endif

#ifndef SINGLE_THREAD
    if (g_sendQueueHandle && g_sendQueueHandle->threadMutex)
    {
        CAQueueingThreadStop(g_sendQueueHandle);
    }

    CAIPDeinitializeQueueHandles();
#endif

    CAIPStopNetworkMonitor();
    CAIPStopServer();
    //Re-initializing the Globals to start them again
    CAInitializeIPGlobals();

    OIC_LOG(DEBUG, TAG, "OUT");
    return CA_STATUS_OK;
}
Beispiel #2
0
CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
                          CANetworkPacketReceivedCallback networkPacketCallback,
                          CAAdapterChangeCallback netCallback,
                          CAErrorHandleCallback errorCallback, ca_thread_pool_t handle)
{
    OIC_LOG(DEBUG, TAG, "IN");
    VERIFY_NON_NULL(registerCallback, TAG, "registerCallback");
    VERIFY_NON_NULL(networkPacketCallback, TAG, "networkPacketCallback");
    VERIFY_NON_NULL(netCallback, TAG, "netCallback");
#ifndef SINGLE_THREAD
    VERIFY_NON_NULL(handle, TAG, "thread pool handle");
#endif

    g_networkChangeCallback = netCallback;
    g_networkPacketCallback = networkPacketCallback;
    g_errorCallback = errorCallback;

    CAInitializeIPGlobals();
    caglobals.ip.threadpool = handle;

    CAIPSetErrorHandler(CAIPErrorHandler);
    CAIPSetPacketReceiveCallback(CAIPPacketReceivedCB);
#ifndef SINGLE_THREAD
    CAIPSetConnectionStateChangeCallback(CAIPConnectionStateCB);
#endif
#ifdef __WITH_DTLS__
    CAAdapterNetDtlsInit();

    CADTLSSetAdapterCallbacks(CAIPPacketReceivedCB, CAIPPacketSendCB, 0);
#endif

    static const CAConnectivityHandler_t ipHandler =
        {
            .startAdapter = CAStartIP,
            .stopAdapter = CAStopIP,
            .startListenServer = CAStartIPListeningServer,
            .stopListenServer = CAStopIPListeningServer,
            .startDiscoveryServer = CAStartIPDiscoveryServer,
            .sendData = CASendIPUnicastData,
            .sendDataToAll = CASendIPMulticastData,
            .GetnetInfo = CAGetIPInterfaceInformation,
            .readData = CAReadIPData,
            .terminate = CATerminateIP,
            .cType = CA_ADAPTER_IP
        };
    registerCallback(ipHandler);

    OIC_LOG(INFO, TAG, "OUT IntializeIP is Success");
    return CA_STATUS_OK;
}