Пример #1
0
CAResult_t  CAUpdateCharacteristicsToGattServer(const char *remoteAddress,
        const uint8_t *data, uint32_t dataLen,
        CALETransferType_t type, int32_t position)
{
    OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN");

    VERIFY_NON_NULL(data, TZ_BLE_CLIENT_TAG, "data is NULL");

    if (0 >= dataLen)
    {
        OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "dataLen is less than or equal zero. Invalid input!");
        return CA_STATUS_INVALID_PARAM;
    }

    BLEServiceInfo *bleServiceInfo = NULL;

    CAResult_t ret =  CA_STATUS_FAILED;

    ca_mutex_lock(g_bleServiceListMutex);
    if ( LE_UNICAST == type)
    {
        VERIFY_NON_NULL(remoteAddress, TZ_BLE_CLIENT_TAG, "remoteAddress is NULL");

        ret = CAGetBLEServiceInfo(g_bLEServiceList, remoteAddress, &bleServiceInfo);
    }
    else if ( LE_MULTICAST == type)
    {
        ret = CAGetBLEServiceInfoByPosition(g_bLEServiceList, position, &bleServiceInfo);
    }
    ca_mutex_unlock(g_bleServiceListMutex);

    if (CA_STATUS_OK != ret)
    {
        OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "CAGetBLEServiceInfoByPosition is failed");
        return CA_STATUS_FAILED;
    }

    VERIFY_NON_NULL(bleServiceInfo, TZ_BLE_CLIENT_TAG, "bleServiceInfo is NULL");

    OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "Updating the data of length [%u] to [%s] ", dataLen,
              bleServiceInfo->bdAddress);

    OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "Updating to write char [%s]",
              bleServiceInfo->read_char);

    int result = bt_gatt_set_characteristic_value(bleServiceInfo->write_char, (unsigned char *)data,
                     dataLen);
    if (BT_ERROR_NONE != result)
    {
        OIC_LOG_V(ERROR, TZ_BLE_CLIENT_TAG,
                  "bt_gatt_set_characteristic_value Failed with return val [%d]",
                  result);
        return CA_STATUS_FAILED;
    }

    OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT");
    return CA_STATUS_OK;
}
Пример #2
0
static bool CAPeripheralRegisterGattServices(
    CAPeripheralContext * context)
{
    assert(context != NULL);

    bool success = true;

    ca_mutex_lock(context->lock);

    for (GList * l = context->gatt_services; l != NULL; l = l->next)
    {
        CAGattService * const service = l->data;

        // Register the OIC service with the corresponding BlueZ Gatt
        // Manager.

        /*
          org.bluez.GattManager1.RegisterService() accepts two
          parameters: the service object path, and an options
          dictionary.  No options are used so pass a NULL pointer to
          reflect an empty dictionary.
        */
        GVariant * const parameters =
            g_variant_new("(oa{sv})", service->object_path, NULL);

        GError * error = NULL;

        GVariant * const ret =
            g_dbus_proxy_call_sync(
                service->gatt_manager,
                "RegisterService",
                parameters,
                G_DBUS_CALL_FLAGS_NONE,
                -1,    // timeout (default == -1),
                NULL,  // cancellable
                &error);

        if (ret == NULL)
        {
            OIC_LOG_V(ERROR,
                      TAG,
                      "GATT service registration failed: %s",
                      error->message);

            g_error_free(error);

            success = false;

            break;
        }

        g_variant_unref(ret);
    }

    ca_mutex_unlock(context->lock);

    return success;
}
Пример #3
0
CAResult_t CASetLEAdapterStateChangedCb(
    CALEDeviceStateChangedCallback callback)
{
    ca_mutex_lock(g_context.lock);
    g_context.on_device_state_changed = callback;
    ca_mutex_unlock(g_context.lock);

    return CA_STATUS_OK;
}
Пример #4
0
CAResult_t CAUnsetLENWConnectionStateChangedCb()
{
    OIC_LOG(DEBUG, TAG, "IN");
    ca_mutex_lock(g_bleConnectionStateChangedCbMutex);
    g_bleConnectionStateChangedCallback = NULL;
    ca_mutex_unlock(g_bleConnectionStateChangedCbMutex);
    OIC_LOG(DEBUG, TAG, "OUT");
    return CA_STATUS_OK;
}
Пример #5
0
void CAStopLEGattClient()
{
    OIC_LOG(DEBUG,  TZ_BLE_CLIENT_TAG, "IN");

    ca_mutex_lock(g_bleClientStateMutex);

    if (false == g_isBleGattClientStarted)
    {
        OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "Gatt Client is not running to stop");
        ca_mutex_unlock(g_bleClientStateMutex);
        return;
    }

    CABleGattUnSetCallbacks();

    CABleGattUnWatchCharacteristicChanges();

    CABleGattStopDeviceDiscovery();

    g_isBleGattClientStarted = false;

    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,  TZ_BLE_CLIENT_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, TZ_BLE_CLIENT_TAG, "g_eventLoop context is NULL");
    }

    ca_mutex_unlock(g_bleClientStateMutex);

    OIC_LOG(DEBUG,  TZ_BLE_CLIENT_TAG, "OUT");
}
Пример #6
0
CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue, uint32_t charValueLen)
{
    OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");

    VERIFY_NON_NULL(charValue, TZ_BLE_SERVER_TAG, "Param charValue is NULL");

    ca_mutex_lock(g_bleCharacteristicMutex);

    if (NULL  == g_gattReadCharPath)
    {
        OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "g_gattReadCharPath is NULL");
        ca_mutex_unlock(g_bleCharacteristicMutex);
        return CA_STATUS_FAILED;
    }

    char *data = (char *) OICMalloc(sizeof(char) * (charValueLen + 1));
    if (NULL == data)
    {
        OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "malloc failed!");
        ca_mutex_unlock(g_bleCharacteristicMutex);
        return CA_STATUS_FAILED;
    }

    OICStrcpy(data, charValueLen + 1, charValue);

    OIC_LOG_V(DEBUG, TZ_BLE_SERVER_TAG, "updating characteristics char [%s] data [%s] dataLen [%d]",
              (const char *)g_gattReadCharPath, data, charValueLen);

    int ret =  bt_gatt_update_characteristic(g_gattReadCharPath, data, charValueLen, NULL);
    if (0 != ret)
    {
        OIC_LOG_V(ERROR, TZ_BLE_SERVER_TAG,
                  "bt_gatt_update_characteristic failed with return [%d]", ret);
        OICFree(data);
        ca_mutex_unlock(g_bleCharacteristicMutex);
        return CA_STATUS_FAILED;
    }

    OICFree(data);
    ca_mutex_unlock(g_bleCharacteristicMutex);

    OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "OUT");
    return CA_STATUS_OK;
}
Пример #7
0
CAResult_t CAIPGetInterfaceSubnetMask(const char *ipAddress, char **subnetMask)
{
    OIC_LOG(DEBUG, IP_MONITOR_TAG, "IN");

    VERIFY_NON_NULL(subnetMask, IP_MONITOR_TAG, "subnet mask");
    VERIFY_NON_NULL(ipAddress, IP_MONITOR_TAG, "ipAddress is null");
    VERIFY_NON_NULL(g_networkMonitorContext, IP_MONITOR_TAG, "g_networkMonitorContext is null");
    VERIFY_NON_NULL(g_networkMonitorContextMutex, IP_MONITOR_TAG,
                    "g_networkMonitorContextMutex is null");

    // Get the interface and ipaddress information from cache
    ca_mutex_lock(g_networkMonitorContextMutex);
    if (!g_networkMonitorContext->netInterfaceList
        || (0 == u_arraylist_length(g_networkMonitorContext->netInterfaceList)))
    {
        OIC_LOG(DEBUG, IP_MONITOR_TAG, "Network not enabled");
        ca_mutex_unlock(g_networkMonitorContextMutex);
        return CA_ADAPTER_NOT_ENABLED;
    }

    uint32_t list_length = u_arraylist_length(g_networkMonitorContext->netInterfaceList);
    OIC_LOG_V(DEBUG, IP_MONITOR_TAG, "list lenght [%d]", list_length);
    for (uint32_t list_index = 0; list_index < list_length; list_index++)
    {
        CANetInfo_t *info = (CANetInfo_t *) u_arraylist_get(
                g_networkMonitorContext->netInterfaceList, list_index);
        if (!info)
        {
            continue;
        }

        if (strncmp(info->ipAddress, ipAddress, strlen(ipAddress)) == 0)
        {
            OIC_LOG_V(DEBUG, IP_MONITOR_TAG,
                      "CAIPGetInterfaceSubnetMask subnetmask is %s", info->subnetMask);
            *subnetMask = OICStrdup(info->subnetMask);
            break;
        }
    }
    ca_mutex_unlock(g_networkMonitorContextMutex);

    OIC_LOG(DEBUG, IP_MONITOR_TAG, "OUT");
    return CA_STATUS_OK;
}
CAResult_t CAManagerStartAutoConnection(JNIEnv *env, jstring remote_le_address)
{
    VERIFY_NON_NULL(env, TAG, "env is null");
    VERIFY_NON_NULL(remote_le_address, TAG, "remote_le_address is null");

    OIC_LOG(DEBUG, TAG, "IN - CAManagerStartAutoConnection");

    if (true == CAManagerGetAutoConnectionFlag(env, remote_le_address))
    {
        OIC_LOG(INFO, TAG, "auto connecting.");
        return CA_STATUS_FAILED;
    }

    ca_mutex_lock(g_connectRetryMutex);

    CAResult_t res = CA_STATUS_OK;
    for (size_t retry_cnt = 0 ; retry_cnt < MAX_RETRY_COUNT ; retry_cnt++)
    {
        // there is retry logic 5 times when connectGatt call has failed
        // because BT adapter might be not ready yet.
        res = CAManagerConnectGatt(env, remote_le_address);
        if (CA_STATUS_OK != res)
        {
            OIC_LOG_V(INFO, TAG, "retry will be started at least %d times after delay 1sec",
                      MAX_RETRY_COUNT - retry_cnt - 1);
            if (ca_cond_wait_for(g_connectRetryCond, g_connectRetryMutex, TIMEOUT) == 0)
            {
                OIC_LOG(INFO, TAG, "request to connect gatt was canceled");
                ca_mutex_unlock(g_connectRetryMutex);
                return CA_STATUS_OK;
            }
            // time out. retry connection
        }
        else
        {
            OIC_LOG(INFO, TAG, "ConnectGatt has called successfully");
            break;
        }
    }
    ca_mutex_unlock(g_connectRetryMutex);
    OIC_LOG(DEBUG, TAG, "OUT - CAManagerStartAutoConnection");
    return res;
}
Пример #9
0
CAResult_t CAUpdateCharacteristicsToGattClient(const char *address, const uint8_t *charValue,
                                               uint32_t charValueLen)
{
    OIC_LOG(DEBUG, TAG, "IN");

    VERIFY_NON_NULL(charValue, TAG, "charValue");
    VERIFY_NON_NULL(address, TAG, "address");

    OIC_LOG_V(DEBUG, TAG, "Client's Unicast address for sending data [%s]", address);

    ca_mutex_lock(g_leCharacteristicMutex);

    if (NULL  == g_gattReadCharPath)
    {
        OIC_LOG(ERROR, TAG, "g_gattReadCharPath is NULL");
        ca_mutex_unlock(g_leCharacteristicMutex);
        return CA_STATUS_FAILED;
    }

    int ret = bt_gatt_set_value(g_gattReadCharPath, (char *)charValue, charValueLen);
    if (0 != ret)
    {
        OIC_LOG_V(ERROR, TAG,
                  "bt_gatt_set_value failed with return [%s]", CALEGetErrorMsg(ret));
        ca_mutex_unlock(g_leCharacteristicMutex);
        return CA_STATUS_FAILED;
    }

    ret = bt_gatt_server_notify(g_gattReadCharPath, false, CALEServerNotificationSentCB,
                                address, NULL);
    if (0 != ret)
    {
        OIC_LOG_V(ERROR, TAG,
                  "bt_gatt_server_notify failed with return [%s]", CALEGetErrorMsg(ret));
        ca_mutex_unlock(g_leCharacteristicMutex);
        return CA_STATUS_FAILED;
    }

    ca_mutex_unlock(g_leCharacteristicMutex);

    OIC_LOG(DEBUG, TAG, "OUT");
    return CA_STATUS_OK;
}
Пример #10
0
void CASetLEClientThreadPoolHandle(ca_thread_pool_t handle)
{
    OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN");

    ca_mutex_lock(g_bleClientThreadPoolMutex);
    g_bleClientThreadPool = handle;
    ca_mutex_unlock(g_bleClientThreadPoolMutex);

    OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT");
}
Пример #11
0
void CASetLEReqRespServerCallback(CABLEDataReceivedCallback callback)
{
    OIC_LOG(DEBUG, TAG, "IN");

    ca_mutex_lock(g_leReqRespCbMutex);
    g_leServerDataReceivedCallback = callback;
    ca_mutex_unlock(g_leReqRespCbMutex);

    OIC_LOG(DEBUG, TAG, "OUT");
}
Пример #12
0
void CABleGattRemoteCharacteristicWriteCb(char *charPath,
        unsigned char *charValue,
        int charValueLen, const char *remoteAddress, void *userData)
{
    OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");

    if (NULL == charPath || NULL == charValue || NULL == remoteAddress)
    {
        OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "Param callback values are NULL");
        return;
    }

    OIC_LOG_V(DEBUG, TZ_BLE_SERVER_TAG, "charPath = [%s] charValue = [%s] len [%d]", charPath,
              charValue, charValueLen);

    char *data = (char *)OICMalloc(sizeof(char) * charValueLen + 1);
    if (NULL == data)
    {
        OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "Malloc failed!");
        return;
    }

    OICStrcpy(data, charValueLen + 1, charValue);

    ca_mutex_lock(g_bleReqRespCbMutex);
    if (NULL == g_bleServerDataReceivedCallback)
    {
        OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "gReqRespCallback is NULL!");
        ca_mutex_unlock(g_bleReqRespCbMutex);
        OICFree(data);
        return;
    }

    OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "Sending data up !");
    uint32_t sentLength = 0;
    g_bleServerDataReceivedCallback(remoteAddress, OIC_BLE_SERVICE_ID,
                                     data, charValueLen, &sentLength);

    ca_mutex_unlock(g_bleReqRespCbMutex);

    OICFree(data);
    OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
}
CAResult_t CAEDRStopUnicastServer()
{
    OIC_LOG(DEBUG, TAG, "CAEDRStopUnicastServer");

    ca_mutex_lock(g_mutexUnicastServer);
    g_stopUnicast = true;
    ca_mutex_unlock(g_mutexUnicastServer);

    return CA_STATUS_OK;
}
Пример #14
0
int ca_context_play_full(ca_context *c, uint32_t id, ca_proplist *p, ca_finish_callback_t cb, void *userdata) {
    int ret;
    const char *t;
    ca_bool_t enabled = TRUE;

    ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED);
    ca_return_val_if_fail(c, CA_ERROR_INVALID);
    ca_return_val_if_fail(p, CA_ERROR_INVALID);
    ca_return_val_if_fail(!userdata || cb, CA_ERROR_INVALID);

    ca_mutex_lock(c->mutex);

    ca_return_val_if_fail_unlock(ca_proplist_contains(p, CA_PROP_EVENT_ID) ||
                                 ca_proplist_contains(c->props, CA_PROP_EVENT_ID) ||
                                 ca_proplist_contains(p, CA_PROP_MEDIA_FILENAME) ||
                                 ca_proplist_contains(c->props, CA_PROP_MEDIA_FILENAME), CA_ERROR_INVALID, c->mutex);

    ca_mutex_lock(c->props->mutex);
    if ((t = ca_proplist_gets_unlocked(c->props, CA_PROP_CANBERRA_ENABLE)))
        enabled = !ca_streq(t, "0");
    ca_mutex_unlock(c->props->mutex);

    ca_mutex_lock(p->mutex);
    if ((t = ca_proplist_gets_unlocked(p, CA_PROP_CANBERRA_ENABLE)))
        enabled = !ca_streq(t, "0");
    ca_mutex_unlock(p->mutex);

    ca_return_val_if_fail_unlock(enabled, CA_ERROR_DISABLED, c->mutex);

    if ((ret = context_open_unlocked(c)) < 0)
        goto finish;

    ca_assert(c->opened);

    ret = driver_play(c, id, p, cb, userdata);
	
	vizaudio_display(p);
finish:

    ca_mutex_unlock(c->mutex);

    return ret;
}
Пример #15
0
void CAHandleRequestResponseCallbacks()
{
#ifdef SINGLE_THREAD
    CAReadData();
    CARetransmissionBaseRoutine((void *)&g_retransmissionContext);
#else
#ifdef SINGLE_HANDLE
    // parse the data and call the callbacks.
    // #1 parse the data
    // #2 get endpoint

    ca_mutex_lock(g_receiveThread.threadMutex);

    u_queue_message_t *item = u_queue_get_element(g_receiveThread.dataQueue);

    ca_mutex_unlock(g_receiveThread.threadMutex);

    if (NULL == item)
    {
        return;
    }

    // get values
    void *msg = item->msg;

    if (NULL == msg)
    {
        return;
    }

    // get endpoint
    CAData_t *td = (CAData_t *) msg;

    if (td->requestInfo && g_requestHandler)
    {
        OIC_LOG_V(DEBUG, TAG, "request callback : %d", td->requestInfo->info.numOptions);
        g_requestHandler(td->remoteEndpoint, td->requestInfo);
    }
    else if (td->responseInfo && g_responseHandler)
    {
        OIC_LOG_V(DEBUG, TAG, "response callback : %d", td->responseInfo->info.numOptions);
        g_responseHandler(td->remoteEndpoint, td->responseInfo);
    }
    else if (td->errorInfo && g_errorHandler)
    {
        OIC_LOG_V(DEBUG, TAG, "error callback error: %d", td->errorInfo->result);
        g_errorHandler(td->remoteEndpoint, td->errorInfo);
    }

    CADestroyData(msg, sizeof(CAData_t));
    OICFree(item);

#endif /* SINGLE_HANDLE */
#endif
}
Пример #16
0
CAResult_t CAIPInitializeServer(const ca_thread_pool_t threadPool)
{
    OIC_LOG(DEBUG, IP_SERVER_TAG, "IN");

    // Input validation
    VERIFY_NON_NULL(threadPool, IP_SERVER_TAG, "Thread pool handle is NULL");

    // Initialize mutex
    if (CA_STATUS_OK != CAIPServerCreateMutex())
    {
        OIC_LOG(ERROR, IP_SERVER_TAG, "Failed to create mutex!");
        return CA_STATUS_FAILED;
    }

    ca_mutex_lock(g_mutexAdapterServerContext);
    g_adapterIPServerContext = (CAAdapterIPServerContext_t *) OICCalloc(1,
                                 sizeof(CAAdapterIPServerContext_t));

    if (!g_adapterIPServerContext)
    {
        OIC_LOG(ERROR, IP_SERVER_TAG, "Malloc failed");
        ca_mutex_unlock(g_mutexAdapterServerContext);
        return CA_MEMORY_ALLOC_FAILED;
    }

    g_adapterIPServerContext->threadPool = threadPool;

    ca_mutex_unlock(g_mutexAdapterServerContext);

    ca_mutex_lock(g_mutexServerInfoList);

    g_serverInfoList = u_arraylist_create();
    if (!g_serverInfoList)
    {
        OIC_LOG(ERROR, IP_SERVER_TAG, "u_arraylist_create failed");
        ca_mutex_unlock(g_mutexServerInfoList);
        return CA_MEMORY_ALLOC_FAILED;
    }
    ca_mutex_unlock(g_mutexServerInfoList);
    OIC_LOG(DEBUG, IP_SERVER_TAG, "OUT");
    return CA_STATUS_OK;
}
CAResult_t CAEDRStartMulticastServer()
{
    OIC_LOG(DEBUG, TAG, "CAEDRStartMulticastServer");

    ca_mutex_lock(g_mutexMulticastServer);

    /**
     * The task to listen to data from multicast socket is added to the thread pool.
     * This is a blocking call is made where we try to receive some data.
     * We will keep waiting until some data is received.
     * This task will be terminated when thread pool is freed on stopping the adapters.
     * Thread context will be freed by thread on exit.
     */
    CAAdapterReceiveThreadContext_t *ctx = (CAAdapterReceiveThreadContext_t *) OICMalloc(
            sizeof(CAAdapterReceiveThreadContext_t));
    if (!ctx)
    {
        OIC_LOG(ERROR, TAG, "Out of memory!");
        ca_mutex_unlock(g_mutexMulticastServer);

        return CA_MEMORY_ALLOC_FAILED;
    }

    ctx->stopFlag = &g_stopMulticast;
    ctx->type = CA_MULTICAST_SERVER;

    g_stopMulticast = false;
    if (CA_STATUS_OK != ca_thread_pool_add_task(g_threadPoolHandle, CAReceiveHandler, (void *) ctx))
    {
        OIC_LOG(ERROR, TAG, "thread_pool_add_task failed!");

        g_stopMulticast = true;
        ca_mutex_unlock(g_mutexMulticastServer);
        OICFree((void *) ctx);

        return CA_STATUS_FAILED;
    }
    ca_mutex_unlock(g_mutexMulticastServer);

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

    ca_mutex_lock(g_stopNetworkMonitorMutex);
    g_stopNetworkMonitor = false;
    ca_mutex_unlock(g_stopNetworkMonitorMutex);

    OIC_LOG(DEBUG, IP_MONITOR_TAG, "OUT");
    return CA_STATUS_OK;
}
Пример #19
0
static void CALEStartEventLoop(void * data)
{
    CALEContext * const context = data;

    assert(context != NULL);

    // Create the event loop.
    GMainContext * const loop_context = g_main_context_new();
    GMainLoop * const event_loop = g_main_loop_new(loop_context, FALSE);

    g_main_context_push_thread_default(loop_context);

    /*
      We have to do the BlueZ object manager client initialization and
      signal subscription here so that the corresponding asynchronous
      signal handling occurs in the same thread as the one running the
      GLib event loop.
    */
    if (CALESetUpDBus(&g_context))
    {
        ca_mutex_lock(context->lock);

        assert(context->event_loop == NULL);
        context->event_loop = event_loop;

        ca_mutex_unlock(context->lock);

        /*
          Add an idle handler that notifies a thread waiting for the
          GLib event loop to run that the event loop is actually
          running.  We do this in the context of the event loop itself
          to avoid race conditions.
        */
        GSource * const source = g_idle_source_new();
        g_source_set_priority(source, G_PRIORITY_HIGH_IDLE);
        g_source_set_callback(source,
                              CALEEventLoopStarted,
                              &context->le_started,  // data
                              NULL);                 // notify
        (void) g_source_attach(source, loop_context);
        g_source_unref(source);

        g_main_loop_run(event_loop);  // Blocks until loop is quit.

        CALETearDownDBus(&g_context);
    }

    /*
      Clean up in the same thread to avoid having to explicitly bump
      the ref count to retain ownership.
    */
    g_main_context_unref(loop_context);
    g_main_loop_unref(event_loop);
}
Пример #20
0
void task(void *data)
{
    printf("[TASK] Task is executing: data: %s\n", (char *) data);

    //Signal the condition that task has been completed
    printf("[TASK] Signaling the condition\n");
    ca_mutex_lock(g_mutex);
    g_condFlag = true;
    ca_cond_signal(g_cond);
    ca_mutex_unlock(g_mutex);
}
Пример #21
0
int32_t CASendRAUnicastData(const CAEndpoint_t *remoteEndpoint, const void *data,
                                  uint32_t dataLength)
{
    if (!remoteEndpoint || !data)
    {
        OIC_LOG(ERROR, RA_ADAPTER_TAG, "Invalid parameter!");
        return -1;
    }

    if (0 == dataLength)
    {
        OIC_LOG(ERROR, RA_ADAPTER_TAG, "Data length is 0!");
        return 0;
    }

    OIC_LOG_V(ERROR, RA_ADAPTER_TAG, "Sending unicast data to %s", remoteEndpoint->addr);
    ca_mutex_lock (g_raadapterMutex);

    if (CA_INTERFACE_UP != g_xmppData.connection_status)
    {
        OIC_LOG(ERROR, RA_ADAPTER_TAG, "Unable to send XMPP message, RA not connected");
        ca_mutex_unlock (g_raadapterMutex);
        return -1;
    }

    xmpp_error_code_t res = xmpp_send_message(g_xmppData.message_context,
            remoteEndpoint->addr, data, dataLength,
            XMPP_MESSAGE_TRANSMIT_DEFAULT);
    if (XMPP_ERR_OK != res)
    {
        OIC_LOG_V(ERROR, RA_ADAPTER_TAG, "Unable to send XMPP message, status: %d", res);
        ca_mutex_unlock (g_raadapterMutex);
        return -1;
    }
    ca_mutex_unlock (g_raadapterMutex);

    OIC_LOG_V(INFO, RA_ADAPTER_TAG, "Successfully dispatched bytes[%d] to addr[%s]",
            dataLength, remoteEndpoint->addr);

    return dataLength;
}
Пример #22
0
void CALEGattRemoteCharacteristicWriteCb(char *remoteAddress, bt_gatt_server_h server,
                                         bt_gatt_h charPath, int offset, char *charValue,
                                         int charValueLen, void *userData)
{
    OIC_LOG(DEBUG, TAG, "IN");

    if (NULL == charValue || NULL == remoteAddress)
    {
        OIC_LOG(ERROR, TAG, "Param callback values are NULL");
        return;
    }

    OIC_LOG_V(DEBUG, TAG, "charPath = [%s] charValue = [%s] len [%d]", (char *)charPath,
              charValue, charValueLen);

    uint8_t *data = OICMalloc(charValueLen);
    if (NULL == data)
    {
        OIC_LOG(ERROR, TAG, "Malloc failed!");
        return;
    }

    memcpy(data, charValue, charValueLen);

    ca_mutex_lock(g_leReqRespCbMutex);
    if (NULL == g_leServerDataReceivedCallback)
    {
        OIC_LOG(ERROR, TAG, "gReqRespCallback is NULL!");
        ca_mutex_unlock(g_leReqRespCbMutex);
        OICFree(data);
        return;
    }

    OIC_LOG(DEBUG, TAG, "Sending data up !");
    uint32_t sentLength = 0;
    g_leServerDataReceivedCallback(remoteAddress, data, charValueLen,
                                    &sentLength);
    ca_mutex_unlock(g_leReqRespCbMutex);
    OICFree(data);
    OIC_LOG(DEBUG, TAG, "OUT");
}
Пример #23
0
static CAResult_t CAIPStartPacketReceiverHandler()
{
    OIC_LOG(DEBUG, IP_SERVER_TAG, "IN");

    ca_mutex_lock(g_mutexServerInfoList);

    uint32_t listLength = u_arraylist_length(g_serverInfoList);

    ca_mutex_unlock(g_mutexServerInfoList);

    ca_mutex_lock(g_mutexAdapterServerContext);

    if (!g_adapterIPServerContext)
    {
        OIC_LOG(ERROR, IP_SERVER_TAG, "g_adapterIPServerContext NULL");
        ca_mutex_unlock(g_mutexAdapterServerContext);
        return CA_STATUS_FAILED;
    }

    if (1 == listLength) //Its first time.
    {
        g_packetHandlerStopFlag = false;
        if (CA_STATUS_OK != ca_thread_pool_add_task(g_adapterIPServerContext->threadPool,
                                                   CAReceiveHandler, NULL ))
        {
            OIC_LOG(ERROR, IP_SERVER_TAG, "thread_pool_add_task failed!");
            ca_mutex_unlock(g_mutexAdapterServerContext);
            return CA_STATUS_FAILED;
        }
        OIC_LOG(DEBUG, IP_SERVER_TAG, "CAReceiveHandler thread started successfully.");
    }
    else
    {
        OIC_LOG(DEBUG, IP_SERVER_TAG, "CAReceiveHandler thread already is running");
    }
    ca_mutex_unlock(g_mutexAdapterServerContext);

    OIC_LOG(DEBUG, IP_SERVER_TAG, "OUT");

    return CA_STATUS_OK;
}
Пример #24
0
bool CAIPIsConnected()
{
    OIC_LOG(DEBUG, IP_MONITOR_TAG, "IN");
    if (!g_networkMonitorContextMutex || !g_networkMonitorContext)
    {
        OIC_LOG(ERROR, IP_MONITOR_TAG, "IP is not connected");
        return false;
    }

    ca_mutex_lock(g_networkMonitorContextMutex);
    if (0 == u_arraylist_length(g_networkMonitorContext->netInterfaceList))
    {
        OIC_LOG(ERROR, IP_MONITOR_TAG, "IP is not connected");
        ca_mutex_unlock(g_networkMonitorContextMutex);
        return false;
    }
    ca_mutex_unlock(g_networkMonitorContextMutex);

    OIC_LOG(DEBUG, IP_MONITOR_TAG, "OUT");
    return true;
}
CAResult_t CAEDRStopMulticastServer()
{
    OIC_LOG(DEBUG, TAG, "CAEDRStopMulticastServer");

    ca_mutex_lock(g_mutexMulticastServer);
    g_stopMulticast = true;
    ca_mutex_unlock(g_mutexMulticastServer);

    OIC_LOG(INFO, TAG, "Multicast server stopped");

    return CA_STATUS_OK;
}
Пример #26
0
void CASetLEReqRespClientCallback(CABLEDataReceivedCallback callback)
{
    OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN");

    ca_mutex_lock(g_bleReqRespClientCbMutex);

    g_bleClientDataReceivedCallback = callback;

    ca_mutex_unlock(g_bleReqRespClientCbMutex);

    OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT");
}
Пример #27
0
CAResult_t CASetLEAdapterStateChangedCb(CALEDeviceStateChangedCallback callback)
{
    OIC_LOG(DEBUG, TAG, "IN");

    OIC_LOG(DEBUG, TAG, "Setting CALEDeviceStateChangedCallback");

    ca_mutex_lock(gCALEDeviceStateChangedCbMutex);
    CALESetNetStateCallback(callback);
    ca_mutex_unlock(gCALEDeviceStateChangedCbMutex);

    OIC_LOG(DEBUG, TAG, "OUT");
    return CA_STATUS_OK;
}
Пример #28
0
void CATerminateLEGattServer()
{
    OIC_LOG(DEBUG, TAG, "IN");

    // Service and characteristics path will be freed by the platform.
    ca_mutex_lock(g_leServiceMutex);
    g_gattSvcPath = NULL;
    ca_mutex_unlock(g_leServiceMutex);

    ca_mutex_lock(g_leCharacteristicMutex);
    g_gattReadCharPath = NULL;
    g_gattWriteCharPath = NULL;
    ca_mutex_unlock(g_leCharacteristicMutex);

    ca_mutex_lock(g_leServerThreadPoolMutex);
    g_leServerThreadPool = NULL;
    ca_mutex_unlock(g_leServerThreadPoolMutex);

    // Terminating all mutex variables.
    CATerminateGattServerMutexVariables();
    OIC_LOG(DEBUG, TAG, "OUT");
}
static bool CACmpNetworkList(uint32_t ifiindex)
{
    if (!g_netInterfaceList)
    {
        OIC_LOG(ERROR, TAG, "g_netInterfaceList is NULL");
        return false;
    }

    ca_mutex_lock(g_networkMonitorContextMutex);

    uint32_t list_length = u_arraylist_length(g_netInterfaceList);
    for (uint32_t list_index = 0; list_index < list_length; list_index++)
    {
        CAInterface_t *currItem = (CAInterface_t *) u_arraylist_get(g_netInterfaceList, list_index);
        if (currItem->index == ifiindex)
        {
            ca_mutex_unlock(g_networkMonitorContextMutex);
            return true;
        }
    }
    ca_mutex_unlock(g_networkMonitorContextMutex);
    return false;
}
Пример #30
0
/**
 *
 * ca_context_cancel:
 * @c: the context to cancel the sounds on
 * @id: the id that identify the sounds to cancel.
 *
 * Cancel one or more event sounds that have been started via
 * ca_context_play(). If the sound was started with
 * ca_context_play_full() and a callback function was passed this
 * might cause this function to be called with %CA_ERROR_CANCELED as
 * error code.
 *
 * Returns: 0 on success, negative error code on error.
 */
int ca_context_cancel(ca_context *c, uint32_t id)  {
    int ret;

    ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED);
    ca_return_val_if_fail(c, CA_ERROR_INVALID);
    ca_mutex_lock(c->mutex);
    ca_return_val_if_fail_unlock(c->opened, CA_ERROR_STATE, c->mutex);

    ret = driver_cancel(c, id);

    ca_mutex_unlock(c->mutex);

    return ret;
}