-# [Section]
-# Keycode: power
-# - set keycode to be configured
-# Duration: start,end
-# - set interval that filters event
-# - end=-1 means infinite
-# - level trigger event will be triggered on reaching start time after
-# holding a key
-# - edge trigger event will be triggered only when a key is released
-# in between of the interval
-# TriggerType: edge / level
-# - edge: trigger event on releaseing key within a specific interval
-# - level: trigger event on holding key for a duration
-# Action=broadcast
-# - broadcast event using dbus signal
-# Action=curr,next
-# - add state transition event from curr to next
+# [EVENT_ACTION] - define event and corresponding action
+# Name=string
+# - define mnemonic for the event, and it is only used for logging
+# Enum=integer
+# - define an integer that represents the event. deviced uses this
+# integer in broadcasting dbus signal.
+# Keycode=integer
+# - define keycode to filter key event
+# Duration=integer,integer
+# - define time window in milisecond for filtering key event. -1 means no limit.
+# TriggerType=level/edge
+# - define event type
+# Action=broadcast
+# - define broadcast action for the event.
+# Action=current,next
+# - define state transition action for the event.
-[BLINKKEY_EDGE]
+[EVENT_ACTION]
+Name=BLINKKEY_EDGE
Enum=1000
Keycode=power
Duration=0,2000
TriggerType=edge
Action=sleep,sleep
-[SHORTKEY_LEVEL]
+[EVENT_ACTION]
+Name=SHORTKEY_LEVEL
Enum=1001
Keycode=power
Duration=2000,-1
TriggerType=level
Action=broadcast
-[SHORTKEY_EDGE]
+[EVENT_ACTION]
+Name=SHORTKEY_EDGE
Enum=1002
Keycode=power
Duration=2000,7000
Action=normal,sleep
Action=sleep,normal
-[LONGKEY_LEVEL]
+[EVENT_ACTION]
+Name=LONGKEY_LEVEL
Enum=1003
Keycode=power
Duration=7000,-1
TriggerType=level
Action=broadcast
-[LONGKEY_EDGE]
+[EVENT_ACTION]
+Name=LONGKEY_EDGE
Enum=1004
Keycode=power
Duration=7000,-1
return PSM_MAX;
}
-static void add_action_transition_state(struct input_event_unit *ieu, char *curr, char *next)
+static void add_action_transition_info(struct input_event_unit *ieu, char *curr, char *next)
{
struct trans_info *ti = NULL;
GList **action_list = (GList **) &(ieu->user_data);
} else if (sscanf(action, "%15[^,],%15s", curr, next) == 2) {
ieu->notifier = DEVICE_NOTIFIER_INPUT_TRANSITION_STATE;
/* append transition info to ieu->user_data */
- add_action_transition_state(ieu, curr, next);
+ add_action_transition_info(ieu, curr, next);
} else {
_E("Invalid action=%s", action);
}
}
-static int load_input_config(struct parse_result *result, void *data)
+static void parse_event_action_property(gpointer data, gpointer user_data)
{
- GList **tmp = (GList **) data;
- GList *elem;
+ struct section_property *prop = (struct section_property *) data;
+ struct input_event_unit *ieu = (struct input_event_unit *) user_data;
- /* caching previous ieu */
- static struct input_event_unit *ieu = NULL;
-
- /* find ieu if the given name is not matched with cached ieu */
- if (!ieu || strncmp(ieu->name, result->section, strlen(ieu->name) + 1)) {
- SYS_G_LIST_FOREACH(*tmp, elem, ieu) {
- if (!strncmp(ieu->name, result->section, strlen(ieu->name) + 1))
- break;
- }
-
- /* make a new ieu */
- if (!ieu) {
- ieu = calloc(1, sizeof(struct input_event_unit));
- if (!ieu)
- return -ENOMEM;
- ieu->name = strndup(result->section, 32);
- SYS_G_LIST_APPEND(*tmp, ieu);
- }
- }
+ if (!prop || !ieu)
+ return;
- if (MATCH(result->name, "Enum")) {
- sscanf(result->value, "%d", &ieu->id);
- } else if (MATCH(result->name, "Keycode")) {
- parse_keycode(ieu, result->value);
- } else if (MATCH(result->name, "Duration")) {
- parse_duration(ieu, result->value);
- } else if (MATCH(result->name, "TriggerType")) {
- parse_trigger_type(ieu, result->value);
- } else if (MATCH(result->name, "Action")) {
- parse_action(ieu, result->value);
+ _D("Key=%s, Value=%s", prop->key, prop->value);
+
+ if (MATCH(prop->key, "Name")) {
+ ieu->name = strndup(prop->value, 32);
+ } else if (MATCH(prop->key, "Enum")) {
+ sscanf(prop->value, "%d", &ieu->id);
+ } else if (MATCH(prop->key, "Keycode")) {
+ parse_keycode(ieu, prop->value);
+ } else if (MATCH(prop->key, "Duration")) {
+ parse_duration(ieu, prop->value);
+ } else if (MATCH(prop->key, "TriggerType")) {
+ parse_trigger_type(ieu, prop->value);
+ } else if (MATCH(prop->key, "Action")) {
+ parse_action(ieu, prop->value);
}
-
- return 0;
}
-static int parse_input_config(void)
+static int parse_event_action(const struct parse_result *result, void *data)
{
- GList *tmp = NULL;
- GList *elem;
struct input_config *ic;
struct input_event_unit *ieu;
- /* construct config list by section name */
- config_parse(INPUT_CONF_PATH, load_input_config, (void *) &tmp);
-
- /* reconstruct config list by keycode */
- SYS_G_LIST_FOREACH(tmp, elem, ieu) {
- ic = find_input_config(ieu->keycode);
- if (!ic) {
- ic = calloc(1, sizeof(struct input_config));
- if (!ic)
- return -ENOMEM;
- ic->keycode = ieu->keycode;
- SYS_G_LIST_APPEND(input_config_list, ic);
- }
- SYS_G_LIST_APPEND(ic->event_list, ieu);
- _D("Input event unit: name=%s, enum=%d, start=%lu, end=%lu, type=%d, action=%d",
- ieu->name, ieu->id, ieu->interval[0], ieu->interval[1], ieu->type, ieu->notifier);
- if (ieu->notifier == DEVICE_NOTIFIER_INPUT_TRANSITION_STATE) {
- struct trans_info *ti;
- GList *elem;
- SYS_G_LIST_FOREACH((GList *)ieu->user_data, elem, ti)
- _D("Transition state event is registered: %d -> %d", ti->curr, ti->next);
- }
- }
+ if (!result || !result->props)
+ return 0;
+
+ if (!MATCH(result->section, "EVENT_ACTION"))
+ return 0;
+
+ _D("Input section=%s", result->section);
- /* cleanup tmp list */
- g_list_free(tmp);
+ ieu = calloc(1, sizeof(struct input_event_unit));
+ if (!ieu)
+ return 0;
+
+ g_list_foreach(result->props, parse_event_action_property, ieu);
+
+ ic = find_input_config(ieu->keycode);
+ if (!ic) {
+ ic = calloc(1, sizeof(struct input_config));
+ if (!ic)
+ return -ENOMEM;
+ ic->keycode = ieu->keycode;
+ SYS_G_LIST_APPEND(input_config_list, ic);
+ }
+ SYS_G_LIST_APPEND(ic->event_list, ieu);
return 0;
}
void init_input_config(void)
{
- parse_input_config();
+ libsys_config_parse_by_section(INPUT_CONF_PATH, parse_event_action, NULL);
}