}
} /* TTSD_SIGNAL_SET_STATE */
+ else if (dbus_message_is_signal(msg, if_name, TTSD_METHOD_SET_SERVICE_STATE)) {
+ unsigned int uid = TTS_INVALID_UID;
+ int before_state = 0;
+ int current_state = 0;
+
+ dbus_message_get_args(msg, &err, DBUS_TYPE_UINT32, &uid, DBUS_TYPE_INT32, &before_state, DBUS_TYPE_INT32, ¤t_state, DBUS_TYPE_INVALID);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ }
+
+ // TODO: implement notifier
+ } /* TTSD_METHOD_SET_SERVICE_STATE */
+
else if (dbus_message_is_signal(msg, if_name, TTSD_METHOD_ERROR)) {
unsigned int uid;
int uttid;
return result;
}
// LCOV_EXCL_STOP
+
+int tts_dbus_request_get_service_state(unsigned int uid, tts_service_state_e* service_state)
+{
+ if (NULL == service_state) {
+ SLOG(LOG_ERROR, TAG_TTSC, "Input parameter is NULL");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
+ DBusMessage* msg = __tts_dbus_make_message(uid, TTS_METHOD_GET_SERVICE_STATE);
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts get service state : Fail to make message");
+ return TTS_ERROR_OPERATION_FAILED;
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts get service state : uid(%u)", uid);
+ }
+
+ if (true != dbus_message_append_args(msg,
+ DBUS_TYPE_UINT32, &uid,
+ DBUS_TYPE_INVALID)) {
+ dbus_message_unref(msg);
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
+
+ return TTS_ERROR_OPERATION_FAILED;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+ DBusMessage* result_msg;
+ int result = TTS_ERROR_OPERATION_FAILED;
+ result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, WAITING_TIME, &err);
+ dbus_message_unref(msg);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Send error (%s)", err.message);
+ dbus_error_free(&err);
+ }
+
+ int state = (int)TTS_SERVICE_STATE_READY;
+ if (NULL != result_msg) {
+ dbus_message_get_args(result_msg, &err,
+ DBUS_TYPE_INT32, &result,
+ DBUS_TYPE_INT32, &state,
+ DBUS_TYPE_INVALID);
+
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts get service state : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ result = TTS_ERROR_OPERATION_FAILED;
+ }
+ dbus_message_unref(result_msg);
+
+ if (0 == result) {
+ SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts get service state : result(%d)", result);
+ *service_state = (tts_service_state_e)state;
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts get service state : result(%d)", result);
+ }
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL ");
+ tts_dbus_reconnect();
+ result = TTS_ERROR_TIMED_OUT;
+ }
+
+ return result;
+}
int tts_dbus_request_add_pcm(unsigned int uid, int event, const char* data, int data_size, int audio_type, int rate);
+int tts_dbus_request_get_service_state(unsigned int uid, tts_service_state_e* service_state);
+
#ifdef __cplusplus
}
#endif
REQUEST_GET_PRIVATE_DATA,
REQUEST_PLAY_PCM,
REQUEST_STOP_PCM,
- REQUEST_ADD_PCM
+ REQUEST_ADD_PCM,
+ REQUEST_GET_SERVICE_STATE
} tts_ipc_vtable_e;
&tts_dbus_request_hello, &tts_dbus_request_hello_sync, &tts_dbus_request_initialize,
&tts_dbus_request_finalize, &tts_dbus_request_add_text, &tts_dbus_request_play, &tts_dbus_request_stop,
&tts_dbus_request_pause, &tts_dbus_request_set_private_data, &tts_dbus_request_get_private_data,
- &tts_dbus_request_play_pcm, &tts_dbus_request_stop_pcm, &tts_dbus_request_add_pcm };
+ &tts_dbus_request_play_pcm, &tts_dbus_request_stop_pcm, &tts_dbus_request_add_pcm,
+ &tts_dbus_request_get_service_state };
static int(*ttsc_tidl_vtable[])() = { &tts_tidl_open_connection, &tts_tidl_close_connection, &tts_tidl_stop_listening,
&tts_tidl_request_hello, &tts_tidl_request_hello_sync, &tts_tidl_request_initialize,
&tts_tidl_request_finalize, &tts_tidl_request_add_text, &tts_tidl_request_play, &tts_tidl_request_stop,
&tts_tidl_request_pause, &tts_tidl_request_set_private_data, &tts_tidl_request_get_private_data,
- &tts_tidl_request_play_pcm, &tts_tidl_request_stop_pcm, &tts_tidl_request_add_pcm };
+ &tts_tidl_request_play_pcm, &tts_tidl_request_stop_pcm, &tts_tidl_request_add_pcm,
+ &tts_tidl_request_get_service_state };
static int (**g_vtable)();
static tts_ipc_method_e g_ipc_method = TTS_IPC_METHOD_UNDEFINED;
return g_vtable[REQUEST_ADD_PCM](uid, event, data, data_size, audio_type, rate);
}
+
+int tts_ipc_request_get_service_state(unsigned int uid, tts_service_state_e* service_state)
+{
+ SLOG(LOG_INFO, TAG_TTSC, "[IPC] tts_ipc_request_get_service_state");
+
+ RETVM_IF(false == tts_client_is_valid_uid(uid), TTS_ERROR_INVALID_PARAMETER, "Fail to get tts_client with uid(%u)", uid);
+ RETVM_IF(NULL == g_vtable, TTS_ERROR_OPERATION_FAILED, "[ERROR] IPC method is not set");
+
+ return g_vtable[REQUEST_GET_SERVICE_STATE](uid, service_state);
+}
int tts_ipc_request_add_pcm(unsigned int uid, int event, const char* data, int data_size, int audio_type, int rate);
+int tts_ipc_request_get_service_state(unsigned int uid, tts_service_state_e* service_state);
+
#ifdef __cplusplus
}
#endif
if (val) {
tts_core_notify_state_changed(client, (tts_state_e)atoi(val));
}
+ } else if (0 == strncmp(TTSD_METHOD_SET_SERVICE_STATE, method, strlen(TTSD_METHOD_SET_SERVICE_STATE))) {
+ char* before_state = NULL;
+ char* current_state = NULL;
+ bundle_get_str(msg, TTS_BUNDLE_BEFORE_STATE, &before_state);
+ bundle_get_str(msg, TTS_BUNDLE_CURRENT_STATE, ¤t_state);
+
+ // TODO: Implement notifier
} else if (0 == strncmp(TTSD_METHOD_ERROR, method, strlen(TTSD_METHOD_ERROR))) {
char *uttid = NULL;
char *reason = NULL;
return TTS_ERROR_NONE;
}
+
+int tts_tidl_request_get_service_state(unsigned int uid, tts_service_state_e* service_state)
+{
+ SLOG(LOG_DEBUG, TAG_TTSC, "[TIDL] tts_tidl_request_get_service_state");
+
+ tts_client_s* client = tts_client_get_by_uid(uid);
+ RETVM_IF(NULL == client, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get client");
+
+ tts_tidl_info_s* info = __get_tidl_info_s(uid);
+ RETVM_IF(NULL == info, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Fail to get tidl info");
+
+ RETVM_IF(!info->connected, TTS_ERROR_OPERATION_FAILED, "[ERROR] Not Connected");
+
+ int state = (int)TTS_SERVICE_STATE_READY;
+ int ret = rpc_port_proxy_tts_invoke_get_service_state(info->rpc_h, uid, &state);
+ int exception = get_last_result();
+ if (RPC_PORT_ERROR_NONE != exception) {
+ ret = __convert_unhandled_error(exception);
+ }
+
+ if (TTS_ERROR_NONE != ret) {
+ SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request get service state : Fail to invoke message");
+ return ret;
+ }
+
+ *service_state = (tts_service_state_e)state;
+
+ SLOG(LOG_DEBUG, TAG_TTSC, "<<<< get service state : service state(%d)", state);
+
+ return TTS_ERROR_NONE;
+}
int tts_tidl_request_add_pcm(unsigned int uid, int event, const char* data, int data_size, int audio_type, int rate);
+int tts_tidl_request_get_service_state(unsigned int uid, tts_service_state_e* service_state);
+
#ifdef __cplusplus
}
#endif
#define TTS_BUNDLE_REASON "reason"
#define TTS_BUNDLE_ERR_MSG "err_msg"
#define TTS_BUNDLE_CREDENTIAL_NEEDED "credential_needed"
+#define TTS_BUNDLE_BEFORE_STATE "before_state"
+#define TTS_BUNDLE_CURRENT_STATE "current_state"
#define TTS_METHOD_HELLO "tts_method_hello"
#define TTS_METHOD_HELLO_SYNC "tts_method_hello_sync"
#define TTS_METHOD_PLAY_PCM "tts_method_play_pcm"
#define TTS_METHOD_STOP_PCM "tts_method_stop_pcm"
#define TTS_METHOD_ADD_PCM "tts_method_add_pcm"
+#define TTS_METHOD_GET_SERVICE_STATE "tts_method_get_service_state"
#define TTS_METHOD_SET_PRIVATE_DATA "tts_method_set_private_data"
#define TTS_METHOD_GET_PRIVATE_DATA "tts_method_get_private_data"
#define TTSD_METHOD_UTTERANCE_COMPLETED "ttsd_method_utterance_completed"
#define TTSD_METHOD_ERROR "ttsd_method_error"
#define TTSD_METHOD_SET_STATE "ttsd_method_set_state"
+#define TTSD_METHOD_SET_SERVICE_STATE "ttsd_method_set_service_state"
/******************************************************************************************
return __send_message(pid, uid, state, TTSD_METHOD_SET_STATE);
}
+int ttsdc_dbus_send_set_service_state_message(int pid, unsigned int uid, int before_state, int current_state)
+{
+ if (NULL == g_conn_sender) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Dbus connection is not available");
+ return TTSD_ERROR_OPERATION_FAILED;
+ }
+
+ DBusMessage* msg = NULL;
+
+ char target_if_name[64];
+ snprintf(target_if_name, sizeof(target_if_name), "%s%d", TTS_CLIENT_SERVICE_INTERFACE, pid);
+
+ /* create a message */
+ msg = dbus_message_new_signal(
+ TTS_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */
+ target_if_name, /* interface name of the signal */
+ TTSD_METHOD_SET_SERVICE_STATE); /* name of the signal */
+
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to create message : %s", TTSD_METHOD_SET_SERVICE_STATE);
+ return TTSD_ERROR_OPERATION_FAILED;
+ } else {
+ SLOG(LOG_DEBUG, tts_tag(), "[Dbus] Send set service state message : uid(%u) before_state(%d), current_state(%d)", uid, before_state, current_state);
+ }
+
+ dbus_message_append_args(msg, DBUS_TYPE_UINT32, &uid, DBUS_TYPE_INT32, &before_state, DBUS_TYPE_INT32, ¤t_state, DBUS_TYPE_INVALID);
+
+ if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
+ SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Fail to Send");
+ return TTSD_ERROR_OPERATION_FAILED;
+ } else {
+ SLOG(LOG_DEBUG, tts_tag(), "[Dbus] SUCCESS Send");
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+
+ return TTSD_ERROR_NONE;
+}
+
int ttsdc_dbus_send_error_message(int pid, unsigned int uid, int uttid, int reason, char* err_msg)
{
if (NULL == g_conn_sender) {
} else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_ADD_PCM)) {
ttsd_dbus_server_add_pcm(g_conn_listener, msg);
+ } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_GET_SERVICE_STATE)) {
+ ttsd_dbus_server_get_service_state(g_conn_listener, msg);
+
} else {
SLOG(LOG_DEBUG, tts_tag(), "Message is NOT valid");
/* Invalid method */
int ttsdc_dbus_send_set_state_message(int pid, unsigned int uid, int state);
+int ttsdc_dbus_send_set_service_state_message(int pid, unsigned int uid, int before_state, int current_state);
+
#ifdef __cplusplus
}
return 0;
}
+
+int ttsd_dbus_server_get_service_state(DBusConnection* conn, DBusMessage* msg)
+{
+ DBusError err;
+ dbus_error_init(&err);
+
+ unsigned int uid;
+ int state = (int)TTSD_STATE_READY;
+ int ret = 0;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_UINT32, &uid,
+ DBUS_TYPE_INVALID);
+
+ SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS GET SERVICE STATE");
+
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] tts get service state : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = TTSD_ERROR_OPERATION_FAILED;
+ } else {
+ SECURE_SLOG(LOG_DEBUG, tts_tag(), "[IN] tts get service state : uid(%u)", uid);
+ // TODO: implement behavior
+ }
+
+ DBusMessage* reply;
+ reply = dbus_message_new_method_return(msg);
+
+ if (NULL != reply) {
+ dbus_message_append_args(reply, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID);
+
+ if (0 == ret) {
+ SLOG(LOG_DEBUG, tts_tag(), "[OUT] tts get service state : result(%d)", ret);
+ } else {
+ SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts get service state : result(%d)", ret);
+ }
+
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts get service state : Out Of Memory!");
+ }
+
+ dbus_connection_flush(conn);
+ dbus_message_unref(reply);
+ } else {
+ SLOG(LOG_ERROR, tts_tag(), "[OUT ERROR] tts get service state : Fail to create reply message!!");
+ }
+
+ SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
+ SLOG(LOG_DEBUG, tts_tag(), " ");
+
+ return 0;
+}
int ttsd_dbus_server_add_pcm(DBusConnection* conn, DBusMessage* msg);
+int ttsd_dbus_server_get_service_state(DBusConnection* conn, DBusMessage* msg);
+
#ifdef __cplusplus
}
#endif
static int(*ttsd_dbus_vtable[])() = {&ttsd_dbus_open_connection, &ttsd_dbus_close_connection, &ttsdc_dbus_send_utt_start_message,
- &ttsdc_dbus_send_utt_finish_message, &ttsdc_dbus_send_set_state_message, &ttsdc_dbus_send_error_message};
+ &ttsdc_dbus_send_utt_finish_message, &ttsdc_dbus_send_set_state_message, &ttsdc_dbus_send_error_message,
+ &ttsdc_dbus_send_set_service_state_message};
static int(*ttsd_tidl_vtable[])() = {&ttsd_tidl_open_connection, &ttsd_tidl_close_connection, &ttsdc_tidl_send_utt_start_message,
- &ttsdc_tidl_send_utt_finish_message, &ttsdc_tidl_send_set_state_message, &ttsdc_tidl_send_error_message};
+ &ttsdc_tidl_send_utt_finish_message, &ttsdc_tidl_send_set_state_message, &ttsdc_tidl_send_error_message,
+ &ttsdc_tidl_send_set_service_state_message};
int ttsd_ipc_open_connection()
{
return TTSD_ERROR_OPERATION_FAILED;
}
+
+int ttsdc_ipc_send_set_service_state_message(int pid, unsigned int uid, int before_state, int current_state)
+{
+ SLOG(LOG_INFO, tts_tag(), "[IPC] ttsdc_ipc_send_set_service_state_message");
+
+ if (0 > ttsd_data_is_client(uid)) {
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] uid is not valid (%u)", uid);
+ return TTSD_ERROR_INVALID_PARAMETER;
+ }
+
+ switch (ttsd_data_get_ipc_method(uid))
+ {
+ case TTS_IPC_METHOD_DBUS:
+ SLOG(LOG_DEBUG, tts_tag(), "[IPC] ipc method : dbus");
+ return ttsd_dbus_vtable[SEND_SET_SERVICE_STATE](pid, uid, before_state, current_state);
+
+ case TTS_IPC_METHOD_TIDL:
+ SLOG(LOG_DEBUG, tts_tag(), "[IPC] ipc method : tidl");
+ return ttsd_tidl_vtable[SEND_SET_SERVICE_STATE] (pid, uid, before_state, current_state);
+
+ default:
+ SLOG(LOG_ERROR, tts_tag(), "[ERROR] method is not valid");
+ }
+
+ return TTSD_ERROR_OPERATION_FAILED;
+}
SEND_UTTERANCE_START,
SEND_UTTERANCE_FINISH,
SEND_SET_STATE,
- SEND_ERROR
+ SEND_ERROR,
+ SEND_SET_SERVICE_STATE
} ttsd_ipc_vtable_e;
int ttsd_ipc_open_connection();
int ttsdc_ipc_send_set_state_message(int pid, unsigned int uid, int state);
+int ttsdc_ipc_send_set_service_state_message(int pid, unsigned int uid, int before_state, int current_state);
+
+
#ifdef __cplusplus
}
#endif
return TTSD_ERROR_NONE;
}
+static int __get_service_state(rpc_port_stub_tts_context_h context, int uid, int* service_state, void *user_data)
+{
+ unsigned int u_uid = (unsigned int)uid;
+ SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS GET SERVICE STATE (%u)", u_uid);
+
+ // TODO: implement business logic
+
+ SLOG(LOG_DEBUG, tts_tag(), "<<<<<");
+ return TTSD_ERROR_NONE;
+}
+
int ttsd_tidl_open_connection()
{
SLOG(LOG_DEBUG, tts_tag(), "[TIDL] ttsd_tidl_open_connection");
g_callback.get_private = __get_private_cb;
g_callback.play = __play_cb;
g_callback.add_pcm = __add_pcm_cb;
+ g_callback.get_service_state = __get_service_state;
int ret = -1;
return __send_message(pid, uid, state, TTSD_METHOD_SET_STATE);
}
+int ttsdc_tidl_send_set_service_state_message(int pid, unsigned int uid, int before_state, int current_state)
+{
+ SLOG(LOG_DEBUG, tts_tag(), "[TIDL] ttsdc_tidl_send_set_service_state_message");
+
+ char str_before_state[10] = {0, };
+ char str_current_state[10] = {0, };
+
+ snprintf(str_before_state, 10, "%d", before_state);
+ snprintf(str_current_state, 10, "%d", current_state);
+
+ bundle* msg = bundle_create();
+ bundle_add_str(msg, TTS_BUNDLE_METHOD, TTSD_METHOD_SET_SERVICE_STATE);
+ bundle_add_str(msg, TTS_BUNDLE_BEFORE_STATE, str_before_state);
+ bundle_add_str(msg, TTS_BUNDLE_CURRENT_STATE, str_current_state);
+
+ SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTSD SEND SET SERVICE STATE MESSAGE");
+ __send_msg(pid, uid, msg);
+
+ bundle_free(msg);
+ return TTSD_ERROR_NONE;
+}
+
int ttsdc_tidl_send_error_message(int pid, unsigned int uid, int uttid, int reason, char* err_msg)
{
SLOG(LOG_DEBUG, tts_tag(), "[TIDL] ttsdc_tidl_send_error_message");
int ttsdc_tidl_send_error_message(int pid, unsigned int uid, int uttid, int reason, char* err_msg);
+int ttsdc_tidl_send_set_service_state_message(int pid, unsigned int uid, int before_state, int current_state);
+
#ifdef __cplusplus
}
#endif
int get_private(in int uid, string key, out string priv_data);
int play(int uid, string credential);
int add_pcm(int uid, int event, array<char> pcm_data, int data_size, int audio_type, int rate);
+ int get_service_state(in int uid, out int service_state);
}