Added set/unset background volume ratio fucntion.
[platform/core/uifw/tts.git] / common / tts_config_mgr.c
index a5d4e7b..375bc70 100644 (file)
@@ -33,6 +33,7 @@ typedef struct {
        tts_config_speech_rate_changed_cb       speech_cb;
        tts_config_screen_reader_changed_cb     screen_cb;
        tts_config_pitch_changed_cb             pitch_cb;
+       tts_config_bg_volume_ratio_changed_cb bg_volume_ratio_cb;
        void*   user_data;
 } tts_config_client_s;
 
@@ -349,11 +350,12 @@ Eina_Bool tts_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *fd_handl
                int voice_type = -1;
                int speech_rate = -1;
                int pitch = -1;
+               double bg_volume_ratio = -1;
 
                GSList *iter = NULL;
                tts_config_client_s* temp_client = NULL;
 
-               if (0 != tts_parser_find_config_changed(&engine, &setting, &auto_voice, &lang, &voice_type, &speech_rate, &pitch))
+               if (0 != tts_parser_find_config_changed(&engine, &setting, &auto_voice, &lang, &voice_type, &speech_rate, &pitch, &bg_volume_ratio))
                        return ECORE_CALLBACK_PASS_ON;
 
                /* engine changed */
@@ -480,6 +482,28 @@ Eina_Bool tts_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *fd_handl
                        }
                }
 
+               if (-1 != bg_volume_ratio) {
+                       g_config_info->bg_volume_ratio = bg_volume_ratio;
+
+                       SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, "background volume ratio change(%lf)", g_config_info->bg_volume_ratio);
+
+                       /* Call all callbacks of client*/
+                       iter = g_slist_nth(g_config_client_list, 0);
+
+                       while (NULL != iter) {
+                               temp_client = iter->data;
+
+                               if (NULL != temp_client) {
+                                       if (NULL != temp_client->bg_volume_ratio_cb) {
+                                               SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, "background volume ratio changed callback : uid(%d)", temp_client->uid);
+                                               temp_client->bg_volume_ratio_cb(g_config_info->bg_volume_ratio, temp_client->user_data);
+                                       }
+                               }
+
+                               iter = g_slist_next(iter);
+                       }
+               }
+
                if (NULL != engine) {
                        free(engine);
                        engine = NULL;
@@ -1053,6 +1077,7 @@ int tts_config_mgr_initialize(int uid)
                temp_client->speech_cb = NULL;
                temp_client->pitch_cb = NULL;
                temp_client->screen_cb = NULL;
+               temp_client->bg_volume_ratio_cb = NULL;
                temp_client->user_data = NULL;
 
                g_config_client_list = g_slist_append(g_config_client_list, temp_client);
@@ -1071,6 +1096,7 @@ int tts_config_mgr_initialize(int uid)
                temp_client->speech_cb = NULL;
                temp_client->pitch_cb = NULL;
                temp_client->screen_cb = NULL;
+               temp_client->bg_volume_ratio_cb = NULL;
                temp_client->user_data = NULL;
 
                g_config_client_list = g_slist_append(g_config_client_list, temp_client);
@@ -1190,6 +1216,7 @@ int tts_config_mgr_initialize(int uid)
        SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, " voice type : %d", g_config_info->type);
        SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, " speech rate : %d", g_config_info->speech_rate);
        SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, " pitch : %d", g_config_info->pitch);
+       SECURE_SLOG(LOG_DEBUG, TAG_TTSCONFIG, " bg volume ratio : %lf", g_config_info->bg_volume_ratio);
        SLOG(LOG_DEBUG, TAG_TTSCONFIG, "@@@@@");
 
        if (0 != __tts_config_mgr_register_config_event()) {
@@ -1246,6 +1273,7 @@ int tts_config_mgr_set_callback(int uid,
                                tts_config_voice_changed_cb voice_cb, 
                                tts_config_speech_rate_changed_cb speech_cb, 
                                tts_config_pitch_changed_cb pitch_cb,
+                               tts_config_bg_volume_ratio_changed_cb bg_volume_ratio_cb,
                                void* user_data)
 {
        GSList *iter = NULL;
@@ -1263,6 +1291,7 @@ int tts_config_mgr_set_callback(int uid,
                                temp_client->voice_cb = voice_cb;
                                temp_client->speech_cb = speech_cb;
                                temp_client->pitch_cb = pitch_cb;
+                               temp_client->bg_volume_ratio_cb = bg_volume_ratio_cb;
                                temp_client->user_data = user_data;
                        }
                }
@@ -1289,6 +1318,7 @@ int tts_config_mgr_unset_callback(int uid)
                                temp_client->voice_cb = NULL;
                                temp_client->speech_cb = NULL;
                                temp_client->pitch_cb = NULL;
+                               temp_client->bg_volume_ratio_cb = NULL;
                                temp_client->user_data = NULL;
                        }
                }
@@ -1896,6 +1926,40 @@ int tts_config_mgr_set_pitch(int value)
        return 0;
 }
 
+int tts_config_mgr_get_bg_volume_ratio(double *value)
+{
+       if (0 >= g_slist_length(g_config_client_list)) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "Not initialized");
+               return TTS_CONFIG_ERROR_INVALID_PARAMETER;
+       }
+
+       if (NULL == value)
+               return TTS_CONFIG_ERROR_INVALID_PARAMETER;
+       else
+               *value = g_config_info->bg_volume_ratio;
+
+       return 0;
+}
+
+int tts_config_mgr_set_bg_volume_ratio(double value)
+{
+       if (0 >= g_slist_length(g_config_client_list)) {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "Not initialized");
+               return TTS_CONFIG_ERROR_INVALID_PARAMETER;
+       }
+
+       SLOG(LOG_DEBUG, TAG_TTSCONFIG, "[Config] Set bg volume ratio : %lf", value);
+       if (0 != tts_parser_set_bg_volume_ratio(value))
+       {
+               SLOG(LOG_ERROR, TAG_TTSCONFIG, "Fail to save bg volume ratio");
+               return TTS_CONFIG_ERROR_OPERATION_FAILED;
+       }
+
+       g_config_info->bg_volume_ratio = value;
+
+       return 0;
+}
+
 bool tts_config_check_default_engine_is_valid(const char* engine)
 {
        if (0 >= g_slist_length(g_config_client_list)) {