input: clean-up the useless code and add handling code 04/286904/3
authorYunhee Seo <yuni.seo@samsung.com>
Mon, 16 Jan 2023 11:07:13 +0000 (20:07 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Tue, 17 Jan 2023 09:20:47 +0000 (18:20 +0900)
add detecting existence of config file and parsing fail condition,
also added input device manager exit condition check
remove useless header line

Change-Id: I16e5e3c82947f444251156e3305067d536a0ece7
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
src/input/input-parser.c
src/input/input-parser.h
src/input/input.c

index cb9fe90..b72c8b1 100644 (file)
@@ -21,6 +21,7 @@
 #include <string.h>
 #include <errno.h>
 #include <stdbool.h>
+#include <unistd.h>
 
 #include <libsyscommon/ini-parser.h>
 #include <libsyscommon/list.h>
@@ -54,13 +55,13 @@ static bool is_default_input_device_duplicated(int input_device_type)
        return false;
 }
 
-static void parse_input_device_property(gpointer data, gpointer user_data)
+static int parse_input_device_property(gpointer data, gpointer user_data)
 {
        struct section_property *prop = (struct section_property *) data;
        struct input_device_info *input_dev_info = *(struct input_device_info **)user_data;
 
        if (!prop || !input_dev_info)
-               return;
+               return 0;
 
        if (MATCH(prop->key, "InputDeviceType")) {
                if (MATCH(prop->value, "unknown"))
@@ -71,6 +72,8 @@ static void parse_input_device_property(gpointer data, gpointer user_data)
                        input_dev_info->input_device_type = (int)HAL_DEVICE_INPUT_TYPE_KEYBOARD;
                else if (MATCH(prop->value, "custom_knob"))
                        input_dev_info->input_device_type = (int)HAL_DEVICE_INPUT_TYPE_CUSTOM_KNOB;
+               else
+                       return -EPERM;
        } else if (MATCH(prop->key, "InputDeviceId")) {
                sscanf(prop->value, "%d", (&input_dev_info->input_device_id));
        } else if (MATCH(prop->key, "InputDeviceName")) {
@@ -81,12 +84,17 @@ static void parse_input_device_property(gpointer data, gpointer user_data)
                        input_dev_info->input_device_default = 1;
                else if (MATCH(prop->value, "no"))
                        input_dev_info->input_device_default = 0;
+               else
+                       return -EPERM;
        }
+       return 0;
 }
 
 static int parse_input_device_section(const struct parse_result *result, void *data)
 {
        struct input_device_info *input_dev_info;
+       struct section_property *temp_section_prop;
+       GList *temp_glist;
        int ret;
 
        if (!result || !result->props)
@@ -99,7 +107,11 @@ static int parse_input_device_section(const struct parse_result *result, void *d
        if (!input_dev_info)
                return -ENOMEM;
 
-       g_list_foreach(result->props, parse_input_device_property, &input_dev_info);
+       SYS_G_LIST_FOREACH(result->props, temp_glist, temp_section_prop) {
+               if (parse_input_device_property(temp_section_prop, &input_dev_info) < 0)
+                       return -EPERM;
+       }
+
        if (input_dev_info->input_device_default == 1) {
                if (is_default_input_device_duplicated(input_dev_info->input_device_type))
                        return -EPERM;
@@ -123,6 +135,9 @@ int input_parser_init(void)
        g_hash_table_to_check_default_duplicated = g_hash_table_new_full(g_int_hash, g_int_equal,
                g_free, g_free);
 
+       if (access(INPUT_CONF_PATH, F_OK) == -1)
+               return 0;
+
        ret = libsys_config_parse_by_section(INPUT_CONF_PATH, parse_input_device_section, NULL);
 
        if (g_hash_table_to_check_default_duplicated) {
index f041c11..5b3ec60 100644 (file)
@@ -19,8 +19,6 @@
 #ifndef __INPUT_PARSER_H__
 #define __INPUT_PARSER_H__
 
-#include <glib.h>
-
 int input_parser_init(void);
 
 #endif //__INPUT_PARSER_H__
\ No newline at end of file
index e30357f..23563f0 100644 (file)
@@ -122,8 +122,10 @@ static void input_init(void *data)
                _E("Failed to init input_ops");
 
        ret = input_devman_init();
-       if (ret < 0)
+       if (ret < 0) {
                _E("Failed to initialize input device manager(%d)", ret);
+               input_devman_exit();
+       }
 
        ret = input_parser_init();
        if (ret < 0) {