Example #1
0
void CAManagerTerminateLEAutoConnection()
{
    if (g_connectRetryCond)
    {
        ca_cond_signal(g_connectRetryCond);
        ca_cond_free(g_connectRetryCond);
        g_connectRetryCond = NULL;
    }

    if (g_connectRetryMutex)
    {
        ca_mutex_free(g_connectRetryMutex);
        g_connectRetryMutex = NULL;
    }

    if (g_recoveryCond)
    {
        ca_cond_signal(g_recoveryCond);
        ca_cond_free(g_recoveryCond);
        g_recoveryCond = NULL;
    }

    if (g_recoveryMutex)
    {
        ca_mutex_free(g_recoveryMutex);
        g_recoveryMutex = NULL;
    }
}
Example #2
0
/**
 * Inform thread waiting for the event loop to start that the loop has
 * started.  This is done in the context of the event loop itself so
 * that we can be certain that the event loop is indeed running.
 */
static gboolean CAPeripheralEventLoopStarted(gpointer user_data)
{
    ca_cond const condition = user_data;

    ca_cond_signal(condition);  // For service registration

    return G_SOURCE_REMOVE;
}
Example #3
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);
}
Example #4
0
static void CAReceiveHandler(void *data)
{
    (void)data;
    OIC_LOG(DEBUG, TAG, "IN - CAReceiveHandler");

    while (!caglobals.tcp.terminate)
    {
        CAFindReadyMessage();
    }

    ca_mutex_lock(g_mutexObjectList);
    ca_cond_signal(g_condObjectList);
    ca_mutex_unlock(g_mutexObjectList);

    OIC_LOG(DEBUG, TAG, "OUT - CAReceiveHandler");
}
static void CALEHandleInterfaceAdded(GList ** proxy_list,
                                     char const * interface,
                                     GVariant * parameters)
{
    /**
     * @note The @a parameters are of the form "(oa{sv})".
     */
    GDBusProxy * const proxy =
        CAGetBlueZInterfaceProxy(parameters,
                                 interface,
                                 g_context.object_manager);

    if (proxy == NULL)
    {
        return;
    }

    ca_mutex_lock(g_context.lock);

    /*
      Add the object information to the list.

      Note that we prepend instead of append in this case since it
      is more efficient to do so for linked lists like the one used
      here.
    */
    *proxy_list = g_list_prepend(*proxy_list, proxy);

    ca_mutex_unlock(g_context.lock);

    /**
     * Let the thread that may be blocked waiting for Devices to be
     * discovered know that at least one was found.
     *
     * @todo It doesn't feel good putting this @c org.bluez.Device1
     *       specific code here since this function is meant to be
     *       BlueZ interface neutral.  Look into ways of moving this
     *       out of here.
     */
    if (strcmp(interface, BLUEZ_DEVICE_INTERFACE) == 0)
    {
        ca_cond_signal(g_context.condition);
    }
}
Example #6
0
static void CAReceiveHandler(void *data)
{
    (void)data;
    OIC_LOG(DEBUG, TAG, "IN - CAReceiveHandler");

    while (!caglobals.tcp.terminate)
    {
        CAReceiveMessage();
    }

    ca_mutex_lock(g_mutexObjectList);
    // notify the thread
    g_threadCounts--;
    if (!g_threadCounts)
    {
        ca_cond_signal(g_condObjectList);
    }
    ca_mutex_unlock(g_mutexObjectList);

    OIC_LOG(DEBUG, TAG, "OUT - CAReceiveHandler");
}
Example #7
0
static void CAPeripheralStartEventLoop(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);

    // Acquire the bus name after exporting our D-Bus objects.
    guint const owner_id =
        g_bus_own_name_on_connection(context->connection,
                                     CA_DBUS_GATT_SERVICE_NAME,
                                     G_BUS_NAME_OWNER_FLAGS_NONE,
                                     CAPeripheralOnNameAcquired,
                                     CAPeripheralOnNameLost,
                                     NULL, // user_data,
                                     NULL);

    /**
     * Create proxies to the @c org.bluez.LEAdvertisingManager1 D-Bus
     * objects that will later be used to register the OIC LE
     * advertisement data.
     *
     * @todo Failure to retrieve the LE advertising managers is
     *       currently ignored.  We should propagate the failure to
     *       the thread that spawned this one.
     *
     * @note Retrieval of the @c org.bluez.LEAdvertisingManager1
     *       proxies must be done in a thread separate from the one
     *       that makes calls through those proxies since the
     *       underlying GDBusObjectManagerClient sets up signal
     *       subscriptions that are used when dispatching D-Bus method
     *       handling calls (e.g. property retrieval, etc).
     *       Otherwise, a distributed deadlock situation could occur
     *       if a synchronous D-Bus proxy call is made that causes the
     *       recipient (like BlueZ) to call back in to the thread that
     *       handles signals.  For example, registration of our LE
     *       advertisment with BlueZ causes BlueZ itself to make a
     *       call to our own @c org.bluez.LEAdvertisement1 object.
     *       However, the thread that initiated the advertisement
     *       registration is blocked waiting for BlueZ to respond, but
     *       BlueZ is blocked waiting for that same thread to respond
     *       to its own advertisement property retrieval call.
     */
    GList * advertising_managers = NULL;
    if (!CAGetBlueZManagedObjectProxies(
            &advertising_managers,
            BLUEZ_ADVERTISING_MANAGER_INTERFACE,
            context,
            NULL))
    {
        OIC_LOG(ERROR,
                TAG,
                "Failed to retrieve BlueZ LE advertising "
                "manager interface.");
    }

    ca_mutex_lock(g_context.lock);

    assert(g_context.event_loop == NULL);
    g_context.event_loop = event_loop;

    g_context.base = context;

    g_context.owner_id = owner_id;

    /**
     * Initialize all GATT services.
     *
     * @todo Failure to initialize the OIC GATT services is currently
     *       ignored.  We should propagate the failure to the thread
     *       that spawned this one.
     *
     * @note See the @c org.bluez.LEAdvertisingManager1 note above to
     *       understand why the GATT services must be initialized in
     *       a thread seperate from the one that initiates GATT
     *       service registration.
     */
    g_context.gatt_services = CAPeripheralInitializeGattServices(context);

    CALEAdvertisementInitialize(&g_context.advertisement,
                                context->connection,
                                advertising_managers);

    ca_mutex_unlock(g_context.lock);

    ca_cond_signal(g_context.condition);

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

    /*
      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);
}