input: relocate dbus interface initialization 72/286272/1
authorYunhee Seo <yuni.seo@samsung.com>
Mon, 2 Jan 2023 02:11:11 +0000 (11:11 +0900)
committeryunhee seo <yuni.seo@samsung.com>
Tue, 3 Jan 2023 04:55:19 +0000 (04:55 +0000)
Previous input dbus interface was initialized by input plugin part.
Thus, input dbus interface initialization part is moved to core input module.

Change-Id: Ie786e15b49b20d30e35719e5f5f26dd0a492a4e8
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
plugins/iot-headless/input/input-handler.c
plugins/iot-headless/input/input-handler.h
src/input/input-dbus.c
src/input/input-dbus.h
src/input/input-interface.h [new file with mode: 0644]
src/input/input.c
src/input/input.h [new file with mode: 0644]

index ffa7f8383a609c6c706dc66b9251d649b96940df..81f39786e678940e224e8b60efbb1a4be1a2aef5 100644 (file)
@@ -28,6 +28,7 @@
 #include "shared/device-notifier.h"
 #include "shared/log.h"
 #include "shared/event.h"
+#include "input/input-interface.h"
 
 #include "input-config.h"
 #include "input-dbus.h"
@@ -127,7 +128,7 @@ static void stop_event_timer(struct input_config *ic)
        }
 }
 
-void input_handler_process_key(int keycode, int keyvalue)
+static void input_handler_process_key(int keycode, int keyvalue)
 {
        struct input_config *ic;
 
@@ -172,10 +173,14 @@ static int input_handler_execute(void *data)
        return 0;
 }
 
+static struct input_ops input_handler_ops = {
+       .input_handler_process_key = input_handler_process_key,
+};
+
 static void input_handler_init(void *data)
 {
        init_input_config();
-       init_input_dbus();
+       *(struct input_ops**)data = &input_handler_ops;
 }
 
 static const struct device_ops input_handler_device_ops = {
index 8b03f121322c73ccef98ca4d480bbd61380a06ec..e66730dcc130bc61fb2e9baf30a69c7e8ac09006 100644 (file)
@@ -3,4 +3,4 @@
 
 void input_handler_process_key(int keycode, int keyvalue);
 
-#endif //__INPUT_HANDLER_H__
+#endif //__INPUT_HANDLER_H__
\ No newline at end of file
index e8a1e0a3beb9ffb026083f12b76e1dac3b2e2e83..ba001742f25ad7356e952a01c53c143124e3a71b 100644 (file)
@@ -31,7 +31,9 @@
 
 #include "core/log.h"
 #include "shared/common.h"
+#include "input.h"
 #include "input-dbus.h"
+#include "input-interface.h"
 
 /* FIXME: input.keyboard feature check should be added and return DEVICE_ERROR_NOT_SUPPORTED */
 static GVariant *dbus_inputseteventstate(GDBusConnection *conn,
@@ -79,9 +81,23 @@ static GVariant *dbus_inputgeteventstate(GDBusConnection *conn,
        return g_variant_new("(i)", ret);
 }
 
+static GVariant *dbus_emulate_key(GDBusConnection *conn,
+       const gchar *sender, const gchar *path, const gchar *iface, const gchar *name,
+       GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data)
+{
+       int keycode, keyvalue;
+
+       g_variant_get(param, "(ii)", &keycode, &keyvalue);
+
+       input_handler_process_key(keycode, keyvalue);
+
+       return gdbus_new_g_variant_tuple();
+}
+
 static const dbus_method_s dbus_methods[] = {
        {"InputSetEventState", "ii", "i", dbus_inputseteventstate},
        {"InputGetEventState", "i", "i", dbus_inputgeteventstate},
+       {"EmulateKey", "ii", NULL, dbus_emulate_key},
        /* Add methods here */
 };
 
index a7522d93c2347a849913278e2a84b643cf13b6eb..54ada46503916d300aff0a95f5dcf8e918b05dd0 100644 (file)
@@ -21,4 +21,4 @@
 
 int input_dbus_init(void);
 
-#endif //__INPUT_DBUS_H__
+#endif //__INPUT_DBUS_H__
\ No newline at end of file
diff --git a/src/input/input-interface.h b/src/input/input-interface.h
new file mode 100644 (file)
index 0000000..62bbf1e
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * deviced
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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-interface.h
+ * @brief      input interface module header
+ */
+#ifndef __INPUT_INTERFACE_H__
+#define __INPUT_INTERFACE_H__
+
+struct input_ops {
+       void (*input_handler_process_key)(int keycode, int keyvalue);
+};
+
+#endif /* __INPUT_INTERFACE_H__ */
\ No newline at end of file
index c18c6f6497ae5554f6d67c14367fee89c588b871..20b4faf562970b2c9c3514ca2462d12c5d9d2824 100644 (file)
 
 #include "shared/devices.h"
 #include "shared/log.h"
+#include "input.h"
 #include "input-dbus.h"
+#include "input-interface.h"
 
 #define SEAT_NAME   "seat0"
 
 static struct udev *udev;
 static struct libinput *li;
+static struct input_ops *input_plugin_ops;
 static guint efd;
 
 static const struct device_ops *input_handler;
@@ -92,15 +95,17 @@ static const struct libinput_interface interface = {
        .close_restricted = close_restricted,
 };
 
+void input_handler_process_key(int keycode, int keyvalue)
+{
+       if (input_plugin_ops && input_plugin_ops->input_handler_process_key)
+               input_plugin_ops->input_handler_process_key(keycode, keyvalue);
+}
+
 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) {
@@ -109,7 +114,14 @@ static void input_init(void *data)
        }
 
        if (input_handler->init)
-               input_handler->init(NULL);
+               input_handler->init(&input_plugin_ops);
+
+       if (input_plugin_ops == NULL)
+               _E("Failed to init input_ops");
+
+       ret = input_dbus_init();
+       if (ret < 0)
+               _E("Failed to init input device dbus interface(%d)", ret);
 
        udev = udev_new();
        if (!udev) {
diff --git a/src/input/input.h b/src/input/input.h
new file mode 100644 (file)
index 0000000..287ad30
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * deviced
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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.h
+ * @brief      input module header
+ */
+#ifndef __INPUT_H__
+#define __INPUT_H__
+
+void input_handler_process_key(int keycode, int keyvalue);
+
+#endif /* __INPUT_H__ */
\ No newline at end of file