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);
if (config->systemData != NULL)
__release_system_resource(config->systemData);
-
- free(config);
}
}
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;
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");
_W("Not Support");
break;
}
+
+ _D("callback finshied");
}
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
#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))
callback = (file_state_cb)arg;
- if (callback != NULL) {
+ if (callback == NULL) {
_E("Ccallback is null for event");
return NULL;
}
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);
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!!");
+ }
+ }
}
}
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;
}
{
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;
}
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");
{
char *version = NULL;
- if (inputObj == NULL || setupConfig == NULL) {
+ if (inputObj == NULL) {
_E("__parse_version input error");
return -1;
}