From c1f00ded57ab7d486f42a565b9019cb4bd1cf7de Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Mon, 2 Jan 2023 11:11:11 +0900 Subject: [PATCH] input: relocate dbus interface initialization 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 --- plugins/iot-headless/input/input-handler.c | 9 +++++++-- plugins/iot-headless/input/input-handler.h | 2 +- src/input/input-dbus.c | 16 ++++++++++++++++ src/input/input-dbus.h | 2 +- src/input/input-interface.h | 30 ++++++++++++++++++++++++++++++ src/input/input.c | 22 +++++++++++++++++----- src/input/input.h | 28 ++++++++++++++++++++++++++++ 7 files changed, 100 insertions(+), 9 deletions(-) create mode 100644 src/input/input-interface.h create mode 100644 src/input/input.h diff --git a/plugins/iot-headless/input/input-handler.c b/plugins/iot-headless/input/input-handler.c index ffa7f83..81f3978 100644 --- a/plugins/iot-headless/input/input-handler.c +++ b/plugins/iot-headless/input/input-handler.c @@ -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 = { diff --git a/plugins/iot-headless/input/input-handler.h b/plugins/iot-headless/input/input-handler.h index 8b03f12..e66730d 100644 --- a/plugins/iot-headless/input/input-handler.h +++ b/plugins/iot-headless/input/input-handler.h @@ -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 diff --git a/src/input/input-dbus.c b/src/input/input-dbus.c index e8a1e0a..ba00174 100644 --- a/src/input/input-dbus.c +++ b/src/input/input-dbus.c @@ -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 */ }; diff --git a/src/input/input-dbus.h b/src/input/input-dbus.h index a7522d9..54ada46 100644 --- a/src/input/input-dbus.h +++ b/src/input/input-dbus.h @@ -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 index 0000000..62bbf1e --- /dev/null +++ b/src/input/input-interface.h @@ -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 diff --git a/src/input/input.c b/src/input/input.c index c18c6f6..20b4faf 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -32,12 +32,15 @@ #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 index 0000000..287ad30 --- /dev/null +++ b/src/input/input.h @@ -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 -- 2.7.4