From: Mikel Astiz <[email protected]>
Note that this patchset requires the gdbus fix affecting were the ObjectManager gets registered, as submitted by Luiz.
This v1 proposal completes v0 with the following changes:
- Test scripts are now updated (not all were tested though)
- Manager D-Bus object is moved to /org/bluez
- FindAdapter is not removed any more. Instead, it is extended to support the "default" pattern (patch v1 03/16) for convenience.
>From original cover-letter:
While thinking about how profile and their states should be exposed in D-Bus (see previous RFC), I found several potential improvements in the current version of the Manager and Adapter APIs.
Basically, this patchset removes some properties and methods that seem duplicated.
There are other similar methods/properties that could be simplified as well, but for practical reasons I started with the most obvious ones.
Mikel Astiz (16):
cups: Remove unnecessary code
doc: Add missing documentation in FindAdapter
manager: Extend FindAdapter with "default" pattern
test: Avoid using DefaultAdapter()
manager: Move org.bluez.Manager to org/bluez
test: Update to new Manager path
test: Update monitor script to ObjectManager
manager: Expose default adapter using property
test: Update test-manager script to ObjectManager
manager: Remove AdapterAdded/AdapterRemoved signals
manager: Remove redundant Adapters property
test: Use ObjectManager instead of Adapters property
adapter: Remove DeviceCreated/DeviceRemoved signals
adapter: Remove redundant Devices property
test: Use ObjectManager instead of Devices property
adapter: Remove FindDevice method from D-Bus API
doc/adapter-api.txt | 19 ---------
doc/manager-api.txt | 35 ++++------------
profiles/cups/main.c | 38 +++++++----------
src/adapter.c | 85 -------------------------------------
src/manager.c | 111 +++++++++++++------------------------------------
test/agent.c | 57 +------------------------
test/dbusdef.py | 5 ++-
test/gaptest.c | 8 +++-
test/list-devices | 14 +++----
test/monitor-bluetooth | 68 ++++++++++++++----------------
test/mpris-player.c | 55 +-----------------------
test/simple-agent | 4 +-
test/simple-endpoint | 4 +-
test/simple-player | 4 +-
test/simple-service | 4 +-
test/test-adapter | 5 ++-
test/test-attrib | 5 ++-
test/test-audio | 5 ++-
test/test-device | 5 ++-
test/test-discovery | 4 +-
test/test-health | 9 +++-
test/test-health-sink | 10 ++++-
test/test-heartrate | 4 +-
test/test-input | 5 ++-
test/test-manager | 37 +++++++++++------
test/test-nap | 4 +-
test/test-network | 4 +-
test/test-oob | 2 +-
test/test-proximity | 4 +-
test/test-service | 5 ++-
test/test-thermometer | 4 +-
31 files changed, 178 insertions(+), 445 deletions(-)
--
1.7.11.7
Hi Mikel,
On Thu, Nov 15, 2012 at 5:09 PM, Mikel Astiz <[email protected]> wrote:
> From: Mikel Astiz <[email protected]>
>
> Extend the supported values in the given pattern in order to return the
> default adapter if "default" is given.
> ---
> doc/manager-api.txt | 1 +
> src/manager.c | 4 +++-
> 2 files changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/doc/manager-api.txt b/doc/manager-api.txt
> index 8497141..b0d534d 100644
> --- a/doc/manager-api.txt
> +++ b/doc/manager-api.txt
> @@ -27,6 +27,7 @@ Object path /
> patterns are "hci0" or "00:11:22:33:44:55". Other
> supported values are:
> "any"
> + "default"
>
> Possible errors: org.bluez.Error.InvalidArguments
> org.bluez.Error.NoSuchAdapter
> diff --git a/src/manager.c b/src/manager.c
> index 3088dd9..79d049b 100644
> --- a/src/manager.c
> +++ b/src/manager.c
> @@ -110,7 +110,9 @@ static DBusMessage *find_adapter(DBusConnection *conn,
> } else if (!strncmp(pattern, "hci", 3) && strlen(pattern) >= 4) {
> dev_id = atoi(pattern + 3);
> adapter = manager_find_adapter_by_id(dev_id);
> - } else {
> + } else if (!strcmp(pattern, "default"))
> + adapter = manager_find_adapter_by_id(default_adapter_id);
> + else {
> bdaddr_t bdaddr;
> str2ba(pattern, &bdaddr);
> adapter = manager_find_adapter(&bdaddr);
> --
> 1.7.11.7
Hmm, I though we would have a property e.g. DefaultAdapter because
with ObjectManager you also get the properties so once you do
GetManagedObjects you discover what is the default one. It could also
be a property of the Adapter interface e.g. boolean Default but if it
changes we actually have to emit 2 signals so it would no be an atomic
operation as it should be.
--
Luiz Augusto von Dentz
From: Mikel Astiz <[email protected]>
ObjectManager.GetManagedObjects() returns all devices and their
corresponding properties to any interested client. The device address is
included in the property dictionary and therefore having such a
FindDevice method is an unnecessary duplication.
---
doc/adapter-api.txt | 7 -------
src/adapter.c | 38 --------------------------------------
2 files changed, 45 deletions(-)
diff --git a/doc/adapter-api.txt b/doc/adapter-api.txt
index 3582793..983a20d 100644
--- a/doc/adapter-api.txt
+++ b/doc/adapter-api.txt
@@ -64,13 +64,6 @@ Methods void RequestSession()
org.bluez.Error.Failed
org.bluez.Error.NotAuthorized
- object FindDevice(string address)
-
- Returns the object path of device for given address.
-
- Possible Errors: org.bluez.Error.DoesNotExist
- org.bluez.Error.InvalidArguments
-
void RemoveDevice(object device)
This removes the remote device object at the given
diff --git a/src/adapter.c b/src/adapter.c
index eb82102..71b5232 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1518,40 +1518,6 @@ static DBusMessage *remove_device(DBusConnection *conn, DBusMessage *msg,
return NULL;
}
-static DBusMessage *find_device(DBusConnection *conn, DBusMessage *msg,
- void *data)
-{
- struct btd_adapter *adapter = data;
- struct btd_device *device;
- DBusMessage *reply;
- const gchar *address;
- GSList *l;
- const gchar *dev_path;
-
- if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID))
- return btd_error_invalid_args(msg);
-
- l = g_slist_find_custom(adapter->devices,
- address, (GCompareFunc) device_address_cmp);
- if (!l)
- return btd_error_does_not_exist(msg);
-
- device = l->data;
-
- reply = dbus_message_new_method_return(msg);
- if (!reply)
- return NULL;
-
- dev_path = device_get_path(device);
-
- dbus_message_append_args(reply,
- DBUS_TYPE_OBJECT_PATH, &dev_path,
- DBUS_TYPE_INVALID);
-
- return reply;
-}
-
static void agent_removed(struct agent *agent, struct btd_adapter *adapter)
{
mgmt_set_io_capability(adapter->dev_id, IO_CAPABILITY_NOINPUTNOOUTPUT);
@@ -1623,10 +1589,6 @@ static const GDBusMethodTable adapter_methods[] = {
{ GDBUS_ASYNC_METHOD("RemoveDevice",
GDBUS_ARGS({ "device", "o" }), NULL,
remove_device) },
- { GDBUS_METHOD("FindDevice",
- GDBUS_ARGS({ "address", "s" }),
- GDBUS_ARGS({ "device", "o" }),
- find_device) },
{ GDBUS_METHOD("RegisterAgent",
GDBUS_ARGS({ "agent", "o" },
{ "capability", "s" }), NULL,
--
1.7.11.7
From: Mikel Astiz <[email protected]>
Use the objects and interfaces reported by the ObjectManager in order
to list the available devices per adapter.
---
test/list-devices | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/test/list-devices b/test/list-devices
index fcff3e7..e8f3f24 100755
--- a/test/list-devices
+++ b/test/list-devices
@@ -30,6 +30,10 @@ def extract_uuids(uuid_list):
return list
objects = manager.GetManagedObjects()
+
+all_devices = (str(path) for path, interfaces in objects.iteritems() if
+ "org.bluez.Device" in interfaces.keys())
+
for path, interfaces in objects.iteritems():
if "org.bluez.Adapter" not in interfaces.keys():
continue
@@ -39,19 +43,13 @@ for path, interfaces in objects.iteritems():
properties = interfaces["org.bluez.Adapter"]
for key in properties.keys():
value = properties[key]
- if (key == "Devices"):
- list = extract_objects(value)
- print(" %s = %s" % (key, list))
- elif (key == "UUIDs"):
+ if (key == "UUIDs"):
list = extract_uuids(value)
print(" %s = %s" % (key, list))
else:
print(" %s = %s" % (key, value))
- try:
- device_list = properties["Devices"]
- except:
- device_list = []
+ device_list = [d for d in all_devices if d.startswith(path + "/")]
for dev_path in device_list:
print(" [ " + dev_path + " ]")
--
1.7.11.7
From: Mikel Astiz <[email protected]>
The Adapter interface already reports changes in the device list in form
of property changes, so there is no need to keep these two signals.
---
doc/adapter-api.txt | 8 --------
src/adapter.c | 17 -----------------
2 files changed, 25 deletions(-)
diff --git a/doc/adapter-api.txt b/doc/adapter-api.txt
index b638586..132e60f 100644
--- a/doc/adapter-api.txt
+++ b/doc/adapter-api.txt
@@ -116,14 +116,6 @@ Signals DevicesFound(array{object path, dict values})
The dictionary contains the properties from the
org.bluez.Device interface.
- DeviceCreated(object device)
-
- Parameter is object path of created device.
-
- DeviceRemoved(object device)
-
- Parameter is object path of removed device.
-
Properties string Address [readonly]
The Bluetooth device address.
diff --git a/src/adapter.c b/src/adapter.c
index ea2d2ad..aa93785 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1007,7 +1007,6 @@ static struct btd_device *adapter_create_device(struct btd_adapter *adapter,
uint8_t bdaddr_type)
{
struct btd_device *device;
- const char *path;
DBG("%s", address);
@@ -1019,12 +1018,6 @@ static struct btd_device *adapter_create_device(struct btd_adapter *adapter,
adapter->devices = g_slist_append(adapter->devices, device);
- path = device_get_path(device);
- g_dbus_emit_signal(btd_get_dbus_connection(), adapter->path,
- ADAPTER_INTERFACE, "DeviceCreated",
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID);
-
g_dbus_emit_property_changed(btd_get_dbus_connection(),
adapter->path, ADAPTER_INTERFACE, "Devices");
@@ -1052,7 +1045,6 @@ void adapter_remove_device(struct btd_adapter *adapter,
struct btd_device *dev,
gboolean remove_storage)
{
- const gchar *dev_path = device_get_path(dev);
struct discovery *discovery = adapter->discovery;
GList *l;
@@ -1084,11 +1076,6 @@ void adapter_remove_device(struct btd_adapter *adapter,
g_dbus_emit_property_changed(btd_get_dbus_connection(),
adapter->path, ADAPTER_INTERFACE, "Devices");
- g_dbus_emit_signal(btd_get_dbus_connection(), adapter->path,
- ADAPTER_INTERFACE, "DeviceRemoved",
- DBUS_TYPE_OBJECT_PATH, &dev_path,
- DBUS_TYPE_INVALID);
-
device_remove(dev, remove_storage);
}
@@ -1680,10 +1667,6 @@ static const GDBusMethodTable adapter_methods[] = {
};
static const GDBusSignalTable adapter_signals[] = {
- { GDBUS_SIGNAL("DeviceCreated",
- GDBUS_ARGS({ "device", "o" })) },
- { GDBUS_SIGNAL("DeviceRemoved",
- GDBUS_ARGS({ "device", "o" })) },
{ GDBUS_SIGNAL("DevicesFound",
GDBUS_ARGS({ "devices", "a{oa{sv}}" })) },
{ }
--
1.7.11.7
From: Mikel Astiz <[email protected]>
The ObjectManager interface already reports the list of devices, so the
the property can be entirely removed.
---
doc/adapter-api.txt | 4 ----
src/adapter.c | 30 ------------------------------
2 files changed, 34 deletions(-)
diff --git a/doc/adapter-api.txt b/doc/adapter-api.txt
index 132e60f..3582793 100644
--- a/doc/adapter-api.txt
+++ b/doc/adapter-api.txt
@@ -180,10 +180,6 @@ Properties string Address [readonly]
Indicates that a device discovery procedure is active.
- array{object} Devices [readonly]
-
- List of device object paths.
-
array{string} UUIDs [readonly]
List of 128-bit UUIDs that represents the available
diff --git a/src/adapter.c b/src/adapter.c
index aa93785..eb82102 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1018,9 +1018,6 @@ static struct btd_device *adapter_create_device(struct btd_adapter *adapter,
adapter->devices = g_slist_append(adapter->devices, device);
- g_dbus_emit_property_changed(btd_get_dbus_connection(),
- adapter->path, ADAPTER_INTERFACE, "Devices");
-
return device;
}
@@ -1073,9 +1070,6 @@ void adapter_remove_device(struct btd_adapter *adapter,
service_auth_cancel(auth);
}
- g_dbus_emit_property_changed(btd_get_dbus_connection(),
- adapter->path, ADAPTER_INTERFACE, "Devices");
-
device_remove(dev, remove_storage);
}
@@ -1381,29 +1375,6 @@ static gboolean adapter_property_get_discovering(
return TRUE;
}
-static gboolean adapter_property_get_devices(
- const GDBusPropertyTable *property,
- DBusMessageIter *iter, void *data)
-{
- struct btd_adapter *adapter = data;
- DBusMessageIter entry;
- GSList *l;
-
- dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
- DBUS_TYPE_OBJECT_PATH_AS_STRING, &entry);
-
- for (l = adapter->devices; l != NULL; l = l->next) {
- const char *path = device_get_path(l->data);
-
- dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
- &path);
- }
-
- dbus_message_iter_close_container(iter, &entry);
-
- return TRUE;
-}
-
static gboolean adapter_property_get_uuids(const GDBusPropertyTable *property,
DBusMessageIter *iter, void *data)
{
@@ -1688,7 +1659,6 @@ static const GDBusPropertyTable adapter_properties[] = {
{ "PairableTimeout", "u", adapter_property_get_pairable_timeout,
adapter_property_set_pairable_timeout },
{ "Discovering", "b", adapter_property_get_discovering },
- { "Devices", "ao", adapter_property_get_devices },
{ "UUIDs", "as", adapter_property_get_uuids },
{ }
};
--
1.7.11.7
From: Mikel Astiz <[email protected]>
Use the objects and interfaces reported by the ObjectManager in order
to list the available adapters.
---
test/test-health | 11 ++++++++---
test/test-health-sink | 12 +++++++++---
2 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/test/test-health b/test/test-health
index 21d1776..9d2f62f 100755
--- a/test/test-health
+++ b/test/test-health
@@ -131,10 +131,15 @@ if not con:
enter_mainloop()
sys.exit()
-manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
- "org.bluez.Manager")
+manager = dbus.Interface(bus.get_object("org.bluez", "/"),
+ "org.freedesktop.DBus.ObjectManager")
-adapters = manager.GetProperties()["Adapters"]
+objects = manager.GetManagedObjects()
+adapters = []
+
+for path, ifaces in objects.iteritems():
+ if ifaces.has_key("org.bluez.Adapter"):
+ adapters.append(path)
i = 1
for ad in adapters:
diff --git a/test/test-health-sink b/test/test-health-sink
index 7bf1af4..a886d85 100755
--- a/test/test-health-sink
+++ b/test/test-health-sink
@@ -21,10 +21,16 @@ app_path = hdp_manager.CreateApplication({"DataType": dbus.types.UInt16(4103),
print(app_path)
-manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
- "org.bluez.Manager")
+manager = dbus.Interface(bus.get_object("org.bluez", "/"),
+ "org.freedesktop.DBus.ObjectManager")
+
+objects = manager.GetManagedObjects()
+adapters = []
+
+for path, ifaces in objects.iteritems():
+ if ifaces.has_key("org.bluez.Adapter"):
+ adapters.append(path)
-adapters = manager.GetProperties()["Adapters"]
i = 1
for ad in adapters:
print("%d. %s" % (i, ad))
--
1.7.11.7
From: Mikel Astiz <[email protected]>
The ObjectManager interface already reports the available adapters, so
the property can be entirely removed.
---
doc/manager-api.txt | 6 +-----
src/manager.c | 30 ------------------------------
2 files changed, 1 insertion(+), 35 deletions(-)
diff --git a/doc/manager-api.txt b/doc/manager-api.txt
index 693a981..a8f570b 100644
--- a/doc/manager-api.txt
+++ b/doc/manager-api.txt
@@ -25,10 +25,6 @@ Object path /org/bluez
Possible errors: org.bluez.Error.InvalidArguments
org.bluez.Error.NoSuchAdapter
-Properties array{object} Adapters [readonly]
-
- List of adapter object paths.
-
- object DefaultAdapter [readonly, optional]
+Properties object DefaultAdapter [readonly, optional]
Object path for the default adapter, if any.
diff --git a/src/manager.c b/src/manager.c
index 954ab8a..d861031 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -111,29 +111,6 @@ done:
return reply;
}
-static gboolean manager_property_get_adapters(
- const GDBusPropertyTable *property,
- DBusMessageIter *iter, void *data)
-{
- DBusMessageIter entry;
- GSList *l;
-
- dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
- DBUS_TYPE_OBJECT_PATH_AS_STRING, &entry);
-
- for (l = adapters; l != NULL; l = l->next) {
- struct btd_adapter *adapter = l->data;
- const char *path = adapter_get_path(adapter);
-
- dbus_message_iter_append_basic(&entry, DBUS_TYPE_OBJECT_PATH,
- &path);
- }
-
- dbus_message_iter_close_container(iter, &entry);
-
- return TRUE;
-}
-
static gboolean manager_property_get_default_adapter(
const GDBusPropertyTable *property,
DBusMessageIter *iter, void *data)
@@ -168,7 +145,6 @@ static const GDBusMethodTable manager_methods[] = {
};
static const GDBusPropertyTable manager_properties[] = {
- { "Adapters", "ao", manager_property_get_adapters },
{ "DefaultAdapter", "o", manager_property_get_default_adapter, NULL,
manager_property_exists_default_adapter },
{ }
@@ -209,9 +185,6 @@ static void manager_remove_adapter(struct btd_adapter *adapter)
adapters = g_slist_remove(adapters, adapter);
- g_dbus_emit_property_changed(btd_get_dbus_connection(), base_path,
- MANAGER_INTERFACE, "Adapters");
-
if (default_adapter_id == dev_id || default_adapter_id < 0) {
int new_default = hci_get_route(NULL);
@@ -318,9 +291,6 @@ struct btd_adapter *btd_manager_register_adapter(int id, gboolean up)
path = adapter_get_path(adapter);
- g_dbus_emit_property_changed(btd_get_dbus_connection(), base_path,
- MANAGER_INTERFACE, "Adapters");
-
btd_stop_exit_timer();
if (default_adapter_id < 0)
--
1.7.11.7
From: Mikel Astiz <[email protected]>
The Manager interface already reports changes in the adapter list in
form of property changes, so there is no need to keep these two signals
any more.
---
doc/manager-api.txt | 8 --------
src/manager.c | 20 +-------------------
2 files changed, 1 insertion(+), 27 deletions(-)
diff --git a/doc/manager-api.txt b/doc/manager-api.txt
index b89ab68..693a981 100644
--- a/doc/manager-api.txt
+++ b/doc/manager-api.txt
@@ -25,14 +25,6 @@ Object path /org/bluez
Possible errors: org.bluez.Error.InvalidArguments
org.bluez.Error.NoSuchAdapter
-Signals AdapterAdded(object adapter)
-
- Parameter is object path of added adapter.
-
- AdapterRemoved(object adapter)
-
- Parameter is object path of removed adapter.
-
Properties array{object} Adapters [readonly]
List of adapter object paths.
diff --git a/src/manager.c b/src/manager.c
index 08d6625..954ab8a 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -167,14 +167,6 @@ static const GDBusMethodTable manager_methods[] = {
{ }
};
-static const GDBusSignalTable manager_signals[] = {
- { GDBUS_SIGNAL("AdapterAdded",
- GDBUS_ARGS({ "adapter", "o" })) },
- { GDBUS_SIGNAL("AdapterRemoved",
- GDBUS_ARGS({ "adapter", "o" })) },
- { }
-};
-
static const GDBusPropertyTable manager_properties[] = {
{ "Adapters", "ao", manager_property_get_adapters },
{ "DefaultAdapter", "o", manager_property_get_default_adapter, NULL,
@@ -186,7 +178,7 @@ bool manager_init(const char *path)
{
if (!g_dbus_register_interface(btd_get_dbus_connection(),
base_path, MANAGER_INTERFACE,
- manager_methods, manager_signals,
+ manager_methods, NULL,
manager_properties, NULL, NULL))
return false;
@@ -214,7 +206,6 @@ struct btd_adapter *manager_get_default_adapter(void)
static void manager_remove_adapter(struct btd_adapter *adapter)
{
uint16_t dev_id = adapter_get_dev_id(adapter);
- const gchar *path = adapter_get_path(adapter);
adapters = g_slist_remove(adapters, adapter);
@@ -227,11 +218,6 @@ static void manager_remove_adapter(struct btd_adapter *adapter)
manager_set_default_adapter(new_default);
}
- g_dbus_emit_signal(btd_get_dbus_connection(), base_path,
- MANAGER_INTERFACE, "AdapterRemoved",
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID);
-
adapter_remove(adapter);
btd_adapter_unref(adapter);
@@ -331,10 +317,6 @@ struct btd_adapter *btd_manager_register_adapter(int id, gboolean up)
}
path = adapter_get_path(adapter);
- g_dbus_emit_signal(btd_get_dbus_connection(), base_path,
- MANAGER_INTERFACE, "AdapterAdded",
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID);
g_dbus_emit_property_changed(btd_get_dbus_connection(), base_path,
MANAGER_INTERFACE, "Adapters");
--
1.7.11.7
From: Mikel Astiz <[email protected]>
Make the script compatible with the new API provided by the
ObjectManager and Properties interfaces.
---
test/test-manager | 33 +++++++++++++++++++++++----------
1 file changed, 23 insertions(+), 10 deletions(-)
diff --git a/test/test-manager b/test/test-manager
index 2a9c1e9..e35db83 100755
--- a/test/test-manager
+++ b/test/test-manager
@@ -7,14 +7,20 @@ from gi.repository import GObject
import dbus
import dbus.mainloop.glib
-def adapter_added(path):
- print("Adapter with path %s added" % (path))
+def property_changed(interface, changed, invalidated, path):
+ if interface != "org.bluez.Manager":
+ return
+ path = changed.get("DefaultAdapter")
+ if path != None:
+ print("Default adapter is now at path %s" % (path))
-def adapter_removed(path):
- print("Adapter with path %s removed" % (path))
+def interfaces_added(path, interfaces):
+ if interfaces.get("org.bluez.Adapter") != None:
+ print("Adapter with path %s added" % (path))
-def default_changed(path):
- print("Default adapter is now at path %s" % (path))
+def interfaces_removed(path, interfaces):
+ if "org.bluez.Adapter" in interfaces:
+ print("Adapter with path %s removed" % (path))
if __name__ == "__main__":
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
@@ -24,15 +30,22 @@ if __name__ == "__main__":
manager = dbus.Interface(bus.get_object('org.bluez', '/org/bluez'),
'org.bluez.Manager')
- manager.connect_to_signal("AdapterAdded", adapter_added)
+ bus.add_signal_receiver(property_changed, bus_name="org.bluez",
+ dbus_interface="org.freedesktop.DBus.Properties",
+ signal_name="PropertiesChanged",
+ path_keyword="path")
- manager.connect_to_signal("AdapterRemoved", adapter_removed)
+ bus.add_signal_receiver(interfaces_added, bus_name="org.bluez",
+ dbus_interface="org.freedesktop.DBus.ObjectManager",
+ signal_name="InterfacesAdded")
- manager.connect_to_signal("DefaultAdapterChanged", default_changed)
+ bus.add_signal_receiver(interfaces_removed, bus_name="org.bluez",
+ dbus_interface="org.freedesktop.DBus.ObjectManager",
+ signal_name="InterfacesRemoved")
try:
path = manager.FindAdapter("default")
- default_changed(path)
+ print("Default adapter is now at path %s" % (path))
except:
pass
--
1.7.11.7
From: Mikel Astiz <[email protected]>
Replace previous method in the Manager interface with a property. If no
default adapter exists, the property will not be present.
---
doc/manager-api.txt | 20 +++------------
src/manager.c | 71 +++++++++++++++++++++++------------------------------
2 files changed, 35 insertions(+), 56 deletions(-)
diff --git a/doc/manager-api.txt b/doc/manager-api.txt
index cf3284a..b89ab68 100644
--- a/doc/manager-api.txt
+++ b/doc/manager-api.txt
@@ -14,13 +14,6 @@ Service org.bluez
Interface org.bluez.Manager
Object path /org/bluez
- object DefaultAdapter()
-
- Returns object path for the default adapter.
-
- Possible errors: org.bluez.Error.InvalidArguments
- org.bluez.Error.NoSuchAdapter
-
object FindAdapter(string pattern)
Returns object path for the specified adapter. Valid
@@ -40,15 +33,10 @@ Signals AdapterAdded(object adapter)
Parameter is object path of removed adapter.
- DefaultAdapterChanged(object adapter)
-
- Parameter is object path of the new default adapter.
-
- In case all adapters are removed this signal will not
- be emitted. The AdapterRemoved signal has to be used
- to detect that no default adapter is selected or
- available anymore.
-
Properties array{object} Adapters [readonly]
List of adapter object paths.
+
+ object DefaultAdapter [readonly, optional]
+
+ Object path for the default adapter, if any.
diff --git a/src/manager.c b/src/manager.c
index d6e7b80..08d6625 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -64,29 +64,6 @@ const char *manager_get_base_path(void)
return base_path;
}
-static DBusMessage *default_adapter(DBusConnection *conn,
- DBusMessage *msg, void *data)
-{
- DBusMessage *reply;
- struct btd_adapter *adapter;
- const gchar *path;
-
- adapter = manager_find_adapter_by_id(default_adapter_id);
- if (!adapter)
- return btd_error_no_such_adapter(msg);
-
- reply = dbus_message_new_method_return(msg);
- if (!reply)
- return NULL;
-
- path = adapter_get_path(adapter);
-
- dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID);
-
- return reply;
-}
-
static DBusMessage *find_adapter(DBusConnection *conn,
DBusMessage *msg, void *data)
{
@@ -157,10 +134,32 @@ static gboolean manager_property_get_adapters(
return TRUE;
}
+static gboolean manager_property_get_default_adapter(
+ const GDBusPropertyTable *property,
+ DBusMessageIter *iter, void *data)
+{
+ struct btd_adapter *adapter;
+ const char *path;
+
+ adapter = manager_find_adapter_by_id(default_adapter_id);
+ path = adapter_get_path(adapter);
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
+
+ return TRUE;
+}
+
+static gboolean manager_property_exists_default_adapter(
+ const GDBusPropertyTable *property,
+ void *data)
+{
+ if (manager_find_adapter_by_id(default_adapter_id) == NULL)
+ return FALSE;
+ else
+ return TRUE;
+}
+
static const GDBusMethodTable manager_methods[] = {
- { GDBUS_METHOD("DefaultAdapter",
- NULL, GDBUS_ARGS({ "adapter", "o" }),
- default_adapter) },
{ GDBUS_METHOD("FindAdapter",
GDBUS_ARGS({ "pattern", "s" }),
GDBUS_ARGS({ "adapter", "o" }),
@@ -173,13 +172,13 @@ static const GDBusSignalTable manager_signals[] = {
GDBUS_ARGS({ "adapter", "o" })) },
{ GDBUS_SIGNAL("AdapterRemoved",
GDBUS_ARGS({ "adapter", "o" })) },
- { GDBUS_SIGNAL("DefaultAdapterChanged",
- GDBUS_ARGS({ "adapter", "o" })) },
{ }
};
static const GDBusPropertyTable manager_properties[] = {
{ "Adapters", "ao", manager_property_get_adapters },
+ { "DefaultAdapter", "o", manager_property_get_default_adapter, NULL,
+ manager_property_exists_default_adapter },
{ }
};
@@ -198,21 +197,13 @@ bool manager_init(const char *path)
static void manager_set_default_adapter(int id)
{
- struct btd_adapter *adapter;
- const gchar *path;
-
- default_adapter_id = id;
-
- adapter = manager_find_adapter_by_id(id);
- if (!adapter)
+ if (id == default_adapter_id)
return;
- path = adapter_get_path(adapter);
+ default_adapter_id = id;
- g_dbus_emit_signal(btd_get_dbus_connection(), base_path,
- MANAGER_INTERFACE, "DefaultAdapterChanged",
- DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID);
+ g_dbus_emit_property_changed(btd_get_dbus_connection(), base_path,
+ MANAGER_INTERFACE, "DefaultAdapter");
}
struct btd_adapter *manager_get_default_adapter(void)
--
1.7.11.7
From: Mikel Astiz <[email protected]>
Make use of the new object path being used for org.bluez.Manager.
---
profiles/cups/main.c | 4 ++--
test/agent.c | 2 +-
test/dbusdef.py | 3 ++-
test/gaptest.c | 2 +-
test/mpris-player.c | 2 +-
test/simple-agent | 2 +-
test/simple-endpoint | 2 +-
test/simple-player | 2 +-
test/simple-service | 2 +-
test/test-adapter | 3 ++-
test/test-attrib | 3 ++-
test/test-audio | 3 ++-
test/test-device | 3 ++-
test/test-discovery | 2 +-
test/test-health | 2 +-
test/test-health-sink | 2 +-
test/test-heartrate | 2 +-
test/test-input | 3 ++-
test/test-manager | 2 +-
test/test-nap | 2 +-
test/test-network | 2 +-
test/test-oob | 2 +-
test/test-proximity | 2 +-
test/test-service | 3 ++-
test/test-thermometer | 2 +-
25 files changed, 33 insertions(+), 26 deletions(-)
diff --git a/profiles/cups/main.c b/profiles/cups/main.c
index b8bcbd3..ab1d2b9 100644
--- a/profiles/cups/main.c
+++ b/profiles/cups/main.c
@@ -543,7 +543,7 @@ static gboolean list_printers(void)
return TRUE;
/* Get the default adapter */
- message = dbus_message_new_method_call("org.bluez", "/",
+ message = dbus_message_new_method_call("org.bluez", "/org/bluez",
"org.bluez.Manager",
"FindAdapter");
if (message == NULL) {
@@ -634,7 +634,7 @@ static gboolean print_ieee1284(const char *bdaddr)
if (conn == NULL)
return FALSE;
- message = dbus_message_new_method_call("org.bluez", "/",
+ message = dbus_message_new_method_call("org.bluez", "/org/bluez",
"org.bluez.Manager",
"FindAdapter");
diff --git a/test/agent.c b/test/agent.c
index 6ad3bc7..5edd9ce 100644
--- a/test/agent.c
+++ b/test/agent.c
@@ -474,7 +474,7 @@ static char *get_adapter_path(DBusConnection *conn, const char *adapter)
if (!adapter)
adapter = "default";
- msg = dbus_message_new_method_call("org.bluez", "/",
+ msg = dbus_message_new_method_call("org.bluez", "/org/bluez",
"org.bluez.Manager", "FindAdapter");
if (!msg) {
diff --git a/test/dbusdef.py b/test/dbusdef.py
index 1d55f97..f9b955f 100644
--- a/test/dbusdef.py
+++ b/test/dbusdef.py
@@ -8,7 +8,8 @@ dummy = dbus.Interface(bus.get_object('org.bluez', '/'), 'org.freedesktop.DBus.I
#print dummy.Introspect()
-manager = dbus.Interface(bus.get_object('org.bluez', '/'), 'org.bluez.Manager')
+manager = dbus.Interface(bus.get_object('org.bluez', '/org/bluez'),
+ 'org.bluez.Manager')
try:
adapter = dbus.Interface(bus.get_object('org.bluez', manager.FindAdapter("default")), 'org.bluez.Adapter')
diff --git a/test/gaptest.c b/test/gaptest.c
index bcc3959..6ff6c78 100644
--- a/test/gaptest.c
+++ b/test/gaptest.c
@@ -35,7 +35,7 @@
#define BLUEZ_SERVICE "org.bluez"
-#define MANAGER_PATH "/"
+#define MANAGER_PATH "/org/bluez"
#define MANAGER_INTF BLUEZ_SERVICE ".Manager"
#define ADAPTER_INTF BLUEZ_SERVICE ".Adapter"
diff --git a/test/mpris-player.c b/test/mpris-player.c
index 641db6e..b354187 100644
--- a/test/mpris-player.c
+++ b/test/mpris-player.c
@@ -672,7 +672,7 @@ static char *get_adapter(DBusConnection *conn, const char *adapter)
if (!adapter)
adapter = NULL;
- msg = dbus_message_new_method_call("org.bluez", "/",
+ msg = dbus_message_new_method_call("org.bluez", "/org/bluez",
"org.bluez.Manager", "FindAdapter");
if (!msg) {
diff --git a/test/simple-agent b/test/simple-agent
index cad7dc7..09742f4 100755
--- a/test/simple-agent
+++ b/test/simple-agent
@@ -109,7 +109,7 @@ if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
- manager = dbus.Interface(bus.get_object("org.bluez", "/"),
+ manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
"org.bluez.Manager")
capability = "KeyboardDisplay"
diff --git a/test/simple-endpoint b/test/simple-endpoint
index 013ed8c..20ad0b3 100755
--- a/test/simple-endpoint
+++ b/test/simple-endpoint
@@ -79,7 +79,7 @@ if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
- manager = dbus.Interface(bus.get_object("org.bluez", "/"),
+ manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
"org.bluez.Manager")
if len(sys.argv) > 1:
diff --git a/test/simple-player b/test/simple-player
index 5e10e95..b4750f3 100755
--- a/test/simple-player
+++ b/test/simple-player
@@ -137,7 +137,7 @@ if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
- manager = dbus.Interface(bus.get_object("org.bluez", "/"),
+ manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
"org.bluez.Manager")
if len(sys.argv) > 1:
diff --git a/test/simple-service b/test/simple-service
index 9b65e80..4e62283 100755
--- a/test/simple-service
+++ b/test/simple-service
@@ -103,7 +103,7 @@ xml = ' \
'
bus = dbus.SystemBus()
-manager = dbus.Interface(bus.get_object("org.bluez", "/"),
+manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
"org.bluez.Manager")
if len(sys.argv) > 1:
diff --git a/test/test-adapter b/test/test-adapter
index 8d44dd8..4449277 100755
--- a/test/test-adapter
+++ b/test/test-adapter
@@ -9,7 +9,8 @@ from optparse import OptionParser, make_option
bus = dbus.SystemBus()
-manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
+manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
+ "org.bluez.Manager")
option_list = [
make_option("-i", "--device", action="store",
diff --git a/test/test-attrib b/test/test-attrib
index 5263c84..f2ebd0b 100755
--- a/test/test-attrib
+++ b/test/test-attrib
@@ -18,7 +18,8 @@ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
mainloop = gobject.MainLoop()
-manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
+manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
+ "org.bluez.Manager")
option_list = [
make_option("-i", "--device", action="store",
diff --git a/test/test-audio b/test/test-audio
index 77cc22e..b4e024b 100755
--- a/test/test-audio
+++ b/test/test-audio
@@ -8,7 +8,8 @@ from optparse import OptionParser, make_option
bus = dbus.SystemBus()
-manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
+manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
+ "org.bluez.Manager")
option_list = [
make_option("-i", "--device", action="store",
diff --git a/test/test-device b/test/test-device
index 8db1fac..50bad05 100755
--- a/test/test-device
+++ b/test/test-device
@@ -14,7 +14,8 @@ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
mainloop = GObject.MainLoop()
-manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
+manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
+ "org.bluez.Manager")
option_list = [
make_option("-i", "--device", action="store",
diff --git a/test/test-discovery b/test/test-discovery
index f262021..a7c9fcc 100755
--- a/test/test-discovery
+++ b/test/test-discovery
@@ -88,7 +88,7 @@ if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
- manager = dbus.Interface(bus.get_object("org.bluez", "/"),
+ manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
"org.bluez.Manager")
option_list = [
diff --git a/test/test-health b/test/test-health
index a7df679..21d1776 100755
--- a/test/test-health
+++ b/test/test-health
@@ -131,7 +131,7 @@ if not con:
enter_mainloop()
sys.exit()
-manager = dbus.Interface(bus.get_object("org.bluez", "/"),
+manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
"org.bluez.Manager")
adapters = manager.GetProperties()["Adapters"]
diff --git a/test/test-health-sink b/test/test-health-sink
index 333b2fb..7bf1af4 100755
--- a/test/test-health-sink
+++ b/test/test-health-sink
@@ -21,7 +21,7 @@ app_path = hdp_manager.CreateApplication({"DataType": dbus.types.UInt16(4103),
print(app_path)
-manager = dbus.Interface(bus.get_object("org.bluez", "/"),
+manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
"org.bluez.Manager")
adapters = manager.GetProperties()["Adapters"]
diff --git a/test/test-heartrate b/test/test-heartrate
index aee6a46..c9b0218 100755
--- a/test/test-heartrate
+++ b/test/test-heartrate
@@ -36,7 +36,7 @@ if __name__ == "__main__":
bus = dbus.SystemBus()
- manager = dbus.Interface(bus.get_object("org.bluez", "/"),
+ manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
"org.bluez.Manager")
option_list = [
diff --git a/test/test-input b/test/test-input
index 783a19f..45a07a8 100755
--- a/test/test-input
+++ b/test/test-input
@@ -8,7 +8,8 @@ from optparse import OptionParser, make_option
bus = dbus.SystemBus()
-manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
+manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
+ "org.bluez.Manager")
option_list = [
make_option("-i", "--device", action="store",
diff --git a/test/test-manager b/test/test-manager
index 30ca155..2a9c1e9 100755
--- a/test/test-manager
+++ b/test/test-manager
@@ -21,7 +21,7 @@ if __name__ == "__main__":
bus = dbus.SystemBus()
- manager = dbus.Interface(bus.get_object('org.bluez', '/'),
+ manager = dbus.Interface(bus.get_object('org.bluez', '/org/bluez'),
'org.bluez.Manager')
manager.connect_to_signal("AdapterAdded", adapter_added)
diff --git a/test/test-nap b/test/test-nap
index b97b165..0b1857c 100755
--- a/test/test-nap
+++ b/test/test-nap
@@ -9,7 +9,7 @@ from optparse import OptionParser, make_option
bus = dbus.SystemBus()
-manager = dbus.Interface(bus.get_object("org.bluez", "/"),
+manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
"org.bluez.Manager")
option_list = [
diff --git a/test/test-network b/test/test-network
index b920901..dd3e11b 100755
--- a/test/test-network
+++ b/test/test-network
@@ -9,7 +9,7 @@ from optparse import OptionParser, make_option
bus = dbus.SystemBus()
-manager = dbus.Interface(bus.get_object("org.bluez", "/"),
+manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
"org.bluez.Manager")
option_list = [
diff --git a/test/test-oob b/test/test-oob
index d44215f..40f45a8 100755
--- a/test/test-oob
+++ b/test/test-oob
@@ -20,7 +20,7 @@ if __name__ == '__main__':
mainloop = gobject.MainLoop()
bus = dbus.SystemBus()
- manager = dbus.Interface(bus.get_object("org.bluez", "/"),
+ manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
"org.bluez.Manager")
adapter0_path = manager.FindAdapter("hci0")
diff --git a/test/test-proximity b/test/test-proximity
index 9afb1d9..8c0d88a 100755
--- a/test/test-proximity
+++ b/test/test-proximity
@@ -23,7 +23,7 @@ if __name__ == "__main__":
bus = dbus.SystemBus()
- manager = dbus.Interface(bus.get_object("org.bluez", "/"),
+ manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
"org.bluez.Manager")
option_list = [
diff --git a/test/test-service b/test/test-service
index 17e8593..98f00a4 100755
--- a/test/test-service
+++ b/test/test-service
@@ -9,7 +9,8 @@ from optparse import OptionParser, make_option
bus = dbus.SystemBus()
-manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
+manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
+ "org.bluez.Manager")
option_list = [
make_option("-i", "--device", action="store",
diff --git a/test/test-thermometer b/test/test-thermometer
index 16ab0ac..8b86f76 100755
--- a/test/test-thermometer
+++ b/test/test-thermometer
@@ -38,7 +38,7 @@ if __name__ == "__main__":
bus = dbus.SystemBus()
- manager = dbus.Interface(bus.get_object("org.bluez", "/"),
+ manager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
"org.bluez.Manager")
option_list = [
--
1.7.11.7
From: Mikel Astiz <[email protected]>
Make the script compatible with the new API provided by the
ObjectManager and Properties interfaces.
---
test/monitor-bluetooth | 68 +++++++++++++++++++++++---------------------------
1 file changed, 31 insertions(+), 37 deletions(-)
diff --git a/test/monitor-bluetooth b/test/monitor-bluetooth
index 4a598e1..45cc910 100755
--- a/test/monitor-bluetooth
+++ b/test/monitor-bluetooth
@@ -7,15 +7,28 @@ import gobject
import dbus
import dbus.mainloop.glib
-def property_changed(name, value, path, interface):
- iface = interface[interface.rfind(".") + 1:]
- val = str(value)
- print("{%s.PropertyChanged} [%s] %s = %s" % (iface, path, name, val))
+relevant_ifaces = [ "org.bluez.Adapter", "org.bluez.Device" ]
-def object_signal(value, path, interface, member):
+def property_changed(interface, changed, invalidated, path):
iface = interface[interface.rfind(".") + 1:]
- val = str(value)
- print("{%s.%s} [%s] Path = %s" % (iface, member, path, val))
+ for name, value in changed.iteritems():
+ val = str(value)
+ print("{%s.PropertyChanged} [%s] %s = %s" % (iface, path, name,
+ val))
+
+def interfaces_added(path, interfaces):
+ for iface, props in interfaces.iteritems():
+ if not(iface in relevant_ifaces):
+ continue
+ print("{Added %s} [%s]" % (iface, path))
+ for name, value in props.iteritems():
+ print(" %s = %s" % (name, value))
+
+def interfaces_removed(path, interfaces):
+ for iface in interfaces:
+ if not(iface in relevant_ifaces):
+ continue
+ print("{Removed %s} [%s]" % (iface, path))
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
@@ -23,36 +36,17 @@ if __name__ == '__main__':
bus = dbus.SystemBus()
bus.add_signal_receiver(property_changed, bus_name="org.bluez",
- signal_name = "PropertyChanged",
- path_keyword="path",
- interface_keyword="interface")
-
- bus.add_signal_receiver(object_signal, bus_name="org.bluez",
- signal_name = "AdapterAdded",
- path_keyword="path",
- member_keyword="member",
- interface_keyword="interface")
- bus.add_signal_receiver(object_signal, bus_name="org.bluez",
- signal_name = "AdapterRemoved",
- path_keyword="path",
- member_keyword="member",
- interface_keyword="interface")
- bus.add_signal_receiver(object_signal, bus_name="org.bluez",
- signal_name = "DefaultAdapterChanged",
- path_keyword="path",
- member_keyword="member",
- interface_keyword="interface")
-
- bus.add_signal_receiver(object_signal, bus_name="org.bluez",
- signal_name = "DeviceCreated",
- path_keyword="path",
- member_keyword="member",
- interface_keyword="interface")
- bus.add_signal_receiver(object_signal, bus_name="org.bluez",
- signal_name = "DeviceRemoved",
- path_keyword="path",
- member_keyword="member",
- interface_keyword="interface")
+ dbus_interface="org.freedesktop.DBus.Properties",
+ signal_name="PropertiesChanged",
+ path_keyword="path")
+
+ bus.add_signal_receiver(interfaces_added, bus_name="org.bluez",
+ dbus_interface="org.freedesktop.DBus.ObjectManager",
+ signal_name="InterfacesAdded")
+
+ bus.add_signal_receiver(interfaces_removed, bus_name="org.bluez",
+ dbus_interface="org.freedesktop.DBus.ObjectManager",
+ signal_name="InterfacesRemoved")
mainloop = gobject.MainLoop()
mainloop.run()
--
1.7.11.7
From: Mikel Astiz <[email protected]>
Avoid using the root path to make the manager also a managed object,
handled by the ObjectManager. This is also more consistent with how
org.bluez.ProfileManager is being exposed.
---
doc/manager-api.txt | 2 +-
src/manager.c | 14 +++++++-------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/doc/manager-api.txt b/doc/manager-api.txt
index b0d534d..cf3284a 100644
--- a/doc/manager-api.txt
+++ b/doc/manager-api.txt
@@ -12,7 +12,7 @@ Manager hierarchy
Service org.bluez
Interface org.bluez.Manager
-Object path /
+Object path /org/bluez
object DefaultAdapter()
diff --git a/src/manager.c b/src/manager.c
index 79d049b..d6e7b80 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -186,7 +186,7 @@ static const GDBusPropertyTable manager_properties[] = {
bool manager_init(const char *path)
{
if (!g_dbus_register_interface(btd_get_dbus_connection(),
- "/", MANAGER_INTERFACE,
+ base_path, MANAGER_INTERFACE,
manager_methods, manager_signals,
manager_properties, NULL, NULL))
return false;
@@ -209,7 +209,7 @@ static void manager_set_default_adapter(int id)
path = adapter_get_path(adapter);
- g_dbus_emit_signal(btd_get_dbus_connection(), "/",
+ g_dbus_emit_signal(btd_get_dbus_connection(), base_path,
MANAGER_INTERFACE, "DefaultAdapterChanged",
DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
@@ -227,7 +227,7 @@ static void manager_remove_adapter(struct btd_adapter *adapter)
adapters = g_slist_remove(adapters, adapter);
- g_dbus_emit_property_changed(btd_get_dbus_connection(), "/",
+ g_dbus_emit_property_changed(btd_get_dbus_connection(), base_path,
MANAGER_INTERFACE, "Adapters");
if (default_adapter_id == dev_id || default_adapter_id < 0) {
@@ -236,7 +236,7 @@ static void manager_remove_adapter(struct btd_adapter *adapter)
manager_set_default_adapter(new_default);
}
- g_dbus_emit_signal(btd_get_dbus_connection(), "/",
+ g_dbus_emit_signal(btd_get_dbus_connection(), base_path,
MANAGER_INTERFACE, "AdapterRemoved",
DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
@@ -263,7 +263,7 @@ void manager_cleanup(const char *path)
btd_start_exit_timer();
g_dbus_unregister_interface(btd_get_dbus_connection(),
- "/", MANAGER_INTERFACE);
+ base_path, MANAGER_INTERFACE);
}
static gint adapter_id_cmp(gconstpointer a, gconstpointer b)
@@ -340,12 +340,12 @@ struct btd_adapter *btd_manager_register_adapter(int id, gboolean up)
}
path = adapter_get_path(adapter);
- g_dbus_emit_signal(btd_get_dbus_connection(), "/",
+ g_dbus_emit_signal(btd_get_dbus_connection(), base_path,
MANAGER_INTERFACE, "AdapterAdded",
DBUS_TYPE_OBJECT_PATH, &path,
DBUS_TYPE_INVALID);
- g_dbus_emit_property_changed(btd_get_dbus_connection(), "/",
+ g_dbus_emit_property_changed(btd_get_dbus_connection(), base_path,
MANAGER_INTERFACE, "Adapters");
btd_stop_exit_timer();
--
1.7.11.7
From: Mikel Astiz <[email protected]>
Use FindAdapter() with "default" as pattern as a replacement for
DefaultAdapter().
---
profiles/cups/main.c | 12 +++++++++--
test/agent.c | 55 +--------------------------------------------------
test/dbusdef.py | 2 +-
test/gaptest.c | 6 +++++-
test/mpris-player.c | 53 +------------------------------------------------
test/simple-agent | 2 +-
test/simple-endpoint | 2 +-
test/simple-player | 2 +-
test/simple-service | 2 +-
test/test-adapter | 2 +-
test/test-attrib | 2 +-
test/test-audio | 2 +-
test/test-device | 2 +-
test/test-discovery | 2 +-
test/test-heartrate | 2 +-
test/test-input | 2 +-
test/test-manager | 2 +-
test/test-nap | 2 +-
test/test-network | 2 +-
test/test-proximity | 2 +-
test/test-service | 2 +-
test/test-thermometer | 2 +-
22 files changed, 35 insertions(+), 127 deletions(-)
diff --git a/profiles/cups/main.c b/profiles/cups/main.c
index 977c057..b8bcbd3 100644
--- a/profiles/cups/main.c
+++ b/profiles/cups/main.c
@@ -526,6 +526,7 @@ static gboolean list_printers(void)
DBusMessage *reply, *message;
DBusMessageIter reply_iter;
char *adapter, *match;
+ const char *pattern = "default";
conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, NULL);
if (conn == NULL)
@@ -544,12 +545,15 @@ static gboolean list_printers(void)
/* Get the default adapter */
message = dbus_message_new_method_call("org.bluez", "/",
"org.bluez.Manager",
- "DefaultAdapter");
+ "FindAdapter");
if (message == NULL) {
dbus_connection_unref(conn);
return FALSE;
}
+ dbus_message_append_args(message, DBUS_TYPE_STRING, &pattern,
+ DBUS_TYPE_INVALID);
+
reply = dbus_connection_send_with_reply_and_block(conn,
message, -1, &error);
@@ -622,6 +626,7 @@ static gboolean print_ieee1284(const char *bdaddr)
char *object_path = NULL;
char *adapter;
char *id;
+ const char *pattern = "default";
adapter_reply = NULL;
@@ -631,7 +636,10 @@ static gboolean print_ieee1284(const char *bdaddr)
message = dbus_message_new_method_call("org.bluez", "/",
"org.bluez.Manager",
- "DefaultAdapter");
+ "FindAdapter");
+
+ dbus_message_append_args(message, DBUS_TYPE_STRING, &pattern,
+ DBUS_TYPE_INVALID);
adapter_reply = dbus_connection_send_with_reply_and_block(conn,
message, -1, NULL);
diff --git a/test/agent.c b/test/agent.c
index 5cdeeb4..6ad3bc7 100644
--- a/test/agent.c
+++ b/test/agent.c
@@ -464,59 +464,6 @@ static int create_paired_device(DBusConnection *conn, const char *adapter_path,
return 0;
}
-static char *get_default_adapter_path(DBusConnection *conn)
-{
- DBusMessage *msg, *reply;
- DBusError err;
- const char *reply_path;
- char *path;
-
- msg = dbus_message_new_method_call("org.bluez", "/",
- "org.bluez.Manager", "DefaultAdapter");
-
- if (!msg) {
- fprintf(stderr, "Can't allocate new method call\n");
- return NULL;
- }
-
- dbus_error_init(&err);
-
- reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err);
-
- dbus_message_unref(msg);
-
- if (!reply) {
- fprintf(stderr,
- "Can't get default adapter\n");
- if (dbus_error_is_set(&err)) {
- fprintf(stderr, "%s\n", err.message);
- dbus_error_free(&err);
- }
- return NULL;
- }
-
- if (!dbus_message_get_args(reply, &err,
- DBUS_TYPE_OBJECT_PATH, &reply_path,
- DBUS_TYPE_INVALID)) {
- fprintf(stderr,
- "Can't get reply arguments\n");
- if (dbus_error_is_set(&err)) {
- fprintf(stderr, "%s\n", err.message);
- dbus_error_free(&err);
- }
- dbus_message_unref(reply);
- return NULL;
- }
-
- path = strdup(reply_path);
-
- dbus_message_unref(reply);
-
- dbus_connection_flush(conn);
-
- return path;
-}
-
static char *get_adapter_path(DBusConnection *conn, const char *adapter)
{
DBusMessage *msg, *reply;
@@ -525,7 +472,7 @@ static char *get_adapter_path(DBusConnection *conn, const char *adapter)
char *path;
if (!adapter)
- return get_default_adapter_path(conn);
+ adapter = "default";
msg = dbus_message_new_method_call("org.bluez", "/",
"org.bluez.Manager", "FindAdapter");
diff --git a/test/dbusdef.py b/test/dbusdef.py
index 5af6153..1d55f97 100644
--- a/test/dbusdef.py
+++ b/test/dbusdef.py
@@ -11,6 +11,6 @@ dummy = dbus.Interface(bus.get_object('org.bluez', '/'), 'org.freedesktop.DBus.I
manager = dbus.Interface(bus.get_object('org.bluez', '/'), 'org.bluez.Manager')
try:
- adapter = dbus.Interface(bus.get_object('org.bluez', manager.DefaultAdapter()), 'org.bluez.Adapter')
+ adapter = dbus.Interface(bus.get_object('org.bluez', manager.FindAdapter("default")), 'org.bluez.Adapter')
except:
pass
diff --git a/test/gaptest.c b/test/gaptest.c
index 3e9f534..bcc3959 100644
--- a/test/gaptest.c
+++ b/test/gaptest.c
@@ -44,13 +44,17 @@ static char *get_adapter(DBusConnection *conn)
DBusMessage *message, *reply;
DBusError error;
const char *path;
+ const char *pattern = "default";
char *result = NULL;
message = dbus_message_new_method_call(BLUEZ_SERVICE, MANAGER_PATH,
- MANAGER_INTF, "DefaultAdapter");
+ MANAGER_INTF, "FindAdapter");
if (!message)
return NULL;
+ dbus_message_append_args(message, DBUS_TYPE_STRING, &pattern,
+ DBUS_TYPE_INVALID);
+
dbus_error_init(&error);
reply = dbus_connection_send_with_reply_and_block(conn,
diff --git a/test/mpris-player.c b/test/mpris-player.c
index 13f5c85..641db6e 100644
--- a/test/mpris-player.c
+++ b/test/mpris-player.c
@@ -662,57 +662,6 @@ static DBusHandlerResult system_filter(DBusConnection *conn,
return DBUS_HANDLER_RESULT_HANDLED;
}
-static char *get_default_adapter(DBusConnection *conn)
-{
- DBusMessage *msg, *reply;
- DBusError err;
- const char *reply_path;
- char *path;
-
- msg = dbus_message_new_method_call("org.bluez", "/",
- "org.bluez.Manager", "DefaultAdapter");
-
- if (!msg) {
- fprintf(stderr, "Can't allocate new method call\n");
- return NULL;
- }
-
- dbus_error_init(&err);
-
- reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err);
-
- dbus_message_unref(msg);
-
- if (!reply) {
- fprintf(stderr, "Can't get default adapter\n");
- if (dbus_error_is_set(&err)) {
- fprintf(stderr, "%s\n", err.message);
- dbus_error_free(&err);
- }
- return NULL;
- }
-
- if (!dbus_message_get_args(reply, &err,
- DBUS_TYPE_OBJECT_PATH, &reply_path,
- DBUS_TYPE_INVALID)) {
- fprintf(stderr, "Can't get reply arguments\n");
- if (dbus_error_is_set(&err)) {
- fprintf(stderr, "%s\n", err.message);
- dbus_error_free(&err);
- }
- dbus_message_unref(reply);
- return NULL;
- }
-
- path = strdup(reply_path);
-
- dbus_message_unref(reply);
-
- dbus_connection_flush(conn);
-
- return path;
-}
-
static char *get_adapter(DBusConnection *conn, const char *adapter)
{
DBusMessage *msg, *reply;
@@ -721,7 +670,7 @@ static char *get_adapter(DBusConnection *conn, const char *adapter)
char *path;
if (!adapter)
- return get_default_adapter(conn);
+ adapter = NULL;
msg = dbus_message_new_method_call("org.bluez", "/",
"org.bluez.Manager", "FindAdapter");
diff --git a/test/simple-agent b/test/simple-agent
index 092dbe2..cad7dc7 100755
--- a/test/simple-agent
+++ b/test/simple-agent
@@ -127,7 +127,7 @@ if __name__ == '__main__':
if len(args) > 0:
path = manager.FindAdapter(args[0])
else:
- path = manager.DefaultAdapter()
+ path = manager.FindAdapter("default")
adapter = dbus.Interface(bus.get_object("org.bluez", path),
"org.bluez.Adapter")
diff --git a/test/simple-endpoint b/test/simple-endpoint
index 20c8159..013ed8c 100755
--- a/test/simple-endpoint
+++ b/test/simple-endpoint
@@ -85,7 +85,7 @@ if __name__ == '__main__':
if len(sys.argv) > 1:
path = manager.FindAdapter(sys.argv[1])
else:
- path = manager.DefaultAdapter()
+ path = manager.FindAdapter("default")
media = dbus.Interface(bus.get_object("org.bluez", path),
"org.bluez.Media")
diff --git a/test/simple-player b/test/simple-player
index 9e72f3e..5e10e95 100755
--- a/test/simple-player
+++ b/test/simple-player
@@ -143,7 +143,7 @@ if __name__ == '__main__':
if len(sys.argv) > 1:
path = manager.FindAdapter(sys.argv[1])
else:
- path = manager.DefaultAdapter()
+ path = manager.FindAdapter("default")
media = dbus.Interface(bus.get_object("org.bluez", path),
"org.bluez.Media")
diff --git a/test/simple-service b/test/simple-service
index ed27d0c..9b65e80 100755
--- a/test/simple-service
+++ b/test/simple-service
@@ -109,7 +109,7 @@ manager = dbus.Interface(bus.get_object("org.bluez", "/"),
if len(sys.argv) > 1:
path = manager.FindAdapter(sys.argv[1])
else:
- path = manager.DefaultAdapter()
+ path = manager.FindAdapter("default")
service = dbus.Interface(bus.get_object("org.bluez", path),
"org.bluez.Service")
diff --git a/test/test-adapter b/test/test-adapter
index a37dd30..8d44dd8 100755
--- a/test/test-adapter
+++ b/test/test-adapter
@@ -22,7 +22,7 @@ parser = OptionParser(option_list=option_list)
if options.dev_id:
adapter_path = manager.FindAdapter(options.dev_id)
else:
- adapter_path = manager.DefaultAdapter()
+ adapter_path = manager.FindAdapter("default")
adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
"org.freedesktop.DBus.Properties")
diff --git a/test/test-attrib b/test/test-attrib
index f83859d..5263c84 100755
--- a/test/test-attrib
+++ b/test/test-attrib
@@ -31,7 +31,7 @@ parser = OptionParser(option_list=option_list)
if options.dev_id:
adapter_path = manager.FindAdapter(options.dev_id)
else:
- adapter_path = manager.DefaultAdapter()
+ adapter_path = manager.FindAdapter("default")
adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
"org.bluez.Adapter")
diff --git a/test/test-audio b/test/test-audio
index e302264..77cc22e 100755
--- a/test/test-audio
+++ b/test/test-audio
@@ -23,7 +23,7 @@ parser = OptionParser(option_list=option_list)
if options.dev_id:
adapter_path = manager.FindAdapter(options.dev_id)
else:
- adapter_path = manager.DefaultAdapter()
+ adapter_path = manager.FindAdapter("default")
if options.dev_if:
interface = "org.bluez." + options.dev_if
diff --git a/test/test-device b/test/test-device
index c26d7f6..8db1fac 100755
--- a/test/test-device
+++ b/test/test-device
@@ -27,7 +27,7 @@ parser = OptionParser(option_list=option_list)
if options.dev_id:
adapter_path = manager.FindAdapter(options.dev_id)
else:
- adapter_path = manager.DefaultAdapter()
+ adapter_path = manager.FindAdapter("default")
adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
"org.bluez.Adapter")
diff --git a/test/test-discovery b/test/test-discovery
index e85ab60..f262021 100755
--- a/test/test-discovery
+++ b/test/test-discovery
@@ -104,7 +104,7 @@ if __name__ == '__main__':
if options.dev_id:
adapter_path = manager.FindAdapter(options.dev_id)
else:
- adapter_path = manager.DefaultAdapter()
+ adapter_path = manager.FindAdapter("default")
if options.compact:
compact = True;
diff --git a/test/test-heartrate b/test/test-heartrate
index a7d05b4..aee6a46 100755
--- a/test/test-heartrate
+++ b/test/test-heartrate
@@ -59,7 +59,7 @@ if __name__ == "__main__":
if options.adapter:
adapter_path = manager.FindAdapter(options.adapter)
else:
- adapter_path = manager.DefaultAdapter()
+ adapter_path = manager.FindAdapter("default")
adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
"org.bluez.Adapter")
diff --git a/test/test-input b/test/test-input
index 110cbef..783a19f 100755
--- a/test/test-input
+++ b/test/test-input
@@ -21,7 +21,7 @@ parser = OptionParser(option_list=option_list)
if options.dev_id:
adapter_path = manager.FindAdapter(options.dev_id)
else:
- adapter_path = manager.DefaultAdapter()
+ adapter_path = manager.FindAdapter("default")
adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
"org.bluez.Adapter")
diff --git a/test/test-manager b/test/test-manager
index 8a7e2f6..30ca155 100755
--- a/test/test-manager
+++ b/test/test-manager
@@ -31,7 +31,7 @@ if __name__ == "__main__":
manager.connect_to_signal("DefaultAdapterChanged", default_changed)
try:
- path = manager.DefaultAdapter()
+ path = manager.FindAdapter("default")
default_changed(path)
except:
pass
diff --git a/test/test-nap b/test/test-nap
index dc779ad..b97b165 100755
--- a/test/test-nap
+++ b/test/test-nap
@@ -23,7 +23,7 @@ parser = OptionParser(option_list=option_list)
if options.dev_id:
adapter_path = manager.FindAdapter(options.dev_id)
else:
- adapter_path = manager.DefaultAdapter()
+ adapter_path = manager.FindAdapter("default")
server = dbus.Interface(bus.get_object("org.bluez", adapter_path),
"org.bluez.NetworkServer")
diff --git a/test/test-network b/test/test-network
index 2ade584..b920901 100755
--- a/test/test-network
+++ b/test/test-network
@@ -23,7 +23,7 @@ parser = OptionParser(option_list=option_list)
if options.dev_id:
adapter_path = manager.FindAdapter(options.dev_id)
else:
- adapter_path = manager.DefaultAdapter()
+ adapter_path = manager.FindAdapter("default")
adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
"org.bluez.Adapter")
diff --git a/test/test-proximity b/test/test-proximity
index b08a62a..9afb1d9 100755
--- a/test/test-proximity
+++ b/test/test-proximity
@@ -40,7 +40,7 @@ if __name__ == "__main__":
if options.dev_id:
adapter_path = manager.FindAdapter(options.dev_id)
else:
- adapter_path = manager.DefaultAdapter()
+ adapter_path = manager.FindAdapter("default")
adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
"org.bluez.Adapter")
diff --git a/test/test-service b/test/test-service
index 8eea9e2..17e8593 100755
--- a/test/test-service
+++ b/test/test-service
@@ -22,7 +22,7 @@ parser = OptionParser(option_list=option_list)
if options.dev_id:
adapter_path = manager.FindAdapter(options.dev_id)
else:
- adapter_path = manager.DefaultAdapter()
+ adapter_path = manager.FindAdapter("default")
service = dbus.Interface(bus.get_object("org.bluez", adapter_path),
"org.bluez.Service")
diff --git a/test/test-thermometer b/test/test-thermometer
index 2ca260f..16ab0ac 100755
--- a/test/test-thermometer
+++ b/test/test-thermometer
@@ -61,7 +61,7 @@ if __name__ == "__main__":
if options.adapter:
adapter_path = manager.FindAdapter(options.adapter)
else:
- adapter_path = manager.DefaultAdapter()
+ adapter_path = manager.FindAdapter("default")
adapter = dbus.Interface(bus.get_object("org.bluez", adapter_path),
"org.bluez.Adapter")
--
1.7.11.7
From: Mikel Astiz <[email protected]>
Extend the supported values in the given pattern in order to return the
default adapter if "default" is given.
---
doc/manager-api.txt | 1 +
src/manager.c | 4 +++-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/doc/manager-api.txt b/doc/manager-api.txt
index 8497141..b0d534d 100644
--- a/doc/manager-api.txt
+++ b/doc/manager-api.txt
@@ -27,6 +27,7 @@ Object path /
patterns are "hci0" or "00:11:22:33:44:55". Other
supported values are:
"any"
+ "default"
Possible errors: org.bluez.Error.InvalidArguments
org.bluez.Error.NoSuchAdapter
diff --git a/src/manager.c b/src/manager.c
index 3088dd9..79d049b 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -110,7 +110,9 @@ static DBusMessage *find_adapter(DBusConnection *conn,
} else if (!strncmp(pattern, "hci", 3) && strlen(pattern) >= 4) {
dev_id = atoi(pattern + 3);
adapter = manager_find_adapter_by_id(dev_id);
- } else {
+ } else if (!strcmp(pattern, "default"))
+ adapter = manager_find_adapter_by_id(default_adapter_id);
+ else {
bdaddr_t bdaddr;
str2ba(pattern, &bdaddr);
adapter = manager_find_adapter(&bdaddr);
--
1.7.11.7
From: Mikel Astiz <[email protected]>
The method supports the string "any" to return the any adapter object,
so update the documentation accordingly.
---
doc/manager-api.txt | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/doc/manager-api.txt b/doc/manager-api.txt
index 3add587..8497141 100644
--- a/doc/manager-api.txt
+++ b/doc/manager-api.txt
@@ -24,7 +24,9 @@ Object path /
object FindAdapter(string pattern)
Returns object path for the specified adapter. Valid
- patterns are "hci0" or "00:11:22:33:44:55".
+ patterns are "hci0" or "00:11:22:33:44:55". Other
+ supported values are:
+ "any"
Possible errors: org.bluez.Error.InvalidArguments
org.bluez.Error.NoSuchAdapter
--
1.7.11.7
From: Mikel Astiz <[email protected]>
The adapter is always known so the code to handle the NULL case is not
needed.
---
profiles/cups/main.c | 22 ++--------------------
1 file changed, 2 insertions(+), 20 deletions(-)
diff --git a/profiles/cups/main.c b/profiles/cups/main.c
index 5aa927f..977c057 100644
--- a/profiles/cups/main.c
+++ b/profiles/cups/main.c
@@ -31,6 +31,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include <signal.h>
#include <sys/socket.h>
#include <glib.h>
@@ -338,26 +339,7 @@ static void remote_device_found(const char *adapter, const char *bdaddr,
adapter_reply = NULL;
- if (adapter == NULL) {
- message = dbus_message_new_method_call("org.bluez", "/",
- "org.bluez.Manager",
- "DefaultAdapter");
-
- adapter_reply = dbus_connection_send_with_reply_and_block(conn,
- message, -1, NULL);
-
- dbus_message_unref(message);
-
- if (!adapter_reply)
- return;
-
- if (dbus_message_get_args(adapter_reply, NULL,
- DBUS_TYPE_OBJECT_PATH, &adapter,
- DBUS_TYPE_INVALID) == FALSE) {
- dbus_message_unref(adapter_reply);
- return;
- }
- }
+ assert(adapter != NULL);
message = dbus_message_new_method_call("org.bluez", adapter,
"org.bluez.Adapter",
--
1.7.11.7