diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2007-05-17 19:37:49 +0000 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2007-05-17 19:37:49 +0000 |
commit | 2fbfb83dae49fb9de541869986bc719e06b6cf12 (patch) | |
tree | 0da08cbf09b2f33fcaa91379257743b5c9e8d31b /serial | |
parent | 01cb453b85b7cf26ee9e5f848717d82ce455070a (diff) |
serial: added port GetAddress
Diffstat (limited to 'serial')
-rw-r--r-- | serial/manager.c | 8 | ||||
-rw-r--r-- | serial/port.c | 32 | ||||
-rw-r--r-- | serial/port.h | 7 |
3 files changed, 34 insertions, 13 deletions
diff --git a/serial/manager.c b/serial/manager.c index 9a6972da..c6c35131 100644 --- a/serial/manager.c +++ b/serial/manager.c @@ -193,6 +193,7 @@ static void open_notify(int fd, int err, void *data) const char *owner; DBusMessage *reply; struct pending_connect *pc = data; + bdaddr_t dst; if (err) { /* Max tries exceeded */ @@ -229,7 +230,8 @@ static void open_notify(int fd, int err, void *data) DBUS_TYPE_STRING, &pname, DBUS_TYPE_INVALID); - port_add_listener(pc->conn, pc->id, fd, port_name, owner); + str2ba(pc->bda, &dst); + port_add_listener(pc->conn, pc->id, &dst, fd, port_name, owner); } static gboolean rfcomm_connect_cb(GIOChannel *chan, @@ -446,7 +448,7 @@ static void record_reply(DBusPendingCall *call, void *data) } snprintf(port_name, sizeof(port_name), "/dev/rfcomm%d", err); - port_register(pc->conn, err, port_name, path); + port_register(pc->conn, err, &dst, port_name, path); reply = dbus_message_new_method_return(pc->msg); dbus_message_append_args(reply, @@ -721,7 +723,7 @@ static DBusHandlerResult create_port(DBusConnection *conn, return err_failed(conn, msg, strerror(-err)); snprintf(port_name, sizeof(port_name), "/dev/rfcomm%d", err); - port_register(conn, err, port_name, path); + port_register(conn, err, &dst, port_name, path); reply = dbus_message_new_method_return(msg); if (!reply) diff --git a/serial/port.c b/serial/port.c index 76e00e01..ce339a20 100644 --- a/serial/port.c +++ b/serial/port.c @@ -52,15 +52,16 @@ /* Waiting for udev to create the device node */ #define MAX_OPEN_TRIES 5 -#define OPEN_WAIT 300 /* ms */ +#define OPEN_WAIT 300 /* ms */ struct rfcomm_node { int16_t id; /* RFCOMM device id */ + bdaddr_t dst; /* Destination address */ char *name; /* RFCOMM device name */ - DBusConnection *conn; /* for name listener handling */ + DBusConnection *conn; /* for name listener handling */ char *owner; /* Bus name */ GIOChannel *io; /* Connected node IO Channel */ - guint io_id; /* IO Channel ID */ + guint io_id; /* IO Channel ID */ }; struct open_context { @@ -104,7 +105,21 @@ static DBusHandlerResult port_disconnect(DBusConnection *conn, static DBusHandlerResult port_get_address(DBusConnection *conn, DBusMessage *msg, void *data) { - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + struct rfcomm_node *node = data; + DBusMessage *reply; + char bda[18]; + const char *pbda = bda; + + reply = dbus_message_new_method_return(msg); + if (!reply) + return DBUS_HANDLER_RESULT_NEED_MEMORY; + + ba2str(&node->dst, bda); + dbus_message_append_args(reply, + DBUS_TYPE_STRING, &pbda, + DBUS_TYPE_INVALID); + return send_message_and_unref(conn, reply); + } static DBusMethodVTable port_methods[] = { @@ -181,12 +196,13 @@ static void port_handler_unregister(DBusConnection *conn, void *data) rfcomm_node_free(node); } -int port_add_listener(DBusConnection *conn, int id, int fd, - const char *name, const char *owner) +int port_add_listener(DBusConnection *conn, int id, bdaddr_t *dst, + int fd, const char *name, const char *owner) { struct rfcomm_node *node; node = g_new0(struct rfcomm_node, 1); + bacpy(&node->dst, dst); node->id = id; node->name = g_strdup(name); node->conn = dbus_connection_ref(conn); @@ -221,12 +237,14 @@ int port_remove_listener(const char *owner, const char *name) return 0; } -int port_register(DBusConnection *conn, int id, const char *name, char *ppath) +int port_register(DBusConnection *conn, int id, bdaddr_t *dst, + const char *name, char *ppath) { char path[MAX_PATH_LENGTH]; struct rfcomm_node *node; node = g_new0(struct rfcomm_node, 1); + bacpy(&node->dst, dst); node->id = id; node->name = g_strdup(name); node->conn = dbus_connection_ref(conn); diff --git a/serial/port.h b/serial/port.h index c6a74548..2907647b 100644 --- a/serial/port.h +++ b/serial/port.h @@ -24,12 +24,13 @@ typedef void (*open_notify_t) (int fd, int err, void *data); typedef void (*udata_free_t) (void *data); -int port_add_listener(DBusConnection *conn, int id, int fd, - const char *name, const char *owner); +int port_add_listener(DBusConnection *conn, int id, bdaddr_t *dst, + int fd, const char *name, const char *owner); int port_remove_listener(const char *owner, const char *name); -int port_register(DBusConnection *conn, int id, const char *name, char *ppath); +int port_register(DBusConnection *conn, int id, bdaddr_t *dst, + const char *name, char *ppath); int port_unregister(const char *path); |