/*
-* 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
#include "sttd_client_data.h"
#include "sttd_dbus_server.h"
#include "stt_defs.h"
+#include <aul.h>
+#include <vconf.h>
+#include <buxton2.h>
+
+static DBusConnection* g_conn_sender = NULL;
+static DBusConnection* g_conn_listener = NULL;
+static DBusConnection* g_conn_custom = NULL;
+
+static Ecore_Fd_Handler* g_dbus_fd_handler = NULL;
-static DBusConnection* g_conn;
static int g_waiting_time = 3000;
+static int g_internal_result_id = 0;
+
+static char* g_server_service_name = NULL;
+static char* g_server_service_object = NULL;
+static char* g_server_service_interface = NULL;
+
+void __sttd_dbus_service_free();
+
int sttdc_send_hello(int uid)
{
int pid = sttd_client_get_pid(uid);
-
if (0 > pid) {
SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid");
- return -1;
+ return STTD_ERROR_INVALID_PARAMETER;
}
char service_name[64];
char target_if_name[128];
snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
- DBusMessage* msg;
+ DBusMessage* msg = NULL;
SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Send hello message : uid(%d)", uid);
msg = dbus_message_new_method_call(
- service_name,
- STT_CLIENT_SERVICE_OBJECT_PATH,
- target_if_name,
+ service_name,
+ STT_CLIENT_SERVICE_OBJECT_PATH,
+ target_if_name,
STTD_METHOD_HELLO);
- if (NULL == msg) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message");
- return -1;
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message");
+ return STTD_ERROR_OUT_OF_MEMORY;
}
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, msg, g_waiting_time, &err);
+ DBusMessage* result_msg = NULL;
+ 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, TAG_STTD, "[ERROR] Send error (%s)", err.message);
+ if (NULL != err.name) {
+ if (!strcmp(err.name, DBUS_ERROR_SERVICE_UNKNOWN)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[ERROR] Unknown service. Client is not available");
+ dbus_error_free(&err);
+ return 0;
+ }
+ }
+ 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_STTD, "[Dbus] Get arguments error (%s)\n", err.message);
- dbus_error_free(&err);
- result = -1;
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus] Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
}
dbus_message_unref(result_msg);
} else {
SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Result message is NULL. Client is not available");
- result = 0;
}
return result;
}
-int sttdc_send_get_state(int uid, int* state)
+int sttdc_send_set_volume(int uid, float volume)
{
int pid = sttd_client_get_pid(uid);
DBusMessage* msg;
- SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Send get state message : uid(%d)", uid);
+ /* SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Send set volume : uid(%d), volume(%f) volume size(%d)", uid, volume, sizeof(float)); */
- msg = dbus_message_new_method_call(
- service_name,
- STT_CLIENT_SERVICE_OBJECT_PATH,
- target_if_name,
- STTD_METHOD_GET_STATE);
+ msg = dbus_message_new_signal(
+ STT_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */
+ target_if_name, /* interface name of the signal */
+ STTD_METHOD_SET_VOLUME); /* name of the signal */
- if (NULL == msg) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message");
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message");
return -1;
}
- dbus_message_append_args(msg, DBUS_TYPE_INT32, &uid, DBUS_TYPE_INVALID);
-
- DBusError err;
- dbus_error_init(&err);
+ dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &uid,
+ DBUS_TYPE_INT32, &volume,
+ DBUS_TYPE_INVALID);
- DBusMessage* result_msg;
- int tmp = -1;
- int result = 0;
+ if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to send message : Out Of Memory !");
+ } else {
+ SLOG(LOG_DEBUG, TAG_STTD, "<<<< Send set volume : uid(%d), volume(%f)", uid, volume);
+ dbus_connection_flush(g_conn_sender);
+ }
- result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
dbus_message_unref(msg);
- if (NULL != result_msg) {
- dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &tmp, DBUS_TYPE_INVALID);
+ return 0;
+}
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus] Get arguments error (%s)\n", err.message);
- dbus_error_free(&err);
- result = -1;
- } else {
- *state = tmp;
- result = 0;
- }
+int sttdc_send_set_state(int uid, int state)
+{
+ int pid = sttd_client_get_pid(uid);
- dbus_message_unref(result_msg);
+ if (0 > pid) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid");
+ return -1;
+ }
+
+ char service_name[64];
+ memset(service_name, 0, 64);
+ snprintf(service_name, 64, "%s%d", STT_CLIENT_SERVICE_NAME, pid);
+
+ char target_if_name[128];
+ snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
+
+ DBusMessage* msg = NULL;
+ msg = dbus_message_new_signal(
+ STT_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */
+ target_if_name, /* interface name of the signal */
+ STTD_METHOD_SET_STATE); /* name of the signal */
+
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message");
+ return -1;
+ }
+
+ dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &uid,
+ DBUS_TYPE_INT32, &state,
+ DBUS_TYPE_INVALID);
+
+ if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to send change state message : Out Of Memory !");
} else {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus] Result message is NULL. Client is not available");
- result = -1;
+ SLOG(LOG_DEBUG, TAG_STTD, "<<<< Send change state message : uid(%d), state(%d)", uid, state);
+ dbus_connection_flush(g_conn_sender);
}
-
- return result;
+
+ dbus_message_unref(msg);
+
+ return 0;
}
-int sttdc_send_result(int uid, const char* type, const char** data, int data_count, const char* result_msg)
+int sttdc_send_speech_status(int uid, int status)
{
int pid = sttd_client_get_pid(uid);
if (0 > pid) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid" );
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid");
return -1;
}
char target_if_name[128];
snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
- DBusMessage* msg;
-
- SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] send result signal : uid(%d), type(%s), result count(%d)", uid, type, data_count);
-
- msg = dbus_message_new_method_call(
- service_name,
- STT_CLIENT_SERVICE_OBJECT_PATH,
- target_if_name,
- STTD_METHOD_RESULT);
+ DBusMessage* msg = NULL;
+ msg = dbus_message_new_signal(
+ STT_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */
+ target_if_name, /* interface name of the signal */
+ STTD_METHOD_SPEECH_STATUS); /* name of the signal */
- if (NULL == msg) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message");
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message");
return -1;
}
+ dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &uid,
+ DBUS_TYPE_INT32, &status,
+ DBUS_TYPE_INVALID);
+
+ if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to send speech status message : Out Of Memory !");
+ } else {
+ SLOG(LOG_DEBUG, TAG_STTD, "<<<< Send speech status message : uid(%d), status(%d)", uid, status);
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+
+ return 0;
+}
+
+int sttdc_send_result(int uid, int event, const char** data, int data_count, const char* result_msg)
+{
+ int pid = sttd_client_get_pid(uid);
+ if (0 > pid) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid");
+ return STTD_ERROR_INVALID_PARAMETER;
+ }
+
+ char service_name[64];
+ memset(service_name, 0, 64);
+ snprintf(service_name, 64, "%s%d", STT_CLIENT_SERVICE_NAME, pid);
+
+ char target_if_name[128];
+ memset(target_if_name, 0, 128);
+ snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
+
+ DBusMessage* msg = NULL;
+ SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] send result signal : uid(%d), event(%d), result count(%d) result id(%d)",
+ uid, event, data_count, g_internal_result_id);
+
+ msg = dbus_message_new_signal(
+ STT_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */
+ target_if_name, /* interface name of the signal */
+ STTD_METHOD_RESULT); /* name of the signal */
+
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message");
+ return STTD_ERROR_OUT_OF_MEMORY;
+ }
+
DBusMessageIter args;
dbus_message_iter_init_append(msg, &args);
dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &uid);
char* msg_temp;
- if (NULL == type) {
- msg_temp = strdup("None");
- dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(msg_temp));
- SLOG(LOG_WARN, TAG_STTD, "[Dbus] result type is NULL");
- free(msg_temp);
- } else {
- dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(type));
- SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] result type(%s)", type );
- }
+ dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &event);
/* Append result msg */
if (NULL == result_msg) {
msg_temp = strdup("None");
dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &msg_temp);
- SLOG(LOG_WARN, TAG_STTD, "[Dbus] result message is NULL");
+ SLOG(LOG_WARN, TAG_STTD, "[Dbus] result message is NULL");
free(msg_temp);
} else {
- SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] result message(%s)", result_msg );
+ SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] result message(%s)", result_msg);
dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &(result_msg));
}
-
+
/* Append result size */
if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(data_count))) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus] response message : Fail to append result size");
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus] response message : Fail to append result size");
+ dbus_message_unref(msg);
return -1;
}
- int i;
+ if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &(g_internal_result_id))) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus] response message : Fail to append internal result id");
+ dbus_message_unref(msg);
+ return -1;
+ }
+
+ g_internal_result_id++;
+
+ if (10000 == g_internal_result_id) {
+ g_internal_result_id = 1;
+ }
- SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] result size (%d)", data_count);
- for (i=0 ; i<data_count ; i++) {
+ int i;
+ SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] result size (%d)", data_count);
+ for (i = 0; i < data_count; i++) {
if (NULL != data[i]) {
- SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] result (%d, %s)", i, data[i] );
+ SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] result (%d, %s)", i, data[i]);
if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &data[i])) {
SLOG(LOG_ERROR, TAG_STTD, "[Dbus] response message : Fail to append result data");
- return -1;
+ dbus_message_unref(msg);
+ return STTD_ERROR_OPERATION_FAILED;
}
} else {
int reason = (int)STTD_ERROR_OPERATION_FAILED;
if (0 != sttdc_send_error_signal(uid, reason, "Fail to get recognition result from engine")) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to send error info. Remove client data");
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to send error info. Remove client data");
/* clean client data */
sttd_client_delete(uid);
}
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Result from engine is NULL(%d) %s", i);
-
- return -1;
+ dbus_message_unref(msg);
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Result from engine is NULL(%d)", i);
+ return STTD_ERROR_OPERATION_FAILED;
}
}
-
- if (!dbus_connection_send(g_conn, msg, NULL)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to send message : Out Of Memory !");
- return -1;
+
+ if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to send message : Out Of Memory !");
}
- dbus_connection_flush(g_conn);
+ dbus_connection_flush(g_conn_sender);
dbus_message_unref(msg);
return 0;
}
-int sttdc_send_partial_result(int uid, const char* data)
+int sttdc_send_error_signal(int uid, int reason, const char *err_msg)
{
int pid = sttd_client_get_pid(uid);
-
if (0 > pid) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid" );
- return -1;
- }
-
- if (NULL == data) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Input data is NULL" );
- return -1;
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid");
+ return STTD_ERROR_INVALID_PARAMETER;
}
char service_name[64];
char target_if_name[128];
snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
- DBusMessage* msg;
-
- SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] send result signal : uid(%d), result(%s)", uid, data);
-
- msg = dbus_message_new_method_call(
- service_name,
- STT_CLIENT_SERVICE_OBJECT_PATH,
- target_if_name,
- STTD_METHOD_PARTIAL_RESULT);
+ DBusMessage* msg = NULL;
+ msg = dbus_message_new_signal(
+ STT_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */
+ target_if_name, /* interface name of the signal */
+ STTD_METHOD_ERROR); /* name of the signal */
- if (NULL == msg) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message");
- return -1;
+ if (NULL == msg) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message");
+ return STTD_ERROR_OUT_OF_MEMORY;
}
- DBusMessageIter args;
- dbus_message_iter_init_append(msg, &args);
-
- /* Append uid & type */
- dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &uid);
-
- SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Partial result (%s)", data );
+ dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &uid,
+ DBUS_TYPE_INT32, &reason,
+ DBUS_TYPE_STRING, &err_msg,
+ DBUS_TYPE_INVALID);
- if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, data)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus] response message : Fail to append result data");
- return -1;
- }
-
- if (!dbus_connection_send(g_conn, msg, NULL)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to send message : Out Of Memory !");
- return -1;
+ if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] <<<< error message : Out Of Memory !");
+ } else {
+ SLOG(LOG_DEBUG, TAG_STTD, "<<<< Send error message : uid(%d), reason(%d), err_msg(%s)", uid, reason, (NULL == err_msg) ? "NULL" : err_msg);
+ dbus_connection_flush(g_conn_sender);
}
- dbus_connection_flush(g_conn);
dbus_message_unref(msg);
return 0;
}
-int sttdc_send_error_signal(int uid, int reason, char *err_msg)
+static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
{
- if (NULL == err_msg) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Input parameter is NULL");
- return STTD_ERROR_INVALID_PARAMETER;
- }
-
- int pid = sttd_client_get_pid(uid);
-
- if (0 > pid) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid" );
- return -1;
- }
+ SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] listener_event_callback is called!!!");
- char service_name[64];
- memset(service_name, 0, 64);
- snprintf(service_name, 64, "%s%d", STT_CLIENT_SERVICE_NAME, pid);
+ if (NULL == g_conn_listener) return ECORE_CALLBACK_RENEW;
- char target_if_name[128];
- snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
+ dbus_connection_read_write_dispatch(g_conn_listener, 50);
- DBusMessage* msg;
- SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] send error signal : reason(%d), Error Msg(%s)", reason, err_msg);
-
- msg = dbus_message_new_method_call(
- service_name,
- STT_CLIENT_SERVICE_OBJECT_PATH,
- target_if_name,
- STTD_METHOD_ERROR);
+ DBusMessage* msg = NULL;
+ msg = dbus_connection_pop_message(g_conn_listener);
- if (NULL == msg) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message");
- return -1;
+ if (true != dbus_connection_get_is_connected(g_conn_listener)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Connection is disconnected");
+ return ECORE_CALLBACK_RENEW;
}
- dbus_message_append_args(msg,
- DBUS_TYPE_INT32, &uid,
- DBUS_TYPE_INT32, &reason,
- DBUS_TYPE_STRING, &err_msg,
- DBUS_TYPE_INVALID);
-
- DBusError err;
- dbus_error_init(&err);
-
- DBusMessage* result_msg;
-
- result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
- dbus_message_unref(msg);
-
- if (NULL != result_msg) {
- dbus_message_unref(result_msg);
- } else {
- SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Result message is NULL.");
+ /* loop again if we haven't read a message */
+ if (NULL == msg) {
+ return ECORE_CALLBACK_RENEW;
}
- return 0;
-}
-
-int sttdc_send_set_state(int uid, int state)
-{
- int pid = sttd_client_get_pid(uid);
-
- if (0 > pid) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] pid is NOT valid");
- return -1;
- }
+ SLOG(LOG_DEBUG, TAG_STTD, "[Dbus info] service name: %s, service object: %s, service interface: %s", (NULL == g_server_service_name) ? "NULL" : g_server_service_name,
+ (NULL == g_server_service_object) ? "NULL" : g_server_service_object, (NULL == g_server_service_interface) ? "NULL" : g_server_service_interface);
- char service_name[64];
- memset(service_name, 0, 64);
- snprintf(service_name, 64, "%s%d", STT_CLIENT_SERVICE_NAME, pid);
+ /* client event */
+ if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_HELLO))
+ sttd_dbus_server_hello(g_conn_listener, msg);
- char target_if_name[128];
- snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_INITIALIZE))
+ sttd_dbus_server_initialize(g_conn_listener, msg);
- DBusMessage* msg;
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_FINALIZE))
+ sttd_dbus_server_finalize(g_conn_listener, msg);
- SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Send change state message : uid(%d), state(%d)", uid, state);
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_SET_CURRENT_ENGINE))
+ sttd_dbus_server_set_current_engine(g_conn_listener, msg);
- msg = dbus_message_new_method_call(
- service_name,
- STT_CLIENT_SERVICE_OBJECT_PATH,
- target_if_name,
- STTD_METHOD_SET_STATE);
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_CHECK_APP_AGREED))
+ sttd_dbus_server_check_app_agreed(g_conn_listener, msg);
- if (NULL == msg) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to create message");
- return -1;
- }
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_GET_SUPPORT_LANGS))
+ sttd_dbus_server_get_support_lang(g_conn_listener, msg);
- dbus_message_append_args(msg,
- DBUS_TYPE_INT32, &uid,
- DBUS_TYPE_INT32, &state,
- DBUS_TYPE_INVALID);
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_GET_CURRENT_LANG))
+ sttd_dbus_server_get_default_lang(g_conn_listener, msg);
- DBusError err;
- dbus_error_init(&err);
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_SET_PRIVATE_DATA))
+ sttd_dbus_server_set_private_data(g_conn_listener, msg);
- DBusMessage* result_msg;
- int result = -1;
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_GET_PRIVATE_DATA))
+ sttd_dbus_server_get_private_data(g_conn_listener, msg);
- result_msg = dbus_connection_send_with_reply_and_block(g_conn, msg, g_waiting_time, &err);
- dbus_message_unref(msg);
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_IS_TYPE_SUPPORTED))
+ sttd_dbus_server_is_recognition_type_supported(g_conn_listener, msg);
- 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_STTD, "[Dbus] Get arguments error (%s)\n", err.message);
- dbus_error_free(&err);
- result = -1;
- }
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_SET_START_SOUND))
+ sttd_dbus_server_set_start_sound(g_conn_listener, msg);
- dbus_message_unref(result_msg);
- } else {
- SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Result message is NULL. Client is not available");
- }
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_UNSET_START_SOUND))
+ sttd_dbus_server_unset_start_sound(g_conn_listener, msg);
- return result;
-}
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_SET_STOP_SOUND))
+ sttd_dbus_server_set_stop_sound(g_conn_listener, msg);
-static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
-{
- DBusConnection* conn = (DBusConnection*)data;
- DBusMessage* msg = NULL;
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_UNSET_STOP_SOUND))
+ sttd_dbus_server_unset_stop_sound(g_conn_listener, msg);
- if (NULL == conn)
- return ECORE_CALLBACK_RENEW;
- dbus_connection_read_write_dispatch(conn, 50);
-
- msg = dbus_connection_pop_message(conn);
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_START))
+ sttd_dbus_server_start(g_conn_listener, msg);
- /* loop again if we haven't read a message */
- if (NULL == msg || NULL == conn) {
- return ECORE_CALLBACK_RENEW;
- }
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_STOP))
+ sttd_dbus_server_stop(g_conn_listener, msg);
- /* client event */
- if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_HELLO))
- sttd_dbus_server_hello(conn, msg);
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_CANCEL))
+ sttd_dbus_server_cancel(g_conn_listener, msg);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_INITIALIZE))
- sttd_dbus_server_initialize(conn, msg);
-
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_FINALIZE))
- sttd_dbus_server_finalize(conn, msg);
-
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_GET_SUPPORT_LANGS))
- sttd_dbus_server_get_support_lang(conn, msg);
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_START_FILE))
+ sttd_dbus_server_start_file(g_conn_listener, msg);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_GET_CURRENT_LANG))
- sttd_dbus_server_get_default_lang(conn, msg);
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_CANCEL_FILE))
+ sttd_dbus_server_cancel_file(g_conn_listener, msg);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_IS_PARTIAL_SUPPORTED))
- sttd_dbus_server_is_partial_result_supported(conn, msg);
+ /* free the message */
+ dbus_message_unref(msg);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_START))
- sttd_dbus_server_start(conn, msg);
-
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_STOP))
- sttd_dbus_server_stop(conn, msg);
+ return ECORE_CALLBACK_RENEW;
+}
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_CANCEL))
- sttd_dbus_server_cancel(conn, msg);
+void __sttd_dbus_service_free()
+{
+ if (NULL != g_server_service_name) {
+ free(g_server_service_name);
+ g_server_service_name = NULL;
+ }
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_START_FILE_RECONITION))
- sttd_dbus_server_start_file_recognition(conn, msg);
+ if (NULL != g_server_service_object) {
+ free(g_server_service_object);
+ g_server_service_object = NULL;
+ }
- /* setting event */
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_HELLO))
- sttd_dbus_server_hello(conn, msg);
+ if (NULL != g_server_service_interface) {
+ free(g_server_service_interface);
+ g_server_service_interface = NULL;
+ }
+}
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_INITIALIZE))
- sttd_dbus_server_setting_initialize(conn, msg);
+void __sttd_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;
+ }
+ if (NULL != g_conn_custom) {
+ dbus_connection_close(g_conn_custom);
+ g_conn_custom = NULL;
+ }
+}
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_FINALIZE))
- sttd_dbus_server_setting_finalize(conn, msg);
+int __sttd_get_buxtonkey()
+{
+ /* request our name on the bus and check for errors */
+ int pid = getpid();
+ char engine_appid[2048] = {0, };
+ const char* engine_default = NULL;
+
+ struct buxton_client * bux_cli;
+ struct buxton_layer * bux_layer;
+ struct buxton_value * bux_val;
+
+ int ret = buxton_open(&bux_cli, NULL, NULL);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[DBUS-BUXTON2] Fail to open buxton client, ret(%d)", ret);
+ return STTD_ERROR_OPERATION_FAILED;
+ }
+ bux_layer = buxton_create_layer("system");
+ if (NULL == bux_layer) {
+ SLOG(LOG_ERROR, TAG_STTD, "[DBUS-BUXTON2] buxton_create_layer FAIL");
+ buxton_close(bux_cli);
+ bux_cli = NULL;
+ return STTD_ERROR_OPERATION_FAILED;
+ }
+ bux_val = buxton_value_create_string("stt-engine-default");
+ if (NULL == bux_val) {
+ SLOG(LOG_ERROR, TAG_STTD, "[DBUS-BUXTON2] buxton_value_create_string FAIL");
+ buxton_free_layer(bux_layer);
+ buxton_close(bux_cli);
+ bux_layer = NULL;
+ bux_cli = NULL;
+ return STTD_ERROR_OPERATION_FAILED;
+ } else {
+ SLOG(LOG_DEBUG, TAG_STTD, "[DBUS-BUXTON2] layer: %s", buxton_layer_get_name(bux_layer));
+ }
+ ret = buxton_get_value_sync(bux_cli, bux_layer, STT_ENGINE_DB_DEFAULT, &bux_val);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[DBUS-BUXTON2] Fail to get value sync, ret(%d)", ret);
+ buxton_value_free(bux_val);
+ buxton_free_layer(bux_layer);
+ buxton_close(bux_cli);
+
+ bux_cli = NULL;
+ bux_layer = NULL;
+ bux_val = NULL;
+ return STTD_ERROR_OPERATION_FAILED;
+ }
+ ret = buxton_value_get_string(bux_val, &engine_default);
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[DBUS-BUXTON2] Fail to get value string, ret(%d)", ret);
+ buxton_value_free(bux_val);
+ buxton_free_layer(bux_layer);
+ buxton_close(bux_cli);
+
+ bux_cli = NULL;
+ bux_layer = NULL;
+ bux_val = NULL;
+ return STTD_ERROR_OPERATION_FAILED;
+ }
+ SLOG(LOG_DEBUG, TAG_STTD, "[DBUS-BUXTON2] buxton_value_get_string: engine_default: %s", engine_default);
+
+ ret = aul_app_get_appid_bypid(pid, engine_appid, sizeof(engine_appid));
+
+ __sttd_dbus_service_free();
+
+ if (NULL == engine_default || 0 == strncmp(engine_appid, engine_default, strlen(engine_appid))) {
+ g_server_service_name = (char*)calloc(strlen(STT_SERVER_SERVICE_NAME) + 1, sizeof(char));
+ if (g_server_service_name)
+ snprintf(g_server_service_name, strlen(STT_SERVER_SERVICE_NAME) + 1, "%s", STT_SERVER_SERVICE_NAME);
+ g_server_service_object = (char*)calloc(strlen(STT_SERVER_SERVICE_OBJECT_PATH) + 1, sizeof(char));
+ if (g_server_service_object)
+ snprintf(g_server_service_object, strlen(STT_SERVER_SERVICE_OBJECT_PATH) + 1, "%s", STT_SERVER_SERVICE_OBJECT_PATH);
+ g_server_service_interface = (char*)calloc(strlen(STT_SERVER_SERVICE_INTERFACE) + 1, sizeof(char));
+ if (g_server_service_interface)
+ snprintf(g_server_service_interface, strlen(STT_SERVER_SERVICE_INTERFACE) + 1, "%s", STT_SERVER_SERVICE_INTERFACE);
+ } else {
+ g_server_service_name = (char*)calloc(strlen(STT_SERVER_SERVICE_NAME) + strlen(engine_appid) - 8, sizeof(char));
+ if (g_server_service_name)
+ snprintf(g_server_service_name, strlen(STT_SERVER_SERVICE_NAME) + strlen(engine_appid) - 8, "%s%s%s", STT_SERVER_SERVICE_NAME, ".", (engine_appid + 10));
+ g_server_service_object = (char*)calloc(strlen(STT_SERVER_SERVICE_OBJECT_PATH) + strlen(engine_appid) - 8, sizeof(char));
+ if (g_server_service_object)
+ snprintf(g_server_service_object, strlen(STT_SERVER_SERVICE_OBJECT_PATH) + strlen(engine_appid) - 8, "%s%s%s", STT_SERVER_SERVICE_OBJECT_PATH, "/", (engine_appid + 10));
+ g_server_service_interface = (char*)calloc(strlen(STT_SERVER_SERVICE_INTERFACE) + strlen(engine_appid) - 8, sizeof(char));
+ if (g_server_service_interface)
+ snprintf(g_server_service_interface, strlen(STT_SERVER_SERVICE_INTERFACE) + strlen(engine_appid) - 8, "%s%s%s", STT_SERVER_SERVICE_INTERFACE, ".", (engine_appid + 10));
+ }
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_GET_ENGINE_LIST))
- sttd_dbus_server_setting_get_engine_list(conn, msg);
+ if (NULL == g_server_service_name || NULL == g_server_service_object || NULL == g_server_service_interface) {
+ SLOG(LOG_ERROR, TAG_STTD, "[ERROR] dbus info invalid");
+ buxton_value_free(bux_val);
+ buxton_free_layer(bux_layer);
+ buxton_close(bux_cli);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_GET_ENGINE))
- sttd_dbus_server_setting_get_engine(conn, msg);
+ bux_cli = NULL;
+ bux_layer = NULL;
+ bux_val = NULL;
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_SET_ENGINE))
- sttd_dbus_server_setting_set_engine(conn, msg);
+ __sttd_dbus_service_free();
+ return STTD_ERROR_OPERATION_FAILED;
+ }
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_GET_LANG_LIST))
- sttd_dbus_server_setting_get_language_list(conn, msg);
+ char* ret_char = strchr(g_server_service_interface, '-');
+ while (NULL != ret_char) {
+ ret_char[0] = '_';
+ ret_char = strchr(g_server_service_interface, '-');
+ }
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_GET_DEFAULT_LANG))
- sttd_dbus_server_setting_get_default_language(conn, msg);
+ SLOG(LOG_DEBUG, TAG_STTD, "[get_service_interface] service interface: %s", g_server_service_interface);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_SET_DEFAULT_LANG))
- sttd_dbus_server_setting_set_default_language(conn, msg);
+ buxton_value_free(bux_val);
+ buxton_free_layer(bux_layer);
+ buxton_close(bux_cli);
+ bux_cli = NULL;
+ bux_layer = NULL;
+ bux_val = NULL;
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_GET_PROFANITY))
- sttd_dbus_server_setting_get_profanity_filter(conn, msg);
+ SLOG(LOG_DEBUG, TAG_STTD, "[get_service_name] FINISH!! service name: %s", g_server_service_name);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_SET_PROFANITY))
- sttd_dbus_server_setting_set_profanity_filter(conn, msg);
+ return STTD_ERROR_NONE;
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_GET_PUNCTUATION))
- sttd_dbus_server_setting_get_punctuation_override(conn, msg);
+}
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_SET_PUNCTUATION))
- sttd_dbus_server_setting_set_punctuation_override(conn, msg);
+int __sttd_request_custom_dbus_name()
+{
+ DBusError err;
+ dbus_error_init(&err);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_GET_SILENCE))
- sttd_dbus_server_setting_get_silence_detection(conn, msg);
+ /* Create connection for sender */
+ g_conn_custom = dbus_bus_get_private(DBUS_BUS_SESSION, &err);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail dbus_bus_get : %s", err.message);
+ dbus_error_free(&err);
+ __sttd_dbus_connection_free();
+ return STTD_ERROR_OPERATION_FAILED;
+ }
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_SET_SILENCE))
- sttd_dbus_server_setting_set_silence_detection(conn, msg);
+ if (NULL == g_conn_custom) {
+ SLOG(LOG_ERROR, TAG_STTD, "[ERROR] fail to get dbus connection");
+ return STTD_ERROR_OPERATION_FAILED;
+ }
+ dbus_connection_set_exit_on_disconnect(g_conn_custom, false);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_GET_ENGINE_SETTING))
- sttd_dbus_server_setting_get_engine_setting(conn, msg);
+ int ret = dbus_bus_request_name(g_conn_custom, STT_SERVER_CUSTOM_SERVICE_NAME, DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
+ if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to be primary owner");
+ __sttd_dbus_connection_free();
+ return STTD_ERROR_OPERATION_FAILED;
+ }
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_SETTING_METHOD_SET_ENGINE_SETTING))
- sttd_dbus_server_setting_set_engine_setting(conn, msg);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] dbus_bus_request_name() : %s", err.message);
+ dbus_error_free(&err);
+ __sttd_dbus_connection_free();
+ return STTD_ERROR_OPERATION_FAILED;
+ }
+ dbus_bus_release_name(g_conn_custom, STT_SERVER_CUSTOM_SERVICE_NAME, &err);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] dbus_bus_release_name() : %s", err.message);
+ dbus_error_free(&err);
+ __sttd_dbus_connection_free();
+ return STTD_ERROR_OPERATION_FAILED;
+ }
- /* free the message */
- dbus_message_unref(msg);
+ dbus_connection_close(g_conn_custom);
+ g_conn_custom = NULL;
- return ECORE_CALLBACK_RENEW;
+ SLOG(LOG_DEBUG, TAG_STTD, "==");
+ return 0;
}
int sttd_dbus_open_connection()
int ret;
+ /* Create connection for sender */
+ g_conn_sender = dbus_bus_get_private(DBUS_BUS_SESSION, &err);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail dbus_bus_get : %s", err.message);
+ dbus_error_free(&err);
+ }
+
+ if (NULL == g_conn_sender) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to get dbus connection sender");
+ return STTD_ERROR_OPERATION_FAILED;
+ }
+
+ dbus_connection_set_exit_on_disconnect(g_conn_sender, false);
+
/* connect to the bus and check for errors */
- g_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+ g_conn_listener = dbus_bus_get_private(DBUS_BUS_SESSION, &err);
- if (dbus_error_is_set(&err)) {
+ if (dbus_error_is_set(&err)) {
SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail dbus_bus_get : %s", err.message);
- dbus_error_free(&err);
+ dbus_error_free(&err);
}
- if (NULL == g_conn) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to get dbus connection" );
- return -1;
+ if (NULL == g_conn_listener) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to get dbus connection");
+ __sttd_dbus_connection_free();
+ return STTD_ERROR_OPERATION_FAILED;
}
- /* request our name on the bus and check for errors */
- ret = dbus_bus_request_name(g_conn, STT_SERVER_SERVICE_NAME, DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
+ dbus_connection_set_exit_on_disconnect(g_conn_listener, false);
+
+ /* Get buxton key */
+ ret = __sttd_get_buxtonkey();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to get buxton key");
+ __sttd_dbus_service_free();
+ __sttd_dbus_connection_free();
+ return ret;
+ }
+
+ ret = __sttd_request_custom_dbus_name();
+ if (0 != ret) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to request custom dbus name");
+ __sttd_dbus_service_free();
+ __sttd_dbus_connection_free();
+ return ret;
+ }
+
+ ret = dbus_bus_request_name(g_conn_listener, g_server_service_name, DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
- printf("Fail to be primary owner in dbus request.");
SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to be primary owner");
- return -1;
+ __sttd_dbus_service_free();
+ __sttd_dbus_connection_free();
+ return STTD_ERROR_OPERATION_FAILED;
}
- if (dbus_error_is_set(&err)) {
+ if (dbus_error_is_set(&err)) {
SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] dbus_bus_request_name() : %s", err.message);
- dbus_error_free(&err);
- return -1;
+ dbus_error_free(&err);
+ __sttd_dbus_service_free();
+ __sttd_dbus_connection_free();
+ return STTD_ERROR_OPERATION_FAILED;
}
/* add a rule for getting signal */
char rule[128];
- snprintf(rule, 128, "type='signal',interface='%s'", STT_SERVER_SERVICE_INTERFACE);
+ snprintf(rule, 128, "type='signal',interface='%s'", g_server_service_interface);
/* add a rule for which messages we want to see */
- dbus_bus_add_match(g_conn, rule, &err); /* see signals from the given interface */
- dbus_connection_flush(g_conn);
+ dbus_bus_add_match(g_conn_listener, rule, &err); /* see signals from the given interface */
+ dbus_connection_flush(g_conn_listener);
- if (dbus_error_is_set(&err)) {
+ if (dbus_error_is_set(&err)) {
SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] dbus_bus_add_match() : %s", err.message);
- return -1;
+ dbus_error_free(&err);
+ __sttd_dbus_service_free();
+ __sttd_dbus_connection_free();
+ return STTD_ERROR_OPERATION_FAILED;
}
int fd = 0;
- dbus_connection_get_unix_fd(g_conn, &fd);
-
- if (!ecore_init()) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] ecore_init()");
- return -1;
- }
+ dbus_connection_get_unix_fd(g_conn_listener, &fd);
- Ecore_Fd_Handler* fd_handler;
- fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ , (Ecore_Fd_Cb)listener_event_callback, g_conn, NULL, NULL);
-
- if (NULL == fd_handler) {
+ g_dbus_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_dbus_fd_handler) {
SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to get fd handler");
- return -1;
+ __sttd_dbus_service_free();
+ __sttd_dbus_connection_free();
+ return STTD_ERROR_OPERATION_FAILED;
}
return 0;
DBusError err;
dbus_error_init(&err);
- dbus_bus_release_name (g_conn, STT_SERVER_SERVICE_NAME, &err);
+ if (NULL != g_dbus_fd_handler) {
+ ecore_main_fd_handler_del(g_dbus_fd_handler);
+ g_dbus_fd_handler = NULL;
+ }
- if (dbus_error_is_set(&err)) {
- SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] dbus_bus_release_name() : %s", err.message);
- dbus_error_free(&err);
- return -1;
+ if (NULL != g_conn_listener) {
+ dbus_bus_release_name(g_conn_listener, g_server_service_name, &err);
+ if (dbus_error_is_set(&err)) {
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] dbus_bus_release_name() : %s", err.message);
+ dbus_error_free(&err);
+ }
}
+ __sttd_dbus_connection_free();
+ __sttd_dbus_service_free();
+
+ SLOG(LOG_DEBUG, TAG_STTD, "[Server] Close dbus connection");
+
return 0;
}