summaryrefslogtreecommitdiffstats
path: root/input
diff options
context:
space:
mode:
Diffstat (limited to 'input')
-rw-r--r--input/device.c74
-rw-r--r--input/device.h4
-rw-r--r--input/error.h2
-rw-r--r--input/manager.c6
4 files changed, 40 insertions, 46 deletions
diff --git a/input/device.c b/input/device.c
index 7e7325fb..5f70ede1 100644
--- a/input/device.c
+++ b/input/device.c
@@ -34,9 +34,9 @@
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
+#include <bluetooth/hidp.h>
#include <bluetooth/l2cap.h>
#include <bluetooth/rfcomm.h>
-#include <bluetooth/hidp.h>
#include <glib.h>
@@ -47,10 +47,10 @@
#include "textfile.h"
#include "uinput.h"
-#include "storage.h"
+#include "device.h"
#include "error.h"
#include "manager.h"
-#include "device.h"
+#include "storage.h"
#define INPUT_DEVICE_INTERFACE "org.bluez.input.Device"
@@ -1003,21 +1003,11 @@ static const DBusObjectPathVTable device_table = {
/*
* Input registration functions
*/
-int input_device_register(DBusConnection *conn, bdaddr_t *src, bdaddr_t *dst,
- struct hidp_connadd_req *hid, const char **path)
+static int register_path(DBusConnection *conn, const char *path, struct input_device *idev)
{
DBusMessage *msg;
- struct input_device *idev;
-
- idev = input_device_new(src, dst);
- *path = create_input_path(idev->major, idev->minor);
-
- memcpy(&idev->hidp, hid, sizeof(struct hidp_connadd_req));
-
- /* FIXME: rd_data is a pointer - hacking */
-
- if (!dbus_connection_register_object_path(conn,
- *path, &device_table, idev)) {
+ if (!dbus_connection_register_object_path(conn, path,
+ &device_table, idev)) {
error("Input device path registration failed");
return -1;
}
@@ -1028,50 +1018,56 @@ int input_device_register(DBusConnection *conn, bdaddr_t *src, bdaddr_t *dst,
return -1;
dbus_message_append_args(msg,
- DBUS_TYPE_STRING, &*path,
+ DBUS_TYPE_STRING, &path,
DBUS_TYPE_INVALID);
send_message_and_unref(conn, msg);
- info("Created input device: %s", *path);
+ info("Created input device: %s", path);
return 0;
}
-int fake_input_register(DBusConnection *conn, bdaddr_t *src,
- bdaddr_t *dst, uint8_t ch, const char **path)
+int input_device_register(DBusConnection *conn, bdaddr_t *src, bdaddr_t *dst,
+ struct hidp_connadd_req *hid, const char **ppath)
{
- DBusMessage *msg;
struct input_device *idev;
+ const char *path;
idev = input_device_new(src, dst);
- *path = create_input_path(idev->major, idev->minor);
+ path = create_input_path(idev->major, idev->minor);
- idev->fake = g_new0(struct fake_input, 1);
- idev->fake->ch = ch;
+ /* rd_data must not be deallocated since the memory address is copied */
+ memcpy(&idev->hidp, hid, sizeof(struct hidp_connadd_req));
- if (!dbus_connection_register_object_path(conn,
- *path, &device_table, idev)) {
- error("Fake input device path registration failed");
+ if (register_path(conn, path, idev) < 0)
return -1;
- }
- /* FIXME: dupplicated code */
- msg = dbus_message_new_signal(INPUT_PATH,
- INPUT_MANAGER_INTERFACE, "DeviceCreated");
- if (!msg)
- return -1;
+ if (*ppath)
+ *ppath = path;
- dbus_message_append_args(msg,
- DBUS_TYPE_STRING, &*path,
- DBUS_TYPE_INVALID);
+ return 0;
+}
- send_message_and_unref(conn, msg);
+int fake_input_register(DBusConnection *conn, bdaddr_t *src,
+ bdaddr_t *dst, uint8_t ch, const char **ppath)
+{
+ struct input_device *idev;
+ const char *path;
- info("Created input device: %s", *path);
+ idev = input_device_new(src, dst);
+ path = create_input_path(idev->major, idev->minor);
- return 0;
+ idev->fake = g_new0(struct fake_input, 1);
+ idev->fake->ch = ch;
+
+ if (register_path(conn, path, idev) < 0)
+ return -1;
+ if (*ppath)
+ *ppath = path;
+
+ return 0;
}
int input_device_unregister(DBusConnection *conn, const char *path)
diff --git a/input/device.h b/input/device.h
index 604d7b79..fa5cec12 100644
--- a/input/device.h
+++ b/input/device.h
@@ -45,7 +45,7 @@ struct input_device {
};
int input_device_register(DBusConnection *conn, bdaddr_t *src, bdaddr_t *dst,
- struct hidp_connadd_req *hidp, const char **path);
+ struct hidp_connadd_req *hidp, const char **ppath);
int fake_input_register(DBusConnection *conn, bdaddr_t *src,
- bdaddr_t *dst, uint8_t ch, const char **path);
+ bdaddr_t *dst, uint8_t ch, const char **ppath);
int input_device_unregister(DBusConnection *conn, const char *path);
diff --git a/input/error.h b/input/error.h
index 9f767d1a..f5f4c757 100644
--- a/input/error.h
+++ b/input/error.h
@@ -40,5 +40,3 @@ DBusHandlerResult err_does_not_exist(DBusConnection *conn,
DBusMessage *msg, const char *str);
DBusHandlerResult err_not_supported(DBusConnection *conn, DBusMessage *msg);
-
-
diff --git a/input/manager.c b/input/manager.c
index 2675b5cb..2ad8948e 100644
--- a/input/manager.c
+++ b/input/manager.c
@@ -30,9 +30,9 @@
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
+#include <bluetooth/hidp.h>
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>
-#include <bluetooth/hidp.h>
#include <glib.h>
@@ -42,10 +42,10 @@
#include "logging.h"
#include "textfile.h"
-#include "error.h"
-#include "storage.h"
#include "device.h"
+#include "error.h"
#include "manager.h"
+#include "storage.h"
const char *pnp_uuid = "00001200-0000-1000-8000-00805f9b34fb";
const char *hid_uuid = "00001124-0000-1000-8000-00805f9b34fb";