/*
-* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd All Rights Reserved
+* Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* limitations under the License.
*/
-
#include <Ecore.h>
+#include <errno.h>
+#include <fcntl.h>
#include <sys/inotify.h>
-#include "tts_main.h"
+#include "tts_client.h"
+#include "tts_config_mgr.h"
#include "tts_dbus.h"
#include "tts_defs.h"
-#include "tts_client.h"
-
-#define INIT_WAITING_TIME 5000
-#define WAITING_TIME 1000
+#include "tts_main.h"
+#include "tts_internal.h"
-#define BUFFER_SIZE 20
+#define HELLO_WAITING_TIME 500
+#define WAITING_TIME 5000
-static Ecore_Fd_Handler* g_fd_handler = NULL;
+static DBusConnection* g_conn_sender = NULL;
+static DBusConnection* g_conn_listener = NULL;
-static DBusConnection* g_conn = NULL;
+static Ecore_Fd_Handler* g_dbus_fd_handler = NULL;
-static Ecore_Fd_Handler* g_fd_handler_noti = NULL;
-static int g_fd_noti;
-static int g_wd_noti;
-extern int __tts_cb_error(int uid, tts_error_e reason, int utt_id);
+extern int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char *err_msg);
extern int __tts_cb_set_state(int uid, int state);
static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
{
- DBusConnection* conn = (DBusConnection*)data;
-
- if (NULL == conn) return ECORE_CALLBACK_RENEW;
-
- dbus_connection_read_write_dispatch(conn, 50);
-
- DBusMessage* msg = NULL;
- msg = dbus_connection_pop_message(conn);
-
- /* loop again if we haven't read a message */
- if (NULL == msg) {
- return ECORE_CALLBACK_RENEW;
- }
+ if (NULL == g_conn_listener) return ECORE_CALLBACK_RENEW;
- DBusError err;
- dbus_error_init(&err);
-
- DBusMessage *reply = NULL;
-
- char if_name[64];
- snprintf(if_name, 64, "%s%d", TTS_CLIENT_SERVICE_INTERFACE, getpid());
+ dbus_connection_read_write_dispatch(g_conn_listener, 50);
- /* check if the message is a signal from the correct interface and with the correct name */
- if (dbus_message_is_method_call(msg, if_name, TTSD_METHOD_HELLO)) {
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Get Hello");
- int uid = 0;
- int response = -1;
+ while (1) {
+ DBusMessage* msg = NULL;
+ msg = dbus_connection_pop_message(g_conn_listener);
- dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
-
- if (uid > 0) {
- SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts get hello : uid(%d) \n", uid);
-
- /* check uid */
- tts_client_s* client = tts_client_get_by_uid(uid);
- if (NULL != client)
- response = 1;
- else
- response = 0;
- } else {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts get hello : invalid uid \n");
+ if (true != dbus_connection_get_is_connected(g_conn_listener)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Connection is disconnected");
+ break;
}
- reply = dbus_message_new_method_return(msg);
-
- if (NULL != reply) {
- dbus_message_append_args(reply, DBUS_TYPE_INT32, &response, DBUS_TYPE_INVALID);
-
- if (!dbus_connection_send(conn, reply, NULL))
- SLOG(LOG_ERROR, TAG_TTSC, ">>>> tts get hello : fail to send reply");
- else
- SLOG(LOG_DEBUG, TAG_TTSC, ">>>> tts get hello : result(%d)", response);
-
- dbus_connection_flush(conn);
- dbus_message_unref(reply);
- } else {
- SLOG(LOG_ERROR, TAG_TTSC, ">>>> tts get hello : fail to create reply message");
+ /* loop again if we haven't read a message */
+ if (NULL == msg) {
+ break;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
- } /* TTSD_METHOD_HELLO */
-
-#if 0
- else if (dbus_message_is_method_call(msg, if_name, TTSD_METHOD_UTTERANCE_STARTED)) {
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Get utterance started");
- int uid, uttid;
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &uid,
- DBUS_TYPE_INT32, &uttid,
- DBUS_TYPE_INVALID);
+ DBusError err;
+ dbus_error_init(&err);
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< Get Utterance started - Get arguments error (%s)\n", err.message);
- dbus_error_free(&err);
- } else {
- SLOG(LOG_DEBUG, TAG_TTSC, "<<<< Get Utterance started message : uid(%d), uttid(%d) \n", uid, uttid);
- __tts_cb_utt_started(uid, uttid);
- }
+ char if_name[64] = {0, };
+ snprintf(if_name, 64, "%s", TTS_CLIENT_SERVICE_INTERFACE);
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
- }/* TTS_SIGNAL_UTTERANCE_STARTED */
+ if (dbus_message_is_signal(msg, if_name, TTSD_METHOD_UTTERANCE_STARTED)) {
+ int uid = 0;
+ int uttid = 0;
- else if (dbus_message_is_method_call(msg, if_name, TTSD_METHOD_UTTERANCE_COMPLETED)) {
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Get utterance completed");
- int uid, uttid;
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &uid,
- DBUS_TYPE_INT32, &uttid,
- DBUS_TYPE_INVALID);
+ dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INT32, &uttid, 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);
+ }
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< Get Utterance completed - Get arguments error (%s)\n", err.message);
- dbus_error_free(&err);
- } else {
- SLOG(LOG_DEBUG, TAG_TTSC, "<<<< Get Utterance completed message : uid(%d), uttid(%d) \n", uid, uttid);
- __tts_cb_utt_completed(uid, uttid);
- }
+ if (0 == __tts_cb_utt_started(uid, uttid)) {
+ SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts utterance started : uid(%d) uttid(%d)", uid, uttid);
+ }
+ } /* TTSD_METHOD_UTTERANCE_STARTED */
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
- }/* TTS_SIGNAL_UTTERANCE_COMPLETED */
-
- else if (dbus_message_is_method_call(msg, if_name, TTSD_METHOD_SET_STATE)) {
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Get state changed callback");
- int uid;
- int state;
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &uid,
- DBUS_TYPE_INT32, &state,
- DBUS_TYPE_INVALID);
+ else if (dbus_message_is_signal(msg, if_name, TTSD_METHOD_UTTERANCE_COMPLETED)) {
+ int uid = 0;
+ int uttid = 0;
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< Get state change - Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- } else {
- SLOG(LOG_DEBUG, TAG_TTSC, "<<<< Get state change : uid(%d) , state(%d)", uid, state);
- __tts_cb_set_state(uid, state);
- }
+ dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INT32, &uttid, 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);
+ }
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
- } /* TTSD_METHOD_SET_STATE */
-#endif
+ if (0 == __tts_cb_utt_completed(uid, uttid)) {
+ SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts utterance completed : uid(%d) uttid(%d)", uid, uttid);
+ }
+ } /* TTS_SIGNAL_UTTERANCE_STARTED */
- else if (dbus_message_is_method_call(msg, if_name, TTSD_METHOD_ERROR)) {
- SLOG(LOG_DEBUG, TAG_TTSC, "===== Get error callback");
+ else if (dbus_message_is_signal(msg, if_name, TTSD_METHOD_SET_STATE)) {
+ int uid = 0;
+ int state = 0;
- int uid;
- int uttid;
- int reason;
+ dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INT32, &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);
+ }
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &uid,
- DBUS_TYPE_INT32, &uttid,
- DBUS_TYPE_INT32, &reason,
- DBUS_TYPE_INVALID);
+ if (0 == __tts_cb_set_state(uid, state)) {
+ SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts state changed : uid(%d) state(%d)", uid, state);
+ }
+ } /* TTSD_SIGNAL_SET_STATE */
+
+ else if (dbus_message_is_signal(msg, if_name, TTSD_METHOD_ERROR)) {
+ int uid;
+ int uttid;
+ int reason;
+ char* err_msg;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &uid,
+ DBUS_TYPE_INT32, &uttid,
+ DBUS_TYPE_INT32, &reason,
+ DBUS_TYPE_STRING, &err_msg,
+ DBUS_TYPE_INVALID);
+
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< Get Error message - Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< Get Error message : uid(%d), error(%d), uttid(%d), err_msg(%s)", uid, reason, uttid, (NULL == err_msg) ? "NULL" : err_msg);
+ __tts_cb_error(uid, reason, uttid, err_msg);
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< Get Error signal - Get arguments error (%s)\n", err.message);
- dbus_error_free(&err);
- } else {
- SLOG(LOG_DEBUG, TAG_TTSC, "<<<< Get Error signal : uid(%d), error(%d), uttid(%d)\n", uid, reason, uttid);
- __tts_cb_error(uid, reason, uttid);
+ }
+ } /* TTSD_SIGNAL_ERROR */
+
+ else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameOwnerChanged")) {
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Owner Changed");
+ __tts_cb_error(-1, TTS_ERROR_SERVICE_RESET, -1, "Daemon Reset");
+ SLOG(LOG_DEBUG, TAG_TTSC, "@@@");
+ SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ } /* NameOwnerChanged */
+
+ else {
+ SLOG(LOG_DEBUG, TAG_TTSC, "Message is NOT valid");
+ dbus_message_unref(msg);
+ break;
}
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
- }/* TTS_SIGNAL_ERROR */
-
- /* free the message */
- dbus_message_unref(msg);
-
+ /* free the message */
+ dbus_message_unref(msg);
+ }
return ECORE_CALLBACK_PASS_ON;
}
+static void __tts_dbus_connection_free()
+{
+ if (NULL != g_conn_listener) {
+ dbus_connection_close(g_conn_listener);
+ g_conn_listener = NULL;
+ }
+ if (NULL != g_conn_sender) {
+ dbus_connection_close(g_conn_sender);
+ g_conn_sender = NULL;
+ }
+}
+
int tts_dbus_open_connection()
{
- if (NULL != g_conn) {
+ if (NULL != g_conn_sender && NULL != g_conn_listener) {
SLOG(LOG_WARN, TAG_TTSC, "already existed connection ");
return 0;
}
DBusError err;
- int ret;
/* initialise the error value */
dbus_error_init(&err);
/* connect to the DBUS system bus, and check for errors */
- g_conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
-
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Dbus Connection Error (%s)\n", err.message);
- dbus_error_free(&err);
+ g_conn_sender = dbus_bus_get_private(DBUS_BUS_SESSION, &err);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Dbus Connection Error (%s)", err.message);
+ dbus_error_free(&err);
}
- if (NULL == g_conn) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] fail to get dbus connection \n");
- return TTS_ERROR_OPERATION_FAILED;
+ if (NULL == g_conn_sender) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] fail to get dbus connection");
+ return TTS_ERROR_OPERATION_FAILED;
}
- dbus_connection_set_exit_on_disconnect(g_conn, false);
-
- int pid = getpid();
-
- char service_name[64];
- memset(service_name, 0, 64);
- snprintf(service_name, 64, "%s%d", TTS_CLIENT_SERVICE_NAME, pid);
-
- SLOG(LOG_DEBUG, TAG_TTSC, "Service name is %s\n", service_name);
-
- /* register our name on the bus, and check for errors */
- ret = dbus_bus_request_name(g_conn, service_name, DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
+ dbus_connection_set_exit_on_disconnect(g_conn_sender, false);
+ g_conn_listener = dbus_bus_get_private(DBUS_BUS_SESSION, &err);
if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Name Error (%s)\n", err.message);
- dbus_error_free(&err);
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Dbus Connection Error (%s)", err.message);
+ dbus_error_free(&err);
}
- if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to open connection : Service name has already been existed. \n");
+ if (NULL == g_conn_listener) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] fail to get dbus connection for listener");
+ __tts_dbus_connection_free();
return TTS_ERROR_OPERATION_FAILED;
}
- char rule[128];
- snprintf(rule, 128, "type='signal',interface='%s%d'", TTS_CLIENT_SERVICE_INTERFACE, pid);
+ dbus_connection_set_exit_on_disconnect(g_conn_listener, false);
- /* add a rule for which messages we want to see */
- dbus_bus_add_match(g_conn, rule, &err);
- dbus_connection_flush(g_conn);
+ char rule[128] = {0, };
+ snprintf(rule, 128, "type='signal',interface='%s'", TTS_CLIENT_SERVICE_INTERFACE);
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Match Error (%s)\n", err.message);
- return TTS_ERROR_OPERATION_FAILED;
- }
+ /* add a rule for which messages we want to see */
+ dbus_bus_add_match(g_conn_listener, rule, &err);
+ dbus_connection_flush(g_conn_listener);
int fd = 0;
- dbus_connection_get_unix_fd(g_conn, &fd);
-
- g_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, g_conn, NULL, NULL);
+ if (true != dbus_connection_get_unix_fd(g_conn_listener, &fd)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "Fail to get fd from dbus");
+ __tts_dbus_connection_free();
+ return TTS_ERROR_OPERATION_FAILED;
+ } else {
+ SLOG(LOG_DEBUG, TAG_TTSC, "Get fd from dbus : %d", fd);
+ }
- if (NULL == g_fd_handler) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get fd handler from ecore \n");
+ g_dbus_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, NULL, NULL, NULL);
+ if (NULL == g_dbus_fd_handler) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to get fd handler from ecore");
+ __tts_dbus_connection_free();
return TTS_ERROR_OPERATION_FAILED;
}
return 0;
}
-
int tts_dbus_close_connection()
{
DBusError err;
dbus_error_init(&err);
- ecore_main_fd_handler_del(g_fd_handler);
-
- int pid = getpid();
-
- char service_name[64];
- memset(service_name, 0, 64);
- snprintf(service_name, 64, "%s%d", TTS_CLIENT_SERVICE_NAME, pid);
-
- dbus_bus_release_name (g_conn, service_name, &err);
+ if (NULL != g_dbus_fd_handler) {
+ ecore_main_fd_handler_del(g_dbus_fd_handler);
+ g_dbus_fd_handler = NULL;
+ }
- dbus_connection_close(g_conn);
-
- g_fd_handler = NULL;
- g_conn = NULL;
+ __tts_dbus_connection_free();
return 0;
}
-
int tts_dbus_reconnect()
{
- bool connected = dbus_connection_get_is_connected(g_conn);
- SLOG(LOG_DEBUG, TAG_TTSC, "[DBUS] %s\n", connected ? "Connected" : "Not connected");
+ if (!g_conn_sender || !g_conn_listener) {
+ tts_dbus_close_connection();
- if (false == connected) {
+ if (0 != tts_dbus_open_connection()) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to reconnect");
+ return -1;
+ }
+
+ SLOG(LOG_DEBUG, TAG_TTSC, "[DBUS] Reconnect");
+ return 0;
+ }
+
+ bool sender_connected = dbus_connection_get_is_connected(g_conn_sender);
+ bool listener_connected = dbus_connection_get_is_connected(g_conn_listener);
+ SLOG(LOG_DEBUG, TAG_TTSC, "[DBUS] Sender(%s) Listener(%s)",
+ sender_connected ? "Connected" : "Not connected", listener_connected ? "Connected" : "Not connected");
+
+ if (false == sender_connected || false == listener_connected) {
tts_dbus_close_connection();
- if(0 != tts_dbus_open_connection()) {
+ if (0 != tts_dbus_open_connection()) {
SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to reconnect");
return -1;
- }
+ }
SLOG(LOG_DEBUG, TAG_TTSC, "[DBUS] Reconnect");
}
-
+
return 0;
}
DBusMessage* __tts_dbus_make_message(int uid, const char* method)
{
if (NULL == method) {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input method is NULL");
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input method is NULL");
return NULL;
}
TTS_SR_SERVER_SERVICE_OBJECT_PATH,
TTS_SR_SERVER_SERVICE_INTERFACE,
method);
+ } else if (TTS_MODE_INTERRUPT == client->mode) {
+ msg = dbus_message_new_method_call(
+ TTS_INTERRUPT_SERVER_SERVICE_NAME,
+ TTS_INTERRUPT_SERVER_SERVICE_OBJECT_PATH,
+ TTS_INTERRUPT_SERVER_SERVICE_INTERFACE,
+ method);
} else {
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input mode is not available");
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Input mode is not available");
return NULL;
}
int tts_dbus_request_hello(int uid)
{
+ DBusError err;
+ dbus_error_init(&err);
DBusMessage* msg;
msg = __tts_dbus_make_message(uid, TTS_METHOD_HELLO);
- if (NULL == msg) {
- SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts hello : Fail to make message \n");
- return TTS_ERROR_OPERATION_FAILED;
- }
+ if (dbus_error_is_set(&err)) {
+// SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts dbus log : %s", err);
+ dbus_error_free(&err);
+ }
- DBusError err;
- dbus_error_init(&err);
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts hello : Fail to make message");
+ return TTS_ERROR_OPERATION_FAILED;
+ }
DBusMessage* result_msg = NULL;
int result = 0;
- result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, WAITING_TIME, &err);
-
+ result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, HELLO_WAITING_TIME, &err);
dbus_message_unref(msg);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts dbus log : %s", err);
+ dbus_error_free(&err);
+ }
if (NULL != result_msg) {
dbus_message_unref(result_msg);
- SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts hello");
+// SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts hello");
result = 0;
} else {
- result = TTS_ERROR_OPERATION_FAILED;
+ result = TTS_ERROR_TIMED_OUT;
}
return result;
}
-int tts_dbus_request_initialize(int uid)
+int tts_dbus_request_initialize(int uid, bool* credential_needed)
{
DBusMessage* msg;
DBusError err;
msg = __tts_dbus_make_message(uid, TTS_METHOD_INITIALIZE);
- if (NULL == msg) {
- SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts initialize : Fail to make message \n");
- if (dbus_error_is_set(&err))
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message);
-
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts initialize : Fail to make message");
return TTS_ERROR_OPERATION_FAILED;
} else {
SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts initialize : uid(%d)", uid);
int pid = getpid();
if (true != dbus_message_append_args(msg, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID)) {
dbus_message_unref(msg);
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
return TTS_ERROR_OPERATION_FAILED;
}
DBusMessage* result_msg;
int result = TTS_ERROR_OPERATION_FAILED;
- result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, INIT_WAITING_TIME, &err);
+ 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);
+ }
- if (dbus_error_is_set(&err))
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message);
-
+ int temp = 0;
if (NULL != result_msg) {
dbus_message_get_args(result_msg, &err,
DBUS_TYPE_INT32, &result,
+ DBUS_TYPE_INT32, &temp,
DBUS_TYPE_INVALID);
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, TAG_TTSC, "Get arguments error (%s)\n", err.message);
- dbus_error_free(&err);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
result = TTS_ERROR_OPERATION_FAILED;
}
dbus_message_unref(result_msg);
+
+ if (0 == result) {
+ *credential_needed = (bool)temp;
+ SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts initialize : result = %d, credential_needed(%d)", result, *credential_needed);
+
+ /* add a rule for daemon error */
+ char rule_err[256] = {0, };
+ tts_client_s* client = tts_client_get_by_uid(uid);
+ if (NULL == client) {
+ SLOG(LOG_ERROR, TAG_TTSC, "Fail to get TTS client");
+ return TTS_ERROR_OPERATION_FAILED;
+ }
+
+ if (TTS_ERROR_SERVICE_RESET != client->reason) {
+ if (TTS_MODE_DEFAULT == client->mode) {
+ snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SERVER_SERVICE_INTERFACE);
+ } else if (TTS_MODE_NOTIFICATION == client->mode) {
+ snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_NOTI_SERVER_SERVICE_INTERFACE);
+ } else if (TTS_MODE_SCREEN_READER == client->mode) {
+ snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SR_SERVER_SERVICE_INTERFACE);
+ } else if (TTS_MODE_INTERRUPT == client->mode) {
+ snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_INTERRUPT_SERVER_SERVICE_INTERFACE);
+ }
+ dbus_bus_add_match(g_conn_listener, rule_err, &err);
+ dbus_connection_flush(g_conn_listener);
+
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "Match Error (%s)", err.message);
+ dbus_error_free(&err);
+ return TTS_ERROR_OPERATION_FAILED;
+ }
+ client->reason = 0; // default value
+ }
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts initialize : result = %d", result);
+ }
} else {
SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL ");
- if (dbus_error_is_set(&err))
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message);
tts_dbus_reconnect();
+ result = TTS_ERROR_TIMED_OUT;
}
- if (0 == result) {
- SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts initialize : result = %d \n", result);
- } else {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts initialize : result = %d \n", result);
- }
-
return result;
}
DBusError err;
dbus_error_init(&err);
- msg = __tts_dbus_make_message(uid, TTS_METHOD_FINALIZE);
+ /* remove a rule for daemon error */
+ char rule_err[256] = {0, };
+ tts_client_s* client = tts_client_get_by_uid(uid);
+ if (NULL == client) {
+ SLOG(LOG_ERROR, TAG_TTSC, "Fail to get TTS client");
+ return TTS_ERROR_OPERATION_FAILED;
+ }
- if (NULL == msg) {
- SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts finalize : Fail to make message");
- if (dbus_error_is_set(&err))
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message);
+ if (TTS_MODE_DEFAULT == client->mode) {
+ snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SERVER_SERVICE_INTERFACE);
+ } else if (TTS_MODE_NOTIFICATION == client->mode) {
+ snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_NOTI_SERVER_SERVICE_INTERFACE);
+ } else if (TTS_MODE_SCREEN_READER == client->mode) {
+ snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_SR_SERVER_SERVICE_INTERFACE);
+ } else if (TTS_MODE_INTERRUPT == client->mode) {
+ snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", TTS_INTERRUPT_SERVER_SERVICE_INTERFACE);
+ }
+ dbus_bus_remove_match(g_conn_listener, rule_err, &err);
+ dbus_connection_flush(g_conn_listener);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "Match Error (%s)", err.message);
+ dbus_error_free(&err);
+ }
+ msg = __tts_dbus_make_message(uid, TTS_METHOD_FINALIZE);
+
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts finalize : Fail to make message");
return TTS_ERROR_OPERATION_FAILED;
} else {
SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts finalize : uid(%d)", uid);
if (true != dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID)) {
dbus_message_unref(msg);
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
return TTS_ERROR_OPERATION_FAILED;
}
DBusMessage* result_msg;
int result = TTS_ERROR_OPERATION_FAILED;
- result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, WAITING_TIME, &err);
+ 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] %s", err.message);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Send error %s", err.message);
+ dbus_error_free(&err);
+ }
if (NULL != result_msg) {
dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &result, DBUS_TYPE_INVALID);
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< Get arguments error (%s)\n", err.message);
- dbus_error_free(&err);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< 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 finalize : result = %d", result);
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts finalize : result = %d", result);
+ }
} else {
SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL ");
- if (dbus_error_is_set(&err))
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message);
tts_dbus_reconnect();
- }
-
- if (0 == result) {
- SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts finalize : result = %d \n", result);
- } else {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts finalize : result = %d \n", result);
+ result = TTS_ERROR_TIMED_OUT;
}
return result;
}
-int tts_dbus_request_get_support_voice(int uid, tts_h tts, tts_supported_voice_cb callback, void* user_data)
+int tts_dbus_request_add_text(int uid, const char* text, const char* lang, int vctype, int speed, int uttid, const char* credential)
{
+ if (NULL == text || NULL == lang) {
+ SLOG(LOG_ERROR, TAG_TTSC, "Input parameter is NULL");
+ return TTS_ERROR_INVALID_PARAMETER;
+ }
+
DBusMessage* msg;
DBusError err;
dbus_error_init(&err);
- msg = __tts_dbus_make_message(uid, TTS_METHOD_GET_SUPPORT_VOICES);
-
- if (NULL == msg) {
- SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts get supported voices : Fail to make message");
- if (dbus_error_is_set(&err))
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message);
+ msg = __tts_dbus_make_message(uid, TTS_METHOD_ADD_QUEUE);
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts add text : Fail to make message");
return TTS_ERROR_OPERATION_FAILED;
} else {
- SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts get supported voices : uid(%d)", uid);
+ SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts add text : uid(%d), text(%s), lang(%s), type(%d), speed(%d), id(%d), credential(%s)",
+ uid, text, lang, vctype, speed, uttid, (NULL == credential) ? "NULL" : credential);
+ }
+
+ char *temp = NULL;
+ if (NULL == credential) {
+ temp = strdup("NULL");
+ } else {
+ temp = strdup(credential);
}
- if (true != dbus_message_append_args( msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID)) {
+ if (true != dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &uid,
+ DBUS_TYPE_STRING, &text,
+ DBUS_TYPE_STRING, &lang,
+ DBUS_TYPE_INT32, &vctype,
+ DBUS_TYPE_INT32, &speed,
+ DBUS_TYPE_INT32, &uttid,
+ DBUS_TYPE_STRING, &temp,
+ DBUS_TYPE_INVALID)) {
dbus_message_unref(msg);
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
+ if (NULL != temp) {
+ free(temp);
+ temp = NULL;
+ }
return TTS_ERROR_OPERATION_FAILED;
}
DBusMessage* result_msg;
- DBusMessageIter args;
int result = TTS_ERROR_OPERATION_FAILED;
- result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, WAITING_TIME, &err );
+ 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] %s", err.message);
- printf("result message : %p\n", result_msg);
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Send error (%s)", err.message);
+ dbus_error_free(&err);
}
if (NULL != result_msg) {
- if (dbus_message_iter_init(result_msg, &args)) {
- /* Get result */
- if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) {
- dbus_message_iter_get_basic(&args, &result);
- dbus_message_iter_next(&args);
- }
-
- if (0 == result) {
- SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts get supported voices : result = %d \n", result);
-
- int size ;
- char* temp_char;
- int temp_int;
-
- /* Get voice size */
- if (DBUS_TYPE_INT32 == dbus_message_iter_get_arg_type(&args)) {
- dbus_message_iter_get_basic(&args, &size);
- dbus_message_iter_next(&args);
- }
+ dbus_message_get_args(result_msg, &err,
+ DBUS_TYPE_INT32, &result,
+ DBUS_TYPE_INVALID);
- if (0 >= size) {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts size of voice error : size = %d \n", size);
- } else {
- int i=0;
- for (i=0 ; i<size ; i++) {
- dbus_message_iter_get_basic(&args, &(temp_char) );
- dbus_message_iter_next(&args);
- dbus_message_iter_get_basic(&args, &(temp_int) );
- dbus_message_iter_next(&args);
-
- if (true != callback(tts, temp_char, (tts_voice_type_e)temp_int, user_data)) {
- break;
- }
- }
- }
- } else {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts get supported voices : result = %d \n", result);
- }
- } else {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts get supported voices : result message is invalid \n");
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts add text : 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 add text : result(%d)", result);
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts add text : result(%d)", result);
+ }
} else {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL");
- if (dbus_error_is_set(&err))
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message);
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL ");
tts_dbus_reconnect();
+ result = TTS_ERROR_TIMED_OUT;
}
+ if (NULL != temp) {
+ free(temp);
+ temp = NULL;
+ }
return result;
}
-int tts_dbus_request_get_default_voice(int uid , char** lang, tts_voice_type_e* vctype)
+int tts_dbus_request_set_private_data(int uid, const char* key, const char* data)
{
- if (NULL == lang || NULL == vctype) {
+ if (NULL == key || NULL == data) {
SLOG(LOG_ERROR, TAG_TTSC, "Input parameter is NULL");
return TTS_ERROR_INVALID_PARAMETER;
}
DBusError err;
dbus_error_init(&err);
- msg = __tts_dbus_make_message(uid, TTS_METHOD_GET_CURRENT_VOICE);
-
- if (NULL == msg) {
- SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts get default voice : Fail to make message");
- if (dbus_error_is_set(&err))
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message);
+ msg = __tts_dbus_make_message(uid, TTS_METHOD_SET_PRIVATE_DATA);
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts set private data : Fail to make message");
return TTS_ERROR_OPERATION_FAILED;
} else {
- SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts get default voice : uid(%d)", uid);
+ SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts set private data : uid(%d)", uid);
}
- if (true != dbus_message_append_args( msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID)) {
+ if (true != dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &uid,
+ DBUS_TYPE_STRING, &key,
+ DBUS_TYPE_STRING, &data,
+ DBUS_TYPE_INVALID)) {
dbus_message_unref(msg);
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
return TTS_ERROR_OPERATION_FAILED;
}
DBusMessage* result_msg;
int result = TTS_ERROR_OPERATION_FAILED;
- char* temp_lang;
- int voice_type;
- result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, WAITING_TIME, &err);
+ 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] %s", err.message);
- printf("result message : %p\n", result_msg);
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Send error (%s)", err.message);
+ dbus_error_free(&err);
}
if (NULL != result_msg) {
dbus_message_get_args(result_msg, &err,
DBUS_TYPE_INT32, &result,
- DBUS_TYPE_STRING, &temp_lang,
- DBUS_TYPE_INT32, &voice_type,
DBUS_TYPE_INVALID);
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< Get arguments error (%s)\n", err.message);
- dbus_error_free(&err);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts set private data : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
result = TTS_ERROR_OPERATION_FAILED;
- }
+ }
dbus_message_unref(result_msg);
- } else {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL ");
- if (dbus_error_is_set(&err))
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message);
- tts_dbus_reconnect();
- }
-
- if (0 == result) {
- *lang = strdup(temp_lang);
- *vctype = (tts_voice_type_e)voice_type;
- if (NULL == *lang) {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts get default voice : Out of memory \n");
- result = TTS_ERROR_OUT_OF_MEMORY;
+ if (0 == result) {
+ SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts set private data : result(%d)", result);
} else {
- SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts get default voice : result(%d), lang(%s), vctype(%d) \n", result, *lang, *vctype);
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts set private data : result(%d)", result);
}
} else {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts get default voice : result(%d) \n", result);
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL ");
+ tts_dbus_reconnect();
+ result = TTS_ERROR_TIMED_OUT;
}
return result;
}
-int tts_dbus_request_add_text(int uid, const char* text, const char* lang, int vctype, int speed, int uttid)
+int tts_dbus_request_get_private_data(int uid, const char* key, char** data)
{
- if (NULL == text || NULL == lang) {
+ if (NULL == key || NULL == data) {
SLOG(LOG_ERROR, TAG_TTSC, "Input parameter is NULL");
return TTS_ERROR_INVALID_PARAMETER;
}
DBusError err;
dbus_error_init(&err);
- msg = __tts_dbus_make_message(uid, TTS_METHOD_ADD_QUEUE);
-
- if (NULL == msg) {
- SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts add text : Fail to make message");
- if (dbus_error_is_set(&err))
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message);
+ msg = __tts_dbus_make_message(uid, TTS_METHOD_GET_PRIVATE_DATA);
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts get private data : Fail to make message");
return TTS_ERROR_OPERATION_FAILED;
} else {
- SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts add text : uid(%d), text(%s), lang(%s), type(%d), speed(%d), id(%d)",
- uid, text, lang, vctype, speed, uttid);
+ SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts get private data : uid(%d)", uid);
}
- if (true != dbus_message_append_args( msg,
+ if (true != dbus_message_append_args(msg,
DBUS_TYPE_INT32, &uid,
- DBUS_TYPE_STRING, &text,
- DBUS_TYPE_STRING, &lang,
- DBUS_TYPE_INT32, &vctype,
- DBUS_TYPE_INT32, &speed,
- DBUS_TYPE_INT32, &uttid,
+ DBUS_TYPE_STRING, &key,
DBUS_TYPE_INVALID)) {
dbus_message_unref(msg);
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
return TTS_ERROR_OPERATION_FAILED;
}
DBusMessage* result_msg;
int result = TTS_ERROR_OPERATION_FAILED;
- result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 5000, &err);
+ 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);
+ }
- if (dbus_error_is_set(&err))
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message);
-
+ char* temp = NULL;
if (NULL != result_msg) {
dbus_message_get_args(result_msg, &err,
DBUS_TYPE_INT32, &result,
+ DBUS_TYPE_STRING, &temp,
DBUS_TYPE_INVALID);
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts add text : Get arguments error (%s)\n", err.message);
- dbus_error_free(&err);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts get private data : 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 private data : result(%d)", result);
+ if (NULL != temp) {
+ *data = strdup(temp);
+ }
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts get private data : result(%d)", result);
+ }
} else {
SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL ");
- if (dbus_error_is_set(&err))
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message);
tts_dbus_reconnect();
+ result = TTS_ERROR_TIMED_OUT;
}
- if (0 == result) {
- SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts add text : result(%d) \n", result);
- } else {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts add text : result(%d) \n", result);
- }
-
return result;
}
-int tts_dbus_request_play(int uid)
+int tts_dbus_request_play(int uid, const char* credential)
{
DBusMessage* msg;
DBusError err;
msg = __tts_dbus_make_message(uid, TTS_METHOD_PLAY);
- if (NULL == msg) {
- SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts play : Fail to make message");
- if (dbus_error_is_set(&err))
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message);
-
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts play : Fail to make message");
return TTS_ERROR_OPERATION_FAILED;
} else {
SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts play : uid(%d)", uid);
}
-
- if (true != dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID)) {
+
+ char *temp = NULL;
+ if (NULL == credential) {
+ temp = strdup("NULL");
+ } else {
+ temp = strdup(credential);
+ }
+
+ if (true != dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &uid,
+ DBUS_TYPE_STRING, &temp,
+ DBUS_TYPE_INVALID)) {
dbus_message_unref(msg);
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
+ if (NULL != temp) {
+ free(temp);
+ temp = NULL;
+ }
return TTS_ERROR_OPERATION_FAILED;
}
DBusMessage* result_msg;
int result = TTS_ERROR_OPERATION_FAILED;
- result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 5000, &err);
+ 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] %s", err.message);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Send error (%s)", err.message);
+ dbus_error_free(&err);
+ }
if (NULL != result_msg) {
dbus_message_get_args(result_msg, &err,
DBUS_TYPE_INT32, &result,
DBUS_TYPE_INVALID);
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts play : Get arguments error (%s)\n", err.message);
- dbus_error_free(&err);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts play : 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 play : result(%d)", result);
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts play : result(%d)", result);
+ }
} else {
SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL ");
- if (dbus_error_is_set(&err))
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message);
tts_dbus_reconnect();
+ result = TTS_ERROR_TIMED_OUT;
}
- if (0 == result) {
- SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts play : result(%d) \n", result);
- } else {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts play : result(%d) \n", result);
+ if (NULL != temp) {
+ free(temp);
+ temp = NULL;
}
-
return result;
}
-
int tts_dbus_request_stop(int uid)
{
DBusMessage* msg;
msg = __tts_dbus_make_message(uid, TTS_METHOD_STOP);
- if (NULL == msg) {
- SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts stop : Fail to make message");
- if (dbus_error_is_set(&err))
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message);
-
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts stop : Fail to make message");
return TTS_ERROR_OPERATION_FAILED;
} else {
SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts stop : uid(%d)", uid);
if (true != dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID)) {
dbus_message_unref(msg);
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
return TTS_ERROR_OPERATION_FAILED;
}
- result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 5000, &err);
+ 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] %s", err.message);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Send error (%s)", err.message);
+ dbus_error_free(&err);
+ }
if (NULL != result_msg) {
dbus_message_get_args(result_msg, &err,
DBUS_TYPE_INT32, &result,
DBUS_TYPE_INVALID);
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts stop : Get arguments error (%s)\n", err.message);
- dbus_error_free(&err);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts stop : 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 stop : result(%d)", result);
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts stop : result(%d)", result);
+ }
} else {
SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL ");
- if (dbus_error_is_set(&err))
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message);
tts_dbus_reconnect();
- }
-
- if (0 == result) {
- SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts stop : result(%d) \n", result);
- } else {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts stop : result(%d) \n", result);
+ result = TTS_ERROR_TIMED_OUT;
}
return result;
msg = __tts_dbus_make_message(uid, TTS_METHOD_PAUSE);
- if (NULL == msg) {
- SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts pause : Fail to make message");
- if (dbus_error_is_set(&err))
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message);
-
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts pause : Fail to make message");
return TTS_ERROR_OPERATION_FAILED;
} else {
SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts pause : uid(%d)", uid);
if (true != dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID)) {
dbus_message_unref(msg);
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
return TTS_ERROR_OPERATION_FAILED;
}
- result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, 5000, &err);
+ 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] %s", err.message);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Send error (%s)", err.message);
+ dbus_error_free(&err);
+ }
if (NULL != result_msg) {
dbus_message_get_args(result_msg, &err,
DBUS_TYPE_INT32, &result,
DBUS_TYPE_INVALID);
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts pause : Get arguments error (%s)\n", err.message);
- dbus_error_free(&err);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts pause : 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 pause : result(%d)", result);
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts pause : result(%d)", result);
+ }
} else {
SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL ");
- if (dbus_error_is_set(&err))
- SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] %s", err.message);
tts_dbus_reconnect();
- }
-
- if (0 == result) {
- SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts pause : result(%d) \n", result);
- } else {
- SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts pause : result(%d) \n", result);
+ result = TTS_ERROR_TIMED_OUT;
}
return result;
}
-
-static Eina_Bool inotify_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
+int tts_dbus_request_play_pcm(int uid)
{
- SLOG(LOG_DEBUG, TAG_TTSC, "===== [File message] Inotify event call");
-
- int length;
+ DBusMessage* msg;
+ DBusError err;
+ dbus_error_init(&err);
- char buffer[sizeof(struct inotify_event) * BUFFER_SIZE];
+ msg = __tts_dbus_make_message(uid, TTS_METHOD_PLAY_PCM);
- length = read(g_fd_noti, buffer, (sizeof(struct inotify_event) * BUFFER_SIZE));
- if (0 > length) {
- SLOG(LOG_ERROR, TAG_TTSC, "[File message] Empty Inotify event");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
- return ECORE_CALLBACK_RENEW;
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts play pcm : Fail to make message");
+ return TTS_ERROR_OPERATION_FAILED;
+ } else {
+ SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts play pcm : uid(%d)", uid);
}
- bool is_empty_file = true;
-
- char filename[64];
- memset(filename, 0, 64);
- snprintf(filename, 64, "%s_%d", MESSAGE_FILE_PATH, getpid());
- FILE *fp;
+ if (true != dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &uid,
+ DBUS_TYPE_INVALID)) {
+ dbus_message_unref(msg);
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
+ return TTS_ERROR_OPERATION_FAILED;
+ }
- int i = 0;
- while (i < length) {
- char text[256];
- char msg[256];
- int uid, send_data;
+ DBusMessage* result_msg;
+ int result = TTS_ERROR_OPERATION_FAILED;
- struct inotify_event *event = (struct inotify_event *)&buffer[i];
- i = i + sizeof(struct inotify_event) + event->len;
+ 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);
+ }
- if (IN_CLOSE_WRITE == event->mask) {
+ if (NULL != result_msg) {
+ dbus_message_get_args(result_msg, &err,
+ DBUS_TYPE_INT32, &result,
+ DBUS_TYPE_INVALID);
- fp = fopen(filename, "r");
- if (NULL == fp) {
- SLOG(LOG_ERROR, TAG_TTSC, "[File message ERROR] open file failed");
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
- return ECORE_CALLBACK_RENEW;
- }
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts play pcm : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ result = TTS_ERROR_OPERATION_FAILED;
+ }
+ dbus_message_unref(result_msg);
- while (NULL != fgets(text, 256, fp)) {
- if (0 > sscanf(text, "%s %d %d", msg, &uid, &send_data)) {
- SLOG(LOG_ERROR, TAG_TTSC, "[File message] sscanf failed");
- continue;
- }
- SLOG(LOG_DEBUG, TAG_TTSC, "[File message] message - %s, uid - %d, send_data - %d", msg, uid, send_data);
- is_empty_file = false;
-
- int uttid;
- if (!strcmp(TTSD_METHOD_UTTERANCE_STARTED, msg)) {
- uttid = send_data;
- SLOG(LOG_DEBUG, TAG_TTSC, "<<<< Get Utterance started message : uid(%d), uttid(%d) \n", uid, uttid);
- __tts_cb_utt_started(uid, uttid);
- } else if (!strcmp(TTSD_METHOD_UTTERANCE_COMPLETED, msg)) {
- uttid = send_data;
- SLOG(LOG_DEBUG, TAG_TTSC, "<<<< Get Utterance completed message : uid(%d), uttid(%d) \n", uid, uttid);
- __tts_cb_utt_completed(uid, uttid);
-
- } else if (!strcmp(TTSD_METHOD_SET_STATE, msg)) {
- int state = send_data;
- SLOG(LOG_DEBUG, TAG_TTSC, "<<<< Get state change : uid(%d) , state(%d)", uid, state);
- __tts_cb_set_state(uid, state);
- }
- }
- fclose(fp);
+ if (0 == result) {
+ SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts play pcm : result(%d)", result);
} else {
- SLOG(LOG_ERROR, TAG_TTSC, "[File message] Undefined event");
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts play pcm : result(%d)", result);
}
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL ");
+ tts_dbus_reconnect();
+ result = TTS_ERROR_TIMED_OUT;
}
- if (true == is_empty_file)
- return ECORE_CALLBACK_PASS_ON;
+ return result;
+}
+
+int tts_dbus_request_stop_pcm(int uid)
+{
+ DBusMessage* msg;
+ DBusError err;
+ dbus_error_init(&err);
+
+ msg = __tts_dbus_make_message(uid, TTS_METHOD_STOP_PCM);
- fp = fopen(filename, "w+");
- if (NULL == fp) {
- SLOG(LOG_ERROR, TAG_TTSC, "[File message ERROR] open file failed");
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts stop pcm : Fail to make message");
+ return TTS_ERROR_OPERATION_FAILED;
} else {
- fclose(fp);
+ SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts stop pcm : uid(%d)", uid);
}
- SLOG(LOG_DEBUG, TAG_TTSC, "=====");
- SLOG(LOG_DEBUG, TAG_TTSC, " ");
+ if (true != dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &uid,
+ DBUS_TYPE_INVALID)) {
+ dbus_message_unref(msg);
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
+ return TTS_ERROR_OPERATION_FAILED;
+ }
- return ECORE_CALLBACK_PASS_ON;
+ 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);
+ }
+
+ if (NULL != result_msg) {
+ dbus_message_get_args(result_msg, &err,
+ DBUS_TYPE_INT32, &result,
+ DBUS_TYPE_INVALID);
+
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts stop pcm : 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 stop pcm : result(%d)", result);
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts stop pcm : 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_file_msg_open_connection()
+int tts_dbus_request_add_pcm(int uid, int event, const char* data, int data_size, int audio_type, int rate)
{
- /* get file notification handler */
- int fd;
- int wd;
+ DBusMessage* msg;
+ DBusError err;
+ dbus_error_init(&err);
+
+ msg = __tts_dbus_make_message(uid, TTS_METHOD_ADD_PCM);
+
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_TTSC, ">>>> Request tts add pcm : Fail to make message");
+ return TTS_ERROR_OPERATION_FAILED;
+ } else {
+ SLOG(LOG_DEBUG, TAG_TTSC, ">>>> Request tts add pcm : uid(%d)", uid);
+ }
- fd = inotify_init();
- if (fd < 0) {
- SLOG(LOG_ERROR, TAG_TTSC, "[File message ERROR] Fail get inotify_fd");
- return -1;
+ if (true != dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &uid,
+ DBUS_TYPE_INT32, &event,
+ DBUS_TYPE_INT32, &audio_type,
+ DBUS_TYPE_INT32, &rate,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
+ &data, data_size,
+ DBUS_TYPE_INVALID)) {
+ dbus_message_unref(msg);
+ SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to append args");
+ return TTS_ERROR_OPERATION_FAILED;
}
- g_fd_noti = fd;
- int pid = getpid();
- char path[64];
- memset(path, 0, 64);
- snprintf(path, 64, "%s_%d", MESSAGE_FILE_PATH, pid);
+ DBusMessage* result_msg;
+ int result = TTS_ERROR_OPERATION_FAILED;
- wd = inotify_add_watch(fd, path, IN_CLOSE_WRITE);
- g_wd_noti = wd;
- g_fd_handler_noti = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)inotify_event_callback, NULL, NULL, NULL);
- if (NULL == g_fd_handler_noti) {
- SLOG(LOG_ERROR, TAG_TTSC, "[File message ERROR] Fail to get handler_noti");
- return -1;
+ 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);
}
- return 0;
-}
-int tts_file_msg_close_connection()
-{
- /* del inotify variable */
- ecore_main_fd_handler_del(g_fd_handler_noti);
- inotify_rm_watch(g_fd_noti, g_wd_noti);
- close(g_fd_noti);
+ if (NULL != result_msg) {
+ dbus_message_get_args(result_msg, &err,
+ DBUS_TYPE_INT32, &result,
+ DBUS_TYPE_INVALID);
- return 0;
-}
\ No newline at end of file
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts add pcm : 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 add pcm : result(%d)", result);
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< tts add pcm : result(%d)", result);
+ }
+ } else {
+ SLOG(LOG_ERROR, TAG_TTSC, "<<<< Result message is NULL ");
+ tts_dbus_reconnect();
+ result = TTS_ERROR_TIMED_OUT;
+ }
+
+ return result;
+}