diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-10-26 15:34:00 +0000 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-10-26 15:34:00 +0000 |
commit | b349c091ed2747c2af175ef0017d5eebb9f3fce3 (patch) | |
tree | 34587b47205c93efda20fb88f6fabe09b27b5b89 | |
parent | 7a8ce43929e0a25d49a81b89d60bbc69e9bc6c12 (diff) |
Send Release to all service agents before the hcid daemon exits
-rw-r--r-- | hcid/dbus-service.c | 50 | ||||
-rw-r--r-- | hcid/dbus.c | 1 | ||||
-rw-r--r-- | hcid/dbus.h | 1 |
3 files changed, 44 insertions, 8 deletions
diff --git a/hcid/dbus-service.c b/hcid/dbus-service.c index dac91746..a7db85cc 100644 --- a/hcid/dbus-service.c +++ b/hcid/dbus-service.c @@ -105,6 +105,7 @@ static void service_agent_free(struct service_agent *agent) if (agent->description) free(agent->description); + free(agent); } @@ -163,7 +164,7 @@ static void forward_reply(DBusPendingCall *call, void *udata) dbus_message_set_no_reply(source_reply, TRUE); dbus_message_set_reply_serial(source_reply, dbus_message_get_serial(call_data->msg)); - /* FIXME: Handle send error */ + /* FIXME: send fails only due to lack of memory */ dbus_connection_send(call_data->conn, source_reply, NULL); dbus_message_unref(reply); @@ -196,21 +197,20 @@ static DBusHandlerResult get_interface_names(DBusConnection *conn, dbus_pending_call_set_notify(pending, forward_reply, call_data, service_call_free); dbus_message_unref(forward); + return DBUS_HANDLER_RESULT_HANDLED; } static DBusHandlerResult get_connection_name(DBusConnection *conn, DBusMessage *msg, void *data) { + struct service_agent *agent = data; DBusMessage *reply; - struct service_agent *agent; reply = dbus_message_new_method_return(msg); if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - agent = data; - dbus_message_append_args(reply, DBUS_TYPE_STRING, &agent->id, DBUS_TYPE_INVALID); @@ -243,16 +243,14 @@ static DBusHandlerResult get_name(DBusConnection *conn, static DBusHandlerResult get_description(DBusConnection *conn, DBusMessage *msg, void *data) { + struct service_agent *agent = data; DBusMessage *reply; - struct service_agent *agent; const char *description = ""; reply = dbus_message_new_method_return(msg); if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - agent = data; - if (agent->description) description = agent->description; @@ -403,7 +401,7 @@ int unregister_service_agent(DBusConnection *conn, const char *sender, const cha struct slist *l; debug("Unregistering service object: %s", path); - + if (!dbus_connection_get_object_path_data(conn, path, (void *) &agent)) return -1; @@ -419,10 +417,46 @@ int unregister_service_agent(DBusConnection *conn, const char *sender, const cha return 0; } +void send_release(DBusConnection *conn, const char *id, const char *path) +{ + DBusMessage *msg; + + msg = dbus_message_new_method_call(id, path, + "org.bluez.ServiceAgent", "Release"); + if (!msg) + return; + + dbus_message_set_no_reply(msg, TRUE); + dbus_connection_send(conn, msg, NULL); + dbus_message_unref(msg); +} + +void release_service_agents(DBusConnection *conn) +{ + struct slist *l = services; + struct service_agent *agent; + const char *path; + + while (l) { + path = l->data; + + l = l->next; + + if (dbus_connection_get_object_path_data(conn, path, (void *) &agent)) { + send_release(conn, agent->id, path); + service_agent_free(agent); + } + + dbus_connection_unregister_object_path (conn, path); + } + +} + void append_available_services(DBusMessageIter *array_iter) { struct slist *l = services; const char *path; + while (l) { path = l->data; dbus_message_iter_append_basic(array_iter, diff --git a/hcid/dbus.c b/hcid/dbus.c index 0241f8ee..e38d82b2 100644 --- a/hcid/dbus.c +++ b/hcid/dbus.c @@ -1980,6 +1980,7 @@ void hcid_dbus_exit(void) return; release_default_agent(); + release_service_agents(connection); /* Unregister all paths in Adapter path hierarchy */ if (!dbus_connection_list_registered(connection, BASE_PATH, &children)) diff --git a/hcid/dbus.h b/hcid/dbus.h index 6d8b80b0..a5f7f562 100644 --- a/hcid/dbus.h +++ b/hcid/dbus.h @@ -161,6 +161,7 @@ DBusHandlerResult msg_func_manager(DBusConnection *conn, DBusMessage *msg, void int register_service_agent(DBusConnection *conn, const char *sender, const char *path, const char *name, const char *description); int unregister_service_agent(DBusConnection *conn, const char *sender, const char *path); +void release_service_agents(DBusConnection *conn); void append_available_services(DBusMessageIter *iter); const char *major_class_str(uint32_t class); |