Merge "remove duplicated codes" into tizen
[platform/core/uifw/stt.git] / server / sttd_dbus.c
index eb24920..1bfcc03 100644 (file)
@@ -197,6 +197,50 @@ int sttdc_send_set_state(int uid, int state)
        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;
+       }
+
+       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_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_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);
@@ -548,7 +592,7 @@ int __sttd_get_buxtonkey()
        }
 
        char* ret_char = strchr(g_server_service_interface, '-');
-       while(NULL != ret_char) {
+       while (NULL != ret_char) {
                ret_char[0] = '_';
                ret_char = strchr(g_server_service_interface, '-');
        }
@@ -589,11 +633,6 @@ int __sttd_request_custom_dbus_name()
                return STTD_ERROR_OPERATION_FAILED;
        }
 
-       if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
-               SLOG(LOG_ERROR, TAG_STTD, "[Dbus ERROR] Fail to be primary owner");
-               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);