2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
7 * Unless required by applicable law or agreed to in writing, software
8 * distributed under the License is distributed on an "AS IS" BASIS,
9 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 * See the License for the specific language governing permissions and
11 * limitations under the License.
31 REQUEST_SET_PRIVATE_DATA,
32 REQUEST_GET_PRIVATE_DATA,
36 REQUEST_GET_SERVICE_STATE
40 static int(*ttsc_dbus_vtable[])() = { &tts_dbus_open_connection, &tts_dbus_close_connection, &tts_dbus_stop_listening,
41 &tts_dbus_request_hello, &tts_dbus_request_hello_sync, &tts_dbus_request_initialize,
42 &tts_dbus_request_finalize, &tts_dbus_request_add_text, &tts_dbus_request_play, &tts_dbus_request_stop,
43 &tts_dbus_request_pause, &tts_dbus_request_set_private_data, &tts_dbus_request_get_private_data,
44 &tts_dbus_request_play_pcm, &tts_dbus_request_stop_pcm, &tts_dbus_request_add_pcm,
45 &tts_dbus_request_get_service_state };
47 static int(*ttsc_tidl_vtable[])() = { &tts_tidl_open_connection, &tts_tidl_close_connection, &tts_tidl_stop_listening,
48 &tts_tidl_request_hello, &tts_tidl_request_hello_sync, &tts_tidl_request_initialize,
49 &tts_tidl_request_finalize, &tts_tidl_request_add_text, &tts_tidl_request_play, &tts_tidl_request_stop,
50 &tts_tidl_request_pause, &tts_tidl_request_set_private_data, &tts_tidl_request_get_private_data,
51 &tts_tidl_request_play_pcm, &tts_tidl_request_stop_pcm, &tts_tidl_request_add_pcm,
52 &tts_tidl_request_get_service_state };
54 static int (**g_vtable)();
55 static tts_ipc_method_e g_ipc_method = TTS_IPC_METHOD_UNDEFINED;
57 int tts_ipc_set_method(tts_ipc_method_e method)
60 case TTS_IPC_METHOD_DBUS:
61 g_vtable = ttsc_dbus_vtable;
63 case TTS_IPC_METHOD_TIDL:
64 g_vtable = ttsc_tidl_vtable;
67 SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] IPC method is not valid");
69 return TTS_ERROR_INVALID_PARAMETER;
72 g_ipc_method = method;
73 return TTS_ERROR_NONE;
76 bool tts_ipc_is_method_set()
78 SLOG(LOG_INFO, TAG_TTSC, "Set method (TIDL or DBUS) for ipc");
79 return (g_ipc_method != TTS_IPC_METHOD_UNDEFINED);
82 int tts_ipc_open_connection(unsigned int uid)
84 SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_open_connection");
86 RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid);
87 RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set");
89 return g_vtable[OPEN_CONNECTION](uid);
92 int tts_ipc_close_connection(unsigned int uid)
94 SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_close_connection");
96 RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid);
97 RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set");
99 return g_vtable[CLOSE_CONNECTION](uid);
102 int tts_ipc_stop_listening(unsigned int uid)
104 SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_stop_listening");
106 RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid);
107 RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set");
109 return g_vtable[STOP_LISTENING](uid);
112 int tts_ipc_request_hello(unsigned int uid, tts_mode_e mode, tts_playing_mode_e playing_mode, int registered_event_mask)
114 SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_hello");
116 RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid);
117 RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set");
119 return g_vtable[REQUEST_HELLO](uid, mode, playing_mode, registered_event_mask);
122 int tts_ipc_request_hello_sync(unsigned int uid)
124 SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_hello_sync");
126 RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid);
127 RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set");
129 return g_vtable[REQUEST_HELLO_SYNC](uid);
132 int tts_ipc_request_initialize(unsigned int uid, tts_mode_e mode, tts_playing_mode_e playing_mode, int registered_event_mask, tts_service_state_e* service_state, bool* credential_needed)
134 SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_initialize");
136 RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid);
137 RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set");
139 return g_vtable[REQUEST_INITIALIZE](uid, mode, registered_event_mask, service_state, credential_needed);
142 int tts_ipc_request_finalize(unsigned int uid)
144 SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_finalize");
146 RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid);
147 RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set");
149 return g_vtable[REQUEST_FINALIZE](uid);
152 int tts_ipc_request_add_text(unsigned int uid, const char* text, const char* lang, int vctype, int speed, int uttid, const char* credential)
154 SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_add_text");
156 RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid);
157 RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set");
159 return g_vtable[REQUEST_ADD_TEXT](uid, text, lang, vctype, speed, uttid, credential);
162 int tts_ipc_request_set_private_data(unsigned int uid, const char* key, const char* data)
164 SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_set_private_data");
166 RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid);
167 RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set");
169 return g_vtable[REQUEST_SET_PRIVATE_DATA](uid, key, data);
172 int tts_ipc_request_get_private_data(unsigned int uid, const char* key, char** data)
174 SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_get_private_data");
176 RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid);
177 RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set");
179 return g_vtable[REQUEST_GET_PRIVATE_DATA](uid, key, data);
182 int tts_ipc_request_play(unsigned int uid, const char* credential)
184 SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_play");
186 RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid);
187 RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set");
189 return g_vtable[REQUEST_PLAY](uid, credential);
192 int tts_ipc_request_stop(unsigned int uid)
194 SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_stop");
196 RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid);
197 RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set");
199 return g_vtable[REQUEST_STOP](uid);
202 int tts_ipc_request_pause(unsigned int uid)
204 SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_pause");
206 RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid);
207 RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set");
209 return g_vtable[REQUEST_PAUSE](uid);
212 int tts_ipc_request_play_pcm(unsigned int uid)
214 SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_play_pcm");
216 RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid);
217 RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set");
219 return g_vtable[REQUEST_PLAY_PCM](uid);
222 int tts_ipc_request_stop_pcm(unsigned int uid)
224 SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_stop_pcm");
226 RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid);
227 RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set");
229 return g_vtable[REQUEST_STOP_PCM](uid);
232 int tts_ipc_request_add_pcm(unsigned int uid, int event, const char* data, int data_size, int audio_type, int rate)
234 SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_add_pcm");
236 RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid);
237 RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set");
239 return g_vtable[REQUEST_ADD_PCM](uid, event, data, data_size, audio_type, rate);
242 int tts_ipc_request_get_service_state(unsigned int uid, tts_service_state_e* service_state)
244 SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_get_service_state");
246 RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid);
247 RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set");
249 return g_vtable[REQUEST_GET_SERVICE_STATE](uid, service_state);