Update hello protocol
[platform/core/uifw/tts.git] / client / tts_setting.c
index 911e17b..50d0cdc 100644 (file)
@@ -1,5 +1,5 @@
 /*
-*  Copyright (c) 2011-2014 Samsung Electronics Co., Ltd All Rights Reserved 
+*  Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 #include "tts_main.h"
 #include "tts_setting.h"
 
-/** 
+/**
 * @brief Enumerations of setting state.
 */
 typedef enum {
        TTS_SETTING_STATE_NONE = 0,
        TTS_SETTING_STATE_READY
-}tts_setting_state_e;
+} tts_setting_state_e;
 
 
 static tts_setting_state_e g_state = TTS_SETTING_STATE_NONE;
@@ -46,6 +46,8 @@ static void* g_speed_changed_user_data;
 static tts_setting_pitch_changed_cb g_pitch_changed_cb;
 static void* g_pitch_changed_user_data;
 
+static tts_setting_background_volume_ratio_changed_cb g_bg_volume_ratio_changed_cb;
+static void* g_bg_volume_ratio_changed_user_data;
 
 
 const char* tts_tag()
@@ -68,10 +70,10 @@ static int __setting_convert_config_error_code(tts_config_error_e code)
        return TTS_SETTING_ERROR_NONE;
 }
 
-void __setting_config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, int voice_type, bool auto_voice, void* user_data)
+void __setting_config_engine_changed_cb(const char* engine_id, const char* setting, const char* language, int voice_type, bool auto_voice, bool need_credential, void* user_data)
 {
-       SLOG(LOG_DEBUG, TAG_TTSC, "Engine chagned : engine(%s) setting(%s) lang(%s) type(%d)", 
-               engine_id, setting, language, language, voice_type);
+       SLOG(LOG_DEBUG, TAG_TTSC, "Engine changed : engine(%s) setting(%s) lang(%s) type(%d)",
+                engine_id, setting, language, voice_type);
 
        if (NULL != g_engine_changed_cb)
                g_engine_changed_cb(engine_id, g_engine_changed_user_data);
@@ -104,14 +106,21 @@ void __setting_config_pitch_changed_cb(int value, void* user_data)
                g_pitch_changed_cb(value, g_pitch_changed_user_data);
 }
 
+void __setting_config_bg_volume_ratio_changed_cb(double value, void* user_data)
+{
+       SLOG(LOG_DEBUG, TAG_TTSC, "Rratio : %lf", value);
+
+       if (NULL != g_bg_volume_ratio_changed_cb)
+               g_bg_volume_ratio_changed_cb(value, g_bg_volume_ratio_changed_user_data);
+}
+
 int tts_setting_initialize()
 {
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Initialize TTS Setting");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Initialize TTS Setting");
 
        if (TTS_SETTING_STATE_READY == g_state) {
                SLOG(LOG_WARN, TAG_TTSC, "[WARNING] TTS Setting has already been initialized.");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_SETTING_ERROR_NONE;
        }
 
@@ -121,8 +130,8 @@ int tts_setting_initialize()
                return __setting_convert_config_error_code(ret);
        }
 
-       ret = tts_config_mgr_set_callback(getpid(), __setting_config_engine_changed_cb, __setting_config_voice_changed_cb, 
-               __setting_config_speech_rate_changed_cb, __setting_config_pitch_changed_cb, NULL);
+       ret = tts_config_mgr_set_callback(getpid(), __setting_config_engine_changed_cb, __setting_config_voice_changed_cb,
+                                                                         __setting_config_speech_rate_changed_cb, __setting_config_pitch_changed_cb, __setting_config_bg_volume_ratio_changed_cb, NULL);
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to set config changed : %d", ret);
                return __setting_convert_config_error_code(ret);
@@ -142,22 +151,20 @@ int tts_setting_initialize()
        g_pitch_changed_cb = NULL;
        g_pitch_changed_user_data = NULL;
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return TTS_SETTING_ERROR_NONE;
 }
 
 int tts_setting_finalize()
 {
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Finalize TTS Setting");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Finalize TTS Setting");
 
        tts_config_mgr_finalize(getpid());
 
        g_state = TTS_SETTING_STATE_NONE;
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return TTS_SETTING_ERROR_NONE;
 }
@@ -172,8 +179,8 @@ bool __tts_config_mgr_get_engine_list(const char* engine_id, const char* engine_
 }
 
 int tts_setting_foreach_supported_engines(tts_setting_supported_engine_cb callback, void* user_data)
-{    
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Foreach supported engines");
+{
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Foreach supported engines");
 
        if (TTS_SETTING_STATE_NONE == g_state) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
@@ -194,27 +201,24 @@ int tts_setting_foreach_supported_engines(tts_setting_supported_engine_cb callba
 
        g_engine_cb = NULL;
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return __setting_convert_config_error_code(ret);
 }
 
 int tts_setting_get_engine(char** engine_id)
 {
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Get current engine");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get current engine");
 
        if (TTS_SETTING_STATE_NONE == g_state) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_SETTING_ERROR_INVALID_STATE;
        }
 
        if (NULL == engine_id) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Engine id is NULL");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_SETTING_ERROR_INVALID_PARAMETER;
        }
 
@@ -225,27 +229,24 @@ int tts_setting_get_engine(char** engine_id)
                SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Get current engine");
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return __setting_convert_config_error_code(ret);
 }
 
 int tts_setting_set_engine(const char* engine_id)
 {
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Set current engine");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Set current engine");
 
        if (TTS_SETTING_STATE_NONE == g_state) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_SETTING_ERROR_INVALID_STATE;
        }
 
        if (NULL == engine_id) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Engine id is NULL");
-               SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-               SLOG(LOG_DEBUG, TAG_TTSC, " ");
+               SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
                return TTS_SETTING_ERROR_INVALID_PARAMETER;
        }
 
@@ -255,16 +256,15 @@ int tts_setting_set_engine(const char* engine_id)
        } else {
                SECURE_SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set current engine : %s", engine_id);
        }
-       
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
-    
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
        return __setting_convert_config_error_code(ret);
 }
 
 int tts_setting_foreach_supported_voices(tts_setting_supported_voice_cb callback, void* user_data)
 {
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Foreach supported voices");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Foreach supported voices");
 
        if (TTS_SETTING_STATE_NONE == g_state) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
@@ -294,15 +294,14 @@ int tts_setting_foreach_supported_voices(tts_setting_supported_voice_cb callback
                SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Foreach supported voices");
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return __setting_convert_config_error_code(ret);
 }
 
 int tts_setting_get_voice(char** language, int* voice_type)
 {
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Get default voice");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get default voice");
 
        if (TTS_SETTING_STATE_NONE == g_state) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
@@ -321,15 +320,14 @@ int tts_setting_get_voice(char** language, int* voice_type)
                SECURE_SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Get default voices : lang(%s) type(%d)", *language, *voice_type);
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return __setting_convert_config_error_code(ret);
 }
 
 int tts_setting_set_voice(const char* language, int voice_type)
 {
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Set default voice");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Set default voice");
 
        if (TTS_SETTING_STATE_NONE == g_state) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
@@ -350,18 +348,17 @@ int tts_setting_set_voice(const char* language, int voice_type)
        if (0 != ret) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Result : %d", ret);
        } else {
-               SECURE_SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set default voice : lang(%s) type(%d)",language, voice_type);
+               SECURE_SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set default voice : lang(%s) type(%d)", language, voice_type);
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
-    
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
        return __setting_convert_config_error_code(ret);
 }
 
 int tts_setting_set_auto_voice(bool value)
 {
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Set auto voice");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Set auto voice");
 
        if (TTS_SETTING_STATE_NONE == g_state) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
@@ -380,15 +377,14 @@ int tts_setting_set_auto_voice(bool value)
                SECURE_SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set auto voice %s", value ? "on" : "off");
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return __setting_convert_config_error_code(ret);
 }
 
 int tts_setting_get_auto_voice(bool* value)
 {
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Get auto voice");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get auto voice");
 
        if (TTS_SETTING_STATE_NONE == g_state) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
@@ -407,15 +403,14 @@ int tts_setting_get_auto_voice(bool* value)
                SECURE_SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Get auto voice : %d ", (int)*value);
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return __setting_convert_config_error_code(ret);
 }
 
 int tts_setting_get_speed_range(int* min, int* normal, int* max)
 {
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Get speed range");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get speed range");
 
        if (TTS_SETTING_STATE_NONE == g_state) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
@@ -438,7 +433,7 @@ int tts_setting_get_speed_range(int* min, int* normal, int* max)
 
 int tts_setting_get_speed(int* speed)
 {
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Get default speed");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get default speed");
 
        if (TTS_SETTING_STATE_NONE == g_state) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
@@ -462,15 +457,14 @@ int tts_setting_get_speed(int* speed)
                SECURE_SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Get default speed : %d ", *speed);
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return __setting_convert_config_error_code(ret);
 }
 
 int tts_setting_set_speed(int speed)
 {
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Set default speed");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Set default speed");
 
        if (TTS_SETTING_STATE_NONE == g_state) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
@@ -488,16 +482,15 @@ int tts_setting_set_speed(int speed)
        } else {
                SECURE_SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set default speed, %d", speed);
        }
-       
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return __setting_convert_config_error_code(ret);
 }
 
 int tts_setting_get_pitch_range(int* min, int* normal, int* max)
 {
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Get speed range");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get speed range");
 
        if (TTS_SETTING_STATE_NONE == g_state) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
@@ -520,7 +513,7 @@ int tts_setting_get_pitch_range(int* min, int* normal, int* max)
 
 int tts_setting_set_pitch(int pitch)
 {
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Set default pitch");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Set default pitch");
 
        if (TTS_SETTING_STATE_NONE == g_state) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
@@ -539,15 +532,71 @@ int tts_setting_set_pitch(int pitch)
                SECURE_SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set default pitch, %d", pitch);
        }
 
-       SLOG(LOG_DEBUG, TAG_TTSC, "=====");
-       SLOG(LOG_DEBUG, TAG_TTSC, " ");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
+       return __setting_convert_config_error_code(ret);
+}
+
+int tts_setting_get_background_volume_ratio(double *ratio)
+{
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get background ratio");
+
+       if (TTS_SETTING_STATE_NONE == g_state) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
+               return TTS_SETTING_ERROR_INVALID_STATE;
+       }
+
+       if (NULL == ratio) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Param is NULL");
+               return TTS_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       double temp;
+       temp = 0;
+
+       int ret = tts_config_mgr_get_bg_volume_ratio(&temp);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Result : %d", ret);
+       } else {
+               /* Copy value */
+               *ratio = temp;
+               SECURE_SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Get bg volume duration : %lf", *ratio);
+       }
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+
+       return __setting_convert_config_error_code(ret);
+}
+
+int tts_setting_set_background_volume_ratio(double ratio)
+{
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Set bg volume duration");
+
+       if (TTS_SETTING_STATE_NONE == g_state) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
+               return TTS_SETTING_ERROR_INVALID_STATE;
+       }
+
+       if (0.0 > ratio || ratio > 1.0) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid bg volume ratio(%lf)", ratio);
+               return TTS_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       int ret = tts_config_mgr_set_bg_volume_ratio(ratio);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Result : %d", ret);
+       } else {
+               SECURE_SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set bg volume ratio : %lf", ratio);
+       }
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
 
        return __setting_convert_config_error_code(ret);
 }
 
 int tts_setting_get_pitch(int* pitch)
 {
-       SLOG(LOG_DEBUG, TAG_TTSC, "===== Get default pitch");
+       SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get default pitch");
 
        if (TTS_SETTING_STATE_NONE == g_state) {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Not initialized");
@@ -658,3 +707,25 @@ int tts_setting_unset_pitch_changed_cb()
 
        return TTS_SETTING_ERROR_NONE;
 }
+
+
+int tts_setting_set_background_volume_ratio_changed_cb(tts_setting_background_volume_ratio_changed_cb callback, void* user_data)
+{
+       if (NULL == callback) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input param is NULL");
+               return TTS_SETTING_ERROR_INVALID_PARAMETER;
+       }
+
+       g_bg_volume_ratio_changed_cb = callback;
+       g_bg_volume_ratio_changed_user_data = user_data;
+
+       return TTS_SETTING_ERROR_NONE;
+}
+
+int tts_setting_unset_background_volume_ratio_changed_cb()
+{
+       g_bg_volume_ratio_changed_cb = NULL;
+       g_bg_volume_ratio_changed_user_data = NULL;
+
+       return TTS_SETTING_ERROR_NONE;
+}