struct device_cb_info {
device_changed_cb cb;
void *data;
+ int type;
};
+#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 int flash_sigid;
+static int key_sigid;
//LCOV_EXCL_START Not called Callback
static void battery_capacity_cb(keynode_t *key, void *data)
}
//LCOV_EXCL_STOP
+//LCOV_EXCL_START Target specific callback
+static void key_input_cb(GDBusConnection *conn,
+ const gchar *sender,
+ const gchar *object,
+ const gchar *interface,
+ const gchar *signal,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ struct device_cb_info *cb_info;
+ GList *elem, *elem_next;
+ 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) {
+ if (cb_info->type == type)
+ cb_info->cb(type, NULL, cb_info->data);
+ }
+}
+//LCOV_EXCL_STOP
+
static int register_signal(const char *bus_name,
const char *object_path,
const char *interface_name,
return 0;
}
-static int register_request(device_callback_e type)
+static int register_request(int type)
{
switch (type) {
case DEVICE_CALLBACK_BATTERY_CAPACITY:
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);
+ }
break;
}
return -EINVAL;
}
-static int release_request(device_callback_e type)
+static int release_request(int type)
{
switch (type) {
case DEVICE_CALLBACK_BATTERY_CAPACITY:
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);
+ }
break;
}
return -EINVAL;
}
-static int device_callback_check_feature_supported(device_callback_e type)
+static int device_callback_check_feature_supported(int type)
{
static bool f_display = false;
static bool f_battery = false;
f_flash = true;
return 0;
default:
- return -EINVAL;
+ return 0;
}
}
-int device_add_callback(device_callback_e type, device_changed_cb cb, void *data)
+int device_add_callback(device_callback_e enumtype, device_changed_cb cb, void *data)
{
struct device_cb_info *cb_info;
GList *elem, *elem_next;
+ GList **cb_list;
int ret_request, n;
+ int type = (int) enumtype;
- if (type < 0 || type >= DEVICE_CALLBACK_MAX)
+ 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 (device_callback_check_feature_supported(type) != 0)
return DEVICE_ERROR_NOT_SUPPORTED;
+ 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;
+
/* check if it is the first request */
- n = SYS_G_LIST_LENGTH(device_cb_list[type]);
+ n = SYS_G_LIST_LENGTH(*cb_list);
if (n == 0) {
ret_request = register_request(type);
if (ret_request < 0)
}
/* check for the same request */
- SYS_G_LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info) {
+ SYS_G_LIST_FOREACH_SAFE(*cb_list, elem, elem_next, cb_info) {
if (cb_info->cb == cb)
return DEVICE_ERROR_ALREADY_IN_PROGRESS;
}
cb_info->cb = cb;
cb_info->data = data;
+ cb_info->type = type;
- SYS_G_LIST_APPEND(device_cb_list[type], cb_info);
+ SYS_G_LIST_APPEND(*cb_list, cb_info);
return DEVICE_ERROR_NONE;
}
-int device_remove_callback(device_callback_e type, device_changed_cb cb)
+int device_remove_callback(device_callback_e enumtype, device_changed_cb cb)
{
struct device_cb_info *cb_info;
GList *elem, *elem_next;
+ GList **cb_list;
int ret_request, n;
+ int type = (int) enumtype;
- if (type < 0 || type >= DEVICE_CALLBACK_MAX)
+ 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 (device_callback_check_feature_supported(type) != 0)
return DEVICE_ERROR_NOT_SUPPORTED;
+ 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;
+
/* search for the same element with callback */
- SYS_G_LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info) {
+ SYS_G_LIST_FOREACH_SAFE(*cb_list, elem, elem_next, cb_info) {
if (cb_info->cb == cb)
break;
}
return DEVICE_ERROR_INVALID_PARAMETER;
/* remove device callback from list (local) */
- SYS_G_LIST_REMOVE(device_cb_list[type], cb_info);
+ SYS_G_LIST_REMOVE(*cb_list, cb_info);
free(cb_info);
/* check if this callback is last element */
- n = SYS_G_LIST_LENGTH(device_cb_list[type]);
+ n = SYS_G_LIST_LENGTH(*cb_list);
if (n == 0) {
ret_request = release_request(type);
if (ret_request < 0)