diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2007-08-10 19:49:57 +0000 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2007-08-10 19:49:57 +0000 |
commit | 71d64082d40bcf1ce620fd3303494667ae1e4771 (patch) | |
tree | d0b5aab7b4309ef7daf005341e2eb3d39fc32254 /serial/manager.c | |
parent | 89d79b500b8559e11af44fe11dc01432eafa9541 (diff) |
serial: added proxy registration function
Diffstat (limited to 'serial/manager.c')
-rw-r--r-- | serial/manager.c | 83 |
1 files changed, 82 insertions, 1 deletions
diff --git a/serial/manager.c b/serial/manager.c index c15d102e..bdad9b32 100644 --- a/serial/manager.c +++ b/serial/manager.c @@ -59,6 +59,7 @@ #include "manager.h" #define BASE_UUID "00000000-0000-1000-8000-00805F9B34FB" +#define SERIAL_PROXY_INTERFACE "org.bluez.serial.Proxy" /* Waiting for udev to create the device node */ #define MAX_OPEN_TRIES 5 @@ -100,11 +101,25 @@ static struct { { NULL } }; +struct proxy { + bdaddr_t src; + bdaddr_t dst; + uuid_t uuid; + char *tty; +}; + static DBusConnection *connection = NULL; static GSList *pending_connects = NULL; static GSList *proxies_paths = NULL; static int rfcomm_ctl = -1; +static void proxy_free(struct proxy *prx) +{ + if (prx->tty) + g_free(prx->tty); + g_free(prx); +} + static void pending_connect_free(struct pending_connect *pc) { if (pc->conn) @@ -895,6 +910,69 @@ static DBusHandlerResult remove_port(DBusConnection *conn, return DBUS_HANDLER_RESULT_HANDLED; } +static DBusHandlerResult proxy_enable(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + +static DBusHandlerResult proxy_disable(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + +static DBusHandlerResult proxy_get_info(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + +static DBusMethodVTable proxy_methods[] = { + { "Enable", proxy_enable, "", "" }, + { "Disable", proxy_disable, "", "" }, + { "GetInfo", proxy_get_info, "", "{sv}" }, + { NULL, NULL, NULL, NULL }, +}; + +static void proxy_handler_unregister(DBusConnection *conn, void *data) +{ + struct proxy *prx = data; + + info("Unregistered proxy: %s", prx->tty); + + /* FIXME: Unregister the service record */ + + proxy_free(prx); +} + +static int proxy_register(DBusConnection *conn, + const char *path, uuid_t *uuid, const char *tty) +{ + struct proxy *prx; + + prx = g_new0(struct proxy, 1); + prx->tty = g_strdup(tty); + memcpy(&prx->uuid, uuid, sizeof(uuid_t)); + bacpy(&prx->src, BDADDR_ANY); + + if (!dbus_connection_create_object_path(conn, path, prx, + proxy_handler_unregister)) { + proxy_free(prx); + return -1; + } + + if (!dbus_connection_register_interface(conn, path, + SERIAL_PROXY_INTERFACE, + proxy_methods, + NULL, NULL)) { + dbus_connection_destroy_object_path(conn, path); + return -1; + } + + return 0; +} + static int str2uuid(uuid_t *uuid, const char *string) { uint16_t data1, data2, data3, data5; @@ -971,7 +1049,10 @@ static DBusHandlerResult create_proxy(DBusConnection *conn, if (!reply) return DBUS_HANDLER_RESULT_NEED_MEMORY; - /* FIXME: Register the proxy object */ + if (proxy_register(conn, path, &uuid, tty) < 0) { + dbus_message_unref(reply); + return err_failed(conn, msg, "Create object path failed"); + } /* FIXME: persistent storage */ proxies_paths = g_slist_append(proxies_paths, g_strdup(path)); |