summaryrefslogtreecommitdiffstats
path: root/hcid
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2008-03-07 17:53:50 +0000
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2008-03-07 17:53:50 +0000
commitda0e7105811dc046d13d0365404efc1189ee4a8c (patch)
treedffa4eee585192d1402a6427bb087a7263cc399c /hcid
parentc6638ee5c399991f1496b213de64529fcd8556eb (diff)
Registering device's object path
Diffstat (limited to 'hcid')
-rw-r--r--hcid/adapter.c13
-rw-r--r--hcid/adapter.h6
-rw-r--r--hcid/dbus-hci.c5
-rw-r--r--hcid/device.c13
-rw-r--r--hcid/device.h7
5 files changed, 36 insertions, 8 deletions
diff --git a/hcid/adapter.c b/hcid/adapter.c
index e58cb87a..31eb8309 100644
--- a/hcid/adapter.c
+++ b/hcid/adapter.c
@@ -3180,6 +3180,7 @@ static void discover_services_cb(gpointer user_data, sdp_list_t *recs, int err)
{
struct adapter *adapter = user_data;
DBusMessage *reply;
+ const char *path;
if (err < 0) {
error_connection_attempt_failed(adapter->create->conn,
@@ -3187,11 +3188,20 @@ static void discover_services_cb(gpointer user_data, sdp_list_t *recs, int err)
goto failed;
}
- /* FIXME: Register the device object path */
+ path = device_create(adapter, adapter->create->address, recs);
+ if (!path)
+ goto failed;
reply = dbus_message_new_method_return(adapter->create->msg);
+ if (!reply)
+ goto failed;
+
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &path,
+ DBUS_TYPE_INVALID);
send_message_and_unref(adapter->create->conn, reply);
+ adapter->devices = g_slist_append(adapter->devices, g_strdup(path));
+
failed:
dbus_connection_unref(adapter->create->conn);
dbus_message_unref(adapter->create->msg);
@@ -3233,6 +3243,7 @@ static DBusHandlerResult create_device(DBusConnection *conn,
create = g_malloc0(sizeof(struct create_device_req));
create->conn = dbus_connection_ref(conn);
create->msg = dbus_message_ref(msg);
+ strcpy(create->address, address);
adapter->create = create;
return DBUS_HANDLER_RESULT_HANDLED;
diff --git a/hcid/adapter.h b/hcid/adapter.h
index b6f30291..c9ceea0f 100644
--- a/hcid/adapter.h
+++ b/hcid/adapter.h
@@ -81,8 +81,9 @@ struct pending_dc_info {
};
struct create_device_req {
- DBusConnection *conn;
- DBusMessage *msg;
+ char address[18]; /* Destination address */
+ DBusConnection *conn; /* Connection reference */
+ DBusMessage *msg; /* Message reference */
};
struct adapter {
@@ -112,6 +113,7 @@ struct adapter {
GSList *pin_reqs;
struct pending_dc_info *pending_dc;
struct create_device_req *create;
+ GSList *devices; /* Devices paths */
};
dbus_bool_t adapter_init(DBusConnection *conn, const char *path);
diff --git a/hcid/dbus-hci.c b/hcid/dbus-hci.c
index 4e082ab3..defa5375 100644
--- a/hcid/dbus-hci.c
+++ b/hcid/dbus-hci.c
@@ -442,6 +442,11 @@ int unregister_adapter_path(const char *path)
dc_pending_timeout_cleanup(adapter);
}
+ if (adapter->devices) {
+ g_slist_foreach(adapter->devices, (GFunc) free, NULL);
+ g_slist_free(adapter->devices);
+ }
+
g_free(adapter);
unreg:
diff --git a/hcid/device.c b/hcid/device.c
index bf84ad2c..51e6bebc 100644
--- a/hcid/device.c
+++ b/hcid/device.c
@@ -54,6 +54,7 @@
#include "adapter.h"
#include "device.h"
+#include "dbus-common.h"
#define MAX_DEVICES 16
@@ -789,7 +790,8 @@ static DBusSignalVTable device_signals[] = {
{ NULL, NULL }
};
-struct device *device_create(struct adapter *adapter, const char *address)
+const char *device_create(struct adapter *adapter,
+ const char *address, sdp_list_t *recs)
{
struct device *device;
@@ -797,7 +799,8 @@ struct device *device_create(struct adapter *adapter, const char *address)
if (device == NULL)
return NULL;
- device->path = g_strdup_printf("%s/dev_%s", adapter->address, address);
+ device->path = g_strdup_printf("%s/hci%d/dev_%s",
+ BASE_PATH, adapter->dev_id, address);
g_strdelimit(device->path, ":", '_');
debug("Creating device %s", device->path);
@@ -807,12 +810,16 @@ struct device *device_create(struct adapter *adapter, const char *address)
device_free(device);
return NULL;
}
+
dbus_connection_register_interface(connection, device->path,
DEVICE_INTERFACE, device_methods, device_signals, NULL);
device_list = g_slist_append(device_list, device);
- return device;
+ device->adapter = adapter;
+ device->records = recs;
+
+ return device->path;
}
void device_remove(const char *path)
diff --git a/hcid/device.h b/hcid/device.h
index e0277de7..0eaa92c7 100644
--- a/hcid/device.h
+++ b/hcid/device.h
@@ -23,11 +23,14 @@
*/
struct device {
- char *path;
+ char *path;
+ struct adapter *adapter;
+ sdp_list_t *records;
};
gboolean device_init(DBusConnection *conn);
void device_cleanup(void);
void device_foreach(GFunc func, gpointer user_data);
-struct device *device_create(struct adapter *adapter, const char *address);
+const char *device_create(struct adapter *adapter,
+ const char *address, sdp_list_t *recs);
void device_remove(const char *path);