This email list is read-only.  Emails sent to this list will be discarded
----------------------------------
 include/dbus.h      |    3 ++
 include/element.h   |    1 +
 plugins/bluetooth.c |   63 +++++++++++++++++++++++++++++++++++---
 src/dbus.c          |   84 ++++++++++++++++++++++++++++-----------------------
 src/element.c       |    1 +
 5 files changed, 109 insertions(+), 43 deletions(-)

New commits:
commit c586908e887ba0f25efb682e0f835755d36077b8
Author: Marcel Holtmann <[email protected]>
Date:   Sat Dec 20 08:26:04 2008 +0100

    Add support for switching Bluetooth devices on and off

commit f45eb6d3bac2de0cd890183583656411f0366f16
Author: Marcel Holtmann <[email protected]>
Date:   Sat Dec 20 08:25:15 2008 +0100

    Add variable to hold a possible object path

commit 0548e30af62395997767f51ac5c0804f8d7545cc
Author: Marcel Holtmann <[email protected]>
Date:   Sat Dec 20 08:24:41 2008 +0100

    Add D-Bus helper for appending properties


Diff in this email is a maximum of 400 lines.
diff --git a/include/dbus.h b/include/dbus.h
index 9c8a893..97a58ba 100644
--- a/include/dbus.h
+++ b/include/dbus.h
@@ -41,6 +41,9 @@ extern "C" {
 #define CONNMAN_NETWORK_INTERFACE      CONNMAN_SERVICE ".Network"
 #define CONNMAN_CONNECTION_INTERFACE   CONNMAN_SERVICE ".Connection"
 
+extern void connman_dbus_property_append_variant(DBusMessageIter *property,
+                                       const char *key, int type, void *val);
+
 extern void connman_dbus_dict_append_array(DBusMessageIter *dict,
                                const char *key, int type, void *val, int len);
 extern void connman_dbus_dict_append_variant(DBusMessageIter *dict,
diff --git a/include/element.h b/include/element.h
index 327b8df..083533d 100644
--- a/include/element.h
+++ b/include/element.h
@@ -95,6 +95,7 @@ struct connman_element {
        gboolean remember;
        guint16 priority;
        guint8 strength;
+       gchar *devpath;
        gchar *devname;
 
        struct connman_element *parent;
diff --git a/plugins/bluetooth.c b/plugins/bluetooth.c
index 6988693..d7ae286 100644
--- a/plugins/bluetooth.c
+++ b/plugins/bluetooth.c
@@ -29,15 +29,19 @@
 
 #include <connman/plugin.h>
 #include <connman/driver.h>
+#include <connman/dbus.h>
 #include <connman/log.h>
 
 #define BLUEZ_SERVICE                  "org.bluez"
 #define BLUEZ_MANAGER_INTERFACE                BLUEZ_SERVICE ".Manager"
 #define BLUEZ_ADAPTER_INTERFACE                BLUEZ_SERVICE ".Adapter"
 
+#define LIST_ADAPTERS                  "ListAdapters"
 #define ADAPTER_ADDED                  "AdapterAdded"
 #define ADAPTER_REMOVED                        "AdapterRemoved"
+
 #define PROPERTY_CHANGED               "PropertyChanged"
+#define SET_PROPERTY                   "SetProperty"
 
 #define TIMEOUT 5000
 
@@ -53,18 +57,65 @@ static void bluetooth_remove(struct connman_element *device)
        DBG("device %p name %s", device, device->name);
 }
 
+static void powered_reply(DBusPendingCall *call, void *user_data)
+{
+       DBusMessage *reply;
+
+       DBG("");
+
+       reply = dbus_pending_call_steal_reply(call);
+
+       dbus_message_unref(reply);
+}
+
+static int change_powered(DBusConnection *connection, const char *path,
+                                                       dbus_bool_t powered)
+{
+       DBusMessage *message;
+       DBusMessageIter iter;
+       DBusPendingCall *call;
+
+       DBG("");
+
+       message = dbus_message_new_method_call(BLUEZ_SERVICE, path,
+                                       BLUEZ_ADAPTER_INTERFACE, SET_PROPERTY);
+       if (message == NULL)
+               return -ENOMEM;
+
+       dbus_message_iter_init_append(message, &iter);
+       connman_dbus_property_append_variant(&iter, "Powered",
+                                               DBUS_TYPE_BOOLEAN, &powered);
+
+       if (dbus_connection_send_with_reply(connection, message,
+                                               &call, TIMEOUT) == FALSE) {
+               connman_error("Failed to change Powered property");
+               dbus_message_unref(message);
+               return -EINVAL;
+       }
+
+       dbus_pending_call_set_notify(call, powered_reply, NULL, NULL);
+
+       dbus_message_unref(message);
+
+       return -EINPROGRESS;
+}
+
 static int bluetooth_enable(struct connman_element *device)
 {
+       DBusConnection *connection = connman_element_get_data(device);
+
        DBG("device %p name %s", device, device->name);
 
-       return -EINVAL;
+       return change_powered(connection, device->devpath, TRUE);
 }
 
 static int bluetooth_disable(struct connman_element *device)
 {
+       DBusConnection *connection = connman_element_get_data(device);
+
        DBG("device %p name %s", device, device->name);
 
-       return -EINVAL;
+       return change_powered(connection, device->devpath, FALSE);
 }
 
 static struct connman_driver bluetooth_driver = {
@@ -81,7 +132,6 @@ static GSList *device_list = NULL;
 
 static struct connman_element *find_adapter(const char *path)
 {
-       const char *devname = g_basename(path);
        GSList *list;
 
        DBG("path %s", path);
@@ -89,7 +139,7 @@ static struct connman_element *find_adapter(const char *path)
        for (list = device_list; list; list = list->next) {
                struct connman_element *device = list->data;
 
-               if (g_str_equal(device->devname, devname) == TRUE)
+               if (g_str_equal(device->devpath, path) == TRUE)
                        return device;
        }
 
@@ -242,6 +292,9 @@ static void add_adapter(DBusConnection *connection, const 
char *path)
        device->policy = CONNMAN_ELEMENT_POLICY_IGNORE;
 
        device->name = g_path_get_basename(path);
+       device->devpath = g_strdup(path);
+
+       connman_element_set_data(device, connection);
 
        if (connman_element_register(device, NULL) < 0) {
                connman_element_unref(device);
@@ -338,7 +391,7 @@ static void bluetooth_connect(DBusConnection *connection, 
void *user_data)
        DBG("connection %p", connection);
 
        message = dbus_message_new_method_call(BLUEZ_SERVICE, "/",
-                               BLUEZ_MANAGER_INTERFACE, "ListAdapters");
+                               BLUEZ_MANAGER_INTERFACE, LIST_ADAPTERS);
        if (message == NULL)
                return;
 
diff --git a/src/dbus.c b/src/dbus.c
index 918fb0e..333b4cf 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -25,6 +25,50 @@
 
 #include <connman/dbus.h>
 
+void connman_dbus_property_append_variant(DBusMessageIter *iter,
+                                       const char *key, int type, void *val)
+{
+       DBusMessageIter value;
+       const char *signature;
+
+       dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &key);
+
+       switch (type) {
+       case DBUS_TYPE_BOOLEAN:
+               signature = DBUS_TYPE_BOOLEAN_AS_STRING;
+               break;
+       case DBUS_TYPE_STRING:
+               signature = DBUS_TYPE_STRING_AS_STRING;
+               break;
+       case DBUS_TYPE_BYTE:
+               signature = DBUS_TYPE_BYTE_AS_STRING;
+               break;
+       case DBUS_TYPE_UINT16:
+               signature = DBUS_TYPE_UINT16_AS_STRING;
+               break;
+       case DBUS_TYPE_INT16:
+               signature = DBUS_TYPE_INT16_AS_STRING;
+               break;
+       case DBUS_TYPE_UINT32:
+               signature = DBUS_TYPE_UINT32_AS_STRING;
+               break;
+       case DBUS_TYPE_INT32:
+               signature = DBUS_TYPE_INT32_AS_STRING;
+               break;
+       case DBUS_TYPE_OBJECT_PATH:
+               signature = DBUS_TYPE_OBJECT_PATH_AS_STRING;
+               break;
+       default:
+               signature = DBUS_TYPE_VARIANT_AS_STRING;
+               break;
+       }
+
+       dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+                                                       signature, &value);
+       dbus_message_iter_append_basic(&value, type, val);
+       dbus_message_iter_close_container(iter, &value);
+}
+
 void connman_dbus_dict_append_array(DBusMessageIter *dict,
                                const char *key, int type, void *val, int len)
 {
@@ -61,48 +105,12 @@ void connman_dbus_dict_append_array(DBusMessageIter *dict,
 void connman_dbus_dict_append_variant(DBusMessageIter *dict,
                                        const char *key, int type, void *val)
 {
-       DBusMessageIter entry, value;
-       const char *signature;
+       DBusMessageIter entry;
 
        dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
                                                                NULL, &entry);
 
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       switch (type) {
-       case DBUS_TYPE_BOOLEAN:
-               signature = DBUS_TYPE_BOOLEAN_AS_STRING;
-               break;
-       case DBUS_TYPE_STRING:
-               signature = DBUS_TYPE_STRING_AS_STRING;
-               break;
-       case DBUS_TYPE_BYTE:
-               signature = DBUS_TYPE_BYTE_AS_STRING;
-               break;
-       case DBUS_TYPE_UINT16:
-               signature = DBUS_TYPE_UINT16_AS_STRING;
-               break;
-       case DBUS_TYPE_INT16:
-               signature = DBUS_TYPE_INT16_AS_STRING;
-               break;
-       case DBUS_TYPE_UINT32:
-               signature = DBUS_TYPE_UINT32_AS_STRING;
-               break;
-       case DBUS_TYPE_INT32:
-               signature = DBUS_TYPE_INT32_AS_STRING;
-               break;
-       case DBUS_TYPE_OBJECT_PATH:
-               signature = DBUS_TYPE_OBJECT_PATH_AS_STRING;
-               break;
-       default:
-               signature = DBUS_TYPE_VARIANT_AS_STRING;
-               break;
-       }
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                                                       signature, &value);
-       dbus_message_iter_append_basic(&value, type, val);
-       dbus_message_iter_close_container(&entry, &value);
+       connman_dbus_property_append_variant(&entry, key, type, val);
 
        dbus_message_iter_close_container(dict, &entry);
 }
diff --git a/src/element.c b/src/element.c
index 1145053..0352646 100644
--- a/src/element.c
+++ b/src/element.c
@@ -1195,6 +1195,7 @@ void connman_element_unref(struct connman_element 
*element)
                g_free(element->ipv4.broadcast);
                g_free(element->ipv4.nameserver);
                g_free(element->devname);
+               g_free(element->devpath);
                g_free(element->path);
                g_free(element->name);
                g_free(element);
_______________________________________________
Commits mailing list
[email protected]
https://lists.moblin.org/mailman/listinfo/commits

Reply via email to