aboutsummaryrefslogtreecommitdiffstats
path: root/attrib/client.c
diff options
context:
space:
mode:
authorBruna Moreira <bruna.moreira@openbossa.org>2010-09-29 14:59:23 -0400
committerJohan Hedberg <johan.hedberg@nokia.com>2010-10-04 17:06:48 +0200
commit8edb7f03cfa2b1b562e3cbf54e077df938ec31a3 (patch)
treed7319268d4a818fd122f1338d53a1adde4314c8b /attrib/client.c
parent10840e3c30b29930073cec2dec8c5e13d9cbae86 (diff)
downloadbluez-8edb7f03cfa2b1b562e3cbf54e077df938ec31a3.tar.gz
bluez-8edb7f03cfa2b1b562e3cbf54e077df938ec31a3.tar.xz
bluez-8edb7f03cfa2b1b562e3cbf54e077df938ec31a3.zip
Move connection common code to l2cap_connect()
Common code for connection operations were moved to l2cap_connect() function. This way, register_watchers() and set_value() can use it.
Diffstat (limited to 'attrib/client.c')
-rw-r--r--attrib/client.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/attrib/client.c b/attrib/client.c
index 5c02f40b..e699e758 100644
--- a/attrib/client.c
+++ b/attrib/client.c
@@ -426,24 +426,14 @@ static DBusMessage *get_characteristics(DBusConnection *conn,
return reply;
}
-static DBusMessage *register_watcher(DBusConnection *conn,
- DBusMessage *msg, void *data)
+static int l2cap_connect(struct gatt_service *gatt, GError **gerr,
+ gboolean listen)
{
- const char *sender = dbus_message_get_sender(msg);
- struct primary *prim = data;
- struct gatt_service *gatt = prim->gatt;
- struct watcher *watcher;
- GError *gerr = NULL;
GIOChannel *io;
- char *path;
-
- if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
- DBUS_TYPE_INVALID))
- return invalid_args(msg);
if (gatt->attrib != NULL) {
gatt->attrib = g_attrib_ref(gatt->attrib);
- goto done;
+ return 0;
}
/*
@@ -451,30 +441,48 @@ static DBusMessage *register_watcher(DBusConnection *conn,
* Configuration it is necessary to poll the server from time
* to time checking for modifications.
*/
- io = bt_io_connect(BT_IO_L2CAP, connect_cb, gatt, NULL, &gerr,
+ io = bt_io_connect(BT_IO_L2CAP, connect_cb, gatt, NULL, gerr,
BT_IO_OPT_SOURCE_BDADDR, &gatt->sba,
BT_IO_OPT_DEST_BDADDR, &gatt->dba,
BT_IO_OPT_PSM, gatt->psm,
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
BT_IO_OPT_INVALID);
- if (!io) {
- DBusMessage *reply;
- reply = g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
- "%s", gerr->message);
- g_error_free(gerr);
-
- return reply;
- }
+ if (!io)
+ return -1;
gatt->attrib = g_attrib_new(io);
g_io_channel_unref(io);
- gatt->listen = TRUE;
+ gatt->listen = listen;
g_attrib_set_destroy_function(gatt->attrib, attrib_destroy, gatt);
g_attrib_set_disconnect_function(gatt->attrib, attrib_disconnect,
gatt);
-done:
+ return 0;
+}
+
+static DBusMessage *register_watcher(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ const char *sender = dbus_message_get_sender(msg);
+ struct primary *prim = data;
+ struct watcher *watcher;
+ GError *gerr = NULL;
+ char *path;
+
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+ DBUS_TYPE_INVALID))
+ return invalid_args(msg);
+
+ if (l2cap_connect(prim->gatt, &gerr, TRUE) < 0) {
+ DBusMessage *reply;
+ reply = g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
+ "%s", gerr->message);
+ g_error_free(gerr);
+
+ return reply;
+ }
+
watcher = g_new0(struct watcher, 1);
watcher->name = g_strdup(sender);
watcher->prim = prim;