diff options
Diffstat (limited to 'serial/port.c')
-rw-r--r-- | serial/port.c | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/serial/port.c b/serial/port.c index a433e319..44879ecc 100644 --- a/serial/port.c +++ b/serial/port.c @@ -88,25 +88,32 @@ static struct rfcomm_node *find_node_by_name(GSList *nodes, const char *name) return NULL; } -static DBusHandlerResult port_connect(DBusConnection *conn, +static DBusHandlerResult port_get_address(DBusConnection *conn, DBusMessage *msg, void *data) { - /* FIXME: call port_open() */ + struct rfcomm_node *node = data; + DBusMessage *reply; + char bda[18]; + const char *pbda = bda; - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; -} + 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 DBusHandlerResult port_disconnect(DBusConnection *conn, - DBusMessage *msg, void *data) -{ - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } -static DBusHandlerResult port_get_address(DBusConnection *conn, +static DBusHandlerResult port_get_info(DBusConnection *conn, DBusMessage *msg, void *data) { struct rfcomm_node *node = data; DBusMessage *reply; + DBusMessageIter iter, dict; char bda[18]; const char *pbda = bda; @@ -114,18 +121,31 @@ static DBusHandlerResult port_get_address(DBusConnection *conn, if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; + dbus_message_iter_init_append(reply, &iter); + + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING + DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict); + + dbus_message_iter_append_dict_entry(&dict, "name", + DBUS_TYPE_STRING, &node->name); + ba2str(&node->dst, bda); - dbus_message_append_args(reply, - DBUS_TYPE_STRING, &pbda, - DBUS_TYPE_INVALID); - return send_message_and_unref(conn, reply); + dbus_message_iter_append_dict_entry(&dict, "address", + DBUS_TYPE_STRING, &pbda); + dbus_message_iter_append_dict_entry(&dict, "dev_id", + DBUS_TYPE_INT16, &node->id); + + dbus_message_iter_close_container(&iter, &dict); + + return send_message_and_unref(conn, reply); } static DBusMethodVTable port_methods[] = { - { "Connect", port_connect, "", "" }, - { "Disconnect", port_disconnect, "", "" }, { "GetAddress", port_get_address, "", "s" }, + { "GetInfo", port_get_info, "", "{sv}" }, { NULL, NULL, NULL, NULL }, }; |