From b4bef0231298f2ba554601d9736592f362e2a38a Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 30 Aug 2021 10:03:55 +0900 Subject: [PATCH 01/16] Add new package, plugin-profile-iot-headless Change-Id: I2ab36edc7ef1f87432be2b69435a714b407932a3 Signed-off-by: Youngjae Cho --- packaging/deviced.spec | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index bcd7146..5e5de42 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -120,6 +120,14 @@ Requires: %{name} = %{version}-%{release} %description plugin-profile-iot-headed Plugin libraries for IoT devices +%package plugin-profile-iot-headless +Summary: Plugin libraries for IoT headless devices +Group: System/Management +Requires: %{name} = %{version}-%{release} + +%description plugin-profile-iot-headless +Plugin libraries for IoT headless devices + %prep %setup -q @@ -244,6 +252,11 @@ mv %{_sysconfdir}/deviced/iot-headed-display.conf %{_sysconfdir}/deviced/display mkdir -p %{_libdir}/deviced mv %{_libdir}/iot-headed-display.so %{_libdir}/deviced/display.so +%post plugin-profile-iot-headless +mv %{_sysconfdir}/deviced/iot-headless-display.conf %{_sysconfdir}/deviced/display.conf +mkdir -p %{_libdir}/deviced +mv %{_libdir}/iot-headed-display.so %{_libdir}/deviced/display.so + %files %manifest %{name}.manifest %license LICENSE.Apache-2.0 @@ -354,3 +367,12 @@ mv %{_libdir}/iot-headed-display.so %{_libdir}/deviced/display.so %{_libdir}/iot-headed-display.so %{_unitdir}/rndis.service %{_bindir}/rndis.sh + +%files plugin-profile-iot-headless +%manifest deviced.manifest +%license LICENSE.Apache-2.0 +%defattr(-,root,root,-) +%config %{_sysconfdir}/deviced/iot-headed-display.conf +%{_libdir}/iot-headed-display.so +%{_unitdir}/rndis.service +%{_bindir}/rndis.sh -- 2.7.4 From ab9971c3d5fc4a5c5988e9683d9ed88691a31e2e Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 13 Sep 2021 14:20:47 +0900 Subject: [PATCH 02/16] usbhost: add configuration for display change state Change-Id: I1801f86f15fc41774b73e410c6baecb155ab44f1 Signed-off-by: Youngjae Cho --- conf/iot-headed-display.conf | 5 +++++ plugins/iot-headed/display/core.c | 1 + plugins/mobile/display/core.c | 1 + plugins/tv/display/core.c | 1 + plugins/wearable/display/core.c | 1 + src/display/core.h | 1 + src/display/display.c | 2 ++ src/usbhost/usb-host.c | 20 ++++++++++++++++++-- 8 files changed, 30 insertions(+), 2 deletions(-) diff --git a/conf/iot-headed-display.conf b/conf/iot-headed-display.conf index 10769a8..7e3886e 100644 --- a/conf/iot-headed-display.conf +++ b/conf/iot-headed-display.conf @@ -34,6 +34,11 @@ # If this value is no, LCD is turned off just by external requests. # TimeoutEnable=(yes or no) +# Turn on display on changing usbhost state +# Default: yes +# DisplayOnUsbConnChanged=(yes or no) + LCDAlwaysOn=no TimeoutEnable=yes SleepSupport=no +DisplayOnUsbConnChanged=yes diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index f211259..f998e53 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -201,6 +201,7 @@ static struct display_config display_conf = { .aod_tsp = true, .touch_wakeup = false, .sleep_support = true, + .display_on_usb_conn_changed = true, }; struct display_function_info display_info = { diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index d381e31..ec05af7 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -203,6 +203,7 @@ static struct display_config display_conf = { .aod_tsp = true, .touch_wakeup = false, .sleep_support = true, + .display_on_usb_conn_changed = true, }; struct display_function_info display_info = { diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 47f74b0..bfa19d3 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -201,6 +201,7 @@ static struct display_config display_conf = { .aod_tsp = true, .touch_wakeup = false, .sleep_support = true, + .display_on_usb_conn_changed = true, }; struct display_function_info display_info = { diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 9b58369..fb3523d 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -223,6 +223,7 @@ static struct display_config display_conf = { .aod_tsp = true, .touch_wakeup = false, .sleep_support = true, + .display_on_usb_conn_changed = true, }; struct display_function_info display_info = { diff --git a/src/display/core.h b/src/display/core.h index e623b5d..43d71f0 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -139,6 +139,7 @@ struct display_config { bool input_support; bool touch_wakeup; bool sleep_support; + bool display_on_usb_conn_changed; }; /* diff --git a/src/display/display.c b/src/display/display.c index 871816f..033240e 100644 --- a/src/display/display.c +++ b/src/display/display.c @@ -155,6 +155,8 @@ int display_load_config(struct parse_result *result, void *user_data) } else if (MATCH(result->name, "SleepSupport")) { c->sleep_support = (MATCH(result->value, "yes") ? true : false); _D("SleepSupport is %d", c->sleep_support); + } else if (MATCH(result->name, "DisplayOnUsbConnChanged")) { + c->display_on_usb_conn_changed = (MATCH(result->value, "yes") ? true : false); } return 0; diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index 7843e81..f8a297f 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "core/log.h" #include "core/devices.h" @@ -33,6 +34,7 @@ #include "apps/apps.h" #include "extcon/extcon.h" #include "display/display-ops.h" +#include "display/core.h" #include "dd-usbhost.h" #include "shared/plugin.h" @@ -54,6 +56,9 @@ #define POLICY_FILENAME "usbhost-policy" static struct display_plugin *disp_plgn; +static struct display_config *disp_conf; +static struct display_config* (*fp_get_var_display_config)(void); +static bool display_on_usb_conn_changed = true; static char *POLICY_FILEPATH; /** @@ -241,7 +246,7 @@ static int add_usbhost_list(struct udev_device *dev, const char *devpath) broadcast_usbhost_signal(USB_HOST_ADDED, usbhost); - if (disp_plgn->pm_change_internal) + if (display_on_usb_conn_changed && disp_plgn->pm_change_internal) disp_plgn->pm_change_internal(INTERNAL_LOCK_USB_HOST, LCD_NORMAL); /* for debugging */ @@ -270,7 +275,7 @@ static int remove_usbhost_list(const char *devpath) broadcast_usbhost_signal(USB_HOST_REMOVED, usbhost); - if (disp_plgn->pm_change_internal) + if (display_on_usb_conn_changed && disp_plgn->pm_change_internal) disp_plgn->pm_change_internal(INTERNAL_LOCK_USB_HOST, LCD_NORMAL); /* for debugging */ @@ -1129,6 +1134,17 @@ static void usbhost_init(void *data) { int ret; + fp_get_var_display_config = dlsym(disp_plgn->handle, "get_var_display_config"); + if (fp_get_var_display_config) { + disp_conf = fp_get_var_display_config(); + if (!disp_conf) + _E("Failed to get display config variable."); + else + display_on_usb_conn_changed = disp_conf->display_on_usb_conn_changed; + } else { + _E("Failed to obtain address of get_var_display_config, %s.", dlerror()); + } + /* register usbhost uevent */ ret = register_kernel_uevent_control(&uh); if (ret < 0) -- 2.7.4 From 2900f9fee02221152874f8047f3e979e4963fdff Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 28 Sep 2021 12:14:38 +0900 Subject: [PATCH 03/16] input: detach input from display module For headless profile, separate input from display module. The input module must be initialized with a parameter which is function pointer handling input event. Change-Id: Idc5e821d3cf1d02feae0ee6f9dc367320296f223 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 5 + packaging/deviced.spec | 1 + plugins/iot-headed/display/core.c | 4 +- plugins/mobile/display/core.c | 4 +- plugins/tv/display/core.c | 4 +- plugins/wearable/display/core.c | 4 +- src/core/devices.c | 10 +- src/core/devices.h | 3 +- src/display/{input.c => display-input.c} | 112 +++------------------ src/display/poll.h | 4 +- src/input/input.c | 165 +++++++++++++++++++++++++++++++ 11 files changed, 205 insertions(+), 111 deletions(-) rename src/display/{input.c => display-input.c} (59%) create mode 100644 src/input/input.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 37e4111..4713f60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -155,6 +155,11 @@ IF(DEVICE_BOARD_MODULE STREQUAL on) SET(SRCS ${SRCS} ${BOARD_SRCS}) ENDIF() +IF(DEVICE_INPUT_MODULE STREQUAL on) + ADD_SOURCE(src/input INPUT_SRCS) + SET(SRCS ${SRCS} ${INPUT_SRCS}) +ENDIF() + INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/deviced) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 5e5de42..9c4fb41 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -173,6 +173,7 @@ Plugin libraries for IoT headless devices -DTOUCH_SENSITIVITY_MODULE=on \ -DDUMP_MODULE=on \ -DDEVICE_BOARD_MODULE=on \ + -DDEVICE_INPUT_MODULE=on \ -DCRITICAL_LOG_MODULE=on \ #eol diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index f998e53..45e0f64 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -2044,7 +2044,7 @@ static int input_init_handler(void) if (!display_conf.input_support) return 0; - g_idle_add(init_input, NULL); + g_idle_add(display_input_init, NULL); return 0; } @@ -2257,7 +2257,7 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); - exit_input(); + display_input_exit(); break; } } diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index ec05af7..fde1087 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -2050,7 +2050,7 @@ static int input_init_handler(void) if (!display_conf.input_support) return 0; - g_idle_add(init_input, NULL); + g_idle_add(display_input_init, NULL); return 0; } @@ -2263,7 +2263,7 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); - exit_input(); + display_input_exit(); break; } } diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index bfa19d3..8120d15 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -2041,7 +2041,7 @@ static int input_init_handler(void) if (!display_conf.input_support) return 0; - g_idle_add(init_input, NULL); + g_idle_add(display_input_init, NULL); return 0; } @@ -2254,7 +2254,7 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); - exit_input(); + display_input_exit(); break; } } diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index fb3523d..1326e6c 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -2333,7 +2333,7 @@ static int input_init_handler(void) if (!display_conf.input_support) return 0; - g_idle_add(init_input, NULL); + g_idle_add(display_input_init, NULL); return 0; } @@ -2585,7 +2585,7 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); - exit_input(); + display_input_exit(); break; } } diff --git a/src/core/devices.c b/src/core/devices.c index 3470781..610c9d3 100644 --- a/src/core/devices.c +++ b/src/core/devices.c @@ -126,9 +126,15 @@ void devices_init(void *data) } SYS_G_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { - _D("[%s] Initialization.", dev->name); - if (dev->init) + if (dev->init) { + if (dev->disable_auto_init) { + _D("[%s] Initialization is deferred.", dev->name); + continue; + } + + _D("[%s] Initialization.", dev->name); dev->init(data); + } } ret = gdbus_add_object(NULL, DEVICED_PATH_CORE, &dbus_interface); diff --git a/src/core/devices.h b/src/core/devices.h index 4375edb..372ef0c 100644 --- a/src/core/devices.h +++ b/src/core/devices.h @@ -53,7 +53,8 @@ enum device_flags { }; struct device_ops { - int priority; /* high number will be initialized first */ + int priority; /* high number will be initialized first */ + bool disable_auto_init; /* default: false */ char *name; int len; int (*probe) (void *data); diff --git a/src/display/input.c b/src/display/display-input.c similarity index 59% rename from src/display/input.c rename to src/display/display-input.c index e372058..a43db2d 100644 --- a/src/display/input.c +++ b/src/display/display-input.c @@ -30,13 +30,9 @@ #define SEAT_NAME "seat0" -static struct udev *udev; -static struct libinput *li; -static guint efd; - int (*pm_callback) (int, PMMsg *); -static inline void process_event(struct libinput_event *ev) +static void process_event(struct libinput_event *ev) { static const struct device_ops *display_device_ops; struct input_event input; @@ -114,110 +110,30 @@ static inline void process_event(struct libinput_event *ev) (*pm_callback) (INPUT_POLL_EVENT, NULL); } -static gboolean input_handler(gint fd, GIOCondition cond, void *data) -{ - struct libinput_event *ev; - struct libinput *input = (struct libinput *)data; - - if (!input) - return G_SOURCE_CONTINUE; - - libinput_dispatch(input); - - while ((ev = libinput_get_event(input))) { - process_event(ev); - - libinput_event_destroy(ev); - libinput_dispatch(input); - } - - return G_SOURCE_CONTINUE; -} - -static int open_restricted(const char *path, int flags, void *user_data) -{ - int fd; - unsigned int clockid = CLOCK_MONOTONIC; - - if (!path) - return -EINVAL; - - fd = open(path, flags); - if (fd >= 0) { - /* TODO Why does fd change the clock? */ - if (ioctl(fd, EVIOCSCLOCKID, &clockid) < 0) - _E("fail to change clock %s", path); - } - - return fd < 0 ? -errno : fd; -} - -static void close_restricted(int fd, void *user_data) +gboolean display_input_init(gpointer data) { - close(fd); -} - -static const struct libinput_interface interface = { - .open_restricted = open_restricted, - .close_restricted = close_restricted, -}; + static const struct device_ops *input_device; -gboolean init_input(gpointer data) -{ - int ret; - int fd; - - udev = udev_new(); - if (!udev) { - _E("fail to create udev library context"); + input_device = find_device("input"); + if (!input_device) return G_SOURCE_REMOVE; - } - li = libinput_udev_create_context(&interface, NULL, udev); - if (!li) { - _E("fail to create a new libinput context from udev"); - return G_SOURCE_REMOVE; - } - - ret = libinput_udev_assign_seat(li, SEAT_NAME); - if (ret < 0) { - _E("fail to assign a seat"); - return G_SOURCE_REMOVE; - } - - fd = libinput_get_fd(li); - if (fd < 0) { - _E("fail to get file descriptor from libinput context"); - return G_SOURCE_REMOVE; - } - - /* add to poll handler */ - efd = g_unix_fd_add(fd, G_IO_IN, - input_handler, - (void *)((intptr_t)li)); - if (!efd) { - _E("fail to g_unix_fd_add"); - /* TODO Does it really need close()? */ - close(fd); - return G_SOURCE_REMOVE; - } + _D("[%s] Initialization.", input_device->name); + if (input_device->init) + input_device->init(process_event); return G_SOURCE_REMOVE; } -int exit_input(void) +int display_input_exit(void) { - if (efd) { - g_source_remove(efd); - efd = -1; - } - /* todo: close fd */ + static const struct device_ops *input_device; - if (li) - libinput_unref(li); + input_device = find_device("input"); + if (!input_device) + return 0; - if (udev) - udev_unref(udev); + input_device->exit(NULL); return 0; } diff --git a/src/display/poll.h b/src/display/poll.h index 662b0f3..83bba86 100644 --- a/src/display/poll.h +++ b/src/display/poll.h @@ -152,8 +152,8 @@ typedef struct { extern int (*pm_callback) (int, PMMsg *); -gboolean init_input(gpointer data); -int exit_input(void); +gboolean display_input_init(gpointer data); +int display_input_exit(void); /** * @} diff --git a/src/input/input.c b/src/input/input.c new file mode 100644 index 0000000..e1b57b3 --- /dev/null +++ b/src/input/input.c @@ -0,0 +1,165 @@ +/* + * deviced + * + * Copyright (c) 2015 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. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "core/devices.h" +#include "shared/log.h" + +#define SEAT_NAME "seat0" + +static struct udev *udev; +static struct libinput *li; +static guint efd; + +static void (*input_event_handler) (struct libinput_event *); + +static gboolean input_handler(gint fd, GIOCondition cond, void *data) +{ + struct libinput_event *ev; + struct libinput *input = (struct libinput *)data; + + if (!input || !input_event_handler) + return G_SOURCE_CONTINUE; + + libinput_dispatch(input); + + while ((ev = libinput_get_event(input))) { + input_event_handler(ev); + + libinput_event_destroy(ev); + libinput_dispatch(input); + } + + return G_SOURCE_CONTINUE; +} + +static int open_restricted(const char *path, int flags, void *user_data) +{ + int fd; + unsigned int clockid = CLOCK_MONOTONIC; + + if (!path) + return -EINVAL; + + fd = open(path, flags); + if (fd >= 0) { + /* TODO Why does fd change the clock? */ + if (ioctl(fd, EVIOCSCLOCKID, &clockid) < 0) + _E("fail to change clock %s", path); + } + + return fd < 0 ? -errno : fd; +} + +static void close_restricted(int fd, void *user_data) +{ + close(fd); +} + +static const struct libinput_interface interface = { + .open_restricted = open_restricted, + .close_restricted = close_restricted, +}; + +static void input_init(void *data) +{ + int ret; + int fd; + + if (!data) { + _E("there is no handler for input event"); + return; + } + + /* registering input event handler */ + input_event_handler = data; + + udev = udev_new(); + if (!udev) { + _E("fail to create udev library context"); + return; + } + + li = libinput_udev_create_context(&interface, NULL, udev); + if (!li) { + _E("fail to create a new libinput context from udev"); + return; + } + + ret = libinput_udev_assign_seat(li, SEAT_NAME); + if (ret < 0) { + _E("fail to assign a seat"); + return; + } + + fd = libinput_get_fd(li); + if (fd < 0) { + _E("fail to get file descriptor from libinput context"); + return; + } + + /* add to poll handler */ + efd = g_unix_fd_add(fd, G_IO_IN, + input_handler, + (void *)((intptr_t)li)); + if (!efd) { + _E("fail to g_unix_fd_add"); + /* TODO Does it really need close()? */ + close(fd); + } +} + +static void input_exit(void *data) +{ + if (efd) { + g_source_remove(efd); + efd = -1; + } + /* todo: close fd */ + + if (li) + libinput_unref(li); + + if (udev) + udev_unref(udev); + + input_event_handler = NULL; +} + +/* input module parse and transfer + * input event to input event handler */ +static const struct device_ops input_device_ops = { + DECLARE_NAME_LEN("input"), + .init = input_init, + .exit = input_exit, + .disable_auto_init = true, +}; + +DEVICE_OPS_REGISTER(&input_device_ops) -- 2.7.4 From b73d3ae8ca548b59ee711ae4a6e793dafc744428 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 28 Sep 2021 18:17:20 +0900 Subject: [PATCH 04/16] display: remove pm_callback function pointer Instead, invoke poll_callback() function, which is identical to the pm_callback function pointer. Change-Id: Ic7a4bc2ea5a5729a39b6333d572621303a00fc95 Signed-off-by: Youngjae Cho --- plugins/iot-headed/display/core.c | 3 +-- plugins/iot-headed/display/key-filter.c | 2 +- plugins/mobile/display/core.c | 3 +-- plugins/mobile/display/key-filter.c | 5 ++--- plugins/tv/display/core.c | 3 +-- plugins/tv/display/key-filter.c | 2 +- plugins/wearable/display/core.c | 3 +-- plugins/wearable/display/key-filter.c | 2 +- src/display/core.h | 8 ++++++++ src/display/display-input.c | 7 +------ src/display/poll.c | 15 +++------------ src/display/poll.h | 9 --------- 12 files changed, 21 insertions(+), 41 deletions(-) diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index 45e0f64..c4e6f18 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -1609,7 +1609,7 @@ static void default_saving_mode(int onoff) backlight_ops->update(); } -static int poll_callback(int condition, PMMsg *data) +int poll_callback(int condition, PMMsg *data) { static time_t last_t; time_t now; @@ -2129,7 +2129,6 @@ static void display_init(void *data) break; case INIT_POLL: _I("input init"); - pm_callback = poll_callback; ret = input_init_handler(); pm_lock_detector_init(); diff --git a/plugins/iot-headed/display/key-filter.c b/plugins/iot-headed/display/key-filter.c index 470b513..ccfb22f 100644 --- a/plugins/iot-headed/display/key-filter.c +++ b/plugins/iot-headed/display/key-filter.c @@ -139,7 +139,7 @@ static void longkey_pressed(void) /* change state - LCD on */ if (disp_plgn->pm_change_internal) disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_NORMAL); - (*pm_callback)(INPUT_POLL_EVENT, NULL); + poll_callback(INPUT_POLL_EVENT, NULL); } if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF)) { diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index fde1087..62b1a9a 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -1619,7 +1619,7 @@ static void default_saving_mode(int onoff) backlight_ops->update(); } -static int poll_callback(int condition, PMMsg *data) +int poll_callback(int condition, PMMsg *data) { static time_t last_t; time_t now; @@ -2135,7 +2135,6 @@ static void display_init(void *data) break; case INIT_POLL: _I("input init"); - pm_callback = poll_callback; ret = input_init_handler(); pm_lock_detector_init(); diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index 17bca2c..2054adb 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -130,7 +130,7 @@ static void longkey_pressed(void) /* change state - LCD on */ if (disp_plgn->pm_change_internal) disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_NORMAL); - (*pm_callback)(INPUT_POLL_EVENT, NULL); + poll_callback(INPUT_POLL_EVENT, NULL); } if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF)) { @@ -425,8 +425,7 @@ static gboolean display_on_cb(void *data) broadcast_lcdon_by_powerkey(); lcd_on_direct(LCD_ON_BY_POWER_KEY); - if (pm_callback) - (*pm_callback) (INPUT_POLL_EVENT, NULL); + poll_callback(INPUT_POLL_EVENT, NULL); } return G_SOURCE_REMOVE; diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 8120d15..21af9f5 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -1609,7 +1609,7 @@ static void default_saving_mode(int onoff) backlight_ops->update(); } -static int poll_callback(int condition, PMMsg *data) +int poll_callback(int condition, PMMsg *data) { static time_t last_t; time_t now; @@ -2126,7 +2126,6 @@ static void display_init(void *data) break; case INIT_POLL: _I("input init"); - pm_callback = poll_callback; ret = input_init_handler(); pm_lock_detector_init(); diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index b0667ec..33214b1 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -139,7 +139,7 @@ static void longkey_pressed(void) /* change state - LCD on */ if (disp_plgn->pm_change_internal) disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_NORMAL); - (*pm_callback)(INPUT_POLL_EVENT, NULL); + poll_callback(INPUT_POLL_EVENT, NULL); } if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF)) { diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 1326e6c..8d27e91 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -1885,7 +1885,7 @@ static void default_saving_mode(int onoff) } } -static int poll_callback(int condition, PMMsg *data) +int poll_callback(int condition, PMMsg *data) { static time_t last_t; time_t now; @@ -2456,7 +2456,6 @@ static void display_init(void *data) break; case INIT_POLL: _I("input init"); - pm_callback = poll_callback; ret = input_init_handler(); pm_lock_detector_init(); diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index cc9a56b..5b1cf9d 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -129,7 +129,7 @@ static void longkey_pressed(void) /* change state - LCD on */ if (disp_plgn->pm_change_internal) disp_plgn->pm_change_internal(INTERNAL_LOCK_POWERKEY, LCD_NORMAL); - (*pm_callback)(INPUT_POLL_EVENT, NULL); + poll_callback(INPUT_POLL_EVENT, NULL); } if (!display_has_caps(caps, DISPLAY_CAPA_LCDOFF)) { diff --git a/src/display/core.h b/src/display/core.h index 43d71f0..e001f65 100644 --- a/src/display/core.h +++ b/src/display/core.h @@ -173,6 +173,14 @@ struct display_keyfilter_ops { extern const struct display_keyfilter_ops *keyfilter_ops; extern GList *lcdon_ops; +typedef struct { + pid_t pid; + unsigned int cond; + unsigned int timeout; + unsigned int timeout2; +} PMMsg; +extern int poll_callback(int condition, PMMsg *data); + /* If the bit in a condition variable is set, * we cannot transit the state until clear this bit. */ int check_processes(enum state_t prohibit_state); diff --git a/src/display/display-input.c b/src/display/display-input.c index a43db2d..9b86aff 100644 --- a/src/display/display-input.c +++ b/src/display/display-input.c @@ -30,8 +30,6 @@ #define SEAT_NAME "seat0" -int (*pm_callback) (int, PMMsg *); - static void process_event(struct libinput_event *ev) { static const struct device_ops *display_device_ops; @@ -46,9 +44,6 @@ static void process_event(struct libinput_event *ev) return; } - if (!pm_callback) - return; - if (!display_device_ops) { display_device_ops = find_device("display"); if (!display_device_ops) @@ -107,7 +102,7 @@ static void process_event(struct libinput_event *ev) return; /* lcd on or update lcd timeout */ - (*pm_callback) (INPUT_POLL_EVENT, NULL); + poll_callback(INPUT_POLL_EVENT, NULL); } gboolean display_input_init(gpointer data) diff --git a/src/display/poll.c b/src/display/poll.c index 0e3ab28..600c2ef 100644 --- a/src/display/poll.c +++ b/src/display/poll.c @@ -84,9 +84,6 @@ static int __pm_lock_internal(pid_t pid, int s_bits, int flag, int timeout) { int cond; - if (!pm_callback) - return -1; - cond = get_state(s_bits); if (cond < 0) return cond; @@ -107,7 +104,7 @@ static int __pm_lock_internal(pid_t pid, int s_bits, int flag, int timeout) recv_data.cond = cond; recv_data.timeout = timeout; - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); + poll_callback(PM_CONTROL_EVENT, &recv_data); return 0; } @@ -116,9 +113,6 @@ static int __pm_unlock_internal(pid_t pid, int s_bits, int flag) { int cond; - if (!pm_callback) - return -1; - cond = get_state(s_bits); if (cond < 0) return cond; @@ -138,7 +132,7 @@ static int __pm_unlock_internal(pid_t pid, int s_bits, int flag) recv_data.cond = cond; recv_data.timeout = 0; - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); + poll_callback(PM_CONTROL_EVENT, &recv_data); return 0; } @@ -148,9 +142,6 @@ static int __pm_change_internal(pid_t pid, int s_bits) int cond, ret; const int display_on = LCD_NORMAL | LCD_DIM; - if (!pm_callback) - return -1; - cond = get_state(s_bits); if (cond < 0) return cond; @@ -170,7 +161,7 @@ static int __pm_change_internal(pid_t pid, int s_bits) recv_data.cond = cond; recv_data.timeout = 0; - (*pm_callback)(PM_CONTROL_EVENT, &recv_data); + poll_callback(PM_CONTROL_EVENT, &recv_data); return 0; } diff --git a/src/display/poll.h b/src/display/poll.h index 83bba86..096316d 100644 --- a/src/display/poll.h +++ b/src/display/poll.h @@ -143,15 +143,6 @@ enum cond_flags_e { #define RESET_TIMER_STR "resettimer" #define KEEP_TIMER_STR "keeptimer" -typedef struct { - pid_t pid; - unsigned int cond; - unsigned int timeout; - unsigned int timeout2; -} PMMsg; - -extern int (*pm_callback) (int, PMMsg *); - gboolean display_input_init(gpointer data); int display_input_exit(void); -- 2.7.4 From 1b16c4840c59f30c9fb59674c4696c08ee38cedb Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 28 Sep 2021 17:15:48 +0900 Subject: [PATCH 05/16] input: add input-handler for iot-headless Change-Id: Ie90573af3c1351d8f1f6ed8622ed8ec021eb8ba8 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 2 + packaging/deviced.spec | 2 + plugins/iot-headless/input/CMakeLists.txt | 17 ++++ plugins/iot-headless/input/input-handler.c | 130 +++++++++++++++++++++++++++++ src/display/display-input.c | 6 +- 5 files changed, 154 insertions(+), 3 deletions(-) create mode 100644 plugins/iot-headless/input/CMakeLists.txt create mode 100644 plugins/iot-headless/input/input-handler.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 4713f60..e16edd2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -339,10 +339,12 @@ ADD_SUBDIRECTORY(plugins/mobile/display) ADD_SUBDIRECTORY(plugins/wearable/display) ADD_SUBDIRECTORY(plugins/tv/display) ADD_SUBDIRECTORY(plugins/iot-headed/display) +ADD_SUBDIRECTORY(plugins/iot-headless/input) IF(BATTERY_MODULE STREQUAL on) ADD_SUBDIRECTORY(plugins/mobile/battery) ADD_SUBDIRECTORY(plugins/wearable/battery) ENDIF() + INSTALL_CONF(conf mobile-display) INSTALL_CONF(conf wearable-display) INSTALL_CONF(conf tv-display) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 9c4fb41..34679aa 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -257,6 +257,7 @@ mv %{_libdir}/iot-headed-display.so %{_libdir}/deviced/display.so mv %{_sysconfdir}/deviced/iot-headless-display.conf %{_sysconfdir}/deviced/display.conf mkdir -p %{_libdir}/deviced mv %{_libdir}/iot-headed-display.so %{_libdir}/deviced/display.so +mv %{_libdir}/iot-headless-input-handler.so %{_libdir}/deviced/input-handler.so %files %manifest %{name}.manifest @@ -375,5 +376,6 @@ mv %{_libdir}/iot-headed-display.so %{_libdir}/deviced/display.so %defattr(-,root,root,-) %config %{_sysconfdir}/deviced/iot-headed-display.conf %{_libdir}/iot-headed-display.so +%{_libdir}/iot-headless-input-handler.so %{_unitdir}/rndis.service %{_bindir}/rndis.sh diff --git a/plugins/iot-headless/input/CMakeLists.txt b/plugins/iot-headless/input/CMakeLists.txt new file mode 100644 index 0000000..f9a7881 --- /dev/null +++ b/plugins/iot-headless/input/CMakeLists.txt @@ -0,0 +1,17 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +PROJECT(iot-headless-input-handler C) + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(REQUIRED_PKGS REQUIRED + glib-2.0 + dlog + libinput) + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src) + +FILE(GLOB SRCS "*.c") +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES OUTPUT_NAME iot-headless-input-handler) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) diff --git a/plugins/iot-headless/input/input-handler.c b/plugins/iot-headless/input/input-handler.c new file mode 100644 index 0000000..cacd970 --- /dev/null +++ b/plugins/iot-headless/input/input-handler.c @@ -0,0 +1,130 @@ +/* + * deviced + * + * Copyright (c) 2021 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. + */ + +#include +#include + +#include "core/devices.h" +#include "shared/log.h" + +#define KEYCODE_LEFTKEY 114 +#define KEYCODE_RIGHTKEY 116 + +#define KEYVALUE_PRESS 1 +#define KEYVALUE_RELEASE 0 + +#define LONGPRESS_INTERVAL 3000 /* milisecond */ + +static guint longpress_timer_id; + +static gboolean longpressed_cb(void *data) +{ + const struct device_ops *power_device; + + longpress_timer_id = 0; + + power_device = find_device("power"); + if (check_default(power_device)) + return G_SOURCE_REMOVE; + + if (power_device->execute) { + _D("longkey pressed, do poweroff"); + power_device->execute("poweroff"); + } + + return G_SOURCE_REMOVE; +} + +static void start_longpress_timer(void) +{ + if (longpress_timer_id) { + g_source_remove(longpress_timer_id); + longpress_timer_id = 0; + } + + longpress_timer_id = g_timeout_add(LONGPRESS_INTERVAL, longpressed_cb, NULL); +} + +static void stop_longpress_timer(void) +{ + if (longpress_timer_id) { + g_source_remove(longpress_timer_id); + longpress_timer_id = 0; + } +} + +/* poweroff if left button is pressed longer than LONGPRESS_INTERVAL */ +static void input_event_handler(struct libinput_event *e) +{ + struct libinput_event_keyboard *ek; + int keycode, keyvalue; + + if (libinput_event_get_type(e) != LIBINPUT_EVENT_KEYBOARD_KEY) + return; + + ek = libinput_event_get_keyboard_event(e); + keycode = libinput_event_keyboard_get_key(ek); + keyvalue = libinput_event_keyboard_get_key_state(ek); + + _D("key input: code=%d, value=%d", keycode, keyvalue); + + if (keycode == KEYCODE_LEFTKEY) { + if (keyvalue == KEYVALUE_PRESS) + start_longpress_timer(); + else if (keyvalue == KEYVALUE_RELEASE) + stop_longpress_timer(); + } +} + +static void input_event_handler_init(void *data) +{ + const struct device_ops *input_device; + + input_device = find_device("input"); + if (check_default(input_device)) { + _E("There is no input device"); + return; + } + + if (input_device->init) { + _D("[%s] Initialization.", input_device->name); + input_device->init(input_event_handler); + } +} + +static void input_event_handler_exit(void *data) +{ + const struct device_ops *input_device; + + input_device = find_device("input"); + if (check_default(input_device)) { + _E("There is no input device"); + return; + } + + if (input_device->exit) + input_device->exit(NULL); +} + +static const struct device_ops input_event_handler_device_ops = { + DECLARE_NAME_LEN("input-event-handler"), + .init = input_event_handler_init, + .exit = input_event_handler_exit, +}; + +DEVICE_OPS_REGISTER(&input_event_handler_device_ops); diff --git a/src/display/display-input.c b/src/display/display-input.c index 9b86aff..0e1d4c6 100644 --- a/src/display/display-input.c +++ b/src/display/display-input.c @@ -46,7 +46,7 @@ static void process_event(struct libinput_event *ev) if (!display_device_ops) { display_device_ops = find_device("display"); - if (!display_device_ops) + if (check_default(display_device_ops)) return; } @@ -110,7 +110,7 @@ gboolean display_input_init(gpointer data) static const struct device_ops *input_device; input_device = find_device("input"); - if (!input_device) + if (check_default(input_device)) return G_SOURCE_REMOVE; _D("[%s] Initialization.", input_device->name); @@ -125,7 +125,7 @@ int display_input_exit(void) static const struct device_ops *input_device; input_device = find_device("input"); - if (!input_device) + if (check_default(input_device)) return 0; input_device->exit(NULL); -- 2.7.4 From d5922628fc93864273a694e5777a64fda73faf6f Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 30 Sep 2021 14:35:24 +0900 Subject: [PATCH 06/16] power: support cpu lock/unlock for headless Add power-control-plugin module to support headless-exclusive cpu lock/unlock. Change-Id: I3d39f5b9479af114fb0f42281511c93590a29ff7 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 1 + packaging/deviced.spec | 2 + plugins/iot-headless/power/CMakeLists.txt | 17 ++ plugins/iot-headless/power/power-control.c | 246 +++++++++++++++++++++++++++++ src/core/devices.c | 4 +- src/power/power-control.c | 42 +++++ src/shared/device-notifier.h | 2 + 7 files changed, 311 insertions(+), 3 deletions(-) create mode 100644 plugins/iot-headless/power/CMakeLists.txt create mode 100644 plugins/iot-headless/power/power-control.c diff --git a/CMakeLists.txt b/CMakeLists.txt index e16edd2..d900646 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -340,6 +340,7 @@ ADD_SUBDIRECTORY(plugins/wearable/display) ADD_SUBDIRECTORY(plugins/tv/display) ADD_SUBDIRECTORY(plugins/iot-headed/display) ADD_SUBDIRECTORY(plugins/iot-headless/input) +ADD_SUBDIRECTORY(plugins/iot-headless/power) IF(BATTERY_MODULE STREQUAL on) ADD_SUBDIRECTORY(plugins/mobile/battery) ADD_SUBDIRECTORY(plugins/wearable/battery) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 34679aa..c0dc3a3 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -258,6 +258,7 @@ mv %{_sysconfdir}/deviced/iot-headless-display.conf %{_sysconfdir}/deviced/displ mkdir -p %{_libdir}/deviced mv %{_libdir}/iot-headed-display.so %{_libdir}/deviced/display.so mv %{_libdir}/iot-headless-input-handler.so %{_libdir}/deviced/input-handler.so +mv %{_libdir}/iot-headless-power.so %{_libdir}/deviced/power.so %files %manifest %{name}.manifest @@ -377,5 +378,6 @@ mv %{_libdir}/iot-headless-input-handler.so %{_libdir}/deviced/input-handler.so %config %{_sysconfdir}/deviced/iot-headed-display.conf %{_libdir}/iot-headed-display.so %{_libdir}/iot-headless-input-handler.so +%{_libdir}/iot-headless-power.so %{_unitdir}/rndis.service %{_bindir}/rndis.sh diff --git a/plugins/iot-headless/power/CMakeLists.txt b/plugins/iot-headless/power/CMakeLists.txt new file mode 100644 index 0000000..2f9a962 --- /dev/null +++ b/plugins/iot-headless/power/CMakeLists.txt @@ -0,0 +1,17 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +PROJECT(iot-headless-power C) + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(REQUIRED_PKGS REQUIRED + glib-2.0 + dlog + libsyscommon) + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src) + +FILE(GLOB SRCS "*.c") +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "") +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES OUTPUT_NAME iot-headless-power) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) diff --git a/plugins/iot-headless/power/power-control.c b/plugins/iot-headless/power/power-control.c new file mode 100644 index 0000000..ee67309 --- /dev/null +++ b/plugins/iot-headless/power/power-control.c @@ -0,0 +1,246 @@ +/* + * deviced + * + * Copyright (c) 2021 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. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "core/devices.h" +#include "shared/log.h" +#include "shared/device-notifier.h" + +#ifndef PROCESS_CHECK_TIMEOUT +#define PROCESS_CHECK_TIMEOUT 3600000 /* milisecond, 1 hour */ +#endif + +static GList *lock_list; + +struct lock_node { + pid_t pid; + char comm[64]; + int timer_id; + int timeout; + char locktime[64]; +}; + +static void print_lock_node(void) +{ + GList *elem; + struct lock_node *node; + + _D("List of remaining CPU locks"); + SYS_G_LIST_FOREACH(lock_list, elem, node) + _D(" pid=%d(%s), locktime=%s, timeout=%dms", + node->pid, node->comm, node->locktime, node->timeout); +} + +/* remove given node from lock list. + * if list is empty after removing the lock, + * automatically release powerlock */ +static void remove_lock_node(struct lock_node *node) +{ + if (!node) + return; + + if (node->timer_id) { + g_source_remove(node->timer_id); + node->timer_id = 0; + } + + SYS_G_LIST_REMOVE(lock_list, node); + free(node); + + if (SYS_G_LIST_LENGTH(lock_list) == 0) + device_notify(DEVICE_NOTIFIER_REQUEST_WAKE_UNLOCK, NULL); + else + print_lock_node(); +} + +static gboolean lock_expired_cb(void *data) +{ + struct lock_node *this = (struct lock_node *) data; + + _D("powerlock of pid=%d(%s) for %dms is expired", this->pid, this->comm, this->timeout); + remove_lock_node(this); + + return G_SOURCE_REMOVE; +} + +/* check existance of process for every PROCESS_CHECK_TIMEOUT + * if the process has requested infinite CPU lock */ +static gboolean process_check_cb(void *data) +{ + struct lock_node *this = (struct lock_node *) data; + + if (kill(this->pid, 0) != 0) { + _D("pid=%d(%s) is not found, deviced release the CPU lock", this->pid, this->comm); + remove_lock_node(this); + return G_SOURCE_REMOVE; + } + + return G_SOURCE_CONTINUE; +} + +static GVariant *dbus_power_lock_cpu(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + int timeout; + int ret = 0; + pid_t pid; + GList *elem; + struct lock_node *node; + + time_t current; + struct tm current_tm; + struct tm *rettm; + + /* lock timeout in milisecond */ + g_variant_get(param, "(i)", &timeout); + if (timeout < 0) { + ret = -EINVAL; + goto out; + } + + pid = gdbus_connection_get_sender_pid(conn, sender); + if (pid == -1 || kill(pid, 0) == -1) { + _E("%d process does not exist, dbus ignored.", pid); + ret = -ESRCH; + goto out; + } + + SYS_G_LIST_FOREACH(lock_list, elem, node) { + if (node->pid == pid) + break; + } + + if (!node) { + int retval; + char commpath[128]; + char *sep; + + node = calloc(1, sizeof(struct lock_node)); + if (!node) { + ret = -ENOMEM; + goto out; + } + + node->pid = pid; + snprintf(commpath, sizeof(commpath), "/proc/%d/comm", pid); + retval = sys_get_str(commpath, node->comm, sizeof(node->comm)); + if (retval != 0) + snprintf(node->comm, sizeof(node->comm), "Unknown"); + + /* remove whitesapce */ + sep = strpbrk(node->comm, " \n\t\r"); + if (sep) + *sep = '\0'; + + SYS_G_LIST_APPEND(lock_list, node); + } + + /* set current time for logging */ + current = time(NULL); + rettm = localtime_r(¤t, ¤t_tm); + if (!rettm) + snprintf(node->locktime, sizeof(node->locktime), "Unknown"); + else + strftime(node->locktime, sizeof(node->locktime), "%Y-%m-%d %H:%M:%S", ¤t_tm); + + node->timeout = timeout; + + if (node->timer_id) { + g_source_remove(node->timer_id); + node->timer_id = 0; + } + + _D("pid=%d(%s) request CPU lock for %dms", pid, node->comm, timeout); + device_notify(DEVICE_NOTIFIER_REQUEST_WAKE_LOCK, NULL); + + if (timeout > 0) + node->timer_id = g_timeout_add(timeout, lock_expired_cb, node); + else if (timeout == 0) /* endless CPU lock: add checker that monitors the process*/ + node->timer_id = g_timeout_add(PROCESS_CHECK_TIMEOUT, process_check_cb, node); + +out: + return g_variant_new("(i)", ret); +} + +static GVariant *dbus_power_unlock_cpu(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + int ret = 0; + pid_t pid; + GList *elem; + struct lock_node *node; + + pid = gdbus_connection_get_sender_pid(conn, sender); + if (pid == -1 || kill(pid, 0) == -1) { + _E("%d process does not exist, dbus ignored.", pid); + ret = -ESRCH; + goto out; + } + + SYS_G_LIST_FOREACH(lock_list, elem, node) { + if (node->pid == pid) + break; + } + + if (node) { + _D("pid=%d(%s) release CPU lock", node->pid, node->comm); + remove_lock_node(node); + } + +out: + return g_variant_new("(i)", ret); +} + +static const dbus_method_s dbus_methods[] = { + { "LockCpu", "i", "i", dbus_power_lock_cpu }, + { "UnlockCpu", NULL, "i", dbus_power_unlock_cpu }, + /* Add methods here */ +}; + +static const dbus_interface_u dbus_interface = { + .oh = NULL, + .name = DEVICED_INTERFACE_POWER, + .methods = dbus_methods, + .nr_methods = ARRAY_SIZE(dbus_methods), +}; + +static void power_control_init(void *data) +{ + int retval; + + retval = gdbus_add_object(NULL, DEVICED_PATH_POWER, &dbus_interface); + if (retval < 0) + _E("Failed to init dbus method."); +} + +static const struct device_ops power_control_plugin_device_ops = { + DECLARE_NAME_LEN("power-control-plugin"), + .init = power_control_init, + .disable_auto_init = true, +}; + +DEVICE_OPS_REGISTER(&power_control_plugin_device_ops) diff --git a/src/core/devices.c b/src/core/devices.c index 610c9d3..1b36fa2 100644 --- a/src/core/devices.c +++ b/src/core/devices.c @@ -127,10 +127,8 @@ void devices_init(void *data) SYS_G_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { if (dev->init) { - if (dev->disable_auto_init) { - _D("[%s] Initialization is deferred.", dev->name); + if (dev->disable_auto_init) continue; - } _D("[%s] Initialization.", dev->name); dev->init(data); diff --git a/src/power/power-control.c b/src/power/power-control.c index 51f368e..3b3649c 100644 --- a/src/power/power-control.c +++ b/src/power/power-control.c @@ -291,3 +291,45 @@ int set_wakeup_count(int cnt) return 0; } + +static int __pm_power_lock(void *data) +{ + if (mainlock_status == POWER_UNLOCK) + pm_power_lock(); + + return 0; +} + +static int __pm_power_unlock(void *data) +{ + if (mainlock_status == POWER_LOCK) + pm_power_unlock(); + + return 0; +} + +static void power_control_init(void *data) +{ + const struct device_ops *plugin_device_ops; + + plugin_device_ops = find_device("power-control-plugin"); + if (check_default(plugin_device_ops)) + return; + + /* if there is plugin of power-control, + * register notifier for the plugin module */ + register_notifier(DEVICE_NOTIFIER_REQUEST_WAKE_LOCK, __pm_power_lock); + register_notifier(DEVICE_NOTIFIER_REQUEST_WAKE_UNLOCK, __pm_power_unlock); + + _D("[%s] Initialization.", plugin_device_ops->name); + if (plugin_device_ops->init) + plugin_device_ops->init(NULL); +} + +static const struct device_ops power_control_device_ops = { + DECLARE_NAME_LEN("power-control"), + .init = power_control_init, + .priority = 900, /* power-control should be initialized asap */ +}; + +DEVICE_OPS_REGISTER(&power_control_device_ops) diff --git a/src/shared/device-notifier.h b/src/shared/device-notifier.h index f8f190d..24d6350 100644 --- a/src/shared/device-notifier.h +++ b/src/shared/device-notifier.h @@ -61,6 +61,8 @@ enum device_notifier_type { DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, DEVICE_NOTIFIER_ULTRAPOWERSAVING, DEVICE_NOTIFIER_EXTCON_COUNT, + DEVICE_NOTIFIER_REQUEST_WAKE_LOCK, + DEVICE_NOTIFIER_REQUEST_WAKE_UNLOCK, DEVICE_NOTIFIER_MAX, }; -- 2.7.4 From 7d36ee1a68267bdfb090cbc273c9efa6b33f05a7 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 1 Oct 2021 15:43:00 +0900 Subject: [PATCH 07/16] extcon: defer init until booting done Change-Id: I1a4556d7c5e6e42aa7de8e0eef57f8d107dafce1 Signed-off-by: Youngjae Cho --- src/extcon/extcon.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/extcon/extcon.c b/src/extcon/extcon.c index 0925f28..74dae19 100644 --- a/src/extcon/extcon.c +++ b/src/extcon/extcon.c @@ -466,15 +466,22 @@ static int event_handler_state_changed(void *data) return 0; } -static void extcon_init(void *data) +static int booting_done(void *data) { + static int done; int ret_dbus; GList *l; struct extcon_ops *dev; device_notifier_state_e state = DEVICE_NOTIFIER_STATE_START; + if (!data) + return done; + done = *(int *) data; + if (!done) + return done; + if (!extcon_list) - return; + return done; /* initialize extcon devices */ SYS_G_LIST_FOREACH(extcon_list, l, dev) { @@ -490,8 +497,14 @@ static void extcon_init(void *data) if (ret_dbus < 0) _E("Failed to init dbus method: %d", ret_dbus); - register_notifier(DEVICE_NOTIFIER_EVENT_HANDLER, event_handler_state_changed); + + return done; +} + +static void extcon_init(void *data) +{ + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); } static void extcon_exit(void *data) -- 2.7.4 From 7ea46700b445c98976c92211e17770c28b5bbb77 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 5 Oct 2021 13:30:19 +0900 Subject: [PATCH 08/16] extcon: register dbus object on init Change-Id: Ia20bb373f1f20fb1b50d1957636d7f9625b5f07b Signed-off-by: Youngjae Cho --- src/extcon/extcon.c | 60 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/src/extcon/extcon.c b/src/extcon/extcon.c index 74dae19..46deb7e 100644 --- a/src/extcon/extcon.c +++ b/src/extcon/extcon.c @@ -40,6 +40,9 @@ static GList *extcon_list; static bool extcon_dev_available = false; +static void extcon_deferred_init(void); +static int booting_done(void *data); + void add_extcon(struct extcon_ops *dev) { SYS_G_LIST_APPEND(extcon_list, dev); @@ -303,6 +306,9 @@ static GVariant * dbus_get_extcon_status(GDBusConnection *conn, char *str; int ret; + if (!booting_done(NULL)) + extcon_deferred_init(); + g_variant_get(param, "(s)", &str); dev = find_extcon(str); @@ -327,6 +333,9 @@ static GVariant *dbus_enable_device(GDBusConnection *conn, char *device; int ret; + if (!booting_done(NULL)) + extcon_deferred_init(); + g_variant_get(param, "(s)", &device); ret = extcon_update(device, NULL, "1"); @@ -342,6 +351,9 @@ static GVariant *dbus_disable_device(GDBusConnection *conn, char *device; int ret; + if (!booting_done(NULL)) + extcon_deferred_init(); + g_variant_get(param, "(s)", &device); ret = extcon_update(device, NULL, "0"); @@ -466,44 +478,60 @@ static int event_handler_state_changed(void *data) return 0; } -static int booting_done(void *data) +/* defer extcon init until booting done as it takes long time. + * if dbus request is arrived before the booting done, + * initialize extcon on arriving that request even though + * system booting has not been finished */ +static void extcon_deferred_init(void) { - static int done; - int ret_dbus; GList *l; struct extcon_ops *dev; device_notifier_state_e state = DEVICE_NOTIFIER_STATE_START; + static int initialized = false; - if (!data) - return done; - done = *(int *) data; - if (!done) - return done; - - if (!extcon_list) - return done; + if (initialized) + return; /* initialize extcon devices */ SYS_G_LIST_FOREACH(extcon_list, l, dev) { _I("Extcon(%s) init.", dev->name); if (dev->init) - dev->init(data); + dev->init(NULL); dev->enabled = true; } event_handler_state_changed((void *)&state); + register_notifier(DEVICE_NOTIFIER_EVENT_HANDLER, event_handler_state_changed); - ret_dbus = gdbus_add_object(NULL, DEVICED_PATH_EXTCON, &dbus_interface); - if (ret_dbus < 0) - _E("Failed to init dbus method: %d", ret_dbus); + initialized = true; +} - register_notifier(DEVICE_NOTIFIER_EVENT_HANDLER, event_handler_state_changed); +static int booting_done(void *data) +{ + static int done; + + if (!data) + return done; + done = *(int *) data; + if (!done) + return done; + + if (!extcon_list) + return done; + + extcon_deferred_init(); return done; } static void extcon_init(void *data) { + int retval; + + retval = gdbus_add_object(NULL, DEVICED_PATH_EXTCON, &dbus_interface); + if (retval < 0) + _E("Failed to init dbus method: %d", retval); + register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); } -- 2.7.4 From 2f655c33a4abe1a16d28ff368c3eb7c2fd6b2085 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 5 Oct 2021 16:45:11 +0900 Subject: [PATCH 09/16] battery-notification: remove duplicated code Change-Id: I391743067775c6eb0134cabe02fb277894f4ab5b Signed-off-by: Youngjae Cho --- plugins/mobile/battery/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/mobile/battery/CMakeLists.txt b/plugins/mobile/battery/CMakeLists.txt index c7792f6..b9c0f42 100644 --- a/plugins/mobile/battery/CMakeLists.txt +++ b/plugins/mobile/battery/CMakeLists.txt @@ -3,8 +3,6 @@ PROJECT(mobile-battery C) FILE(GLOB ALL_SRCS "*.c") SET(SRCS ${ALL_SRCS}) -ADD_SOURCE(${CMAKE_SOURCE_DIR}/src/battery COMMON_SRCS) -SET(SRCS ${SRCS} ${COMMON_SRCS}) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/battery) -- 2.7.4 From e9de71152e0a9794fd6b856db5e954596d59f915 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 5 Oct 2021 15:44:18 +0900 Subject: [PATCH 10/16] Rename booting_done to delayed_init_done Technically, the DEVICE_NOTIFIER_BOOTING_DONE is generated on receiving dbus signal "StartupFinished", not "BootingDone". Therefore rename this notifier to DEVICE_NOTIFIER_DELAYED_INIT and booting_done() callbacks to delayed_init_done(). Change-Id: Ib7c9a38826ce3fdc7eb0b10ee2a62314c8b0dde6 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 2 +- plugins/iot-headed/display/core.c | 14 ++-- plugins/iot-headed/display/key-filter.c | 4 +- plugins/mobile/display/core.c | 14 ++-- plugins/mobile/display/device-interface.c | 6 +- plugins/mobile/display/key-filter.c | 4 +- plugins/tv/display/core.c | 14 ++-- plugins/tv/display/key-filter.c | 4 +- plugins/wearable/display/core.c | 14 ++-- plugins/wearable/display/key-filter.c | 4 +- plugins/wearable/display/powersaver.c | 4 +- src/battery/lowbat-handler.c | 6 +- src/battery/power-supply.c | 12 ++-- src/core/delayed-init-notifier.c | 103 ++++++++++++++++++++++++++ src/core/late-booting-done-notifier.c | 115 ------------------------------ src/core/main.c | 2 +- src/cpu/pmqos.c | 6 +- src/display/auto-brightness.c | 6 +- src/extcon/extcon.c | 12 ++-- src/power/boot.c | 14 ++-- src/power/boot.h | 4 +- src/power/power-handler.c | 6 +- src/shared/device-notifier.c | 3 +- src/shared/device-notifier.h | 3 +- src/thermal/thermal.c | 6 +- src/touchscreen/sensitivity.c | 6 +- src/touchscreen/touchscreen.c | 8 +-- src/tzip/tzip.c | 6 +- src/usbhost/usb-host.c | 6 +- 29 files changed, 197 insertions(+), 211 deletions(-) create mode 100644 src/core/delayed-init-notifier.c delete mode 100644 src/core/late-booting-done-notifier.c diff --git a/CMakeLists.txt b/CMakeLists.txt index d900646..0aef649 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,7 @@ SET(VERSION 0.1.0) SET(SRCS src/apps/apps.c src/control/control.c - src/core/late-booting-done-notifier.c + src/core/delayed-init-notifier.c src/core/devices.c src/core/event-handler.c src/core/execute.c diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index c4e6f18..f462b17 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -164,7 +164,7 @@ static int trans_table[S_END][EVENT_END] = { #define S_COVER_TIMEOUT 8000 #define GET_HOLDKEY_BLOCK_STATE(x) ((x >> SHIFT_LOCK_FLAG) & HOLD_KEY_BLOCK_BIT) -#define BOOTING_DONE_WATING_TIME 60000 /* 1 minute */ +#define DELAYED_INIT_WATING_TIME 60000 /* 1 minute */ #define LOCK_SCREEN_WATING_TIME 300 /* 0.3 second */ #define LONG_PRESS_INTERVAL 2 /* 2 seconds */ @@ -1926,7 +1926,7 @@ void reset_lcd_timeout(GDBusConnection *conn, states[get_pm_cur_state()].trans(EVENT_INPUT); } -static int booting_done(void *data) +static int delayed_init_done(void *data) { static bool done = false; @@ -1966,7 +1966,7 @@ static int battery_health_changed(void *data) return 0; } -static gboolean delayed_init_dpms(gpointer data) +static gboolean delayed_init_done_dpms(gpointer data) { int timeout; @@ -1999,7 +1999,7 @@ static gboolean delayed_init_dpms(gpointer data) static void add_timer_for_init_dpms(void) { - guint id = g_timeout_add(500/* milliseconds */, delayed_init_dpms, NULL); + guint id = g_timeout_add(500/* milliseconds */, delayed_init_done_dpms, NULL); if (id == 0) _E("Failed to add init_dpms timeout."); } @@ -2107,7 +2107,7 @@ static void display_init(void *data) register_kernel_uevent_control(&lcd_uevent_ops); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); @@ -2190,7 +2190,7 @@ static void display_init(void *data) */ if (disp_plgn->pm_lock_internal) disp_plgn->pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, - STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); + STAY_CUR_STATE, DELAYED_INIT_WATING_TIME); /* Initial display state right after the booting done */ if (is_lcdon_blocked()) @@ -2249,7 +2249,7 @@ static void display_exit(void *data) exit_sysfs(); break; case INIT_POLL: - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); diff --git a/plugins/iot-headed/display/key-filter.c b/plugins/iot-headed/display/key-filter.c index ccfb22f..2dbfe2a 100644 --- a/plugins/iot-headed/display/key-filter.c +++ b/plugins/iot-headed/display/key-filter.c @@ -728,7 +728,7 @@ static int check_key_filter(void *data, int fd) return 0; } -static int booting_done_cb(void *data) +static int delayed_init_done(void *data) { booting_check = 0; @@ -766,7 +766,7 @@ static void keyfilter_init(void) touchled = find_device(TOUCHLED_NAME); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb); } diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 62b1a9a..19d63dc 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -166,7 +166,7 @@ static int trans_table[S_END][EVENT_END] = { #define S_COVER_TIMEOUT 8000 #define GET_HOLDKEY_BLOCK_STATE(x) ((x >> SHIFT_LOCK_FLAG) & HOLD_KEY_BLOCK_BIT) -#define BOOTING_DONE_WATING_TIME 60000 /* 1 minute */ +#define DELAYED_INIT_WATING_TIME 60000 /* 1 minute */ #define LOCK_SCREEN_WATING_TIME 300 /* 0.3 second */ #define LONG_PRESS_INTERVAL 400 /* 0.4 seconds */ @@ -1936,7 +1936,7 @@ void reset_lcd_timeout(GDBusConnection *conn, states[get_pm_cur_state()].trans(EVENT_INPUT); } -static int booting_done(void *data) +static int delayed_init_done(void *data) { static bool done = false; @@ -1976,7 +1976,7 @@ static int battery_health_changed(void *data) return 0; } -static gboolean delayed_init_dpms(gpointer data) +static gboolean delayed_init_done_dpms(gpointer data) { int timeout; @@ -2009,7 +2009,7 @@ static gboolean delayed_init_dpms(gpointer data) static void add_timer_for_init_dpms(void) { - guint id = g_timeout_add(500/* milliseconds */, delayed_init_dpms, NULL); + guint id = g_timeout_add(500/* milliseconds */, delayed_init_done_dpms, NULL); if (id == 0) _E("Failed to add init_dpms timeout."); } @@ -2113,7 +2113,7 @@ static void display_init(void *data) register_kernel_uevent_control(&lcd_uevent_ops); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); @@ -2196,7 +2196,7 @@ static void display_init(void *data) */ if (disp_plgn->pm_lock_internal) disp_plgn->pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, - STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); + STAY_CUR_STATE, DELAYED_INIT_WATING_TIME); /* Initial display state right after the booting done */ if (is_lcdon_blocked()) @@ -2255,7 +2255,7 @@ static void display_exit(void *data) exit_sysfs(); break; case INIT_POLL: - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index ba2b4e7..bb328df 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -801,7 +801,7 @@ int display_service_free(void) return hal_device_display_put_backend(); } -static int booting_done(void *data) +static int delayed_init_done(void *data) { static int done = false; @@ -816,7 +816,7 @@ static int booting_done(void *data) int is_lcdon_blocked(void) { /* block lcdon until booting done in silent boot mode */ - if (silent_boot && !booting_done(NULL)) + if (silent_boot && !delayed_init_done(NULL)) return LCDON_BLOCK_DURING_SILENT_BOOT; return LCDON_BLOCK_NONE; @@ -825,7 +825,7 @@ int is_lcdon_blocked(void) int init_sysfs(unsigned int flags) { register_notifier(DEVICE_NOTIFIER_VITAL_STATE, vital_state_changed); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); return 0; } diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index 2054adb..13bc8a6 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -754,7 +754,7 @@ static int check_key_filter(void *data, int fd) return 0; } -static int booting_done_cb(void *data) +static int delayed_init_done(void *data) { booting_check = 0; @@ -792,7 +792,7 @@ static void keyfilter_init(void) touchled = find_device(TOUCHLED_NAME); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb); } diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 21af9f5..b55dea3 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -164,7 +164,7 @@ static int trans_table[S_END][EVENT_END] = { #define S_COVER_TIMEOUT 8000 #define GET_HOLDKEY_BLOCK_STATE(x) ((x >> SHIFT_LOCK_FLAG) & HOLD_KEY_BLOCK_BIT) -#define BOOTING_DONE_WATING_TIME 60000 /* 1 minute */ +#define DELAYED_INIT_WATING_TIME 60000 /* 1 minute */ #define LOCK_SCREEN_WATING_TIME 300 /* 0.3 second */ #define LONG_PRESS_INTERVAL 2 /* 2 seconds */ @@ -1926,7 +1926,7 @@ void reset_lcd_timeout(GDBusConnection *conn, states[get_pm_cur_state()].trans(EVENT_INPUT); } -static int booting_done(void *data) +static int delayed_init_done(void *data) { static bool done = false; @@ -1966,7 +1966,7 @@ static int battery_health_changed(void *data) return 0; } -static gboolean delayed_init_dpms(gpointer data) +static gboolean delayed_init_done_dpms(gpointer data) { int timeout; @@ -1999,7 +1999,7 @@ static gboolean delayed_init_dpms(gpointer data) static void add_timer_for_init_dpms(void) { - guint id = g_timeout_add(500/* milliseconds */, delayed_init_dpms, NULL); + guint id = g_timeout_add(500/* milliseconds */, delayed_init_done_dpms, NULL); if (id == 0) _E("Failed to add init_dpms timeout."); } @@ -2104,7 +2104,7 @@ static void display_init(void *data) register_kernel_uevent_control(&lcd_uevent_ops); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); @@ -2187,7 +2187,7 @@ static void display_init(void *data) */ if (disp_plgn->pm_lock_internal) disp_plgn->pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, - STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); + STAY_CUR_STATE, DELAYED_INIT_WATING_TIME); /* Initial display state right after the booting done */ if (is_lcdon_blocked()) @@ -2246,7 +2246,7 @@ static void display_exit(void *data) exit_sysfs(); break; case INIT_POLL: - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index 33214b1..1031fa7 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -722,7 +722,7 @@ static int check_key_filter(void *data, int fd) return 0; } -static int booting_done_cb(void *data) +static int delayed_init_done(void *data) { booting_check = 0; @@ -760,7 +760,7 @@ static void keyfilter_init(void) touchled = find_device(TOUCHLED_NAME); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb); } diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 8d27e91..268fa62 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -172,7 +172,7 @@ static int trans_table[S_END][EVENT_END] = { #define S_COVER_TIMEOUT 8000 #define GET_HOLDKEY_BLOCK_STATE(x) ((x >> SHIFT_LOCK_FLAG) & HOLD_KEY_BLOCK_BIT) -#define BOOTING_DONE_WATING_TIME 60000 /* 1 minute */ +#define DELAYED_INIT_WATING_TIME 60000 /* 1 minute */ #define LOCK_SCREEN_WATING_TIME 300 /* 0.3 second */ #define LONG_PRESS_INTERVAL 500 /* 0.5 seconds */ @@ -2198,7 +2198,7 @@ void reset_lcd_timeout(GDBusConnection *conn, states[get_pm_cur_state()].trans(EVENT_INPUT); } -static int booting_done(void *data) +static int delayed_init_done(void *data) { static bool done = false; @@ -2259,7 +2259,7 @@ static int powerlock_load_config(struct parse_result *result, void *user_data) return 0; } -static gboolean delayed_init_dpms(gpointer data) +static gboolean delayed_init_done_dpms(gpointer data) { int timeout; @@ -2292,7 +2292,7 @@ static gboolean delayed_init_dpms(gpointer data) static void add_timer_for_init_dpms(void) { - guint id = g_timeout_add(500/* milliseconds */, delayed_init_dpms, NULL); + guint id = g_timeout_add(500/* milliseconds */, delayed_init_done_dpms, NULL); if (id == 0) _E("Failed to add init_dpms timeout."); } @@ -2434,7 +2434,7 @@ static void display_init(void *data) register_kernel_uevent_control(&lcd_uevent_ops); register_kernel_uevent_control(&sec_dsim_uevent_ops); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); register_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); register_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); register_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); @@ -2517,7 +2517,7 @@ static void display_init(void *data) */ if (disp_plgn->pm_lock_internal) disp_plgn->pm_lock_internal(INTERNAL_LOCK_BOOTING, LCD_OFF, - STAY_CUR_STATE, BOOTING_DONE_WATING_TIME); + STAY_CUR_STATE, DELAYED_INIT_WATING_TIME); /* Initial display state right after the booting done */ if (is_lcdon_blocked()) @@ -2577,7 +2577,7 @@ static void display_exit(void *data) exit_sysfs(); break; case INIT_POLL: - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_BACKGROUND, display_app_background); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_FOREGROUND, display_app_foreground); unregister_notifier(DEVICE_NOTIFIER_APPLICATION_TERMINATED, display_app_terminated); diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index 5b1cf9d..21bdd95 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -673,7 +673,7 @@ static int check_key_filter(void *data, int fd) return 0; } -static int booting_done_cb(void *data) +static int delayed_init_done(void *data) { booting_check = 0; @@ -709,7 +709,7 @@ static void keyfilter_init(void) display_add_actor(&display_powerkey_actor); display_add_actor(&display_menukey_actor); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); register_notifier(DEVICE_NOTIFIER_BEZEL_WAKEUP, bezel_wakeup_cb); } diff --git a/plugins/wearable/display/powersaver.c b/plugins/wearable/display/powersaver.c index 87d0d8a..56c3391 100644 --- a/plugins/wearable/display/powersaver.c +++ b/plugins/wearable/display/powersaver.c @@ -86,7 +86,7 @@ static void powersaver_status_changed(keynode_t *key_nodes, void *data) _E("Failed to update powersaver state %d.", ret); } -static int booting_done(void *data) +static int delayed_init_done(void *data) { static int done; int ret, status; @@ -135,7 +135,7 @@ out: static void powersaver_init(void *data) { - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); } static void powersaver_exit(void *data) diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index e771b44..3b58753 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -162,7 +162,7 @@ static int power_execute(void *data) return ops->execute(data); } -static int booting_done(void *data) +static int delayed_init_done(void *data) { int status; static int done; @@ -237,7 +237,7 @@ int lowbat_popup(int option) direct_launch: _D("Popup value=%s", value); - if (booting_done(NULL)) { + if (delayed_init_done(NULL)) { if (launched_poweroff == 1) { _I("Will be foreced power off."); @@ -717,7 +717,7 @@ static void lowbat_init(void *data) { int ret; - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); register_notifier(DEVICE_NOTIFIER_POWER_SUPPLY, lowbat_monitor_init); ret = gdbus_add_object(NULL, DEVICED_PATH_BATTERY, &dbus_interface); diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 9537559..4e64746 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -105,7 +105,7 @@ bool battery_initialized; bool battery_do_not_disturb(void); int battery_pm_change_internal(int pid, int s_bits); -static int booting_done(void *data); +static int delayed_init_done(void *data); static void update_health(enum battery_noti_status status); static bool battery_dev_available = false; static int load_uevent(struct parse_result *result, void *user_data); @@ -914,7 +914,7 @@ static void uevent_power_handler(struct udev_device *dev) battery_initialized = true; - ret_val = booting_done(NULL); + ret_val = delayed_init_done(NULL); if (ret_val) { if (battery.online > POWER_SUPPLY_TYPE_BATTERY) power_supply_noti(DEVICE_NOTI_BATT_CHARGE, DEVICE_NOTI_ON); @@ -1013,7 +1013,7 @@ static void battery_changed(struct battery_info *info, void *data) if (ret_val != 1) return; - ret_val = booting_done(NULL); + ret_val = delayed_init_done(NULL); if (ret_val) { /* If the same notification is requested repeatedly, it is ignored by power_supply_noti(). * A notification will be triggered only when charge_status changes between @@ -1490,7 +1490,7 @@ static const dbus_interface_u dbus_interface = { .nr_methods = ARRAY_SIZE(dbus_methods), }; -static int booting_done(void *data) +static int delayed_init_done(void *data) { static int done; device_notifier_state_e state = DEVICE_NOTIFIER_STATE_START; @@ -1513,7 +1513,7 @@ static int booting_done(void *data) CHARGE_MISC_EVENT_SIGNAL, battery.misc, CHARGE_HEALTH_SIGNAL, battery.health, battery.health_s); - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); return done; } @@ -1695,7 +1695,7 @@ static void power_supply_init(void *data) /* process check battery timer until booting done */ power_supply_timer_start(); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); register_notifier(DEVICE_NOTIFIER_EVENT_HANDLER, event_handler_state_changed); ret_dbus = gdbus_add_object(NULL, DEVICED_PATH_BATTERY, &dbus_interface); diff --git a/src/core/delayed-init-notifier.c b/src/core/delayed-init-notifier.c new file mode 100644 index 0000000..53a86d1 --- /dev/null +++ b/src/core/delayed-init-notifier.c @@ -0,0 +1,103 @@ +/* + * deviced + * + * Copyright (c) 2012 - 2013 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. + */ + + +#include "log.h" +#include "shared/device-notifier.h" +#include "shared/common.h" +#include "core/devices.h" +#include +#include + +static guint delayed_init_timer; + +#define DELAYED_INIT_WAIT_TIME 30 /* second */ +#define DEFAULT_DELAYED_INIT_VALUE (guint)0x0DEF0DEF + +static void delayed_init_stop(void) +{ + if (delayed_init_timer == 0 || delayed_init_timer == DEFAULT_DELAYED_INIT_VALUE) + return; + + g_source_remove(delayed_init_timer); + delayed_init_timer = 0; +} + +static int delayed_init_done(void *data) +{ + static int done; + + if (data == NULL) + goto out; + + done = *(int *)data; + if (delayed_init_timer == 0) + return done; + delayed_init_stop(); +out: + return done; +} + +static gboolean delayed_init_timer_cb(void *data) +{ + int done; + + delayed_init_stop(); + delayed_init_timer = 0; + + done = delayed_init_done(NULL); + if (done) + return G_SOURCE_REMOVE; + + _I("delayed init"); + + done = 1; + device_notify_once(DEVICE_NOTIFIER_DELAYED_INIT, (void *)&done); + + return G_SOURCE_REMOVE; +} + +static void delayed_init_done_notifier_init(void *data) +{ + int ret; + + ret = check_systemd_active(); + if (ret == TRUE) { + _I("restart booting done"); + return; + } + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); + delayed_init_timer = g_timeout_add_seconds(DELAYED_INIT_WAIT_TIME, + delayed_init_timer_cb, NULL); + + if (!delayed_init_timer) + delayed_init_timer = DEFAULT_DELAYED_INIT_VALUE; +} + +static void delayed_init_done_notifier_exit(void *data) +{ + +} + +static const struct device_ops notifier_device_ops = { + DECLARE_NAME_LEN("delayed-init-notifier"), + .init = delayed_init_done_notifier_init, + .exit = delayed_init_done_notifier_exit, +}; + +DEVICE_OPS_REGISTER(¬ifier_device_ops) diff --git a/src/core/late-booting-done-notifier.c b/src/core/late-booting-done-notifier.c deleted file mode 100644 index 36f882a..0000000 --- a/src/core/late-booting-done-notifier.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 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. - */ - - -#include "log.h" -#include "shared/device-notifier.h" -#include "shared/common.h" -#include "core/devices.h" -#include -#include - -static guint late_init_timer; - -#define LATE_INIT_WAIT_TIME 30 /* second */ -#define DEFAULT_LATE_INIT_VALUE (guint)0x0DEF0DEF - -static void late_init_stop(void) -{ - if (late_init_timer == 0 || late_init_timer == DEFAULT_LATE_INIT_VALUE) - return; - - g_source_remove(late_init_timer); - late_init_timer = 0; -} - -static int booting_done(void *data) -{ - static int done; - - if (data == NULL) - goto out; - - done = *(int *)data; - if (late_init_timer == 0) - return done; - late_init_stop(); -out: - return done; -} - -static int early_booting_done(void *data) -{ - static int done; - - if (data == NULL) - goto out; - - done = *(int *)data; -out: - return done; -} - -static gboolean late_init_timer_cb(void *data) -{ - int done; - - late_init_stop(); - done = early_booting_done(NULL); - if (!done) - device_notify(DEVICE_NOTIFIER_EARLY_BOOTING_DONE, (void *)&done); - done = booting_done(NULL); - late_init_timer = 0; - if (done) - return G_SOURCE_REMOVE; - _I("late booting done"); - done = TRUE; - device_notify_once(DEVICE_NOTIFIER_BOOTING_DONE, (void *)&done); - return G_SOURCE_REMOVE; -} - -static void late_booting_done_notifier_init(void *data) -{ - int ret; - - ret = check_systemd_active(); - if (ret == TRUE) { - _I("restart booting done"); - return; - } - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); - register_notifier(DEVICE_NOTIFIER_EARLY_BOOTING_DONE, early_booting_done); - late_init_timer = g_timeout_add_seconds(LATE_INIT_WAIT_TIME, - late_init_timer_cb, NULL); - - if (!late_init_timer) - late_init_timer = DEFAULT_LATE_INIT_VALUE; -} - -static void late_booting_done_notifier_exit(void *data) -{ - -} - -static const struct device_ops notifier_device_ops = { - DECLARE_NAME_LEN("late-booting-done-notifier"), - .init = late_booting_done_notifier_init, - .exit = late_booting_done_notifier_exit, -}; - -DEVICE_OPS_REGISTER(¬ifier_device_ops) diff --git a/src/core/main.c b/src/core/main.c index 24968d9..5b3862c 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -80,7 +80,7 @@ static void deviced_dbus_name_acquired(GDBusConnection *connection, const gchar if (ret == 1) { /* Restarted: deviced was terminated */ _I("Notify relaunch."); - device_notify_once(DEVICE_NOTIFIER_BOOTING_DONE, &ret); + device_notify_once(DEVICE_NOTIFIER_DELAYED_INIT, &ret); } _I("sd_notify(READY=1)"); diff --git a/src/cpu/pmqos.c b/src/cpu/pmqos.c index a53c73c..ad20456 100644 --- a/src/cpu/pmqos.c +++ b/src/cpu/pmqos.c @@ -204,7 +204,7 @@ static const dbus_interface_u dbus_interface = { .nr_methods = ARRAY_SIZE(dbus_methods), }; -static int booting_done(void *data) +static int delayed_init_done(void *data) { static int done; int ret = 0; @@ -243,13 +243,13 @@ static void pmqos_init(void *data) if (ret < 0) _E("Failed to init dbus method: %d", ret); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); } static void pmqos_exit(void *data) { /* unregister notifier for each event */ - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); unregister_notifier(DEVICE_NOTIFIER_CPU_BOOST_LOWBAT, pmqos_lowbat); unregister_notifier(DEVICE_NOTIFIER_CPU_BOOST_POWEROFF, pmqos_poweroff); } diff --git a/src/display/auto-brightness.c b/src/display/auto-brightness.c index 2128ab0..9b00ecf 100644 --- a/src/display/auto-brightness.c +++ b/src/display/auto-brightness.c @@ -628,7 +628,7 @@ static int lcd_changed_cb(void *data) return 0; } -static int booting_done_cb(void *data) +static int delayed_init_done(void *data) { int state; @@ -663,7 +663,7 @@ static void auto_brightness_init(void *data) display_info.reset_autobrightness_min = reset_autobrightness_min; register_notifier(DEVICE_NOTIFIER_LCD, lcd_changed_cb); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); } static void auto_brightness_exit(void *data) @@ -671,7 +671,7 @@ static void auto_brightness_exit(void *data) exit_lsensor(); unregister_notifier(DEVICE_NOTIFIER_LCD, lcd_changed_cb); - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done_cb); + unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); } static const struct display_ops display_autobrightness_ops = { diff --git a/src/extcon/extcon.c b/src/extcon/extcon.c index 46deb7e..d0accfd 100644 --- a/src/extcon/extcon.c +++ b/src/extcon/extcon.c @@ -41,7 +41,7 @@ static GList *extcon_list; static bool extcon_dev_available = false; static void extcon_deferred_init(void); -static int booting_done(void *data); +static int delayed_init_done(void *data); void add_extcon(struct extcon_ops *dev) { @@ -306,7 +306,7 @@ static GVariant * dbus_get_extcon_status(GDBusConnection *conn, char *str; int ret; - if (!booting_done(NULL)) + if (!delayed_init_done(NULL)) extcon_deferred_init(); g_variant_get(param, "(s)", &str); @@ -333,7 +333,7 @@ static GVariant *dbus_enable_device(GDBusConnection *conn, char *device; int ret; - if (!booting_done(NULL)) + if (!delayed_init_done(NULL)) extcon_deferred_init(); g_variant_get(param, "(s)", &device); @@ -351,7 +351,7 @@ static GVariant *dbus_disable_device(GDBusConnection *conn, char *device; int ret; - if (!booting_done(NULL)) + if (!delayed_init_done(NULL)) extcon_deferred_init(); g_variant_get(param, "(s)", &device); @@ -506,7 +506,7 @@ static void extcon_deferred_init(void) initialized = true; } -static int booting_done(void *data) +static int delayed_init_done(void *data) { static int done; @@ -532,7 +532,7 @@ static void extcon_init(void *data) if (retval < 0) _E("Failed to init dbus method: %d", retval); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); } static void extcon_exit(void *data) diff --git a/src/power/boot.c b/src/power/boot.c index 458c79a..a819fed 100644 --- a/src/power/boot.c +++ b/src/power/boot.c @@ -37,13 +37,13 @@ static struct display_plugin *disp_plgn; static guint sig_id[2] = {0, 0}; -void remove_booting_done_handler(void *data) +void remove_delayed_init_done_handler(void *data) { gdbus_signal_unsubscribe(NULL, sig_id[0]); gdbus_signal_unsubscribe(NULL, sig_id[1]); } -static void booting_done_received(GDBusConnection *conn, +static void delayed_init_done_received(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, @@ -64,7 +64,7 @@ static void booting_done_received(GDBusConnection *conn, return; } CRITICAL_LOG("System session is ready."); - device_notify_once(DEVICE_NOTIFIER_BOOTING_DONE, &system_done); + device_notify_once(DEVICE_NOTIFIER_DELAYED_INIT, &system_done); } else if (strcmp(name, SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED) == 0) { if (user_done) @@ -76,7 +76,7 @@ static void booting_done_received(GDBusConnection *conn, if (!system_done || !user_done) return; - remove_booting_done_handler(NULL); + remove_delayed_init_done_handler(NULL); _I("Real booting done. Unlock LCD_OFF."); if (disp_plgn->pm_unlock_internal) @@ -87,7 +87,7 @@ static void booting_done_received(GDBusConnection *conn, doze_init(); } -void add_booting_done_handler(void *data) +void add_delayed_init_done_handler(void *data) { /* System Session is loaded completely */ /*ret = */ @@ -95,7 +95,7 @@ void add_booting_done_handler(void *data) SYSTEMD_DBUS_PATH, SYSTEMD_DBUS_IFACE_MANAGER, SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED, - booting_done_received, + delayed_init_done_received, NULL, NULL); if (sig_id[0] <= 0) @@ -106,7 +106,7 @@ void add_booting_done_handler(void *data) SYSTEMD_DBUS_PATH, SYSTEMD_DBUS_IFACE_MANAGER, SYSTEMD_DBUS_SIGNAL_USER_STARTUP_FINISHED, - booting_done_received, + delayed_init_done_received, NULL, NULL); if (sig_id[1] <= 0) diff --git a/src/power/boot.h b/src/power/boot.h index aab7cc1..a5d5b7f 100644 --- a/src/power/boot.h +++ b/src/power/boot.h @@ -19,8 +19,8 @@ #ifndef __DEVICED_BOOT_H__ #define __DEVICED_BOOT_H__ -void add_booting_done_handler(void *data); -void remove_booting_done_handler(void *data); +void add_delayed_init_done_handler(void *data); +void remove_delayed_init_done_handler(void *data); extern int silent_boot; diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 2844825..6eed091 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -749,7 +749,7 @@ static int load_config(struct parse_result *result, void *user_data) return 0; } -static int booting_done(void *data) +static int delayed_init_done(void *data) { static int done; @@ -770,9 +770,9 @@ static void power_init(void *data) if (ret_val < 0) _E("Failed to init dbus method: %d", ret_val); - add_booting_done_handler(NULL); + add_delayed_init_done_handler(NULL); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); add_poweroff_option(POWEROFF_TYPE_POWEROFF, NULL); add_poweroff_option(POWEROFF_TYPE_RESTART, NULL); diff --git a/src/shared/device-notifier.c b/src/shared/device-notifier.c index e835a9c..b755d37 100644 --- a/src/shared/device-notifier.c +++ b/src/shared/device-notifier.c @@ -43,7 +43,7 @@ static guint idl; static const char *device_notifier_type_str[DEVICE_NOTIFIER_MAX] = { NOTIFY_STR(DEVICE_NOTIFIER_DAEMON_RESTARTED), - NOTIFY_STR(DEVICE_NOTIFIER_BOOTING_DONE), + NOTIFY_STR(DEVICE_NOTIFIER_DELAYED_INIT), NOTIFY_STR(DEVICE_NOTIFIER_LCD), NOTIFY_STR(DEVICE_NOTIFIER_LCD_OFF), NOTIFY_STR(DEVICE_NOTIFIER_LOWBAT), @@ -64,7 +64,6 @@ static const char *device_notifier_type_str[DEVICE_NOTIFIER_MAX] = { NOTIFY_STR(DEVICE_NOTIFIER_USB_DEBUG_MODE), NOTIFY_STR(DEVICE_NOTIFIER_USB_TETHERING_MODE), NOTIFY_STR(DEVICE_NOTIFIER_EVENT_HANDLER), - NOTIFY_STR(DEVICE_NOTIFIER_EARLY_BOOTING_DONE), NOTIFY_STR(DEVICE_NOTIFIER_PMQOS), NOTIFY_STR(DEVICE_NOTIFIER_PMQOS_ULTRAPOWERSAVING), NOTIFY_STR(DEVICE_NOTIFIER_PMQOS_POWERSAVING), diff --git a/src/shared/device-notifier.h b/src/shared/device-notifier.h index 24d6350..ba597b1 100644 --- a/src/shared/device-notifier.h +++ b/src/shared/device-notifier.h @@ -22,7 +22,7 @@ enum device_notifier_type { DEVICE_NOTIFIER_DAEMON_RESTARTED, - DEVICE_NOTIFIER_BOOTING_DONE, + DEVICE_NOTIFIER_DELAYED_INIT, DEVICE_NOTIFIER_LCD, DEVICE_NOTIFIER_LCD_OFF, DEVICE_NOTIFIER_LCD_OFF_COMPLETE, @@ -48,7 +48,6 @@ enum device_notifier_type { DEVICE_NOTIFIER_CPU_BOOST_LOWBAT, DEVICE_NOTIFIER_CPU_BOOST_POWEROFF, /* Experimental for Specific device - contact to deviced owner */ - DEVICE_NOTIFIER_EARLY_BOOTING_DONE, DEVICE_NOTIFIER_PMQOS, DEVICE_NOTIFIER_PMQOS_ULTRAPOWERSAVING, DEVICE_NOTIFIER_PMQOS_POWERSAVING, diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c index e3e32d5..e46b190 100644 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -32,7 +32,7 @@ static bool thermal_dev_available = false; -static int booting_done(void *data) +static int delayed_init_done(void *data) { static int done; @@ -85,7 +85,7 @@ static void thermal_init(void *data) { int ret; - ret = register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + ret = register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); if (ret < 0) _E("Failed to register booting done notifier."); @@ -98,7 +98,7 @@ static void thermal_exit(void *data) { int ret; - ret = unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + ret = unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); if (ret < 0) _E("Failed to unregister booting done notifier."); diff --git a/src/touchscreen/sensitivity.c b/src/touchscreen/sensitivity.c index b0e0da4..d724361 100644 --- a/src/touchscreen/sensitivity.c +++ b/src/touchscreen/sensitivity.c @@ -134,7 +134,7 @@ static const dbus_interface_u dbus_interface = { .nr_methods = ARRAY_SIZE(dbus_methods), }; -static int booting_done(void *data) +static int delayed_init_done(void *data) { static int done; int ret; @@ -158,7 +158,7 @@ static int booting_done(void *data) } ret = hal_device_touchscreen_glove_mode_set_state(TOUCHSENSITIVITY_GLOVE_MODE_ON); _I("Change auto touch sensitivity enable: %s", ret ? "fail" : "set"); - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); out: return done; } @@ -195,7 +195,7 @@ static void sensitivity_init(void *data) if (ret <= 0) _E("Failed to register signal handler: %d", ret); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); } static const struct device_ops sensitivity_device_ops = { diff --git a/src/touchscreen/touchscreen.c b/src/touchscreen/touchscreen.c index bcbe669..6eb899c 100644 --- a/src/touchscreen/touchscreen.c +++ b/src/touchscreen/touchscreen.c @@ -46,7 +46,7 @@ static int powersaving_support = true; static int touchscreen_start(enum device_flags flags); static int touchscreen_stop(enum device_flags flags); -static int booting_done(void *data); +static int delayed_init_done(void *data); static struct display_config *display_conf; static struct _backlight_ops *backlight_ops; @@ -176,7 +176,7 @@ static int touchscreen_start(enum device_flags flags) return 0; /* Do not enable touchscreen during silent boot mode */ - if (silent_boot && !booting_done(NULL)) + if (silent_boot && !delayed_init_done(NULL)) return -ENOTSUP; /* @@ -286,7 +286,7 @@ static const dbus_interface_u dbus_interface = { .nr_methods = ARRAY_SIZE(dbus_methods), }; -static int booting_done(void *data) +static int delayed_init_done(void *data) { static int done = false; @@ -354,7 +354,7 @@ static void touchscreen_init(void *data) if (ret < 0) _E("Failed to init dbus method. (%d)", ret); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); } static const struct device_ops touchscreen_device_ops = { diff --git a/src/tzip/tzip.c b/src/tzip/tzip.c index 6f6a857..94eed6a 100644 --- a/src/tzip/tzip.c +++ b/src/tzip/tzip.c @@ -998,7 +998,7 @@ static const dbus_interface_u dbus_interface = { .nr_methods = ARRAY_SIZE(dbus_methods), }; -static int booting_done(void *data) +static int delayed_init_done(void *data) { /* To reduce the latency of the first Tzip operation, you can apply this optimization. tzip_server_init(); */ @@ -1020,7 +1020,7 @@ static void tzip_init(void *data) tzip_lock_init(); - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); register_notifier(DEVICE_NOTIFIER_POWEROFF, tzip_poweroff); ret = gdbus_add_object(NULL, DEVICED_PATH_TZIP, &dbus_interface); @@ -1036,7 +1036,7 @@ static void tzip_exit(void *data) { _D("tzip_exit"); tzip_server_exit(); - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); unregister_notifier(DEVICE_NOTIFIER_POWEROFF, tzip_poweroff); tzip_lock_deinit(); diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index f8a297f..367a5b4 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -1115,7 +1115,7 @@ static const dbus_interface_u dbus_interface = { }; -static int booting_done(void *data) +static int delayed_init_done(void *data) { /** * To search the attched usb host device is not an urgent task. @@ -1125,7 +1125,7 @@ static int booting_done(void *data) usbhost_init_from_udev_enumerate(); /* unregister booting done notifier */ - unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + unregister_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); return 0; } @@ -1156,7 +1156,7 @@ static void usbhost_init(void *data) _E("Failed to register dbus interface and method: %d", ret); /* register notifier */ - register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done); ret = asprintf(&POLICY_FILEPATH, "%s/%s", ROOTPATH, POLICY_FILENAME); if (ret < 0) { -- 2.7.4 From 3c4822785e56eb13979fe0786942b20acc24be46 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 7 Oct 2021 14:27:41 +0900 Subject: [PATCH 11/16] input: change power off key mapping Change-Id: If580a63972c3cdf13fe612bf1fc99fd34e2d7f2b Signed-off-by: Youngjae Cho --- plugins/iot-headless/input/input-handler.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/iot-headless/input/input-handler.c b/plugins/iot-headless/input/input-handler.c index cacd970..133aa7d 100644 --- a/plugins/iot-headless/input/input-handler.c +++ b/plugins/iot-headless/input/input-handler.c @@ -22,8 +22,8 @@ #include "core/devices.h" #include "shared/log.h" -#define KEYCODE_LEFTKEY 114 -#define KEYCODE_RIGHTKEY 116 +#define KEYCODE_BT_PAIRING 114 +#define KEYCODE_POWERKEY 116 #define KEYVALUE_PRESS 1 #define KEYVALUE_RELEASE 0 @@ -43,7 +43,7 @@ static gboolean longpressed_cb(void *data) return G_SOURCE_REMOVE; if (power_device->execute) { - _D("longkey pressed, do poweroff"); + _D("powerkey long pressed, start poweroff sequence"); power_device->execute("poweroff"); } @@ -68,7 +68,7 @@ static void stop_longpress_timer(void) } } -/* poweroff if left button is pressed longer than LONGPRESS_INTERVAL */ +/* poweroff if power button is pressed longer than LONGPRESS_INTERVAL */ static void input_event_handler(struct libinput_event *e) { struct libinput_event_keyboard *ek; @@ -83,7 +83,7 @@ static void input_event_handler(struct libinput_event *e) _D("key input: code=%d, value=%d", keycode, keyvalue); - if (keycode == KEYCODE_LEFTKEY) { + if (keycode == KEYCODE_POWERKEY) { if (keyvalue == KEYVALUE_PRESS) start_longpress_timer(); else if (keyvalue == KEYVALUE_RELEASE) -- 2.7.4 From 56c91370620c077fb26fc19f1e8acc4d5a05b5e7 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 8 Oct 2021 15:07:19 +0900 Subject: [PATCH 12/16] input: replace keycode macro with one in linux header Change-Id: I04da6e45adad9a3360627cd241bba32e0fc04d94 Signed-off-by: Youngjae Cho --- plugins/iot-headless/input/input-handler.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/iot-headless/input/input-handler.c b/plugins/iot-headless/input/input-handler.c index 133aa7d..cf78e23 100644 --- a/plugins/iot-headless/input/input-handler.c +++ b/plugins/iot-headless/input/input-handler.c @@ -17,14 +17,12 @@ */ #include +#include #include #include "core/devices.h" #include "shared/log.h" -#define KEYCODE_BT_PAIRING 114 -#define KEYCODE_POWERKEY 116 - #define KEYVALUE_PRESS 1 #define KEYVALUE_RELEASE 0 @@ -83,7 +81,7 @@ static void input_event_handler(struct libinput_event *e) _D("key input: code=%d, value=%d", keycode, keyvalue); - if (keycode == KEYCODE_POWERKEY) { + if (keycode == KEY_POWER) { if (keyvalue == KEYVALUE_PRESS) start_longpress_timer(); else if (keyvalue == KEYVALUE_RELEASE) -- 2.7.4 From fa61b71512e798437b13240cd838cfcab8626ac0 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 13 Oct 2021 10:57:33 +0900 Subject: [PATCH 13/16] partition-switch: add new tool for partition switch Add new tool for switching partition during FOTA. In addition to this partition-switch tool, this patch makes new "tools" directory to collect codes that produce executables, and those executables will be packaged into deviced-tools. Change-Id: I3d91265e97d4aeefc374fb7eb3a496ed7b670ce3 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 3 ++- packaging/deviced.spec | 1 + src/{ => tools}/devicectl/CMakeLists.txt | 0 src/{ => tools}/devicectl/devicectl.c | 0 src/{ => tools}/devicectl/usb.c | 0 src/{ => tools}/devicectl/usb.h | 0 src/tools/partition-switch/CMakeLists.txt | 15 +++++++++++++++ src/tools/partition-switch/partition-switch.c | 6 ++++++ 8 files changed, 24 insertions(+), 1 deletion(-) rename src/{ => tools}/devicectl/CMakeLists.txt (100%) rename src/{ => tools}/devicectl/devicectl.c (100%) rename src/{ => tools}/devicectl/usb.c (100%) rename src/{ => tools}/devicectl/usb.h (100%) create mode 100644 src/tools/partition-switch/CMakeLists.txt create mode 100644 src/tools/partition-switch/partition-switch.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 0aef649..a75ab28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -325,7 +325,8 @@ ENDIF() ADD_SUBDIRECTORY(src/battery-monitor) ADD_SUBDIRECTORY(src/libdeviced) -ADD_SUBDIRECTORY(src/devicectl) +ADD_SUBDIRECTORY(src/tools/devicectl) +ADD_SUBDIRECTORY(src/tools/partition-switch) IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on) ADD_SUBDIRECTORY(src/usb-host-ffs-test-daemon) ENDIF() diff --git a/packaging/deviced.spec b/packaging/deviced.spec index c0dc3a3..4b3a7c1 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -321,6 +321,7 @@ mv %{_libdir}/iot-headless-power.so %{_libdir}/deviced/power.so #if #{?usb_module} == on ==> always on %{_bindir}/direct_set_debug.sh %{TZ_SYS_DUMPGEN}/dump_pmstate_log.sh +%attr(2551,root,root) %{_bindir}/partition_switch #endif %files auto-test diff --git a/src/devicectl/CMakeLists.txt b/src/tools/devicectl/CMakeLists.txt similarity index 100% rename from src/devicectl/CMakeLists.txt rename to src/tools/devicectl/CMakeLists.txt diff --git a/src/devicectl/devicectl.c b/src/tools/devicectl/devicectl.c similarity index 100% rename from src/devicectl/devicectl.c rename to src/tools/devicectl/devicectl.c diff --git a/src/devicectl/usb.c b/src/tools/devicectl/usb.c similarity index 100% rename from src/devicectl/usb.c rename to src/tools/devicectl/usb.c diff --git a/src/devicectl/usb.h b/src/tools/devicectl/usb.h similarity index 100% rename from src/devicectl/usb.h rename to src/tools/devicectl/usb.h diff --git a/src/tools/partition-switch/CMakeLists.txt b/src/tools/partition-switch/CMakeLists.txt new file mode 100644 index 0000000..402eef8 --- /dev/null +++ b/src/tools/partition-switch/CMakeLists.txt @@ -0,0 +1,15 @@ +SET(CMAKE_C_FLAGS ENV${CFLAGS}) + +INCLUDE(FindPkgConfig) +pkg_check_modules(REQUIRED_PKGS REQUIRED hal-api-device) +FOREACH(flag ${REQUIRED_PKGS_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) +SET(CMAKE_C_FLAGS ${EXTRA_CFLAGS}) + +ADD_EXECUTABLE(partition_switch partition-switch.c) +SET_TARGET_PROPERTIES(partition_switch PROPERTIES COMPILE_FLAGS "-fPIE") +SET_TARGET_PROPERTIES(partition_switch PROPERTIES LINK_FLAGS "-pie") +TARGET_LINK_LIBRARIES(partition_switch ${REQUIRED_PKGS_LDFLAGS}) + +INSTALL(TARGETS partition_switch DESTINATION bin) diff --git a/src/tools/partition-switch/partition-switch.c b/src/tools/partition-switch/partition-switch.c new file mode 100644 index 0000000..d06fd02 --- /dev/null +++ b/src/tools/partition-switch/partition-switch.c @@ -0,0 +1,6 @@ +#include + +int main(int argc, char *argv[]) +{ + return hal_device_board_switch_partition(argc, argv); +} -- 2.7.4 From 71b4562490f3f8dd8b879629cffe2536de41bc26 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 19 Oct 2021 15:12:17 +0900 Subject: [PATCH 14/16] shared: move devices from core to shared Separate commonly used functions from core/devices.c to shared/devices.c. As headers for those two, core/devices.h and shared/devices.h, have the same name, take care about exact include path when you use header devices.h. Change-Id: I5ff977db01c37765a3e870c3426eeec03d2e8c5d Signed-off-by: Youngjae Cho --- plugins/iot-headed/display/core.c | 2 +- plugins/iot-headed/display/device-interface.c | 2 +- plugins/iot-headed/display/key-filter.c | 2 +- plugins/iot-headless/input/input-handler.c | 2 +- plugins/iot-headless/power/power-control.c | 2 +- plugins/mobile/display/core.c | 2 +- plugins/mobile/display/device-interface.c | 2 +- plugins/mobile/display/key-filter.c | 2 +- plugins/tv/display/core.c | 2 +- plugins/tv/display/device-interface.c | 2 +- plugins/tv/display/key-filter.c | 2 +- plugins/tv/display/state-tv.c | 2 +- plugins/wearable/display/bezel.c | 2 +- plugins/wearable/display/core.c | 2 +- plugins/wearable/display/device-interface.c | 2 +- plugins/wearable/display/display-handler.c | 2 +- plugins/wearable/display/enhance.c | 2 +- plugins/wearable/display/key-filter.c | 2 +- plugins/wearable/display/powersaver.c | 2 +- plugins/wearable/display/swim.c | 2 +- src/battery-monitor/battery-monitor.c | 2 +- src/battery/battery-time.c | 2 +- src/battery/lowbat-handler.c | 2 +- src/battery/power-supply.c | 2 +- src/board/board-info.c | 2 +- src/control/control.c | 2 +- src/core/delayed-init-notifier.c | 2 +- src/core/devices.c | 58 +-------- src/core/devices.h | 147 +---------------------- src/core/event-handler.c | 2 +- src/core/main.c | 3 +- src/core/sig-handler.c | 2 +- src/core/udev.c | 2 +- src/cpu/pmqos.c | 2 +- src/display/ambient-mode.c | 2 +- src/display/device-interface.h | 2 +- src/display/display-dbus.c | 2 +- src/display/display-ops.h | 2 +- src/display/display-signal.h | 2 +- src/dump/dump.c | 2 +- src/extcon/extcon.c | 2 +- src/input/input.c | 2 +- src/ir/ir.c | 2 +- src/led/rgb.c | 2 +- src/led/torch.c | 2 +- src/led/touch-key.c | 2 +- src/power/power-control.c | 2 +- src/power/power-handler.c | 2 +- src/proc/cpu-info.c | 2 +- src/shared/devices.c | 76 ++++++++++++ src/shared/devices.h | 163 ++++++++++++++++++++++++++ src/thermal/thermal.c | 4 +- src/time/time-handler.c | 2 +- src/touchscreen/sensitivity.c | 2 +- src/touchscreen/touchscreen.c | 2 +- src/tzip/tzip.c | 2 +- src/usb-host-test/usb-host-test.c | 2 +- src/usbhost/usb-host.c | 2 +- 58 files changed, 301 insertions(+), 254 deletions(-) create mode 100644 src/shared/devices.c create mode 100644 src/shared/devices.h diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index f462b17..a91533b 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -47,7 +47,7 @@ #include "core.h" #include "lock-detector.h" #include "display-ops.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/device-notifier.h" #include "core/udev.h" #include "shared/common.h" diff --git a/plugins/iot-headed/display/device-interface.c b/plugins/iot-headed/display/device-interface.c index 694e69b..99dba58 100644 --- a/plugins/iot-headed/display/device-interface.c +++ b/plugins/iot-headed/display/device-interface.c @@ -35,7 +35,7 @@ #include "ambient-mode.h" #include "power/power-control.h" #include "core/log.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/common.h" #include "shared/device-notifier.h" #include "util.h" diff --git a/plugins/iot-headed/display/key-filter.c b/plugins/iot-headed/display/key-filter.c index 2dbfe2a..ec07875 100644 --- a/plugins/iot-headed/display/key-filter.c +++ b/plugins/iot-headed/display/key-filter.c @@ -34,7 +34,7 @@ #include "display-actor.h" #include "display-ops.h" #include "shared/common.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/device-notifier.h" #include "shared/common.h" #include "shared/plugin.h" diff --git a/plugins/iot-headless/input/input-handler.c b/plugins/iot-headless/input/input-handler.c index cf78e23..9601f75 100644 --- a/plugins/iot-headless/input/input-handler.c +++ b/plugins/iot-headless/input/input-handler.c @@ -20,7 +20,7 @@ #include #include -#include "core/devices.h" +#include "shared/devices.h" #include "shared/log.h" #define KEYVALUE_PRESS 1 diff --git a/plugins/iot-headless/power/power-control.c b/plugins/iot-headless/power/power-control.c index ee67309..f7b477c 100644 --- a/plugins/iot-headless/power/power-control.c +++ b/plugins/iot-headless/power/power-control.c @@ -24,7 +24,7 @@ #include #include -#include "core/devices.h" +#include "shared/devices.h" #include "shared/log.h" #include "shared/device-notifier.h" diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 19d63dc..3d11cbd 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -46,7 +46,7 @@ #include "core.h" #include "lock-detector.h" #include "display-ops.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/device-notifier.h" #include "core/udev.h" #include "shared/common.h" diff --git a/plugins/mobile/display/device-interface.c b/plugins/mobile/display/device-interface.c index bb328df..c66f5bd 100644 --- a/plugins/mobile/display/device-interface.c +++ b/plugins/mobile/display/device-interface.c @@ -34,7 +34,7 @@ #include "ambient-mode.h" #include "core/log.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/common.h" #include "shared/device-notifier.h" #include "util.h" diff --git a/plugins/mobile/display/key-filter.c b/plugins/mobile/display/key-filter.c index 13bc8a6..c4d5b0a 100644 --- a/plugins/mobile/display/key-filter.c +++ b/plugins/mobile/display/key-filter.c @@ -34,7 +34,7 @@ #include "display-actor.h" #include "display-ops.h" #include "shared/common.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/device-notifier.h" #include "shared/common.h" #include "shared/plugin.h" diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index b55dea3..86807aa 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -46,7 +46,7 @@ #include "core.h" #include "lock-detector.h" #include "display-ops.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/device-notifier.h" #include "core/udev.h" #include "shared/common.h" diff --git a/plugins/tv/display/device-interface.c b/plugins/tv/display/device-interface.c index d915779..a67f924 100644 --- a/plugins/tv/display/device-interface.c +++ b/plugins/tv/display/device-interface.c @@ -34,7 +34,7 @@ #include "ambient-mode.h" #include "core/log.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/common.h" #include "shared/device-notifier.h" #include "util.h" diff --git a/plugins/tv/display/key-filter.c b/plugins/tv/display/key-filter.c index 1031fa7..7f78ef0 100644 --- a/plugins/tv/display/key-filter.c +++ b/plugins/tv/display/key-filter.c @@ -34,7 +34,7 @@ #include "display-actor.h" #include "display-ops.h" #include "shared/common.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/device-notifier.h" #include "shared/common.h" #include "shared/plugin.h" diff --git a/plugins/tv/display/state-tv.c b/plugins/tv/display/state-tv.c index 16aedab..fc6fb5b 100644 --- a/plugins/tv/display/state-tv.c +++ b/plugins/tv/display/state-tv.c @@ -23,7 +23,7 @@ #include "shared/common.h" #include "core/log.h" #include "shared/device-notifier.h" -#include "core/devices.h" +#include "shared/devices.h" #include "display/display-ops.h" #include "display/display-lock.h" #include "power/power-handler.h" diff --git a/plugins/wearable/display/bezel.c b/plugins/wearable/display/bezel.c index ea71119..b2beefa 100644 --- a/plugins/wearable/display/bezel.c +++ b/plugins/wearable/display/bezel.c @@ -19,7 +19,7 @@ #include #include -#include "core/devices.h" +#include "shared/devices.h" #include "shared/common.h" #include "shared/device-notifier.h" #include "display/util.h" diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 268fa62..5acaa70 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -47,7 +47,7 @@ #include "core.h" #include "lock-detector.h" #include "display-ops.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/device-notifier.h" #include "core/udev.h" #include "shared/common.h" diff --git a/plugins/wearable/display/device-interface.c b/plugins/wearable/display/device-interface.c index eb029de..6f4d30f 100644 --- a/plugins/wearable/display/device-interface.c +++ b/plugins/wearable/display/device-interface.c @@ -34,7 +34,7 @@ #include "ambient-mode.h" #include "core/log.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/common.h" #include "shared/device-notifier.h" #include "util.h" diff --git a/plugins/wearable/display/display-handler.c b/plugins/wearable/display/display-handler.c index 3df2b75..1310419 100644 --- a/plugins/wearable/display/display-handler.c +++ b/plugins/wearable/display/display-handler.c @@ -27,7 +27,7 @@ #include "display/core.h" #include "display/poll.h" #include "shared/common.h" -#include "core/devices.h" +#include "shared/devices.h" #include "display/display-actor.h" #include "display/display-ops.h" #include "display-info.h" diff --git a/plugins/wearable/display/enhance.c b/plugins/wearable/display/enhance.c index a5606be..56d3a04 100644 --- a/plugins/wearable/display/enhance.c +++ b/plugins/wearable/display/enhance.c @@ -25,7 +25,7 @@ #include "display/core.h" #include "display/display-ops.h" -#include "core/devices.h" +#include "shared/devices.h" #include "core/log.h" #include "shared/common.h" #include "shared/device-notifier.h" diff --git a/plugins/wearable/display/key-filter.c b/plugins/wearable/display/key-filter.c index 21bdd95..bb89700 100644 --- a/plugins/wearable/display/key-filter.c +++ b/plugins/wearable/display/key-filter.c @@ -34,7 +34,7 @@ #include "display-actor.h" #include "display-ops.h" #include "shared/common.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/device-notifier.h" #include "shared/common.h" #include "shared/plugin.h" diff --git a/plugins/wearable/display/powersaver.c b/plugins/wearable/display/powersaver.c index 56c3391..600671e 100644 --- a/plugins/wearable/display/powersaver.c +++ b/plugins/wearable/display/powersaver.c @@ -20,7 +20,7 @@ #include #include "shared/common.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/device-notifier.h" #include "core/log.h" #include "display/core.h" diff --git a/plugins/wearable/display/swim.c b/plugins/wearable/display/swim.c index cffed6f..d30eade 100644 --- a/plugins/wearable/display/swim.c +++ b/plugins/wearable/display/swim.c @@ -19,7 +19,7 @@ #include #include "shared/device-notifier.h" -#include "core/devices.h" +#include "shared/devices.h" #include "display/core.h" #include "display/util.h" #include "display/display-ops.h" diff --git a/src/battery-monitor/battery-monitor.c b/src/battery-monitor/battery-monitor.c index 46c4dad..b6d13ab 100644 --- a/src/battery-monitor/battery-monitor.c +++ b/src/battery-monitor/battery-monitor.c @@ -23,7 +23,7 @@ #include "battery-monitor.h" #include "core/log.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/common.h" #include "display/core.h" diff --git a/src/battery/battery-time.c b/src/battery/battery-time.c index 68557af..146a503 100644 --- a/src/battery/battery-time.c +++ b/src/battery/battery-time.c @@ -25,7 +25,7 @@ #include #include "shared/common.h" -#include "core/devices.h" +#include "shared/devices.h" #include "core/log.h" #include "core/udev.h" #include "display/display-ops.h" diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 3b58753..fd8cfed 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -33,7 +33,7 @@ #include "battery.h" #include "config.h" #include "core/log.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/device-notifier.h" #include "shared/common.h" #include "core/udev.h" diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 4e64746..d00b2b4 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -26,7 +26,7 @@ #include #include -#include "core/devices.h" +#include "shared/devices.h" #include "shared/device-notifier.h" #include "core/udev.h" #include "core/log.h" diff --git a/src/board/board-info.c b/src/board/board-info.c index f44264c..b6fca67 100644 --- a/src/board/board-info.c +++ b/src/board/board-info.c @@ -20,7 +20,7 @@ #include #include "core/log.h" -#include "core/devices.h" +#include "shared/devices.h" #include #define SERIAL_MAX 128 diff --git a/src/control/control.c b/src/control/control.c index b2acac8..2128a87 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -26,7 +26,7 @@ #include "core/log.h" #include "shared/common.h" -#include "core/devices.h" +#include "shared/devices.h" #include "extcon/extcon.h" #define CONTROL_HANDLER_NAME "control" diff --git a/src/core/delayed-init-notifier.c b/src/core/delayed-init-notifier.c index 53a86d1..0de44a3 100644 --- a/src/core/delayed-init-notifier.c +++ b/src/core/delayed-init-notifier.c @@ -20,7 +20,7 @@ #include "log.h" #include "shared/device-notifier.h" #include "shared/common.h" -#include "core/devices.h" +#include "shared/devices.h" #include #include diff --git a/src/core/devices.c b/src/core/devices.c index 1b36fa2..a3f9c3c 100644 --- a/src/core/devices.c +++ b/src/core/devices.c @@ -16,65 +16,12 @@ * limitations under the License. */ - -#include #include - -#include "log.h" -#include "devices.h" - -static const struct device_ops default_ops = { - DECLARE_NAME_LEN("default-ops"), -}; +#include +#include static GList *dev_head; -GList *get_device_list_head(void) -{ - return dev_head; -} - -void add_device(const struct device_ops *dev) -{ - SYS_G_LIST_APPEND(dev_head, dev); -} - -void remove_device(const struct device_ops *dev) -{ - SYS_G_LIST_REMOVE(dev_head, dev); -} - -const struct device_ops *find_device(const char *name) -{ - GList *elem; - const struct device_ops *dev; - int len; - - if (!name) { - _E("there is no name"); - return NULL; - } - - len = strlen(name); - - SYS_G_LIST_FOREACH(dev_head, elem, dev) { - if (dev->len != len) - continue; - if (dev->len == 0) - _E("%s len is not defined", dev->name); - if (!strncmp(dev->name, name, len)) - return dev; - } - - dev = &default_ops; - return dev; -} - -int check_default(const struct device_ops *dev) -{ - return (dev == &default_ops); -} - static GVariant *dbus_device_list(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) @@ -115,6 +62,7 @@ void devices_init(void *data) const struct device_ops *dev; int ret; + dev_head = get_device_list_head(); dev_head = g_list_sort(dev_head, compare_priority); SYS_G_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { diff --git a/src/core/devices.h b/src/core/devices.h index 372ef0c..5e82190 100644 --- a/src/core/devices.h +++ b/src/core/devices.h @@ -16,151 +16,10 @@ * limitations under the License. */ - -#ifndef __DEVICES_H__ -#define __DEVICES_H__ - -#include -#include - -#include "shared/common.h" - -#define DEVICE_PRIORITY_NORMAL 0 -#define DEVICE_PRIORITY_HIGH 1 - -enum device_flags { - NORMAL_MODE = 0x00000001, - AMBIENT_MODE = 0x00000002, - FORCE_OFF_MODE = 0x00000004, - CORE_LOGIC_MODE = 0x00001000, - TOUCH_SCREEN_OFF_MODE = 0x00002000, - LCD_PANEL_OFF_MODE = 0x00004000, - LCD_PHASED_TRANSIT_MODE = 0x00008000, - LCD_ON_BY_GESTURE = 0x00010000, - LCD_ON_BY_POWER_KEY = 0x00020000, - LCD_ON_BY_BACK_KEY = 0x00040000, - LCD_ON_BY_EVENT = 0x00080000, - LCD_ON_BY_TOUCH = 0x00100000, - LCD_ON_BY_BEZEL = 0x00200000, - LCD_OFF_BY_DISPLAY_DETACH = 0x01000000, - LCD_OFF_BY_POWER_KEY = 0x02000000, - LCD_OFF_BY_TIMEOUT = 0x04000000, - LCD_OFF_BY_EVENT = 0x08000000, - LCD_OFF_LATE_MODE = 0x10000000, - LCD_OFF_BY_PROXIMITY = 0x20000000, - LCD_OFF_BY_GESTURE = 0x40000000, - LCD_OFF_BY_PALM = 0x80000000, -}; - -struct device_ops { - int priority; /* high number will be initialized first */ - bool disable_auto_init; /* default: false */ - char *name; - int len; - int (*probe) (void *data); - void (*init) (void *data); - void (*exit) (void *data); - int (*start) (enum device_flags flags); - int (*stop) (enum device_flags flags); - int (*status) (void); - int (*execute) (void *data); - void (*suspend) (void); - void (*resume) (void); - int (*dump) (FILE *fp, int mode, void *dump_data); - void *dump_data; -}; - -enum device_ops_status { - DEVICE_OPS_STATUS_UNINIT, - DEVICE_OPS_STATUS_START, - DEVICE_OPS_STATUS_STOP, - DEVICE_OPS_STATUS_MAX, -}; +#ifndef __CORE_DEVICES_H__ +#define __CORE_DEVICES_H__ void devices_init(void *data); void devices_exit(void *data); -static inline int device_start(const struct device_ops *dev) -{ - if (dev && dev->start) - return dev->start(NORMAL_MODE); - - return -EINVAL; -} - -static inline int device_stop(const struct device_ops *dev) -{ - if (dev && dev->stop) - return dev->stop(NORMAL_MODE); - - return -EINVAL; -} - -static inline int device_exit(const struct device_ops *dev, void *data) -{ - if (dev && dev->exit) { - dev->exit(data); - return 0; - } - - return -EINVAL; -} - -static inline int device_execute(const struct device_ops *dev, void *data) -{ - if (dev && dev->execute) - return dev->execute(data); - - return -EINVAL; -} - -static inline int device_get_status(const struct device_ops *dev) -{ - if (dev && dev->status) - return dev->status(); - - return -EINVAL; -} - -#define DEVICE_OPS_REGISTER(dev) \ -static void __CONSTRUCTOR__ module_init(void) \ -{ \ - add_device(dev); \ -} \ -static void __DESTRUCTOR__ module_exit(void) \ -{ \ - remove_device(dev); \ -} - -GList *get_device_list_head(void); -void add_device(const struct device_ops *dev); -void remove_device(const struct device_ops *dev); - -const struct device_ops *find_device(const char *name); -int check_default(const struct device_ops *dev); - -#define NOT_SUPPORT_OPS(dev) \ - ((check_default(dev)) ? 1 : 0) - -#define FIND_DEVICE(dev, name) do { \ - if (!dev) dev = find_device(name); \ -} while (0) - -#define FIND_DEVICE_INT(dev, name) do { \ - if (!dev) dev = find_device(name); if (check_default(dev)) return -ENODEV; \ -} while (0) - -#define FIND_DEVICE_VOID(dev, name) do { \ - if (!dev) dev = find_device(name); if (check_default(dev)) return; \ -} while (0) - -#define GET_DEVICE_STATUS(name, defaults, ret) do { \ - const struct device_ops *dev; \ - dev = find_device(name); \ - ret = dev->status ? dev->status() : defaults; \ -} while (0) - -#define DECLARE_NAME_LEN(x) \ - .name = (x), \ - .len = __builtin_strlen(x) -#endif +#endif //__CORE_DEVICES_H__ diff --git a/src/core/event-handler.c b/src/core/event-handler.c index a2448bc..25219bd 100644 --- a/src/core/event-handler.c +++ b/src/core/event-handler.c @@ -22,7 +22,7 @@ #include #include "shared/common.h" -#include "devices.h" +#include "shared/devices.h" #include "shared/device-notifier.h" #include "log.h" diff --git a/src/core/main.c b/src/core/main.c index 5b3862c..fa1e4a1 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -30,11 +30,12 @@ #include "display/core.h" #include "log.h" #include "shared/common.h" -#include "devices.h" +#include "shared/devices.h" #include "power/boot.h" #include "power/power-handler.h" #include "shared/plugin.h" #include "shared/device-notifier.h" +#include "core/devices.h" #define PIDFILE_PATH "/var/run/.deviced.pid" #define WATCHDOG_REFRESH_TIME 5 diff --git a/src/core/sig-handler.c b/src/core/sig-handler.c index bf19021..fcb3cf2 100644 --- a/src/core/sig-handler.c +++ b/src/core/sig-handler.c @@ -22,7 +22,7 @@ #include #include "log.h" -#include "devices.h" +#include "shared/devices.h" #include "shared/common.h" static struct sigaction sig_child_old_act; diff --git a/src/core/udev.c b/src/core/udev.c index 8b1c581..6f28bba 100644 --- a/src/core/udev.c +++ b/src/core/udev.c @@ -25,7 +25,7 @@ #include "log.h" #include "shared/device-notifier.h" -#include "devices.h" +#include "shared/devices.h" #include "udev.h" #define KERNEL "kernel" diff --git a/src/cpu/pmqos.c b/src/cpu/pmqos.c index ad20456..2dfb44b 100644 --- a/src/cpu/pmqos.c +++ b/src/cpu/pmqos.c @@ -26,7 +26,7 @@ #include #include "core/log.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/common.h" #include "shared/device-notifier.h" diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index fbd5131..6615309 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -26,7 +26,7 @@ #include "display.h" #include "display-ops.h" #include "shared/device-notifier.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/plugin.h" #define ON "on" diff --git a/src/display/device-interface.h b/src/display/device-interface.h index f9d8b69..759ff50 100644 --- a/src/display/device-interface.h +++ b/src/display/device-interface.h @@ -26,7 +26,7 @@ #include #include -#include "core/devices.h" +#include "shared/devices.h" #define FLAG_X_DPMS 0x2 diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index acf12d6..d6d6e53 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -34,7 +34,7 @@ #include "core.h" #include "lock-detector.h" #include "shared/common.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/device-notifier.h" #include "apps/apps.h" #include "dd-display.h" diff --git a/src/display/display-ops.h b/src/display/display-ops.h index 5235ce7..7fd6d42 100644 --- a/src/display/display-ops.h +++ b/src/display/display-ops.h @@ -22,7 +22,7 @@ #include #include "shared/common.h" -#include "core/devices.h" +#include "shared/devices.h" #include "display.h" struct display_ops { diff --git a/src/display/display-signal.h b/src/display/display-signal.h index 1d0afe8..f0abbcc 100644 --- a/src/display/display-signal.h +++ b/src/display/display-signal.h @@ -23,7 +23,7 @@ #include #include "util.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/device-notifier.h" static inline long clock_gettime_to_long(void) diff --git a/src/dump/dump.c b/src/dump/dump.c index ffb6f78..a074940 100644 --- a/src/dump/dump.c +++ b/src/dump/dump.c @@ -22,7 +22,7 @@ #include "core/log.h" #include "shared/common.h" -#include "core/devices.h" +#include "shared/devices.h" #include #include diff --git a/src/extcon/extcon.c b/src/extcon/extcon.c index d0accfd..3af9f94 100644 --- a/src/extcon/extcon.c +++ b/src/extcon/extcon.c @@ -24,7 +24,7 @@ #include "core/log.h" #include "shared/common.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/device-notifier.h" #include "core/udev.h" #include "extcon.h" diff --git a/src/input/input.c b/src/input/input.c index e1b57b3..76c82b9 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -29,7 +29,7 @@ #include #include -#include "core/devices.h" +#include "shared/devices.h" #include "shared/log.h" #define SEAT_NAME "seat0" diff --git a/src/ir/ir.c b/src/ir/ir.c index f2bb1f7..cc9b052 100644 --- a/src/ir/ir.c +++ b/src/ir/ir.c @@ -20,7 +20,7 @@ #include #include #include -#include "core/devices.h" +#include "shared/devices.h" #include "shared/common.h" #include "core/log.h" diff --git a/src/led/rgb.c b/src/led/rgb.c index fad7567..a545ae5 100644 --- a/src/led/rgb.c +++ b/src/led/rgb.c @@ -29,7 +29,7 @@ #include "core/log.h" #include "shared/common.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/device-notifier.h" struct rgb_request { diff --git a/src/led/torch.c b/src/led/torch.c index a9304eb..576b609 100644 --- a/src/led/torch.c +++ b/src/led/torch.c @@ -25,7 +25,7 @@ #include #include "core/log.h" -#include "core/devices.h" +#include "shared/devices.h" #include "torch.h" #define LED_MAX_BRIGHTNESS 100 diff --git a/src/led/touch-key.c b/src/led/touch-key.c index a86eff5..b241481 100644 --- a/src/led/touch-key.c +++ b/src/led/touch-key.c @@ -23,7 +23,7 @@ #include #include "core/log.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/device-notifier.h" #include "display/core.h" #include "display/setting.h" diff --git a/src/power/power-control.c b/src/power/power-control.c index 3b3649c..749c4e5 100644 --- a/src/power/power-control.c +++ b/src/power/power-control.c @@ -33,7 +33,7 @@ #include #include "core/log.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/common.h" #include "shared/device-notifier.h" #include "vconf.h" diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 6eed091..b52bb6d 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -41,7 +41,7 @@ #include "core/log.h" #include "shared/device-notifier.h" #include "shared/common.h" -#include "core/devices.h" +#include "shared/devices.h" #include "display/poll.h" #include "display/setting.h" #include "display/core.h" diff --git a/src/proc/cpu-info.c b/src/proc/cpu-info.c index fed0c19..f516f24 100644 --- a/src/proc/cpu-info.c +++ b/src/proc/cpu-info.c @@ -21,7 +21,7 @@ #include #include "core/log.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/common.h" #define METHOD_GET_REVISION "GetRevision" diff --git a/src/shared/devices.c b/src/shared/devices.c new file mode 100644 index 0000000..66c1c9f --- /dev/null +++ b/src/shared/devices.c @@ -0,0 +1,76 @@ +/* + * deviced + * + * Copyright (c) 2012 - 2013 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. + */ + + +#include +#include + +#include "log.h" +#include "devices.h" + +static const struct device_ops default_ops = { + DECLARE_NAME_LEN("default-ops"), +}; + +static GList *dev_head; + +GList *get_device_list_head(void) +{ + return dev_head; +} + +void add_device(const struct device_ops *dev) +{ + SYS_G_LIST_APPEND(dev_head, dev); +} + +void remove_device(const struct device_ops *dev) +{ + SYS_G_LIST_REMOVE(dev_head, dev); +} + +const struct device_ops *find_device(const char *name) +{ + GList *elem; + const struct device_ops *dev; + int len; + + if (!name) { + _E("there is no name"); + return NULL; + } + + len = strlen(name); + + SYS_G_LIST_FOREACH(dev_head, elem, dev) { + if (dev->len != len) + continue; + if (dev->len == 0) + _E("%s len is not defined", dev->name); + if (!strncmp(dev->name, name, len)) + return dev; + } + + dev = &default_ops; + return dev; +} + +int check_default(const struct device_ops *dev) +{ + return (dev == &default_ops); +} diff --git a/src/shared/devices.h b/src/shared/devices.h new file mode 100644 index 0000000..a7d4469 --- /dev/null +++ b/src/shared/devices.h @@ -0,0 +1,163 @@ +/* + * deviced + * + * Copyright (c) 2012 - 2013 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 __SHARED_DEVICES_H__ +#define __SHARED_DEVICES_H__ + +#include +#include + +#include "shared/common.h" + +#define DEVICE_PRIORITY_NORMAL 0 +#define DEVICE_PRIORITY_HIGH 1 + +enum device_flags { + NORMAL_MODE = 0x00000001, + AMBIENT_MODE = 0x00000002, + FORCE_OFF_MODE = 0x00000004, + CORE_LOGIC_MODE = 0x00001000, + TOUCH_SCREEN_OFF_MODE = 0x00002000, + LCD_PANEL_OFF_MODE = 0x00004000, + LCD_PHASED_TRANSIT_MODE = 0x00008000, + LCD_ON_BY_GESTURE = 0x00010000, + LCD_ON_BY_POWER_KEY = 0x00020000, + LCD_ON_BY_BACK_KEY = 0x00040000, + LCD_ON_BY_EVENT = 0x00080000, + LCD_ON_BY_TOUCH = 0x00100000, + LCD_ON_BY_BEZEL = 0x00200000, + LCD_OFF_BY_DISPLAY_DETACH = 0x01000000, + LCD_OFF_BY_POWER_KEY = 0x02000000, + LCD_OFF_BY_TIMEOUT = 0x04000000, + LCD_OFF_BY_EVENT = 0x08000000, + LCD_OFF_LATE_MODE = 0x10000000, + LCD_OFF_BY_PROXIMITY = 0x20000000, + LCD_OFF_BY_GESTURE = 0x40000000, + LCD_OFF_BY_PALM = 0x80000000, +}; + +struct device_ops { + int priority; /* high number will be initialized first */ + bool disable_auto_init; /* default: false */ + char *name; + int len; + int (*probe) (void *data); + void (*init) (void *data); + void (*exit) (void *data); + int (*start) (enum device_flags flags); + int (*stop) (enum device_flags flags); + int (*status) (void); + int (*execute) (void *data); + void (*suspend) (void); + void (*resume) (void); + int (*dump) (FILE *fp, int mode, void *dump_data); + void *dump_data; +}; + +enum device_ops_status { + DEVICE_OPS_STATUS_UNINIT, + DEVICE_OPS_STATUS_START, + DEVICE_OPS_STATUS_STOP, + DEVICE_OPS_STATUS_MAX, +}; + +static inline int device_start(const struct device_ops *dev) +{ + if (dev && dev->start) + return dev->start(NORMAL_MODE); + + return -EINVAL; +} + +static inline int device_stop(const struct device_ops *dev) +{ + if (dev && dev->stop) + return dev->stop(NORMAL_MODE); + + return -EINVAL; +} + +static inline int device_exit(const struct device_ops *dev, void *data) +{ + if (dev && dev->exit) { + dev->exit(data); + return 0; + } + + return -EINVAL; +} + +static inline int device_execute(const struct device_ops *dev, void *data) +{ + if (dev && dev->execute) + return dev->execute(data); + + return -EINVAL; +} + +static inline int device_get_status(const struct device_ops *dev) +{ + if (dev && dev->status) + return dev->status(); + + return -EINVAL; +} + +#define DEVICE_OPS_REGISTER(dev) \ +static void __CONSTRUCTOR__ module_init(void) \ +{ \ + add_device(dev); \ +} \ +static void __DESTRUCTOR__ module_exit(void) \ +{ \ + remove_device(dev); \ +} + +GList *get_device_list_head(void); +void add_device(const struct device_ops *dev); +void remove_device(const struct device_ops *dev); + +const struct device_ops *find_device(const char *name); +int check_default(const struct device_ops *dev); + +#define NOT_SUPPORT_OPS(dev) \ + ((check_default(dev)) ? 1 : 0) + +#define FIND_DEVICE(dev, name) do { \ + if (!dev) dev = find_device(name); \ +} while (0) + +#define FIND_DEVICE_INT(dev, name) do { \ + if (!dev) dev = find_device(name); if (check_default(dev)) return -ENODEV; \ +} while (0) + +#define FIND_DEVICE_VOID(dev, name) do { \ + if (!dev) dev = find_device(name); if (check_default(dev)) return; \ +} while (0) + +#define GET_DEVICE_STATUS(name, defaults, ret) do { \ + const struct device_ops *dev; \ + dev = find_device(name); \ + ret = dev->status ? dev->status() : defaults; \ +} while (0) + +#define DECLARE_NAME_LEN(x) \ + .name = (x), \ + .len = __builtin_strlen(x) +#endif diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c index e46b190..6eee263 100644 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -24,10 +24,10 @@ #include #include "apps/apps.h" -#include "core/devices.h" +#include "shared/devices.h" #include "core/log.h" #include "shared/device-notifier.h" -#include "core/devices.h" +#include "shared/devices.h" #include "thermal.h" static bool thermal_dev_available = false; diff --git a/src/time/time-handler.c b/src/time/time-handler.c index 0482eb6..6c7fa10 100644 --- a/src/time/time-handler.c +++ b/src/time/time-handler.c @@ -34,7 +34,7 @@ #include #include "core/log.h" -#include "core/devices.h" +#include "shared/devices.h" #include "display/poll.h" #include "display/core.h" #include "display/display-ops.h" diff --git a/src/touchscreen/sensitivity.c b/src/touchscreen/sensitivity.c index d724361..95ddab2 100644 --- a/src/touchscreen/sensitivity.c +++ b/src/touchscreen/sensitivity.c @@ -21,7 +21,7 @@ #include #include -#include "core/devices.h" +#include "shared/devices.h" #include "shared/common.h" #include "core/log.h" #include "shared/device-notifier.h" diff --git a/src/touchscreen/touchscreen.c b/src/touchscreen/touchscreen.c index 6eb899c..83b78a7 100644 --- a/src/touchscreen/touchscreen.c +++ b/src/touchscreen/touchscreen.c @@ -22,7 +22,7 @@ #include #include #include -#include "core/devices.h" +#include "shared/devices.h" #include "shared/common.h" #include "core/log.h" #include "shared/device-notifier.h" diff --git a/src/tzip/tzip.c b/src/tzip/tzip.c index 94eed6a..9ae85dd 100644 --- a/src/tzip/tzip.c +++ b/src/tzip/tzip.c @@ -39,7 +39,7 @@ #include #include "core/log.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/device-notifier.h" #include "shared/common.h" #include "tzip-utility.h" diff --git a/src/usb-host-test/usb-host-test.c b/src/usb-host-test/usb-host-test.c index 349cc9d..f6cba3b 100644 --- a/src/usb-host-test/usb-host-test.c +++ b/src/usb-host-test/usb-host-test.c @@ -29,7 +29,7 @@ #include "core/log.h" #include "shared/device-notifier.h" -#include "core/devices.h" +#include "shared/devices.h" #define SYS_DUMMY_HCD_PATH "/sys/module/dummy_hcd" #define SYS_USB_FFS_PATH "/sys/kernel/config/usb_gadget/hal-gadget/functions/ffs.sdb.default" diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index 367a5b4..1af7c9c 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -28,7 +28,7 @@ #include #include "core/log.h" -#include "core/devices.h" +#include "shared/devices.h" #include "shared/device-notifier.h" #include "core/udev.h" #include "apps/apps.h" -- 2.7.4 From d606cb306c9678fe388b0507973f9e66fad3b860 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 20 Oct 2021 15:29:14 +0900 Subject: [PATCH 15/16] devices: change dev_head to global Sorting dev_head, which is returned by get_device_list_head(), changes the dev_head. But it is not applied to the original dev_head in shared/devices.c. Therefore the original dev_head is not the head of the list anymore. To avoid it, make dev_head global so that result of list operation can be applied to the original dev_head. Change-Id: I2e6ee2b3ea0ad91cb6de44c5e9f6e2d718eb727c Signed-off-by: Youngjae Cho --- src/core/devices.c | 3 --- src/dump/dump.c | 3 +-- src/shared/devices.c | 7 +------ src/shared/devices.h | 2 +- 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/src/core/devices.c b/src/core/devices.c index a3f9c3c..0dd4e15 100644 --- a/src/core/devices.c +++ b/src/core/devices.c @@ -20,8 +20,6 @@ #include #include -static GList *dev_head; - static GVariant *dbus_device_list(GDBusConnection *conn, const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) @@ -62,7 +60,6 @@ void devices_init(void *data) const struct device_ops *dev; int ret; - dev_head = get_device_list_head(); dev_head = g_list_sort(dev_head, compare_priority); SYS_G_LIST_FOREACH_SAFE(dev_head, elem, elem_n, dev) { diff --git a/src/dump/dump.c b/src/dump/dump.c index a074940..980fdd1 100644 --- a/src/dump/dump.c +++ b/src/dump/dump.c @@ -50,7 +50,6 @@ static void send_dump_signal(char *signal) static void dump_all_devices(int mode, char *path) { - GList *head = get_device_list_head(); GList *elem; FILE *fp = NULL; char fname[PATH_MAX]; @@ -68,7 +67,7 @@ static void dump_all_devices(int mode, char *path) _I("Failed to open '%s', print to DLOG.", fname); /* save dump each device ops */ - SYS_G_LIST_FOREACH(head, elem, dev) { + SYS_G_LIST_FOREACH(dev_head, elem, dev) { if (dev->dump) { _D("[%s] Get dump.", dev->name); LOG_DUMP(fp, "\n==== %s\n\n", dev->name); diff --git a/src/shared/devices.c b/src/shared/devices.c index 66c1c9f..950c1d7 100644 --- a/src/shared/devices.c +++ b/src/shared/devices.c @@ -27,12 +27,7 @@ static const struct device_ops default_ops = { DECLARE_NAME_LEN("default-ops"), }; -static GList *dev_head; - -GList *get_device_list_head(void) -{ - return dev_head; -} +GList *dev_head; void add_device(const struct device_ops *dev) { diff --git a/src/shared/devices.h b/src/shared/devices.h index a7d4469..d42c490 100644 --- a/src/shared/devices.h +++ b/src/shared/devices.h @@ -129,7 +129,7 @@ static void __DESTRUCTOR__ module_exit(void) \ remove_device(dev); \ } -GList *get_device_list_head(void); +extern GList *dev_head; void add_device(const struct device_ops *dev); void remove_device(const struct device_ops *dev); -- 2.7.4 From 9c36fb21499f06b4ca97e3013c5052dc05d39b47 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 21 Oct 2021 19:00:37 +0900 Subject: [PATCH 16/16] Remove duplicated call of gdbus_register_object_all() All of the added dbus interfaces should be registered all at once by devices_init(). Change-Id: I251049b6d1757b381eccc93cbe1117d94d47bf6d Signed-off-by: Hyotaek Shim --- src/cpu/pmqos.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/cpu/pmqos.c b/src/cpu/pmqos.c index 2dfb44b..c53dd8d 100644 --- a/src/cpu/pmqos.c +++ b/src/cpu/pmqos.c @@ -217,10 +217,6 @@ static int delayed_init_done(void *data) goto out; _I("Booting done."); - ret = gdbus_register_object_all(NULL); - if (ret < 0) - _E("Failed to register dbus method: %d", ret); - /* register notifier for each event */ register_notifier(DEVICE_NOTIFIER_CPU_BOOST_LOWBAT, pmqos_lowbat); register_notifier(DEVICE_NOTIFIER_CPU_BOOST_POWEROFF, pmqos_poweroff); -- 2.7.4