else if (dbus_message_is_signal(msg, "org.freedesktop.DBus", "NameOwnerChanged")) {
SLOG(LOG_DEBUG, TAG_STTC, "===== Owner Changed");
+ DBusError err;
+ dbus_error_init(&err);
+
+ /* remove a rule for daemon error */
+ char rule_err[256] = {0, };
+ snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", g_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_STTC, "Match Error (%s)", err.message);
+ dbus_error_free(&err);
+ }
+
__stt_cb_error(-1, STT_ERROR_SERVICE_RESET, "Daemon Reset");
SLOG(LOG_DEBUG, TAG_STTC, "=====");
SLOG(LOG_DEBUG, TAG_STTC, " ");
return ECORE_CALLBACK_RENEW;
}
+static void __stt_dbus_connection_free()
+{
+ if (NULL != g_conn_listener) {
+ dbus_connection_close(g_conn_listener);
+ dbus_connection_unref(g_conn_listener);
+ g_conn_listener = NULL;
+ }
+ if (NULL != g_conn_sender) {
+ dbus_connection_close(g_conn_sender);
+ dbus_connection_unref(g_conn_sender);
+ g_conn_sender = NULL;
+ }
+}
+
int stt_dbus_open_connection()
{
if (NULL != g_conn_sender && NULL != g_conn_listener) {
if (NULL == g_conn_listener) {
SLOG(LOG_ERROR, TAG_STTC, "Fail to get dbus connection");
+ __stt_dbus_connection_free();
return STT_ERROR_OPERATION_FAILED;
}
+ dbus_connection_set_exit_on_disconnect(g_conn_listener, false);
+
int pid = getpid();
char service_name[64];
if (dbus_error_is_set(&err)) {
SLOG(LOG_ERROR, TAG_STTC, "Match Error (%s)", err.message);
dbus_error_free(&err);
+ __stt_dbus_connection_free();
return STT_ERROR_OPERATION_FAILED;
}
int fd = 0;
if (true != dbus_connection_get_unix_fd(g_conn_listener, &fd)) {
SLOG(LOG_ERROR, TAG_STTC, "Fail to get fd from dbus");
+ __stt_dbus_connection_free();
return STT_ERROR_OPERATION_FAILED;
} else {
SLOG(LOG_DEBUG, TAG_STTC, "Get fd from dbus : %d", fd);
g_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, g_conn_listener, NULL, NULL);
if (NULL == g_fd_handler) {
SLOG(LOG_ERROR, TAG_STTC, "fail to get fd handler from ecore");
+ __stt_dbus_connection_free();
return STT_ERROR_OPERATION_FAILED;
}
dbus_error_free(&err);
}
- dbus_connection_close(g_conn_sender);
- dbus_connection_close(g_conn_listener);
-
- dbus_connection_unref(g_conn_sender);
- dbus_connection_unref(g_conn_listener);
-
- g_conn_sender = NULL;
- g_conn_listener = NULL;
-
+ __stt_dbus_connection_free();
__stt_dbus_service_free();
return 0;
int stt_dbus_reconnect()
{
+ if (!g_conn_sender || !g_conn_listener) {
+ stt_dbus_close_connection();
+
+ if (0 != stt_dbus_open_connection()) {
+ SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to reconnect");
+ return -1;
+ }
+
+ SLOG(LOG_DEBUG, TAG_STTC, "[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_STTC, "[DBUS] Sender(%s) Listener(%s)",
}
if (NULL == msg) {
- SLOG(LOG_ERROR, TAG_STTC, ">>>> Request stt hello : Fail to make message");
- return STT_ERROR_OPERATION_FAILED;
+// SLOG(LOG_ERROR, TAG_STTC, ">>>> Request stt hello : Fail to make message");
+ result = stt_dbus_reconnect();
+ if (0 != result)
+ return STT_ERROR_OPERATION_FAILED;
}
-
-
if (g_conn_sender) {
result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, g_waiting_short_time, &err);
dbus_message_unref(msg);
}
} else {
SLOG(LOG_WARN, TAG_STTC, "[WARN] dbus connection handle is null (%p)", g_conn_sender);
+ stt_dbus_reconnect();
result = STT_ERROR_OPERATION_FAILED;
}
/* add a rule for daemon error */
char rule_err[256] = {0, };
- snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", STT_SERVER_SERVICE_INTERFACE);
+ snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", g_server_service_interface);
dbus_bus_add_match(g_conn_listener, rule_err, &err);
dbus_connection_flush(g_conn_listener);
/* remove a rule for daemon error */
char rule_err[256] = {0, };
- snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", STT_SERVER_SERVICE_INTERFACE);
+ snprintf(rule_err, 256, "sender='org.freedesktop.DBus',path='/org/freedesktop/DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',type='signal',arg0='%s'", g_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)) {
return result;
#endif
}
+
+int stt_dbus_request_start_file(int uid, const char* lang, const char* type, int silence, const char* appid, const char* credential, const char* filepath, stt_audio_type_e audio_type, int sample_rate)
+{
+ if (NULL == lang || NULL == type || NULL == appid) {
+ SLOG(LOG_ERROR, TAG_STTC, "Input parameter is NULL");
+ return STT_ERROR_INVALID_PARAMETER;
+ }
+
+ DBusMessage* msg;
+
+ /* create a signal & check for errors */
+ msg = dbus_message_new_method_call(
+ g_server_service_name,
+ g_server_service_object,
+ g_server_service_interface,
+ STT_METHOD_START_FILE);
+
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_STTC, ">>>> stt start file : Fail to make message");
+ return STT_ERROR_OPERATION_FAILED;
+ } else {
+ SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt start file : uid(%d), language(%s), type(%s), appid(%s), filepath(%s), audio_type(%d), sample_rate(%d)", uid, lang, type, appid, filepath, audio_type, sample_rate);
+ }
+
+ char *temp = NULL;
+ if (NULL == credential) {
+ temp = strdup("NULL");
+ } else {
+ temp = strdup(credential);
+ }
+
+ dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &uid,
+ DBUS_TYPE_STRING, &lang,
+ DBUS_TYPE_STRING, &type,
+ DBUS_TYPE_INT32, &silence,
+ DBUS_TYPE_STRING, &appid,
+ DBUS_TYPE_STRING, &temp,
+ DBUS_TYPE_STRING, &filepath,
+ DBUS_TYPE_INT32, &audio_type,
+ DBUS_TYPE_INT32, &sample_rate,
+ DBUS_TYPE_INVALID);
+ if (g_conn_sender) {
+ dbus_message_set_no_reply(msg, TRUE);
+
+ if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
+ SLOG(LOG_ERROR, TAG_STTC, "[Dbus ERROR] <<<< stt start message : Out Of Memory !");
+ if (NULL != temp) {
+ free(temp);
+ temp = NULL;
+ }
+ return STT_ERROR_OUT_OF_MEMORY;
+ } else {
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+
+ } else {
+ SLOG(LOG_WARN, TAG_STTC, "[WARN] dbus connection handle is null (%p)", g_conn_sender);
+ if (NULL != temp) {
+ free(temp);
+ temp = NULL;
+ }
+ return STT_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL != temp) {
+ free(temp);
+ temp = NULL;
+ }
+ return 0;
+}
+
+int stt_dbus_request_cancel_file(int uid)
+{
+ DBusMessage* msg;
+
+ /* create a signal & check for errors */
+ msg = dbus_message_new_method_call(
+ g_server_service_name,
+ g_server_service_object,
+ g_server_service_interface,
+ STT_METHOD_CANCEL_FILE);
+
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_STTC, ">>>> stt cancel file : Fail to make message");
+ return STT_ERROR_OPERATION_FAILED;
+ } else {
+ SLOG(LOG_DEBUG, TAG_STTC, ">>>> stt cancel file : uid(%d)", uid);
+ }
+
+ dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &uid,
+ DBUS_TYPE_INVALID);
+
+ if (g_conn_sender) {
+ dbus_message_set_no_reply(msg, TRUE);
+
+ if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
+ SLOG(LOG_ERROR, TAG_STTC, "[Dbus ERROR] <<<< stt stop message : Out Of Memory !");
+ return STT_ERROR_OUT_OF_MEMORY;
+ } else {
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+ } else {
+ SLOG(LOG_WARN, TAG_STTC, "[WARN] dbus connection handle is null (%p)", g_conn_sender);
+ return STT_ERROR_OPERATION_FAILED;
+ }
+
+ return 0;
+}
+