summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@openbossa.org>2008-09-04 12:18:28 -0300
committerClaudio Takahasi <claudio.takahasi@openbossa.org>2008-09-04 12:18:28 -0300
commitddb4d5c0e46f6fd606e1d4123447c4a8ce747b3d (patch)
tree2b9fdbb8e29864030d1eafb9ac38e2ca020a36d3
parent9304400a8efe5b59c4bcd88fda9083b4a5cf7b93 (diff)
Input: Converting hid server to adapter driver structure
-rw-r--r--input/manager.c41
-rw-r--r--input/server.c53
-rw-r--r--input/server.h4
3 files changed, 79 insertions, 19 deletions
diff --git a/input/manager.c b/input/manager.c
index dfd2da3a..a2a22762 100644
--- a/input/manager.c
+++ b/input/manager.c
@@ -171,7 +171,7 @@ static void input_remove(struct btd_device *device, const char *uuid)
input_device_unregister(path, uuid);
}
-static int hid_probe(struct btd_device *device, GSList *records)
+static int hid_device_probe(struct btd_device *device, GSList *records)
{
struct btd_adapter *adapter = device_get_adapter(device);
const gchar *path = device_get_path(device);
@@ -206,7 +206,7 @@ done:
HID_UUID, hidp.idle_to);
}
-static void hid_remove(struct btd_device *device)
+static void hid_device_remove(struct btd_device *device)
{
input_remove(device, HID_UUID);
}
@@ -252,11 +252,33 @@ static void headset_remove(struct btd_device *device)
input_remove(device, HSP_HS_UUID);
}
+static int hid_server_probe(struct btd_adapter *adapter)
+{
+ const char *addr;
+ bdaddr_t src;
+
+ addr = adapter_get_address(adapter);
+ str2ba(addr, &src);
+
+ return server_start(&src);
+}
+
+static void hid_server_remove(struct btd_adapter *adapter)
+{
+ const char *addr;
+ bdaddr_t src;
+
+ addr = adapter_get_address(adapter);
+ str2ba(addr, &src);
+
+ server_stop(&src);
+}
+
static struct btd_device_driver input_hid_driver = {
.name = "input-hid",
.uuids = BTD_UUIDS(HID_UUID),
- .probe = hid_probe,
- .remove = hid_remove,
+ .probe = hid_device_probe,
+ .remove = hid_device_remove,
};
static struct btd_device_driver input_headset_driver = {
@@ -266,6 +288,12 @@ static struct btd_device_driver input_headset_driver = {
.remove = headset_remove,
};
+static struct btd_adapter_driver input_server_driver = {
+ .name = "input-server",
+ .probe = hid_server_probe,
+ .remove = hid_server_remove,
+};
+
int input_manager_init(DBusConnection *conn, GKeyFile *config)
{
GError *err = NULL;
@@ -281,7 +309,7 @@ int input_manager_init(DBusConnection *conn, GKeyFile *config)
connection = dbus_connection_ref(conn);
- server_start();
+ btd_register_adapter_driver(&input_server_driver);
btd_register_device_driver(&input_hid_driver);
btd_register_device_driver(&input_headset_driver);
@@ -291,7 +319,8 @@ int input_manager_init(DBusConnection *conn, GKeyFile *config)
void input_manager_exit(void)
{
- server_stop();
+
+ btd_unregister_adapter_driver(&input_server_driver);
btd_unregister_device_driver(&input_hid_driver);
btd_unregister_device_driver(&input_headset_driver);
diff --git a/input/server.c b/input/server.c
index e3411cb5..d097d26a 100644
--- a/input/server.c
+++ b/input/server.c
@@ -44,12 +44,26 @@
#include "glib-helper.h"
static const char *HID_UUID = "00001124-0000-1000-8000-00805f9b34fb";
+static GSList *servers = NULL;
+struct server {
+ bdaddr_t src;
+ GIOChannel *ctrl;
+ GIOChannel *intr;
+};
struct authorization_data {
bdaddr_t src;
bdaddr_t dst;
};
+static gint server_cmp(gconstpointer s, gconstpointer user_data)
+{
+ const struct server *server = s;
+ const bdaddr_t *src = user_data;
+
+ return bacmp(&server->src, src);
+}
+
static void auth_callback(DBusError *derr, void *user_data)
{
struct authorization_data *auth = user_data;
@@ -109,12 +123,12 @@ static void connect_event_cb(GIOChannel *chan, int err, const bdaddr_t *src,
return;
}
-static GIOChannel *ctrl_io = NULL;
-static GIOChannel *intr_io = NULL;
-
-int server_start(void)
+int server_start(bdaddr_t *src)
{
- ctrl_io = bt_l2cap_listen(BDADDR_ANY, L2CAP_PSM_HIDP_CTRL, 0, 0,
+ struct server *server;
+ GIOChannel *ctrl_io, *intr_io;
+
+ ctrl_io = bt_l2cap_listen(src, L2CAP_PSM_HIDP_CTRL, 0, 0,
connect_event_cb,
GUINT_TO_POINTER(L2CAP_PSM_HIDP_CTRL));
if (!ctrl_io) {
@@ -123,24 +137,41 @@ int server_start(void)
}
g_io_channel_set_close_on_unref(ctrl_io, TRUE);
- intr_io = bt_l2cap_listen(BDADDR_ANY, L2CAP_PSM_HIDP_INTR, 0, 0,
+ intr_io = bt_l2cap_listen(src, L2CAP_PSM_HIDP_INTR, 0, 0,
connect_event_cb,
GUINT_TO_POINTER(L2CAP_PSM_HIDP_INTR));
if (!intr_io) {
error("Failed to listen on interrupt channel");
g_io_channel_unref(ctrl_io);
ctrl_io = NULL;
+ return -1;
}
g_io_channel_set_close_on_unref(intr_io, TRUE);
+ server = g_new0(struct server, 1);
+ bacpy(&server->src, src);
+ server->ctrl = ctrl_io;
+ server->intr = intr_io;
+
+ servers = g_slist_append(servers, server);
+
return 0;
}
-void server_stop(void)
+void server_stop(bdaddr_t *src)
{
- if (intr_io)
- g_io_channel_unref(intr_io);
+ struct server *server;
+ GSList *l;
- if (ctrl_io)
- g_io_channel_unref(ctrl_io);
+ l = g_slist_find_custom(servers, src, server_cmp);
+ if (!l)
+ return;
+
+ server = l->data;
+
+ g_io_channel_unref(server->intr);
+ g_io_channel_unref(server->ctrl);
+
+ servers = g_slist_remove(servers, server);
+ g_free(server);
}
diff --git a/input/server.h b/input/server.h
index 75cf704c..33a681c4 100644
--- a/input/server.h
+++ b/input/server.h
@@ -21,5 +21,5 @@
*
*/
-int server_start(void);
-void server_stop(void);
+int server_start(bdaddr_t *src);
+void server_stop(bdaddr_t *src);