summaryrefslogtreecommitdiffstats
path: root/hcid
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2008-05-29 14:43:27 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2008-05-29 14:43:27 +0000
commitcc0f97ec2cb298bde87cd3753fd96f11ce41ff64 (patch)
treee02bb5f68ca60810d2793708939306174f4aa100 /hcid
parent4baf1de49d3aad2837a968a18a7181d568ff9457 (diff)
Change name_listener API to libgdbus watch API
Diffstat (limited to 'hcid')
-rw-r--r--hcid/adapter.c49
-rw-r--r--hcid/agent.c11
-rw-r--r--hcid/dbus-database.c14
-rw-r--r--hcid/dbus-hci.c22
-rw-r--r--hcid/dbus-security.c76
-rw-r--r--hcid/dbus-test.c21
6 files changed, 91 insertions, 102 deletions
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;
}