From c0c7c00270535bdde663fa941ed16beb38e03c58 Mon Sep 17 00:00:00 2001 From: "nshero.lee" Date: Wed, 20 Dec 2017 21:50:30 +0900 Subject: [PATCH] Fixed parsing issue Signed-off-by: nshero.lee --- src/adaptor.c | 34 +++++++++++++-------------- src/input_file.c | 57 +++++++++++++++++++++++++++------------------- src/setup_system.c | 4 ++-- 3 files changed, 52 insertions(+), 43 deletions(-) diff --git a/src/adaptor.c b/src/adaptor.c index 1a9aa91..3c6f653 100644 --- a/src/adaptor.c +++ b/src/adaptor.c @@ -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 diff --git a/src/input_file.c b/src/input_file.c index e8c4f42..d08897a 100644 --- a/src/input_file.c +++ b/src/input_file.c @@ -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; } diff --git a/src/setup_system.c b/src/setup_system.c index c98d768..209b451 100644 --- a/src/setup_system.c +++ b/src/setup_system.c @@ -20,10 +20,10 @@ 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 -- 2.34.1