Implement getter for service state 46/279846/2
authorSuyeon Hwang <stom.hwang@samsung.com>
Thu, 11 Aug 2022 06:35:07 +0000 (15:35 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Fri, 19 Aug 2022 07:07:01 +0000 (16:07 +0900)
This patch implements the business logic for service state getter
functions. For thses, this patch uses interfaces introduced previous
commit.

Change-Id: Ic20dce885dbfde86fd9911dcb971d65c8d66629b
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/tts.c
client/tts_core.c
client/tts_core.h
server/ttsd_dbus_server.c
server/ttsd_server.c
server/ttsd_server.h
server/ttsd_tidl.c

index 94432c8..94c663c 100644 (file)
@@ -721,7 +721,11 @@ int tts_get_service_state(tts_h tts, tts_service_state_e* service_state)
        tts_state_e current_state = tts_client_get_current_state(client);
        RETVM_IF(TTS_STATE_CREATED == current_state, TTS_ERROR_INVALID_STATE, "[ERROR] The current state(%d) is invalid", current_state);
 
-       // TODO: Implement business logic
+       int ret = tts_core_get_service_state(client, service_state);
+       if (TTS_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get service state. ret(%d/%s)", ret, get_error_message(ret));
+               return ret;
+       }
 
        return TTS_ERROR_NONE;
 }
index a8db105..7eb6d71 100644 (file)
@@ -1385,3 +1385,26 @@ int tts_core_get_private_data(tts_client_s* client, const char* key, char** data
        SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_dbus_request_get_private_data");
        return TTS_ERROR_NONE;
 }
+
+int tts_core_get_service_state(tts_client_s* client, tts_service_state_e* service_state)
+{
+       RETVM_IF(false == tts_client_is_valid_client(client), TTS_ERROR_INVALID_PARAMETER, "[ERROR] Client is invalid.");
+
+       unsigned int uid = tts_client_get_uid(client);
+       int ret = -1;
+       tts_client_set_reprepared(client, false);
+       for (int count = 0; count < TTS_RETRY_COUNT; count++) {
+               ret = tts_ipc_request_get_service_state(uid, service_state);
+               if (false == __is_ipc_retry_needed(client, ret)) {
+                       break;
+               }
+       }
+
+       if (TTS_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request");
+               return ret;
+       }
+
+       SLOG(LOG_INFO, TAG_TTSC, "[INFO] Success tts_core_get_service_state");
+       return TTS_ERROR_NONE;
+}
index 538d44f..4d43eb1 100644 (file)
@@ -61,6 +61,8 @@ int tts_core_stop_pcm(tts_client_s* client);
 int tts_core_set_private_data(tts_client_s* client, const char* key, const char* data);
 int tts_core_get_private_data(tts_client_s* client, const char* key, char** data);
 
+int tts_core_get_service_state(tts_client_s* client, tts_service_state_e* service_state);
+
 int tts_core_receive_hello(unsigned int uid, int ret, int credential_needed);
 int tts_core_handle_service_reset();
 
index 1915609..d4eca70 100644 (file)
@@ -850,7 +850,7 @@ int ttsd_dbus_server_get_service_state(DBusConnection* conn, DBusMessage* msg)
                ret = TTSD_ERROR_OPERATION_FAILED;
        } else {
                SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts get service state : uid(%u)", uid);
-               // TODO: implement behavior
+               ret = ttsd_server_get_service_state(uid, &state);
        }
 
        DBusMessage* reply;
index 4887875..dee5f0c 100644 (file)
@@ -1314,3 +1314,16 @@ int ttsd_server_add_pcm(unsigned int uid, int event, void* data, int data_size,
 
        return TTSD_ERROR_NONE;
 }
+
+int ttsd_server_get_service_state(unsigned int uid, int* service_state)
+{
+       if (0 > ttsd_data_is_client(uid)) {
+               SLOG(LOG_ERROR, tts_tag(), "[Server ERROR] ttsd_server_get_service_state : uid is not valid");
+               return TTSD_ERROR_INVALID_PARAMETER;
+       }
+
+       *service_state = (int)ttsd_state_get_state();
+       SLOG(LOG_DEBUG, tts_tag(), "[Server] Get current service state. service state(%d) ", *service_state);
+
+       return TTSD_ERROR_NONE;
+}
index bf52d15..ebcb54a 100644 (file)
@@ -73,6 +73,8 @@ int ttsd_server_play_pcm(unsigned int uid);
 
 int ttsd_server_add_pcm(unsigned int uid, int event, void* data, int data_size, int audio_type, int rate);
 
+int ttsd_server_get_service_state(unsigned int uid, int* service_state);
+
 #ifdef __cplusplus
 }
 #endif
index 495b737..9b50d1b 100644 (file)
@@ -457,7 +457,11 @@ static int __get_service_state(rpc_port_stub_tts_context_h context, int uid, int
        unsigned int u_uid = (unsigned int)uid;
        SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS GET SERVICE STATE (%u)", u_uid);
 
-       // TODO: implement business logic
+       int ret = ttsd_server_get_service_state(u_uid, service_state);
+       if (TTSD_ERROR_NONE != ret) {
+               SLOG(LOG_ERROR, tts_tag(), "[ERROR] TTS GET SERVICE STATE (%u) fail (%d/%s) <<<<<", u_uid, ret, get_error_message(ret));
+               return ret;
+       }
 
        SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
        return TTSD_ERROR_NONE;