summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2009-02-18 19:17:48 -0300
committerJohan Hedberg <johan.hedberg@nokia.com>2009-02-19 10:19:11 +0200
commitb5519a1fede5ea4f480c788789f957d9af80efc6 (patch)
tree66c7d86cc22efa3eea71afd4c6dfea30bc7366c1
parentb075dea3ec7acbd0aae170c21e1c6a857d8250e8 (diff)
downloadbluez-b5519a1fede5ea4f480c788789f957d9af80efc6.tar.gz
Make serial plugin to use BtIO API.
-rw-r--r--serial/port.c48
-rw-r--r--serial/proxy.c35
2 files changed, 56 insertions, 27 deletions
diff --git a/serial/port.c b/serial/port.c
index 32e583428..ddb07b2c5 100644
--- a/serial/port.c
+++ b/serial/port.c
@@ -49,6 +49,7 @@
#include "logging.h"
#include "glib-helper.h"
+#include "btio.h"
#include "error.h"
#include "manager.h"
@@ -291,22 +292,22 @@ static int port_open(struct serial_port *port)
return fd;
}
-static void rfcomm_connect_cb(GIOChannel *chan, int err_cb, const bdaddr_t *src,
- const bdaddr_t *dst, gpointer user_data)
+static void rfcomm_connect_cb(GIOChannel *chan, GError *conn_err,
+ gpointer user_data)
{
struct serial_port *port = user_data;
struct serial_device *device = port->device;
struct rfcomm_dev_req req;
- int sk, err, fd;
+ int sk, fd;
DBusMessage *reply;
/* Owner exited? */
if (!port->listener_id)
return;
- if (err_cb < 0) {
- error("connect(): %s (%d)", strerror(-err_cb), -err_cb);
- reply = failed(port->msg, strerror(-err_cb));
+ if (conn_err) {
+ error("%s", conn_err->message);
+ reply = failed(port->msg, conn_err->message);
goto fail;
}
@@ -319,18 +320,20 @@ static void rfcomm_connect_cb(GIOChannel *chan, int err_cb, const bdaddr_t *src,
sk = g_io_channel_unix_get_fd(chan);
port->id = ioctl(sk, RFCOMMCREATEDEV, &req);
- g_io_channel_close(chan);
- g_io_channel_unref(chan);
if (port->id < 0) {
- err = errno;
+ int err = errno;
error("ioctl(RFCOMMCREATEDEV): %s (%d)", strerror(err), err);
- reply = failed(port->msg, strerror(-err_cb));
+ reply = failed(port->msg, strerror(err));
+ g_io_channel_close(chan);
goto fail;
}
+
port->dev = g_strdup_printf("/dev/rfcomm%d", port->id);
debug("Serial port %s created", port->dev);
+ g_io_channel_close(chan);
+
/* Addressing connect port */
fd = port_open(port);
if (fd < 0)
@@ -352,7 +355,8 @@ static DBusMessage *port_connect(DBusConnection *conn,
struct serial_device *device = user_data;
struct serial_port *port;
const char *uuid;
- int err;
+ GIOChannel *io;
+ GError *err = NULL;
if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &uuid,
DBUS_TYPE_INVALID) == FALSE)
@@ -371,15 +375,25 @@ static DBusMessage *port_connect(DBusConnection *conn,
NULL);
port->msg = dbus_message_ref(msg);
- err = bt_rfcomm_connect(&device->src, &device->dst, port->channel,
- rfcomm_connect_cb, port);
- if (err < 0) {
- error("RFCOMM connect failed: %s(%d)", strerror(-err), -err);
+ io = bt_io_connect(BT_IO_RFCOMM, rfcomm_connect_cb, port,
+ NULL, &err,
+ BT_IO_OPT_SOURCE_BDADDR, &device->src,
+ BT_IO_OPT_DEST_BDADDR, &device->dst,
+ BT_IO_OPT_CHANNEL, port->channel,
+ BT_IO_OPT_INVALID);
+ if (!io) {
+ DBusMessage *reply;
+
+ error("%s", err->message);
g_dbus_remove_watch(conn, port->listener_id);
port->listener_id = 0;
- return failed(msg, strerror(-err));
+ reply = failed(msg, err->message);
+ g_error_free(err);
+ return reply;
}
+ g_io_channel_unref(io);
+
return NULL;
}
@@ -450,7 +464,7 @@ static struct serial_device *create_serial_device(DBusConnection *conn,
}
int port_register(DBusConnection *conn, const char *path, bdaddr_t *src,
- bdaddr_t *dst, const char *uuid, uint8_t channel)
+ bdaddr_t *dst, const char *uuid, uint8_t channel)
{
struct serial_device *device;
struct serial_port *port;
diff --git a/serial/proxy.c b/serial/proxy.c
index 76f2e1d2a..aab2e87d7 100644
--- a/serial/proxy.c
+++ b/serial/proxy.c
@@ -60,6 +60,7 @@
#include "storage.h"
#include "sdpd.h"
#include "glib-helper.h"
+#include "btio.h"
#include "proxy.h"
#define SERIAL_PORT_NAME "spp"
@@ -382,19 +383,26 @@ static inline int tty_open(const char *tty, struct termios *ti)
return sk;
}
-static void connect_event_cb(GIOChannel *chan, int err, const bdaddr_t *src,
- const bdaddr_t *dst, gpointer data)
+static void connect_event_cb(GIOChannel *chan, GError *conn_err, gpointer data)
{
struct serial_proxy *prx = data;
GIOChannel *io;
int sk;
+ GError *err = NULL;
- if (err < 0) {
- error("accept: %s (%d)", strerror(-err), -err);
+ if (conn_err) {
+ error("%s", conn_err->message);
return;
}
- bacpy(&prx->dst, dst);
+ bt_io_get(chan, BT_IO_RFCOMM, &err,
+ BT_IO_OPT_DEST_BDADDR, &prx->dst,
+ NULL);
+ if (err) {
+ error("%s", err->message);
+ g_error_free(err);
+ return;
+ }
switch (prx->type) {
case UNIX_SOCKET_PROXY:
@@ -439,17 +447,24 @@ static DBusMessage *proxy_enable(DBusConnection *conn,
struct serial_proxy *prx = data;
struct serial_adapter *adapter = prx->adapter;
sdp_record_t *record;
+ GError *err = NULL;
if (prx->io)
return failed(msg, "Already enabled");
/* Listen */
- prx->io = bt_rfcomm_listen_allocate(&adapter->src, &prx->channel, 0,
- connect_event_cb, prx);
+ prx->io = bt_io_listen(BT_IO_RFCOMM, connect_event_cb, NULL, prx,
+ NULL, &err,
+ BT_IO_OPT_SOURCE_BDADDR, &adapter->src,
+ BT_IO_OPT_CHANNEL, prx->channel,
+ BT_IO_OPT_INVALID);
if (!prx->io) {
- const char *strerr = strerror(errno);
- error("RFCOMM listen socket failed: %s(%d)", strerr, errno);
- return failed(msg, strerr);
+ DBusMessage *reply;
+
+ error("%s", err->message);
+ reply = failed(msg, err->message);
+ g_error_free(err);
+ return reply;
}
g_io_channel_set_close_on_unref(prx->io, TRUE);