Add to check if app agreed or not 85/153685/1
authorWonnam Jang <wn.jang@samsung.com>
Fri, 29 Sep 2017 06:24:46 +0000 (15:24 +0900)
committerWonnam Jang <wn.jang@samsung.com>
Fri, 29 Sep 2017 06:24:46 +0000 (15:24 +0900)
Change-Id: Iba982d2ed086a4319356efb4b3ddf2339cfadc65
Signed-off-by: Wonnam Jang <wn.jang@samsung.com>
client/tts.c
server/ttsd_data.cpp
server/ttsd_data.h
server/ttsd_engine_agent.c
server/ttsd_engine_agent.h
server/ttsd_player.c
server/ttsd_server.c

index d76ef7c..1b07804 100644 (file)
@@ -601,6 +601,16 @@ static Eina_Bool __tts_connect_daemon(void *data)
                client->conn_timer = NULL;
                return EINA_FALSE;
 
+       } else if (TTS_ERROR_PERMISSION_DENIED == ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret));
+
+               client->reason = TTS_ERROR_PERMISSION_DENIED;
+               client->utt_id = -1;
+
+               ecore_timer_add(0, __tts_notify_error, (void*)client->tts);
+               client->conn_timer = NULL;
+               return EINA_FALSE;
+
        } else if (TTS_ERROR_NONE != ret) {
                SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Fail to connection. Retry to connect : %s", __tts_get_error_code(ret));
                return EINA_TRUE;
index fa8226f..93bbd50 100644 (file)
@@ -31,7 +31,7 @@ typedef struct
        int             pid;
        int             uid;
        int             utt_id_stopped;
-       app_state_e     state;
+       app_tts_state_e state;
 
        std::list<speak_data_s*> m_speak_data;
        std::list<sound_data_s*> m_wav_data;
@@ -544,7 +544,7 @@ int ttsd_data_clear_data(int uid)
        return TTSD_ERROR_NONE;
 }
 
-int ttsd_data_get_client_state(int uid, app_state_e* state)
+int ttsd_data_get_client_state(int uid, app_tts_state_e* state)
 {
        int index = 0;
 
@@ -559,7 +559,7 @@ int ttsd_data_get_client_state(int uid, app_state_e* state)
        return TTSD_ERROR_NONE;
 }
 
-int ttsd_data_set_client_state(int uid, app_state_e state)
+int ttsd_data_set_client_state(int uid, app_tts_state_e state)
 {
        int index = 0;
 
@@ -694,7 +694,7 @@ int ttsd_data_save_error_log(int uid, FILE* fp)
                fprintf(fp, "pid - %d", pid);
        }
        /* app state */
-       app_state_e state;
+       app_tts_state_e state;
        ret = ttsd_data_get_client_state(uid, &state);
        if (0 != ret) {
                SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to get app state");
index 8860968..afbd213 100644 (file)
 extern "C" {
 #endif
 
+
 typedef enum {
        APP_STATE_CREATED = 0,
        APP_STATE_READY,
        APP_STATE_PLAYING,
        APP_STATE_PAUSED
-} app_state_e;
+} app_tts_state_e;
 
 typedef struct {
        int     utt_id; 
@@ -80,14 +81,14 @@ int ttsd_data_set_used_voice(int uid, const char* lang, int type);
 
 int ttsd_data_reset_used_voice(int uid, ttsd_used_voice_cb callback);
 
-int ttsd_data_get_client_state(int pid, app_state_e* state);
+int ttsd_data_get_client_state(int pid, app_tts_state_e* state);
 
-int ttsd_data_set_client_state(int pid, app_state_e state);
+int ttsd_data_set_client_state(int pid, app_tts_state_e state);
 
 
 int ttsd_data_get_current_playing();
 
-typedef bool(*ttsd_data_get_client_cb)(int pid, int uid, app_state_e state, void* user_data);
+typedef bool(*ttsd_data_get_client_cb)(int pid, int uid, app_tts_state_e state, void* user_data);
 
 int ttsd_data_foreach_clients(ttsd_data_get_client_cb callback, void* user_data);
 
index cd31434..2f87c11 100644 (file)
@@ -1166,6 +1166,42 @@ int ttsd_engine_get_private_data(const char* key, char** data)
        return ret;
 }
 
+int ttsd_engine_check_app_agreed(const char* appid, bool* is_agreed)
+{
+       if (false == g_agent_init) {
+               SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not Initialized");
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
+
+       if (false == g_engine_info->is_loaded) {
+               SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] No loaded engine");
+               return TTSD_ERROR_ENGINE_NOT_FOUND;
+       }
+
+       if (NULL == appid || NULL == is_agreed) {
+               SLOG(LOG_WARN, tts_tag(), "[Engine Agent WARNING] Invalid parameter, appid is NULL");
+               return TTSD_ERROR_NONE;
+       }
+
+
+       if (NULL == g_engine_info->callbacks->check_app_agreed) {
+               SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Not supported feature");
+               return TTSD_ERROR_NOT_SUPPORTED_FEATURE;
+       }
+
+       int ret = 0;
+       bool tmp = true; // default value is true until now
+       ret = g_engine_info->callbacks->check_app_agreed(appid, &tmp);
+       if (0 != ret) {
+               SLOG(LOG_ERROR, tts_tag(), "[Engine Agent ERROR] Fail to check app agreed(%d)", ret);
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
+
+       *is_agreed = tmp;
+
+       return ret;
+}
+
 void __free_voice_list(GList* voice_list)
 {
        GList *iter = NULL;
index c3eda4f..13b821c 100644 (file)
@@ -65,6 +65,8 @@ int ttsd_engine_set_private_data(const char* key, const char* data);
 
 int ttsd_engine_get_private_data(const char* key, char** data);
 
+int ttsd_engine_check_app_agreed(const char* appid, bool* is_agreed);
+
 /*
 * TTS Engine Interfaces for client
 */
index ec6a4db..44f1167 100644 (file)
@@ -33,7 +33,7 @@ typedef enum {
 
 typedef struct {
        int                     uid;    /** client id */
-       app_state_e             state;  /** client state */
+       app_tts_state_e         state;  /** client state */
 
        /* Current utterance information */
        ttse_result_event_e     event;  /** event of last utterance */
@@ -1031,7 +1031,7 @@ int ttsd_player_all_stop()
                        /* Get handle data from list */
                        data = (player_s*)iter->data;
 
-                       app_state_e state;
+                       app_tts_state_e state;
                        if (0 > ttsd_data_get_client_state(data->uid, &state)) {
                                SLOG(LOG_ERROR, tts_tag(), "[player ERROR] uid(%d) is not valid", data->uid);
                                ttsd_player_destroy_instance(data->uid);
index cdd6e9b..c49a7bd 100644 (file)
@@ -11,6 +11,7 @@
 *  limitations under the License.
 */
 
+#include <app_manager.h>
 #include <aul.h>
 #include <Ecore.h>
 
@@ -297,7 +298,7 @@ int ttsd_send_result(ttse_result_event_e event, const void* data, unsigned int d
        return TTSD_ERROR_NONE;
 }
 
-bool __get_client_cb(int pid, int uid, app_state_e state, void* user_data)
+bool __get_client_cb(int pid, int uid, app_tts_state_e state, void* user_data)
 {
        /* clear client data */
        ttsd_data_clear_data(uid);
@@ -406,7 +407,7 @@ void __config_changed_cb(tts_config_type_e type, const char* str_param, int int_
        return;
 }
 
-bool __terminate_client(int pid, int uid, app_state_e state, void* user_data)
+bool __terminate_client(int pid, int uid, app_tts_state_e state, void* user_data)
 {
        SLOG(LOG_INFO, tts_tag(), "@@@ Start to terminate client [%d]", uid);
        ttsd_server_finalize(uid);
@@ -523,9 +524,29 @@ int ttsd_server_initialize(int pid, int uid, bool* credential_needed)
        }
 
        if (0 != ttsd_engine_agent_is_credential_needed(uid, credential_needed)) {
-               SLOG(LOG_ERROR, tts_tag(), "Server ERROR] Fail to get credential necessity");
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to get credential necessity");
                return TTSD_ERROR_OPERATION_FAILED;
        }
+
+       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);
+               return TTSD_ERROR_OPERATION_FAILED;
+       }
+       if (!appid)
+               free(appid);
+
+       if (false == is_agreed) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] App is not agreed");
+               return TTSD_ERROR_PERMISSION_DENIED;
+       }
+
        if (0 != ttsd_data_new_client(pid, uid)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] Fail to add client info");
                return TTSD_ERROR_OPERATION_FAILED;
@@ -584,7 +605,7 @@ static void __read_proc()
        return;
 }
 
-bool __get_client_for_clean_up(int pid, int uid, app_state_e state, void* user_data)
+bool __get_client_for_clean_up(int pid, int uid, app_tts_state_e state, void* user_data)
 {
        bool exist = false;
        int i = 0;
@@ -661,7 +682,7 @@ int ttsd_server_finalize(int uid)
 {
        SLOG(LOG_INFO, tts_tag(), "[Server] Server finalize");
 
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_finalize : uid is not valid");
        }
@@ -690,7 +711,7 @@ int ttsd_server_finalize(int uid)
 
 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_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_add_queue : uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -809,7 +830,7 @@ Eina_Bool __send_interrupt_client(void *data)
 
 int ttsd_server_play(int uid, const char* credential)
 {
-       app_state_e state;
+       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;
@@ -892,7 +913,7 @@ int ttsd_server_play(int uid, const char* credential)
 
 int ttsd_server_stop(int uid)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -926,7 +947,7 @@ int ttsd_server_stop(int uid)
 
 int ttsd_server_pause(int uid, int* utt_id)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_pause : uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -954,7 +975,7 @@ int ttsd_server_pause(int uid, int* utt_id)
 
 int ttsd_server_get_support_voices(int uid, GList** voice_list)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -974,7 +995,7 @@ int ttsd_server_get_support_voices(int uid, GList** voice_list)
 
 int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_get_current_voice : uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;
@@ -994,7 +1015,7 @@ int ttsd_server_get_current_voice(int uid, char** language, int* voice_type)
 
 int ttsd_server_set_private_data(int uid, const char* key, const char* data)
 {
-       app_state_e state;
+       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;
@@ -1017,7 +1038,7 @@ int ttsd_server_set_private_data(int uid, const char* key, const char* data)
 
 int ttsd_server_get_private_data(int uid, const char* key, char** data)
 {
-       app_state_e state;
+       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;
@@ -1066,7 +1087,7 @@ int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback)
 
 int ttsd_server_play_pcm(int uid)
 {
-       app_state_e state;
+       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;
@@ -1125,7 +1146,7 @@ int ttsd_server_play_pcm(int uid)
 
 int ttsd_server_stop_pcm(int uid)
 {
-       app_state_e state;
+       app_tts_state_e state;
        if (0 > ttsd_data_get_client_state(uid, &state)) {
                SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] uid is not valid");
                return TTSD_ERROR_INVALID_PARAMETER;