From 93d9f91c26d25dd928c3c96a96b53aef9bfb20cf Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 14 Jun 2022 13:58:11 +0900 Subject: [PATCH] callback: allow additional internal types Change-Id: I48d987304887fc36cf071c5aaed4fcb72ea9b3f4 Signed-off-by: Youngjae Cho --- include/callback.h | 5 ----- src/callback.c | 62 +++++++++++++++++++----------------------------------- 2 files changed, 22 insertions(+), 45 deletions(-) diff --git a/include/callback.h b/include/callback.h index fad0d72..662a87d 100644 --- a/include/callback.h +++ b/include/callback.h @@ -47,11 +47,6 @@ typedef enum { DEVICE_CALLBACK_MAX, } device_callback_e; -typedef enum { - DEVICE_CALLBACK_KEY_INPUT_MIN = 1000, - DEVICE_CALLBACK_KEY_INPUT_MAX = 1100, -} device_callback_internal_e; - /** * @brief Called when a device status is changed. diff --git a/src/callback.c b/src/callback.c index fd28ea6..0aefad5 100644 --- a/src/callback.c +++ b/src/callback.c @@ -42,9 +42,9 @@ struct device_cb_info { #define DEVICE_CALLBACK_KEY_INPUT_SIZE (DEVICE_CALLBACK_KEY_INPUT_MAX - DEVICE_CALLBACK_KEY_INPUT_MIN) static GList *device_cb_list[DEVICE_CALLBACK_MAX]; -static GList *device_key_cb_list; +static GList *deviced_internal_event_list; static int flash_sigid; -static int key_sigid; +static int event_sigid; //LCOV_EXCL_START Not called Callback static void battery_capacity_cb(keynode_t *key, void *data) @@ -166,7 +166,7 @@ static void flash_state_cb(GDBusConnection *conn, //LCOV_EXCL_STOP //LCOV_EXCL_START Target specific callback -static void key_input_cb(GDBusConnection *conn, +static void deviced_internal_event_cb(GDBusConnection *conn, const gchar *sender, const gchar *object, const gchar *interface, @@ -179,10 +179,8 @@ static void key_input_cb(GDBusConnection *conn, int type = 0; g_variant_get(parameters, "(i)", &type); - if (type < DEVICE_CALLBACK_KEY_INPUT_MIN || type >= DEVICE_CALLBACK_KEY_INPUT_MAX) - return; - SYS_G_LIST_FOREACH_SAFE(device_key_cb_list, elem, elem_next, cb_info) { + SYS_G_LIST_FOREACH_SAFE(deviced_internal_event_list, elem, elem_next, cb_info) { if (cb_info->type == type) cb_info->cb(type, NULL, cb_info->data); } @@ -281,18 +279,16 @@ static int register_request(int type) if (flash_sigid) return -EEXIST; return register_signal(DEVICED_BUS_NAME, - DEVICED_PATH_LED, - DEVICED_INTERFACE_LED, - SIGNAL_FLASH_STATE, flash_state_cb, &flash_sigid); + DEVICED_PATH_LED, + DEVICED_INTERFACE_LED, + SIGNAL_FLASH_STATE, flash_state_cb, &flash_sigid); default: - if (type >= DEVICE_CALLBACK_KEY_INPUT_MIN && type < DEVICE_CALLBACK_KEY_INPUT_MAX) { - if (key_sigid) - return -EEXIST; - return register_signal(DEVICED_BUS_NAME, - DEVICED_PATH_INPUT, - DEVICED_INTERFACE_INPUT, - "Key", key_input_cb, &key_sigid); - } + if (event_sigid) + return -EEXIST; + return register_signal(DEVICED_BUS_NAME, + "/Org/Tizen/System/DeviceD/Event", + "org.tizen.system.deviced.Event", + "Id", deviced_internal_event_cb, &event_sigid); break; } @@ -319,11 +315,9 @@ static int release_request(int type) return -ENOENT; return unregister_signal(&flash_sigid); default: - if (type >= DEVICE_CALLBACK_KEY_INPUT_MIN && type < DEVICE_CALLBACK_KEY_INPUT_MAX) { - if (!key_sigid) - return -ENOENT; - return unregister_signal(&key_sigid); - } + if (!event_sigid) + return -ENOENT; + return unregister_signal(&event_sigid); break; } @@ -388,11 +382,7 @@ int device_add_callback(device_callback_e enumtype, device_changed_cb cb, void * int ret_request, n; int type = (int) enumtype; - if ((type < 0 || type >= DEVICE_CALLBACK_MAX) - && (type < DEVICE_CALLBACK_KEY_INPUT_MIN || type >= DEVICE_CALLBACK_KEY_INPUT_MAX)) - return DEVICE_ERROR_INVALID_PARAMETER; - - if (!cb) + if (type < 0 || !cb) return DEVICE_ERROR_INVALID_PARAMETER; if (device_callback_check_feature_supported(type) != 0) @@ -400,10 +390,8 @@ int device_add_callback(device_callback_e enumtype, device_changed_cb cb, void * if (type >= 0 && type < DEVICE_CALLBACK_MAX) cb_list = &device_cb_list[type]; - else if (type >= DEVICE_CALLBACK_KEY_INPUT_MIN && type < DEVICE_CALLBACK_KEY_INPUT_MAX) - cb_list = &device_key_cb_list; else - return DEVICE_ERROR_INVALID_PARAMETER; + cb_list = &deviced_internal_event_list; /* check if it is the first request */ n = SYS_G_LIST_LENGTH(*cb_list); @@ -415,7 +403,7 @@ int device_add_callback(device_callback_e enumtype, device_changed_cb cb, void * /* check for the same request */ SYS_G_LIST_FOREACH_SAFE(*cb_list, elem, elem_next, cb_info) { - if (cb_info->cb == cb) + if (cb_info->type == type && cb_info->cb == cb) return DEVICE_ERROR_ALREADY_IN_PROGRESS; } @@ -441,11 +429,7 @@ int device_remove_callback(device_callback_e enumtype, device_changed_cb cb) int ret_request, n; int type = (int) enumtype; - if ((type < 0 || type >= DEVICE_CALLBACK_MAX) - && (type < DEVICE_CALLBACK_KEY_INPUT_MIN || type >= DEVICE_CALLBACK_KEY_INPUT_MAX)) - return DEVICE_ERROR_INVALID_PARAMETER; - - if (!cb) + if (type < 0 || !cb) return DEVICE_ERROR_INVALID_PARAMETER; if (device_callback_check_feature_supported(type) != 0) @@ -453,14 +437,12 @@ int device_remove_callback(device_callback_e enumtype, device_changed_cb cb) if (type >= 0 && type < DEVICE_CALLBACK_MAX) cb_list = &device_cb_list[type]; - else if (type >= DEVICE_CALLBACK_KEY_INPUT_MIN && type < DEVICE_CALLBACK_KEY_INPUT_MAX) - cb_list = &device_key_cb_list; else - return DEVICE_ERROR_INVALID_PARAMETER; + cb_list = &deviced_internal_event_list; /* search for the same element with callback */ SYS_G_LIST_FOREACH_SAFE(*cb_list, elem, elem_next, cb_info) { - if (cb_info->cb == cb) + if (cb_info->type == type && cb_info->cb == cb) break; } -- 2.7.4