summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2012-11-14 13:56:53 +0200
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2012-11-14 14:30:14 +0200
commit23d1cf9da12aa93772b0799c554eff97b660f49f (patch)
treeb09cb17ff2cc00377d00044ed5cea7fd505fbe04
parentfc0bcdd01015b918e8167d3a5dcabfb30cc86989 (diff)
downloadobexd-23d1cf9da12aa93772b0799c554eff97b660f49f.tar.gz
tools: Fix using BT_IO_TYPE in test-client and test-server
-rw-r--r--tools/test-client.c81
-rw-r--r--tools/test-server.c44
2 files changed, 61 insertions, 64 deletions
diff --git a/tools/test-client.c b/tools/test-client.c
index 81a2be0..8488a20 100644
--- a/tools/test-client.c
+++ b/tools/test-client.c
@@ -344,69 +344,66 @@ static void conn_callback(GIOChannel *io, GError *err, gpointer user_data)
transport_connect(io, transport);
}
-static GIOChannel *bluetooth_connect(GObexTransportType transport)
+static GIOChannel *l2cap_connect(GObexTransportType transport, GError **err)
{
- GIOChannel *io;
- GError *err = NULL;
- BtIOType type;
- BtIOOption option;
-
- if (option_dest == NULL || option_channel < 0)
- return NULL;
-
- if (option_channel > 31) {
- type = option_packet ? BT_IO_L2CAP : BT_IO_L2ERTM;
- option = BT_IO_OPT_PSM;
- } else {
- type = BT_IO_RFCOMM;
- option = BT_IO_OPT_CHANNEL;
- }
-
- if (option_source) {
- if (type == BT_IO_L2CAP) {
- io = bt_io_connect(type, conn_callback,
+ if (option_source)
+ return bt_io_connect(conn_callback,
GUINT_TO_POINTER(transport),
- NULL, &err,
+ NULL, err,
BT_IO_OPT_SOURCE, option_source,
BT_IO_OPT_DEST, option_dest,
- option, option_channel,
+ BT_IO_OPT_PSM, option_channel,
BT_IO_OPT_MODE, BT_IO_MODE_ERTM,
BT_IO_OPT_OMTU, option_omtu,
BT_IO_OPT_IMTU, option_imtu,
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
BT_IO_OPT_INVALID);
- } else {
- io = bt_io_connect(type, conn_callback,
+
+ return bt_io_connect(conn_callback,
GUINT_TO_POINTER(transport),
- NULL, &err,
- BT_IO_OPT_SOURCE, option_source,
+ NULL, err,
BT_IO_OPT_DEST, option_dest,
- option, option_channel,
+ BT_IO_OPT_PSM, option_channel,
+ BT_IO_OPT_MODE, BT_IO_MODE_ERTM,
+ BT_IO_OPT_OMTU, option_omtu,
+ BT_IO_OPT_IMTU, option_imtu,
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
BT_IO_OPT_INVALID);
- }
- } else {
- if (type == BT_IO_L2CAP) {
- io = bt_io_connect(type, conn_callback,
+}
+
+static GIOChannel *rfcomm_connect(GObexTransportType transport, GError **err)
+{
+ if (option_source)
+ return bt_io_connect(conn_callback,
GUINT_TO_POINTER(transport),
- NULL, &err,
+ NULL, err,
+ BT_IO_OPT_SOURCE, option_source,
BT_IO_OPT_DEST, option_dest,
- option, option_channel,
- BT_IO_OPT_MODE, BT_IO_MODE_ERTM,
- BT_IO_OPT_OMTU, option_omtu,
- BT_IO_OPT_IMTU, option_imtu,
+ BT_IO_OPT_CHANNEL, option_channel,
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
BT_IO_OPT_INVALID);
- } else {
- io = bt_io_connect(type, conn_callback,
+
+ return bt_io_connect(conn_callback,
GUINT_TO_POINTER(transport),
- NULL, &err,
+ NULL, err,
BT_IO_OPT_DEST, option_dest,
- option, option_channel,
+ BT_IO_OPT_CHANNEL, option_channel,
BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_LOW,
BT_IO_OPT_INVALID);
- }
- }
+}
+
+static GIOChannel *bluetooth_connect(GObexTransportType transport)
+{
+ GIOChannel *io;
+ GError *err = NULL;
+
+ if (option_dest == NULL || option_channel < 0)
+ return NULL;
+
+ if (option_channel > 31)
+ io = l2cap_connect(transport, &err);
+ else
+ io = rfcomm_connect(transport, &err);
if (io != NULL)
return io;
diff --git a/tools/test-server.c b/tools/test-server.c
index 3a660f4..e37c56f 100644
--- a/tools/test-server.c
+++ b/tools/test-server.c
@@ -308,40 +308,40 @@ static gboolean bluetooth_watch(GIOChannel *chan, GIOCondition cond, gpointer da
return FALSE;
}
+static GIOChannel *l2cap_listen(GError **err)
+{
+ return bt_io_listen(bluetooth_accept, NULL, NULL,
+ NULL, err,
+ BT_IO_OPT_PSM, option_channel,
+ BT_IO_OPT_MODE, BT_IO_MODE_ERTM,
+ BT_IO_OPT_OMTU, option_omtu,
+ BT_IO_OPT_IMTU, option_imtu,
+ BT_IO_OPT_INVALID);
+}
+
+static GIOChannel *rfcomm_listen(GError **err)
+{
+ return bt_io_listen(bluetooth_accept, NULL, NULL,
+ NULL, err,
+ BT_IO_OPT_CHANNEL, option_channel,
+ BT_IO_OPT_INVALID);
+}
+
static guint bluetooth_listen(void)
{
GIOChannel *io;
guint id;
GError *err = NULL;
- BtIOType type;
- BtIOOption option;
if (option_channel == -1) {
g_printerr("Bluetooth channel not set\n");
return 0;
}
- if (option_packet || option_channel > 31) {
- type = option_packet ? BT_IO_L2CAP : BT_IO_L2ERTM;
- option = BT_IO_OPT_PSM;
- } else {
- type = BT_IO_RFCOMM;
- option = BT_IO_OPT_CHANNEL;
- }
-
- if (type == BT_IO_L2CAP)
- io = bt_io_listen(type, bluetooth_accept, NULL, NULL,
- NULL, &err,
- option, option_channel,
- BT_IO_OPT_MODE, BT_IO_MODE_ERTM,
- BT_IO_OPT_OMTU, option_omtu,
- BT_IO_OPT_IMTU, option_imtu,
- BT_IO_OPT_INVALID);
+ if (option_packet || option_channel > 31)
+ io = l2cap_listen(&err);
else
- io = bt_io_listen(type, bluetooth_accept, NULL, NULL,
- NULL, &err,
- option, option_channel,
- BT_IO_OPT_INVALID);
+ io = rfcomm_listen(&err);
if (io == NULL) {
g_printerr("%s\n", err->message);