diff options
author | Johan Hedberg <johan.hedberg@nokia.com> | 2008-05-29 14:43:27 +0000 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2008-05-29 14:43:27 +0000 |
commit | cc0f97ec2cb298bde87cd3753fd96f11ce41ff64 (patch) | |
tree | e02bb5f68ca60810d2793708939306174f4aa100 | |
parent | 4baf1de49d3aad2837a968a18a7181d568ff9457 (diff) |
Change name_listener API to libgdbus watch API
-rw-r--r-- | daemon/database.c | 8 | ||||
-rw-r--r-- | gdbus/gdbus.h | 16 | ||||
-rw-r--r-- | gdbus/watch.c | 63 | ||||
-rw-r--r-- | hcid/adapter.c | 49 | ||||
-rw-r--r-- | hcid/agent.c | 11 | ||||
-rw-r--r-- | hcid/dbus-database.c | 14 | ||||
-rw-r--r-- | hcid/dbus-hci.c | 22 | ||||
-rw-r--r-- | hcid/dbus-security.c | 76 | ||||
-rw-r--r-- | hcid/dbus-test.c | 21 | ||||
-rw-r--r-- | serial/manager.c | 40 | ||||
-rw-r--r-- | serial/port.c | 17 |
11 files changed, 141 insertions, 196 deletions
diff --git a/daemon/database.c b/daemon/database.c index 47e21915..be6ca28c 100644 --- a/daemon/database.c +++ b/daemon/database.c @@ -69,7 +69,7 @@ static struct record_data *find_record(uint32_t handle, const char *sender) return NULL; } -static void exit_callback(const char *name, void *user_data) +static void exit_callback(void *user_data) { struct record_data *user_record = user_data; @@ -145,9 +145,9 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, records = g_slist_append(records, user_record); - user_record->listener_id = name_listener_add(conn, sender, + user_record->listener_id = g_dbus_add_disconnect_watch(conn, sender, exit_callback, - user_record); + user_record, NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -176,7 +176,7 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, if (!user_record) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - name_listener_id_remove(user_record->listener_id); + g_dbus_remove_watch(conn, user_record->listener_id); remove_record_from_server(handle); diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h index 6f3ddb79..22c10569 100644 --- a/gdbus/gdbus.h +++ b/gdbus/gdbus.h @@ -185,14 +185,14 @@ gboolean g_dbus_send_reply(DBusConnection *connection, gboolean g_dbus_send_reply_valist(DBusConnection *connection, DBusMessage *message, int type, va_list args); -typedef void (*name_cb_t)(const char *name, void *user_data); - -guint name_listener_add(DBusConnection *connection, const char *name, - name_cb_t func, void *user_data); -int name_listener_remove(DBusConnection *connection, const char *name, - name_cb_t func, void *user_data); -gboolean name_listener_id_remove(guint id); -int name_listener_indicate_disconnect(DBusConnection *connection); +typedef void (* GDBusWatchFunction) (void *user_data); + +guint g_dbus_add_disconnect_watch(DBusConnection *connection, + const char *name, + GDBusWatchFunction function, + void *user_data, GDBusDestroyFunction destroy); +gboolean g_dbus_remove_watch(DBusConnection *connection, guint tag); +void g_dbus_remove_all_watches(DBusConnection *connection); #ifdef __cplusplus } diff --git a/gdbus/watch.c b/gdbus/watch.c index 80be3a6a..3c7a03a4 100644 --- a/gdbus/watch.c +++ b/gdbus/watch.c @@ -41,7 +41,7 @@ static guint listener_id = 0; static GSList *name_listeners = NULL; struct name_callback { - name_cb_t func; + GDBusWatchFunction func; void *user_data; guint id; }; @@ -74,7 +74,7 @@ static struct name_data *name_data_find(DBusConnection *connection, } static struct name_callback *name_callback_find(GSList *callbacks, - name_cb_t func, void *user_data) + GDBusWatchFunction func, void *user_data) { GSList *current; @@ -94,7 +94,7 @@ static void name_data_call_and_free(struct name_data *data) for (l = data->callbacks; l != NULL; l = l->next) { struct name_callback *cb = l->data; if (cb->func) - cb->func(data->name, cb->user_data); + cb->func(cb->user_data); g_free(cb); } @@ -116,7 +116,7 @@ static void name_data_free(struct name_data *data) } static int name_data_add(DBusConnection *connection, const char *name, - name_cb_t func, void *user_data, guint id) + GDBusWatchFunction func, void *user_data, guint id) { int first = 1; struct name_data *data = NULL; @@ -147,7 +147,7 @@ done: } static void name_data_remove(DBusConnection *connection, - const char *name, name_cb_t func, void *user_data) + const char *name, GDBusWatchFunction func, void *user_data) { struct name_data *data; struct name_callback *cb = NULL; @@ -246,7 +246,7 @@ static DBusHandlerResult name_exit_filter(DBusConnection *connection, for (l = data->callbacks; l != NULL; l = l->next) { struct name_callback *cb = l->data; - cb->func(name, cb->user_data); + cb->func(cb->user_data); } name_listeners = g_slist_remove(name_listeners, data); @@ -257,8 +257,10 @@ static DBusHandlerResult name_exit_filter(DBusConnection *connection, return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } -guint name_listener_add(DBusConnection *connection, const char *name, - name_cb_t func, void *user_data) +guint g_dbus_add_disconnect_watch(DBusConnection *connection, + const char *name, + GDBusWatchFunction func, + void *user_data, GDBusDestroyFunction destroy) { int first; @@ -289,44 +291,7 @@ guint name_listener_add(DBusConnection *connection, const char *name, return listener_id; } -int name_listener_remove(DBusConnection *connection, const char *name, - name_cb_t func, void *user_data) -{ - struct name_data *data; - struct name_callback *cb; - - data = name_data_find(connection, name); - if (!data) { - error("remove_name_listener: no listener for %s", name); - return -1; - } - - cb = name_callback_find(data->callbacks, func, user_data); - if (!cb) { - error("No matching callback found for %s", name); - return -1; - } - - data->callbacks = g_slist_remove(data->callbacks, cb); - g_free(cb); - - /* Don't remove the filter if other callbacks exist */ - if (data->callbacks) - return 0; - - if (name) { - debug("name_listener_remove(%s)", name); - - if (!remove_match(connection, name)) - return -1; - } - - name_data_remove(connection, name, func, user_data); - - return 0; -} - -gboolean name_listener_id_remove(guint id) +gboolean g_dbus_remove_watch(DBusConnection *connection, guint id) { struct name_data *data; struct name_callback *cb; @@ -362,19 +327,17 @@ remove: return TRUE; } -int name_listener_indicate_disconnect(DBusConnection *connection) +void g_dbus_remove_all_watches(DBusConnection *connection) { struct name_data *data; data = name_data_find(connection, NULL); if (!data) { error("name_listener_indicate_disconnect: no listener found"); - return -1; + return; } debug("name_listener_indicate_disconnect"); name_data_call_and_free(data); - - return 0; } diff --git a/hcid/adapter.c b/hcid/adapter.c index 81e9ac4c..3c731745 100644 --- a/hcid/adapter.c +++ b/hcid/adapter.c @@ -725,10 +725,10 @@ static void confirm_mode_cb(struct agent *agent, DBusError *err, void *data) return; cleanup: - dbus_connection_unref(req->conn); dbus_message_unref(req->msg); if (req->id) - name_listener_id_remove(req->id); + g_dbus_remove_watch(req->conn, req->id); + dbus_connection_unref(req->conn); g_free(req); } @@ -2576,15 +2576,15 @@ failed: remove_pending_device(adapter); cleanup: - name_listener_id_remove(adapter->bonding->listener_id); - + g_dbus_remove_watch(adapter->bonding->conn, + adapter->bonding->listener_id); bonding_request_free(adapter->bonding); adapter->bonding = NULL; return FALSE; } -static void create_bond_req_exit(const char *name, void *user_data) +static void create_bond_req_exit(void *user_data) { struct adapter *adapter = user_data; char path[MAX_PATH_LENGTH]; @@ -2592,8 +2592,7 @@ static void create_bond_req_exit(const char *name, void *user_data) snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, adapter->dev_id); - debug("CreateConnection requestor (%s) exited before bonding was completed", - name); + debug("CreateConnection requestor exited before bonding was completed"); cancel_passkey_agent_requests(adapter->passkey_agents, path, &adapter->bonding->bdaddr); @@ -2680,9 +2679,10 @@ static DBusHandlerResult create_bonding(DBusConnection *conn, DBusMessage *msg, (GIOFunc) create_bonding_conn_complete, adapter); - bonding->listener_id = name_listener_add(conn, - dbus_message_get_sender(msg), - create_bond_req_exit, adapter); + bonding->listener_id = g_dbus_add_disconnect_watch(conn, + dbus_message_get_sender(msg), + create_bond_req_exit, adapter, + NULL); adapter->bonding = bonding; @@ -2940,11 +2940,11 @@ static DBusHandlerResult adapter_get_encryption_key_size(DBusConnection *conn, return send_message_and_unref(conn, reply); } -static void periodic_discover_req_exit(const char *name, void *user_data) +static void periodic_discover_req_exit(void *user_data) { struct adapter *adapter = user_data; - debug("PeriodicDiscovery requestor (%s) exited", name); + debug("PeriodicDiscovery requestor exited"); /* Cleanup the discovered devices list and send the cmd to exit from * periodic inquiry or cancel remote name request. The return value can @@ -3027,10 +3027,10 @@ static DBusHandlerResult adapter_start_periodic(DBusConnection *conn, /* track the request owner to cancel it automatically if the owner * exits */ - adapter->pdiscov_listener = name_listener_add(conn, + adapter->pdiscov_listener = g_dbus_add_disconnect_watch(conn, dbus_message_get_sender(msg), periodic_discover_req_exit, - adapter); + adapter, NULL); return send_message_and_unref(conn, reply); } @@ -3141,11 +3141,11 @@ static DBusHandlerResult adapter_get_pdiscov_resolve(DBusConnection *conn, return send_message_and_unref(conn, reply); } -static void discover_devices_req_exit(const char *name, void *user_data) +static void discover_devices_req_exit(void *user_data) { struct adapter *adapter = user_data; - debug("DiscoverDevices requestor (%s) exited", name); + debug("DiscoverDevices requestor exited"); /* Cleanup the discovered devices list and send the command to cancel * inquiry or cancel remote name request. The return can be ignored. */ @@ -3225,10 +3225,10 @@ static DBusHandlerResult adapter_discover_devices(DBusConnection *conn, /* track the request owner to cancel it automatically if the owner * exits */ - adapter->discov_listener = name_listener_add(conn, + adapter->discov_listener = g_dbus_add_disconnect_watch(conn, dbus_message_get_sender(msg), discover_devices_req_exit, - adapter); + adapter, NULL); return send_message_and_unref(conn, reply); } @@ -3718,7 +3718,7 @@ static DBusHandlerResult set_property(DBusConnection *conn, return error_invalid_arguments(conn, msg, NULL); } -static void session_exit(const char *name, void *data) +static void session_exit(void *data) { struct mode_req *req = data; struct adapter *adapter = req->adapter; @@ -3766,8 +3766,9 @@ static DBusHandlerResult request_mode(DBusConnection *conn, req->conn = dbus_connection_ref(conn); req->msg = dbus_message_ref(msg); req->mode = new_mode; - req->id = name_listener_add(conn, dbus_message_get_sender(msg), - session_exit, req); + req->id = g_dbus_add_disconnect_watch(conn, + dbus_message_get_sender(msg), + session_exit, req, NULL); if (!adapter->sessions) adapter->global_mode = adapter->mode; @@ -3785,9 +3786,9 @@ static DBusHandlerResult request_mode(DBusConnection *conn, ret = agent_confirm_mode_change(adapter->agent, mode, confirm_mode_cb, req); if (ret < 0) { - dbus_connection_unref(req->conn); dbus_message_unref(req->msg); - name_listener_id_remove(req->id); + g_dbus_remove_watch(req->conn, req->id); + dbus_connection_unref(req->conn); g_free(req); return error_invalid_arguments(conn, msg, NULL); } @@ -3807,7 +3808,7 @@ static DBusHandlerResult release_mode(DBusConnection *conn, if (!l) return error_failed(conn, msg, "No Mode to release"); - session_exit(dbus_message_get_sender(msg), l->data); + session_exit(l->data); reply = dbus_message_new_method_return(msg); if (!reply) diff --git a/hcid/agent.c b/hcid/agent.c index 831f68b2..b2fbe03c 100644 --- a/hcid/agent.c +++ b/hcid/agent.c @@ -126,11 +126,11 @@ static void agent_request_free(struct agent_request *req) g_free(req); } -static void agent_exited(const char *name, void *user_data) +static void agent_exited(void *user_data) { struct agent *agent = user_data; - debug("Agent %s exited without calling Unregister", name); + debug("Agent exited without calling Unregister"); agent_destroy(agent, TRUE); } @@ -172,7 +172,7 @@ static void agent_free(struct agent *agent) g_source_remove(agent->timeout); if (!agent->exited) { - name_listener_id_remove(agent->listener_id); + g_dbus_remove_watch(connection, agent->listener_id); agent_release(agent); } @@ -217,8 +217,9 @@ struct agent *agent_create(struct adapter *adapter, const char *name, (GSourceFunc) agent_timeout, agent); } - agent->listener_id = name_listener_add(connection, name, agent_exited, - agent); + agent->listener_id = g_dbus_add_disconnect_watch(connection, name, + agent_exited, agent, + NULL); return agent; } diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index cf2369b1..41702d9b 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -74,7 +74,7 @@ static struct record_data *find_record(uint32_t handle, const char *sender) return NULL; } -static void exit_callback(const char *name, void *user_data) +static void exit_callback(void *user_data) { struct record_data *user_record = user_data; @@ -134,9 +134,10 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, records = g_slist_append(records, user_record); - user_record->listener_id = name_listener_add(conn, sender, - exit_callback, - user_record); + user_record->listener_id = g_dbus_add_disconnect_watch(conn, sender, + exit_callback, + user_record, + NULL); reply = dbus_message_new_method_return(msg); if (!reply) @@ -174,7 +175,8 @@ int add_xml_record(DBusConnection *conn, const char *sender, bdaddr_t *src, records = g_slist_append(records, user_record); - name_listener_add(conn, sender, exit_callback, user_record); + g_dbus_add_disconnect_watch(conn, sender, exit_callback, user_record, + NULL); *handle = user_record->handle; @@ -317,7 +319,7 @@ int remove_record(DBusConnection *conn, const char *sender, if (!user_record) return -1; - name_listener_id_remove(user_record->listener_id); + g_dbus_remove_watch(conn, user_record->listener_id); records = g_slist_remove(records, user_record); diff --git a/hcid/dbus-hci.c b/hcid/dbus-hci.c index c8d01f7f..fec4d3bb 100644 --- a/hcid/dbus-hci.c +++ b/hcid/dbus-hci.c @@ -334,7 +334,8 @@ static void reply_pending_requests(const char *path, struct adapter *adapter) remove_pending_device(adapter); - name_listener_id_remove(adapter->bonding->listener_id); + g_dbus_remove_watch(adapter->bonding->conn, + adapter->bonding->listener_id); if (adapter->bonding->io_id) g_source_remove(adapter->bonding->io_id); @@ -416,14 +417,14 @@ int unregister_adapter_path(const char *path) } if (adapter->discov_requestor) { - name_listener_id_remove(adapter->discov_listener); + g_dbus_remove_watch(connection, adapter->discov_listener); adapter->discov_listener = 0; g_free(adapter->discov_requestor); adapter->discov_requestor = NULL; } if (adapter->pdiscov_requestor) { - name_listener_id_remove(adapter->pdiscov_listener); + g_dbus_remove_watch(connection, adapter->pdiscov_listener); adapter->pdiscov_listener = 0; g_free(adapter->pdiscov_requestor); adapter->pdiscov_requestor = NULL; @@ -830,14 +831,14 @@ int hcid_dbus_stop_device(uint16_t id) release_passkey_agents(adapter, NULL); if (adapter->discov_requestor) { - name_listener_id_remove(adapter->discov_listener); + g_dbus_remove_watch(connection, adapter->discov_listener); adapter->discov_listener = 0; g_free(adapter->discov_requestor); adapter->discov_requestor = NULL; } if (adapter->pdiscov_requestor) { - name_listener_id_remove(adapter->pdiscov_listener); + g_dbus_remove_watch(connection, adapter->pdiscov_listener); adapter->pdiscov_listener = 0; g_free(adapter->pdiscov_requestor); adapter->pdiscov_requestor = NULL; @@ -1136,7 +1137,7 @@ proceed: } cleanup: - name_listener_id_remove(adapter->bonding->listener_id); + g_dbus_remove_watch(connection, adapter->bonding->listener_id); if (adapter->bonding->io_id) g_source_remove(adapter->bonding->io_id); @@ -1408,7 +1409,7 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local) adapter->found_devices = NULL; if (adapter->discov_requestor) { - name_listener_id_remove(adapter->discov_listener); + g_dbus_remove_watch(connection, adapter->discov_listener); adapter->discov_listener = 0; g_free(adapter->discov_requestor); adapter->discov_requestor = NULL; @@ -1516,7 +1517,7 @@ void hcid_dbus_periodic_inquiry_exit(bdaddr_t *local, uint8_t status) adapter->oor_devices = NULL; if (adapter->pdiscov_requestor) { - name_listener_id_remove(adapter->pdiscov_listener); + g_dbus_remove_watch(connection, adapter->pdiscov_listener); adapter->pdiscov_listener = 0; g_free(adapter->pdiscov_requestor); adapter->pdiscov_requestor = NULL; @@ -1848,7 +1849,7 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status, /* The discovery completed signal must be sent only for discover * devices request WITH name resolving */ if (adapter->discov_requestor) { - name_listener_id_remove(adapter->discov_listener); + g_dbus_remove_watch(connection, adapter->discov_listener); adapter->discov_listener = 0; g_free(adapter->discov_requestor); adapter->discov_requestor = NULL; @@ -2022,7 +2023,8 @@ void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status, send_message_and_unref(connection, reply); } - name_listener_id_remove(adapter->bonding->listener_id); + g_dbus_remove_watch(adapter->bonding->conn, + adapter->bonding->listener_id); if (adapter->bonding->io_id) g_source_remove(adapter->bonding->io_id); diff --git a/hcid/dbus-security.c b/hcid/dbus-security.c index 11de85c6..b6f15ebc 100644 --- a/hcid/dbus-security.c +++ b/hcid/dbus-security.c @@ -136,26 +136,17 @@ static void passkey_agent_free(struct passkey_agent *agent) g_free(agent); } -static void agent_exited(const char *name, void *user_data) +static void agent_exited(void *user_data) { - struct adapter *adapter = user_data; - GSList *cur, *next; - - debug("Passkey agent %s exited without calling Unregister", name); - - for (cur = adapter->passkey_agents; cur != NULL; cur = next) { - struct passkey_agent *agent = cur->data; - - next = cur->next; + struct passkey_agent *agent = user_data; + struct adapter *adapter = agent->adapter; - if (strcmp(agent->name, name)) - continue; + debug("Passkey agent exited without calling Unregister"); - agent->exited = 1; + agent->exited = 1; - adapter->passkey_agents = g_slist_remove(adapter->passkey_agents, agent); - passkey_agent_free(agent); - } + adapter->passkey_agents = g_slist_remove(adapter->passkey_agents, agent); + passkey_agent_free(agent); } static gboolean agent_timeout(struct passkey_agent *agent) @@ -174,15 +165,10 @@ static gboolean agent_timeout(struct passkey_agent *agent) return FALSE; } -static void default_agent_exited(const char *name, void *data) +static void default_agent_exited(void *data) { - debug("%s exited without unregistering the default passkey agent", name); - - if (!default_agent || strcmp(name, default_agent->name)) { - /* This should never happen (there's a bug in the code if it does) */ - debug("default_agent_exited: mismatch with actual default_agent"); - return; - } + debug("D-Bus client exited without unregistering the" + " default passkey agent"); default_agent->exited = 1; @@ -289,9 +275,11 @@ static DBusHandlerResult register_passkey_agent(DBusConnection *conn, /* Only add a name listener if there isn't one already for this name */ ref.addr = NULL; ref.path = NULL; - if (!g_slist_find_custom(adapter->passkey_agents, &ref, (GCompareFunc) agent_cmp)) - agent->listener_id = name_listener_add(conn, ref.name, - agent_exited, adapter); + if (!g_slist_find_custom(adapter->passkey_agents, &ref, + (GCompareFunc) agent_cmp)) + agent->listener_id = g_dbus_add_disconnect_watch(conn, ref.name, + agent_exited, agent, + NULL); agent->timeout = g_timeout_add(AGENT_TIMEOUT, (GSourceFunc)agent_timeout, agent); @@ -334,7 +322,7 @@ static DBusHandlerResult unregister_passkey_agent(DBusConnection *conn, agent = match->data; - name_listener_id_remove(agent->listener_id); + g_dbus_remove_watch(agent->conn, agent->listener_id); adapter->passkey_agents = g_slist_remove(adapter->passkey_agents, agent); agent->exited = 1; @@ -370,8 +358,8 @@ static DBusHandlerResult register_default_passkey_agent(DBusConnection *conn, if (!reply) goto need_memory; - name_listener_add(conn, default_agent->name, - (name_cb_t) default_agent_exited, NULL); + g_dbus_add_disconnect_watch(conn, default_agent->name, + default_agent_exited, NULL, NULL); info("Default passkey agent (%s, %s) registered", default_agent->name, default_agent->path); @@ -411,7 +399,7 @@ static DBusHandlerResult unregister_default_passkey_agent(DBusConnection *conn, if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - name_listener_id_remove(default_agent->listener_id); + g_dbus_remove_watch(default_agent->conn, default_agent->listener_id); info("Default passkey agent (%s, %s) unregistered", default_agent->name, default_agent->path); @@ -522,17 +510,10 @@ static struct authorization_agent *auth_agent_new(DBusConnection *conn, return agent; } -static void default_auth_agent_exited(const char *name, void *data) +static void default_auth_agent_exited(void *data) { - debug("%s exited without unregistering the " - "default authorization agent", name); - - if (!default_auth_agent || strcmp(name, default_auth_agent->name)) { - /* This should never happen! */ - debug("default_auth_agent_exited: mismatch with " - "actual default_auth_agent"); - return; - } + debug("D-Bus client exited without unregistering the " + "default authorization agent"); auth_agent_cancel_requests(default_auth_agent); auth_agent_free(default_auth_agent); @@ -557,7 +538,7 @@ static void auth_agent_release(struct authorization_agent *agent) send_message_and_unref(agent->conn, message); if (agent == default_auth_agent) - name_listener_id_remove(agent->listener_id); + g_dbus_remove_watch(agent->conn, agent->listener_id); } static DBusHandlerResult register_default_auth_agent(DBusConnection *conn, @@ -584,8 +565,8 @@ static DBusHandlerResult register_default_auth_agent(DBusConnection *conn, if (!reply) goto need_memory; - name_listener_add(conn, default_auth_agent->name, - (name_cb_t) default_auth_agent_exited, NULL); + g_dbus_add_disconnect_watch(conn, default_auth_agent->name, + default_auth_agent_exited, NULL, NULL); info("Default authorization agent (%s, %s) registered", default_auth_agent->name, default_auth_agent->path); @@ -626,7 +607,8 @@ static DBusHandlerResult unregister_default_auth_agent(DBusConnection *conn, if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - name_listener_id_remove(default_auth_agent->listener_id); + g_dbus_remove_watch(default_auth_agent->conn, + default_auth_agent->listener_id); info("Default authorization agent (%s, %s) unregistered", default_auth_agent->name, default_auth_agent->path); @@ -1280,7 +1262,7 @@ static void release_agent(struct passkey_agent *agent) send_message_and_unref(agent->conn, message); if (agent == default_agent) - name_listener_id_remove(agent->listener_id); + g_dbus_remove_watch(agent->conn, agent->listener_id); else { struct passkey_agent ref; @@ -1290,7 +1272,7 @@ static void release_agent(struct passkey_agent *agent) ref.name = agent->name; if (!g_slist_find_custom(agent->adapter->passkey_agents, &ref, (GCompareFunc) agent_cmp)) - name_listener_id_remove(agent->listener_id); + g_dbus_remove_watch(agent->conn, agent->listener_id); } } diff --git a/hcid/dbus-test.c b/hcid/dbus-test.c index 23876c07..87d106a3 100644 --- a/hcid/dbus-test.c +++ b/hcid/dbus-test.c @@ -129,11 +129,11 @@ static void send_audit_status(struct audit *audit, const char *name) DBUS_TYPE_INVALID); } -static void audit_requestor_exited(const char *name, void *user_data) +static void audit_requestor_exited(void *user_data) { struct audit *audit = user_data; - debug("AuditRemoteDevice requestor %s exited", name); + debug("AuditRemoteDevice requestor exited"); audits = g_slist_remove(audits, audit); if (audit->io) { @@ -183,7 +183,7 @@ static gboolean l2raw_input_timer(struct audit *audit) g_io_channel_close(audit->io); audits = g_slist_remove(audits, audit); - name_listener_id_remove(audit->listener_id); + g_dbus_remove_watch(audit->conn, audit->listener_id); audit_free(audit); return FALSE; @@ -327,7 +327,7 @@ failed: g_io_channel_close(io); g_io_channel_unref(io); audits = g_slist_remove(audits, audit); - name_listener_id_remove(audit->listener_id); + g_dbus_remove_watch(audit->conn, audit->listener_id); process_audits_list(audit->adapter_path); @@ -402,7 +402,7 @@ failed: g_io_channel_close(io); g_io_channel_unref(io); audits = g_slist_remove(audits, audit); - name_listener_id_remove(audit->listener_id); + g_dbus_remove_watch(audit->conn, audit->listener_id); audit_free(audit); return FALSE; @@ -483,9 +483,10 @@ static DBusHandlerResult audit_remote_device(DBusConnection *conn, (GIOFunc) l2raw_connect_complete, audit); } - audit->listener_id = name_listener_add(conn, + audit->listener_id = g_dbus_add_disconnect_watch(conn, dbus_message_get_sender(msg), - audit_requestor_exited, audit); + audit_requestor_exited, audit, + NULL); audits = g_slist_append(audits, audit); @@ -541,7 +542,7 @@ static DBusHandlerResult cancel_audit_remote_device(DBusConnection *conn, g_source_remove(audit->timeout); audits = g_slist_remove(audits, audit); - name_listener_id_remove(audit->listener_id); + g_dbus_remove_watch(audit->conn, audit->listener_id); audit_free(audit); reply = dbus_message_new_method_return(msg); @@ -684,7 +685,7 @@ void process_audits_list(const char *adapter_path) if (!adapter) { audits = g_slist_remove(audits, audit); - name_listener_id_remove(audit->listener_id); + g_dbus_remove_watch(audit->conn, audit->listener_id); audit_free(audit); continue; } @@ -697,7 +698,7 @@ void process_audits_list(const char *adapter_path) if (sk < 0) { send_audit_status(audit, "AuditRemoteDeviceFailed"); audits = g_slist_remove(audits, audit); - name_listener_id_remove(audit->listener_id); + g_dbus_remove_watch(audit->conn, audit->listener_id); audit_free(audit); continue; } diff --git a/serial/manager.c b/serial/manager.c index 095abf6b..3d5b6e88 100644 --- a/serial/manager.c +++ b/serial/manager.c @@ -79,6 +79,7 @@ struct pending_connect { int id; /* RFCOMM device id */ int ntries; /* Open attempts */ int canceled; /* Operation canceled */ + guint listener_id; }; /* FIXME: Common file required */ @@ -189,35 +190,23 @@ static struct pending_connect *find_pending_connect_by_pattern(const char *bda, return NULL; } -static void transaction_owner_exited(const char *name, void *data) +static void transaction_owner_exited(void *data) { - GSList *l, *tmp = NULL; - debug("transaction owner %s exited", name); + struct pending_connect *pc = data; - /* Remove all pending calls that belongs to this owner */ - for (l = pending_connects; l != NULL; l = l->next) { - struct pending_connect *pc = l->data; - if (strcmp(name, dbus_message_get_sender(pc->msg)) != 0) { - tmp = g_slist_append(tmp, pc); - continue; - } + debug("transaction owner exited"); - if (pc->id >= 0) - rfcomm_release(pc->id); + if (pc->id >= 0) + rfcomm_release(pc->id); - pending_connect_free(pc); - } + pending_connects = g_slist_remove(pending_connects, pc); - g_slist_free(pending_connects); - pending_connects = tmp; + pending_connect_free(pc); } static void pending_connect_remove(struct pending_connect *pc) { - /* Remove the connection request owner */ - name_listener_remove(pc->conn, dbus_message_get_sender(pc->msg), - (name_cb_t) transaction_owner_exited, NULL); - + g_dbus_remove_watch(pc->conn, pc->listener_id); pending_connects = g_slist_remove(pending_connects, pc); pending_connect_free(pc); } @@ -463,8 +452,10 @@ static DBusHandlerResult connect_pending(DBusConnection *conn, DBusMessage *msg, if (!g_slist_find(pending_connects, pc)) { pending_connects = g_slist_append(pending_connects, pc); - name_listener_add(conn, dbus_message_get_sender(msg), - (name_cb_t) transaction_owner_exited, NULL); + pc->listener_id = g_dbus_add_disconnect_watch(conn, + dbus_message_get_sender(msg), + transaction_owner_exited, pc, + NULL); } str2ba(pc->adapter, &src); @@ -634,8 +625,9 @@ static DBusHandlerResult search_uuid(DBusConnection *conn, DBusMessage *msg, } pending_connects = g_slist_append(pending_connects, pc); - name_listener_add(conn, dbus_message_get_sender(msg), - (name_cb_t) transaction_owner_exited, NULL); + pc->listener_id = g_dbus_add_disconnect_watch(conn, + dbus_message_get_sender(msg), + transaction_owner_exited, pc, NULL); return DBUS_HANDLER_RESULT_HANDLED; } diff --git a/serial/port.c b/serial/port.c index 0e2ad200..bacf093c 100644 --- a/serial/port.c +++ b/serial/port.c @@ -244,12 +244,12 @@ static void rfcomm_node_free(struct rfcomm_node *node) g_free(node); } -static void connection_owner_exited(const char *name, void *user_data) +static void connection_owner_exited(void *user_data) { struct rfcomm_node *node = user_data; - debug("Connect requestor %s exited. Releasing %s node", - name, node->device); + debug("Connect requestor exited. Releasing %s node", + node->device); dbus_connection_emit_signal(node->conn, SERIAL_MANAGER_PATH, SERIAL_MANAGER_INTERFACE, "ServiceDisconnected" , @@ -265,7 +265,7 @@ static gboolean rfcomm_disconnect_cb(GIOChannel *io, { debug("RFCOMM node %s was disconnected", node->device); - name_listener_id_remove(node->listener_id); + g_dbus_remove_watch(node->conn, node->listener_id); dbus_connection_emit_signal(node->conn, SERIAL_MANAGER_PATH, SERIAL_MANAGER_INTERFACE, "ServiceDisconnected" , @@ -299,15 +299,16 @@ void port_add_listener(DBusConnection *conn, int16_t id, bdaddr_t *dst, node->device = g_strdup(dev); node->conn = dbus_connection_ref(conn); node->owner = g_strdup(owner); - node->io = g_io_channel_unix_new(fd); + node->io = g_io_channel_unix_new(fd); node->io_id = g_io_add_watch(node->io, G_IO_ERR | G_IO_NVAL | G_IO_HUP, (GIOFunc) rfcomm_disconnect_cb, node); connected_nodes = g_slist_append(connected_nodes, node); /* Service connection listener */ - node->listener_id = name_listener_add(conn, owner, - connection_owner_exited, node); + node->listener_id = g_dbus_add_disconnect_watch(conn, owner, + connection_owner_exited, node, + NULL); } int port_remove_listener(const char *owner, const char *dev) @@ -320,7 +321,7 @@ int port_remove_listener(const char *owner, const char *dev) if (strcmp(node->owner, owner) != 0) return -EPERM; - name_listener_id_remove(node->listener_id); + g_dbus_remove_watch(node->conn, node->listener_id); connected_nodes = g_slist_remove(connected_nodes, node); rfcomm_node_free(node); |