summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2007-05-09 14:53:34 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2007-05-09 14:53:34 +0000
commit74416c5f12cc79cd0769220fa68b0f1bcaeb279e (patch)
treef3ca97438217b218a1c90cfe2c0bc952c90c8d3a
parent0ebe9945de9b9e91169619cf1e09a40796aad41b (diff)
Convert to using generic dbus message dispatching
-rw-r--r--input/device.c76
-rw-r--r--input/manager.c72
2 files changed, 61 insertions, 87 deletions
diff --git a/input/device.c b/input/device.c
index edf8c475..4a76b786 100644
--- a/input/device.c
+++ b/input/device.c
@@ -43,6 +43,7 @@
#include <dbus/dbus.h>
#include "dbus.h"
+#include "dbus-helper.h"
#include "logging.h"
#include "textfile.h"
#include "uinput.h"
@@ -922,42 +923,6 @@ static DBusHandlerResult device_get_vendor_id(DBusConnection *conn,
return send_message_and_unref(conn, reply);
}
-static DBusHandlerResult device_message(DBusConnection *conn,
- DBusMessage *msg, void *data)
-{
- const char *iface, *member;
-
- iface = dbus_message_get_interface(msg);
- member = dbus_message_get_member(msg);
-
- /* Accept messages from the input interface only */
- if (strcmp(INPUT_DEVICE_INTERFACE, iface))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- if (strcmp(member, "Connect") == 0)
- return device_connect(conn, msg, data);
-
- if (strcmp(member, "Disconnect") == 0)
- return device_disconnect(conn, msg, data);
-
- if (strcmp(member, "IsConnected") == 0)
- return device_is_connected(conn, msg, data);
-
- if (strcmp(member, "GetAddress") == 0)
- return device_get_address(conn, msg, data);
-
- if (strcmp(member, "GetName") == 0)
- return device_get_name(conn, msg, data);
-
- if (strcmp(member, "GetProductId") == 0)
- return device_get_product_id(conn, msg, data);
-
- if (strcmp(member, "GetVendorId") == 0)
- return device_get_vendor_id(conn, msg, data);
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
static void device_unregister(DBusConnection *conn, void *data)
{
struct device *idev = data;
@@ -967,10 +932,21 @@ static void device_unregister(DBusConnection *conn, void *data)
device_free(idev);
}
-/* Virtual table to handle device object path hierarchy */
-static const DBusObjectPathVTable device_table = {
- .message_function = device_message,
- .unregister_function = device_unregister,
+static DBusMethodVTable device_methods[] = {
+ { "Connect", device_connect, "", "" },
+ { "Disconnect", device_disconnect, "", "" },
+ { "IsConnected", device_is_connected, "", "b" },
+ { "GetAddress", device_get_address, "", "s" },
+ { "GetName", device_get_name, "", "s" },
+ { "GetProductId", device_get_product_id, "", "q" },
+ { "GetVendorId", device_get_vendor_id, "", "q" },
+ { NULL, NULL, NULL, NULL }
+};
+
+static DBusSignalVTable device_signals[] = {
+ { "Connected", "" },
+ { "Disconnected", "" },
+ { NULL, NULL }
};
/*
@@ -980,12 +956,22 @@ static int register_path(DBusConnection *conn, const char *path, struct device *
{
DBusMessage *msg;
- if (!dbus_connection_register_object_path(conn, path,
- &device_table, idev)) {
+ if (!dbus_connection_create_object_path(conn, path,
+ NULL, device_unregister)) {
error("Input device path registration failed");
return -EINVAL;
}
+ if (!dbus_connection_register_interface(conn, path,
+ INPUT_DEVICE_INTERFACE,
+ device_methods,
+ device_signals, NULL)) {
+ error("Failed to register %s interface to %s",
+ INPUT_DEVICE_INTERFACE, path);
+ dbus_connection_destroy_object_path(conn, path);
+ return -1;
+ }
+
msg = dbus_message_new_signal(INPUT_PATH,
INPUT_MANAGER_INTERFACE, "DeviceCreated");
if (!msg)
@@ -1049,7 +1035,7 @@ int input_device_unregister(DBusConnection *conn, const char *path)
DBusMessage *msg;
struct device *idev;
- if (!dbus_connection_get_object_path_data(conn,
+ if (!dbus_connection_get_object_user_data(conn,
path, (void *) &idev) || !idev)
return -EINVAL;
@@ -1060,7 +1046,7 @@ int input_device_unregister(DBusConnection *conn, const char *path)
del_stored_device_info(&idev->src, &idev->dst);
- dbus_connection_unregister_object_path(conn, path);
+ dbus_connection_destroy_object_path(conn, path);
msg = dbus_message_new_signal(INPUT_PATH,
INPUT_MANAGER_INTERFACE, "DeviceRemoved");
@@ -1081,7 +1067,7 @@ int input_device_get_bdaddr(DBusConnection *conn, const char *path,
{
struct device *idev;
- if (!dbus_connection_get_object_path_data(conn, path,
+ if (!dbus_connection_get_object_user_data(conn, path,
(void *) &idev))
return -1;
diff --git a/input/manager.c b/input/manager.c
index 230740e2..bd87c5fb 100644
--- a/input/manager.c
+++ b/input/manager.c
@@ -43,6 +43,7 @@
#include <dbus/dbus.h>
#include "dbus.h"
+#include "dbus-helper.h"
#include "logging.h"
#include "textfile.h"
@@ -922,35 +923,6 @@ static DBusHandlerResult list_devices(DBusConnection *conn,
return send_message_and_unref(conn, reply);
}
-static DBusHandlerResult manager_message(DBusConnection *conn,
- DBusMessage *msg, void *data)
-{
- const char *path, *iface, *member;
-
- path = dbus_message_get_path(msg);
- iface = dbus_message_get_interface(msg);
- member = dbus_message_get_member(msg);
-
- /* Catching fallback paths */
- if (strcmp(INPUT_PATH, path) != 0)
- return err_unknown_device(conn, msg);
-
- /* Accept messages from the input manager interface only */
- if (strcmp(INPUT_MANAGER_INTERFACE, iface))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- if (strcmp(member, "ListDevices") == 0)
- return list_devices(conn, msg, data);
-
- if (strcmp(member, "CreateDevice") == 0)
- return create_device(conn, msg, data);
-
- if (strcmp(member, "RemoveDevice") == 0)
- return remove_device(conn, msg, data);
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
static void manager_unregister(DBusConnection *conn, void *data)
{
info("Unregistered manager path");
@@ -960,12 +932,6 @@ static void manager_unregister(DBusConnection *conn, void *data)
g_slist_free(device_paths);
}
-/* Virtual table to handle manager object path hierarchy */
-static const DBusObjectPathVTable manager_table = {
- .message_function = manager_message,
- .unregister_function = manager_unregister,
-};
-
/*
* Stored inputs registration functions
*/
@@ -1022,19 +988,41 @@ static void register_stored_inputs(void)
closedir(dir);
}
+static DBusMethodVTable manager_methods[] = {
+ { "ListDevices", list_devices, "", "as" },
+ { "CreateDevice", create_device, "s", "s" },
+ { "RemoveDevice", remove_device, "s", "" },
+ { NULL, NULL, NULL, NULL },
+};
+
+static DBusSignalVTable manager_signals[] = {
+ { "DeviceCreated", "s" },
+ { "DeviceRemoved", "s" },
+ { NULL, NULL }
+};
+
int input_init(DBusConnection *conn)
{
- connection = dbus_connection_ref(conn);
-
- dbus_connection_set_exit_on_disconnect(connection, TRUE);
+ dbus_connection_set_exit_on_disconnect(conn, TRUE);
- /* Fallback to catch invalid device path */
- if (!dbus_connection_register_fallback(connection, INPUT_PATH,
- &manager_table, NULL)) {
+ if (!dbus_connection_create_object_path(conn, INPUT_PATH,
+ NULL, manager_unregister)) {
error("D-Bus failed to register %s path", INPUT_PATH);
return -1;
}
+ if (!dbus_connection_register_interface(conn, INPUT_PATH,
+ INPUT_MANAGER_INTERFACE,
+ manager_methods,
+ manager_signals, NULL)) {
+ error("Failed to register %s interface to %s",
+ INPUT_MANAGER_INTERFACE, INPUT_PATH);
+ dbus_connection_destroy_object_path(connection, INPUT_PATH);
+ return -1;
+ }
+
+ connection = dbus_connection_ref(conn);
+
info("Registered input manager path:%s", INPUT_PATH);
/* Register well known HID devices */
@@ -1047,7 +1035,7 @@ int input_init(DBusConnection *conn)
void input_exit(void)
{
- dbus_connection_unregister_object_path(connection, INPUT_PATH);
+ dbus_connection_destroy_object_path(connection, INPUT_PATH);
server_stop();