From 7ea46700b445c98976c92211e17770c28b5bbb77 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 5 Oct 2021 13:30:19 +0900 Subject: [PATCH 01/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 02/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 03/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 04/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 05/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 06/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 07/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 08/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 09/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 From aa1ff5958cefabcaa80a6e2b5fc82d93eda69c6e Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 22 Oct 2021 12:42:20 +0900 Subject: [PATCH 10/16] input-handler: fix powerkey longpress timeout Change-Id: Ib6e97e5d291ca30311e4c28f680e820b4b3812b8 Signed-off-by: Youngjae Cho --- plugins/iot-headless/input/input-handler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/iot-headless/input/input-handler.c b/plugins/iot-headless/input/input-handler.c index 9601f75..bb2bb43 100644 --- a/plugins/iot-headless/input/input-handler.c +++ b/plugins/iot-headless/input/input-handler.c @@ -26,7 +26,7 @@ #define KEYVALUE_PRESS 1 #define KEYVALUE_RELEASE 0 -#define LONGPRESS_INTERVAL 3000 /* milisecond */ +#define LONGPRESS_INTERVAL 10000 /* milisecond */ static guint longpress_timer_id; -- 2.7.4 From 1cc4808c842b437f59d36c5dbd1e63923a351231 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 22 Oct 2021 16:45:27 +0900 Subject: [PATCH 11/16] Fix warning on 64bit build environment Change-Id: Ibb001db94bd0ec1b29efab43e1e38fc0ff802150 Signed-off-by: Youngjae Cho --- plugins/wearable/display/display-handler.c | 5 +++-- src/cpu/pmqos.c | 1 - src/usb/usb-debug.c | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/wearable/display/display-handler.c b/plugins/wearable/display/display-handler.c index 1310419..19517ed 100644 --- a/plugins/wearable/display/display-handler.c +++ b/plugins/wearable/display/display-handler.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "auto-brightness-sensorhub.h" @@ -50,7 +51,7 @@ static bool aod_clock_displayed; /* True while AOD screen is displayed */ static gboolean lcdon_from_aod_cb(gpointer data) { - int level = (int) data; + int level = (int)(intptr_t) data; autobrt_timer = 0; @@ -99,7 +100,7 @@ static GVariant *dbus_autobrightnesschanged(GDBusConnection *conn, * heavy loaded time and therefore make it change smoothly. */ if (aod_clock_displayed) { autobrtlevel = level; /* reserve the level, defer applying */ - autobrt_timer = g_timeout_add(200, lcdon_from_aod_cb, (gpointer)level); + autobrt_timer = g_timeout_add(200, lcdon_from_aod_cb, (gpointer)(intptr_t) level); } else { /* S_NORMAL state or LCDON from usual OFF state, not from AOD */ display_info.set_brightness_level(level); } diff --git a/src/cpu/pmqos.c b/src/cpu/pmqos.c index c53dd8d..1b36a77 100644 --- a/src/cpu/pmqos.c +++ b/src/cpu/pmqos.c @@ -207,7 +207,6 @@ static const dbus_interface_u dbus_interface = { static int delayed_init_done(void *data) { static int done; - int ret = 0; if (data == NULL) goto out; diff --git a/src/usb/usb-debug.c b/src/usb/usb-debug.c index 0681742..3f138d4 100644 --- a/src/usb/usb-debug.c +++ b/src/usb/usb-debug.c @@ -18,6 +18,7 @@ #include +#include #include #include @@ -76,7 +77,7 @@ static void usb_debug_changed(keynode_t *key, void *data) _I("USB debug mode is changed to %s.", mode ? "ON" : "OFF"); - device_notify(DEVICE_NOTIFIER_USB_DEBUG_MODE, (void *)mode); + device_notify(DEVICE_NOTIFIER_USB_DEBUG_MODE, (void *)(intptr_t) mode); } static int usb_debug_mode_changed(void *on) @@ -96,7 +97,7 @@ static int usb_debug_mode_changed(void *on) * debug off + rndis off : USB_FUNCTION_MTP | USB_FUNCTION_ACM */ - if ((int)on) { + if ((int)(intptr_t) on) { if (rndis_is_enabled) new_mode = USB_FUNCTION_ACM | USB_FUNCTION_SDB | USB_FUNCTION_RNDIS; else -- 2.7.4 From 2bc00c9396ff8ec55a0d6586fc93d2ae36ab64d8 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 25 Oct 2021 19:59:13 +0900 Subject: [PATCH 12/16] shared: add test for libdeviced-common-private This test runs automatically at build time. If the test fails, build will fail. In addition to adding the test, collect existing usb-host-test under src/tests directory. Change-Id: Id825b5747c0e9144d390687bf7d0bf9293075b72 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 19 ++--- packaging/deviced.spec | 1 + src/auto-test/CMakeLists.txt | 6 +- src/shared/CMakeLists.txt | 12 +++ src/shared/device-notifier.c | 1 + src/{core => shared}/execute.c | 0 src/shared/log.h | 4 + src/shared/plugin.c | 4 +- src/tests/shared/CMakeLists.txt | 37 +++++++++ src/tests/shared/test-bitmap.c | 95 ++++++++++++++++++++++ src/tests/shared/test-device-notifier.c | 66 +++++++++++++++ src/tests/shared/test-main.c | 24 ++++++ src/tests/shared/test-main.h | 19 +++++ src/tests/shared/test-mock.c | 20 +++++ src/tests/shared/test-mock.h | 11 +++ src/tests/shared/test-plugin.c | 65 +++++++++++++++ .../usb-host-ffs-test-daemon/CMakeLists.txt | 0 .../usb-host-ffs-test-daemon/descs_gen.c | 0 .../usb-host-ffs-test-daemon.c | 0 src/{ => tests}/usb-host-test/test_gadget.gs | 0 src/{ => tests}/usb-host-test/usb-host-test.c | 0 21 files changed, 371 insertions(+), 13 deletions(-) create mode 100644 src/shared/CMakeLists.txt rename src/{core => shared}/execute.c (100%) create mode 100644 src/tests/shared/CMakeLists.txt create mode 100644 src/tests/shared/test-bitmap.c create mode 100644 src/tests/shared/test-device-notifier.c create mode 100644 src/tests/shared/test-main.c create mode 100644 src/tests/shared/test-main.h create mode 100644 src/tests/shared/test-mock.c create mode 100644 src/tests/shared/test-mock.h create mode 100644 src/tests/shared/test-plugin.c rename src/{ => tests}/usb-host-ffs-test-daemon/CMakeLists.txt (100%) rename src/{ => tests}/usb-host-ffs-test-daemon/descs_gen.c (100%) rename src/{ => tests}/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c (100%) rename src/{ => tests}/usb-host-test/test_gadget.gs (100%) rename src/{ => tests}/usb-host-test/usb-host-test.c (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a75ab28..be87671 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,7 +69,6 @@ SET(SRCS src/core/delayed-init-notifier.c src/core/devices.c src/core/event-handler.c - src/core/execute.c src/core/log.c src/core/main.c src/core/sig-handler.c @@ -144,9 +143,9 @@ IF(TIZEN_FEATURE_CPU_MODULE STREQUAL on) ENDIF() IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on) - ADD_SOURCE(src/usb-host-test USB_HOST_TEST_SRCS) + ADD_SOURCE(src/tests/usb-host-test USB_HOST_TEST_SRCS) SET(SRCS ${SRCS} ${USB_HOST_TEST_SRCS}) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/usb-host-test/test_gadget.gs + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/usb-host-test/test_gadget.gs DESTINATION /etc/deviced/usb-host-test/) ENDIF() @@ -239,10 +238,7 @@ ENDIF() ADD_DEFINITIONS("-DDEBUG") # Build libdeviced-common-private.so -FILE(GLOB SHARED_SRC "src/shared/*.c") -ADD_LIBRARY(deviced-common-private SHARED ${SHARED_SRC}) -TARGET_LINK_LIBRARIES(deviced-common-private ${REQUIRED_PKGS_LDFLAGS}) -INSTALL(TARGETS deviced-common-private DESTINATION ${CMAKE_INSTALL_LIBDIR}) +ADD_SUBDIRECTORY(src/shared) ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) SET(deviced_LDFLAGS ${REQUIRED_PKGS_LDFLAGS}) @@ -250,7 +246,7 @@ TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${REQUIRED_PKGS_LDFLAGS} "-lrt -ldl -lm" d INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) IF(POWER_MODULE STREQUAL on) - ADD_EXECUTABLE(deviced-shutdown src/power-shutdown/shutdown.c src/shared/common.c src/core/execute.c) + ADD_EXECUTABLE(deviced-shutdown src/power-shutdown/shutdown.c src/shared/common.c src/shared/execute.c) SET(deviced-shutdown_LDFLAGS ${REQUIRED_PKGS_LDFLAGS}) TARGET_LINK_LIBRARIES(deviced-shutdown ${REQUIRED_PKGS_LDFLAGS} "-lrt -ldl -lm" deviced-common-private) INSTALL(TARGETS deviced-shutdown DESTINATION /usr/lib/systemd) @@ -265,7 +261,7 @@ IF(POWER_MODULE STREQUAL on) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/deviced-request-shutdown-exit.conf DESTINATION /usr/lib/systemd/system/systemd-exit.service.d) - ADD_EXECUTABLE(deviced-request-shutdown src/power-command/command.c src/shared/common.c src/core/execute.c) + ADD_EXECUTABLE(deviced-request-shutdown src/power-command/command.c src/shared/common.c src/shared/execute.c) SET(deviced-request-shutdown_LDFLAGS ${REQUIRED_PKGS_LDFLAGS}) TARGET_LINK_LIBRARIES(deviced-request-shutdown ${REQUIRED_PKGS_LDFLAGS} "-lrt -ldl -lm" deviced-common-private) INSTALL(TARGETS deviced-request-shutdown DESTINATION /usr/sbin) @@ -328,7 +324,7 @@ ADD_SUBDIRECTORY(src/libdeviced) 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) + ADD_SUBDIRECTORY(src/tests/usb-host-ffs-test-daemon) ENDIF() ADD_SUBDIRECTORY(src/auto-test) @@ -351,3 +347,6 @@ INSTALL_CONF(conf mobile-display) INSTALL_CONF(conf wearable-display) INSTALL_CONF(conf tv-display) INSTALL_CONF(conf iot-headed-display) + +# Tests +ADD_SUBDIRECTORY(src/tests/shared) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 4b3a7c1..cb13612 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -41,6 +41,7 @@ BuildRequires: pkgconfig(tizen-extension-client) BuildRequires: pkgconfig(tizen-dpms-client) BuildRequires: pkgconfig(zlib) BuildRequires: pkgconfig(argos_watchdog) +BuildRequires: pkgconfig(cmocka) Requires: %{name}-tools = %{version}-%{release} %{?systemd_requires} diff --git a/src/auto-test/CMakeLists.txt b/src/auto-test/CMakeLists.txt index e75088c..91db6fd 100644 --- a/src/auto-test/CMakeLists.txt +++ b/src/auto-test/CMakeLists.txt @@ -31,7 +31,11 @@ SET(SRCS INCLUDE(FindPkgConfig) pkg_check_modules(pkgs REQUIRED - capi-system-device) + capi-system-device + vconf + udev + hal-api-common + hal-api-device) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt new file mode 100644 index 0000000..44ad940 --- /dev/null +++ b/src/shared/CMakeLists.txt @@ -0,0 +1,12 @@ +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(SHARED_REQUIRED_PKGS REQUIRED + libsyscommon + dlog + bundle + capi-system-info + eventsystem) + +FILE(GLOB SHARED_SRCS "*.c") +ADD_LIBRARY(deviced-common-private SHARED ${SHARED_SRCS}) +TARGET_LINK_LIBRARIES(deviced-common-private ${SHARED_REQUIRED_PKGS_LDFLAGS}) +INSTALL(TARGETS deviced-common-private DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/src/shared/device-notifier.c b/src/shared/device-notifier.c index b755d37..08044f1 100644 --- a/src/shared/device-notifier.c +++ b/src/shared/device-notifier.c @@ -17,6 +17,7 @@ */ +#include #include "log.h" #include "device-notifier.h" #include "shared/common.h" diff --git a/src/core/execute.c b/src/shared/execute.c similarity index 100% rename from src/core/execute.c rename to src/shared/execute.c diff --git a/src/shared/log.h b/src/shared/log.h index 29b6c85..27681f2 100644 --- a/src/shared/log.h +++ b/src/shared/log.h @@ -24,6 +24,10 @@ #define ENABLE_DLOG #endif +#if defined(ENABLE_TEST) && defined(ENABLE_DLOG) +#undef ENABLE_DLOG +#endif + #define LOG_TAG "DEVICED" #include "shared/log-macro.h" diff --git a/src/shared/plugin.c b/src/shared/plugin.c index fc9b17b..d74f981 100644 --- a/src/shared/plugin.c +++ b/src/shared/plugin.c @@ -90,7 +90,7 @@ int unload_plugin(void *h) return dlclose(h); } -void load_plugins() +void load_plugins(void) { DIR *dir; void *handle = NULL; @@ -123,7 +123,7 @@ void load_plugins() return; } -void unload_plugins() +void unload_plugins(void) { GList *plugin = plgn_list; void *handle = NULL; diff --git a/src/tests/shared/CMakeLists.txt b/src/tests/shared/CMakeLists.txt new file mode 100644 index 0000000..5cd27ed --- /dev/null +++ b/src/tests/shared/CMakeLists.txt @@ -0,0 +1,37 @@ +SET(${CMAKE_C_FLAGS} $ENV{CFLAGS}) + +ADD_DEFINITIONS("-DENABLE_TEST") + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(ORIG_REQUIRED_PKGS REQUIRED + libsyscommon + bundle + capi-system-info + eventsystem) + +SET(WRAP_FLAGS "-Wl,--wrap=dlopen") +SET(WRAP_FLAGS "${WRAP_FLAGS} -Wl,--wrap=access") + +FILE(GLOB ORIG_SRCS "${CMAKE_SOURCE_DIR}/src/shared/*.c") +ADD_LIBRARY(test-shared SHARED ${ORIG_SRCS}) +SET_TARGET_PROPERTIES(test-shared PROPERTIES LINK_FLAGS ${WRAP_FLAGS}) +TARGET_LINK_LIBRARIES(test-shared ${ORIG_REQUIRED_PKGS_LDFLAGS}) + +PKG_CHECK_MODULES(TEST_REQUIRED_PKGS REQUIRED cmocka) + +LIST(APPEND TEST_DRIVERS test-bitmap.c) +LIST(APPEND TEST_DRIVERS test-device-notifier.c) +LIST(APPEND TEST_DRIVERS test-plugin.c) + +ADD_EXECUTABLE(test-main test-main.c test-mock.c ${TEST_DRIVERS}) +ADD_DEPENDENCIES(test-main test-shared) +SET_TARGET_PROPERTIES(test-main PROPERTIES COMPILE_FLAGS "-rdynamic -Wno-unused-variable") +SET_TARGET_PROPERTIES(test-main PROPERTIES LINK_FLAGS "-Wl,--rpath=${CMAKE_CURRENT_SOURCE_DIR}") +TARGET_LINK_LIBRARIES(test-main test-shared dl ${TEST_REQUIRED_PKGS_LDFLAGS}) + +REMOVE_DEFINITIONS("-DENABLE_TEST") + +ADD_CUSTOM_TARGET(run-test ALL "./test-main") +ADD_DEPENDENCIES(run-test test-main) diff --git a/src/tests/shared/test-bitmap.c b/src/tests/shared/test-bitmap.c new file mode 100644 index 0000000..23e5644 --- /dev/null +++ b/src/tests/shared/test-bitmap.c @@ -0,0 +1,95 @@ +#include + +#include "test-main.h" + +static void test_init_bitmap_p(void **state) +{ + struct dd_bitmap *bm; + + bm = init_bitmap(10); + assert_non_null(bm); + + deinit_bitmap(bm); +} + +static void test_init_bitmap_n(void **state) +{ + struct dd_bitmap *bm = NULL; + + bm = init_bitmap(0); + assert_null(bm); +} + +static void test_test_bit(void **state) +{ + struct dd_bitmap *bm; + const int bmsize = 37; + bool bit; + int i, nbit; + + bm = init_bitmap(bmsize); + assert_non_null(bm); + + for (i = 0; i < bmsize; ++i) { + bit = test_bit(bm, i); + assert_false(bit); + } + + /* count bit by setting one by one */ + for (i = 0; i < bmsize; ++i) { + set_bit(bm, i); + nbit = count_set_bit(bm); + assert_int_equal(nbit, i + 1); + } + + /* test the marginal bit */ + bit = test_bit(bm, 0); + assert_true(bit); + bit = test_bit(bm, bmsize - 1); + assert_true(bit); + bit = test_bit(bm, bmsize); + assert_false(bit); + + + /* count bit by clearing one by one */ + for (i = 0; i < bmsize; ++i) { + clear_bit(bm, i); + nbit = count_set_bit(bm); + assert_int_equal(nbit, bmsize - i - 1); + } + + deinit_bitmap(bm); +} + +static void test_all_bit(void **state) +{ + struct dd_bitmap *bm; + const int bmsize = 37; + int nbit; + + bm = init_bitmap(bmsize); + assert_non_null(bm); + + set_all_bits(bm); + nbit = count_set_bit(bm); + assert_int_equal(nbit, bmsize); + + clear_all_bits(bm); + nbit = count_set_bit(bm); + assert_int_equal(nbit, 0); + + deinit_bitmap(bm); +} + +static int run_bitmap_test(void) +{ + static const struct CMUnitTest testsuite[] = { + cmocka_unit_test(test_init_bitmap_p), + cmocka_unit_test(test_init_bitmap_n), + cmocka_unit_test(test_test_bit), + cmocka_unit_test(test_all_bit), + }; + + return cmocka_run_group_tests(testsuite, NULL, NULL); +} +ADD_TEST_FUNCTION(run_bitmap_test) diff --git a/src/tests/shared/test-device-notifier.c b/src/tests/shared/test-device-notifier.c new file mode 100644 index 0000000..bc86513 --- /dev/null +++ b/src/tests/shared/test-device-notifier.c @@ -0,0 +1,66 @@ +#include +#include +#include + +#include "test-main.h" + +static int notified; + +static int notify_callback(void *data) +{ + notified = (int)(intptr_t) data; + + return 0; +} + +static void test_device_notify_n(void **state) +{ + int retval; + + retval = register_notifier(DEVICE_NOTIFIER_MAX, NULL); + assert_int_equal(retval, -EINVAL); +} + +static void test_device_notify_p(void **state) +{ + int retval; + + notified = 999; + + retval = register_notifier(DEVICE_NOTIFIER_LCD, notify_callback); + assert_int_equal(retval, 0); + + for (int i = 3; i < 8; ++i) { + device_notify(DEVICE_NOTIFIER_LCD, (void *)(intptr_t) i); + assert_int_equal(notified, i); + } +} + +static void test_device_notify_once_p(void **state) +{ + int retval; + int value = 721; + + notified = 999; + + retval = register_notifier(DEVICE_NOTIFIER_LCD_OFF, notify_callback); + assert_int_equal(retval, 0); + + device_notify_once(DEVICE_NOTIFIER_LCD_OFF, (void *)(intptr_t) value); + assert_int_equal(notified, value); + + device_notify(DEVICE_NOTIFIER_LCD_OFF, (void *)(intptr_t) (value - 1)); + assert_int_equal(notified, value); +} + +static int run_device_notifier_test(void) +{ + static const struct CMUnitTest testsuite[] = { + cmocka_unit_test(test_device_notify_n), + cmocka_unit_test(test_device_notify_p), + cmocka_unit_test(test_device_notify_once_p), + }; + + return cmocka_run_group_tests(testsuite, NULL, NULL); +} +ADD_TEST_FUNCTION(run_device_notifier_test) diff --git a/src/tests/shared/test-main.c b/src/tests/shared/test-main.c new file mode 100644 index 0000000..cb6b11a --- /dev/null +++ b/src/tests/shared/test-main.c @@ -0,0 +1,24 @@ +#include +#include + +#include "test-main.h" + +static GList *tests; + + +void __add_test_function(test_function f) +{ + SYS_G_LIST_APPEND(tests, f); +} + +int main(int argc, char *argv[]) +{ + GList *elem; + test_function run; + int failed = 0; + + SYS_G_LIST_FOREACH(tests, elem, run) + failed += run(); + + return failed; +} diff --git a/src/tests/shared/test-main.h b/src/tests/shared/test-main.h new file mode 100644 index 0000000..dc28c6f --- /dev/null +++ b/src/tests/shared/test-main.h @@ -0,0 +1,19 @@ +#ifndef __TEST_MAIN_H__ +#define __TEST_MAIN_H__ + +#include +#include +#include +#include + +typedef int (*test_function)(void); +void __add_test_function(test_function f); + +#define ADD_TEST_FUNCTION(f) \ +__attribute__((constructor)) \ +static void add_test_function(void) \ +{ \ + __add_test_function(f); \ +} + +#endif //__TEST_MAIN_H__ diff --git a/src/tests/shared/test-mock.c b/src/tests/shared/test-mock.c new file mode 100644 index 0000000..63ea2cd --- /dev/null +++ b/src/tests/shared/test-mock.c @@ -0,0 +1,20 @@ +#include + +#include "test-main.h" +#include "test-mock.h" + +int __wrap_access(const char *pathname, int mode) +{ + return mock_type(int); +} + +void *__wrap_dlopen(const char *filename, int flags) +{ + void *ret; + + ret = mock_ptr_type(void *); + if (ret == NULL) + return ret; + + return ret; +} diff --git a/src/tests/shared/test-mock.h b/src/tests/shared/test-mock.h new file mode 100644 index 0000000..6841770 --- /dev/null +++ b/src/tests/shared/test-mock.h @@ -0,0 +1,11 @@ +#ifndef __TEST_MOCK_H__ +#define __TEST_MOCK_H__ + +#include + +#include "test-main.h" + +int __wrap_access(const char *pathname, int mode); +void *__wrap_dlopen(const char *filename, int flags); + +#endif //__TEST_MOCK_H__ diff --git a/src/tests/shared/test-plugin.c b/src/tests/shared/test-plugin.c new file mode 100644 index 0000000..69c879a --- /dev/null +++ b/src/tests/shared/test-plugin.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include + +#include "test-main.h" +#include "test-mock.h" + +static void test_load_plugin_n1(void **state) +{ + int retval; + + retval = load_plugin("", NULL); + assert_int_equal(retval, -EINVAL); +} + +static void test_load_plugin_n2(void **state) +{ + int retval; + void *handle; + + /* not existing .so */ + will_return(__wrap_access, -1); + + retval = load_plugin("display.so", &handle); + assert_int_equal(retval, -ENODEV); +} + +static void test_load_plugin_n3(void **state) +{ + int retval; + void *handle; + + will_return(__wrap_access, 0); + will_return(__wrap_dlopen, NULL); + + retval = load_plugin("something.so", &handle); + assert_int_equal(retval, -ENOENT); +} + +static void test_load_plugin_p(void **state) +{ + int retval; + void *handle; + + will_return(__wrap_access, 0); + will_return(__wrap_dlopen, (void *)(intptr_t) 0x123); + + retval = load_plugin("something.so", &handle); + assert_int_equal(retval, 0); + assert_ptr_equal(handle, 0x123); +} + +static int run_plugin_test(void) +{ + static const struct CMUnitTest testsuite[] = { + cmocka_unit_test(test_load_plugin_n1), + cmocka_unit_test(test_load_plugin_n2), + cmocka_unit_test(test_load_plugin_n3), + cmocka_unit_test(test_load_plugin_p), + }; + + return cmocka_run_group_tests(testsuite, NULL, NULL); +} +ADD_TEST_FUNCTION(run_plugin_test) diff --git a/src/usb-host-ffs-test-daemon/CMakeLists.txt b/src/tests/usb-host-ffs-test-daemon/CMakeLists.txt similarity index 100% rename from src/usb-host-ffs-test-daemon/CMakeLists.txt rename to src/tests/usb-host-ffs-test-daemon/CMakeLists.txt diff --git a/src/usb-host-ffs-test-daemon/descs_gen.c b/src/tests/usb-host-ffs-test-daemon/descs_gen.c similarity index 100% rename from src/usb-host-ffs-test-daemon/descs_gen.c rename to src/tests/usb-host-ffs-test-daemon/descs_gen.c diff --git a/src/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c b/src/tests/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c similarity index 100% rename from src/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c rename to src/tests/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c diff --git a/src/usb-host-test/test_gadget.gs b/src/tests/usb-host-test/test_gadget.gs similarity index 100% rename from src/usb-host-test/test_gadget.gs rename to src/tests/usb-host-test/test_gadget.gs diff --git a/src/usb-host-test/usb-host-test.c b/src/tests/usb-host-test/usb-host-test.c similarity index 100% rename from src/usb-host-test/usb-host-test.c rename to src/tests/usb-host-test/usb-host-test.c -- 2.7.4 From 3fb87fc42a70b0fb475234befc77b29536ff3196 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 26 Oct 2021 10:36:25 +0900 Subject: [PATCH 13/16] tests: move tests to the topmost directory Change-Id: I96af0cd9a652d2f5d1ed5467d73e57de8c63850e Signed-off-by: Youngjae Cho --- CMakeLists.txt | 10 +++++----- {src => tests}/auto-test/CMakeLists.txt | 2 +- {src => tests}/auto-test/auto-test.conf | 0 {src => tests}/auto-test/battery-monitor-test.c | 0 {src => tests}/auto-test/battery.c | 0 {src => tests}/auto-test/boot.c | 0 {src => tests}/auto-test/brightness.c | 0 {src => tests}/auto-test/config.c | 0 {src => tests}/auto-test/config.h | 0 {src => tests}/auto-test/display.c | 0 {src => tests}/auto-test/extcon.c | 0 {src => tests}/auto-test/ir.c | 0 {src => tests}/auto-test/led.c | 0 {src => tests}/auto-test/main.c | 0 {src => tests}/auto-test/pmqos.c | 0 {src => tests}/auto-test/power.c | 0 {src => tests}/auto-test/proc.c | 0 {src => tests}/auto-test/result.c | 0 {src => tests}/auto-test/test.c | 0 {src => tests}/auto-test/test.h | 0 {src => tests}/auto-test/test_dbus_interface.c | 0 {src => tests}/auto-test/test_dbus_interface.h | 0 {src => tests}/auto-test/time.c | 0 {src => tests}/auto-test/touchscreen.c | 0 {src => tests}/auto-test/udev.c | 0 .../deviced-common-private-test}/CMakeLists.txt | 1 + .../shared => tests/deviced-common-private-test}/test-bitmap.c | 0 .../deviced-common-private-test}/test-device-notifier.c | 0 .../shared => tests/deviced-common-private-test}/test-main.c | 0 .../shared => tests/deviced-common-private-test}/test-main.h | 0 .../shared => tests/deviced-common-private-test}/test-mock.c | 0 .../shared => tests/deviced-common-private-test}/test-mock.h | 0 .../shared => tests/deviced-common-private-test}/test-plugin.c | 0 {src/tests => tests}/usb-host-ffs-test-daemon/CMakeLists.txt | 0 {src/tests => tests}/usb-host-ffs-test-daemon/descs_gen.c | 0 .../usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c | 0 {src/tests => tests}/usb-host-test/test_gadget.gs | 0 {src/tests => tests}/usb-host-test/usb-host-test.c | 0 38 files changed, 7 insertions(+), 6 deletions(-) rename {src => tests}/auto-test/CMakeLists.txt (95%) rename {src => tests}/auto-test/auto-test.conf (100%) rename {src => tests}/auto-test/battery-monitor-test.c (100%) rename {src => tests}/auto-test/battery.c (100%) rename {src => tests}/auto-test/boot.c (100%) rename {src => tests}/auto-test/brightness.c (100%) rename {src => tests}/auto-test/config.c (100%) rename {src => tests}/auto-test/config.h (100%) rename {src => tests}/auto-test/display.c (100%) rename {src => tests}/auto-test/extcon.c (100%) rename {src => tests}/auto-test/ir.c (100%) rename {src => tests}/auto-test/led.c (100%) rename {src => tests}/auto-test/main.c (100%) rename {src => tests}/auto-test/pmqos.c (100%) rename {src => tests}/auto-test/power.c (100%) rename {src => tests}/auto-test/proc.c (100%) rename {src => tests}/auto-test/result.c (100%) rename {src => tests}/auto-test/test.c (100%) rename {src => tests}/auto-test/test.h (100%) rename {src => tests}/auto-test/test_dbus_interface.c (100%) rename {src => tests}/auto-test/test_dbus_interface.h (100%) rename {src => tests}/auto-test/time.c (100%) rename {src => tests}/auto-test/touchscreen.c (100%) rename {src => tests}/auto-test/udev.c (100%) rename {src/tests/shared => tests/deviced-common-private-test}/CMakeLists.txt (96%) rename {src/tests/shared => tests/deviced-common-private-test}/test-bitmap.c (100%) rename {src/tests/shared => tests/deviced-common-private-test}/test-device-notifier.c (100%) rename {src/tests/shared => tests/deviced-common-private-test}/test-main.c (100%) rename {src/tests/shared => tests/deviced-common-private-test}/test-main.h (100%) rename {src/tests/shared => tests/deviced-common-private-test}/test-mock.c (100%) rename {src/tests/shared => tests/deviced-common-private-test}/test-mock.h (100%) rename {src/tests/shared => tests/deviced-common-private-test}/test-plugin.c (100%) rename {src/tests => tests}/usb-host-ffs-test-daemon/CMakeLists.txt (100%) rename {src/tests => tests}/usb-host-ffs-test-daemon/descs_gen.c (100%) rename {src/tests => tests}/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c (100%) rename {src/tests => tests}/usb-host-test/test_gadget.gs (100%) rename {src/tests => tests}/usb-host-test/usb-host-test.c (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index be87671..926fcbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,9 +143,9 @@ IF(TIZEN_FEATURE_CPU_MODULE STREQUAL on) ENDIF() IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on) - ADD_SOURCE(src/tests/usb-host-test USB_HOST_TEST_SRCS) + ADD_SOURCE(tests/usb-host-test USB_HOST_TEST_SRCS) SET(SRCS ${SRCS} ${USB_HOST_TEST_SRCS}) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/tests/usb-host-test/test_gadget.gs + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/tests/usb-host-test/test_gadget.gs DESTINATION /etc/deviced/usb-host-test/) ENDIF() @@ -324,10 +324,9 @@ ADD_SUBDIRECTORY(src/libdeviced) ADD_SUBDIRECTORY(src/tools/devicectl) ADD_SUBDIRECTORY(src/tools/partition-switch) IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on) - ADD_SUBDIRECTORY(src/tests/usb-host-ffs-test-daemon) + ADD_SUBDIRECTORY(tests/usb-host-ffs-test-daemon) ENDIF() -ADD_SUBDIRECTORY(src/auto-test) # Plugins ADD_SOURCE(src/display DISPLAY_SRCS) @@ -349,4 +348,5 @@ INSTALL_CONF(conf tv-display) INSTALL_CONF(conf iot-headed-display) # Tests -ADD_SUBDIRECTORY(src/tests/shared) +ADD_SUBDIRECTORY(tests/deviced-common-private-test) +ADD_SUBDIRECTORY(tests/auto-test) diff --git a/src/auto-test/CMakeLists.txt b/tests/auto-test/CMakeLists.txt similarity index 95% rename from src/auto-test/CMakeLists.txt rename to tests/auto-test/CMakeLists.txt index 91db6fd..341c366 100644 --- a/src/auto-test/CMakeLists.txt +++ b/tests/auto-test/CMakeLists.txt @@ -1,7 +1,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(deviced-auto-test C) -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src) IF("$ENV{CFLAGS}" MATCHES "-DTIZEN_ENGINEER_MODE") OPTION(USE_ENGINEER_MODE "Use Engineer mode" ON) diff --git a/src/auto-test/auto-test.conf b/tests/auto-test/auto-test.conf similarity index 100% rename from src/auto-test/auto-test.conf rename to tests/auto-test/auto-test.conf diff --git a/src/auto-test/battery-monitor-test.c b/tests/auto-test/battery-monitor-test.c similarity index 100% rename from src/auto-test/battery-monitor-test.c rename to tests/auto-test/battery-monitor-test.c diff --git a/src/auto-test/battery.c b/tests/auto-test/battery.c similarity index 100% rename from src/auto-test/battery.c rename to tests/auto-test/battery.c diff --git a/src/auto-test/boot.c b/tests/auto-test/boot.c similarity index 100% rename from src/auto-test/boot.c rename to tests/auto-test/boot.c diff --git a/src/auto-test/brightness.c b/tests/auto-test/brightness.c similarity index 100% rename from src/auto-test/brightness.c rename to tests/auto-test/brightness.c diff --git a/src/auto-test/config.c b/tests/auto-test/config.c similarity index 100% rename from src/auto-test/config.c rename to tests/auto-test/config.c diff --git a/src/auto-test/config.h b/tests/auto-test/config.h similarity index 100% rename from src/auto-test/config.h rename to tests/auto-test/config.h diff --git a/src/auto-test/display.c b/tests/auto-test/display.c similarity index 100% rename from src/auto-test/display.c rename to tests/auto-test/display.c diff --git a/src/auto-test/extcon.c b/tests/auto-test/extcon.c similarity index 100% rename from src/auto-test/extcon.c rename to tests/auto-test/extcon.c diff --git a/src/auto-test/ir.c b/tests/auto-test/ir.c similarity index 100% rename from src/auto-test/ir.c rename to tests/auto-test/ir.c diff --git a/src/auto-test/led.c b/tests/auto-test/led.c similarity index 100% rename from src/auto-test/led.c rename to tests/auto-test/led.c diff --git a/src/auto-test/main.c b/tests/auto-test/main.c similarity index 100% rename from src/auto-test/main.c rename to tests/auto-test/main.c diff --git a/src/auto-test/pmqos.c b/tests/auto-test/pmqos.c similarity index 100% rename from src/auto-test/pmqos.c rename to tests/auto-test/pmqos.c diff --git a/src/auto-test/power.c b/tests/auto-test/power.c similarity index 100% rename from src/auto-test/power.c rename to tests/auto-test/power.c diff --git a/src/auto-test/proc.c b/tests/auto-test/proc.c similarity index 100% rename from src/auto-test/proc.c rename to tests/auto-test/proc.c diff --git a/src/auto-test/result.c b/tests/auto-test/result.c similarity index 100% rename from src/auto-test/result.c rename to tests/auto-test/result.c diff --git a/src/auto-test/test.c b/tests/auto-test/test.c similarity index 100% rename from src/auto-test/test.c rename to tests/auto-test/test.c diff --git a/src/auto-test/test.h b/tests/auto-test/test.h similarity index 100% rename from src/auto-test/test.h rename to tests/auto-test/test.h diff --git a/src/auto-test/test_dbus_interface.c b/tests/auto-test/test_dbus_interface.c similarity index 100% rename from src/auto-test/test_dbus_interface.c rename to tests/auto-test/test_dbus_interface.c diff --git a/src/auto-test/test_dbus_interface.h b/tests/auto-test/test_dbus_interface.h similarity index 100% rename from src/auto-test/test_dbus_interface.h rename to tests/auto-test/test_dbus_interface.h diff --git a/src/auto-test/time.c b/tests/auto-test/time.c similarity index 100% rename from src/auto-test/time.c rename to tests/auto-test/time.c diff --git a/src/auto-test/touchscreen.c b/tests/auto-test/touchscreen.c similarity index 100% rename from src/auto-test/touchscreen.c rename to tests/auto-test/touchscreen.c diff --git a/src/auto-test/udev.c b/tests/auto-test/udev.c similarity index 100% rename from src/auto-test/udev.c rename to tests/auto-test/udev.c diff --git a/src/tests/shared/CMakeLists.txt b/tests/deviced-common-private-test/CMakeLists.txt similarity index 96% rename from src/tests/shared/CMakeLists.txt rename to tests/deviced-common-private-test/CMakeLists.txt index 5cd27ed..7c3323d 100644 --- a/src/tests/shared/CMakeLists.txt +++ b/tests/deviced-common-private-test/CMakeLists.txt @@ -1,3 +1,4 @@ +# test for libdeviced-common-private.so SET(${CMAKE_C_FLAGS} $ENV{CFLAGS}) ADD_DEFINITIONS("-DENABLE_TEST") diff --git a/src/tests/shared/test-bitmap.c b/tests/deviced-common-private-test/test-bitmap.c similarity index 100% rename from src/tests/shared/test-bitmap.c rename to tests/deviced-common-private-test/test-bitmap.c diff --git a/src/tests/shared/test-device-notifier.c b/tests/deviced-common-private-test/test-device-notifier.c similarity index 100% rename from src/tests/shared/test-device-notifier.c rename to tests/deviced-common-private-test/test-device-notifier.c diff --git a/src/tests/shared/test-main.c b/tests/deviced-common-private-test/test-main.c similarity index 100% rename from src/tests/shared/test-main.c rename to tests/deviced-common-private-test/test-main.c diff --git a/src/tests/shared/test-main.h b/tests/deviced-common-private-test/test-main.h similarity index 100% rename from src/tests/shared/test-main.h rename to tests/deviced-common-private-test/test-main.h diff --git a/src/tests/shared/test-mock.c b/tests/deviced-common-private-test/test-mock.c similarity index 100% rename from src/tests/shared/test-mock.c rename to tests/deviced-common-private-test/test-mock.c diff --git a/src/tests/shared/test-mock.h b/tests/deviced-common-private-test/test-mock.h similarity index 100% rename from src/tests/shared/test-mock.h rename to tests/deviced-common-private-test/test-mock.h diff --git a/src/tests/shared/test-plugin.c b/tests/deviced-common-private-test/test-plugin.c similarity index 100% rename from src/tests/shared/test-plugin.c rename to tests/deviced-common-private-test/test-plugin.c diff --git a/src/tests/usb-host-ffs-test-daemon/CMakeLists.txt b/tests/usb-host-ffs-test-daemon/CMakeLists.txt similarity index 100% rename from src/tests/usb-host-ffs-test-daemon/CMakeLists.txt rename to tests/usb-host-ffs-test-daemon/CMakeLists.txt diff --git a/src/tests/usb-host-ffs-test-daemon/descs_gen.c b/tests/usb-host-ffs-test-daemon/descs_gen.c similarity index 100% rename from src/tests/usb-host-ffs-test-daemon/descs_gen.c rename to tests/usb-host-ffs-test-daemon/descs_gen.c diff --git a/src/tests/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c b/tests/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c similarity index 100% rename from src/tests/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c rename to tests/usb-host-ffs-test-daemon/usb-host-ffs-test-daemon.c diff --git a/src/tests/usb-host-test/test_gadget.gs b/tests/usb-host-test/test_gadget.gs similarity index 100% rename from src/tests/usb-host-test/test_gadget.gs rename to tests/usb-host-test/test_gadget.gs diff --git a/src/tests/usb-host-test/usb-host-test.c b/tests/usb-host-test/usb-host-test.c similarity index 100% rename from src/tests/usb-host-test/usb-host-test.c rename to tests/usb-host-test/usb-host-test.c -- 2.7.4 From 34132c4276782ae16d6d1ebe491d5a0976ad6f24 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 1 Nov 2021 10:21:53 +0900 Subject: [PATCH 14/16] Remove unnecessaries from iot-headless plugin package Change-Id: I89bf3db908b078c1609284e1c650cda7a02ead4a Signed-off-by: Youngjae Cho --- packaging/deviced.spec | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index cb13612..3c80351 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -255,9 +255,7 @@ 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 mv %{_libdir}/iot-headless-input-handler.so %{_libdir}/deviced/input-handler.so mv %{_libdir}/iot-headless-power.so %{_libdir}/deviced/power.so @@ -377,8 +375,6 @@ mv %{_libdir}/iot-headless-power.so %{_libdir}/deviced/power.so %manifest deviced.manifest %license LICENSE.Apache-2.0 %defattr(-,root,root,-) -%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 -- 2.7.4 From b6fc94e23753ed3e4b5d16ece7bebfc06d71e292 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 1 Nov 2021 15:31:39 +0900 Subject: [PATCH 15/16] input: make input module initialize plugin input-handler Change-Id: Ia72cd8f207b782da369e4161e1bd9269045e19e6 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 2 +- plugins/iot-headed/display/core.c | 5 +-- plugins/iot-headless/input/input-handler.c | 55 +++++++++++------------------- plugins/mobile/display/core.c | 5 +-- plugins/tv/display/core.c | 5 +-- plugins/wearable/display/core.c | 5 +-- src/display/display-input.c | 35 ++++++++----------- src/display/poll.h | 3 -- src/input/input.c | 38 ++++++++++++--------- src/shared/common.c | 1 - src/shared/devices.c | 11 ++++++ src/shared/devices.h | 1 + src/shared/plugin.c | 2 -- src/tzip/tzip-utility.c | 1 - src/tzip/tzip.c | 1 - src/usbhost/usb-host.c | 2 -- 16 files changed, 74 insertions(+), 98 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 926fcbc..15d8125 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -205,7 +205,7 @@ FOREACH(flag ${REQUIRED_PKGS_CFLAGS}) ENDFOREACH(flag) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIE -rdynamic") -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions -D_GNU_SOURCE") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") SET(CMAKE_EXE_LINKER_FLAGS "-pie") diff --git a/plugins/iot-headed/display/core.c b/plugins/iot-headed/display/core.c index a91533b..c772d9e 100644 --- a/plugins/iot-headed/display/core.c +++ b/plugins/iot-headed/display/core.c @@ -2042,9 +2042,7 @@ static int display_probe(void *data) static int input_init_handler(void) { if (!display_conf.input_support) - return 0; - - g_idle_add(display_input_init, NULL); + remove_device_by_devname("input"); return 0; } @@ -2256,7 +2254,6 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); - display_input_exit(); break; } } diff --git a/plugins/iot-headless/input/input-handler.c b/plugins/iot-headless/input/input-handler.c index bb2bb43..ae25482 100644 --- a/plugins/iot-headless/input/input-handler.c +++ b/plugins/iot-headless/input/input-handler.c @@ -20,6 +20,7 @@ #include #include +#include "shared/common.h" #include "shared/devices.h" #include "shared/log.h" @@ -28,6 +29,7 @@ #define LONGPRESS_INTERVAL 10000 /* milisecond */ +static int longpress_interval = LONGPRESS_INTERVAL; static guint longpress_timer_id; static gboolean longpressed_cb(void *data) @@ -55,7 +57,7 @@ static void start_longpress_timer(void) longpress_timer_id = 0; } - longpress_timer_id = g_timeout_add(LONGPRESS_INTERVAL, longpressed_cb, NULL); + longpress_timer_id = g_timeout_add(longpress_interval, longpressed_cb, NULL); } static void stop_longpress_timer(void) @@ -66,14 +68,19 @@ static void stop_longpress_timer(void) } } -/* poweroff if power button is pressed longer than LONGPRESS_INTERVAL */ -static void input_event_handler(struct libinput_event *e) +static int input_handler_execute(void *data) { + struct libinput_event *e; struct libinput_event_keyboard *ek; int keycode, keyvalue; + if (!data) + return 0; + + e = (struct libinput_event *) data; + if (libinput_event_get_type(e) != LIBINPUT_EVENT_KEYBOARD_KEY) - return; + return 0; ek = libinput_event_get_keyboard_event(e); keycode = libinput_event_keyboard_get_key(ek); @@ -87,42 +94,20 @@ static void input_event_handler(struct libinput_event *e) 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); - } + return 0; } -static void input_event_handler_exit(void *data) +static void input_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->exit) - input_device->exit(NULL); + // TODO: parse system config, which set holding time of short/long key } -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, +static const struct device_ops input_handler_device_ops = { + DECLARE_NAME_LEN("input-handler"), + .init = input_handler_init, + .execute = input_handler_execute, + .disable_auto_init = true, }; -DEVICE_OPS_REGISTER(&input_event_handler_device_ops); +DEVICE_OPS_REGISTER(&input_handler_device_ops) diff --git a/plugins/mobile/display/core.c b/plugins/mobile/display/core.c index 3d11cbd..6b3aad8 100644 --- a/plugins/mobile/display/core.c +++ b/plugins/mobile/display/core.c @@ -2048,9 +2048,7 @@ static int display_probe(void *data) static int input_init_handler(void) { if (!display_conf.input_support) - return 0; - - g_idle_add(display_input_init, NULL); + remove_device_by_devname("input"); return 0; } @@ -2262,7 +2260,6 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); - display_input_exit(); break; } } diff --git a/plugins/tv/display/core.c b/plugins/tv/display/core.c index 86807aa..3f9357d 100644 --- a/plugins/tv/display/core.c +++ b/plugins/tv/display/core.c @@ -2039,9 +2039,7 @@ static int display_probe(void *data) static int input_init_handler(void) { if (!display_conf.input_support) - return 0; - - g_idle_add(display_input_init, NULL); + remove_device_by_devname("input"); return 0; } @@ -2253,7 +2251,6 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); - display_input_exit(); break; } } diff --git a/plugins/wearable/display/core.c b/plugins/wearable/display/core.c index 5acaa70..2ff8cf6 100644 --- a/plugins/wearable/display/core.c +++ b/plugins/wearable/display/core.c @@ -2331,9 +2331,7 @@ static int display_probe(void *data) static int input_init_handler(void) { if (!display_conf.input_support) - return 0; - - g_idle_add(display_input_init, NULL); + remove_device_by_devname("input"); return 0; } @@ -2584,7 +2582,6 @@ static void display_exit(void *data) unregister_notifier(DEVICE_NOTIFIER_BATTERY_HEALTH, battery_health_changed); unregister_notifier(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS, display_brightness_changed); - display_input_exit(); break; } } diff --git a/src/display/display-input.c b/src/display/display-input.c index 0e1d4c6..05fcde6 100644 --- a/src/display/display-input.c +++ b/src/display/display-input.c @@ -30,7 +30,7 @@ #define SEAT_NAME "seat0" -static void process_event(struct libinput_event *ev) +static void process_input(struct libinput_event *ev) { static const struct device_ops *display_device_ops; struct input_event input; @@ -105,30 +105,25 @@ static void process_event(struct libinput_event *ev) poll_callback(INPUT_POLL_EVENT, NULL); } -gboolean display_input_init(gpointer data) +static int input_handler_execute(void *data) { - static const struct device_ops *input_device; - - input_device = find_device("input"); - if (check_default(input_device)) - return G_SOURCE_REMOVE; + if (!data) + return 0; - _D("[%s] Initialization.", input_device->name); - if (input_device->init) - input_device->init(process_event); + process_input(data); - return G_SOURCE_REMOVE; + return 0; } -int display_input_exit(void) +static void input_handler_init(void *data) { - static const struct device_ops *input_device; - - input_device = find_device("input"); - if (check_default(input_device)) - return 0; +} - input_device->exit(NULL); +static const struct device_ops input_handler_device_ops = { + DECLARE_NAME_LEN("input-handler"), + .init = input_handler_init, + .execute = input_handler_execute, + .disable_auto_init = true, +}; - return 0; -} +DEVICE_OPS_REGISTER(&input_handler_device_ops) diff --git a/src/display/poll.h b/src/display/poll.h index 096316d..aed0736 100644 --- a/src/display/poll.h +++ b/src/display/poll.h @@ -143,9 +143,6 @@ enum cond_flags_e { #define RESET_TIMER_STR "resettimer" #define KEEP_TIMER_STR "keeptimer" -gboolean display_input_init(gpointer data); -int display_input_exit(void); - /** * @} */ diff --git a/src/input/input.c b/src/input/input.c index 76c82b9..f39e7b8 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "shared/devices.h" #include "shared/log.h" @@ -38,21 +39,23 @@ static struct udev *udev; static struct libinput *li; static guint efd; -static void (*input_event_handler) (struct libinput_event *); +static const struct device_ops *input_handler; -static gboolean input_handler(gint fd, GIOCondition cond, void *data) +static gboolean input_callback(gint fd, GIOCondition cond, void *data) { struct libinput_event *ev; - struct libinput *input = (struct libinput *)data; + struct libinput *input = (struct libinput *) data; - if (!input || !input_event_handler) + if (!input_handler) + return G_SOURCE_REMOVE; + + if (!input) return G_SOURCE_CONTINUE; libinput_dispatch(input); while ((ev = libinput_get_event(input))) { - input_event_handler(ev); - + input_handler->execute(ev); libinput_event_destroy(ev); libinput_dispatch(input); } @@ -93,13 +96,15 @@ static void input_init(void *data) int ret; int fd; - if (!data) { - _E("there is no handler for input event"); + /* load plugin input handler */ + input_handler = find_device("input-handler"); + if (check_default(input_handler) || input_handler->execute == NULL) { + input_handler = NULL; return; } - /* registering input event handler */ - input_event_handler = data; + if (input_handler->init) + input_handler->init(NULL); udev = udev_new(); if (!udev) { @@ -125,9 +130,9 @@ static void input_init(void *data) return; } - /* add to poll handler */ + /* add poll callback */ efd = g_unix_fd_add(fd, G_IO_IN, - input_handler, + input_callback, (void *)((intptr_t)li)); if (!efd) { _E("fail to g_unix_fd_add"); @@ -150,16 +155,17 @@ static void input_exit(void *data) if (udev) udev_unref(udev); - input_event_handler = NULL; + if (input_handler && input_handler->exit) + input_handler->exit(NULL); + + input_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, + .priority = -1, /* initialize at last */ }; DEVICE_OPS_REGISTER(&input_device_ops) diff --git a/src/shared/common.c b/src/shared/common.c index af6e980..c7f4bb0 100644 --- a/src/shared/common.c +++ b/src/shared/common.c @@ -16,7 +16,6 @@ * limitations under the License. */ -#define _GNU_SOURCE #include #include #include diff --git a/src/shared/devices.c b/src/shared/devices.c index 950c1d7..f3884a1 100644 --- a/src/shared/devices.c +++ b/src/shared/devices.c @@ -39,6 +39,17 @@ void remove_device(const struct device_ops *dev) SYS_G_LIST_REMOVE(dev_head, dev); } +void remove_device_by_devname(const char *devname) +{ + const struct device_ops *dev = find_device(devname); + + if (check_default(dev)) + return; + + _D("remove device=%s", devname); + remove_device(dev); +} + const struct device_ops *find_device(const char *name) { GList *elem; diff --git a/src/shared/devices.h b/src/shared/devices.h index d42c490..b0feb6a 100644 --- a/src/shared/devices.h +++ b/src/shared/devices.h @@ -132,6 +132,7 @@ static void __DESTRUCTOR__ module_exit(void) \ extern GList *dev_head; void add_device(const struct device_ops *dev); void remove_device(const struct device_ops *dev); +void remove_device_by_devname(const char *devname); const struct device_ops *find_device(const char *name); int check_default(const struct device_ops *dev); diff --git a/src/shared/plugin.c b/src/shared/plugin.c index d74f981..db8725c 100644 --- a/src/shared/plugin.c +++ b/src/shared/plugin.c @@ -16,8 +16,6 @@ * limitations under the License. */ -#define _GNU_SOURCE - #include #include #include diff --git a/src/tzip/tzip-utility.c b/src/tzip/tzip-utility.c index 8e749e3..671163e 100644 --- a/src/tzip/tzip-utility.c +++ b/src/tzip/tzip-utility.c @@ -16,7 +16,6 @@ * limitations under the License. */ -#define _GNU_SOURCE #include #include #include diff --git a/src/tzip/tzip.c b/src/tzip/tzip.c index 9ae85dd..d99ed56 100644 --- a/src/tzip/tzip.c +++ b/src/tzip/tzip.c @@ -18,7 +18,6 @@ #define FUSE_USE_VERSION 26 -#define _GNU_SOURCE #include #include #include diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index 1af7c9c..9155fb5 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -15,8 +15,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#define _GNU_SOURCE - #include #include #include -- 2.7.4 From 31cb94dd663b45e3d905e31b20a97bc145d9d769 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 22 Oct 2021 16:32:21 +0900 Subject: [PATCH 16/16] input: support powerkey shortpress for iot-headless Change-Id: I0451471b0b17746e30e159c7ac5e0e7395fd39e1 Signed-off-by: Youngjae Cho --- plugins/iot-headless/input/input-handler.c | 41 +++++++++++++++++++++++++++--- src/shared/device-notifier.h | 1 + 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/plugins/iot-headless/input/input-handler.c b/plugins/iot-headless/input/input-handler.c index ae25482..69b619e 100644 --- a/plugins/iot-headless/input/input-handler.c +++ b/plugins/iot-headless/input/input-handler.c @@ -22,16 +22,27 @@ #include "shared/common.h" #include "shared/devices.h" +#include "shared/device-notifier.h" #include "shared/log.h" #define KEYVALUE_PRESS 1 #define KEYVALUE_RELEASE 0 #define LONGPRESS_INTERVAL 10000 /* milisecond */ +#define SHORTPRESS_INTERVAL 3000 /* milisecond */ static int longpress_interval = LONGPRESS_INTERVAL; +static int shortpress_interval = SHORTPRESS_INTERVAL; +static guint shortpress_timer_id; static guint longpress_timer_id; +static gboolean shortpressed_cb(void *data) +{ + shortpress_timer_id = 0; + + return G_SOURCE_REMOVE; +} + static gboolean longpressed_cb(void *data) { const struct device_ops *power_device; @@ -43,13 +54,23 @@ static gboolean longpressed_cb(void *data) return G_SOURCE_REMOVE; if (power_device->execute) { - _D("powerkey long pressed, start poweroff sequence"); + _D("powerkey long pressed"); power_device->execute("poweroff"); } return G_SOURCE_REMOVE; } +static void start_shortpress_timer(void) +{ + if (shortpress_timer_id) { + g_source_remove(shortpress_timer_id); + shortpress_timer_id = 0; + } + + shortpress_timer_id = g_timeout_add(shortpress_interval, shortpressed_cb, NULL); +} + static void start_longpress_timer(void) { if (longpress_timer_id) { @@ -60,6 +81,17 @@ static void start_longpress_timer(void) longpress_timer_id = g_timeout_add(longpress_interval, longpressed_cb, NULL); } +static void stop_shortpress_timer(void) +{ + if (shortpress_timer_id) { + g_source_remove(shortpress_timer_id); + shortpress_timer_id = 0; + } else { + _D("powerkey short pressed"); + device_notify(DEVICE_NOTIFIER_KEY_SHORTPRESS, (void *)(intptr_t) KEY_POWER); + } +} + static void stop_longpress_timer(void) { if (longpress_timer_id) { @@ -89,10 +121,13 @@ static int input_handler_execute(void *data) _D("key input: code=%d, value=%d", keycode, keyvalue); if (keycode == KEY_POWER) { - if (keyvalue == KEYVALUE_PRESS) + if (keyvalue == KEYVALUE_PRESS) { + start_shortpress_timer(); start_longpress_timer(); - else if (keyvalue == KEYVALUE_RELEASE) + } else if (keyvalue == KEYVALUE_RELEASE) { + stop_shortpress_timer(); stop_longpress_timer(); + } } return 0; diff --git a/src/shared/device-notifier.h b/src/shared/device-notifier.h index ba597b1..72d2ed8 100644 --- a/src/shared/device-notifier.h +++ b/src/shared/device-notifier.h @@ -61,6 +61,7 @@ enum device_notifier_type { DEVICE_NOTIFIER_ULTRAPOWERSAVING, DEVICE_NOTIFIER_EXTCON_COUNT, DEVICE_NOTIFIER_REQUEST_WAKE_LOCK, + DEVICE_NOTIFIER_KEY_SHORTPRESS, /* hold down a key for a short duration */ DEVICE_NOTIFIER_REQUEST_WAKE_UNLOCK, DEVICE_NOTIFIER_MAX, }; -- 2.7.4