From 8468af04958c5245d7cded590a74385a791eacbd Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Wed, 13 Nov 2019 19:32:37 +0900 Subject: [PATCH] Add internal API for setting assistant language Change-Id: Ib6df74773133616884fd98a79cd61f5cb85de1ee --- client/ma.c | 36 ++++++++++++++++- client/ma_dbus.c | 64 ++++++++++++++++++++++++++++++ client/ma_dbus.h | 2 + common/ma_defs.h | 1 + include/CMakeLists.txt | 1 + include/multi_assistant_internal.h | 48 ++++++++++++++++++++++ packaging/multi-assistant.spec | 1 + 7 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 include/multi_assistant_internal.h diff --git a/client/ma.c b/client/ma.c index c4aa5d5..ecb6c4b 100644 --- a/client/ma.c +++ b/client/ma.c @@ -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 diff --git a/client/ma_dbus.c b/client/ma_dbus.c index 7df74c9..b4af77a 100644 --- a/client/ma_dbus.c +++ b/client/ma_dbus.c @@ -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; +} diff --git a/client/ma_dbus.h b/client/ma_dbus.h index 2e737d1..baad62d 100644 --- a/client/ma_dbus.h +++ b/client/ma_dbus.h @@ -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 diff --git a/common/ma_defs.h b/common/ma_defs.h index 6b62aa4..4825e99 100644 --- a/common/ma_defs.h +++ b/common/ma_defs.h @@ -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" diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 7d2d209..04afd82 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -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 index 0000000..0bdb93b --- /dev/null +++ b/include/multi_assistant_internal.h @@ -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__ */ diff --git a/packaging/multi-assistant.spec b/packaging/multi-assistant.spec index 2ab1792..e079f5f 100644 --- a/packaging/multi-assistant.spec +++ b/packaging/multi-assistant.spec @@ -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,-) -- 2.34.1