diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-11-08 13:41:17 +0000 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-11-08 13:41:17 +0000 |
commit | 346cb4d17e492265b9e14c6352c8ee6c564b5498 (patch) | |
tree | 02642134862d6df694658abe41d6c315b040c82b /hcid/dbus-service.c | |
parent | 4ed477329df88211caca3806824249fab80f5a7e (diff) |
Register the service record using the binary registration function
Diffstat (limited to 'hcid/dbus-service.c')
-rw-r--r-- | hcid/dbus-service.c | 66 |
1 files changed, 55 insertions, 11 deletions
diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c index b4207059..00693439 100644 --- a/hcid/dbus-service.c +++ b/hcid/dbus-service.c @@ -46,6 +46,39 @@ static struct slist *services = NULL; +struct binary_record *binary_record_new() +{ + struct binary_record *rec; + rec = malloc(sizeof(struct binary_record)); + if (!rec) + return NULL; + + memset(rec, 0, sizeof(struct binary_record)); + rec->handle = 0xffffffff; + + return rec; +} + +void binary_record_free(struct binary_record *rec) +{ + if (!rec) + return; + + if (rec->buf) { + if (rec->buf->data) + free(rec->buf->data); + free(rec->buf); + } + + free(rec); +} + +int binary_record_cmp(struct binary_record *rec, uint32_t *handle) +{ + return (rec->handle - *handle); +} + + struct service_call *service_call_new(DBusConnection *conn, DBusMessage *msg, struct service_agent *agent) { @@ -128,8 +161,7 @@ static void service_agent_free(struct service_agent *agent) } if (agent->records) { - /* FIXME: currently sdp_device_record_unregister free the service record */ - //slist_foreach(agent->records, (slist_func_t) sdp_record_free, NULL); + slist_foreach(agent->records, (slist_func_t) binary_record_free, NULL); slist_free(agent->records); } @@ -176,7 +208,8 @@ mem_fail: int register_agent_records(struct slist *lrecords) { sdp_session_t *sess; - sdp_record_t *rec; + struct binary_record *rec; + uint32_t handle; /* FIXME: attach to a specific adapter */ sess = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, 0); @@ -187,12 +220,19 @@ int register_agent_records(struct slist *lrecords) while (lrecords) { rec = lrecords->data; - if (sdp_device_record_register(sess, BDADDR_ANY, rec, SDP_RECORD_PERSIST) < 0) { + lrecords = lrecords->next; + + if (!rec || !rec->buf) + continue; + + handle = 0; + if (sdp_device_record_register_binary(sess, BDADDR_LOCAL, rec->buf->data, + rec->buf->data_size, SDP_RECORD_PERSIST, &handle) < 0) { /* FIXME: If just one of the service record registration fails */ - error("Service Record registration failed:(%s, %d)", strerror(errno), errno); + error("Service Record registration failed:(%s, %d)", + strerror(errno), errno); } - - lrecords = lrecords->next; + rec->handle = handle; } sdp_close(sess); return 0; @@ -201,7 +241,7 @@ int register_agent_records(struct slist *lrecords) static int unregister_agent_records(struct slist *lrecords) { sdp_session_t *sess; - sdp_record_t *rec; + struct binary_record *rec; /* FIXME: attach to a specific adapter */ sess = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, 0); @@ -212,11 +252,15 @@ static int unregister_agent_records(struct slist *lrecords) while (lrecords) { rec = lrecords->data; - if (sdp_device_record_unregister(sess, BDADDR_ANY, rec) < 0) { + lrecords = lrecords->next; + if (!rec) + continue; + + if (sdp_device_record_unregister_binary(sess, BDADDR_ANY, rec->handle) < 0) { /* FIXME: If just one of the service record registration fails */ - error("Service Record unregistration failed:(%s, %d)", strerror(errno), errno); + error("Service Record unregistration failed:(%s, %d)", + strerror(errno), errno); } - lrecords = lrecords->next; } sdp_close(sess); return 0; |