input: add the input dbus interface 71/285671/1
authorYunhee Seo <yuni.seo@samsung.com>
Tue, 13 Dec 2022 02:41:35 +0000 (11:41 +0900)
committeryunhee seo <yuni.seo@samsung.com>
Fri, 16 Dec 2022 07:56:40 +0000 (07:56 +0000)
Add a getter and setter function of input device event status
With input device id parameter, it is possible to enable/disable input device event

Input device event getter/setter dbus methods
1. Set input event state
    path: /Org/Tizen/System/DeviceD/Input
    interface: org.tizen.system.deviced.input
    member: InputSetEventState
    parameter: "(ii)", input device id to be set event state, value to be set
    return: "(i)", 0 on success, negative on error.
2. Get input event state
    path: /Org/Tizen/System/DeviceD/Input
    interface: org.tizen.system.deviced.input
    member: InputGetEventState
    parameter: "(i)", input device id to be get event state
    return: "(i)", get value on success, negative on error.

Change-Id: I820add4689222198e3cc9a24fd616382800bcf16
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
(cherry picked from commit 4e1f541f0a9e027a64a5ba4e53e091fe5ef24853)

src/input/input-dbus.c [new file with mode: 0644]
src/input/input-dbus.h [new file with mode: 0644]
src/input/input.c

diff --git a/src/input/input-dbus.c b/src/input/input-dbus.c
new file mode 100644 (file)
index 0000000..e8a1e0a
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * deviced
+ *
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file       input-dbus.c
+ * @brief      dbus interface related to control input devices
+ *             in this dbus methods will be added to
+ *             "org.tizen.system.deviced.input" dbus interface.
+ */
+
+#include <error.h>
+#include <unistd.h>
+
+#include <libsyscommon/libgdbus.h>
+#include <hal/device/hal-device-input.h>
+
+#include "core/log.h"
+#include "shared/common.h"
+#include "input-dbus.h"
+
+/* FIXME: input.keyboard feature check should be added and return DEVICE_ERROR_NOT_SUPPORTED */
+static GVariant *dbus_inputseteventstate(GDBusConnection *conn,
+       const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
+       GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
+{
+       int input_device_id, event_state;
+       int ret = 0;
+       pid_t pid;
+
+       g_variant_get(param, "(ii)", &input_device_id, &event_state);
+
+       ret = hal_device_input_set_event_state(input_device_id, event_state);
+       if (ret < 0)
+               _E("Failed to set input event state");
+
+       pid = gdbus_connection_get_sender_pid(conn, sender);
+       _D("Input set event state pid=%d input device id=%d event state=%d",
+               pid, input_device_id, event_state);
+
+       return g_variant_new("(i)", ret);
+}
+
+/* FIXME: input.keyboard feature check should be added and return DEVICE_ERROR_NOT_SUPPORTED */
+static GVariant *dbus_inputgeteventstate(GDBusConnection *conn,
+       const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
+       GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
+{
+       int input_device_id, event_state = 0;
+       int ret = 0;
+       pid_t pid;
+
+       g_variant_get(param, "(i)", &input_device_id);
+
+       ret = hal_device_input_get_event_state(input_device_id, &event_state);
+       if (ret < 0)
+               _E("Failed to get input event state");
+       else
+               ret = event_state;
+
+       pid = gdbus_connection_get_sender_pid(conn, sender);
+       _D("Input get event state pid=%d input device id=%d event_state=%d",
+               pid, input_device_id, event_state);
+
+       return g_variant_new("(i)", ret);
+}
+
+static const dbus_method_s dbus_methods[] = {
+       {"InputSetEventState", "ii", "i", dbus_inputseteventstate},
+       {"InputGetEventState", "i", "i", dbus_inputgeteventstate},
+       /* Add methods here */
+};
+
+static const dbus_interface_u dbus_interface = {
+       .oh = NULL,
+       .name = DEVICED_INTERFACE_INPUT,
+       .methods = dbus_methods,
+       .nr_methods = ARRAY_SIZE(dbus_methods),
+};
+
+int input_dbus_init(void)
+{
+       int ret = 0;
+
+       ret = gdbus_add_object(NULL, DEVICED_PATH_INPUT, &dbus_interface);
+       if (ret < 0) {
+               _E("Failed to init input device dbus interface(%d)", ret);
+               return ret;
+       }
+       return 0;
+}
\ No newline at end of file
diff --git a/src/input/input-dbus.h b/src/input/input-dbus.h
new file mode 100644 (file)
index 0000000..a7522d9
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * deviced
+ *
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __INPUT_DBUS_H__
+#define __INPUT_DBUS_H__
+
+int input_dbus_init(void);
+
+#endif //__INPUT_DBUS_H__
index f39e7b8..c18c6f6 100644 (file)
@@ -32,6 +32,7 @@
 
 #include "shared/devices.h"
 #include "shared/log.h"
+#include "input-dbus.h"
 
 #define SEAT_NAME   "seat0"
 
@@ -96,6 +97,10 @@ static void input_init(void *data)
        int ret;
        int fd;
 
+       ret = input_dbus_init();
+       if(ret < 0)
+               _E("Failed to init input device dbus interface(%d)", ret);
+
        /* load plugin input handler */
        input_handler = find_device("input-handler");
        if (check_default(input_handler) || input_handler->execute == NULL) {