Re: [Bluez-devel] [PATCH] Send DefaultAdapterChanged more often

Bastien Nocera
2008-02-01T12:33:16Z

[-- Attachment #1: Type: text/plain, Size: 536 bytes --]

On Fri, 2008-02-01 at 11:42 +0000, Bastien Nocera wrote:
> Before the patch, we only used to send the DefaultAdapter changed from
> one adapter to another, never when there wasn't a new default adapter.
>
> This allows us to remove bad tricks from client.c as well.
>
> Both patches attached. The bluez-gnome patch includes the changes from
> the client.c cleanup thread.
>
> Try plugging/unplugging your adapters after the patching, and the
> treeview will magically change its contents.

Updated patch with documentation changes.

[-- Attachment #2: bluez-utils-more-default-adapter-signal-2.patch --]
[-- Type: text/x-patch, Size: 2352 bytes --]

Index: dbus-api.txt
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus-api.txt,v
retrieving revision 1.136
diff -u -p -r1.136 dbus-api.txt
--- dbus-api.txt 1 Feb 2008 12:22:09 -0000 1.136
+++ dbus-api.txt 1 Feb 2008 12:32:46 -0000
@@ -224,7 +224,8 @@ Signals void AdapterAdded(string path)

void DefaultAdapterChanged(string path)

- Parameter is object path of the new default adapter.
+ Parameter is object path of the new default adapter,
+ or an empty string if there is no available adapters.

void ServiceAdded(string path)

Index: dbus-hci.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus-hci.c,v
retrieving revision 1.35
diff -u -p -r1.35 dbus-hci.c
--- dbus-hci.c 28 Jan 2008 10:38:40 -0000 1.35
+++ dbus-hci.c 1 Feb 2008 12:32:47 -0000
@@ -532,7 +532,7 @@ int hcid_dbus_unregister_device(uint16_t

ret = unregister_adapter_path(path);

- if (ret == 0 && get_default_adapter() == id) {
+ if (ret == 0 && (get_default_adapter() == id || get_default_adapter() < 0)) {
int new_default = hci_get_route(NULL);
set_default_adapter(new_default);
if (new_default >= 0) {
@@ -543,6 +543,13 @@ int hcid_dbus_unregister_device(uint16_t
"DefaultAdapterChanged",
DBUS_TYPE_STRING, &pptr,
DBUS_TYPE_INVALID);
+ } else {
+ *path = '\0';
+ dbus_connection_emit_signal(connection, BASE_PATH,
+ MANAGER_INTERFACE,
+ "DefaultAdapterChanged",
+ DBUS_TYPE_STRING, &pptr,
+ DBUS_TYPE_INVALID);
}
}

@@ -551,7 +558,7 @@ int hcid_dbus_unregister_device(uint16_t

int hcid_dbus_start_device(uint16_t id)
{
- char path[MAX_PATH_LENGTH];
+ char path[MAX_PATH_LENGTH], *pptr;
struct hci_dev_info di;
struct adapter* adapter;
struct hci_conn_list_req *cl = NULL;
@@ -633,10 +640,17 @@ int hcid_dbus_start_device(uint16_t id)
DBUS_TYPE_STRING, &mode,
DBUS_TYPE_INVALID);

-failed:
- if (ret == 0 && get_default_adapter() < 0)
+ if (get_default_adapter() < 0) {
set_default_adapter(id);
+ pptr = path;
+ dbus_connection_emit_signal(connection, BASE_PATH,
+ MANAGER_INTERFACE,
+ "DefaultAdapterChanged",
+ DBUS_TYPE_STRING, &pptr,
+ DBUS_TYPE_INVALID);
+ }

+failed:
if (dd >= 0)
hci_close_dev(dd);

[-- Attachment #3: Type: text/plain, Size: 228 bytes --]

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

[-- Attachment #4: Type: text/plain, Size: 164 bytes --]