Update hello protocol
[platform/core/uifw/tts.git] / common / tts_config_parser.c
index 1cbdec8..51ff971 100644 (file)
@@ -39,6 +39,7 @@
 #define TTS_TAG_CONFIG_LANGUAGE                "language"
 #define TTS_TAG_CONFIG_SPEECH_RATE     "speech-rate"
 #define TTS_TAG_CONFIG_PITCH           "pitch"
+#define TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO         "background-volume-ratio"
 #define TTS_TAG_VOICE_TYPE_FEMALE      "female"
 #define TTS_TAG_VOICE_TYPE_MALE                "male"
 #define TTS_TAG_VOICE_TYPE_CHILD       "child"
@@ -516,6 +517,15 @@ int tts_parser_load_config(tts_config_s** config_info)
                        } else {
                                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Pitch is NULL");
                        }
+               } else if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
+                       key = xmlNodeGetContent(cur);
+                       if (NULL != key) {
+                               temp->bg_volume_ratio = atof((char*)key);
+                               xmlFree(key);
+                               key = NULL;
+                       } else {
+                               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Background volume ratio is NULL");
+                       }
                } else {
 
                }
@@ -951,8 +961,65 @@ int tts_parser_set_pitch(int value)
        return 0;
 }
 
+int tts_parser_set_bg_volume_ratio(double value)
+{
+       xmlNodePtr cur = NULL;
+       cur = xmlDocGetRootElement(g_config_doc);
+       if (cur == NULL) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
+               return -1;
+       }
+
+       if (xmlStrcmp(cur->name, (const xmlChar *) TTS_TAG_CONFIG_BASE_TAG)) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s", TTS_TAG_CONFIG_BASE_TAG);
+               return -1;
+       }
+
+       cur = cur->xmlChildrenNode;
+       if (cur == NULL) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document");
+               return -1;
+       }
+
+       while (cur != NULL) {
+               if (0 == xmlStrcmp(cur->name, (const xmlChar *)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
+                       char temp[10];
+                       memset(temp, '\0', 10);
+                       snprintf(temp, 10, "%lf", value);
+                       xmlNodeSetContent(cur, (const xmlChar *)temp);
+                       break;
+               }
+
+               cur = cur->next;
+       }
+
+       if (0 == access(TTS_CONFIG, F_OK)) {
+               int ret = xmlSaveFile(TTS_CONFIG, g_config_doc);
+               if (0 > ret) {
+                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Save result : %d", ret);
+               } else {
+                       static FILE* pFile;
+                       pFile = fopen(TTS_CONFIG, "r");
+                       int fd = -1;
+                       if (NULL == pFile) {
+                               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to open file %s", TTS_CONFIG);
+                       } else {
+                               fd = fileno(pFile);
+                               fsync(fd);
+                               fclose(pFile);
+                               SLOG(LOG_INFO, TAG_TTSCONFIG, "[DEBUG] Success to fsync %s", TTS_CONFIG);
+                       }
+                       SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Success to save %s", TTS_CONFIG);
+               }
+       } else {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to access to %s", TTS_CONFIG);
+       }
+
+       return 0;
+}
+
 int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voice, char** language, int* voice_type, 
-                                  int* speech_rate, int* pitch)
+                                  int* speech_rate, int* pitch, double* bg_volume_ratio)
 {
        if (NULL == engine || NULL == setting || NULL == language || NULL == voice_type || NULL == speech_rate) {
                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Input parameter is NULL");
@@ -1175,6 +1242,26 @@ int tts_parser_find_config_changed(char** engine, char**setting, bool* auto_voic
                        } else {
                                SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
                        }
+               } else if (0 == xmlStrcmp(cur_new->name, (const xmlChar*)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
+                       if (0 == xmlStrcmp(cur_old->name, (const xmlChar*)TTS_TAG_CONFIG_BACKGROUND_VOLUME_RATIO)) {
+                               key_old = xmlNodeGetContent(cur_old);
+                               if (NULL != key_old) {
+                                       key_new = xmlNodeGetContent(cur_new);
+                                       if (NULL != key_new) {
+                                               if (0 != xmlStrcmp(key_old, key_new)) {
+                                                       SLOG(LOG_DEBUG, TAG_TTSCONFIG, "Old bg volume ratio(%s), New bg volume ratio(%s)", 
+                                                               (char*)key_old, (char*)key_new);
+                                                       *bg_volume_ratio = atof((char*)key_new);
+                                               }
+                                               xmlFree(key_new);
+                                               key_new = NULL;
+                                       }
+                                       xmlFree(key_old);
+                                       key_old = NULL;
+                               }
+                       } else {
+                               SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] old config and new config are different");
+                       }
                } else {
 
                }