Add internal API for setting assistant language 04/217704/2
authorJi-hoon Lee <dalton.lee@samsung.com>
Wed, 13 Nov 2019 10:32:37 +0000 (19:32 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Wed, 13 Nov 2019 10:33:21 +0000 (19:33 +0900)
Change-Id: Ib6df74773133616884fd98a79cd61f5cb85de1ee

client/ma.c
client/ma_dbus.c
client/ma_dbus.h
common/ma_defs.h
include/CMakeLists.txt
include/multi_assistant_internal.h [new file with mode: 0644]
packaging/multi-assistant.spec

index c4aa5d51805addd01226bff42f63f1f978cca363..ecb6c4b7744286b80ea9c8613d22d72dece27736 100644 (file)
@@ -2011,4 +2011,38 @@ int ma_unset_preprocessing_result_received_cb(void)
 
        return MA_ERROR_NONE;
 }
-//LCOV_EXCL_STOP
+
+int ma_set_assistant_language(const char* language)
+{
+       SLOG(LOG_DEBUG, TAG_MAC, "[Manager] Set assistant language");
+
+       if (0 != __ma_get_feature_enabled()) {
+               SLOG(LOG_DEBUG, TAG_MAC, "@@@ [Manager] not supported");
+               return MA_ERROR_NOT_SUPPORTED;
+       }
+
+       ma_state_e state;
+       if (0 != ma_client_get_client_state(g_ma, &state)) {
+               SLOG(LOG_ERROR, TAG_MAC, "[ERROR] A handle is not available");
+               SLOG(LOG_DEBUG, TAG_MAC, "@@@");
+               return MA_ERROR_INVALID_STATE;
+       }
+
+       if (state != MA_STATE_READY) {
+               SLOG(LOG_ERROR, TAG_MAC, "[ERROR] Invalid State: Current state is not 'READY', state(%d)", state);
+               SLOG(LOG_DEBUG, TAG_MAC, "@@@");
+               return MA_ERROR_INVALID_STATE;
+       }
+
+       /* Set assistant language */
+       int pid = getpid();
+       int ret = ma_dbus_set_assistant_language(pid, language);
+       if (0 != ret) {
+               SLOG(LOG_WARN, TAG_MAC, "[WARNING] Failed to set assistant language");
+       } else {
+               SLOG(LOG_DEBUG, TAG_MAC, "[DEBUG] Success to set");
+       }
+       return ret;
+}
+
+//LCOV_EXCL_STOP
\ No newline at end of file
index 7df74c9f3d82a8a5f17eed8daae8c3fbe3da0deb..b4af77a2448aa30fbc9950df9a25f18243064381 100644 (file)
@@ -1391,3 +1391,67 @@ int ma_dbus_set_wake_word_audio_require_flag(int pid, bool require)
 
        return 0;
 }
+
+int ma_dbus_set_assistant_language(int pid, const char* language)
+{
+       if (0 != __dbus_check()) {
+               return MA_ERROR_OPERATION_FAILED;
+       }
+
+       DBusMessage* msg;
+
+       msg = dbus_message_new_method_call(
+                         MA_SERVER_SERVICE_NAME,
+                         MA_SERVER_SERVICE_OBJECT_PATH,
+                         MA_SERVER_SERVICE_INTERFACE,
+                         MA_METHOD_SET_ASSISTANT_LANGUAGE);
+
+       if (NULL == msg) {
+               SLOG(LOG_ERROR, TAG_MAC, "@@ Request multi-assistant set assistant language : Fail to make message"); //LCOV_EXCL_LINE
+               return MA_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_MAC, "[DEBUG] multi-assistant set assistant language");
+       }
+
+       char* tmp_language = NULL;
+       if (NULL != language) {
+               tmp_language = strdup(language);
+       } else {
+               tmp_language = strdup("#NULL");
+       }
+
+       dbus_message_append_args(msg,
+               DBUS_TYPE_INT32, &pid,
+               DBUS_TYPE_STRING, &tmp_language,
+               DBUS_TYPE_INVALID);
+
+       dbus_message_set_no_reply(msg, TRUE);
+
+       DBusError error;
+       dbus_error_init (&error);
+       if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
+               if (dbus_error_is_set (&error)) {
+                       SLOG(LOG_ERROR, TAG_MAC, "[Dbus ERROR] Fail to Send : %s", error.message); //LCOV_EXCL_LINE
+                       dbus_error_free (&error);
+               } else {
+                       SLOG(LOG_ERROR, TAG_MAC, "[Dbus ERROR] Fail to Send"); //LCOV_EXCL_LINE
+               }
+               if (NULL != tmp_language) {
+                       free(tmp_language);
+                       tmp_language = NULL;
+               }
+               return MA_ERROR_OPERATION_FAILED;
+       } else {
+               SLOG(LOG_DEBUG, TAG_MAC, "[Dbus DEBUG] Success to Send");
+               dbus_connection_flush(g_conn_sender);
+       }
+
+       if (NULL != tmp_language) {
+               free(tmp_language);
+               tmp_language = NULL;
+       }
+
+       dbus_message_unref(msg);
+
+       return 0;
+}
index 2e737d13ad8eb0efc98b16c5194608ec39f580af..baad62dbda7a4807dc972805aa76d692c7a6440f 100644 (file)
@@ -63,6 +63,8 @@ int ma_dbus_send_preprocessing_result(int pid, bool result);
 
 int ma_dbus_set_wake_word_audio_require_flag(int pid, bool require);
 
+int ma_dbus_set_assistant_language(int pid, const char* language);
+
 #ifdef __cplusplus
 }
 #endif
index 6b62aa40ab6e11c6bc823d3c8d91c36d123e6251..4825e990621cd36155f219b515c2543eaf872ce9 100644 (file)
@@ -81,6 +81,7 @@ extern "C"
 #define MA_METHOD_SET_PREPROCESSING_ALLOW_MODE         "ma_method_set_preprocessing_allow_mode"
 #define MA_METHOD_SEND_PREPROCESSING_RESULT                    "ma_method_send_preprocessing_result"
 #define MA_METHOD_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG     "ma_method_set_wake_word_audio_require_flag"
+#define MA_METHOD_SET_ASSISTANT_LANGUAGE                       "ma_method_set_assistant_language"
 #define MA_METHOD_ERROR                                                                "ma_method_error"
 
 #define MA_UI_METHOD_INITIALIZE                                                "ma_ui_method_initialize"
index 7d2d2099a26e40bcffaea11b239d3d0d2548d9fe..04afd82536c6247bdc0c0e33844256b2c185a057 100644 (file)
@@ -11,3 +11,4 @@ INSTALL(FILES ${CMAKE_BINARY_DIR}/include/multi_assistant.h DESTINATION ${INCLUD
 INSTALL(FILES ${CMAKE_BINARY_DIR}/include/multi_assistant_ui.h DESTINATION ${INCLUDEDIR})
 INSTALL(FILES ${CMAKE_BINARY_DIR}/include/multi_assistant_common.h DESTINATION ${INCLUDEDIR})
 INSTALL(FILES ${CMAKE_BINARY_DIR}/include/multi_assistant_settings.h DESTINATION ${INCLUDEDIR})
+INSTALL(FILES ${CMAKE_BINARY_DIR}/include/multi_assistant_internal.h DESTINATION ${INCLUDEDIR})
diff --git a/include/multi_assistant_internal.h b/include/multi_assistant_internal.h
new file mode 100644 (file)
index 0000000..0bdb93b
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2011-2019 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef __TIZEN_UIFW_MULTI_ASSISTANT_INTERNAL_H__
+#define __TIZEN_UIFW_MULTI_ASSISTANT_INTERNAL_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * @brief Sets the voice language for the current assistant.
+ * @since_tizen 5.5
+ *
+ * @param[in] language The language that will be used for the current assistant
+ *                     It should be denoted by two-letter code defined by IS 639-1,
+ *                     optionally combined with two-letter code defined by ISO 3166.
+ *                     For example, "ko_KR" for Korean, "en_US" for American English.
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #MA_ERROR_NONE Successful
+ * @retval #MA_ERROR_NOT_SUPPORTED Not supported
+ * @retval #MA_ERROR_INVALID_STATE Invalid state
+ *
+ * @pre The state should be #MA_STATE_INITIALIZED.
+ */
+int ma_set_assistant_language(const char* language);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_UIFW_MULTI_ASSISTANT_INTERNAL_H__ */
index 2ab179286fb71641fb222cea47d7d618fd0affd8..e079f5f3e4f22767d3600e2fcd18bb7a0c2ec635 100644 (file)
@@ -126,6 +126,7 @@ mkdir -p %{_libdir}/multiassistant/ma
 %{_includedir}/multi_assistant_ui.h
 %{_includedir}/multi_assistant_common.h
 %{_includedir}/multi_assistant_settings.h
+%{_includedir}/multi_assistant_internal.h
 
 %files ui-devel
 %defattr(-,root,root,-)