Beispiel #1
0
static gboolean bt_any_to_connected(const gchar *type,
        const gchar *path,
        enum bt_state prev_state,
        enum bt_state new_state)
{
    (void) prev_state;
    (void) new_state;
    (void) path;

    OHM_DEBUG(DBG_BT, "running dres with type %s and setting device on", type);
    dres_accessory_request(type, -1, 1);

    /* this might not be needed, since the BT status is reseted when HSP
     * goes to "playing" state */
    if (strcmp(type, BT_TYPE_HSP) == 0) {
        /* HSP device goes to connected state. We need to see that the
         * bluetooth override state is reseted. */

        /* This isn't very clear, but this function is not run when
         * BTHSP goes from "playing" to "connected", since there is a
         * separate function for that. Because of this we can safely set
         * the BT override to "default" state here. */
        run_policy_hook("bthsp_connect", 0, NULL);
    }

    return TRUE;
}
Beispiel #2
0
/* return TRUE if really disconnected, FALSE otherwise */
static gboolean disconnect_device(OhmFact *fact, const gchar *type)
{
    GValue *gval;
    
    OHM_DEBUG(DBG_BT, "Disconnecting fact %p profile %s", fact, type);

    if (!fact) {
        return FALSE;
    }

    gval = ohm_fact_get(fact, type);
    
    if (gval &&
            G_VALUE_TYPE(gval) == G_TYPE_STRING) {

        OHM_DEBUG(DBG_BT, "%s profile to be disconnected", type);
        dres_accessory_request(type, -1, 0);

        if (strcmp(type, BT_TYPE_HSP) == 0) {
            /* HSP device goes to disconnected state. We need to forget the
             * bluetooth override state. */
            run_policy_hook("bthsp_disconnect", 0, NULL);
        }
        return TRUE;
    }
    OHM_DEBUG(DBG_BT, "Could not get type information from the fact");

    return FALSE;
}
Beispiel #3
0
static DBusHandlerResult info(DBusConnection *c, DBusMessage * msg, void *data)
{
    int              driver    = -1;
    int              connected = -1;
    int             *valueptr  = &driver;
    int              value     = -1;
    DBusMessageIter  msgit;
    DBusMessageIter  devit;
    char            *string;
    char            *end;
    char            *device;
    gboolean         is_info;

    (void) c;
    (void) data;

    /* This is an example of what we should get:

       string "connected"
       string "1"
       array [
          string "fmtx"
       ]

    */

    is_info = dbus_message_is_signal(msg, "com.nokia.policy", "info");
    if (!is_info)
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;

    OHM_DEBUG(DBG_INFO, "received an info message");

    dbus_message_iter_init(msg, &msgit);

    for (;;) {
        if (dbus_message_iter_get_arg_type(&msgit) != DBUS_TYPE_STRING)
            goto done;

        dbus_message_iter_get_basic(&msgit, (void *)&string);

        if (!strcmp(string, "media"))
            goto not_our_signal;

        if (!strcmp(string, "driver")) {
            valueptr = &driver;

            if (!dbus_message_iter_next(&msgit))
                goto done;
        }
        else if (!strcmp(string, "connected")) {
            valueptr = &connected;

            if (!dbus_message_iter_next(&msgit))
                goto done;
        }
        else {
            value = strtol(string, &end, 10);

            if (*end == '\0' && (value == 0 || value == 1)) {
                *valueptr = value;
                break;
            }

            goto done;
        }
    }

    if (!dbus_message_iter_next(&msgit) ||
        dbus_message_iter_get_arg_type(&msgit) != DBUS_TYPE_ARRAY)
        goto done;

    dbus_message_iter_recurse(&msgit, &devit);

    do {
        if (dbus_message_iter_get_arg_type(&devit) != DBUS_TYPE_STRING)
            continue;

        dbus_message_iter_get_basic(&devit, (void *)&device);

        OHM_DEBUG(DBG_INFO, "device: '%s', driver: '%d', connected: '%d'",
                  device ? device : "NULL", driver, connected);
        if (!is_spurious_event(device, driver, connected))
            dres_accessory_request(device, driver, connected);

    } while (dbus_message_iter_next(&devit));

    dres_all();

 done:
 not_our_signal:
    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}