Add to check RW config file and reset config info
[platform/core/uifw/tts.git] / common / tts_config_mgr.c
index 8ad002b..1522950 100644 (file)
@@ -330,7 +330,7 @@ int __tts_config_mgr_select_lang(const char* engine_id, char** language, int* ty
 
 Eina_Bool tts_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *fd_handler)
 {
-       SLOG(LOG_DEBUG, tts_tag(), "===== Config changed callback event");
+       SLOG(LOG_DEBUG, tts_tag(), "@@@ Config changed callback event");
 
        int length;
        struct inotify_event event;
@@ -339,8 +339,7 @@ Eina_Bool tts_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *fd_handl
        length = read(g_config_fd_noti, &event, sizeof(struct inotify_event));
        if (0 > length) {
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty Inotify event");
-               SLOG(LOG_DEBUG, tts_tag(), "=====");
-               SLOG(LOG_DEBUG, tts_tag(), " ");
+               SLOG(LOG_DEBUG, tts_tag(), "@@@");
                return ECORE_CALLBACK_DONE;
        }
 
@@ -496,12 +495,17 @@ Eina_Bool tts_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *fd_handl
                        free(lang);
                        lang = NULL;
                }
+       } else if (IN_DELETE_SELF == event.mask) {
+               SLOG(LOG_ERROR, tts_tag(), "[ERROR] IN_DELETE_SELF event");
+
+               tts_parser_unload_config(g_config_info);
+               tts_parser_reset();
+               tts_parser_load_config(&g_config_info);
        } else {
-               SLOG(LOG_ERROR, tts_tag(), "[ERROR] Undefined event");
+               SLOG(LOG_ERROR, tts_tag(), "[ERROR] Undefined event (0x%x)", event.mask);
        }
 
-       SLOG(LOG_DEBUG, tts_tag(), "=====");
-       SLOG(LOG_DEBUG, tts_tag(), " ");
+       SLOG(LOG_DEBUG, tts_tag(), "@@@");
 
        return ECORE_CALLBACK_PASS_ON;
 }
@@ -519,7 +523,7 @@ int __tts_config_mgr_register_config_event()
        }
        g_config_fd_noti = fd;
 
-       wd = inotify_add_watch(fd, TTS_CONFIG, IN_CLOSE_WRITE);
+       wd = inotify_add_watch(fd, TTS_CONFIG, IN_CLOSE_WRITE|IN_DELETE_SELF);
        g_config_wd_noti = wd;
 
        g_config_fd_handler_noti = ecore_main_fd_handler_add(fd, ECORE_FD_READ,
@@ -860,7 +864,7 @@ int __tts_config_mgr_get_engine_info()
 
 static Eina_Bool __tts_config_mgr_engine_config_inotify_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
 {
-       SLOG(LOG_DEBUG, tts_tag(), "===== Engine config updated callback event");
+       SLOG(LOG_DEBUG, tts_tag(), "@@@ Engine config updated callback event");
 
        tts_engine_inotify_s *ino = (tts_engine_inotify_s *)data;
        int dir_fd = ino->dir_fd;
@@ -872,8 +876,7 @@ static Eina_Bool __tts_config_mgr_engine_config_inotify_event_callback(void* dat
        length = read(dir_fd, &event, sizeof(struct inotify_event));
        if (0 > length) {
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Empty Inotify event");
-               SLOG(LOG_DEBUG, tts_tag(), "=====");
-               SLOG(LOG_DEBUG, tts_tag(), " ");
+               SLOG(LOG_DEBUG, tts_tag(), "@@@");
                return ECORE_CALLBACK_DONE;
        }
 
@@ -928,8 +931,7 @@ static Eina_Bool __tts_config_mgr_engine_config_inotify_event_callback(void* dat
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Undefined event");
        }
 
-       SLOG(LOG_DEBUG, tts_tag(), "=====");
-       SLOG(LOG_DEBUG, tts_tag(), " ");
+       SLOG(LOG_DEBUG, tts_tag(), "@@@");
 
        return ECORE_CALLBACK_PASS_ON;
 }
@@ -1044,6 +1046,12 @@ int tts_config_mgr_initialize(int uid)
                        return TTS_CONFIG_ERROR_OUT_OF_MEMORY;
                }
                temp_client->uid = uid;
+               temp_client->engine_cb = NULL;
+               temp_client->voice_cb = NULL;
+               temp_client->speech_cb = NULL;
+               temp_client->pitch_cb = NULL;
+               temp_client->screen_cb = NULL;
+               temp_client->user_data = NULL;
 
                g_config_client_list = g_slist_append(g_config_client_list, temp_client);
 
@@ -1056,6 +1064,12 @@ int tts_config_mgr_initialize(int uid)
                        return TTS_CONFIG_ERROR_OUT_OF_MEMORY;
                }
                temp_client->uid = uid;
+               temp_client->engine_cb = NULL;
+               temp_client->voice_cb = NULL;
+               temp_client->speech_cb = NULL;
+               temp_client->pitch_cb = NULL;
+               temp_client->screen_cb = NULL;
+               temp_client->user_data = NULL;
 
                g_config_client_list = g_slist_append(g_config_client_list, temp_client);
        }
@@ -1166,7 +1180,7 @@ int tts_config_mgr_initialize(int uid)
        }
 
        /* print daemon config */
-       SLOG(LOG_DEBUG, tts_tag(), "== TTS config ==");
+       SLOG(LOG_DEBUG, tts_tag(), "@@@ TTS config @@@");
        SECURE_SLOG(LOG_DEBUG, tts_tag(), " engine : %s", g_config_info->engine_id);
        SECURE_SLOG(LOG_DEBUG, tts_tag(), " setting : %s", g_config_info->setting);
        SECURE_SLOG(LOG_DEBUG, tts_tag(), " auto voice : %s", g_config_info->auto_voice ? "on" : "off");
@@ -1174,7 +1188,7 @@ int tts_config_mgr_initialize(int uid)
        SECURE_SLOG(LOG_DEBUG, tts_tag(), " voice type : %d", g_config_info->type);
        SECURE_SLOG(LOG_DEBUG, tts_tag(), " speech rate : %d", g_config_info->speech_rate);
        SECURE_SLOG(LOG_DEBUG, tts_tag(), " pitch : %d", g_config_info->pitch);
-       SLOG(LOG_DEBUG, tts_tag(), "=================");
+       SLOG(LOG_DEBUG, tts_tag(), "@@@@@");
 
        if (0 != __tts_config_mgr_register_config_event()) {
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to register config event");
@@ -2029,3 +2043,53 @@ int __tts_config_mgr_print_engine_info()
 
        return 0;
 }
+
+int tts_config_mgr_get_max_text_size(unsigned int* size)
+{
+       if (0 >= g_slist_length(g_config_client_list)) {
+               SLOG(LOG_ERROR, tts_tag(), "Not initialized");
+               return TTS_CONFIG_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == size) {
+               return TTS_CONFIG_ERROR_INVALID_PARAMETER;
+       }
+
+       GSList *iter = NULL;
+       tts_engine_info_s *engine_info = NULL;
+
+       if (0 >= g_slist_length(g_engine_list)) {
+               SLOG(LOG_ERROR, tts_tag(), "[ERROR] There is no engine!!");
+               return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND;
+       }
+
+       /* Get a first item */
+       iter = g_slist_nth(g_engine_list, 0);
+
+       while (NULL != iter) {
+               engine_info = iter->data;
+
+               if (NULL == engine_info) {
+                       SLOG(LOG_ERROR, tts_tag(), "engine info is NULL");
+                       return TTS_CONFIG_ERROR_OPERATION_FAILED;
+               }
+
+               if (0 != strcmp(g_config_info->engine_id, engine_info->uuid)) {
+                       iter = g_slist_next(iter);
+                       continue;
+               }
+
+               break;
+       }
+
+       if (NULL == engine_info) {
+               SLOG(LOG_ERROR, tts_tag(), "engine info is NULL");
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
+       *size = engine_info->text_size;
+       SLOG(LOG_DEBUG, tts_tag(), "[DEBUG] Max text size is %d.", *size);
+
+       return 0;
+}
+