Implement behavior of new APIs 62/279162/5
authorSuyeon Hwang <stom.hwang@samsung.com>
Mon, 1 Aug 2022 08:35:07 +0000 (17:35 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Wed, 17 Aug 2022 02:55:39 +0000 (11:55 +0900)
This patch is for implementing new APIs introduced from previous commit.

Change-Id: Iaa157ffd229bf39f2a20754dfb641ea943c2e532
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
server/ttsd_engine_agent.c
server/ttsd_engine_agent.h
server/ttsd_main.h
server/ttsd_server.c
server/ttsd_server.h
server/ttse.c

index 37046ac..eed66c6 100644 (file)
@@ -189,6 +189,7 @@ static int __set_engine_callback(ttse_request_callback_s* callback, ttsengine_in
 
        engine_info->callbacks->private_data_set = NULL;
        engine_info->callbacks->private_data_requested = NULL;
+       engine_info->callbacks->activated_mode_changed = NULL;
 
        SLOG(LOG_DEBUG, tts_tag(), "--- Valid Engine ---");
        SLOG(LOG_DEBUG, tts_tag(), "Engine uuid : %s", engine_info->engine_uuid);
@@ -1154,6 +1155,23 @@ int ttsd_engine_check_app_agreed(const char* appid, bool* is_agreed)
        return ret;
 }
 
+int ttsd_engine_notify_activated_mode_changed(int activated_mode)
+{
+       if (false == __is_agent_initialized()) {
+               SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
+               return TTSD_ERROR_INVALID_STATE;
+       }
+
+       if (NULL == g_engine_info->callbacks->activated_mode_changed) {
+               SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not supported feature");
+               return TTSD_ERROR_NOT_SUPPORTED_FEATURE;
+       }
+
+       g_engine_info->callbacks->activated_mode_changed(activated_mode);
+
+       return TTSD_ERROR_NONE;
+}
+
 void __free_voice_list(GList* voice_list)
 {
        GList *iter = NULL;
@@ -1249,3 +1267,15 @@ int ttsd_engine_agent_set_private_data_requested_cb(ttse_private_data_requested_
 
        return TTSD_ERROR_NONE;
 }
+
+int ttsd_engine_agent_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback)
+{
+       if (false == __is_agent_initialized()) {
+               SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
+               return TTSD_ERROR_INVALID_STATE;
+       }
+
+       g_engine_info->callbacks->activated_mode_changed = callback;
+
+       return TTSD_ERROR_NONE;
+}
index e258448..29a4fe8 100644 (file)
@@ -39,6 +39,7 @@ int ttsd_engine_agent_load_current_engine();
 /** Set callbacks of the current engine */
 int ttsd_engine_agent_set_private_data_set_cb(ttse_private_data_set_cb callback);
 int ttsd_engine_agent_set_private_data_requested_cb(ttse_private_data_requested_cb callback);
+int ttsd_engine_agent_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback);
 
 /** Unload current engine */
 int ttsd_engine_agent_unload_current_engine();
@@ -67,6 +68,8 @@ int ttsd_engine_get_private_data(const char* key, char** data);
 
 int ttsd_engine_check_app_agreed(const char* appid, bool* is_agreed);
 
+int ttsd_engine_notify_activated_mode_changed(int activated_mode);
+
 /*
 * TTS Engine Interfaces for client
 */
index 4aef762..d35def8 100644 (file)
@@ -98,6 +98,7 @@ typedef struct {
        ttse_need_app_credential_cb             need_app_credential;
        ttse_private_data_set_cb                private_data_set;
        ttse_private_data_requested_cb          private_data_requested;
+       ttse_activated_mode_changed_cb          activated_mode_changed;
 } tts_engine_callback_s;
 
 
index 76c9659..f515c33 100644 (file)
@@ -55,6 +55,7 @@ static GList *g_proc_list = NULL;
 
 static bool g_is_terminated = false;
 
+static int g_activated_mode = 0;
 
 /* Function definitions */
 static int __stop_and_send_ready_state(unsigned int uid)
@@ -586,6 +587,8 @@ int ttsd_initialize(ttse_request_callback_s *callback)
                SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to create timer");
        }
 
+       g_activated_mode = 0;
+
        return TTSD_ERROR_NONE;
 }
 
@@ -672,6 +675,51 @@ int ttsd_server_is_already_initialized(int pid, unsigned int uid, bool* is_initi
        return TTSD_ERROR_NONE;
 }
 
+static void __set_and_notify_activated_mode()
+{
+       int activated_mode = ttsd_data_get_activated_mode();
+       if (g_activated_mode == activated_mode) {
+               return;
+       }
+
+       SLOG(LOG_INFO, tts_tag(), "[Server] Activated mode is changed from(%d) to (%d)", g_activated_mode, activated_mode);
+
+       g_activated_mode = activated_mode;
+       int ret = ttsd_engine_notify_activated_mode_changed(g_activated_mode);
+       if (TTSD_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to notify activated mode changed event.(%d)", ret);
+       }
+}
+
+static int __check_app_agreed(int pid, unsigned int uid, bool credential_needed)
+{
+       if (false == credential_needed) {
+               return TTSD_ERROR_NONE;
+       }
+
+       char* appid = NULL;
+       if (APP_MANAGER_ERROR_NONE != app_manager_get_app_id(pid, &appid)) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id, pid(%d)", pid);
+       }
+
+       bool is_agreed = false;
+       int ret = ttsd_engine_check_app_agreed(appid, &is_agreed);
+       free(appid);
+       appid = NULL;
+
+       if (TTSD_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed");
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
+
+       if (false == is_agreed) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
+               return TTSD_ERROR_PERMISSION_DENIED;
+       }
+
+       return TTSD_ERROR_NONE;
+}
+
 int ttsd_server_initialize(int pid, unsigned int uid, ttsd_mode_e mode, tts_ipc_method_e method, bool* credential_needed)
 {
        SLOG(LOG_INFO, tts_tag(), "[Server] Server initialize");
@@ -681,46 +729,35 @@ int ttsd_server_initialize(int pid, unsigned int uid, ttsd_mode_e mode, tts_ipc_
                return TTSD_ERROR_NONE;
        }
 
-       if (0 != ttsd_data_new_client(pid, uid, mode, method)) {
+       if (TTSD_ERROR_NONE != ttsd_data_new_client(pid, uid, mode, method)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info");
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
+       __set_and_notify_activated_mode();
+
        if (TTSD_ERROR_NONE != ttsd_engine_agent_load_current_engine()) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to load current engine");
                ttsd_data_delete_client(uid);
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       if (0 != ttsd_engine_agent_is_credential_needed(uid, credential_needed)) {
+       bool is_needed = false;
+       if (TTSD_ERROR_NONE != ttsd_engine_agent_is_credential_needed(uid, &is_needed)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get credential necessity");
                ttsd_data_delete_client(uid);
                return TTSD_ERROR_OPERATION_FAILED;
        }
 
-       if (true == *credential_needed) {
-               char* appid = NULL;
-               if (0 != app_manager_get_app_id(pid, &appid)) {
-                       SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get app id, pid(%d)", pid);
-               }
-               bool is_agreed = false;
-               if (0 != ttsd_engine_check_app_agreed(appid, &is_agreed)) {
-                       SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to check app agreed");
-                       if (!appid)
-                               free(appid);
-                       ttsd_data_delete_client(uid);
-                       return TTSD_ERROR_OPERATION_FAILED;
-               }
-               if (!appid)
-                       free(appid);
-
-               if (false == is_agreed) {
-                       SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
-                       ttsd_data_delete_client(uid);
-                       return TTSD_ERROR_PERMISSION_DENIED;
-               }
+       int ret = __check_app_agreed(pid, uid, is_needed);
+       if (TTSD_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Checking credential is finished(%d)", ret);
+               ttsd_data_delete_client(uid);
+               return ret;
        }
 
+       *credential_needed = is_needed;
+
        return TTSD_ERROR_NONE;
 }
 
@@ -753,6 +790,7 @@ int ttsd_server_finalize(unsigned int uid)
        }
 
        ttsd_data_delete_client(uid);
+       __set_and_notify_activated_mode();
 
        /* unload engine, if ref count of client is 0 */
        if (0 == ttsd_data_get_client_count()) {
@@ -1164,6 +1202,26 @@ int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback)
        return ret;
 }
 
+int ttsd_get_activated_mode(int* activated_mode)
+{
+       if (NULL == activated_mode) {
+               return TTSD_ERROR_INVALID_PARAMETER;
+       }
+
+       *activated_mode = ttsd_data_get_activated_mode();
+       return TTSD_ERROR_NONE;
+}
+
+int ttsd_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback)
+{
+       int ret = ttsd_engine_agent_set_activated_mode_changed_cb(callback);
+       if (TTSD_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to set private data requested cb : ret(%d)", ret);
+       }
+
+       return ret;
+}
+
 int ttsd_server_play_pcm(unsigned int uid)
 {
        app_tts_state_e state = ttsd_data_get_client_state(uid);
index 271a8eb..bf52d15 100644 (file)
@@ -40,6 +40,9 @@ int ttsd_send_error(ttse_error_e error, const char* msg);
 int ttsd_set_private_data_set_cb(ttse_private_data_set_cb callback);
 int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback);
 
+int ttsd_get_activated_mode(int* activated_mode);
+int ttsd_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback);
+
 /*
 * Server API for client
 */
index a04fc84..e9b8c36 100755 (executable)
@@ -248,8 +248,17 @@ int ttse_get_activated_mode(int* activated_mode)
                return TTSE_ERROR_INVALID_PARAMETER;
        }
 
-       // TODO: Implement function
-       return TTSE_ERROR_NONE;
+       if (g_is_terminated) {
+               SLOG(LOG_ERROR, tts_tag(), "[ERROR] Service engine is terminated.");
+               return TTSE_ERROR_INVALID_STATE;
+       }
+
+       int ret = ttsd_get_activated_mode(activated_mode);
+       if (TTSD_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get activated mode. ret(%d/%s)", ret, get_error_message(ret));
+       }
+
+       return ret;
 }
 
 int ttse_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback)
@@ -259,6 +268,15 @@ int ttse_set_activated_mode_changed_cb(ttse_activated_mode_changed_cb callback)
                return TTSE_ERROR_INVALID_PARAMETER;
        }
 
-       // TODO: Implement function
-       return TTSE_ERROR_NONE;
+       if (g_is_terminated) {
+               SLOG(LOG_ERROR, tts_tag(), "[ERROR] Service engine is terminated.");
+               return TTSE_ERROR_INVALID_STATE;
+       }
+
+       int ret = ttsd_set_activated_mode_changed_cb(callback);
+       if (TTSD_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to set activated mode changed cb. ret(%d/%s)", ret, get_error_message(ret));
+       }
+
+       return ret;
 }