Unify TTSD processes into two processes (default, interrupt) 82/265982/6
authorsooyeon <sooyeon.kim@samsung.com>
Wed, 3 Nov 2021 15:40:57 +0000 (00:40 +0900)
committersooyeon <sooyeon.kim@samsung.com>
Thu, 4 Nov 2021 15:21:19 +0000 (00:21 +0900)
- To reduce RAM usage, unifying 3 TTSD processes (default, sr, noti) is necessary.
- (server) Add a variable 'mode' into 'app_data_s' in ttsd_data. This is used when ttsd_player checks the current playing_info's mode.
- (client) Make only Default mode TTSD process launched, when client's mode is default/sr/noti.

Change-Id: Iba8c4ff99dd8d5b035c2804148a1b5b0803c4a27
Signed-off-by: sooyeon <sooyeon.kim@samsung.com>
15 files changed:
client/tts_core.c
client/tts_dbus.c
client/tts_dbus.h
client/tts_tidl.c
common/tts_defs.h
server/ttsd_data.cpp
server/ttsd_data.h
server/ttsd_dbus.c
server/ttsd_dbus_server.c
server/ttsd_dbus_server.h
server/ttsd_player.c
server/ttsd_server.c
server/ttsd_server.h
server/ttsd_tidl.c
tidl/tts.tidl

index 92b3579c8cd1b30ad6c2a5e5546d14314c7d08ec..3ed28a40b7eaff70bf692eb0a04dfb845c7e59e0 100644 (file)
@@ -64,12 +64,12 @@ static char* __get_engine_appid(int mode) {
                return NULL;
        }
 
-       if (TTS_MODE_DEFAULT == mode) {
+       if (TTS_MODE_DEFAULT <= mode && TTS_MODE_SCREEN_READER >= mode) {
                snprintf(appid, 256, "%s", g_engine_name);
-       } else if (TTS_MODE_NOTIFICATION == mode) {
-               snprintf(appid, 256, "%s-noti", g_engine_name);
-       } else if (TTS_MODE_SCREEN_READER == mode) {
-               snprintf(appid, 256, "%s-sr", g_engine_name);
+//     } else if (TTS_MODE_NOTIFICATION == mode) {
+//             snprintf(appid, 256, "%s-noti", g_engine_name);
+//     } else if (TTS_MODE_SCREEN_READER == mode) {
+//             snprintf(appid, 256, "%s-sr", g_engine_name);
        } else if (TTS_MODE_INTERRUPT == mode) {
                snprintf(appid, 256, "%s-interrupt", g_engine_name);
        } else {
index ac4655b6a6fa64b70b06fbd60ae7f2ff11b269a6..8519d29c73379fb17851338f0bb5406928043345 100644 (file)
@@ -46,12 +46,12 @@ static int __tts_dbus_add_match(int uid)
        }
 
        tts_mode_e mode = tts_client_get_mode(client);
-       if (TTS_MODE_DEFAULT == mode) {
+       if (TTS_MODE_DEFAULT <= mode && TTS_MODE_SCREEN_READER >= mode) {
                snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SERVER_SERVICE_INTERFACE);
-       } else if (TTS_MODE_NOTIFICATION == mode) {
-               snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_NOTI_SERVER_SERVICE_INTERFACE);
-       } else if (TTS_MODE_SCREEN_READER == mode) {
-               snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SR_SERVER_SERVICE_INTERFACE);
+//     } else if (TTS_MODE_NOTIFICATION == mode) {
+//             snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_NOTI_SERVER_SERVICE_INTERFACE);
+//     } else if (TTS_MODE_SCREEN_READER == mode) {
+//             snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SR_SERVER_SERVICE_INTERFACE);
        } else if (TTS_MODE_INTERRUPT == mode) {
                snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_INTERRUPT_SERVER_SERVICE_INTERFACE);
        }
@@ -81,12 +81,12 @@ static int __tts_dbus_remove_match(int mode)
        /* remove a rule for daemon error */
        char rule_err[256] = {0, };
 
-       if (TTS_MODE_DEFAULT == mode) {
+       if (TTS_MODE_DEFAULT <= mode && TTS_MODE_SCREEN_READER >= mode) {
                snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SERVER_SERVICE_INTERFACE);
-       } else if (TTS_MODE_NOTIFICATION == mode) {
-               snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_NOTI_SERVER_SERVICE_INTERFACE);
-       } else if (TTS_MODE_SCREEN_READER == mode) {
-               snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SR_SERVER_SERVICE_INTERFACE);
+//     } else if (TTS_MODE_NOTIFICATION == mode) {
+//             snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_NOTI_SERVER_SERVICE_INTERFACE);
+//     } else if (TTS_MODE_SCREEN_READER == mode) {
+//             snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SR_SERVER_SERVICE_INTERFACE);
        } else if (TTS_MODE_INTERRUPT == mode) {
                snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_INTERRUPT_SERVER_SERVICE_INTERFACE);
        }
@@ -152,6 +152,11 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
                                        __tts_dbus_add_match(uid);
                                }
                                tts_core_receive_hello(uid, ret, credential_needed);
+
+                               tts_client_s* client = tts_client_get_by_uid(uid);
+                               if (client) {
+                                       tts_dbus_request_set_mode(uid, tts_client_get_mode(client));
+                               }
                        }
 
                        SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
@@ -434,13 +439,13 @@ DBusMessage* __tts_dbus_make_message(int uid, const char* method)
        DBusMessage* msg;
 
        tts_mode_e mode = tts_client_get_mode(client);
-       if (TTS_MODE_DEFAULT == mode) {
+       if (TTS_MODE_DEFAULT <= mode && TTS_MODE_SCREEN_READER >= mode) {
                msg = dbus_message_new_method_call(
                        TTS_SERVER_SERVICE_NAME,
                        TTS_SERVER_SERVICE_OBJECT_PATH,
                        TTS_SERVER_SERVICE_INTERFACE,
                        method);
-       } else if (TTS_MODE_NOTIFICATION == mode) {
+/*     } else if (TTS_MODE_NOTIFICATION == mode) {
                msg = dbus_message_new_method_call(
                        TTS_NOTI_SERVER_SERVICE_NAME,
                        TTS_NOTI_SERVER_SERVICE_OBJECT_PATH,
@@ -452,7 +457,7 @@ DBusMessage* __tts_dbus_make_message(int uid, const char* method)
                        TTS_SR_SERVER_SERVICE_OBJECT_PATH,
                        TTS_SR_SERVER_SERVICE_INTERFACE,
                        method);
-       } else if (TTS_MODE_INTERRUPT == mode) {
+*/     } else if (TTS_MODE_INTERRUPT == mode) {
                msg = dbus_message_new_method_call(
                        TTS_INTERRUPT_SERVER_SERVICE_NAME,
                        TTS_INTERRUPT_SERVER_SERVICE_OBJECT_PATH,
@@ -608,12 +613,12 @@ int tts_dbus_request_initialize(int uid, bool* credential_needed)
                        }
 
                        tts_mode_e mode = tts_client_get_mode(client);
-                       if (TTS_MODE_DEFAULT == mode) {
+                       if (TTS_MODE_DEFAULT <= mode && TTS_MODE_SCREEN_READER >= mode) {
                                snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SERVER_SERVICE_INTERFACE);
-                       } else if (TTS_MODE_NOTIFICATION == mode) {
-                               snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_NOTI_SERVER_SERVICE_INTERFACE);
-                       } else if (TTS_MODE_SCREEN_READER == mode) {
-                               snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SR_SERVER_SERVICE_INTERFACE);
+//                     } else if (TTS_MODE_NOTIFICATION == mode) {
+//                             snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_NOTI_SERVER_SERVICE_INTERFACE);
+//                     } else if (TTS_MODE_SCREEN_READER == mode) {
+//                             snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SR_SERVER_SERVICE_INTERFACE);
                        } else if (TTS_MODE_INTERRUPT == mode) {
                                snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_INTERRUPT_SERVER_SERVICE_INTERFACE);
                        }
@@ -653,12 +658,12 @@ int tts_dbus_request_finalize(int uid)
        /* remove a rule for daemon error */
        tts_mode_e mode = tts_client_get_mode(client);
        SLOG(LOG_INFO, TAG_TTSC, "[INFO] Remove match, mode(%d)", mode);
-       if (TTS_MODE_DEFAULT == mode) {
+       if (TTS_MODE_DEFAULT <= mode && TTS_MODE_SCREEN_READER >= mode) {
                __tts_dbus_remove_match(TTS_MODE_DEFAULT);
-       } else if (TTS_MODE_NOTIFICATION == mode) {
-               __tts_dbus_remove_match(TTS_MODE_NOTIFICATION);
-       } else if (TTS_MODE_SCREEN_READER == mode) {
-               __tts_dbus_remove_match(TTS_MODE_SCREEN_READER);
+//     } else if (TTS_MODE_NOTIFICATION == mode) {
+//             __tts_dbus_remove_match(TTS_MODE_NOTIFICATION);
+//     } else if (TTS_MODE_SCREEN_READER == mode) {
+//             __tts_dbus_remove_match(TTS_MODE_SCREEN_READER);
        } else if (TTS_MODE_INTERRUPT == mode) {
                __tts_dbus_remove_match(TTS_MODE_INTERRUPT);
        }
@@ -714,6 +719,67 @@ int tts_dbus_request_finalize(int uid)
        return result;
 }
 
+int tts_dbus_request_set_mode(int uid, tts_mode_e mode)
+{
+       DBusMessage* msg;
+       DBusError err;
+       dbus_error_init(&err);
+
+       msg = __tts_dbus_make_message(uid, TTS_METHOD_SET_MODE);
+
+       if (NULL == msg) {
+               SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts set mode : Fail to make message");
+               return TTS_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts set mode : uid(%d), mode(%d)", uid, mode);
+       }
+
+       if (true != dbus_message_append_args(msg,
+               DBUS_TYPE_INT32, &uid,
+               DBUS_TYPE_INT32, &mode,
+               DBUS_TYPE_INVALID)) {
+               dbus_message_unref(msg);
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
+
+               return TTS_ERROR_OPERATION_FAILED;
+       }
+
+       DBusMessage* result_msg;
+       int result = TTS_ERROR_OPERATION_FAILED;
+
+       result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, WAITING_TIME, &err);
+       dbus_message_unref(msg);
+       if (dbus_error_is_set(&err)) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Send error (%s)", err.message);
+               dbus_error_free(&err);
+       }
+
+       if (NULL != result_msg) {
+               dbus_message_get_args(result_msg, &err,
+                       DBUS_TYPE_INT32, &result,
+                       DBUS_TYPE_INVALID);
+
+               if (dbus_error_is_set(&err)) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts set mode : Get arguments error (%s)", err.message);
+                       dbus_error_free(&err);
+                       result = TTS_ERROR_OPERATION_FAILED;
+               }
+               dbus_message_unref(result_msg);
+
+               if (0 == result) {
+                       SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts set mode : result(%d)", result);
+               } else {
+                       SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts set mode : result(%d)", result);
+               }
+       } else {
+               SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL ");
+               tts_dbus_reconnect();
+               result = TTS_ERROR_TIMED_OUT;
+       }
+
+       return result;
+}
+
 int tts_dbus_request_add_text(int uid, const char* text, const char* lang, int vctype, int speed, int uttid, const char* credential)
 {
        if (NULL == text || NULL == lang) {
index 6842fc3a7e5870fcaa030f9634414b7575191925..8c44495523210f6fe648032676eff785100b7193 100644 (file)
@@ -35,7 +35,7 @@ int tts_dbus_request_initialize(int uid, bool* credential_needed);
 
 int tts_dbus_request_finalize(int uid);
 
-int tts_dbus_set_sound_type(int uid, int type);
+int tts_dbus_request_set_mode(int uid, tts_mode_e mode);
 
 int tts_dbus_request_add_text(int uid, const char* text, const char* lang, int vctype, int speed, int uttid, const char* credential);
 
index 0c99d388d9c98892e897ab96d088e2c108499090..969ab39008a6f58f5fac8bc9ebd781fdb772c122 100644 (file)
@@ -161,7 +161,7 @@ static void __on_connected(rpc_port_proxy_tts_h h, void *user_data)
        info->connected = true;
        info->connection_requesting = false;
        info->register_callback_invoked = false;
-       if (0 != rpc_port_proxy_tts_invoke_set_mode(info->rpc_h, tts_client_get_mode(client))) {
+       if (0 != rpc_port_proxy_tts_invoke_set_mode(info->rpc_h, uid, tts_client_get_mode(client))) {
                SLOG(LOG_ERROR, TAG_TTSC, "Failed to set mode");
                return;
        }
@@ -231,11 +231,7 @@ static void __get_engine_app_id(int mode, int size, char* app_id)
        }
 
        char* mode_str = "";
-       if (TTS_MODE_NOTIFICATION == mode) {
-               mode_str = TTS_NOTI_SERVER_MODE;
-       } else if (TTS_MODE_SCREEN_READER == mode) {
-               mode_str = TTS_SR_SERVER_MODE;
-       } else if (TTS_MODE_INTERRUPT == mode) {
+       if (TTS_MODE_INTERRUPT == mode) {
                mode_str = TTS_INTERRUPT_SERVER_MODE;
        }
 
index 385bad84a1632c2727838e5643becbf4769d115b..80c6a4076d32e7c2ae3cfb8aef99b7a135cfe3cd 100644 (file)
@@ -39,12 +39,12 @@ extern "C" {
 #define TTS_NOTI_SERVER_SERVICE_NAME           "org.tizen.voice.ttsnotiserver"
 #define TTS_NOTI_SERVER_SERVICE_OBJECT_PATH    "/org/tizen/voice/ttsnotiserver"
 #define TTS_NOTI_SERVER_SERVICE_INTERFACE      "org.tizen.voice.ttsnotiserver"
-#define TTS_NOTI_SERVER_MODE                "-noti"
+//#define TTS_NOTI_SERVER_MODE                "-noti"
 
 #define TTS_SR_SERVER_SERVICE_NAME             "org.tizen.voice.ttssrserver"
 #define TTS_SR_SERVER_SERVICE_OBJECT_PATH      "/org/tizen/voice/ttssrserver"
 #define TTS_SR_SERVER_SERVICE_INTERFACE                "org.tizen.voice.ttssrserver"
-#define TTS_SR_SERVER_MODE                  "-sr"
+//#define TTS_SR_SERVER_MODE                  "-sr"
 
 #define TTS_INTERRUPT_SERVER_SERVICE_NAME              "org.tizen.voice.ttsinterruptserver"
 #define TTS_INTERRUPT_SERVER_SERVICE_OBJECT_PATH       "/org/tizen/voice/ttsinterruptserver"
@@ -65,6 +65,7 @@ extern "C" {
 #define TTS_METHOD_HELLO_SYNC       "tts_method_hello_sync"
 #define TTS_METHOD_INITIALIZE          "tts_method_initialize"
 #define TTS_METHOD_FINALIZE            "tts_method_finalilze"
+#define TTS_METHOD_SET_MODE     "tts_method_set_mode"
 #define TTS_METHOD_GET_SUPPORT_VOICES  "tts_method_get_support_voices"
 #define TTS_METHOD_GET_CURRENT_VOICE   "tts_method_get_current_voice"
 #define TTS_METHOD_ADD_QUEUE           "tts_method_add_queue"
index 94604fac905dee0f361a6e9f398b58af91686e80..70393bc74dc77cbc6a516a990a5f7674c4473001 100644 (file)
@@ -16,7 +16,6 @@
 #include <mutex>
 #include <vector>
 
-#include "ttsd_main.h"
 #include "ttsd_data.h"
 
 using namespace std;
@@ -33,6 +32,7 @@ typedef struct
        int             uid;
        int             utt_id_stopped;
        app_tts_state_e state;
+       ttsd_mode_e     mode;
 
        std::list<speak_data_s*> m_speak_data;
        std::list<sound_data_s*> m_wav_data;
@@ -162,6 +162,7 @@ int ttsd_data_new_client(int pid, int uid)
        app.uid = uid;
        app.utt_id_stopped = 0;
        app.state = APP_STATE_READY;
+       app.mode = TTSD_MODE_DEFAULT;
        app.ipc_method = TTS_IPC_METHOD_UNDEFINED;
 
        g_app_list.push_back(app);
@@ -319,6 +320,32 @@ tts_ipc_method_e ttsd_data_get_ipc_method(int uid)
        return app_data->ipc_method;
 }
 
+int ttsd_data_set_mode(int uid, ttsd_mode_e mode)
+{
+       lock_guard<mutex> lock(g_app_data_mutex);
+       app_data_s* app_data = __get_client_app_data(uid);
+       if (nullptr == app_data) {
+               SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
+               return TTSD_ERROR_INVALID_PARAMETER;
+       }
+
+       app_data->mode = mode;
+
+       return TTSD_ERROR_NONE;
+}
+
+ttsd_mode_e ttsd_data_get_mode(int uid)
+{
+       lock_guard<mutex> lock(g_app_data_mutex);
+       app_data_s* app_data = __get_client_app_data(uid);
+       if (nullptr == app_data) {
+               SECURE_SLOG(LOG_ERROR, tts_tag(), "[DATA ERROR] uid is not valid (%d)", uid);
+               return TTSD_MODE_DEFAULT;
+       }
+
+       return app_data->mode;
+}
+
 int ttsd_data_get_speak_data_size(int uid)
 {
        lock_guard<mutex> lock(g_app_data_mutex);
index cdc3861033b7c8b63c71a89f6df69eed80ad8a14..069333cbfa2e2aa53de52237a459e41ebabbde20 100644 (file)
@@ -18,6 +18,7 @@
 #include "ttse.h"
 #include "ttsd_stub.h"
 #include "tts_ipc_method.h"
+#include "ttsd_main.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -76,6 +77,10 @@ int ttsd_data_set_ipc_method(int uid, tts_ipc_method_e method);
 
 tts_ipc_method_e ttsd_data_get_ipc_method(int uid);
 
+int ttsd_data_set_mode(int uid, ttsd_mode_e mode);
+
+ttsd_mode_e ttsd_data_get_mode(int uid);
+
 /* speak data */
 int ttsd_data_add_speak_data(int uid, speak_data_s* data);
 
index 9395d141185516f88ed985ebabfb3ebf3c879b26..972735d508d8a6df6b5e4b88e2e3fb0374103b30 100644 (file)
@@ -227,6 +227,9 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
                } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_FINALIZE)) {
                        ttsd_dbus_server_finalize(g_conn_listener, msg);
 
+               } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_SET_MODE)) {
+                       ttsd_dbus_server_set_mode(g_conn_listener, msg);
+
                } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_GET_SUPPORT_VOICES)) {
                        ttsd_dbus_server_get_support_voices(g_conn_listener, msg);
 
index c0adacf7b09eeb7c2b8ac2b5698557f3ec42d51e..f6814dc49dc9893d4ccde6a5e68932d33dacd3e0 100644 (file)
@@ -190,6 +190,62 @@ int ttsd_dbus_server_finalize(DBusConnection* conn, DBusMessage* msg)
        return 0;
 }
 
+int ttsd_dbus_server_set_mode(DBusConnection* conn, DBusMessage* msg)
+{
+       DBusError err;
+       dbus_error_init(&err);
+
+       int uid;
+       int tmp_mode;
+       ttsd_mode_e mode;
+       int ret = 0;
+       dbus_message_get_args(msg, &err,
+               DBUS_TYPE_INT32, &uid,
+               DBUS_TYPE_INT32, &tmp_mode,
+               DBUS_TYPE_INVALID);
+
+       mode = (ttsd_mode_e)tmp_mode;
+       SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS set mode");
+
+       if (dbus_error_is_set(&err)) {
+               SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] Fail to get arguments (%s)", err.message);
+               dbus_error_free(&err);
+               ret = TTSD_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, tts_tag(), "[IN] tts set mode. uid(%d), mode(%d)", uid, mode);
+               ret = ttsd_server_set_mode(uid, mode);
+       }
+
+       DBusMessage* reply;
+       reply = dbus_message_new_method_return(msg);
+
+       if (NULL != reply) {
+               dbus_message_append_args(reply,
+                       DBUS_TYPE_INT32, &ret,
+                       DBUS_TYPE_INVALID);
+
+               if (0 == ret) {
+                       SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts set mode : (%d)", ret);
+               } else {
+                       SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts set mode : (%d)", ret);
+               }
+
+               if (!dbus_connection_send(conn, reply, NULL)) {
+                       SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] Fail to send reply");
+               }
+
+               dbus_connection_flush(conn);
+               dbus_message_unref(reply);
+       } else {
+               SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] Fail to create reply message");
+       }
+
+       SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
+       SLOG(LOG_DEBUG, tts_tag(), "");
+
+       return 0;
+}
+
 int ttsd_dbus_server_get_support_voices(DBusConnection* conn, DBusMessage* msg)
 {
        DBusError err;
index ec6dce1abf1791aaa85b0668147874e0a9050723..dad43c0e58d5e4db4b7bd8d01155038e9fb8a51a 100644 (file)
@@ -33,6 +33,8 @@ int ttsd_dbus_server_initialize(DBusConnection* conn, DBusMessage* msg);
 
 int ttsd_dbus_server_finalize(DBusConnection* conn, DBusMessage* msg);
 
+int ttsd_dbus_server_set_mode(DBusConnection* conn, DBusMessage* msg);
+
 int ttsd_dbus_server_get_support_voices(DBusConnection* conn, DBusMessage* msg);
 
 int ttsd_dbus_server_get_current_voice(DBusConnection* conn, DBusMessage* msg);
index cd506eb8f3dbc363c7f2aafe3b48dc2bdf96cb7e..76a8c8b8ce721097d6471287b74ecd52f0e34fb3 100644 (file)
@@ -191,11 +191,13 @@ static void __player_focus_state_cb(sound_stream_info_h stream_info, sound_strea
                return;
        }
 
-       switch (ttsd_get_mode()) {
+       int uid = g_playing_info->uid;
+       ttsd_mode_e mode = ttsd_data_get_mode(uid);
+
+       switch (mode) {
        case TTSD_MODE_DEFAULT:
-               SLOG(LOG_DEBUG, tts_tag(), "[Player] Pause current player - mode(%d)", ttsd_get_mode());
+               SLOG(LOG_DEBUG, tts_tag(), "[Player] Pause current player - mode(%d)", mode);
                g_audio_state = AUDIO_STATE_READY;
-               int uid = g_playing_info->uid;
 
                if (0 != ttsd_player_pause(uid)) {
                        SLOG(LOG_WARN, tts_tag(), "[Player WARNING] Fail to pause the player");
@@ -214,15 +216,15 @@ static void __player_focus_state_cb(sound_stream_info_h stream_info, sound_strea
                break;
        case TTSD_MODE_NOTIFICATION:
        case TTSD_MODE_SCREEN_READER:
-               SLOG(LOG_DEBUG, tts_tag(), "[Player] Stop current player - mode(%d)", ttsd_get_mode());
+               SLOG(LOG_DEBUG, tts_tag(), "[Player] Stop current player - mode(%d)", mode);
                g_audio_state = AUDIO_STATE_READY;
                ttsd_send_all_stop();
                break;
        case TTSD_MODE_INTERRUPT:
-               SLOG(LOG_DEBUG, tts_tag(), "[Player] Ignore focus release - mode(%d)", ttsd_get_mode());
+               SLOG(LOG_DEBUG, tts_tag(), "[Player] Ignore focus release - mode(%d)", mode);
                break;
        default:
-               SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Invalid mode - mode(%d)", ttsd_get_mode());
+               SLOG(LOG_ERROR, tts_tag(), "[Player ERROR] Invalid mode - mode(%d)", mode);
                break;
        }
 
@@ -378,7 +380,7 @@ static void __del_timer_for_delayed_recover(void* data)
        }
 }
 
-static void __set_policy_for_playing(int volume)
+static void __set_policy_for_playing(void)
 {
        ecore_main_loop_thread_safe_call_async(__del_timer_for_delayed_recover, NULL);
 
@@ -552,7 +554,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
        int idx = 0;
 
        /* set volume policy as 40% */
-       __set_policy_for_playing(40);
+       __set_policy_for_playing();
        while (1) { // 1st while(1)
                pthread_mutex_lock(&g_play_thread_mutex);
                /* check g_playing_info one more time */
@@ -679,7 +681,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
 
                                if (AUDIO_STATE_READY == g_audio_state || AUDIO_STATE_WAIT_FOR_PLAYING == g_audio_state) {
                                        /* set volume policy as 40%, when resume play thread*/
-                                       __set_policy_for_playing(40);
+                                       __set_policy_for_playing();
                                }
 
                                /* resume play thread */
@@ -766,7 +768,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                        }
 
                        SLOG(LOG_INFO, tts_tag(), "[Player INFO] Success to destroy and recreate audio out");
-                       __set_policy_for_playing(40);
+                       __set_policy_for_playing();
                }
 
                while (APP_STATE_PLAYING == player->state || APP_STATE_PAUSED == player->state) {
@@ -782,7 +784,7 @@ static void __play_thread(void *data, Ecore_Thread *thread)
                        // Check whether set_policy is done or not
                        if (false == g_is_set_policy) {
                                SLOG(LOG_INFO, tts_tag(), "[Player INFO] Set policy");
-                               __set_policy_for_playing(40);
+                               __set_policy_for_playing();
                        }
 
                        if (AUDIO_STATE_READY == g_audio_state || AUDIO_STATE_WAIT_FOR_PLAYING == g_audio_state) {
index 21c3808fbd873d616b0b7e26ec3328cc35438ff1..c13273b048a287da9fd92c80eeec179d37b43d61 100644 (file)
@@ -450,7 +450,7 @@ Eina_Bool ttsd_terminate_daemon(void *data)
 
 void __screen_reader_changed_cb(bool value)
 {
-       if (TTSD_MODE_SCREEN_READER == ttsd_get_mode() && false == value) {
+/*     if (TTSD_MODE_SCREEN_READER == ttsd_get_mode() && false == value) {
                SLOG(LOG_INFO, tts_tag(), "[Server] Screen reader is OFF. Start to terminate tts daemon");
                if (g_terminate_timer) {
                        ecore_timer_del(g_terminate_timer);
@@ -458,8 +458,9 @@ void __screen_reader_changed_cb(bool value)
                }
                g_terminate_timer = ecore_timer_add(1, ttsd_terminate_daemon, NULL);
        } else {
+*/
                SLOG(LOG_DEBUG, tts_tag(), "[Server] Screen reader is %s", value ? "ON" : "OFF");
-       }
+//     }
        return;
 }
 
@@ -524,9 +525,9 @@ int ttsd_initialize(ttse_request_callback_s *callback)
 
        ttsd_set_synth_control(TTSD_SYNTHESIS_CONTROL_EXPIRED);
 
-       if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
+//     if (TTSD_MODE_SCREEN_READER == ttsd_get_mode()) {
                ttsd_config_set_screen_reader_callback(__screen_reader_changed_cb);
-       }
+//     }
 
        g_check_client_timer = ecore_timer_add(CLIENT_CLEAN_UP_TIME, ttsd_cleanup_client, NULL);
        if (NULL == g_check_client_timer) {
@@ -827,6 +828,29 @@ int ttsd_server_finalize(int uid)
        return TTSD_ERROR_NONE;
 }
 
+int ttsd_server_set_mode(int uid, ttsd_mode_e mode)
+{
+       app_tts_state_e state;
+       if (0 > ttsd_data_get_client_state(uid, &state)) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid(%d) is NOT valid", uid);
+               return TTSD_ERROR_INVALID_PARAMETER;
+       }
+
+       if (APP_STATE_READY != state) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Current state(%d) is NOT 'READY'", uid);
+               return TTSD_ERROR_INVALID_STATE;
+       }
+
+       int ret = ttsd_data_set_mode(uid, mode);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set mode : ret(%d)", ret);
+       } else {
+               SLOG(LOG_DEBUG, tts_tag(), "[Server] Set mode. uid(%d), mode(%d)", uid, mode);
+       }
+
+       return ret;
+}
+
 int ttsd_server_add_queue(int uid, const char* text, const char* lang, int voice_type, int speed, int utt_id, const char* credential)
 {
        app_tts_state_e state;
@@ -940,7 +964,8 @@ Eina_Bool __send_interrupt_client(void *data)
                return EINA_FALSE;
        }
 
-       if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
+       ttsd_mode_e mode = ttsd_data_get_mode(uid);
+       if (TTSD_MODE_DEFAULT != mode) {
                /* send message to client about changing state */
                ttsdc_ipc_send_set_state_message(pid, uid, APP_STATE_READY);
        } else {
@@ -982,7 +1007,7 @@ int ttsd_server_play(int uid, const char* credential)
        SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
 
        if (uid != current_uid && -1 != current_uid) {
-               if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
+               if (TTSD_MODE_DEFAULT != ttsd_data_get_mode(current_uid)) {
                        /* Send interrupt message */
                        SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid);
 
@@ -1245,7 +1270,7 @@ int ttsd_server_play_pcm(int uid)
        SLOG(LOG_INFO, tts_tag(), "[Server] playing uid (%d)", current_uid);
 
        if (uid != current_uid && -1 != current_uid) {
-               if (TTSD_MODE_DEFAULT != ttsd_get_mode()) {
+               if (TTSD_MODE_DEFAULT != ttsd_data_get_mode(current_uid)) {
                        /* Send interrupt message */
                        SLOG(LOG_DEBUG, tts_tag(), "[Server] Old uid(%d) will be interrupted into 'Stop' state ", current_uid);
 
index 4b3b771d699f298ceb98ad0629be3f60387b98d5..f2251b216c2484e764793cd04c6207494d7c3245 100644 (file)
@@ -55,6 +55,8 @@ int ttsd_server_initialize(int pid, int uid, tts_ipc_method_e method, bool* cred
 
 int ttsd_server_finalize(int uid);
 
+int ttsd_server_set_mode(int uid, ttsd_mode_e mode);
+
 int ttsd_server_get_support_voices(int uid, GList** voice_list);
 
 int ttsd_server_get_current_voice(int uid, char** language, int* voice_type);
index e11797b49bd8ff34dac03e2d3db1973b54076306..f73cefd408d805c0833f1c23b01c227556f3b7db 100644 (file)
@@ -234,10 +234,17 @@ static int __register_cb_sync(rpc_port_stub_tts_context_h context, int pid, int
        return TTSE_ERROR_NONE;
 }
 
-static int __set_mode_cb(rpc_port_stub_tts_context_h context, int mode, void* user_data)
+static int __set_mode_cb(rpc_port_stub_tts_context_h context, int uid, int mode, void* user_data)
 {
        //ttsd_set_mode(mode);
-       SLOG(LOG_INFO, tts_tag(), "[Server] TTSD MODE : (%d)", ttsd_get_mode());
+       SLOG(LOG_INFO, tts_tag(), "[Server] Set client mode. uid (%d), mode (%d)", uid, mode);
+
+       int ret = -1;
+       ret = ttsd_data_set_mode(uid, mode);
+       if (TTSD_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server] Fail to set mode. uid is not invalid");
+               return ret;
+       }
 
        return TTSE_ERROR_NONE;
 }
index 9b0bb1955f219a65d852da82a697daf8ce4d129b..38fcf5773a76040f63cc82a6d3dc364145f19a42 100644 (file)
@@ -3,7 +3,7 @@ interface tts {
        void register_cb(int pid, int uid, notify_cb callback) async;
        int register_cb_sync(int pid, int uid, notify_cb callback);
 
-       int set_mode(int mode);
+       int set_mode(in int uid, in int mode);
        int initialize(in int pid, in int uid, out bool credential_needed);
        int finalize(in int uid);
        int add_text(int uid, string text, string lang, int vctype, int speed, int uttid, string credential);