summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2006-11-16 20:26:43 +0000
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2006-11-16 20:26:43 +0000
commit4223f91dd1beb9160fb0cd2b67793a1cf2436094 (patch)
treeb31bb38614ed4294dbe6b93d18d2b14698aabce4
parent540775d2ea97de236ff2aa9da43ebd42de3f8f8f (diff)
Added pre-allocate service record handles
-rw-r--r--hcid/dbus-manager.c11
-rw-r--r--hcid/dbus-service.c8
-rw-r--r--hcid/dbus-service.h1
3 files changed, 14 insertions, 6 deletions
diff --git a/hcid/dbus-manager.c b/hcid/dbus-manager.c
index dd6c0b4c..cd423d60 100644
--- a/hcid/dbus-manager.c
+++ b/hcid/dbus-manager.c
@@ -51,6 +51,8 @@
static int default_adapter_id = -1;
static int autostart = 1;
+static uint32_t next_handle = 0x10000;
+
static DBusHandlerResult interface_version(DBusConnection *conn,
DBusMessage *msg, void *data)
{
@@ -442,6 +444,9 @@ static DBusHandlerResult add_service_record(DBusConnection *conn,
return error_invalid_arguments(conn, msg);
}
+ /* Assign a new handle */
+ rec->ext_handle = next_handle++;
+
if (agent->running) {
sdp_session_t *sess;
uint32_t handle = 0;
@@ -472,7 +477,7 @@ static DBusHandlerResult add_service_record(DBusConnection *conn,
agent->records = slist_append(agent->records, rec);
dbus_message_append_args(reply,
- DBUS_TYPE_UINT32, &rec->handle,
+ DBUS_TYPE_UINT32, &rec->ext_handle,
DBUS_TYPE_INVALID);
return send_message_and_unref(conn, reply);
@@ -520,9 +525,9 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn,
agent->records = slist_remove(agent->records, rec);
/* If the service agent is running: remove it from the from sdpd */
- if (agent->running) {
+ if (agent->running && rec->handle != 0xffffffff) {
sdp_session_t *sess;
-
+
/* FIXME: attach to a specific adapter */
sess = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, 0);
if (!sess) {
diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c
index 75a72de1..00e29e52 100644
--- a/hcid/dbus-service.c
+++ b/hcid/dbus-service.c
@@ -54,6 +54,7 @@ struct binary_record *binary_record_new()
return NULL;
memset(rec, 0, sizeof(struct binary_record));
+ rec->ext_handle = 0xffffffff;
rec->handle = 0xffffffff;
return rec;
@@ -75,7 +76,7 @@ void binary_record_free(struct binary_record *rec)
int binary_record_cmp(struct binary_record *rec, uint32_t *handle)
{
- return (rec->handle - *handle);
+ return (rec->ext_handle - *handle);
}
@@ -223,7 +224,7 @@ int register_agent_records(struct slist *lrecords)
rec = lrecords->data;
lrecords = lrecords->next;
- if (!rec || !rec->buf)
+ if (!rec || !rec->buf || rec->handle != 0xffffffff)
continue;
handle = 0;
@@ -259,7 +260,7 @@ static int unregister_agent_records(struct slist *lrecords)
while (lrecords) {
rec = lrecords->data;
lrecords = lrecords->next;
- if (!rec)
+ if (!rec || rec->handle == 0xffffffff)
continue;
if (sdp_device_record_unregister_binary(sess, BDADDR_ANY, rec->handle) < 0) {
@@ -267,6 +268,7 @@ static int unregister_agent_records(struct slist *lrecords)
error("Service Record unregistration failed:(%s, %d)",
strerror(errno), errno);
}
+ rec->handle = 0xffffffff;
}
err = errno;
diff --git a/hcid/dbus-service.h b/hcid/dbus-service.h
index 4476d937..f96f2aa7 100644
--- a/hcid/dbus-service.h
+++ b/hcid/dbus-service.h
@@ -44,6 +44,7 @@ struct service_call {
};
struct binary_record {
+ uint32_t ext_handle;
uint32_t handle;
sdp_buf_t *buf;
};