diff options
author | Johan Hedberg <johan.hedberg@nokia.com> | 2009-04-11 20:41:50 +0300 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2009-04-11 20:41:50 +0300 |
commit | fc4c6f53f10e4aba7c3183ba294618ec489fc683 (patch) | |
tree | 8f20d69cd9b8d9ef4bb76447761f96208363e040 | |
parent | 3174a9545803475c52e0ef547fb390f4f6be6e57 (diff) | |
download | bluez-fc4c6f53f10e4aba7c3183ba294618ec489fc683.tar.gz |
Add GDestroyNotify support to agent callbacks
-rw-r--r-- | src/adapter.c | 5 | ||||
-rw-r--r-- | src/agent.c | 34 | ||||
-rw-r--r-- | src/agent.h | 14 | ||||
-rw-r--r-- | src/device.c | 6 |
4 files changed, 38 insertions, 21 deletions
diff --git a/src/adapter.c b/src/adapter.c index a22026735..214d100ec 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -1394,7 +1394,7 @@ static DBusMessage *request_session(DBusConnection *conn, return dbus_message_new_method_return(msg); ret = agent_confirm_mode_change(adapter->agent, mode2str(new_mode), - confirm_mode_cb, req); + confirm_mode_cb, req, NULL); if (ret < 0) { session_unref(req); return failed_strerror(msg, -ret); @@ -2945,7 +2945,8 @@ static int btd_adapter_authorize(struct btd_adapter *adapter, dev_path = device_get_path(device); - return agent_authorize(agent, dev_path, uuid, agent_auth_cb, auth); + return agent_authorize(agent, dev_path, uuid, agent_auth_cb, auth, + NULL); } int btd_request_authorization(const bdaddr_t *src, const bdaddr_t *dst, diff --git a/src/agent.c b/src/agent.c index a92d500ac..a6d1c0b4b 100644 --- a/src/agent.c +++ b/src/agent.c @@ -77,6 +77,7 @@ struct agent_request { DBusPendingCall *call; void *cb; void *user_data; + GDestroyNotify destroy; }; static DBusConnection *connection = NULL; @@ -127,6 +128,8 @@ static void agent_request_free(struct agent_request *req) dbus_pending_call_unref(req->call); if (req->agent && req->agent->request) req->agent->request = NULL; + if (req->destroy) + req->destroy(req->user_data); g_free(req); } @@ -216,7 +219,8 @@ int agent_destroy(struct agent *agent, gboolean exited) static struct agent_request *agent_request_new(struct agent *agent, agent_request_type_t type, void *cb, - void *user_data) + void *user_data, + GDestroyNotify destroy) { struct agent_request *req; @@ -226,6 +230,7 @@ static struct agent_request *agent_request_new(struct agent *agent, req->type = type; req->cb = cb; req->user_data = user_data; + req->destroy = destroy; return req; } @@ -332,7 +337,8 @@ int agent_authorize(struct agent *agent, const char *path, const char *uuid, agent_cb cb, - void *user_data) + void *user_data, + GDestroyNotify destroy) { struct agent_request *req; int err; @@ -340,7 +346,8 @@ int agent_authorize(struct agent *agent, if (agent->request) return -EBUSY; - req = agent_request_new(agent, AGENT_REQUEST_AUTHORIZE, cb, user_data); + req = agent_request_new(agent, AGENT_REQUEST_AUTHORIZE, cb, + user_data, destroy); err = agent_call_authorize(req, path, uuid); if (err < 0) { @@ -451,7 +458,8 @@ static int pincode_request_new(struct agent_request *req, const char *device_pat } int agent_request_pincode(struct agent *agent, struct btd_device *device, - agent_pincode_cb cb, void *user_data) + agent_pincode_cb cb, void *user_data, + GDestroyNotify destroy) { struct agent_request *req; const gchar *dev_path = device_get_path(device); @@ -460,7 +468,8 @@ int agent_request_pincode(struct agent *agent, struct btd_device *device, if (agent->request) return -EBUSY; - req = agent_request_new(agent, AGENT_REQUEST_PINCODE, cb, user_data); + req = agent_request_new(agent, AGENT_REQUEST_PINCODE, cb, + user_data, destroy); err = pincode_request_new(req, dev_path, FALSE); if (err < 0) @@ -502,7 +511,8 @@ static int confirm_mode_change_request_new(struct agent_request *req, } int agent_confirm_mode_change(struct agent *agent, const char *new_mode, - agent_cb cb, void *user_data) + agent_cb cb, void *user_data, + GDestroyNotify destroy) { struct agent_request *req; int err; @@ -514,7 +524,7 @@ int agent_confirm_mode_change(struct agent *agent, const char *new_mode, agent->name, agent->path, new_mode); req = agent_request_new(agent, AGENT_REQUEST_CONFIRM_MODE, - cb, user_data); + cb, user_data, destroy); err = confirm_mode_change_request_new(req, new_mode); if (err < 0) @@ -605,7 +615,8 @@ static int passkey_request_new(struct agent_request *req, } int agent_request_passkey(struct agent *agent, struct btd_device *device, - agent_passkey_cb cb, void *user_data) + agent_passkey_cb cb, void *user_data, + GDestroyNotify destroy) { struct agent_request *req; const gchar *dev_path = device_get_path(device); @@ -617,7 +628,8 @@ int agent_request_passkey(struct agent *agent, struct btd_device *device, debug("Calling Agent.RequestPasskey: name=%s, path=%s", agent->name, agent->path); - req = agent_request_new(agent, AGENT_REQUEST_PASSKEY, cb, user_data); + req = agent_request_new(agent, AGENT_REQUEST_PASSKEY, cb, + user_data, destroy); err = passkey_request_new(req, dev_path); if (err < 0) @@ -663,7 +675,7 @@ static int confirmation_request_new(struct agent_request *req, int agent_request_confirmation(struct agent *agent, struct btd_device *device, uint32_t passkey, agent_cb cb, - void *user_data) + void *user_data, GDestroyNotify destroy) { struct agent_request *req; const gchar *dev_path = device_get_path(device); @@ -676,7 +688,7 @@ int agent_request_confirmation(struct agent *agent, struct btd_device *device, agent->name, agent->path, passkey); req = agent_request_new(agent, AGENT_REQUEST_CONFIRMATION, cb, - user_data); + user_data, destroy); err = confirmation_request_new(req, dev_path, passkey); if (err < 0) diff --git a/src/agent.h b/src/agent.h index 7b4290b53..314baf995 100644 --- a/src/agent.h +++ b/src/agent.h @@ -42,20 +42,24 @@ struct agent *agent_create(struct btd_adapter *adapter, const char *name, int agent_destroy(struct agent *agent, gboolean exited); int agent_authorize(struct agent *agent, const char *path, - const char *uuid, agent_cb cb, void *user_data); + const char *uuid, agent_cb cb, void *user_data, + GDestroyNotify destroy); int agent_request_pincode(struct agent *agent, struct btd_device *device, - agent_pincode_cb cb, void *user_data); + agent_pincode_cb cb, void *user_data, + GDestroyNotify destroy); int agent_confirm_mode_change(struct agent *agent, const char *new_mode, - agent_cb cb, void *user_data); + agent_cb cb, void *user_data, + GDestroyNotify destroy); int agent_request_passkey(struct agent *agent, struct btd_device *device, - agent_passkey_cb cb, void *user_data); + agent_passkey_cb cb, void *user_data, + GDestroyNotify destroy); int agent_request_confirmation(struct agent *agent, struct btd_device *device, uint32_t passkey, agent_cb cb, - void *user_data); + void *user_data, GDestroyNotify destroy); int agent_display_passkey(struct agent *agent, struct btd_device *device, uint32_t passkey); diff --git a/src/device.c b/src/device.c index ae0f63dbe..47cd3758d 100644 --- a/src/device.c +++ b/src/device.c @@ -1958,15 +1958,15 @@ int device_request_authentication(struct btd_device *device, auth_type_t type, switch (type) { case AUTH_TYPE_PINCODE: ret = agent_request_pincode(agent, device, pincode_cb, - auth); + auth, NULL); break; case AUTH_TYPE_PASSKEY: ret = agent_request_passkey(agent, device, passkey_cb, - auth); + auth, NULL); break; case AUTH_TYPE_CONFIRM: ret = agent_request_confirmation(agent, device, passkey, - confirm_cb, auth); + confirm_cb, auth, NULL); break; case AUTH_TYPE_NOTIFY: ret = agent_display_passkey(agent, device, passkey); |