/*
-* Copyright (c) 2011-2014 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 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)
{
char service_name[64];
memset(service_name, 0, 64);
- snprintf(service_name, 64, "%s", STT_CLIENT_SERVICE_NAME);
+ 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", STT_CLIENT_SERVICE_INTERFACE);
+ snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
DBusMessage* msg = NULL;
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Send hello message : uid(%d)", uid);
+ 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) {
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);
}
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);
+ SLOG(LOG_ERROR, TAG_STTD, "[Dbus] Get arguments error (%s)", err.message);
dbus_error_free(&err);
- result = -1;
}
dbus_message_unref(result_msg);
return result;
}
-int sttdc_send_set_state(int uid, int state)
+int sttdc_send_set_volume(int uid, float volume)
{
int pid = sttd_client_get_pid(uid);
char service_name[64];
memset(service_name, 0, 64);
- snprintf(service_name, 64, "%s", STT_CLIENT_SERVICE_NAME);
+ 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", STT_CLIENT_SERVICE_INTERFACE);
+ snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
DBusMessage* msg;
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Send change state message : uid(%d), state(%d)", uid, state);
+ /* 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_SET_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");
dbus_message_append_args(msg,
DBUS_TYPE_INT32, &uid,
- DBUS_TYPE_INT32, &state,
+ DBUS_TYPE_INT32, &volume,
DBUS_TYPE_INVALID);
- dbus_message_set_no_reply(msg, TRUE);
-
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 error message : uid(%d), state(%d)", uid, state);
+ SLOG(LOG_DEBUG, TAG_STTD, "<<<< Send set volume : uid(%d), volume(%f)", uid, volume);
dbus_connection_flush(g_conn_sender);
}
- dbus_connection_flush(g_conn_sender);
dbus_message_unref(msg);
return 0;
}
-int sttdc_send_get_state(int uid, int* state)
+
+int sttdc_send_set_state(int uid, int state)
{
int pid = sttd_client_get_pid(uid);
char service_name[64];
memset(service_name, 0, 64);
- snprintf(service_name, 64, "%s", STT_CLIENT_SERVICE_NAME);
+ 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", STT_CLIENT_SERVICE_INTERFACE);
-
- DBusMessage* msg;
-
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] Send get state message : uid(%d)", uid);
+ snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
- msg = dbus_message_new_method_call(
- service_name,
- STT_CLIENT_SERVICE_OBJECT_PATH,
- target_if_name,
- STTD_METHOD_GET_STATE);
+ 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_INVALID);
-
- DBusError err;
- dbus_error_init(&err);
+ dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &uid,
+ DBUS_TYPE_INT32, &state,
+ 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 change state message : Out Of Memory !");
+ } else {
+ SLOG(LOG_DEBUG, TAG_STTD, "<<<< Send change state message : uid(%d), state(%d)", uid, state);
+ dbus_connection_flush(g_conn_sender);
+ }
- 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);
- dbus_error_free(&err);
+
+ return 0;
+}
+
+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");
+ return -1;
}
- if (NULL != result_msg) {
- dbus_message_get_args(result_msg, &err, DBUS_TYPE_INT32, &tmp, DBUS_TYPE_INVALID);
+ char service_name[64];
+ memset(service_name, 0, 64);
+ snprintf(service_name, 64, "%s%d", STT_CLIENT_SERVICE_NAME, pid);
- 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;
- }
+ char target_if_name[128];
+ snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
- dbus_message_unref(result_msg);
+ 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");
+ 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_ERROR, TAG_STTD, "[Dbus] Result message is NULL. Client is not available");
- result = -1;
+ SLOG(LOG_DEBUG, TAG_STTD, "<<<< Send speech status message : uid(%d), status(%d)", uid, status);
+ dbus_connection_flush(g_conn_sender);
}
- return result;
+ dbus_message_unref(msg);
+
+ return 0;
}
int sttdc_send_result(int uid, int event, const char** data, int data_count, const char* result_msg)
char service_name[64];
memset(service_name, 0, 64);
- snprintf(service_name, 64, "%s", STT_CLIENT_SERVICE_NAME);
+ 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", STT_CLIENT_SERVICE_INTERFACE);
+ 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)", uid, event, data_count);
+ 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_method_call(
- service_name,
- STT_CLIENT_SERVICE_OBJECT_PATH,
- target_if_name,
- STTD_METHOD_RESULT);
+ 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");
/* 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");
+ dbus_message_unref(msg);
+ return -1;
+ }
+
+ 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;
+ }
+
int i;
- SECURE_SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] result size (%d)", data_count);
+ SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] result size (%d)", data_count);
for (i = 0; i < data_count; i++) {
if (NULL != data[i]) {
- SECURE_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");
}
}
- dbus_message_set_no_reply(msg, TRUE);
-
if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to send message : Out Of Memory !");
}
int sttdc_send_error_signal(int uid, int reason, const char *err_msg)
{
- 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");
char service_name[64];
memset(service_name, 0, 64);
- snprintf(service_name, 64, "%s", STT_CLIENT_SERVICE_NAME);
+ 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", STT_CLIENT_SERVICE_INTERFACE);
+ snprintf(target_if_name, sizeof(target_if_name), "%s%d", STT_CLIENT_SERVICE_INTERFACE, pid);
DBusMessage* msg = NULL;
- msg = dbus_message_new_method_call(
- service_name,
- STT_CLIENT_SERVICE_OBJECT_PATH,
- target_if_name,
- STTD_METHOD_ERROR);
+ 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 STTD_ERROR_OUT_OF_MEMORY;
}
- dbus_message_append_args(msg,
- DBUS_TYPE_INT32, &uid,
- DBUS_TYPE_INT32, &reason,
+ dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &uid,
+ DBUS_TYPE_INT32, &reason,
DBUS_TYPE_STRING, &err_msg,
DBUS_TYPE_INVALID);
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, err_msg);
+ 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);
}
static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
{
+ SLOG(LOG_DEBUG, TAG_STTD, "[Dbus] listener_event_callback is called!!!");
+
if (NULL == g_conn_listener) return ECORE_CALLBACK_RENEW;
dbus_connection_read_write_dispatch(g_conn_listener, 50);
return ECORE_CALLBACK_RENEW;
}
+ 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);
+
/* client event */
- if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_HELLO))
+ if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_HELLO))
sttd_dbus_server_hello(g_conn_listener, msg);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_INITIALIZE))
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_INITIALIZE))
sttd_dbus_server_initialize(g_conn_listener, msg);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_FINALIZE))
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_FINALIZE))
sttd_dbus_server_finalize(g_conn_listener, msg);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_SET_CURRENT_ENGINE))
+ 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);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_CHECK_APP_AGREED))
+ 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);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_GET_SUPPORT_LANGS))
+ 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);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_GET_CURRENT_LANG))
+ 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);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_IS_TYPE_SUPPORTED))
+ 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);
+
+ 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);
+
+ 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);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_SET_START_SOUND))
+ 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);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_UNSET_START_SOUND))
+ 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);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_SET_STOP_SOUND))
+ 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);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_UNSET_STOP_SOUND))
+ 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);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_START))
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_START))
sttd_dbus_server_start(g_conn_listener, msg);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_STOP))
+ else if (dbus_message_is_method_call(msg, g_server_service_interface, STT_METHOD_STOP))
sttd_dbus_server_stop(g_conn_listener, msg);
- else if (dbus_message_is_method_call(msg, STT_SERVER_SERVICE_INTERFACE, STT_METHOD_CANCEL))
+ 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, 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, g_server_service_interface, STT_METHOD_CANCEL_FILE))
+ sttd_dbus_server_cancel_file(g_conn_listener, msg);
/* free the message */
dbus_message_unref(msg);
return ECORE_CALLBACK_RENEW;
}
+void __sttd_dbus_service_free()
+{
+ if (NULL != g_server_service_name) {
+ free(g_server_service_name);
+ g_server_service_name = NULL;
+ }
+
+ if (NULL != g_server_service_object) {
+ free(g_server_service_object);
+ g_server_service_object = NULL;
+ }
+
+ if (NULL != g_server_service_interface) {
+ free(g_server_service_interface);
+ g_server_service_interface = NULL;
+ }
+}
+
+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;
+ }
+}
+
+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));
+ }
+
+ 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);
+
+ bux_cli = NULL;
+ bux_layer = NULL;
+ bux_val = NULL;
+
+ __sttd_dbus_service_free();
+ return STTD_ERROR_OPERATION_FAILED;
+ }
+
+ char* ret_char = strchr(g_server_service_interface, '-');
+ while (NULL != ret_char) {
+ ret_char[0] = '_';
+ ret_char = strchr(g_server_service_interface, '-');
+ }
+
+ SLOG(LOG_DEBUG, TAG_STTD, "[get_service_interface] service interface: %s", g_server_service_interface);
+
+ buxton_value_free(bux_val);
+ buxton_free_layer(bux_layer);
+ buxton_close(bux_cli);
+
+ bux_cli = NULL;
+ bux_layer = NULL;
+ bux_val = NULL;
+
+ SLOG(LOG_DEBUG, TAG_STTD, "[get_service_name] FINISH!! service name: %s", g_server_service_name);
+
+ return STTD_ERROR_NONE;
+
+}
+
+int __sttd_request_custom_dbus_name()
+{
+ DBusError err;
+ dbus_error_init(&err);
+
+ /* 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;
+ }
+
+ 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);
+
+ 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;
+ }
+
+ 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;
+ }
+
+ dbus_connection_close(g_conn_custom);
+ g_conn_custom = NULL;
+
+ SLOG(LOG_DEBUG, TAG_STTD, "==");
+ return 0;
+}
+
int sttd_dbus_open_connection()
{
DBusError err;
int ret;
/* Create connection for sender */
- g_conn_sender = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+ 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);
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_listener = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+ g_conn_listener = 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);
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_listener, 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) {
SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to be primary owner");
+ __sttd_dbus_service_free();
+ __sttd_dbus_connection_free();
return STTD_ERROR_OPERATION_FAILED;
}
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_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_listener, rule, &err); /* see signals from the given interface */
if (dbus_error_is_set(&err)) {
SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] dbus_bus_add_match() : %s", err.message);
+ dbus_error_free(&err);
+ __sttd_dbus_service_free();
+ __sttd_dbus_connection_free();
return STTD_ERROR_OPERATION_FAILED;
}
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");
+ __sttd_dbus_service_free();
+ __sttd_dbus_connection_free();
return STTD_ERROR_OPERATION_FAILED;
}
g_dbus_fd_handler = NULL;
}
- dbus_bus_release_name(g_conn_listener, STT_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);
+ 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);
+ }
}
- g_conn_listener = NULL;
- g_conn_sender = NULL;
+ __sttd_dbus_connection_free();
+ __sttd_dbus_service_free();
+
+ SLOG(LOG_DEBUG, TAG_STTD, "[Server] Close dbus connection");
return 0;
}