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;
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");
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);
}
}
+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 */
__sttd_dbus_service_free();
- if (NULL == engine_appid || NULL == engine_default || 0 == strncmp(engine_appid, engine_default, strlen(engine_appid))) {
+ 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));
- snprintf(g_server_service_name, strlen(STT_SERVER_SERVICE_NAME) + 1, "%s", STT_SERVER_SERVICE_NAME);
+ 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));
- snprintf(g_server_service_object, strlen(STT_SERVER_SERVICE_OBJECT_PATH) + 1, "%s", STT_SERVER_SERVICE_OBJECT_PATH);
+ 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));
- snprintf(g_server_service_interface, strlen(STT_SERVER_SERVICE_INTERFACE) + 1, "%s", STT_SERVER_SERVICE_INTERFACE);
+ 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));
- snprintf(g_server_service_name, strlen(STT_SERVER_SERVICE_NAME) + strlen(engine_appid) - 8, "%s%s%s", STT_SERVER_SERVICE_NAME, ".", (engine_appid + 10));
+ 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));
- 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));
+ 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));
- 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 (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) {
bux_cli = NULL;
bux_layer = NULL;
bux_val = NULL;
+
+ __sttd_dbus_service_free();
return STTD_ERROR_OPERATION_FAILED;
}
int __sttd_request_custom_dbus_name()
{
- static DBusConnection* g_conn_custom = NULL;
DBusError err;
dbus_error_init(&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;
}
- 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");
+ 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;
}
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);
- dbus_connection_unref(g_conn_custom);
g_conn_custom = NULL;
SLOG(LOG_DEBUG, TAG_STTD, "==");
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_private(DBUS_BUS_SESSION, &err);
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;
}
+ 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;
}
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;
}
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, 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);
+ 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);
+ }
}
- dbus_connection_close(g_conn_listener);
- dbus_connection_close(g_conn_sender);
-
- dbus_connection_unref(g_conn_sender);
- dbus_connection_unref(g_conn_listener);
-
- 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");