コード例 #1
0
CAResult_t CAInitLENwkMonitorMutexVaraibles()
{
    OIC_LOG(DEBUG, TAG, "IN");
    if (NULL == g_bleDeviceStateChangedCbMutex)
    {
        g_bleDeviceStateChangedCbMutex = ca_mutex_new();
        if (NULL == g_bleDeviceStateChangedCbMutex)
        {
            OIC_LOG(ERROR, TAG, "ca_mutex_new has failed");
            return CA_STATUS_FAILED;
        }
    }

    if (NULL == g_bleConnectionStateChangedCbMutex)
    {
    	g_bleConnectionStateChangedCbMutex = ca_mutex_new();
        if (NULL == g_bleConnectionStateChangedCbMutex)
        {
            OIC_LOG(ERROR, TAG, "ca_mutex_new has failed");
            ca_mutex_free(g_bleDeviceStateChangedCbMutex);
            return CA_STATUS_FAILED;
        }
    }

    OIC_LOG(DEBUG, TAG, "OUT");
    return CA_STATUS_OK;
}
コード例 #2
0
CAResult_t CAInitializeLENetworkMonitor()
{
    /**
     * @note "Network monitor" operations are started in the
     *       @c CAStartLEAdapter() function rather than this function
     *       due to glib/D-Bus signal handling threads related
     *       issues.
     *
     * @see @c CAStartLEAdapter() for further details.
     */

    g_context.lock      = ca_mutex_new();
    g_context.condition = ca_cond_new();

    static int const PSHARED        = 0;  // shared between threads
    static unsigned int const VALUE = 0;  // force sem_wait() to block

    if (sem_init(&g_context.le_started, PSHARED, VALUE) != 0)
    {
        return CA_STATUS_FAILED;
    }

    /*
      The CA LE interface doesn't expose a CAInitializeLEGattServer()
      function so perform initialization here.
     */
    CAPeripheralInitialize();

    return CA_STATUS_OK;
}
コード例 #3
0
ファイル: cableserver.c プロジェクト: darcyg/iotivity-1
CAResult_t CAInitGattServerMutexVariables()
{
    OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
    if (NULL == g_bleServerStateMutex)
    {
        g_bleServerStateMutex = ca_mutex_new();
        if (NULL == g_bleServerStateMutex)
        {
            OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "ca_mutex_new failed");
            return CA_STATUS_FAILED;
        }
    }

    if (NULL == g_bleServiceMutex)
    {
        g_bleServiceMutex = ca_mutex_new();
        if (NULL == g_bleServiceMutex)
        {
            OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "ca_mutex_new failed");
            return CA_STATUS_FAILED;
        }
    }

    if (NULL == g_bleCharacteristicMutex)
    {
        g_bleCharacteristicMutex = ca_mutex_new();
        if (NULL == g_bleCharacteristicMutex)
        {
            OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "ca_mutex_new failed");
            return CA_STATUS_FAILED;
        }
    }

    if (NULL == g_bleReqRespCbMutex)
    {
        g_bleReqRespCbMutex = ca_mutex_new();
        if (NULL == g_bleReqRespCbMutex)
        {
            OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "ca_mutex_new failed");
            return CA_STATUS_FAILED;
        }
    }
    OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
    return CA_STATUS_OK;
}
コード例 #4
0
ファイル: caleautoconnector.c プロジェクト: aaronkim/iotivity
CAResult_t CAManagerInitLEAutoConnection()
{
    if (NULL == g_connectRetryMutex)
    {
        g_connectRetryMutex = ca_mutex_new();
        if (NULL == g_connectRetryMutex)
        {
            OIC_LOG(ERROR, TAG, "ca_mutex_new has failed");
            return CA_STATUS_FAILED;
        }
    }

    if (NULL == g_connectRetryCond)
    {
        g_connectRetryCond = ca_cond_new();
        if (NULL == g_connectRetryCond)
        {
            OIC_LOG(ERROR, TAG, "ca_cond_new has failed");
            return CA_STATUS_FAILED;
        }
    }

    if (NULL == g_recoveryMutex)
    {
        g_recoveryMutex = ca_mutex_new();
        if (NULL == g_recoveryMutex)
        {
            OIC_LOG(ERROR, TAG, "ca_mutex_new has failed");
            return CA_STATUS_FAILED;
        }
    }

    if (NULL == g_recoveryCond)
    {
        g_recoveryCond = ca_cond_new();
        if (NULL == g_recoveryCond)
        {
            OIC_LOG(ERROR, TAG, "ca_cond_new has failed");
            return CA_STATUS_FAILED;
        }
    }

    return CA_STATUS_OK;
}
コード例 #5
0
ファイル: caedrclient.c プロジェクト: darcyg/iotivity-1
void CAEDRManagerInitializeMutex(void)
{
    OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");

    if (!g_edrDeviceListMutex)
    {
        g_edrDeviceListMutex = ca_mutex_new();
    }

    OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
}
コード例 #6
0
ファイル: caedrclient.c プロジェクト: chetan336/iotivity
static CAResult_t CAEDRCreateMutex()
{
    OIC_LOG(DEBUG, TAG, "IN");

    g_mutexUnicastServer = ca_mutex_new();
    if (!g_mutexUnicastServer)
    {
        OIC_LOG(ERROR, TAG, "Failed to created mutex!");
        return CA_STATUS_FAILED;
    }

    g_mutexMulticastServer = ca_mutex_new();
    if (!g_mutexMulticastServer)
    {
        OIC_LOG(ERROR, TAG, "Failed to created mutex!");

        CAEDRDestroyMutex();
        return CA_STATUS_FAILED;
    }

    g_mutexStateList = ca_mutex_new();
    if (!g_mutexStateList)
    {
        OIC_LOG(ERROR, TAG, "Failed to created mutex!");

        CAEDRDestroyMutex();
        return CA_STATUS_FAILED;
    }

    g_mutexObjectList = ca_mutex_new();
    if (!g_mutexObjectList)
    {
        OIC_LOG(ERROR, TAG, "Failed to created mutex!");

        CAEDRDestroyMutex();
        return CA_STATUS_FAILED;
    }

    OIC_LOG(DEBUG, TAG, "OUT");
    return CA_STATUS_OK;
}
コード例 #7
0
ファイル: caedrclient.c プロジェクト: nvelozsavino/iotivity
static CAResult_t CAEDRCreateMutex()
{
    g_mutexStateList = ca_mutex_new();
    if (!g_mutexStateList)
    {
        OIC_LOG(ERROR, TAG, "Failed to created mutex!");

        CAEDRDestroyMutex();
        return CA_STATUS_FAILED;
    }

    g_mutexObjectList = ca_mutex_new();
    if (!g_mutexObjectList)
    {
        OIC_LOG(ERROR, TAG, "Failed to created mutex!");

        CAEDRDestroyMutex();
        return CA_STATUS_FAILED;
    }

    return CA_STATUS_OK;
}
コード例 #8
0
CAResult_t CAManagerInitMutexVaraibles()
{
    if (NULL == g_deviceACDataListMutex)
    {
        g_deviceACDataListMutex = ca_mutex_new();
        if (NULL == g_deviceACDataListMutex)
        {
            OIC_LOG(ERROR, TAG, "ca_mutex_new has failed");
            return CA_STATUS_FAILED;
        }
    }
    return CA_STATUS_OK;
}
コード例 #9
0
ファイル: catcpserver.c プロジェクト: rajesh89s/iotivity
static CAResult_t CATCPCreateMutex()
{
    if (!g_mutexObjectList)
    {
        g_mutexObjectList = ca_mutex_new();
        if (!g_mutexObjectList)
        {
            OIC_LOG(ERROR, TAG, "Failed to created mutex!");
            return CA_STATUS_FAILED;
        }
    }

    return CA_STATUS_OK;
}
コード例 #10
0
ファイル: caipserver.c プロジェクト: darcyg/iotivity-1
static CAResult_t CAIPServerCreateMutex(void)
{
    OIC_LOG(DEBUG, IP_SERVER_TAG, "IN");

    g_mutexServerInfoList = ca_mutex_new();
    if (!g_mutexServerInfoList)
    {
        OIC_LOG(DEBUG, IP_SERVER_TAG, "OUT");
        return CA_MEMORY_ALLOC_FAILED;
    }

    g_mutexAdapterServerContext = ca_mutex_new();
    if (!g_mutexAdapterServerContext)
    {
        OIC_LOG(ERROR, IP_SERVER_TAG, "Failed to created mutex!");
        ca_mutex_free(g_mutexServerInfoList);
        g_mutexServerInfoList = NULL;
        return CA_MEMORY_ALLOC_FAILED;
    }

    OIC_LOG(DEBUG, IP_SERVER_TAG, "OUT");
    return CA_STATUS_OK;
}
コード例 #11
0
static CAResult_t CAEDRServerCreateMutex()
{
    g_mutexUnicastServer = ca_mutex_new();
    if (!g_mutexUnicastServer)
    {
        OIC_LOG(ERROR, TAG, "Failed to created mutex!");
        return CA_STATUS_FAILED;
    }

    g_mutexMulticastServer = ca_mutex_new();
    if (!g_mutexMulticastServer)
    {
        OIC_LOG(ERROR, TAG, "Failed to created mutex!");

        CAEDRServerDestroyMutex();
        return CA_STATUS_FAILED;
    }

    g_mutexAcceptServer = ca_mutex_new();
    if (!g_mutexAcceptServer)
    {
        OIC_LOG(ERROR, TAG, "Failed to created mutex!");

        CAEDRServerDestroyMutex();
        return CA_STATUS_FAILED;
    }

    g_mutexServerSocket = ca_mutex_new();
    if (!g_mutexServerSocket)
    {
        OIC_LOG(ERROR, TAG, "Failed to created mutex!");

        CAEDRServerDestroyMutex();
        return CA_STATUS_FAILED;
    }

    g_mutexStateList = ca_mutex_new();
    if (!g_mutexStateList)
    {
        OIC_LOG(ERROR, TAG, "Failed to created mutex!");

        CAEDRServerDestroyMutex();
        return CA_STATUS_FAILED;
    }

    g_mutexObjectList = ca_mutex_new();
    if (!g_mutexObjectList)
    {
        OIC_LOG(ERROR, TAG, "Failed to created mutex!");

        CAEDRServerDestroyMutex();
        return CA_STATUS_FAILED;
    }

    return CA_STATUS_OK;
}
コード例 #12
0
ファイル: caipnwmonitor.c プロジェクト: darcyg/iotivity-1
static CAResult_t CAInitializeNetworkMonitorMutexes()
{
    if (!g_networkMonitorContextMutex)
    {
        g_networkMonitorContextMutex = ca_mutex_new();
        if (!g_networkMonitorContextMutex)
        {
            OIC_LOG(ERROR, IP_MONITOR_TAG, "g_networkMonitorContextMutex Malloc  failed");
            return CA_MEMORY_ALLOC_FAILED;
        }
    }

    if (!g_stopNetworkMonitorMutex)
    {
        g_stopNetworkMonitorMutex = ca_mutex_new();
        if (!g_stopNetworkMonitorMutex)
        {
            OIC_LOG(ERROR, IP_MONITOR_TAG, "g_stopNetworkMonitorMutex Malloc  failed");
            ca_mutex_free(g_networkMonitorContextMutex);
            return CA_MEMORY_ALLOC_FAILED;
        }
    }
    return CA_STATUS_OK;
}
コード例 #13
0
CAResult_t CAStartRA()
{
    if (g_xmppData.handle.abstract_handle)
    {
        OIC_LOG(WARNING, RA_ADAPTER_TAG, "RA adapter already started");
        return CA_STATUS_OK;
    }

    OIC_LOG(DEBUG, RA_ADAPTER_TAG, PCF("Starting RA adapter"));

    g_raadapterMutex = ca_mutex_new ();
    if (!g_raadapterMutex)
    {
        OIC_LOG (ERROR, RA_ADAPTER_TAG, PCF("Memory allocation for mutex failed."));
        return CA_MEMORY_ALLOC_FAILED;
    }

    ca_mutex_lock (g_raadapterMutex);

    xmpp_context_init(&g_xmppData.context);
    g_xmppData.handle = xmpp_startup(&g_xmppData.context);

    // Wire up connection callbacks and call API to connect to XMPP server
    g_xmppData.connection_callback.on_connected = CARAXmppConnectedCB;
    g_xmppData.connection_callback.on_disconnected = CARAXmppDisonnectedCB;

    xmpp_error_code_t ret = xmpp_connect(g_xmppData.handle, &g_xmppData.g_host,
            &g_xmppData.g_identity, g_xmppData.connection_callback);

    // Destroy host and identity structures as they are only
    // required to establish initial connection
    xmpp_identity_destroy(&g_xmppData.g_identity);
    xmpp_host_destroy(&g_xmppData.g_host);

    ca_mutex_unlock (g_raadapterMutex);

    if (XMPP_ERR_OK != ret)
    {
        OIC_LOG_V(ERROR, RA_ADAPTER_TAG, "Failed to init XMPP connection status: %d",
            ret);
        return CA_STATUS_FAILED;
    }

    OIC_LOG(DEBUG, RA_ADAPTER_TAG, "RA adapter started succesfully");
    return CA_STATUS_OK;
}
コード例 #14
0
int ca_context_create(ca_context **_c) {
    ca_context *c;
    int ret;
    const char *d;

    ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED);
    ca_return_val_if_fail(_c, CA_ERROR_INVALID);

    if (!(c = ca_new0(ca_context, 1)))
        return CA_ERROR_OOM;

    if (!(c->mutex = ca_mutex_new())) {
        ca_context_destroy(c);
        return CA_ERROR_OOM;
    }

    if ((ret = ca_proplist_create(&c->props)) < 0) {
        ca_context_destroy(c);
        return ret;
    }

    if ((d = getenv("CANBERRA_DRIVER"))) {
        if ((ret = ca_context_set_driver(c, d)) < 0) {
            ca_context_destroy(c);
            return ret;
        }
    }

    if ((d = getenv("CANBERRA_DEVICE"))) {
        if ((ret = ca_context_change_device(c, d)) < 0) {
            ca_context_destroy(c);
            return ret;
        }
    }

    *_c = c;
    return CA_SUCCESS;
}
コード例 #15
0
static CAResult_t CAIPInitializeNetworkMonitorList()
{
    if (!g_networkMonitorContextMutex)
    {
        g_networkMonitorContextMutex = ca_mutex_new();
        if (!g_networkMonitorContextMutex)
        {
            OIC_LOG(ERROR, TAG, "ca_mutex_new has failed");
            return CA_STATUS_FAILED;
        }
    }

    if (!g_netInterfaceList)
    {
        g_netInterfaceList = u_arraylist_create();
        if (!g_netInterfaceList)
        {
            OIC_LOG(ERROR, TAG, "u_arraylist_create has failed");
            CAIPDestroyNetworkMonitorList();
            return CA_STATUS_FAILED;
        }
    }
}
コード例 #16
0
CAResult_t CAInitGattClientMutexVariables()
{
    OIC_LOG(DEBUG,  TZ_BLE_CLIENT_TAG, "IN");
    if (NULL == g_bleClientStateMutex)
    {
        g_bleClientStateMutex = ca_mutex_new();
        if (NULL == g_bleClientStateMutex)
        {
            OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "ca_mutex_new failed");
            return CA_STATUS_FAILED;
        }
    }

    if (NULL == g_bleServiceListMutex)
    {
        g_bleServiceListMutex = ca_mutex_new();
        if (NULL == g_bleServiceListMutex)
        {
            OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "ca_mutex_new failed");
            return CA_STATUS_FAILED;
        }
    }

    if (NULL == g_bleReqRespClientCbMutex)
    {
        g_bleReqRespClientCbMutex = ca_mutex_new();
        if (NULL == g_bleReqRespClientCbMutex)
        {
            OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "ca_mutex_new failed");
            return CA_STATUS_FAILED;
        }
    }

    if (NULL == g_bleClientThreadPoolMutex)
    {
        g_bleClientThreadPoolMutex = ca_mutex_new();
        if (NULL == g_bleClientThreadPoolMutex)
        {
            OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "ca_mutex_new failed");
            return CA_STATUS_FAILED;
        }
    }

    if (NULL == g_bleClientConnectMutex)
    {
        g_bleClientConnectMutex = ca_mutex_new();
        if (NULL == g_bleClientConnectMutex)
        {
            OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "ca_mutex_new failed");
            return CA_STATUS_FAILED;
        }
    }

    if (NULL == g_bleClientSendCondWait)
    {
        g_bleClientSendCondWait = ca_cond_new();
        if (NULL == g_bleClientSendCondWait)
        {
            OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "ca_cond_new failed");
            return CA_STATUS_FAILED;
        }
    }

    if (NULL == g_bleServerBDAddressMutex)
    {
        g_bleServerBDAddressMutex = ca_mutex_new();
        if (NULL == g_bleServerBDAddressMutex)
        {
            OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "ca_mutex_new failed");
            return CA_STATUS_FAILED;
        }
    }

    OIC_LOG(DEBUG,  TZ_BLE_CLIENT_TAG, "OUT");
    return CA_STATUS_OK;
}
コード例 #17
0
// this implementation doesn't do a thread pool, so this function is essentially
// a no-op besides creating a valid ca_thread_pool_t object.  It was determined after
// reading through the existing implementation that the thread-pooling was unnecessary
// for the posix platforms.  Behavior shouldn't be changed since previously num_of_threads
// was greater than the number of requested threads.
CAResult_t ca_thread_pool_init(int32_t num_of_threads, ca_thread_pool_t *thread_pool)
{
    OIC_LOG(DEBUG, TAG, "IN");

    if(!thread_pool)
    {
        OIC_LOG(ERROR, TAG, "Parameter thread_pool was null!");
        return CA_STATUS_INVALID_PARAM;
    }

    if(num_of_threads <= 0)
    {
        OIC_LOG(ERROR, TAG, "num_of_threads must be positive and non-zero");
        return CA_STATUS_INVALID_PARAM;
    }

    *thread_pool = OICMalloc(sizeof(struct ca_thread_pool));

    if(!*thread_pool)
    {
        OIC_LOG(ERROR, TAG, "Failed to allocate for thread-pool");
        return CA_MEMORY_ALLOC_FAILED;
    }

    (*thread_pool)->details = OICMalloc(sizeof(struct ca_thread_pool_details_t));
    if(!(*thread_pool)->details)
    {
        OIC_LOG(ERROR, TAG, "Failed to allocate for thread-pool details");
        OICFree(*thread_pool);
        *thread_pool=NULL;
        return CA_MEMORY_ALLOC_FAILED;
    }

    (*thread_pool)->details->list_lock = ca_mutex_new();

    if(!(*thread_pool)->details->list_lock)
    {
        OIC_LOG(ERROR, TAG, "Failed to create thread-pool mutex");
        goto exit;
    }

    (*thread_pool)->details->threads_list = u_arraylist_create();

    if(!(*thread_pool)->details->threads_list)
    {
        OIC_LOG(ERROR, TAG, "Failed to create thread-pool list");
        if(!ca_mutex_free((*thread_pool)->details->list_lock))
        {
            OIC_LOG(ERROR, TAG, "Failed to free thread-pool mutex");
        }
        goto exit;
    }

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

exit:
    OICFree((*thread_pool)->details);
    OICFree(*thread_pool);
    *thread_pool = NULL;
    return CA_STATUS_FAILED;
}
コード例 #18
0
ファイル: peripheral.c プロジェクト: keyfour/iotivity
void CAPeripheralInitialize()
{
    g_context.lock      = ca_mutex_new();
    g_context.condition = ca_cond_new();
}
コード例 #19
0
ファイル: main.c プロジェクト: EmuxEvans/iotivity
void testThreadPool(void)
{
    char *string = "Test thread pool";

    //Initialize the mutex
    printf("[testThreadPool] Initializing mutex\n");

    //Initialize the thread pool
    printf("[testThreadPool] Initializing thread pool\n");
    if (CA_STATUS_OK != ca_thread_pool_init(2, &g_threadPoolHandle))
    {
        printf("thread_pool_init failed!\n");
        return;
    }

    //Create the mutex
    printf("[testThreadPool] Creating mutex\n");
    g_mutex = ca_mutex_new();
    if (NULL == g_mutex)
    {
        printf("[testThreadPool] Failed to create mutex!\n");
        ca_thread_pool_free(g_threadPoolHandle);
        return;
    }

    //Create the condition
    printf("[testThreadPool] Creating Condition\n");
    g_cond = ca_cond_new();
    if (NULL == g_cond)
    {
        printf("[testThreadPool] Failed to create condition!\n");
        ca_mutex_free(g_mutex);
        ca_thread_pool_free(g_threadPoolHandle);
        return;
    }

    //Lock the mutex
    printf("[testThreadPool] Locking the mutex\n");
    ca_mutex_lock(g_mutex);

    g_condFlag = false;
    //Add task to thread pool
    printf("[testThreadPool] Adding the task to thread pool\n");
    if (CA_STATUS_OK != ca_thread_pool_add_task(g_threadPoolHandle, task, (void *) string))
    {
        printf("[testThreadPool] thread_pool_add_task failed!\n");
        ca_thread_pool_free(g_threadPoolHandle);
        ca_mutex_unlock(g_mutex);
        ca_mutex_free(g_mutex);
        ca_cond_free(g_cond);
        return;
    }

    //Wait for the task to be executed
    printf("[testThreadPool] Waiting for the task to be completed\n");

    while (!g_condFlag)
    {
        ca_cond_wait(g_cond, g_mutex);
    }

    //Unlock the mutex
    printf("[testThreadPool] Got the signal and unlock the mutex\n");
    ca_mutex_unlock(g_mutex);

    printf("[testThreadPool] Task is completed and terminating threadpool\n");
    ca_cond_free(g_cond);
    ca_mutex_free(g_mutex);
    ca_thread_pool_free(g_threadPoolHandle);

    printf("Exiting from testThreadPool\n");
}