Fix tidl_request_hello logic to match tidl and dbus behavior 08/260008/4
authorSuyeon Hwang <stom.hwang@samsung.com>
Wed, 21 Apr 2021 04:49:48 +0000 (13:49 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Mon, 28 Jun 2021 01:34:50 +0000 (10:34 +0900)
Change-Id: I2b7731701f9117775d94d0efc1bcd77065be24a9
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/tts_tidl.c
common/tts_defs.h
server/ttsd_tidl.c
server/ttsd_tidl.h

index d8c407e..130f2d7 100644 (file)
@@ -138,10 +138,16 @@ static void __notify_cb(void *user_data, int pid, int uid, bundle *msg)
        bundle_get_str(msg, TTS_BUNDLE_METHOD, &method);
 
        if (0 == strncmp(TTSD_METHOD_HELLO, method, strlen(TTSD_METHOD_HELLO))) {
-               bundle_get_str(msg, TTS_BUNDLE_CREDENTIAL_NEEDED, &val);
-               if (val) {
+               char* credential_needed = NULL;
+               char* ret = NULL;
+               bundle_get_str(msg, TTS_BUNDLE_CREDENTIAL_NEEDED, &credential_needed);
+               bundle_get_str(msg, TTS_BUNDLE_REASON, &ret);
+
+               if (NULL != credential_needed && NULL != ret) {
                        tts_client_set_start_listening(uid, true);
-                       tts_core_receive_hello(uid, 0, atoi(val));
+                       tts_core_receive_hello(uid, atoi(ret), atoi(credential_needed));
+               } else {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get message(TTSD_METHOD_HELLO). pid(%d) uid(%d)", pid, uid);
                }
        } else if (0 == strncmp(TTSD_METHOD_UTTERANCE_STARTED, method, strlen(TTSD_METHOD_UTTERANCE_STARTED))) {
                bundle_get_str(msg, TTS_BUNDLE_UTTID, &val);
@@ -169,8 +175,7 @@ static void __notify_cb(void *user_data, int pid, int uid, bundle *msg)
                if (reason && uttid) {
                        tts_core_notify_error_async(client, atoi(reason), atoi(uttid), err_msg);
                }
-       }
-       else {
+       } else {
                SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Invalid msg");
        }
 }
index b2d66b0..828adb4 100644 (file)
@@ -54,7 +54,7 @@ extern "C" {
 /******************************************************************************************
 * Message Definition for APIs
 *******************************************************************************************/
-#define TTS_BUNDLE_METHOD        "method"
+#define TTS_BUNDLE_METHOD "method"
 #define TTS_BUNDLE_STATE "state"
 #define TTS_BUNDLE_UTTID "uttid"
 #define TTS_BUNDLE_REASON "reason"
index b9f7154..284633e 100644 (file)
@@ -65,10 +65,22 @@ static void __register_cb(rpc_port_stub_tts_context_h context, int pid, int uid,
 {
        SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS REGISTER CALLBACK uid(%d)", uid);
 
-       bool credential_needed = false;
-       if (0 != ttsd_server_initialize(pid, uid, TTS_IPC_METHOD_TIDL, &credential_needed)) {
-               SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] ttsd Hello : server initialize");
-               return;
+       bool is_initialized = false;
+       ttsd_server_is_already_initialized(pid, uid, &is_initialized);
+
+       int ret = -1;
+       int credential_needed = 0;
+       if (false == is_initialized) {
+               bool is_credential_needed = false;
+               ret = ttsd_server_initialize(pid, uid, TTS_IPC_METHOD_TIDL, &is_credential_needed);
+               if (0 != ret) {
+                       SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] ttsd Hello : server initialize, ret(%d)", ret);
+               }
+
+               credential_needed = is_credential_needed ? 1 : 0;
+       } else {
+               ret = TTS_ERROR_ALREADY_INITIALIZED;
+               credential_needed = TTS_CREDENTIAL_NEEDED_ALREADY_INITIALIZED;
        }
 
        if (0 != ttsd_data_set_notify_h(uid, callback, NULL)) {
@@ -77,7 +89,7 @@ static void __register_cb(rpc_port_stub_tts_context_h context, int pid, int uid,
        }
 
        SLOG(LOG_INFO, tts_tag(), "create player instance");
-       ttsdc_tidl_send_hello(pid, uid, (int)credential_needed);
+       ttsdc_tidl_send_hello(pid, uid, ret, credential_needed);
 
        SLOG(LOG_ERROR, tts_tag(), "<<<<<<<<<<<");
 
@@ -127,20 +139,30 @@ static int __set_mode_cb(rpc_port_stub_tts_context_h context, int mode, void* us
        return TTSE_ERROR_NONE;
 }
 
-int ttsdc_tidl_send_hello(int pid, int uid, int credential_needed)
+int ttsdc_tidl_send_hello(int pid, int uid, int ret, int credential_needed)
 {
        SLOG(LOG_INFO, tts_tag(), "[TIDL] ttsdc_tidl_send_hello : pid(%d), uid(%d), credential_needed(%d)", pid, uid, credential_needed);
 
        char tmp_val[10] = {0, };
+       char ret_val[12] = {0, };
+       snprintf(tmp_val, 10, "%d", credential_needed);
+       snprintf(ret_val, 12, "%d", ret);
+
        bundle* msg = bundle_create();
-       snprintf(tmp_val, 10, "%d", (int)credential_needed);
+       if (NULL == msg) {
+               SLOG(LOG_ERROR, tts_tag(), "[TIDL] Fail to create bundle: pid(%d), uid(%d)", pid, uid);
+               return TTSD_ERROR_OUT_OF_MEMORY;
+       }
+
        bundle_add_str(msg, TTS_BUNDLE_METHOD, TTSD_METHOD_HELLO);
+       bundle_add_str(msg, TTS_BUNDLE_REASON, ret_val);
        bundle_add_str(msg, TTS_BUNDLE_CREDENTIAL_NEEDED, tmp_val);
 
        SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTSD SEND HELLO MSG");
        __send_msg(pid, uid, msg);
 
-       return TTSE_ERROR_NONE;
+       bundle_free(msg);
+       return TTSD_ERROR_NONE;
 }
 
 static int __initialize_cb(rpc_port_stub_tts_context_h context, int pid, int uid, bool *credential_needed, void *user_data)
@@ -339,6 +361,7 @@ int ttsdc_tidl_send_message(int pid, int uid, int uttid, const char *method)
        SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTSD SEND MSG");
        __send_msg(pid, uid, msg);
 
+       bundle_free(msg);
        return TTSE_ERROR_NONE;
 }
 
@@ -359,5 +382,6 @@ int ttsdc_tidl_send_error_message(int pid, int uid, int uttid, int reason, char*
        SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTSD SEND ERROR MSG");
        __send_msg(pid, uid, msg);
 
+       bundle_free(msg);
        return TTSE_ERROR_NONE;
 }
index e047243..152c2ab 100644 (file)
@@ -23,7 +23,7 @@ int ttsd_tidl_open_connection();
 
 int ttsd_tidl_close_connection();
 
-int ttsdc_tidl_send_hello(int pid, int uid, int credential_needed);
+int ttsdc_tidl_send_hello(int pid, int uid, int ret, int credential_needed);
 
 int ttsdc_tidl_send_message(int pid, int uid, int data, const char *method);