summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2008-03-14 20:50:22 +0000
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2008-03-14 20:50:22 +0000
commit4bab9b442ec3e2e06157014c5d27641c79434e2a (patch)
treef644792a0071d0fe0ce7595196abdf4f6eea3435
parent9fa7cb38ac2f85ea1240b9b896de8145e59dd7d1 (diff)
added new adapter/device D-Bus path
-rw-r--r--hcid/adapter.c27
-rw-r--r--hcid/dbus-common.h1
-rw-r--r--hcid/dbus-hci.c108
-rw-r--r--hcid/device.c4
-rw-r--r--hcid/manager.c6
5 files changed, 112 insertions, 34 deletions
diff --git a/hcid/adapter.c b/hcid/adapter.c
index b509ae43..55565b18 100644
--- a/hcid/adapter.c
+++ b/hcid/adapter.c
@@ -3797,9 +3797,8 @@ GSList *service_classes_str(uint32_t class)
return l;
}
+/* BlueZ 4.0 API */
static DBusMethodVTable adapter_methods[] = {
-
- /* BlueZ 4.0 API */
{ "GetProperties", get_properties, "", "a{sv}" },
{ "SetProperty", set_property, "sv", "" },
{ "DiscoverDevices", adapter_discover_devices, "", "" },
@@ -3811,7 +3810,11 @@ static DBusMethodVTable adapter_methods[] = {
{ "FindDevice", find_device, "s", "o" },
{ "RegisterAgent", register_agent, "o", "" },
{ "UnregisterAgent", unregister_agent, "o", "" },
- /* Deprecated */
+ { NULL, NULL, NULL, NULL }
+};
+
+/* Deprecated */
+static DBusMethodVTable old_adapter_methods[] = {
{ "GetInfo", adapter_get_info,
"", "a{sv}" },
{ "GetAddress", adapter_get_address,
@@ -3949,8 +3952,8 @@ static DBusMethodVTable adapter_methods[] = {
{ NULL, NULL, NULL, NULL }
};
+/* BlueZ 4.X */
static DBusSignalVTable adapter_signals[] = {
- /* BlueZ 4.0 */
{ "DiscoveryStarted", "" },
{ "DiscoveryCompleted", "" },
{ "DeviceCreated", "o" },
@@ -3958,7 +3961,13 @@ static DBusSignalVTable adapter_signals[] = {
{ "DeviceFound", "sa{sv}" },
{ "PropertyChanged", "sv" },
{ "DeviceDisappeared", "s" },
- /* Deprecated */
+ { NULL, NULL }
+};
+
+/* Deprecated */
+static DBusSignalVTable old_adapter_signals[] = {
+ { "DiscoveryStarted", "" },
+ { "DiscoveryCompleted", "" },
{ "ModeChanged", "s" },
{ "DiscoverableTimeoutChanged", "u" },
{ "MinorClassChanged", "s" },
@@ -3986,6 +3995,12 @@ static DBusSignalVTable adapter_signals[] = {
dbus_bool_t adapter_init(DBusConnection *conn, const char *path)
{
- return dbus_connection_register_interface(conn, path, ADAPTER_INTERFACE,
+ if (hcid_dbus_use_experimental())
+ dbus_connection_register_interface(conn,
+ path + ADAPTER_PATH_INDEX, ADAPTER_INTERFACE,
adapter_methods, adapter_signals, NULL);
+
+ return dbus_connection_register_interface(conn,
+ path, ADAPTER_INTERFACE,
+ old_adapter_methods, old_adapter_signals, NULL);
}
diff --git a/hcid/dbus-common.h b/hcid/dbus-common.h
index 20dac475..61782dfe 100644
--- a/hcid/dbus-common.h
+++ b/hcid/dbus-common.h
@@ -23,6 +23,7 @@
*/
#define BASE_PATH "/org/bluez"
+#define ADAPTER_PATH_INDEX 10
#define MAX_PATH_LENGTH 64
diff --git a/hcid/dbus-hci.c b/hcid/dbus-hci.c
index 044c1421..bd05df84 100644
--- a/hcid/dbus-hci.c
+++ b/hcid/dbus-hci.c
@@ -315,7 +315,8 @@ static void adapter_mode_changed(struct adapter *adapter,
DBUS_TYPE_INVALID);
if (hcid_dbus_use_experimental()) {
- dbus_connection_emit_property_changed(connection, path,
+ const char *ptr = path + ADAPTER_PATH_INDEX;
+ dbus_connection_emit_property_changed(connection, ptr,
ADAPTER_INTERFACE, "Mode",
DBUS_TYPE_STRING, &mode);
}
@@ -355,6 +356,16 @@ static void reply_pending_requests(const char *path, struct adapter *adapter)
if (adapter->discov_active) {
/* Send discovery completed signal if there isn't name
* to resolve */
+ if (hcid_dbus_use_experimental()) {
+ const char *ptr = path + ADAPTER_PATH_INDEX;
+
+ dbus_connection_emit_signal(connection, ptr,
+ ADAPTER_INTERFACE,
+ "DiscoveryCompleted",
+ DBUS_TYPE_INVALID);
+
+ }
+
dbus_connection_emit_signal(connection, path,
ADAPTER_INTERFACE,
"DiscoveryCompleted",
@@ -472,6 +483,11 @@ unreg:
return -1;
}
+ if (hcid_dbus_use_experimental()) {
+ const char *ptr = path + ADAPTER_PATH_INDEX;
+ dbus_connection_destroy_object_path(connection, ptr);
+ }
+
return 0;
}
@@ -485,7 +501,7 @@ unreg:
int hcid_dbus_register_device(uint16_t id)
{
char path[MAX_PATH_LENGTH];
- char *pptr = path;
+ char *pptr = path, *ptr = path + ADAPTER_PATH_INDEX;
struct adapter *adapter;
snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id);
@@ -500,13 +516,23 @@ int hcid_dbus_register_device(uint16_t id)
adapter->dev_id = id;
adapter->pdiscov_resolve_names = 1;
- if (!dbus_connection_create_object_path(connection, path, adapter,
- NULL)) {
+ if (!dbus_connection_create_object_path(connection,
+ path, adapter, NULL)) {
error("D-Bus failed to register %s object", path);
g_free(adapter);
return -1;
}
+ if (hcid_dbus_use_experimental()) {
+ if (!dbus_connection_create_object_path(connection,
+ ptr, adapter, NULL)) {
+ error("D-Bus failed to register %s object", ptr);
+ dbus_connection_destroy_object_path(connection, path);
+ g_free(adapter);
+ return -1;
+ }
+ }
+
if (!adapter_init(connection, path)) {
error("Adapter interface init failed");
goto failed;
@@ -529,7 +555,7 @@ int hcid_dbus_register_device(uint16_t id)
dbus_connection_emit_signal(connection, "/",
MANAGER_INTERFACE,
"AdapterAdded",
- DBUS_TYPE_OBJECT_PATH, &pptr,
+ DBUS_TYPE_OBJECT_PATH, &ptr,
DBUS_TYPE_INVALID);
}
@@ -544,6 +570,7 @@ int hcid_dbus_register_device(uint16_t id)
failed:
dbus_connection_destroy_object_path(connection, path);
+ dbus_connection_destroy_object_path(connection, ptr);
g_free(adapter);
return -1;
@@ -552,7 +579,7 @@ failed:
int hcid_dbus_unregister_device(uint16_t id)
{
char path[MAX_PATH_LENGTH];
- char *pptr = path;
+ char *pptr = path, *ptr = path + ADAPTER_PATH_INDEX;
int ret;
snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id);
@@ -561,7 +588,7 @@ int hcid_dbus_unregister_device(uint16_t id)
dbus_connection_emit_signal(connection, "/",
MANAGER_INTERFACE,
"AdapterRemoved",
- DBUS_TYPE_OBJECT_PATH, &pptr,
+ DBUS_TYPE_OBJECT_PATH, &ptr,
DBUS_TYPE_INVALID);
}
@@ -582,7 +609,7 @@ int hcid_dbus_unregister_device(uint16_t id)
dbus_connection_emit_signal(connection, "/",
MANAGER_INTERFACE,
"DefaultAdapterChanged",
- DBUS_TYPE_OBJECT_PATH, &pptr,
+ DBUS_TYPE_OBJECT_PATH, &ptr,
DBUS_TYPE_INVALID);
}
dbus_connection_emit_signal(connection, BASE_PATH,
@@ -592,13 +619,6 @@ int hcid_dbus_unregister_device(uint16_t id)
DBUS_TYPE_INVALID);
} else {
*path = '\0';
- if (hcid_dbus_use_experimental()) {
- dbus_connection_emit_signal(connection, "/",
- MANAGER_INTERFACE,
- "DefaultAdapterChanged",
- DBUS_TYPE_OBJECT_PATH, &pptr,
- DBUS_TYPE_INVALID);
- }
dbus_connection_emit_signal(connection, BASE_PATH,
MANAGER_INTERFACE,
"DefaultAdapterChanged",
@@ -653,7 +673,8 @@ static void register_devices(bdaddr_t *src, struct adapter *adapter)
int hcid_dbus_start_device(uint16_t id)
{
- char path[MAX_PATH_LENGTH], *pptr;
+ char path[MAX_PATH_LENGTH];
+ char *pptr = path, *ptr = path + ADAPTER_PATH_INDEX;
struct hci_dev_info di;
struct adapter* adapter;
struct hci_conn_list_req *cl = NULL;
@@ -736,14 +757,20 @@ int hcid_dbus_start_device(uint16_t id)
DBUS_TYPE_INVALID);
if (hcid_dbus_use_experimental()) {
- dbus_connection_emit_property_changed(connection, path,
+ dbus_connection_emit_property_changed(connection, ptr,
ADAPTER_INTERFACE, "Mode",
DBUS_TYPE_STRING, &mode);
}
if (get_default_adapter() < 0) {
set_default_adapter(id);
- pptr = path;
+ if (hcid_dbus_use_experimental())
+ dbus_connection_emit_signal(connection, "/",
+ MANAGER_INTERFACE,
+ "DefaultAdapterChanged",
+ DBUS_TYPE_OBJECT_PATH, &ptr,
+ DBUS_TYPE_INVALID);
+
dbus_connection_emit_signal(connection, BASE_PATH,
MANAGER_INTERFACE,
"DefaultAdapterChanged",
@@ -853,7 +880,8 @@ int hcid_dbus_stop_device(uint16_t id)
DBUS_TYPE_INVALID);
if (hcid_dbus_use_experimental()) {
- dbus_connection_emit_property_changed(connection, path,
+ const char *ptr = path + ADAPTER_PATH_INDEX;
+ dbus_connection_emit_property_changed(connection, ptr,
ADAPTER_INTERFACE, "Mode",
DBUS_TYPE_STRING, &mode);
}
@@ -1026,6 +1054,7 @@ void hcid_dbus_inquiry_start(bdaddr_t *local)
{
struct adapter *adapter;
char path[MAX_PATH_LENGTH], local_addr[18];
+ const char *ptr = path + ADAPTER_PATH_INDEX;
int id;
ba2str(local, local_addr);
@@ -1053,7 +1082,7 @@ void hcid_dbus_inquiry_start(bdaddr_t *local)
adapter->discov_type &= ~RESOLVE_NAME;
if (hcid_dbus_use_experimental()) {
- dbus_connection_emit_property_changed(connection, path,
+ dbus_connection_emit_property_changed(connection, ptr,
ADAPTER_INTERFACE,
"PeriodicDiscovery",
DBUS_TYPE_BOOLEAN,
@@ -1063,6 +1092,13 @@ void hcid_dbus_inquiry_start(bdaddr_t *local)
send_adapter_signal(connection, adapter->dev_id, "DiscoveryStarted",
DBUS_TYPE_INVALID);
+
+ if (hcid_dbus_use_experimental())
+ dbus_connection_emit_signal(connection,
+ ptr, ADAPTER_INTERFACE,
+ "DiscoveryStarted",
+ DBUS_TYPE_INVALID);
+
}
int found_device_req_name(struct adapter *adapter)
@@ -1174,7 +1210,8 @@ static void send_out_of_range(const char *path, GSList *l)
DBUS_TYPE_INVALID);
if (hcid_dbus_use_experimental()) {
- dbus_connection_emit_signal(connection, path,
+ const char *ptr = path + ADAPTER_PATH_INDEX;
+ dbus_connection_emit_signal(connection, ptr,
ADAPTER_INTERFACE,
"DeviceDisappeared",
DBUS_TYPE_STRING,
@@ -1254,6 +1291,15 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local)
goto done; /* skip - there is name to resolve */
if (adapter->discov_active) {
+ if (hcid_dbus_use_experimental()) {
+ const char *ptr = path + ADAPTER_PATH_INDEX;
+ dbus_connection_emit_signal(connection, ptr,
+ ADAPTER_INTERFACE,
+ "DiscoveryCompleted",
+ DBUS_TYPE_INVALID);
+
+ }
+
dbus_connection_emit_signal(connection, path,
ADAPTER_INTERFACE,
"DiscoveryCompleted",
@@ -1318,7 +1364,8 @@ void hcid_dbus_periodic_inquiry_start(bdaddr_t *local, uint8_t status)
adapter->discov_type &= ~RESOLVE_NAME;
if (hcid_dbus_use_experimental()) {
- dbus_connection_emit_property_changed(connection, path,
+ const char *ptr = path + ADAPTER_PATH_INDEX;
+ dbus_connection_emit_property_changed(connection, ptr,
ADAPTER_INTERFACE,
"PeriodicDiscovery",
DBUS_TYPE_BOOLEAN,
@@ -1335,6 +1382,7 @@ void hcid_dbus_periodic_inquiry_exit(bdaddr_t *local, uint8_t status)
{
struct adapter *adapter;
char path[MAX_PATH_LENGTH], local_addr[18];
+ const char *ptr = path + ADAPTER_PATH_INDEX;
int id;
/* Don't send the signal if the cmd failed */
@@ -1383,6 +1431,12 @@ void hcid_dbus_periodic_inquiry_exit(bdaddr_t *local, uint8_t status)
/* workaround: inquiry completed is not sent when exiting from
* periodic inquiry */
if (adapter->discov_active) {
+ if (hcid_dbus_use_experimental())
+ dbus_connection_emit_signal(connection, ptr,
+ ADAPTER_INTERFACE,
+ "DiscoveryCompleted",
+ DBUS_TYPE_INVALID);
+
dbus_connection_emit_signal(connection, path,
ADAPTER_INTERFACE,
"DiscoveryCompleted",
@@ -1396,7 +1450,7 @@ void hcid_dbus_periodic_inquiry_exit(bdaddr_t *local, uint8_t status)
DBUS_TYPE_INVALID);
if (!hcid_dbus_use_experimental()) {
- dbus_connection_emit_property_changed(connection, path,
+ dbus_connection_emit_property_changed(connection, ptr,
ADAPTER_INTERFACE,
"PeriodicDiscovery",
DBUS_TYPE_BOOLEAN,
@@ -1685,6 +1739,14 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status,
}
if (adapter->discov_active) {
+ if (hcid_dbus_use_experimental()) {
+ const char *ptr = path + ADAPTER_PATH_INDEX;
+ dbus_connection_emit_signal(connection, ptr,
+ ADAPTER_INTERFACE,
+ "DiscoveryCompleted",
+ DBUS_TYPE_INVALID);
+
+ }
dbus_connection_emit_signal(connection, path,
ADAPTER_INTERFACE,
"DiscoveryCompleted",
diff --git a/hcid/device.c b/hcid/device.c
index 2b331361..24ba6e51 100644
--- a/hcid/device.c
+++ b/hcid/device.c
@@ -976,8 +976,8 @@ struct device *device_create(DBusConnection *conn, struct adapter *adapter,
if (device == NULL)
return NULL;
- device->path = g_strdup_printf("%s/hci%d/dev_%s",
- BASE_PATH, adapter->dev_id, address);
+ device->path = g_strdup_printf("/hci%d/dev_%s",
+ adapter->dev_id, address);
g_strdelimit(device->path, ":", '_');
debug("Creating device %s", device->path);
diff --git a/hcid/manager.c b/hcid/manager.c
index cb6e80f5..3e36d184 100644
--- a/hcid/manager.c
+++ b/hcid/manager.c
@@ -385,7 +385,7 @@ static DBusHandlerResult default_adapter(DBusConnection *conn,
if (!reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
- snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, default_adapter_id);
+ snprintf(path, sizeof(path), "/hci%d", default_adapter_id);
dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path_ptr,
DBUS_TYPE_INVALID);
@@ -427,7 +427,7 @@ static DBusHandlerResult find_adapter(DBusConnection *conn,
if (!reply)
return DBUS_HANDLER_RESULT_NEED_MEMORY;
- snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, dev_id);
+ snprintf(path, sizeof(path), "/hci%d", dev_id);
dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path_ptr,
DBUS_TYPE_INVALID);
@@ -488,7 +488,7 @@ static DBusHandlerResult list_adapters(DBusConnection *conn,
if (hci_test_bit(HCI_RAW, &di.flags))
continue;
- snprintf(path, sizeof(path), "%s/%s", BASE_PATH, di.name);
+ snprintf(path, sizeof(path), "/hci%d", di.dev_id);
dbus_message_iter_append_basic(&array_iter,
DBUS_TYPE_OBJECT_PATH, &path_ptr);