Fixed parsing issue
authornshero.lee <nshero.lee@samsung.com>
Wed, 20 Dec 2017 12:50:30 +0000 (21:50 +0900)
committernshero.lee <nshero.lee@samsung.com>
Wed, 20 Dec 2017 12:50:30 +0000 (21:50 +0900)
Signed-off-by: nshero.lee <nshero.lee@samsung.com>
src/adaptor.c
src/input_file.c
src/setup_system.c

index 1a9aa91143c0bb72b89a567456986b9985b56ec0..3c6f65343d4967302123bd4af8da1201969f5948 100644 (file)
@@ -104,8 +104,6 @@ static void __print_config_info(sa_config_s *config)
 
                systemData = config->systemData;
                if (systemData != NULL) {
-                       if (systemData->deviceName != NULL)
-                               _D("SystemData::deviceName[%s]", systemData->deviceName);
                        if (systemData->proxy != NULL) {
                                _D("systemData::httpProxyHost [%s]", systemData->proxy->httpProxyHost);
                                _D("systemData::HttpProxyPort [%d]", systemData->proxy->httpProxyPort);
@@ -148,8 +146,6 @@ static void __release_config_resource(sa_config_s *config)
 
                if (config->systemData != NULL)
                        __release_system_resource(config->systemData);
-
-               free(config);
        }
 }
 
@@ -218,7 +214,6 @@ static int __set_network(sa_network_s *network)
        sa_error_e ret = SA_ERROR_NONE;
        sa_network_type_e conn_type;
        sa_network_state_e conn_state;
-       int index = 0;
 
        if (network != NULL) {
                return -1;
@@ -289,25 +284,22 @@ static int __set_system(sa_system_s *system)
 
 void __monitor_file_state_cb(sa_file_state_e state, void *param1, void *param2)
 {
-       sa_config_s *config = NULL;     
+       sa_config_s config = {0,};      
 
        switch (state) {
        case SA_FILE_STATE_REGISTERED:
                _D("SA_FILE_STATE_REGISTERED");
-               // parsing config 
-               if (SA_ERROR_NONE == __parsing_config(config)) {
-                       // activate network
-                       if (config != NULL) {
-                               if (config->systemData != NULL) {
-                                       __set_system(config->systemData);
-                               }
+               _D("start parsing");
+               if (SA_ERROR_NONE == __parsing_config(&config)) {
+                       if (config.systemData != NULL) {
+                               __set_system(config.systemData);
+                       }
 
-                               if (config->networkData != NULL) {
-                                       __set_network(config->networkData);
-                               }
+                       if (config.networkData != NULL) {
+                               //__set_network(config->networkData);
                        }
-                       __release_config_resource(config);
-               }
+                       __release_config_resource(&config);
+               } 
                break;
        case SA_FILE_STATE_CHANGED:
                _D("SA_FILE_STATE_CHANGED");
@@ -316,6 +308,8 @@ void __monitor_file_state_cb(sa_file_state_e state, void *param1, void *param2)
                _W("Not Support");
                break;
        }
+
+       _D("callback finshied");
 }
 
 int main(int argc, char *argv[])
@@ -335,5 +329,9 @@ int main(int argc, char *argv[])
                _D("config file is not existed, setup-adaptor exit");
        }
 
+       _D("main thread end");
+       while(1) {
+               sleep(1);
+       }
        return 0;
 }
\ No newline at end of file
index e8c4f42410425f4d246e7972e294d9a1a103467c..d08897a46d8f80f63a8de8aedf118e4c1515cc2a 100644 (file)
@@ -27,6 +27,8 @@
 #include "input_file.h"
 
 #define CONFIG_FILE "/etc/setup-adaptor/config.json"
+#define CONFIG_FOLDER "/etc/setup-adaptor"
+#define CONFIG_NAME "config.json"
 #define EVENT_SIZE     (sizeof(struct inotify_event))
 #define BUF_LEN        (1024 * (EVENT_SIZE + 16))
 
@@ -41,7 +43,7 @@ static void *__config_main_loop(void *arg)
 
        callback = (file_state_cb)arg;
 
-       if (callback != NULL) {
+       if (callback == NULL) {
                _E("Ccallback is null for event");
                return NULL;
        }
@@ -53,8 +55,10 @@ static void *__config_main_loop(void *arg)
                return NULL;
        }
 
-       wd = inotify_add_watch(fd, CONFIG_FILE, IN_MODIFY | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO | IN_MOVE_SELF);
-
+       wd = inotify_add_watch(fd, CONFIG_FOLDER, IN_MODIFY | IN_CREATE | IN_DELETE);
+       // Start callack
+       _D("Registerd Callback Triggered");
+       callback(SA_FILE_STATE_REGISTERED, NULL, NULL);
        while (1) {
                int length, i = 0;
                length = read(fd, buffer, BUF_LEN);
@@ -64,28 +68,35 @@ static void *__config_main_loop(void *arg)
 
                while (i < length) {
                        struct inotify_event *event = (struct inotify_event *)&buffer[i];
-                       _D("[debug] wd=%d mask=%d cookie=%d len=%d dir=%s\n", event->wd, event->mask, event->cookie, event->len, (event->mask & IN_ISDIR) ? "yes" : "no");
+                       _D("[debug] wd=%d mask=%d cookie=%d len=%d dir=%s", event->wd, event->mask, event->cookie, event->len, (event->mask & IN_ISDIR) ? "yes" : "no");
                        if (event->len) {
                                if (event->mask & IN_CREATE) {
                                        if (event->mask & IN_ISDIR)
-                                               _D("The directory %s was created.\n", event->name);
-                                       else
-                                               _D("The file %s was created.\n", event->name);
+                                               _D("The directory %s was created", event->name);
+                                       else {
+                                               _D("The file %s was create.", event->name);
+                                               if (!strcmp(event->name, CONFIG_NAME)) {
+                                                       _D("config.json is created!!");
+                                               }
+                                       }
                                } else if (event->mask & IN_DELETE) {
                                        if (event->mask & IN_ISDIR)
-                                               _D("The directory %s was deleted.\n", event->name);
-                                       else
-                                               _D("The file %s was deleted.\n", event->name);
+                                               _D("The directory %s was deleted.", event->name);
+                                       else {
+                                               _D("The file %s was deleted", event->name);
+                                               if (!strcmp(event->name, CONFIG_NAME)) {
+                                                       _D("config.json is deleted!!");
+                                               }
+                                       }
                                } else if (event->mask & IN_MODIFY) {
                                        if (event->mask & IN_ISDIR)
-                                               _D("The directory %s was modified.\n", event->name);
-                                       else
-                                               _D("The file %s was modified.\n", event->name);
-                               } else if (event->mask & IN_MOVED_FROM || event->mask & IN_MOVED_TO || event->mask & IN_MOVE_SELF) {
-                                       if (event->mask & IN_ISDIR)
-                                               _D("The directory %s was moved.\n", event->name);
-                                       else
-                                               _D("The file %s was moved.\n", event->name);
+                                               _D("The directory %s was modified", event->name);
+                                       else {
+                                               _D("The file %s was modified", event->name);
+                                               if (!strcmp(event->name, CONFIG_NAME)) {
+                                                       _D("config.json is modifued!!");
+                                               }
+                                       }
                                }
                        }
 
@@ -342,7 +353,7 @@ static int __parse_network_data(json_object *inputObj, sa_config_s *setupConfig)
        struct json_object *ethernetObj = NULL;
        int wifiRet = 0, ethRet = 0;
 
-       if (inputObj == NULL || setupConfig == NULL) {
+       if (inputObj == NULL) {
                _E("__parse_network_data input error");
                return -1;
        }
@@ -392,8 +403,7 @@ static int __parse_system_data(json_object *inputObj, sa_config_s *setupConfig)
 {
        int ret = 0;
        char *httpProxyHost = NULL;
-       int httpProxyPort = 0;
-       if (inputObj == NULL || setupConfig == NULL) {
+       if (inputObj == NULL) {
                _E("__parse_system_data input error");
                return -1;
        }
@@ -410,7 +420,8 @@ static int __parse_system_data(json_object *inputObj, sa_config_s *setupConfig)
                                httpProxyHost = NULL;
                                
                                //httpProxyPort
-                               httpProxyPort = json_get_int_from_obj(inputObj, SA_CONFIG_NETWORKDATA_HTTPPROXYPORT);
+                               setupConfig->systemData->proxy->httpProxyPort = json_get_int_from_obj(inputObj, SA_CONFIG_NETWORKDATA_HTTPPROXYPORT);
+
                        } else {
                                ret = -1;
                                _E("malloc fail setupConfig->systemData->proxy");
@@ -429,7 +440,7 @@ static int __parse_version(json_object *inputObj, sa_config_s *setupConfig)
 {
        char *version = NULL;
 
-       if (inputObj == NULL || setupConfig == NULL) {
+       if (inputObj == NULL) {
                _E("__parse_version input error");
                return -1;
        }
index c98d768eb5486d9e4dd0908685a5f5db47376d67..209b4515c08142de4579be0d493d0b81736b25ec 100644 (file)
 
 sa_error_e sa_system_set_proxy(sa_proxy_s *info)
 {
-       return SA_ERROR_NONE;
+       return SA_ERROR_NOT_SUPPORTED;
 }
 
 sa_error_e sa_system_get_proxy(sa_proxy_s *info)
 {
-       return SA_ERROR_NONE;
+       return SA_ERROR_NOT_SUPPORTED;
 }
\ No newline at end of file