From: wn.jang Date: Mon, 6 Jan 2020 14:09:02 +0000 (+0900) Subject: Update hello protocol X-Git-Tag: submit/tizen/20200115.024146^0 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Ftts.git;a=commitdiff_plain;h=65251843db39748e4d67cbb0306ed22d4f23382e Update hello protocol Change-Id: I5f5b9c258304b6f33656286db1a964a22e90617b (cherry picked from commit 2bab420365e627aa20f828007a62dc27acda5559) --- diff --git a/client/tts.c b/client/tts.c index cf37dc6..b7176fc 100644 --- a/client/tts.c +++ b/client/tts.c @@ -41,6 +41,7 @@ static int g_max_text_size = -1; static Ecore_Timer* g_check_state_timer = NULL; +static Ecore_Timer* g_hello_timer; /* for repetition */ static char* g_language = NULL; @@ -746,7 +747,7 @@ static Eina_Bool __tts_connect_daemon(void *data) } /* Send hello */ - if (0 != tts_dbus_request_hello(client->uid)) { + if (0 != tts_dbus_request_hello_sync(client->uid)) { return EINA_TRUE; } @@ -822,6 +823,97 @@ static Eina_Bool __tts_connect_daemon(void *data) return EINA_FALSE; } +int __tts_cb_hello(int uid, int ret, int credential_needed) +{ + tts_client_s* client = tts_client_get_by_uid(uid); + if (NULL == client) { + SLOG(LOG_ERROR, TAG_TTSC, "Fail to get TTS client or ignore this uid(%d)", uid); + return TTS_ERROR_OPERATION_FAILED; + } + + if (g_hello_timer) { + ecore_timer_del(g_hello_timer); + g_hello_timer = NULL; + } + + if (TTS_STATE_READY == client->current_state) { + SLOG(LOG_INFO, TAG_TTSC, "[INFO] tts client is already READY"); + return TTS_ERROR_NONE; + } + + if (TTS_ERROR_ENGINE_NOT_FOUND == ret) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret)); + + client->reason = TTS_ERROR_ENGINE_NOT_FOUND; + client->utt_id = -1; + + ecore_timer_add(0, __tts_notify_error, (void*)client->tts); + return TTS_ERROR_OPERATION_FAILED; + + } else if (TTS_ERROR_PERMISSION_DENIED == ret) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to initialize : %s", __tts_get_error_code(ret)); + + client->reason = TTS_ERROR_PERMISSION_DENIED; + client->utt_id = -1; + + ecore_timer_add(0, __tts_notify_error, (void*)client->tts); + return TTS_ERROR_PERMISSION_DENIED; + + } else if (TTS_ERROR_NONE != ret) { + SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Fail to connection. Retry to connect : %s", __tts_get_error_code(ret)); + return TTS_ERROR_OPERATION_FAILED; + + } else { + /* success to connect tts-daemon */ + client->credential_needed = credential_needed; + SLOG(LOG_ERROR, TAG_TTSC, "Supported options : credential(%s)", credential_needed ? "need" : "no need"); + } + + client->before_state = client->current_state; + client->current_state = TTS_STATE_READY; + + ecore_timer_add(0.0, __tts_notify_state_changed, client->tts); + + SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); + return TTS_ERROR_NONE; +} + +static Eina_Bool __send_hello(void *data) +{ + tts_h tts = (tts_h)data; + tts_client_s* client = tts_client_get(tts); + + /* check handle */ + if (NULL == client) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] A handle is not valid"); + g_hello_timer = NULL; + return EINA_FALSE; + } + + /* check state */ + if (client->current_state == TTS_STATE_READY) { + SLOG(LOG_ERROR, TAG_TTSC, "[INFO] TTS client has been already connected to tts service"); //LCOV_EXCL_LINE + SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); + g_hello_timer = NULL; + return EINA_FALSE; + } + + /* Send hello */ + int ret = tts_dbus_request_hello(client->uid); + if (0 != ret) { + SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to request hello !!"); //LCOV_EXCL_LINE + } else { + SLOG(LOG_ERROR, TAG_TTSC, "@@@ Send Hello"); + } + + if (!g_hello_timer) { + SLOG(LOG_ERROR, TAG_TTSC, "@@@ Call checking Hello timer callback"); + g_hello_timer = ecore_timer_add(0.5, __send_hello, tts); + return EINA_FALSE; + } + return EINA_TRUE; +} + int tts_prepare(tts_h tts) { if (0 != __tts_get_feature_enabled()) { @@ -846,13 +938,12 @@ int tts_prepare(tts_h tts) return TTS_ERROR_INVALID_STATE; } - ecore_thread_main_loop_begin(); - if (client->conn_timer) { - ecore_timer_del(client->conn_timer); - client->conn_timer = NULL; + if (NULL == g_hello_timer) { + SLOG(LOG_ERROR, TAG_TTSC, "@@@ Call checking Hello timer callback"); + ecore_thread_main_loop_begin(); + ecore_timer_add(0.0, __send_hello, (void*)tts); + ecore_thread_main_loop_end(); } - client->conn_timer = ecore_timer_add(0.02, __tts_connect_daemon, (void*)tts); - ecore_thread_main_loop_end(); SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); @@ -2176,6 +2267,7 @@ int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg) SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset"); data->current_state = TTS_STATE_CREATED; + data->reason = 0; ecore_thread_run(__start_reprepare_thread, __end_reprepare_thread, NULL, data); } @@ -2211,7 +2303,7 @@ int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg) SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset"); client->current_state = TTS_STATE_CREATED; - + client->reason = 0; ecore_thread_run(__start_reprepare_thread, __end_reprepare_thread, NULL, client); } } diff --git a/client/tts_dbus.c b/client/tts_dbus.c index 0c60f4a..49edc82 100644 --- a/client/tts_dbus.c +++ b/client/tts_dbus.c @@ -40,6 +40,73 @@ extern int __tts_cb_utt_started(int uid, int utt_id); extern int __tts_cb_utt_completed(int uid, int utt_id); +extern int __tts_cb_hello(int uid, int ret, int credential_needed); + + +static int __tts_dbus_add_match(int uid) +{ + /* 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); + } + + /* initialize the error value */ + DBusError err; + dbus_error_init(&err); + + 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 + } + return TTS_ERROR_NONE; +} + +static int __tts_dbus_remove_match(int mode) +{ + DBusError err; + dbus_error_init(&err); + + /* remove a rule for daemon error */ + char rule_err[256] = {0, }; + + if (TTS_MODE_DEFAULT == 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 == 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 == 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 == 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); + } + + return 0; +} static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler) { @@ -65,9 +132,34 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle dbus_error_init(&err); char if_name[64] = {0, }; - snprintf(if_name, 64, "%s", TTS_CLIENT_SERVICE_INTERFACE); + snprintf(if_name, 64, "%s%d", TTS_CLIENT_SERVICE_INTERFACE, getpid()); + + if (dbus_message_is_signal(msg, if_name, TTSD_METHOD_HELLO)) { + SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Get Hello"); + + int uid; + int ret; + int credential_needed; + + dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &uid, + DBUS_TYPE_INT32, &ret, + DBUS_TYPE_INT32, &credential_needed, + DBUS_TYPE_INVALID); - if (dbus_message_is_signal(msg, if_name, TTSD_METHOD_UTTERANCE_STARTED)) { + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, TAG_TTSC, "@@ tts Get Hello message : Get arguments error (%s)", err.message); + dbus_error_free(&err); + } else { + SLOG(LOG_DEBUG, TAG_TTSC, "@@ tts Get Hello message : uid(%d), credential_needed(%d)", uid, credential_needed); + __tts_dbus_add_match(uid); + __tts_cb_hello(uid, ret, credential_needed); + } + + SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); + } + + else if (dbus_message_is_signal(msg, if_name, TTSD_METHOD_UTTERANCE_STARTED)) { int uid = 0; int uttid = 0; @@ -137,6 +229,12 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameOwnerChanged")) { SLOG(LOG_DEBUG, TAG_TTSC, "@@@ Owner Changed"); + + __tts_dbus_remove_match(TTS_MODE_DEFAULT); + __tts_dbus_remove_match(TTS_MODE_NOTIFICATION); + __tts_dbus_remove_match(TTS_MODE_SCREEN_READER); + __tts_dbus_remove_match(TTS_MODE_INTERRUPT); + __tts_cb_error(-1, TTS_ERROR_SERVICE_RESET, -1, "Daemon Reset"); SLOG(LOG_DEBUG, TAG_TTSC, "@@@"); SLOG(LOG_DEBUG, TAG_TTSC, " "); @@ -208,8 +306,18 @@ int tts_dbus_open_connection() dbus_connection_set_exit_on_disconnect(g_conn_listener, false); + /* register our name on the bus, and check for errors */ + dbus_bus_request_name(g_conn_listener, TTS_CLIENT_SERVICE_NAME, DBUS_NAME_FLAG_REPLACE_EXISTING , &err); + + if (dbus_error_is_set(&err)) { + //LCOV_EXCL_START + SLOG(LOG_ERROR, TAG_TTSC, "Name Error (%s)", err.message); + dbus_error_free(&err); + //LCOV_EXCL_STOP + } + char rule[128] = {0, }; - snprintf(rule, 128, "type='signal',interface='%s'", TTS_CLIENT_SERVICE_INTERFACE); + snprintf(rule, 128, "type='signal',interface='%s%d'", TTS_CLIENT_SERVICE_INTERFACE, getpid()); /* add a rule for which messages we want to see */ dbus_bus_add_match(g_conn_listener, rule, &err); @@ -349,6 +457,47 @@ int tts_dbus_request_hello(int uid) return TTS_ERROR_OPERATION_FAILED; } + 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"); + + return TTS_ERROR_OPERATION_FAILED; + } + + dbus_message_set_no_reply(msg, TRUE); + + if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + SLOG(LOG_ERROR, TAG_TTSC, "[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE + dbus_message_unref(msg); + return TTS_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_INFO, TAG_TTSC, "[Dbus DEBUG] Success to Send"); + dbus_connection_flush(g_conn_sender); + } + + dbus_message_unref(msg); + return 0; +} + +int tts_dbus_request_hello_sync(int uid) +{ + DBusError err; + dbus_error_init(&err); + DBusMessage* msg; + + msg = __tts_dbus_make_message(uid, TTS_METHOD_HELLO_SYNC); + + if (dbus_error_is_set(&err)) { +// SLOG(LOG_DEBUG, TAG_TTSC, "<<<< tts dbus log : %s", err); + dbus_error_free(&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; diff --git a/client/tts_dbus.h b/client/tts_dbus.h index 227b4e5..a59ebc6 100644 --- a/client/tts_dbus.h +++ b/client/tts_dbus.h @@ -27,6 +27,8 @@ int tts_dbus_close_connection(); int tts_dbus_request_hello(int uid); +int tts_dbus_request_hello_sync(int uid); + int tts_dbus_request_initialize(int uid, bool* credential_needed); int tts_dbus_request_finalize(int uid); diff --git a/common/tts_defs.h b/common/tts_defs.h index 32afeb7..91901f6 100644 --- a/common/tts_defs.h +++ b/common/tts_defs.h @@ -52,6 +52,7 @@ extern "C" { *******************************************************************************************/ #define TTS_METHOD_HELLO "tts_method_hello" +#define TTS_METHOD_HELLO_SYNC "tts_method_hello_sync" #define TTS_METHOD_INITIALIZE "tts_method_initialize" #define TTS_METHOD_FINALIZE "tts_method_finalilze" #define TTS_METHOD_GET_SUPPORT_VOICES "tts_method_get_support_voices" diff --git a/server/ttsd_dbus.c b/server/ttsd_dbus.c index c69cd30..100074c 100644 --- a/server/ttsd_dbus.c +++ b/server/ttsd_dbus.c @@ -56,69 +56,41 @@ const char* __ttsd_get_error_code(ttsd_error_e err) return NULL; } -int ttsdc_send_hello(int pid, int uid) +int ttsdc_send_hello(int pid, int uid, int ret, int credential_needed) { -#if 0 if (NULL == g_conn_sender) { SLOG(LOG_ERROR, tts_tag(), "[Dbus ERROR] Dbus connection is not available"); return -1; } - char service_name[64]; - memset(service_name, 0, 64); - snprintf(service_name, 64, "%s%d", TTS_CLIENT_SERVICE_NAME, pid); - + DBusMessage* msg; char target_if_name[64]; snprintf(target_if_name, sizeof(target_if_name), "%s%d", TTS_CLIENT_SERVICE_INTERFACE, pid); - DBusMessage* msg; - - /* create a message & check for errors */ - msg = dbus_message_new_method_call( - service_name, - TTS_CLIENT_SERVICE_OBJECT_PATH, - target_if_name, - TTSD_METHOD_HELLO); + /* 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_HELLO); /* name of the signal */ if (NULL == msg) { - SLOG(LOG_ERROR, tts_tag(), "<<<< [Dbus ERROR] Fail to create hello message : uid(%d)", uid); + SLOG(LOG_ERROR, tts_tag(), "<<<< [Dbus ERROR] Fail to create hello message : uid(%d), ret(%d), credential_needed(%d)", uid, ret, credential_needed); return -1; } else { - SLOG(LOG_DEBUG, tts_tag(), "<<<< [Dbus] Send hello message : uid(%d)", uid); - } - - dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID); - - DBusError err; - dbus_error_init(&err); - - DBusMessage* result_msg; - int result = -1; - - result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_time, &err); - dbus_message_unref(msg); - if (dbus_error_is_set(&err)) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Send error (%s)", err.message); - dbus_error_free(&err); + SLOG(LOG_INFO, tts_tag(), "<<<< [Dbus] Send hello message : uid(%d), ret(%d), credential_needed(%d)", uid, ret, credential_needed); } - 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, tts_tag(), ">>>> [Dbus] Get arguments error (%s)", err.message); - dbus_error_free(&err); - result = -1; - } + dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INT32, &credential_needed, DBUS_TYPE_INVALID); - dbus_message_unref(result_msg); + 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] Result message is NULL. Client is not available"); - result = 0; + SLOG(LOG_INFO, tts_tag(), "[Dbus] SUCCESS Send"); + dbus_connection_flush(g_conn_sender); } - return result; -#endif + dbus_message_unref(msg); return 0; } @@ -131,10 +103,13 @@ int ttsdc_send_message(int pid, int uid, int data, const char *method) 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 */ - TTS_CLIENT_SERVICE_INTERFACE, /* interface name of the signal */ + target_if_name, /* interface name of the signal */ method); /* name of the signal */ if (NULL == msg) { @@ -183,10 +158,13 @@ int ttsdc_send_error_message(int pid, int uid, int uttid, int reason, char* err_ 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 */ - TTS_CLIENT_SERVICE_INTERFACE, /* interface name of the signal */ + target_if_name, /* interface name of the signal */ TTSD_METHOD_ERROR); /* name of the signal */ if (NULL == msg) { @@ -240,6 +218,9 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_HELLO)) { ttsd_dbus_server_hello(g_conn_listener, msg); + } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_HELLO_SYNC)) { + ttsd_dbus_server_hello_sync(g_conn_listener, msg); + } else if (dbus_message_is_method_call(msg, g_service_interface, TTS_METHOD_INITIALIZE)) { ttsd_dbus_server_initialize(g_conn_listener, msg); diff --git a/server/ttsd_dbus.h b/server/ttsd_dbus.h index f4772c5..c98ca26 100644 --- a/server/ttsd_dbus.h +++ b/server/ttsd_dbus.h @@ -23,7 +23,7 @@ int ttsd_dbus_open_connection(); int ttsd_dbus_close_connection(); -int ttsdc_send_hello(int pid, int uid); +int ttsdc_send_hello(int pid, int uid, int ret, int credential_needed); int ttsdc_send_utt_start_message(int pid, int uid, int uttid); diff --git a/server/ttsd_dbus_server.c b/server/ttsd_dbus_server.c index e750048..428fd6a 100644 --- a/server/ttsd_dbus_server.c +++ b/server/ttsd_dbus_server.c @@ -26,6 +26,37 @@ int ttsd_dbus_server_hello(DBusConnection* conn, DBusMessage* msg) { SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS Hello"); + DBusError err; + dbus_error_init(&err); + + int pid; + int uid; + dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &pid, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID); + + if (dbus_error_is_set(&err)) { + SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] ttsd Hello : get arguments error (%s)", err.message); + dbus_error_free(&err); + } else { + SLOG(LOG_INFO, tts_tag(), "[IN] ttsd hello : pid(%d), uid(%d)", pid, uid); + bool is_initialized = false; + ttsd_server_is_already_initialized(pid, uid, &is_initialized); + if (false == is_initialized) { + bool credential_needed = 0; + int ret = ttsd_server_initialize(pid, uid, &credential_needed); + if (0 != ret) { + SLOG(LOG_ERROR, tts_tag(), "[IN ERROR] ttsd Hello : server initialize, ret(%d)", ret); + } + ttsdc_send_hello(pid, uid, ret, (int)credential_needed); + } + } + + return 0; +} + +int ttsd_dbus_server_hello_sync(DBusConnection* conn, DBusMessage* msg) +{ + SLOG(LOG_DEBUG, tts_tag(), ">>>>> TTS Hello"); + DBusMessage* reply; reply = dbus_message_new_method_return(msg); diff --git a/server/ttsd_dbus_server.h b/server/ttsd_dbus_server.h index aa28525..ec6dce1 100644 --- a/server/ttsd_dbus_server.h +++ b/server/ttsd_dbus_server.h @@ -23,6 +23,8 @@ extern "C" { int ttsd_dbus_server_hello(DBusConnection* conn, DBusMessage* msg); +int ttsd_dbus_server_hello_sync(DBusConnection* conn, DBusMessage* msg); + /* * Dbus Server functions for APIs */ diff --git a/server/ttsd_server.c b/server/ttsd_server.c index 2687119..bb2e53d 100644 --- a/server/ttsd_server.c +++ b/server/ttsd_server.c @@ -550,6 +550,17 @@ int ttsd_terminate() * TTS Server Functions for Client */ +int ttsd_server_is_already_initialized(int pid, int uid, bool* is_initialized) +{ + if (-1 != ttsd_data_is_client(uid)) + *is_initialized = true; + else + *is_initialized = false; + + SLOG(LOG_INFO, tts_tag(), "[Server INFO] Pid(%d), Uid(%d) is %s", pid, uid, *is_initialized ? "already initialized" : "not initialized yet"); + return TTSD_ERROR_NONE; +} + int ttsd_server_initialize(int pid, int uid, bool* credential_needed) { SLOG(LOG_INFO, tts_tag(), "[Server] Server initialize"); diff --git a/server/ttsd_server.h b/server/ttsd_server.h index 48862fc..d67d227 100644 --- a/server/ttsd_server.h +++ b/server/ttsd_server.h @@ -47,6 +47,8 @@ int ttsd_set_private_data_requested_cb(ttse_private_data_requested_cb callback); * Server API for client */ +int ttsd_server_is_already_initialized(int pid, int uid, bool* is_initialized); + int ttsd_server_initialize(int pid, int uid, bool* credential_needed); int ttsd_server_finalize(int uid); diff --git a/server/ttse.c b/server/ttse.c index 0f40802..4ba73d7 100755 --- a/server/ttse.c +++ b/server/ttse.c @@ -92,12 +92,6 @@ int ttse_main(int argc, char** argv, ttse_request_callback_s *callback) return TTSE_ERROR_OPERATION_FAILED; } - if (0 != ttsd_dbus_open_connection()) { - SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to open dbus connection"); - ecore_shutdown(); - return TTSE_ERROR_OPERATION_FAILED; - } - ret = ttsd_initialize(callback); if (0 != ret) { SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to initialize"); @@ -106,6 +100,12 @@ int ttse_main(int argc, char** argv, ttse_request_callback_s *callback) return ret; } + if (0 != ttsd_dbus_open_connection()) { + SLOG(LOG_ERROR, tts_tag(), "[ERROR] Fail to open dbus connection"); + ecore_shutdown(); + return TTSE_ERROR_OPERATION_FAILED; + } + if (0 != ttsd_network_initialize()) { SLOG(LOG_WARN, tts_tag(), "[WARNING] Fail to initialize network"); }