Add retry logic in case open_connection fails 32/265532/1
authorJi-hoon Lee <dalton.lee@samsung.com>
Thu, 21 Oct 2021 11:08:55 +0000 (20:08 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Thu, 21 Oct 2021 12:09:52 +0000 (21:09 +0900)
Change-Id: I24abf21cafcadb752f40fc4945114b3bbb2dbbe1

src/service_config.cpp
src/service_main.cpp

index d797480..b035179 100644 (file)
@@ -79,7 +79,7 @@ int CServiceConfig::parse_assistant_info(service_config_assistant_info_cb callba
                                        key = xmlNodeGetContent(child_node);
                                        if (key) {
                                                temp.supported_lang[temp.cnt_lang++] = strdup((const char*)key);
-                                               MAS_LOGD("Language : %s", key);
+                                               MAS_LOGI("Language : %s", key);
                                                xmlFree(key);
                                        }
                                }
@@ -93,13 +93,13 @@ int CServiceConfig::parse_assistant_info(service_config_assistant_info_cb callba
                                        key = xmlNodeGetContent(child_node);
                                        if (key) {
                                                temp.wakeup_list[temp.cnt_wakeup] = strdup((const char*)key);
-                                               MAS_LOGD("Wakeup Word : %s", key);
+                                               MAS_LOGI("Wakeup Word : %s", key);
                                                xmlFree(key);
                                        }
                                        xmlChar* prop = xmlNodeGetLang(child_node);
                                        if (prop) {
                                                temp.wakeup_language[temp.cnt_wakeup] = strdup((const char*)prop);
-                                               MAS_LOGD("Wakeup Language for %s : %s", temp.wakeup_list[temp.cnt_wakeup], prop);
+                                               MAS_LOGI("Wakeup Language for %s : %s", temp.wakeup_list[temp.cnt_wakeup], prop);
                                                xmlFree(prop);
                                        }
                                        temp.cnt_wakeup++;
@@ -111,21 +111,21 @@ int CServiceConfig::parse_assistant_info(service_config_assistant_info_cb callba
                        key = xmlNodeGetContent(cur);
                        if (key) {
                                temp.name = strdup((const char*)key);
-                               MAS_LOGD("Name : %s", key);
+                               MAS_LOGI("Name : %s", key);
                                xmlFree(key);
                        }
                } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_APPID)) {
                        key = xmlNodeGetContent(cur);
                        if (key) {
                                temp.app_id = strdup((const char*)key);
-                               MAS_LOGD("ID : %s", key);
+                               MAS_LOGI("ID : %s", key);
                                xmlFree(key);
                        }
                } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_ICON_PATH)) {
                        key = xmlNodeGetContent(cur);
                        if (key) {
                                temp.icon_path = strdup((const char*)key);
-                               MAS_LOGD("Icon Path : %s", key);
+                               MAS_LOGI("Icon Path : %s", key);
                                xmlFree(key);
                        }
                /* For supporting previous version of schema - START */
@@ -134,7 +134,7 @@ int CServiceConfig::parse_assistant_info(service_config_assistant_info_cb callba
                                key = xmlNodeGetContent(cur);
                                if (key) {
                                        temp.wakeup_engine[0] = strdup((const char*)key);
-                                       MAS_LOGD("Wakeup Engine : %s", key);
+                                       MAS_LOGI("Wakeup Engine : %s", key);
                                        xmlFree(key);
                                }
                                temp.cnt_wakeup_engine = 1;
@@ -149,7 +149,7 @@ int CServiceConfig::parse_assistant_info(service_config_assistant_info_cb callba
                                        key = xmlNodeGetContent(child_node);
                                        if (key) {
                                                temp.wakeup_engine[temp.cnt_wakeup_engine] = strdup((const char*)key);
-                                               MAS_LOGD("Wakeup Engine : %s", key);
+                                               MAS_LOGI("Wakeup Engine : %s", key);
                                                xmlFree(key);
                                        }
                                        temp.cnt_wakeup_engine++;
@@ -167,7 +167,7 @@ int CServiceConfig::parse_assistant_info(service_config_assistant_info_cb callba
                                if (0 == xmlStrcasecmp(key, reinterpret_cast<const xmlChar*>("true"))) {
                                        temp.custom_ui_option = true;
                                }
-                               MAS_LOGD("Use custom UI : %d", temp.custom_ui_option);
+                               MAS_LOGI("Use custom UI : %d", temp.custom_ui_option);
                                xmlFree(key);
                        }
                } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_VOICE_KEY_SUPPORT_MODE)) {
@@ -182,14 +182,14 @@ int CServiceConfig::parse_assistant_info(service_config_assistant_info_cb callba
                                } else {
                                        temp.voice_key_support_mode = VOICE_KEY_SUPPORT_MODE_NONE;
                                }
-                               MAS_LOGD("Voice key support mode : %s", cur->name);
+                               MAS_LOGI("Voice key support mode : %s", cur->name);
                                xmlFree(key);
                        }
                } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_VOICE_KEY_TAP_DURATION)) {
                        key = xmlNodeGetContent(cur);
                        if (key) {
                                temp.voice_key_tap_duration = atof((const char*)key);
-                               MAS_LOGD("Voice key tap duration : %s", key);
+                               MAS_LOGI("Voice key tap duration : %s", key);
                                xmlFree(key);
                        }
                } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_AUDIO_DATA_PROCESSOR)) {
@@ -239,6 +239,7 @@ int CServiceConfig::parse_assistant_info(service_config_assistant_info_cb callba
 
 int CServiceConfig::get_assistant_info(service_config_assistant_info_cb callback, void* user_data)
 {
+       MAS_LOGI("[ENTER] %s", MA_ASSISTANT_INFO);
        const char *suffix = ".xml";
 
        DIR *d;
@@ -251,7 +252,7 @@ int CServiceConfig::get_assistant_info(service_config_assistant_info_cb callback
                                if (0 == strcmp(dir->d_name + strlen(dir->d_name) - strlen(suffix), suffix)) {
                                        char fullpath[_POSIX_PATH_MAX];
                                        snprintf(fullpath, _POSIX_PATH_MAX - 1, "%s/%s", MA_ASSISTANT_INFO, dir->d_name);
-                                       MAS_LOGD("Parsing file : %s\n", fullpath);
+                                       MAS_LOGI("Parsing file : %s\n", fullpath);
                                        parse_assistant_info(callback, fullpath, user_data);
                                }
                        }
@@ -259,6 +260,7 @@ int CServiceConfig::get_assistant_info(service_config_assistant_info_cb callback
                closedir(d);
        }
 
+       MAS_LOGI("[EXIT]");
        return 0;
 }
 
index ac25d36..0e616fa 100644 (file)
@@ -1275,9 +1275,22 @@ bool CServiceMain::app_create(void *data)
        mServicePlugin.set_service_ipc(&mServiceIpc);
        mServicePlugin.set_service_main(this);
 
-       int ret = mServiceIpc.open_connection();
-       if (0 != ret) {
-               MAS_LOGE("[ERROR] Fail to open connection");
+       const int retry_interval = 5;
+       const int max_retry_count = 5;
+       int retry_count = 0;
+       int ret;
+       do {
+               ret = mServiceIpc.open_connection();
+               if (0 != ret) {
+                       sleep(retry_interval);
+                       MAS_LOGE("[ERROR] Fail to open connection, Retrying : %d", retry_count);
+               }
+       } while (0 != ret && retry_count++ < max_retry_count);
+
+       if (retry_count >= max_retry_count) {
+               MAS_LOGE("[ERROR] Maximum retry count reached, restarting...");
+               service_app_exit();
+               return false;
        }
 
        initialize_service_plugin();