SET(SRCS
src/main.cpp
- src/multi_assistant_config.cpp
- src/multi_assistant_service.cpp
- src/multi_assistant_service_plugin.cpp
- src/multi_assistant_dbus.cpp
- src/multi_assistant_dbus_server.cpp
+ src/service_config.cpp
+ src/service_main.cpp
+ src/service_plugin.cpp
+ src/service_ipc_dbus.cpp
+ src/service_ipc_dbus_dispatcher.cpp
)
ADD_EXECUTABLE(${BINNAME} ${SRCS})
+++ /dev/null
-/*
- * Copyright 2018-2019 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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 __MULTI_ASSISTANT_CONFIG_H__
-#define __MULTI_ASSISTANT_CONFIG_H__
-
-#include <tizen.h>
-#include <tzplatform_config.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#define MAX_WAKEUP_LIST_NUM 32
-#define MAX_SUPPORTED_LANGUAGE_NUM 128
-
-/**************************************************************************************
- *** Definitions for xml file
- *************************************************************************************/
-#define MA_TAG_ASSISTANT_BASE "multi-assistant"
-#define MA_TAG_ASSISTANT_NAME "name"
-#define MA_TAG_ASSISTANT_APPID "appid"
-#define MA_TAG_ASSISTANT_ICON_PATH "icon-path"
-#define MA_TAG_ASSISTANT_LANGUAGE_SET "languages"
-#define MA_TAG_ASSISTANT_LANGUAGE "language"
-#define MA_TAG_ASSISTANT_WAKEUP_WORD_SET "wakeup-words"
-#define MA_TAG_ASSISTANT_WAKEUP_WORD "wakeup-word"
-#define MA_TAG_ASSISTANT_WAKEUP_ENGINE_APPID "wakeup-engine-appid"
-#define MA_TAG_ASSISTANT_CUSTOM_UI "custom-ui"
-#define MA_TAG_ASSISTANT_VOICE_KEY_SUPPORT_MODE "voice-key-support-mode"
-#define MA_TAG_ASSISTANT_VOICE_KEY_TAP_DURATION "voice-key-tap-duration"
-
-/**************************************************************************************
- *** Definitions for ETC
- *************************************************************************************/
-#define MA_RETRY_COUNT 5
-
-#define MA_ASSISTANT_INFO tzplatform_mkpath(TZ_USER_HOME, "share/.multiassistant/ma/1.0/assistant-info")
-
-#define VOICE_KEY_SUPPORT_MODE_STRING_NONE "none"
-#define VOICE_KEY_SUPPORT_MODE_STRING_PUSH_TO_TALK "push_to_talk"
-#define VOICE_KEY_SUPPORT_MODE_STRING_TAP_TO_TALK "tap_to_talk"
-#define VOICE_KEY_SUPPORT_MODE_STRING_ALL "all"
-
-#define MAX_WAKEUP_WORDS_NUM 255
-#define MAX_WAKEUP_WORD_LEN 32
-#define MAX_SUPPORTED_LANGUAGES_NUM 255
-#define MAX_SUPPORTED_LANGUAGE_LEN 16
-
-typedef enum {
- VOICE_KEY_SUPPORT_MODE_NONE,
- VOICE_KEY_SUPPORT_MODE_PUSH_TO_TALK,
- VOICE_KEY_SUPPORT_MODE_TAP_TO_TALK,
- VOICE_KEY_SUPPORT_MODE_ALL,
-} VOICE_KEY_SUPPORT_MODE;
-
-typedef struct {
- const char* app_id;
- const char* name;
- const char* icon_path;
- const char* wakeup_list[MAX_WAKEUP_LIST_NUM];
- const char* wakeup_language[MAX_WAKEUP_LIST_NUM];
- int cnt_wakeup;
- const char* supported_lang[MAX_SUPPORTED_LANGUAGE_NUM];
- int cnt_lang;
- const char* wakeup_engine;
- bool custom_ui_option;
- VOICE_KEY_SUPPORT_MODE voice_key_support_mode;
- float voice_key_tap_duration;
-} ma_assistant_info_s;
-
-typedef int (*mas_config_assistant_info_cb)(ma_assistant_info_s* info, void* user_data);
-
-class CConfig {
-public:
- CConfig() {};
- virtual ~CConfig() {};
-
- int mas_config_get_assistant_info(mas_config_assistant_info_cb callback, void* user_data);
-
- int mas_config_add_custom_wake_word(const char* wake_word, const char* language,
- char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
- char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]);
- int mas_config_remove_custom_wake_word(const char* wake_word, const char* language,
- char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
- char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]);
- int mas_config_load_custom_wake_words(const char* app_id,
- char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
- char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]);
- int mas_config_save_custom_wake_words(const char* app_id,
- char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
- char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]);
- int mas_config_get_custom_wake_word_num(
- char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
- char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]);
- bool mas_config_has_custom_wake_word(const char* wake_word, const char* language,
- char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
- char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]);
-private:
- int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback,
- const char *path, void* user_data);
-};
-
-#ifdef __cplusplus
-}
-#endif
-
-/**
- * @}
- */
-
-#endif /* __MULTI_ASSISTANT_CONFIG_H__ */
+++ /dev/null
-#ifndef __MULTI_ASSISTANT_SERVICE_H__
-#define __MULTI_ASSISTANT_SERVICE_H__
-
-#include <app.h>
-#include <glib.h>
-#include "multi_wakeup_recognizer.h"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "multi-assistant"
-
-#define MAS_SECURE_LOG_(id, prio, tag, fmt, arg...) \
- ({ do { \
- __dlog_print(id, prio, tag, "%s: %s(%d) > [SECURE_LOG] " fmt, __MODULE__, __func__, __LINE__, ##arg); \
- } while (0); })
-
-#define MAS_LOG_(prio, tag, fmt, arg...) \
- ({ do { \
- dlog_print(prio, tag, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg); \
- } while (0); })
-
-#define MAS_LOGD(fmt, args...) MAS_LOG_(DLOG_DEBUG, LOG_TAG, fmt, ##args)
-#define MAS_LOGI(fmt, args...) MAS_LOG_(DLOG_INFO, LOG_TAG, fmt, ##args)
-#define MAS_LOGW(fmt, args...) MAS_LOG_(DLOG_WARN, LOG_TAG, fmt, ##args)
-#define MAS_LOGE(fmt, args...) MAS_LOG_(DLOG_ERROR, LOG_TAG, fmt, ##args)
-
-#define MAS_SLOGD(fmt, args...) MAS_SECURE_LOG_(DLOG_DEBUG, LOG_TAG, fmt, ##args)
-#define MAS_SLOGI(fmt, args...) MAS_SECURE_LOG_(DLOG_INFO, LOG_TAG, fmt, ##args)
-#define MAS_SLOGW(fmt, args...) MAS_SECURE_LOG_(DLOG_WARN, LOG_TAG, fmt, ##args)
-#define MAS_SLOGE(fmt, args...) MAS_SECURE_LOG_(DLOG_ERROR, LOG_TAG, fmt, ##args)
-
-
-/**************************************************************************************
- *** Definitions for DBus
- *************************************************************************************/
-#define MA_CLIENT_SERVICE_NAME "org.tizen.multiassistant.maclient"
-#define MA_CLIENT_SERVICE_OBJECT_PATH "/org/tizen/multiassistant/maclient"
-#define MA_CLIENT_SERVICE_INTERFACE "org.tizen.multiassistant.maclient"
-
-#define MA_UI_CLIENT_SERVICE_NAME "org.tizen.multiassistant.mauiclient"
-#define MA_UI_CLIENT_SERVICE_OBJECT_PATH "/org/tizen/multiassistant/mauiclient"
-#define MA_UI_CLIENT_SERVICE_INTERFACE "org.tizen.multiassistant.mauiclient"
-
-#define MA_SERVER_SERVICE_NAME "org.tizen.multiassistant.maserver"
-#define MA_SERVER_SERVICE_OBJECT_PATH "/org/tizen/multiassistant/maserver"
-#define MA_SERVER_SERVICE_INTERFACE "org.tizen.multiassistant.maserver"
-
-/**************************************************************************************
- *** Definitions for DBus methods
- *************************************************************************************/
-#define MA_METHOD_HELLO "ma_method_hello"
-
-#define MA_METHOD_INITIALIZE "ma_method_initialize"
-#define MA_METHOD_DEINITIALIZE "ma_method_deinitialize"
-#define MA_METHOD_GET_RECORDING_AUDIO_FORMAT "ma_method_get_recording_audio_format"
-#define MA_METHOD_GET_RECORDING_AUDIO_SOURCE_TYPE "ma_method_get_recording_audio_source_type"
-#define MA_METHOD_SEND_ASR_RESULT "ma_method_send_asr_result"
-#define MA_METHOD_SEND_RESULT "ma_method_send_result"
-#define MA_METHOD_SEND_RECOGNITION_RESULT "ma_method_send_recognition_result"
-#define MA_METHOD_START_STREAMING_AUDIO_DATA "ma_method_start_streaming_audio_data"
-#define MA_METHOD_STOP_STREAMING_AUDIO_DATA "ma_method_stop_streaming_audio_data"
-#define MA_METHOD_UPDATE_VOICE_FEEDBACK_STATE "ma_method_update_voice_feedback_state"
-#define MA_METHOD_SEND_ASSISTANT_SPECIFIC_COMMAND "ma_method_send_assistant_specific_command"
-#define MA_METHOD_SET_BACKGROUND_VOLUME "ma_method_set_background_volume"
-#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_ADD_WAKE_WORD "ma_method_add_wake_word"
-#define MA_METHOD_REMOVE_WAKE_WORD "ma_method_remove_wake_word"
-#define MA_METHOD_ERROR "ma_method_error"
-
-#define MA_UI_METHOD_INITIALIZE "ma_ui_method_initialize"
-#define MA_UI_METHOD_DEINITIALIZE "ma_ui_method_deinitialize"
-#define MA_UI_METHOD_CHANGE_ASSISTANT "ma_ui_method_change_assistant"
-
-#define MAS_METHOD_HELLO "mas_method_hello"
-#define MAS_METHOD_ACTIVE_STATE_CHANGE "mas_method_active_state_change"
-#define MAS_METHOD_STREAMING_AUDIO_DATA "mas_method_streaming_audio_data"
-#define MAS_METHOD_WAKEUP_ENGINE_COMMAND "mas_method_wakeup_engine_command"
-#define MAS_METHOD_ERROR "mas_method_error"
-#define MAS_METHOD_SEND_PREPROCESSING_INFORMATION "mas_method_send_preprocessing_information"
-#define MAS_METHOD_AUDIO_STREAMING_DATA_SECTION "mas_method_audio_streaming_data_section"
-#define MAS_METHOD_SEND_PREPROCESSING_RESULT "mas_method_send_preprocessing_result"
-#define MAS_METHOD_SEND_WAKEUP_ENGINE_COMMAND "mas_method_send_wakeup_engine_command"
-#define MAS_METHOD_SERVICE_STATE_CHANGE "mas_method_service_state_change"
-#define MAS_METHOD_VOICE_KEY_STATUS_CHANGE "mas_method_voice_key_status_change"
-
-#define MAS_UI_METHOD_SEND_ASR_RESULT "mas_ui_method_send_asr_result"
-#define MAS_UI_METHOD_SEND_RESULT "mas_ui_method_send_result"
-#define MAS_UI_METHOD_CHANGE_ASSISTANT "mas_ui_method_change_assistant"
-#define MAS_UI_METHOD_ERROR "mas_ui_method_error"
-#define MAS_UI_METHOD_SEND_RECOGNITION_RESULT "mas_ui_method_send_recognition_result"
-#define MAS_UI_METHOD_ENABLE_COMMON_UI "mas_ui_method_enable_common_ui"
-
-#endif /* __MULTI_ASSISTANT_SERVICE_H__ */
+++ /dev/null
-/*
- * Copyright 2018-2019 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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 _MULTI_ASSISTANT_SERVICE_H_
-#define _MULTI_ASSISTANT_SERVICE_H_
-
-#include <dlog/dlog.h>
-#include <multi_assistant.h>
-#include <multi_assistant_internal.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define MAX_APPID_LEN 255
-
-typedef enum {
- CLIENT_LAUNCH_MODE_ACTIVATION,
- CLIENT_LAUNCH_MODE_PRELAUNCH,
-} CLIENT_LAUNCH_MODE;
-
-typedef enum {
- PREPROCESSING_STATE_NONE,
- PREPROCESSING_STATE_WAKEUP_PREPROCESS_ENABLED,
- PREPROCESSING_STATE_WAKEUP_PREPROCESS_DISABLED,
- PREPROCESSING_STATE_PREPROCESSING_UTTERANCE,
- PREPROCESSING_STATE_PREPROCESSING_FOLLOW_UP,
-} PREPROCESSING_STATE;
-
-typedef enum {
- PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED,
- PREPROCESSING_STATE_EVENT_PREPROCESSING_ALLOW_MODE_CHANGED,
- PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED,
- PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED,
- PREPROCESSING_STATE_EVENT_PREPROCESSING_SUCCEEDED,
- PREPROCESSING_STATE_EVENT_PREPROCESSING_FAILED,
-} PREPROCESSING_STATE_EVENT;
-
-int mas_client_initialize(int pid);
-
-int mas_client_deinitialize(int pid);
-
-int mas_client_get_audio_format(int pid, int* rate, int* channel, int* audio_type);
-
-int mas_client_get_audio_source_type(int pid, char** type);
-
-int mas_client_send_preprocessing_information(int pid);
-
-int mas_client_activate(int pid);
-
-int mas_client_deactivate(int pid);
-
-int mas_client_request_speech_data(int pid);
-
-int mas_client_send_asr_result(int pid, int event, char* asr_result);
-
-int mas_client_send_result(int pid, char* display_text, char* utterance_text, char* result_json);
-
-int mas_client_send_recognition_result(int pid, int result);
-
-int mas_client_start_streaming_audio_data(int pid, int type);
-
-int mas_client_stop_streaming_audio_data(int pid, int type);
-
-int mas_client_update_voice_feedback_state(int pid, int state);
-
-int mas_client_set_assistant_specific_command(int pid, const char *command);
-
-int mas_client_set_background_volume(int pid, double ratio);
-
-int mas_client_set_preprocessing_allow_mode(int pid, ma_preprocessing_allow_mode_e mode, const char* appid);
-
-int mas_client_send_preprocessing_result(int pid, bool result);
-
-int mas_client_set_wake_word_audio_require_flag(int pid, bool require);
-
-int mas_client_set_assistant_language(int pid, const char* language);
-
-int mas_client_send_voice_key_status_change(int pid, ma_voice_key_status_e status);
-
-int mas_client_add_wake_word(int pid, const char* wake_word, const char* language);
-
-int mas_client_remove_wake_word(int pid, const char* wake_word, const char* language);
-
-int mas_ui_client_initialize(int pid);
-
-int mas_ui_client_deinitialize(int pid);
-
-int mas_ui_client_change_assistant(const char* appid);
-
-int mas_get_current_client_pid();
-
-int mas_get_current_preprocessing_client_pid();
-
-int mas_get_client_pid_by_wakeup_word(const char *wakeup_word);
-
-int mas_get_client_pid_by_appid(const char *appid);
-
-const char* mas_get_client_appid_by_pid(int pid);
-
-bool mas_get_client_custom_ui_option_by_appid(const char *appid);
-
-const char* mas_get_client_appid_by_wakeup_word(const char *wakeup_word);
-
-int mas_set_current_client_by_wakeup_word(const char *wakeup_word);
-
-int mas_set_current_client_by_appid(const char *appid);
-
-int mas_launch_client_by_wakeup_word(const char *wakeup_word);
-
-int mas_prelaunch_default_assistant();
-
-int mas_set_current_service_state(ma_service_state_e state);
-
-int mas_bring_client_to_foreground(const char* appid);
-
-ma_service_state_e mas_get_current_service_state();
-
-int mas_launch_client_by_appid(const char *appid, CLIENT_LAUNCH_MODE launch_mode);
-
-int mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event);
-
-int mas_update_voice_key_support_mode();
-
-bool app_create(void *data);
-
-void app_terminate(void *data);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _MULTI_ASSISTANT_SERVICE_H_ */
+++ /dev/null
-/*
- * Copyright 2018-2019 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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 _MULTI_ASSISTANT_SERVICE_PLUGIN_H_
-#define _MULTI_ASSISTANT_SERVICE_PLUGIN_H_
-
-#include <tzplatform_config.h>
-#include <dlog/dlog.h>
-#include <multi_assistant_service.h>
-
-#include "multi_wakeup_recognizer.h"
-#include "multi_assistant_main.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct {
- int plugin_version;
- bool ui_panel_enabled;
-} ma_plugin_settings;
-
-int multi_assistant_service_plugin_initialize(void);
-
-int multi_assistant_service_plugin_deinitialize(void);
-
-int multi_assistant_service_plugin_get_settings(ma_plugin_settings **settings, size_t *struct_size);
-
-int multi_assistant_service_plugin_set_language(const char* language);
-
-int multi_assistant_service_plugin_add_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language);
-
-int multi_assistant_service_plugin_remove_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language);
-
-int multi_assistant_service_plugin_add_assistant_language(const char* appid, const char* language);
-
-int multi_assistant_service_plugin_set_assistant_wakeup_engine(const char* appid, const char* engine);
-
-int multi_assistant_service_plugin_set_default_assistant(const char* appid);
-
-int multi_assistant_service_plugin_get_default_assistant(const char** appid);
-
-int multi_assistant_service_plugin_activate(void);
-
-int multi_assistant_service_plugin_deactivate(void);
-
-int multi_assistant_service_plugin_update_voice_feedback_state(const char* appid, int state);
-
-int multi_assistant_service_plugin_set_assistant_specific_command(const char *appid, const char* command);
-
-int multi_assistant_service_plugin_set_background_volume(const char *appid, double ratio);
-
-int multi_assistant_service_plugin_update_recognition_result(const char* appid, int result);
-
-int multi_assistant_service_plugin_set_preprocessing_allow_mode(const char* appid, int mode, const char* preprocessing_appid);
-
-int multi_assistant_service_plugin_process_event(int event, void* data, int len);
-
-int multi_assistant_service_plugin_start_streaming_utterance_data(void);
-
-int multi_assistant_service_plugin_stop_streaming_utterance_data(void);
-
-int multi_assistant_service_plugin_start_streaming_previous_utterance_data(void);
-
-int multi_assistant_service_plugin_stop_streaming_previous_utterance_data(void);
-
-int multi_assistant_service_plugin_start_streaming_follow_up_data(void);
-
-int multi_assistant_service_plugin_stop_streaming_follow_up_data(void);
-
-int multi_assistant_service_plugin_get_recording_audio_format(int* rate, int* channel, int* audio_type);
-
-int multi_assistant_service_plugin_get_recording_audio_source_type(char **type);
-
-int multi_assistant_service_plugin_set_wake_word_audio_require_flag(const char* appid, bool require);
-
-int multi_assistant_service_plugin_set_assistant_language(const char* appid, const char* language);
-
-int multi_assistant_service_plugin_set_voice_key_support_mode(int mode);
-
-int multi_assistant_service_plugin_set_voice_key_tap_duration(float duration);
-
-int multi_assistant_service_plugin_unset_voice_key_tap_duration(void);
-
-int multi_assistant_service_plugin_set_callbacks(void);
-
-int multi_assistant_service_plugin_set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data);
-
-int multi_assistant_service_plugin_set_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data);
-
-int multi_assistant_service_plugin_set_previous_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data);
-
-int multi_assistant_service_plugin_set_follow_up_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data);
-
-int multi_assistant_service_plugin_set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data);
-
-int multi_assistant_service_plugin_set_setting_changed_callback(wakeup_service_setting_changed_cb callback, void* user_data);
-
-int multi_assistant_service_plugin_set_error_callback(wakeup_service_error_cb callback, void* user_data);
-
-int multi_assistant_service_plugin_set_streaming_section_changed_callback(wakeup_service_streaming_section_changed_cb callback, void* user_data);
-
-int multi_assistant_service_plugin_set_wakeup_engine_command_callback(wakeup_service_wakeup_engine_command_cb callback, void* user_data);
-
-int multi_assistant_service_plugin_set_wakeup_service_state_changed_callback(wakeup_service_wakeup_service_state_changed_cb callback, void* user_data);
-
-int multi_assistant_service_plugin_set_voice_key_status_changed_callback(wakeup_service_voice_key_status_changed_cb callback, void* user_data);
-
-
-#define MA_WAKEUP_MANAGER_PATH tzplatform_mkpath(tzplatform_getid("TZ_SYS_RO_SHARE"), "multiassistant/")
-
-#define MA_DEFAULT_WAKEUP_MANAGER_FILENAME "libma-wakeup-manager.so"
-
-
-#define MA_WAKEUP_MANAGER_FUNC_INITIALIZE "wakeup_manager_initialize"
-typedef int (*wakeup_manager_initialize)(void);
-#define MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE "wakeup_manager_deinitialize"
-typedef int (*wakeup_manager_deinitialize)(void);
-#define MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS "wakeup_manager_get_settings"
-typedef int (*wakeup_manager_get_settings)(ma_plugin_settings **settings, size_t *struct_size);
-#define MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_WORD "wakeup_manager_add_assistant_wakeup_word"
-typedef int (*wakeup_manager_add_assistant_wakeup_word)(const char* appid, const char* wakeup_word, const char* language);
-#define MA_WAKEUP_MANAGER_FUNC_REMOVE_ASSISTANT_WAKEUP_WORD "wakeup_manager_remove_assistant_wakeup_word"
-typedef int (*wakeup_manager_remove_assistant_wakeup_word)(const char* appid, const char* wakeup_word, const char* language);
-#define MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE "wakeup_manager_add_assistant_language"
-typedef int (*wakeup_manager_add_assistant_language)(const char* appid, const char* language);
-#define MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE "wakeup_manager_set_assistant_wakeup_engine"
-typedef int (*wakeup_manager_set_assistant_wakeup_engine)(const char* appid, const char* engine);
-#define MA_WAKEUP_MANAGER_FUNC_SET_DEFAULT_ASSISTANT "wakeup_manager_set_default_assistant"
-typedef int (*wakeup_manager_set_default_assistant)(const char* appid);
-#define MA_WAKEUP_MANAGER_FUNC_GET_DEFAULT_ASSISTANT "wakeup_manager_get_default_assistant"
-typedef int (*wakeup_manager_get_default_assistant)(const char** appid);
-#define MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE "wakeup_manager_set_language"
-typedef int (*wakeup_manager_set_language)(const char* language);
-#define MA_WAKEUP_MANAGER_FUNC_ACTIVATE "wakeup_manager_activate"
-typedef int (*wakeup_manager_activate)(void);
-#define MA_WAKEUP_MANAGER_FUNC_DEACTIVATE "wakeup_manager_deactivate"
-typedef int (*wakeup_manager_deactivate)(void);
-#define MA_WAKEUP_MANAGER_FUNC_UPDATE_VOICE_FEEDBACK_STATE "wakeup_manager_update_voice_feedback_state"
-typedef int (*wakeup_manager_update_voice_feedback_state)(const char* appid, int state);
-#define MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND "wakeup_manager_set_assistant_specific_command"
-typedef int (*wakeup_manager_set_assistant_specific_command)(const char* appid, const char* command);
-#define MA_WAKEUP_MANAGER_FUNC_SET_BACKGROUND_VOLUME "wakeup_manager_set_background_volume"
-typedef int (*wakeup_manager_set_background_volume)(const char* appid, double ratio);
-#define MA_WAKEUP_MANAGER_FUNC_UPDATE_RECOGNITION_RESULT "wakeup_manager_update_recognition_result"
-typedef int (*wakeup_manager_update_recognition_result)(const char* appid, int result);
-#define MA_WAKEUP_MANAGER_FUNC_PROCESS_PLUGIN_EVENT "wakeup_manager_process_plugin_event"
-typedef int (*wakeup_manager_process_plugin_event)(int event, void* data, int len);
-#define MA_WAKEUP_MANAGER_FUNC_START_STREAMING_UTTERANCE_DATA "wakeup_manager_start_streaming_utterance_data"
-typedef int (*wakeup_manager_start_streaming_utterance_data)(void);
-#define MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_UTTERANCE_DATA "wakeup_manager_stop_streaming_utterance_data"
-typedef int (*wakeup_manager_stop_streaming_utterance_data)(void);
-#define MA_WAKEUP_MANAGER_FUNC_START_STREAMING_PREVIOUS_UTTERANCE_DATA "wakeup_manager_start_streaming_previous_utterance_data"
-typedef int (*wakeup_manager_start_streaming_previous_utterance_data)(void);
-#define MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_PREVIOUS_UTTERANCE_DATA "wakeup_manager_stop_streaming_previous_utterance_data"
-typedef int (*wakeup_manager_stop_streaming_previous_utterance_data)(void);
-#define MA_WAKEUP_MANAGER_FUNC_START_STREAMING_FOLLOW_UP_DATA "wakeup_manager_start_streaming_follow_up_data"
-typedef int (*wakeup_manager_start_streaming_follow_up_data)(void);
-#define MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_FOLLOW_UP_DATA "wakeup_manager_stop_streaming_follow_up_data"
-typedef int (*wakeup_manager_stop_streaming_follow_up_data)(void);
-#define MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_FORMAT "wakeup_manager_get_audio_format"
-typedef int (*wakeup_manager_get_audio_format)(int* rate, int* channel, int* audio_type);
-#define MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_SOURCE_TYPE "wakeup_manager_get_audio_source_type"
-typedef int (*wakeup_manager_get_audio_source_type)(char** type);
-#define MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_TAP_DURATION "wakeup_manager_set_voice_key_tap_duration"
-typedef int (*wakeup_manager_set_voice_key_tap_duration)(float duration);
-#define MA_WAKEUP_MANAGER_FUNC_UNSET_VOICE_KEY_TAP_DURATION "wakeup_manager_unset_voice_key_tap_duration"
-typedef int (*wakeup_manager_unset_voice_key_tap_duration)();
-#define MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_SUPPORT_MODE "wakeup_manager_set_voice_key_support_mode"
-typedef int (*wakeup_manager_set_voice_key_support_mode)(int mode);
-#define MA_WAKEUP_MANAGER_FUNC_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG "wakeup_manager_set_wake_word_audio_require_flag"
-typedef int (*wakeup_manager_set_wake_word_audio_require_flag)(bool require);
-#define MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_LANGUAGE "wakeup_manager_set_assistant_language"
-typedef int (*wakeup_manager_set_assistant_language)(const char* appid, const char* language);
-#define MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_EVENT_CALLBACK "wakeup_manager_set_wakeup_event_callback"
-typedef int (*wakeup_manager_set_wakeup_event_callback)(wakeup_service_wakeup_event_cb callback, void* user_data);
-#define MA_WAKEUP_MANAGER_FUNC_SET_UTTERANCE_STREAMING_CALLBACK "wakeup_manager_set_utterance_streaming_callback"
-typedef int (*wakeup_manager_set_utterance_streaming_callback)(wakeup_service_speech_streaming_cb callback, void* user_data);
-#define MA_WAKEUP_MANAGER_FUNC_SET_PREVIOUS_UTTERANCE_STREAMING_CALLBACK "wakeup_manager_set_previous_utterance_streaming_callback"
-typedef int (*wakeup_manager_set_previous_utterance_streaming_callback)(wakeup_service_speech_streaming_cb callback, void* user_data);
-#define MA_WAKEUP_MANAGER_FUNC_SET_FOLLOW_UP_STREAMING_CALLBACK "wakeup_manager_set_follow_up_streaming_callback"
-typedef int (*wakeup_manager_set_follow_up_streaming_callback)(wakeup_service_speech_streaming_cb callback, void* user_data);
-#define MA_WAKEUP_MANAGER_FUNC_SET_SPEECH_STATUS_CALLBACK "wakeup_manager_set_speech_status_callback"
-typedef int (*wakeup_manager_set_speech_status_callback)(wakeup_service_speech_status_cb callback, void* user_data);
-#define MA_WAKEUP_MANAGER_FUNC_SET_SETTING_CHANGED_CALLBACK "wakeup_manager_set_setting_changed_callback"
-typedef int (*wakeup_manager_set_setting_changed_callback)(wakeup_service_setting_changed_cb callback, void* user_data);
-#define MA_WAKEUP_MANAGER_FUNC_SET_ERROR_CALLBACK "wakeup_manager_set_error_callback"
-typedef int (*wakeup_manager_set_error_callback)(wakeup_service_error_cb callback, void* user_data);
-#define MA_WAKEUP_MANAGER_FUNC_SET_STREAMING_SECTION_CHANGED_CALLBACK "wakeup_manager_set_streaming_section_changed_callback"
-typedef int (*wakeup_manager_set_streaming_section_changed_callback)(wakeup_service_streaming_section_changed_cb callback, void* user_data);
-#define MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_ENGINE_COMMAND_CALLBACK "wakeup_manager_set_wakeup_engine_command_callback"
-typedef int (*wakeup_manager_set_wakeup_engine_command_callback)(wakeup_service_wakeup_engine_command_cb callback, void* user_data);
-#define MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_SERVICE_STATE_CHANGED_CALLBACK "wakeup_manager_set_wakeup_service_state_changed_callback"
-typedef int (*wakeup_manager_set_wakeup_service_state_changed_callback)(wakeup_service_wakeup_service_state_changed_cb callback, void* user_data);
-#define MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_STATUS_CHANGED_CALLBACK "wakeup_manager_set_voice_key_status_changed_callback"
-typedef int (*wakeup_manager_set_voice_key_status_changed_callback)(wakeup_service_voice_key_status_changed_cb callback, void* user_data);
-
-typedef struct {
- wakeup_manager_initialize initialize;
- wakeup_manager_deinitialize deinitialize;
- wakeup_manager_get_settings get_settings;
- wakeup_manager_add_assistant_wakeup_word add_assistant_wakeup_word;
- wakeup_manager_remove_assistant_wakeup_word remove_assistant_wakeup_word;
- wakeup_manager_add_assistant_language add_assistant_language;
- wakeup_manager_set_assistant_wakeup_engine set_assistant_wakeup_engine;
- wakeup_manager_set_default_assistant set_default_assistant;
- wakeup_manager_get_default_assistant get_default_assistant;
- wakeup_manager_set_language set_language;
- wakeup_manager_activate activate;
- wakeup_manager_deactivate deactivate;
- wakeup_manager_update_voice_feedback_state update_voice_feedback_state;
- wakeup_manager_set_assistant_specific_command set_assistant_specific_command;
- wakeup_manager_set_background_volume set_background_volume;
- wakeup_manager_update_recognition_result update_recognition_result;
- wakeup_manager_process_plugin_event process_plugin_event;
- wakeup_manager_start_streaming_utterance_data start_streaming_utterance_data;
- wakeup_manager_stop_streaming_utterance_data stop_streaming_utterance_data;
- wakeup_manager_start_streaming_previous_utterance_data start_streaming_previous_utterance_data;
- wakeup_manager_stop_streaming_previous_utterance_data stop_streaming_previous_utterance_data;
- wakeup_manager_start_streaming_follow_up_data start_streaming_follow_up_data;
- wakeup_manager_stop_streaming_follow_up_data stop_streaming_follow_up_data;
- wakeup_manager_get_audio_format get_audio_format;
- wakeup_manager_get_audio_source_type get_audio_source_type;
- wakeup_manager_set_voice_key_tap_duration set_voice_key_tap_duration;
- wakeup_manager_unset_voice_key_tap_duration unset_voice_key_tap_duration;
- wakeup_manager_set_voice_key_support_mode set_voice_key_support_mode;
- wakeup_manager_set_wake_word_audio_require_flag set_wake_word_audio_require_flag;
- wakeup_manager_set_assistant_language set_assistant_language;
- wakeup_manager_set_wakeup_event_callback set_wakeup_event_callback;
- wakeup_manager_set_utterance_streaming_callback set_utterance_streaming_callback;
- wakeup_manager_set_previous_utterance_streaming_callback set_previous_utterance_streaming_callback;
- wakeup_manager_set_follow_up_streaming_callback set_follow_up_streaming_callback;
- wakeup_manager_set_speech_status_callback set_speech_status_callback;
- wakeup_manager_set_setting_changed_callback set_setting_changed_callback;
- wakeup_manager_set_error_callback set_error_callback;
- wakeup_manager_set_streaming_section_changed_callback set_streaming_section_changed_callback;
- wakeup_manager_set_wakeup_engine_command_callback set_wakeup_engine_command_callback;
- wakeup_manager_set_wakeup_service_state_changed_callback set_wakeup_service_state_changed_callback;
- wakeup_manager_set_voice_key_status_changed_callback set_voice_key_status_changed_callback;
-} wakeup_manager_interface;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _MULTI_ASSISTANT_SERVICE_PLUGIN_H_ */
+++ /dev/null
-/*
- * Copyright 2018-2019 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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 _MULTI_WAKEUP_RECOGNIZER_H_
-#define _MULTI_WAKEUP_RECOGNIZER_H_
-
-#include <dlog/dlog.h>
-
-#include <multi_assistant_common.h>
-#include <multi_assistant_service.h>
-#include <multi_assistant_internal.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void (*wakeup_service_wakeup_event_cb)(mas_wakeup_event_info wakeup_info, const char* wakeup_word, void* user_data);
-
-typedef void (*wakeup_service_speech_streaming_cb)(mas_speech_streaming_event_e event, unsigned char* buffer, int len, void *user_data);
-
-typedef void (*wakeup_service_speech_status_cb)(mas_speech_status_e status, void *user_data);
-
-typedef void (*wakeup_service_setting_changed_cb)(void *user_data);
-
-typedef void (*wakeup_service_error_cb)(int error, const char* err_msg, void* user_data);
-
-typedef void (*wakeup_service_streaming_section_changed_cb)(ma_audio_streaming_data_section_e section, void* user_data);
-
-typedef void (*wakeup_service_wakeup_engine_command_cb)(mas_wakeup_engine_command_target_e target, const char* assistant_name, const char* command, void* user_data);
-
-typedef void (*wakeup_service_wakeup_service_state_changed_cb)(ma_service_state_e state, void* user_data);
-
-typedef void (*wakeup_service_voice_key_status_changed_cb)(ma_voice_key_status_e status, void* user_data);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _MULTI_WAKEUP_RECOGNIZER_H_ */
--- /dev/null
+#ifndef __SERVICE_COMMON_H__
+#define __SERVICE_COMMON_H__
+
+#include <app.h>
+#include <glib.h>
+#include <dlog/dlog.h>
+#include <multi_assistant_common.h>
+#include <multi_assistant_service.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "multi-assistant"
+
+#define MAS_SECURE_LOG_(id, prio, tag, fmt, arg...) \
+ ({ do { \
+ __dlog_print(id, prio, tag, "%s: %s(%d) > [SECURE_LOG] " fmt, __MODULE__, __func__, __LINE__, ##arg); \
+ } while (0); })
+
+#define MAS_LOG_(prio, tag, fmt, arg...) \
+ ({ do { \
+ dlog_print(prio, tag, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg); \
+ } while (0); })
+
+#define MAS_LOGD(fmt, args...) MAS_LOG_(DLOG_DEBUG, LOG_TAG, fmt, ##args)
+#define MAS_LOGI(fmt, args...) MAS_LOG_(DLOG_INFO, LOG_TAG, fmt, ##args)
+#define MAS_LOGW(fmt, args...) MAS_LOG_(DLOG_WARN, LOG_TAG, fmt, ##args)
+#define MAS_LOGE(fmt, args...) MAS_LOG_(DLOG_ERROR, LOG_TAG, fmt, ##args)
+
+#define MAS_SLOGD(fmt, args...) MAS_SECURE_LOG_(DLOG_DEBUG, LOG_TAG, fmt, ##args)
+#define MAS_SLOGI(fmt, args...) MAS_SECURE_LOG_(DLOG_INFO, LOG_TAG, fmt, ##args)
+#define MAS_SLOGW(fmt, args...) MAS_SECURE_LOG_(DLOG_WARN, LOG_TAG, fmt, ##args)
+#define MAS_SLOGE(fmt, args...) MAS_SECURE_LOG_(DLOG_ERROR, LOG_TAG, fmt, ##args)
+
+
+/**************************************************************************************
+ *** Definitions for DBus
+ *************************************************************************************/
+#define MA_CLIENT_SERVICE_NAME "org.tizen.multiassistant.maclient"
+#define MA_CLIENT_SERVICE_OBJECT_PATH "/org/tizen/multiassistant/maclient"
+#define MA_CLIENT_SERVICE_INTERFACE "org.tizen.multiassistant.maclient"
+
+#define MA_UI_CLIENT_SERVICE_NAME "org.tizen.multiassistant.mauiclient"
+#define MA_UI_CLIENT_SERVICE_OBJECT_PATH "/org/tizen/multiassistant/mauiclient"
+#define MA_UI_CLIENT_SERVICE_INTERFACE "org.tizen.multiassistant.mauiclient"
+
+#define MA_SERVER_SERVICE_NAME "org.tizen.multiassistant.maserver"
+#define MA_SERVER_SERVICE_OBJECT_PATH "/org/tizen/multiassistant/maserver"
+#define MA_SERVER_SERVICE_INTERFACE "org.tizen.multiassistant.maserver"
+
+/**************************************************************************************
+ *** Definitions for DBus methods
+ *************************************************************************************/
+#define MA_METHOD_HELLO "ma_method_hello"
+
+#define MA_METHOD_INITIALIZE "ma_method_initialize"
+#define MA_METHOD_DEINITIALIZE "ma_method_deinitialize"
+#define MA_METHOD_GET_RECORDING_AUDIO_FORMAT "ma_method_get_recording_audio_format"
+#define MA_METHOD_GET_RECORDING_AUDIO_SOURCE_TYPE "ma_method_get_recording_audio_source_type"
+#define MA_METHOD_SEND_ASR_RESULT "ma_method_send_asr_result"
+#define MA_METHOD_SEND_RESULT "ma_method_send_result"
+#define MA_METHOD_SEND_RECOGNITION_RESULT "ma_method_send_recognition_result"
+#define MA_METHOD_START_STREAMING_AUDIO_DATA "ma_method_start_streaming_audio_data"
+#define MA_METHOD_STOP_STREAMING_AUDIO_DATA "ma_method_stop_streaming_audio_data"
+#define MA_METHOD_UPDATE_VOICE_FEEDBACK_STATE "ma_method_update_voice_feedback_state"
+#define MA_METHOD_SEND_ASSISTANT_SPECIFIC_COMMAND "ma_method_send_assistant_specific_command"
+#define MA_METHOD_SET_BACKGROUND_VOLUME "ma_method_set_background_volume"
+#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_ADD_WAKE_WORD "ma_method_add_wake_word"
+#define MA_METHOD_REMOVE_WAKE_WORD "ma_method_remove_wake_word"
+#define MA_METHOD_ERROR "ma_method_error"
+
+#define MA_UI_METHOD_INITIALIZE "ma_ui_method_initialize"
+#define MA_UI_METHOD_DEINITIALIZE "ma_ui_method_deinitialize"
+#define MA_UI_METHOD_CHANGE_ASSISTANT "ma_ui_method_change_assistant"
+
+#define MAS_METHOD_HELLO "mas_method_hello"
+#define MAS_METHOD_ACTIVE_STATE_CHANGE "mas_method_active_state_change"
+#define MAS_METHOD_STREAMING_AUDIO_DATA "mas_method_streaming_audio_data"
+#define MAS_METHOD_WAKEUP_ENGINE_COMMAND "mas_method_wakeup_engine_command"
+#define MAS_METHOD_ERROR "mas_method_error"
+#define MAS_METHOD_SEND_PREPROCESSING_INFORMATION "mas_method_send_preprocessing_information"
+#define MAS_METHOD_AUDIO_STREAMING_DATA_SECTION "mas_method_audio_streaming_data_section"
+#define MAS_METHOD_SEND_PREPROCESSING_RESULT "mas_method_send_preprocessing_result"
+#define MAS_METHOD_SEND_WAKEUP_ENGINE_COMMAND "mas_method_send_wakeup_engine_command"
+#define MAS_METHOD_SERVICE_STATE_CHANGE "mas_method_service_state_change"
+#define MAS_METHOD_VOICE_KEY_STATUS_CHANGE "mas_method_voice_key_status_change"
+
+#define MAS_UI_METHOD_SEND_ASR_RESULT "mas_ui_method_send_asr_result"
+#define MAS_UI_METHOD_SEND_RESULT "mas_ui_method_send_result"
+#define MAS_UI_METHOD_CHANGE_ASSISTANT "mas_ui_method_change_assistant"
+#define MAS_UI_METHOD_ERROR "mas_ui_method_error"
+#define MAS_UI_METHOD_SEND_RECOGNITION_RESULT "mas_ui_method_send_recognition_result"
+#define MAS_UI_METHOD_ENABLE_COMMON_UI "mas_ui_method_enable_common_ui"
+
+typedef void (*wakeup_service_wakeup_event_cb)(mas_wakeup_event_info wakeup_info, void* user_data);
+
+typedef void (*wakeup_service_speech_streaming_cb)(mas_speech_streaming_event_e event, void* buffer, int len, void *user_data);
+
+typedef void (*wakeup_service_speech_status_cb)(mas_speech_status_e status, void *user_data);
+
+typedef void (*wakeup_service_setting_changed_cb)(void *user_data);
+
+typedef void (*wakeup_service_error_cb)(int error, const char* err_msg, void* user_data);
+
+typedef void (*wakeup_service_streaming_section_changed_cb)(ma_audio_streaming_data_section_e section, void* user_data);
+
+typedef void (*wakeup_service_wakeup_engine_command_cb)(mas_wakeup_engine_command_target_e target, const char* assistant_name, const char* command, void* user_data);
+
+typedef void (*wakeup_service_wakeup_service_state_changed_cb)(ma_service_state_e state, void* user_data);
+
+typedef void (*wakeup_service_voice_key_status_changed_cb)(ma_voice_key_status_e status, void* user_data);
+
+#define MAX_WAKEUP_WORDS_NUM 255
+#define MAX_WAKEUP_WORD_LEN 32
+#define MAX_SUPPORTED_LANGUAGES_NUM 255
+#define MAX_SUPPORTED_LANGUAGE_LEN 16
+
+typedef enum {
+ VOICE_KEY_SUPPORT_MODE_NONE,
+ VOICE_KEY_SUPPORT_MODE_PUSH_TO_TALK,
+ VOICE_KEY_SUPPORT_MODE_TAP_TO_TALK,
+ VOICE_KEY_SUPPORT_MODE_ALL,
+} VOICE_KEY_SUPPORT_MODE;
+
+#endif /* __SERVICE_COMMON_H__ */
--- /dev/null
+/*
+ * Copyright 2018-2019 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 __SERVICE_CONFIG_H__
+#define __SERVICE_CONFIG_H__
+
+#include <tizen.h>
+#include <tzplatform_config.h>
+
+#include "service_common.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define MAX_WAKEUP_LIST_NUM 32
+#define MAX_SUPPORTED_LANGUAGE_NUM 128
+
+/**************************************************************************************
+ *** Definitions for xml file
+ *************************************************************************************/
+#define MA_TAG_ASSISTANT_BASE "multi-assistant"
+#define MA_TAG_ASSISTANT_NAME "name"
+#define MA_TAG_ASSISTANT_APPID "appid"
+#define MA_TAG_ASSISTANT_ICON_PATH "icon-path"
+#define MA_TAG_ASSISTANT_LANGUAGE_SET "languages"
+#define MA_TAG_ASSISTANT_LANGUAGE "language"
+#define MA_TAG_ASSISTANT_WAKEUP_WORD_SET "wakeup-words"
+#define MA_TAG_ASSISTANT_WAKEUP_WORD "wakeup-word"
+#define MA_TAG_ASSISTANT_WAKEUP_ENGINE_APPID "wakeup-engine-appid"
+#define MA_TAG_ASSISTANT_CUSTOM_UI "custom-ui"
+#define MA_TAG_ASSISTANT_VOICE_KEY_SUPPORT_MODE "voice-key-support-mode"
+#define MA_TAG_ASSISTANT_VOICE_KEY_TAP_DURATION "voice-key-tap-duration"
+
+/**************************************************************************************
+ *** Definitions for ETC
+ *************************************************************************************/
+#define MA_RETRY_COUNT 5
+
+#define MA_ASSISTANT_INFO tzplatform_mkpath(TZ_USER_HOME, "share/.multiassistant/ma/1.0/assistant-info")
+
+#define VOICE_KEY_SUPPORT_MODE_STRING_NONE "none"
+#define VOICE_KEY_SUPPORT_MODE_STRING_PUSH_TO_TALK "push_to_talk"
+#define VOICE_KEY_SUPPORT_MODE_STRING_TAP_TO_TALK "tap_to_talk"
+#define VOICE_KEY_SUPPORT_MODE_STRING_ALL "all"
+
+typedef struct {
+ const char* app_id;
+ const char* name;
+ const char* icon_path;
+ const char* wakeup_list[MAX_WAKEUP_LIST_NUM];
+ const char* wakeup_language[MAX_WAKEUP_LIST_NUM];
+ int cnt_wakeup;
+ const char* supported_lang[MAX_SUPPORTED_LANGUAGE_NUM];
+ int cnt_lang;
+ const char* wakeup_engine;
+ bool custom_ui_option;
+ VOICE_KEY_SUPPORT_MODE voice_key_support_mode;
+ float voice_key_tap_duration;
+} ma_assistant_info_s;
+
+typedef int (*service_config_assistant_info_cb)(ma_assistant_info_s* info, void* user_data);
+
+class CServiceConfig {
+public:
+ CServiceConfig() {};
+ virtual ~CServiceConfig() {};
+
+ int get_assistant_info(service_config_assistant_info_cb callback, void* user_data);
+
+ int add_custom_wake_word(const char* wake_word, const char* language,
+ char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
+ char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]);
+ int remove_custom_wake_word(const char* wake_word, const char* language,
+ char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
+ char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]);
+ int load_custom_wake_words(const char* app_id,
+ char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
+ char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]);
+ int save_custom_wake_words(const char* app_id,
+ char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
+ char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]);
+ int get_custom_wake_word_num(
+ char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
+ char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]);
+ bool has_custom_wake_word(const char* wake_word, const char* language,
+ char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
+ char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]);
+private:
+ int parse_assistant_info(service_config_assistant_info_cb callback,
+ const char *path, void* user_data);
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * @}
+ */
+
+#endif /* __SERVICE_CONFIG_H__ */
--- /dev/null
+/*
+ * Copyright 2018-2019 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 __SERVICE_IPC_DBUS_H__
+#define __SERVICE_IPC_DBUS_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <dbus/dbus.h>
+#include <Ecore.h>
+
+#include "service_ipc_dbus_dispatcher.h"
+
+class CServiceMain;
+
+class CServiceIpcDbus {
+public:
+ CServiceIpcDbus() {}
+ virtual ~CServiceIpcDbus() {}
+
+ int open_connection();
+ int close_connection();
+ int send_hello(int pid);
+ int send_error_message(int reason, const char* err_msg);
+ int send_streaming_audio_data(int pid, int event, void* data, unsigned int data_size);
+ int active_state_change(int pid, int state);
+ int send_preprocessing_information(int pid, const char* app_id);
+ int send_streaming_section_changed(int pid, int section);
+ int send_preprocessing_result(int pid, bool result);
+ int send_wakeup_engine_command(int pid, const char* command);
+ int service_state_change(int pid, int state);
+ int voice_key_status_change(int pid, int status);
+ int masc_ui_dbus_send_hello(void);
+ int masc_ui_dbus_send_asr_result(int pid, int event, char* asr_result);
+ int masc_ui_dbus_send_result(int pid, const char* display_text, const char* utterance_text, const char* result_json);
+ int masc_ui_dbus_change_assistant(const char* app_id);
+ int masc_ui_dbus_send_error_message(int reason, const char* err_msg);
+ int masc_ui_dbus_send_recognition_result(int pid, int result);
+ int masc_ui_dbus_enable_common_ui(int enable);
+
+ DBusConnection* get_connection_listener() { return g_conn_listener; }
+ CServiceIpcDbusDispatcher* get_dispatcher() { return &mDispatcher; }
+
+ void set_service_main(CServiceMain* main) {
+ mServiceMain = main;
+ mDispatcher.set_service_main(main);
+ }
+private:
+ int __dbus_check();
+ void connection_free();
+ int reconnect();
+ int mas_check_dbus_connection();
+
+private:
+ CServiceIpcDbusDispatcher mDispatcher;
+
+ DBusConnection* g_conn_sender{NULL};
+ DBusConnection* g_conn_listener{NULL};
+
+ Ecore_Fd_Handler* g_dbus_fd_handler{NULL};
+
+ int g_streaming_data_serial{0};
+
+ CServiceMain* mServiceMain{nullptr};
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SERVICE_IPC_DBUS_H__ */
--- /dev/null
+/*
+ * Copyright 2018-2019 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 __SERVICE_IPC_DBUS_DISPATCHER_H__
+#define __SERVICE_IPC_DBUS_DISPATCHER_H__
+
+#include <dbus/dbus.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+class CServiceMain;
+
+class CServiceIpcDbusDispatcher {
+public:
+ CServiceIpcDbusDispatcher() {}
+ virtual ~CServiceIpcDbusDispatcher() {}
+
+ int on_hello(DBusConnection* conn, DBusMessage* msg);
+ int on_initialize(DBusConnection* conn, DBusMessage* msg);
+ int on_deinitialize(DBusConnection* conn, DBusMessage* msg);
+ int on_get_audio_format(DBusConnection* conn, DBusMessage* msg);
+ int on_get_audio_source_type(DBusConnection* conn, DBusMessage* msg);
+ int on_send_asr_result(DBusConnection* conn, DBusMessage* msg);
+ int on_send_result(DBusConnection* conn, DBusMessage* msg);
+ int on_send_recognition_result(DBusConnection* conn, DBusMessage* msg);
+ int on_start_streaming_audio_data(DBusConnection* conn, DBusMessage* msg);
+ int on_stop_streaming_audio_data(DBusConnection* conn, DBusMessage* msg);
+ int on_update_voice_feedback_state(DBusConnection* conn, DBusMessage* msg);
+ int on_send_assistant_specific_command(DBusConnection* conn, DBusMessage* msg);
+ int on_set_background_volume(DBusConnection* conn, DBusMessage* msg);
+ int on_set_preprocessing_allow_mode(DBusConnection* conn, DBusMessage* msg);
+ int on_send_preprocessing_result(DBusConnection* conn, DBusMessage* msg);
+ int on_set_wake_word_audio_require_flag(DBusConnection* conn, DBusMessage* msg);
+ int on_set_assistant_language(DBusConnection* conn, DBusMessage* msg);
+ int on_add_wake_word(DBusConnection* conn, DBusMessage* msg);
+ int on_remove_wake_word(DBusConnection* conn, DBusMessage* msg);
+ int on_ui_initialize(DBusConnection* conn, DBusMessage* msg);
+ int on_ui_deinitialize(DBusConnection* conn, DBusMessage* msg);
+ int on_ui_change_assistant(DBusConnection* conn, DBusMessage* msg);
+
+ void set_service_main(CServiceMain* main) { mServiceMain = main; }
+private:
+ CServiceMain* mServiceMain{nullptr};
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __SERVICE_IPC_DBUS_DISPATCHER_H__ */
--- /dev/null
+/*
+ * Copyright 2018-2019 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 __SERVICE_MAIN_H__
+#define __SERVICE_MAIN_H__
+
+#include <string>
+
+#include <dlog/dlog.h>
+#include <multi_assistant.h>
+#include <multi_assistant_internal.h>
+#include <package_manager.h>
+
+#include "service_common.h"
+#include "service_config.h"
+#include "service_plugin.h"
+#include "service_ipc_dbus.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define MAX_APPID_LEN 255
+
+typedef enum {
+ CLIENT_LAUNCH_MODE_ACTIVATION,
+ CLIENT_LAUNCH_MODE_PRELAUNCH,
+} CLIENT_LAUNCH_MODE;
+
+typedef enum {
+ PREPROCESSING_STATE_NONE,
+ PREPROCESSING_STATE_WAKEUP_PREPROCESS_ENABLED,
+ PREPROCESSING_STATE_WAKEUP_PREPROCESS_DISABLED,
+ PREPROCESSING_STATE_PREPROCESSING_UTTERANCE,
+ PREPROCESSING_STATE_PREPROCESSING_FOLLOW_UP,
+} PREPROCESSING_STATE;
+
+typedef enum {
+ PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED,
+ PREPROCESSING_STATE_EVENT_PREPROCESSING_ALLOW_MODE_CHANGED,
+ PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED,
+ PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED,
+ PREPROCESSING_STATE_EVENT_PREPROCESSING_SUCCEEDED,
+ PREPROCESSING_STATE_EVENT_PREPROCESSING_FAILED,
+} PREPROCESSING_STATE_EVENT;
+
+#define ENABLE_MULTI_ASSISTANT_BY_DEFAULT
+
+#define MULTI_ASSISTANT_SETTINGS_ACTIVATED "db/multi-assistant/activated"
+#define WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID "db/multi-assistant/preprocessing_assistant_appid"
+#define WAKEUP_SETTINGS_KEY_PRELAUNCH_MODE "db/multi-assistant/prelaunch_mode"
+
+#define MAX_MACLIENT_INFO_NUM 16
+
+typedef struct {
+ int pid;
+ char appid[MAX_APPID_LEN];
+} ma_client_s;
+
+class CServiceMain {
+public:
+ CServiceMain() {}
+ virtual ~CServiceMain() {}
+
+ int mas_client_initialize(int pid);
+ int mas_client_deinitialize(int pid);
+ int mas_client_get_audio_format(int pid, int* rate, int* channel, int* audio_type);
+ int mas_client_get_audio_source_type(int pid, char** type);
+ int mas_client_send_preprocessing_information(int pid);
+ int mas_client_send_voice_key_status_change(int pid, ma_voice_key_status_e status);
+ int mas_client_activate(int pid);
+ int mas_client_deactivate(int pid);
+ int mas_client_request_speech_data(int pid);
+ int mas_client_send_asr_result(int pid, int event, char* asr_result);
+ int mas_client_send_result(int pid, char* display_text, char* utterance_text, char* result_json);
+ int mas_client_send_recognition_result(int pid, int result);
+ int mas_client_start_streaming_audio_data(int pid, int type);
+ int mas_client_stop_streaming_audio_data(int pid, int type);
+ int mas_client_update_voice_feedback_state(int pid, int state);
+ int mas_client_set_assistant_specific_command(int pid, const char *command);
+ int mas_client_set_background_volume(int pid, double ratio);
+ int mas_client_set_preprocessing_allow_mode(int pid, ma_preprocessing_allow_mode_e mode, const char* appid);
+ int mas_client_send_preprocessing_result(int pid, bool result);
+ int mas_client_set_wake_word_audio_require_flag(int pid, bool require);
+ int mas_client_set_assistant_language(int pid, const char* language);
+ int mas_client_add_wake_word(int pid, const char* wake_word, const char* language);
+ int mas_client_remove_wake_word(int pid, const char* wake_word, const char* language);
+ int mas_ui_client_initialize(int pid);
+ int mas_ui_client_deinitialize(int pid);
+ int mas_ui_client_change_assistant(const char* appid);
+ int mas_get_current_client_pid();
+ int mas_get_current_preprocessing_client_pid();
+ int mas_get_client_pid_by_wakeup_word(const char *wakeup_word);
+ int mas_get_client_pid_by_appid(const char *appid);
+ const char* mas_get_client_appid_by_pid(int pid);
+ bool mas_get_client_custom_ui_option_by_appid(const char *appid);
+ const char* mas_get_client_appid_by_wakeup_word(const char *wakeup_word);
+ int mas_set_current_client_by_wakeup_word(const char *wakeup_word);
+ int mas_set_current_client_by_appid(const char *appid);
+ int mas_launch_client_by_wakeup_word(const char *wakeup_word);
+ int mas_prelaunch_default_assistant();
+ int mas_set_current_service_state(ma_service_state_e state);
+ int mas_bring_client_to_foreground(const char* appid);
+ ma_service_state_e mas_get_current_service_state();
+ int mas_launch_client_by_appid(const char *appid, CLIENT_LAUNCH_MODE launch_mode);
+ int mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event);
+ int mas_update_voice_key_support_mode();
+
+ bool app_create(void *data);
+ void app_terminate(void *data);
+
+ int initialize_service_plugin(void);
+ int deinitialize_service_plugin(void);
+
+ bool is_valid_wakeup_engine(const char* appid);
+ int process_activated_setting();
+
+ int add_assistant_info(ma_assistant_info_s* info);
+
+ CServicePlugin* get_service_plugin() { return &mServicePlugin; }
+private:
+ int ma_client_create(ma_client_s *info);
+ int ma_client_destroy(ma_client_s *client);
+ ma_client_s* ma_client_find_by_appid(const char *appid);
+ ma_client_s* ma_client_find_by_pid(int pid);
+
+ bool check_preprocessing_assistant_exists();
+ ma_preprocessing_allow_mode_e get_preprocessing_allow_mode(const char* appid);
+ bool is_current_preprocessing_assistant(const char* appid);
+
+private:
+ std::string g_current_lang{"en_US"};
+
+ typedef struct {
+ bool used;
+ char appid[MAX_APPID_LEN];
+ char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN];
+ char wakeup_language[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN];
+ char wakeup_engine[MAX_APPID_LEN];
+ char supported_language[MAX_SUPPORTED_LANGUAGES_NUM][MAX_SUPPORTED_LANGUAGE_LEN];
+ bool custom_ui_option;
+ VOICE_KEY_SUPPORT_MODE voice_key_support_mode;
+ float voice_key_tap_duration;
+
+ ma_preprocessing_allow_mode_e preprocessing_allow_mode;
+ char preprocessing_allow_appid[MAX_APPID_LEN];
+ } ma_client_info;
+
+ ma_client_info g_maclient_info[MAX_MACLIENT_INFO_NUM];
+
+ int g_current_maclient_info{0};
+ int g_current_preprocessing_maclient_info{-1};
+ std::string g_wakeup_maclient_appid;
+ package_manager_h g_pkgmgr{NULL};
+
+ PREPROCESSING_STATE g_current_preprocessing_state{PREPROCESSING_STATE_NONE};
+ ma_service_state_e g_current_service_state{MA_SERVICE_STATE_INACTIVE};
+
+ /* client list */
+ GSList* g_client_list{nullptr};
+
+ CServiceConfig mServiceConfig;
+ CServicePlugin mServicePlugin;
+ CServiceIpcDbus mServiceIpc;
+
+ ma_voice_key_status_e mLastVoiceKeyStatus{MA_VOICE_KEY_STATUS_RELEASED_AFTER_PUSH};
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SERVICE_MAIN_H__ */
--- /dev/null
+/*
+ * Copyright 2018-2019 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 __SERVICE_PLUGIN_H__
+#define __SERVICE_PLUGIN_H__
+
+#include <tzplatform_config.h>
+
+#include "service_common.h"
+#include "service_ipc_dbus.h"
+#include "service_plugin_interface.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+class CServiceMain;
+
+class CServicePlugin {
+public:
+ CServicePlugin() {};
+ virtual ~CServicePlugin() {};
+
+ int initialize(void);
+ int deinitialize(void);
+ int get_settings(ma_plugin_settings **settings, size_t *struct_size);
+ int set_language(const char* language);
+ int add_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language);
+ int remove_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language);
+ int add_assistant_language(const char* appid, const char* language);
+ int set_assistant_wakeup_engine(const char* appid, const char* engine);
+ int set_default_assistant(const char* appid);
+ int get_default_assistant(const char** appid);
+ int activate(void);
+ int deactivate(void);
+ int update_voice_feedback_state(const char* appid, int state);
+ int set_assistant_specific_command(const char *appid, const char* command);
+ int set_background_volume(const char *appid, double ratio);
+ int update_recognition_result(const char* appid, int result);
+ int set_preprocessing_allow_mode(const char* appid, int mode, const char* preprocessing_appid);
+ int process_event(int event, void* data, int len);
+ int start_streaming_utterance_data(void);
+ int stop_streaming_utterance_data(void);
+ int start_streaming_previous_utterance_data(void);
+ int stop_streaming_previous_utterance_data(void);
+ int start_streaming_follow_up_data(void);
+ int stop_streaming_follow_up_data(void);
+ int get_recording_audio_format(int* rate, int* channel, int* audio_type);
+ int get_recording_audio_source_type(char **type);
+ int set_wake_word_audio_require_flag(const char* appid, bool require);
+ int set_assistant_language(const char* appid, const char* language);
+ int set_voice_key_support_mode(int mode);
+ int set_voice_key_tap_duration(float duration);
+ int unset_voice_key_tap_duration(void);
+ int set_callbacks(void);
+ int set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data);
+ int set_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data);
+ int set_previous_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data);
+ int set_follow_up_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data);
+ int set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data);
+ int set_setting_changed_callback(wakeup_service_setting_changed_cb callback, void* user_data);
+ int set_error_callback(wakeup_service_error_cb callback, void* user_data);
+ int set_streaming_section_changed_callback(wakeup_service_streaming_section_changed_cb callback, void* user_data);
+ int set_wakeup_engine_command_callback(wakeup_service_wakeup_engine_command_cb callback, void* user_data);
+ int set_wakeup_service_state_changed_callback(wakeup_service_wakeup_service_state_changed_cb callback, void* user_data);
+ int set_voice_key_status_changed_callback(wakeup_service_voice_key_status_changed_cb callback, void* user_data);
+
+ bool is_ui_panel_enabled();
+
+ void set_service_ipc(CServiceIpcDbus* ipc) { mServiceIpc = ipc; }
+ CServiceIpcDbus* get_service_ipc() { return mServiceIpc; }
+
+ void set_service_main(CServiceMain* main) { mServiceMain = main; }
+ CServiceMain* get_service_main() { return mServiceMain; }
+private:
+#ifdef BUF_SAVE_MODE
+ char g_temp_file_name[128] = {'\0', };
+ FILE* g_pFile = NULL;
+ int g_count = 1;
+#endif
+
+ void *g_handle = NULL;
+
+ wakeup_manager_interface _wakeup_manager_interface{NULL, };
+ ma_plugin_settings* g_plugin_settings{NULL};
+
+ CServiceIpcDbus* mServiceIpc{nullptr};
+ CServiceMain* mServiceMain{nullptr};
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SERVICE_PLUGIN_H__ */
--- /dev/null
+/*
+ * Copyright 2018-2019 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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 __SERVICE_PLUGIN_INTERFACE_H__
+#define __SERVICE_PLUGIN_INTERFACE_H__
+
+#include <tzplatform_config.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct {
+ int plugin_version;
+ bool ui_panel_enabled;
+} ma_plugin_settings;
+
+#define MA_WAKEUP_MANAGER_PATH tzplatform_mkpath(tzplatform_getid("TZ_SYS_RO_SHARE"), "multiassistant/")
+
+#define MA_DEFAULT_WAKEUP_MANAGER_FILENAME "libma-wakeup-manager.so"
+
+#define MA_WAKEUP_MANAGER_FUNC_INITIALIZE "wakeup_manager_initialize"
+typedef int (*wakeup_manager_initialize)(void);
+#define MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE "wakeup_manager_deinitialize"
+typedef int (*wakeup_manager_deinitialize)(void);
+#define MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS "wakeup_manager_get_settings"
+typedef int (*wakeup_manager_get_settings)(ma_plugin_settings **settings, size_t *struct_size);
+#define MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_WORD "wakeup_manager_add_assistant_wakeup_word"
+typedef int (*wakeup_manager_add_assistant_wakeup_word)(const char* appid, const char* wakeup_word, const char* language);
+#define MA_WAKEUP_MANAGER_FUNC_REMOVE_ASSISTANT_WAKEUP_WORD "wakeup_manager_remove_assistant_wakeup_word"
+typedef int (*wakeup_manager_remove_assistant_wakeup_word)(const char* appid, const char* wakeup_word, const char* language);
+#define MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE "wakeup_manager_add_assistant_language"
+typedef int (*wakeup_manager_add_assistant_language)(const char* appid, const char* language);
+#define MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE "wakeup_manager_set_assistant_wakeup_engine"
+typedef int (*wakeup_manager_set_assistant_wakeup_engine)(const char* appid, const char* engine);
+#define MA_WAKEUP_MANAGER_FUNC_SET_DEFAULT_ASSISTANT "wakeup_manager_set_default_assistant"
+typedef int (*wakeup_manager_set_default_assistant)(const char* appid);
+#define MA_WAKEUP_MANAGER_FUNC_GET_DEFAULT_ASSISTANT "wakeup_manager_get_default_assistant"
+typedef int (*wakeup_manager_get_default_assistant)(const char** appid);
+#define MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE "wakeup_manager_set_language"
+typedef int (*wakeup_manager_set_language)(const char* language);
+#define MA_WAKEUP_MANAGER_FUNC_ACTIVATE "wakeup_manager_activate"
+typedef int (*wakeup_manager_activate)(void);
+#define MA_WAKEUP_MANAGER_FUNC_DEACTIVATE "wakeup_manager_deactivate"
+typedef int (*wakeup_manager_deactivate)(void);
+#define MA_WAKEUP_MANAGER_FUNC_UPDATE_VOICE_FEEDBACK_STATE "wakeup_manager_update_voice_feedback_state"
+typedef int (*wakeup_manager_update_voice_feedback_state)(const char* appid, int state);
+#define MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND "wakeup_manager_set_assistant_specific_command"
+typedef int (*wakeup_manager_set_assistant_specific_command)(const char* appid, const char* command);
+#define MA_WAKEUP_MANAGER_FUNC_SET_BACKGROUND_VOLUME "wakeup_manager_set_background_volume"
+typedef int (*wakeup_manager_set_background_volume)(const char* appid, double ratio);
+#define MA_WAKEUP_MANAGER_FUNC_UPDATE_RECOGNITION_RESULT "wakeup_manager_update_recognition_result"
+typedef int (*wakeup_manager_update_recognition_result)(const char* appid, int result);
+#define MA_WAKEUP_MANAGER_FUNC_PROCESS_PLUGIN_EVENT "wakeup_manager_process_plugin_event"
+typedef int (*wakeup_manager_process_plugin_event)(int event, void* data, int len);
+#define MA_WAKEUP_MANAGER_FUNC_START_STREAMING_UTTERANCE_DATA "wakeup_manager_start_streaming_utterance_data"
+typedef int (*wakeup_manager_start_streaming_utterance_data)(void);
+#define MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_UTTERANCE_DATA "wakeup_manager_stop_streaming_utterance_data"
+typedef int (*wakeup_manager_stop_streaming_utterance_data)(void);
+#define MA_WAKEUP_MANAGER_FUNC_START_STREAMING_PREVIOUS_UTTERANCE_DATA "wakeup_manager_start_streaming_previous_utterance_data"
+typedef int (*wakeup_manager_start_streaming_previous_utterance_data)(void);
+#define MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_PREVIOUS_UTTERANCE_DATA "wakeup_manager_stop_streaming_previous_utterance_data"
+typedef int (*wakeup_manager_stop_streaming_previous_utterance_data)(void);
+#define MA_WAKEUP_MANAGER_FUNC_START_STREAMING_FOLLOW_UP_DATA "wakeup_manager_start_streaming_follow_up_data"
+typedef int (*wakeup_manager_start_streaming_follow_up_data)(void);
+#define MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_FOLLOW_UP_DATA "wakeup_manager_stop_streaming_follow_up_data"
+typedef int (*wakeup_manager_stop_streaming_follow_up_data)(void);
+#define MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_FORMAT "wakeup_manager_get_audio_format"
+typedef int (*wakeup_manager_get_audio_format)(int* rate, int* channel, int* audio_type);
+#define MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_SOURCE_TYPE "wakeup_manager_get_audio_source_type"
+typedef int (*wakeup_manager_get_audio_source_type)(char** type);
+#define MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_TAP_DURATION "wakeup_manager_set_voice_key_tap_duration"
+typedef int (*wakeup_manager_set_voice_key_tap_duration)(float duration);
+#define MA_WAKEUP_MANAGER_FUNC_UNSET_VOICE_KEY_TAP_DURATION "wakeup_manager_unset_voice_key_tap_duration"
+typedef int (*wakeup_manager_unset_voice_key_tap_duration)();
+#define MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_SUPPORT_MODE "wakeup_manager_set_voice_key_support_mode"
+typedef int (*wakeup_manager_set_voice_key_support_mode)(int mode);
+#define MA_WAKEUP_MANAGER_FUNC_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG "wakeup_manager_set_wake_word_audio_require_flag"
+typedef int (*wakeup_manager_set_wake_word_audio_require_flag)(bool require);
+#define MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_LANGUAGE "wakeup_manager_set_assistant_language"
+typedef int (*wakeup_manager_set_assistant_language)(const char* appid, const char* language);
+#define MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_EVENT_CALLBACK "wakeup_manager_set_wakeup_event_callback"
+typedef int (*wakeup_manager_set_wakeup_event_callback)(wakeup_service_wakeup_event_cb callback, void* user_data);
+#define MA_WAKEUP_MANAGER_FUNC_SET_UTTERANCE_STREAMING_CALLBACK "wakeup_manager_set_utterance_streaming_callback"
+typedef int (*wakeup_manager_set_utterance_streaming_callback)(wakeup_service_speech_streaming_cb callback, void* user_data);
+#define MA_WAKEUP_MANAGER_FUNC_SET_PREVIOUS_UTTERANCE_STREAMING_CALLBACK "wakeup_manager_set_previous_utterance_streaming_callback"
+typedef int (*wakeup_manager_set_previous_utterance_streaming_callback)(wakeup_service_speech_streaming_cb callback, void* user_data);
+#define MA_WAKEUP_MANAGER_FUNC_SET_FOLLOW_UP_STREAMING_CALLBACK "wakeup_manager_set_follow_up_streaming_callback"
+typedef int (*wakeup_manager_set_follow_up_streaming_callback)(wakeup_service_speech_streaming_cb callback, void* user_data);
+#define MA_WAKEUP_MANAGER_FUNC_SET_SPEECH_STATUS_CALLBACK "wakeup_manager_set_speech_status_callback"
+typedef int (*wakeup_manager_set_speech_status_callback)(wakeup_service_speech_status_cb callback, void* user_data);
+#define MA_WAKEUP_MANAGER_FUNC_SET_SETTING_CHANGED_CALLBACK "wakeup_manager_set_setting_changed_callback"
+typedef int (*wakeup_manager_set_setting_changed_callback)(wakeup_service_setting_changed_cb callback, void* user_data);
+#define MA_WAKEUP_MANAGER_FUNC_SET_ERROR_CALLBACK "wakeup_manager_set_error_callback"
+typedef int (*wakeup_manager_set_error_callback)(wakeup_service_error_cb callback, void* user_data);
+#define MA_WAKEUP_MANAGER_FUNC_SET_STREAMING_SECTION_CHANGED_CALLBACK "wakeup_manager_set_streaming_section_changed_callback"
+typedef int (*wakeup_manager_set_streaming_section_changed_callback)(wakeup_service_streaming_section_changed_cb callback, void* user_data);
+#define MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_ENGINE_COMMAND_CALLBACK "wakeup_manager_set_wakeup_engine_command_callback"
+typedef int (*wakeup_manager_set_wakeup_engine_command_callback)(wakeup_service_wakeup_engine_command_cb callback, void* user_data);
+#define MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_SERVICE_STATE_CHANGED_CALLBACK "wakeup_manager_set_wakeup_service_state_changed_callback"
+typedef int (*wakeup_manager_set_wakeup_service_state_changed_callback)(wakeup_service_wakeup_service_state_changed_cb callback, void* user_data);
+#define MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_STATUS_CHANGED_CALLBACK "wakeup_manager_set_voice_key_status_changed_callback"
+typedef int (*wakeup_manager_set_voice_key_status_changed_callback)(wakeup_service_voice_key_status_changed_cb callback, void* user_data);
+
+typedef struct {
+ wakeup_manager_initialize initialize;
+ wakeup_manager_deinitialize deinitialize;
+ wakeup_manager_get_settings get_settings;
+ wakeup_manager_add_assistant_wakeup_word add_assistant_wakeup_word;
+ wakeup_manager_remove_assistant_wakeup_word remove_assistant_wakeup_word;
+ wakeup_manager_add_assistant_language add_assistant_language;
+ wakeup_manager_set_assistant_wakeup_engine set_assistant_wakeup_engine;
+ wakeup_manager_set_default_assistant set_default_assistant;
+ wakeup_manager_get_default_assistant get_default_assistant;
+ wakeup_manager_set_language set_language;
+ wakeup_manager_activate activate;
+ wakeup_manager_deactivate deactivate;
+ wakeup_manager_update_voice_feedback_state update_voice_feedback_state;
+ wakeup_manager_set_assistant_specific_command set_assistant_specific_command;
+ wakeup_manager_set_background_volume set_background_volume;
+ wakeup_manager_update_recognition_result update_recognition_result;
+ wakeup_manager_process_plugin_event process_plugin_event;
+ wakeup_manager_start_streaming_utterance_data start_streaming_utterance_data;
+ wakeup_manager_stop_streaming_utterance_data stop_streaming_utterance_data;
+ wakeup_manager_start_streaming_previous_utterance_data start_streaming_previous_utterance_data;
+ wakeup_manager_stop_streaming_previous_utterance_data stop_streaming_previous_utterance_data;
+ wakeup_manager_start_streaming_follow_up_data start_streaming_follow_up_data;
+ wakeup_manager_stop_streaming_follow_up_data stop_streaming_follow_up_data;
+ wakeup_manager_get_audio_format get_audio_format;
+ wakeup_manager_get_audio_source_type get_audio_source_type;
+ wakeup_manager_set_voice_key_tap_duration set_voice_key_tap_duration;
+ wakeup_manager_unset_voice_key_tap_duration unset_voice_key_tap_duration;
+ wakeup_manager_set_voice_key_support_mode set_voice_key_support_mode;
+ wakeup_manager_set_wake_word_audio_require_flag set_wake_word_audio_require_flag;
+ wakeup_manager_set_assistant_language set_assistant_language;
+ wakeup_manager_set_wakeup_event_callback set_wakeup_event_callback;
+ wakeup_manager_set_utterance_streaming_callback set_utterance_streaming_callback;
+ wakeup_manager_set_previous_utterance_streaming_callback set_previous_utterance_streaming_callback;
+ wakeup_manager_set_follow_up_streaming_callback set_follow_up_streaming_callback;
+ wakeup_manager_set_speech_status_callback set_speech_status_callback;
+ wakeup_manager_set_setting_changed_callback set_setting_changed_callback;
+ wakeup_manager_set_error_callback set_error_callback;
+ wakeup_manager_set_streaming_section_changed_callback set_streaming_section_changed_callback;
+ wakeup_manager_set_wakeup_engine_command_callback set_wakeup_engine_command_callback;
+ wakeup_manager_set_wakeup_service_state_changed_callback set_wakeup_service_state_changed_callback;
+ wakeup_manager_set_voice_key_status_changed_callback set_voice_key_status_changed_callback;
+} wakeup_manager_interface;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SERVICE_PLUGIN_INTERFACE_H__ */
#ifndef _WAKEUP_MANAGER_H_
#define _WAKEUP_MANAGER_H_
-#include "multi_assistant_config.h"
+#include "service_config.h"
#include "wakeup_manager_wrapper.h"
#include "wakeup_settings.h"
#include "wakeup_engine_manager.h"
#include <stdexcept>
-#include "multi_assistant_main.h"
+#include "service_common.h"
#include "dependency_resolver.h"
#ifdef LOG_TAG
#include <tizen.h>
#include <service_app.h>
-#include "multi_assistant_service_client.h"
+#include "service_main.h"
+
+CServiceMain g_service_main;
static bool service_app_create(void *data)
{
- return app_create(data);
+ return g_service_main.app_create(data);
}
static void service_app_terminate(void *data)
{
-
- return app_terminate(data);
+ return g_service_main.app_terminate(data);
}
static void service_app_control(app_control_h app_control, void *data)
int main(int argc, char* argv[])
{
- char ad[50] = {0,};
+ char ad[50] = {0, };
service_app_lifecycle_callback_s event_callback;
app_event_handler_h handlers[5] = {NULL, };
+++ /dev/null
-/*
- * Copyright 2018-2019 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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.
- */
-
-#include <libxml/parser.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <unistd.h>
-
-#include <app_preference.h>
-
-#include "multi_assistant_config.h"
-#include "multi_assistant_main.h"
-
-int CConfig::mas_config_parse_assistant_info(mas_config_assistant_info_cb callback,
- const char *path, void* user_data)
-{
- xmlDocPtr doc = NULL;
- xmlNodePtr cur = NULL;
- xmlChar *key;
-
- int loop;
- int retry_count = 0;
-
- while (NULL == doc) {
- doc = xmlParseFile(path);
- if (NULL != doc) {
- break;
- }
-
- if (MA_RETRY_COUNT == retry_count++) {
- MAS_LOGE("[ERROR] Fail to parse file error : %s", path);
- xmlCleanupParser();
- return -1;
- }
- usleep(10000);
- }
-
- cur = xmlDocGetRootElement(doc);
- if (cur == NULL) {
- MAS_LOGE("[ERROR] Empty document");
- xmlFreeDoc(doc);
- return -1;
- }
-
- if (xmlStrcmp(cur->name, (const xmlChar *) MA_TAG_ASSISTANT_BASE)) {
- MAS_LOGE("[ERROR] The wrong type, root node is NOT %s", MA_TAG_ASSISTANT_BASE);
- xmlFreeDoc(doc);
- return -1;
- }
-
- cur = cur->xmlChildrenNode;
- if (cur == NULL) {
- MAS_LOGE("[ERROR] Empty document");
- xmlFreeDoc(doc);
- return -1;
- }
-
- /* alloc assistant info */
- ma_assistant_info_s temp;
-
- temp.app_id = NULL;
- temp.name = NULL;
- temp.icon_path = NULL;
- memset(temp.wakeup_list, 0x00, sizeof(temp.wakeup_list));
- memset(temp.wakeup_language, 0x00, sizeof(temp.wakeup_language));
- temp.cnt_wakeup = 0;
- memset(temp.supported_lang, 0x00, sizeof(temp.supported_lang));
- temp.cnt_lang = 0;
- temp.wakeup_engine = NULL;
- temp.custom_ui_option = false;
- /* TODO: Define these two default values somewhere else */
- temp.voice_key_support_mode = VOICE_KEY_SUPPORT_MODE_PUSH_TO_TALK;
- temp.voice_key_tap_duration = 0.0f; /* Meaning not set */
-
- while (cur != NULL) {
- if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar *)MA_TAG_ASSISTANT_LANGUAGE_SET)) {
- xmlNodePtr child_node = cur->xmlChildrenNode;
- while (child_node != NULL) {
- if (child_node->name && 0 == xmlStrcmp(child_node->name, (const xmlChar*)MA_TAG_ASSISTANT_LANGUAGE)) {
- key = xmlNodeGetContent(child_node);
- if (key) {
- temp.supported_lang[temp.cnt_lang++] = strdup((const char*)key);
- MAS_LOGD("Language : %s", key);
- xmlFree(key);
- }
- }
-
- child_node = child_node->next;
- }
- } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar *)MA_TAG_ASSISTANT_WAKEUP_WORD_SET)) {
- xmlNodePtr child_node = cur->xmlChildrenNode;
- while (child_node != NULL) {
- if (child_node->name && 0 == xmlStrcmp(child_node->name, (const xmlChar*)MA_TAG_ASSISTANT_WAKEUP_WORD)) {
- key = xmlNodeGetContent(child_node);
- if (key) {
- temp.wakeup_list[temp.cnt_wakeup] = strdup((const char*)key);
- MAS_LOGD("Wakeup Word : %s", key);
- xmlFree(key);
- }
- xmlChar* prop = xmlNodeGetLang(child_node);
- if (prop) {
- temp.wakeup_language[temp.cnt_wakeup] = strdup((const char*)prop);
- MAS_LOGD("Wakeup Language for %s : %s", temp.wakeup_list[temp.cnt_wakeup], prop);
- xmlFree(prop);
- }
- temp.cnt_wakeup++;
- }
-
- child_node = child_node->next;
- }
- } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_NAME)) {
- key = xmlNodeGetContent(cur);
- if (key) {
- temp.name = strdup((const char*)key);
- MAS_LOGD("Name : %s", key);
- xmlFree(key);
- }
- } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_APPID)) {
- key = xmlNodeGetContent(cur);
- if (key) {
- temp.app_id = strdup((const char*)key);
- MAS_LOGD("ID : %s", key);
- xmlFree(key);
- }
- } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_ICON_PATH)) {
- key = xmlNodeGetContent(cur);
- if (key) {
- temp.icon_path = strdup((const char*)key);
- MAS_LOGD("Icon Path : %s", key);
- xmlFree(key);
- }
- } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_WAKEUP_ENGINE_APPID)) {
- key = xmlNodeGetContent(cur);
- if (key) {
- temp.wakeup_engine = strdup((const char*)key);
- MAS_LOGD("Wakeup Engine : %s", key);
- xmlFree(key);
- }
- } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_CUSTOM_UI)) {
- key = xmlNodeGetContent(cur);
- if (key) {
- if (0 == xmlStrcasecmp(key, reinterpret_cast<const xmlChar*>("true"))) {
- temp.custom_ui_option = true;
- }
- MAS_LOGD("Use custom UI : %d", temp.custom_ui_option);
- xmlFree(key);
- }
- } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_VOICE_KEY_SUPPORT_MODE)) {
- key = xmlNodeGetContent(cur);
- if (key) {
- if (xmlStrcmp(cur->name, (const xmlChar*)VOICE_KEY_SUPPORT_MODE_STRING_ALL)) {
- temp.voice_key_support_mode = VOICE_KEY_SUPPORT_MODE_ALL;
- } else if (xmlStrcmp(cur->name, (const xmlChar*)VOICE_KEY_SUPPORT_MODE_STRING_TAP_TO_TALK)) {
- temp.voice_key_support_mode = VOICE_KEY_SUPPORT_MODE_TAP_TO_TALK;
- } else if (xmlStrcmp(cur->name, (const xmlChar*)VOICE_KEY_SUPPORT_MODE_STRING_PUSH_TO_TALK)) {
- temp.voice_key_support_mode = VOICE_KEY_SUPPORT_MODE_PUSH_TO_TALK;
- } else {
- temp.voice_key_support_mode = VOICE_KEY_SUPPORT_MODE_NONE;
- }
- MAS_LOGD("Voice key support mode : %s", cur->name);
- xmlFree(key);
- }
- } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_VOICE_KEY_TAP_DURATION)) {
- key = xmlNodeGetContent(cur);
- if (key) {
- temp.voice_key_tap_duration = atof((const char*)key);
- MAS_LOGD("Voice key tap duration : %s", key);
- xmlFree(key);
- }
- }
-
- cur = cur->next;
- }
-
- if (callback) {
- callback(&temp, user_data);
- }
-
- if (temp.app_id) {
- free((void*)temp.app_id);
- }
- if (temp.name) {
- free((void*)temp.name);
- }
- if (temp.icon_path) {
- free((void*)temp.icon_path);
- }
- for (loop = 0; loop < temp.cnt_wakeup; loop++) {
- if (temp.wakeup_list[loop]) {
- free((void*)(temp.wakeup_list[loop]));
- }
- }
- for (loop = 0; loop < temp.cnt_lang; loop++) {
- if (temp.supported_lang[loop]) {
- free((void*)(temp.supported_lang[loop]));
- }
- }
- if (temp.wakeup_engine) {
- free((void*)temp.wakeup_engine);
- }
-
- xmlFreeDoc(doc);
-
- return 0;
-}
-
-int CConfig::mas_config_get_assistant_info(mas_config_assistant_info_cb callback, void* user_data)
-{
- const char *suffix = ".xml";
-
- DIR *d;
- struct dirent *dir;
- d = opendir(MA_ASSISTANT_INFO);
-
- if (d) {
- while (NULL != (dir = readdir(d))) {
- if (suffix && strlen(suffix) <= strlen(dir->d_name)) {
- if (0 == strcmp(dir->d_name + strlen(dir->d_name) - strlen(suffix), suffix)) {
- char fullpath[_POSIX_PATH_MAX];
- snprintf(fullpath, _POSIX_PATH_MAX - 1, "%s/%s", MA_ASSISTANT_INFO, dir->d_name);
- MAS_LOGD("Parsing file : %s\n", fullpath);
- mas_config_parse_assistant_info(callback, fullpath, user_data);
- }
- }
- }
- closedir(d);
- }
-
- return 0;
-}
-
-int CConfig::mas_config_add_custom_wake_word(const char* wake_word, const char* language,
- char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
- char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN])
-{
- if (nullptr == wake_word || nullptr == language) return -1;
-
- bool found = false;
- for (int loop = 0;false == found && loop < MAX_WAKEUP_WORDS_NUM;loop++) {
- if (0 == strncmp(wakeup_word_storage[loop], wake_word, MAX_WAKEUP_WORD_LEN) &&
- 0 == strncmp(wakeup_language_storage[loop], language, MAX_SUPPORTED_LANGUAGE_LEN)) {
- LOGE("The wakeup word already exists!");
- return -1; /* Already exists */
- }
- if (0 == strlen(wakeup_word_storage[loop])) {
- strncpy(wakeup_word_storage[loop], wake_word, MAX_WAKEUP_WORD_LEN);
- wakeup_word_storage[loop][MAX_WAKEUP_WORD_LEN - 1] = '\0';
- strncpy(wakeup_language_storage[loop], language, MAX_SUPPORTED_LANGUAGE_LEN);
- wakeup_language_storage[loop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
- found = true;
- }
- }
- if (!found) {
- LOGE("No empty slot found while trying to add new wake word!");
- return -1;
- }
- return 0;
-}
-
-int CConfig::mas_config_remove_custom_wake_word(const char* wake_word, const char* language,
- char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
- char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN])
-{
- if (nullptr == wake_word || nullptr == language) return -1;
-
- bool found = false;
- for (int loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) {
- if (0 == strncmp(wakeup_word_storage[loop], wake_word, MAX_WAKEUP_WORD_LEN) &&
- 0 == strncmp(wakeup_language_storage[loop], language, MAX_SUPPORTED_LANGUAGE_LEN)) {
- for (int shift = loop;shift < MAX_WAKEUP_WORDS_NUM - 1;shift++) {
- strncpy(wakeup_word_storage[shift],
- wakeup_word_storage[shift + 1], MAX_WAKEUP_WORD_LEN);
- wakeup_word_storage[shift][MAX_WAKEUP_WORD_LEN - 1] = '\0';
- strncpy(wakeup_language_storage[shift],
- wakeup_language_storage[shift + 1], MAX_SUPPORTED_LANGUAGE_LEN);
- wakeup_word_storage[shift][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
- }
- memset(wakeup_word_storage[MAX_WAKEUP_WORDS_NUM - 1],
- 0x00, sizeof(char) * MAX_WAKEUP_WORD_LEN);
- memset(wakeup_language_storage[MAX_WAKEUP_WORDS_NUM - 1],
- 0x00, sizeof(char) * MAX_SUPPORTED_LANGUAGE_LEN);
-
- loop--; /* Just in case there are duplicated items */
- found = true;
- }
- }
- if (!found) return -1;
- return 0;
-}
-
-int CConfig::mas_config_load_custom_wake_words(const char* app_id,
- char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
- char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN])
-{
- /* Add 1 for additional pipe character */
- char wakeup_words[MAX_WAKEUP_WORDS_NUM * (MAX_WAKEUP_WORD_LEN + 1)];
- char wakeup_languages[MAX_WAKEUP_WORDS_NUM * (MAX_SUPPORTED_LANGUAGE_LEN + 1)];
- memset(wakeup_words, 0x00, sizeof(wakeup_words));
- memset(wakeup_languages, 0x00, sizeof(wakeup_languages));
-
- bool existing = false;
- preference_is_existing("custom_wakeup_words", &existing);
- if (!existing) return -1;
- preference_is_existing("custom_wakeup_languages", &existing);
- if (!existing) return -1;
-
- char* value = NULL;
- preference_get_string("custom_wakeup_words", &value);
- if (NULL == value) return -1;
- strncpy(wakeup_words, value, sizeof(wakeup_words) - 1);
- wakeup_words[sizeof(wakeup_words) - 1] = '\0';
- LOGD("Custom wakeup words loaded : %s", wakeup_words);
- free(value);
-
- preference_get_string("custom_wakeup_languages", &value);
- if (NULL == value) return -1;
- strncpy(wakeup_languages, value, sizeof(wakeup_languages) - 1);
- wakeup_languages[sizeof(wakeup_languages) - 1] = '\0';
- LOGD("Custom wakeup languages loaded : %s", wakeup_languages);
- free(value);
-
- char *word_start = wakeup_words;
- char *language_start = wakeup_languages;
- char *word_end = NULL;
- char *language_end = NULL;
- int index = 0;
- while (index < MAX_WAKEUP_WORDS_NUM) {
- word_end = strchrnul(word_start, '|');
- language_end = strchrnul(language_start, '|');
- if ('\0' == *word_end || '\0' == *language_end) break;
- *word_end = '\0';
- *language_end = '\0';
- if (0 == strlen(word_start)) break;
- strncpy(wakeup_word_storage[index], word_start, MAX_WAKEUP_WORD_LEN - 1);
- strncpy(wakeup_language_storage[index], language_start, MAX_WAKEUP_WORD_LEN - 1);
- word_start = word_end + 1;
- language_start = language_end + 1;
- LOGD("Added custom wakeup word : (%s) (%s)",
- wakeup_word_storage[index], wakeup_language_storage[index]);
- index++;
- }
-
- return 0;
-}
-
-int CConfig::mas_config_save_custom_wake_words(const char* app_id,
- char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
- char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN])
-{
- /* Add 1 for additional pipe character */
- char wakeup_words[MAX_WAKEUP_WORDS_NUM * (MAX_WAKEUP_WORD_LEN + 1)];
- char wakeup_languages[MAX_WAKEUP_WORDS_NUM * (MAX_SUPPORTED_LANGUAGE_LEN + 1)];
- memset(wakeup_words, 0x00, sizeof(wakeup_words));
- memset(wakeup_languages, 0x00, sizeof(wakeup_languages));
- for (int loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) {
- if (strlen(wakeup_word_storage[loop]) > 0) {
- int wakeup_words_len = strlen(wakeup_words);
- strncat(wakeup_words, wakeup_word_storage[loop],
- sizeof(wakeup_words) - wakeup_words_len - 1);
- strcat(wakeup_words, "|");
- int wakeup_languages_len = strlen(wakeup_languages);
- strncat(wakeup_languages, wakeup_language_storage[loop],
- sizeof(wakeup_languages) - wakeup_languages_len - 1);
- strcat(wakeup_languages, "|");
- }
- }
- wakeup_words[sizeof(wakeup_words) - 1] = '\0';
- wakeup_languages[sizeof(wakeup_languages) - 1] = '\0';
- preference_set_string("custom_wakeup_words", wakeup_words);
- preference_set_string("custom_wakeup_languages", wakeup_languages);
- return 0;
-}
-
-int CConfig::mas_config_get_custom_wake_word_num(
- char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
- char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN])
-{
- int num = 0;
- for (int loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) {
- if (0 < strlen(wakeup_word_storage[loop])) {
- num++;
- }
- }
- return num;
-}
-
-bool CConfig::mas_config_has_custom_wake_word(const char* wake_word, const char* language,
- char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
- char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN])
-{
- if (nullptr == wake_word || nullptr == language) return false;
-
- for (int loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) {
- if (0 == strncmp(wakeup_word_storage[loop], wake_word, MAX_WAKEUP_WORD_LEN) &&
- 0 == strncmp(wakeup_language_storage[loop], language, MAX_SUPPORTED_LANGUAGE_LEN)) {
- return true;
- }
- }
- return false;
-}
+++ /dev/null
-/*
- * Copyright 2018-2019 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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.
- */
-
-#include <dbus/dbus.h>
-#include <dirent.h>
-#include <dlfcn.h>
-#include <Ecore.h>
-#include <message_port.h>
-
-#include "multi_assistant_main.h"
-#include "multi_assistant_service_client.h"
-#include "multi_assistant_dbus_server.h"
-#include "multi_assistant_dbus.h"
-
-static DBusConnection* g_conn_sender = NULL;
-static DBusConnection* g_conn_listener = NULL;
-
-static Ecore_Fd_Handler* g_dbus_fd_handler = NULL;
-
-static int g_streaming_data_serial = 0;
-
-int mas_dbus_reconnect()
-{
- if (!g_conn_sender || !g_conn_listener) {
- mas_dbus_close_connection();
-
- if (0 != mas_dbus_open_connection()) {
- MAS_LOGE("[ERROR] Fail to reconnect");
- return -1;
- }
-
- MAS_LOGD("[DBUS] Reconnect");
- return 0;
- }
-
- bool sender_connected = dbus_connection_get_is_connected(g_conn_sender);
- bool listener_connected = dbus_connection_get_is_connected(g_conn_listener);
- MAS_LOGW("[DBUS] Sender(%s) Listener(%s)",
- sender_connected ? "Connected" : "Not connected", listener_connected ? "Connected" : "Not connected");
-
- if (false == sender_connected || false == listener_connected) {
- mas_dbus_close_connection();
-
- if (0 != mas_dbus_open_connection()) {
- MAS_LOGE("[ERROR] Fail to reconnect");
- return -1;
- }
-
- MAS_LOGD("[DBUS] Reconnect");
- }
-
- return 0;
-}
-
-static int __dbus_check()
-{
- if (NULL == g_conn_sender || NULL == g_conn_listener) {
- MAS_LOGE("[ERROR] NULL connection");
- return mas_dbus_reconnect();
- }
- return 0;
-}
-
-int mas_check_dbus_connection()
-{
- if (NULL == g_conn_sender || NULL == g_conn_listener) {
- MAS_LOGE("[ERROR] NULL connection sender(%p), listener(%p)", g_conn_sender, g_conn_listener);
- return -1;
- }
- return 0;
-}
-
-int masc_dbus_send_hello(int pid)
-{
- if (0 != __dbus_check()) {
- return -1; //MAS_ERROR_OPERATION_FAILED;
- }
-
- DBusMessage* msg;
- DBusError err;
- dbus_error_init(&err);
-
- msg = dbus_message_new_method_call(
- MA_CLIENT_SERVICE_NAME,
- MA_CLIENT_SERVICE_OBJECT_PATH,
- MA_CLIENT_SERVICE_INTERFACE,
- MAS_METHOD_HELLO);
-
- if (NULL == msg) {
- MAS_LOGE("[DBus ERROR] Request masc hello : Fail to make message");
- return -1;
- }
-
- int result = -1;
- DBusMessage* result_msg = NULL;
- result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, 500, &err);
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[Dbus ERROR] Dbus Error (%s)", err.message);
- dbus_error_free(&err);
- }
-
- dbus_message_unref(msg);
-
- if (NULL != result_msg) {
- dbus_message_unref(result_msg);
- result = 0;
- } else {
- result = -1; //MAS_ERROR_TIMED_OUT;
- }
-
- return result;
-}
-
-int masc_dbus_send_error_message(int reason, const char* err_msg)
-{
- if (0 != __dbus_check()) {
- return -1; //MAS_ERROR_OPERATION_FAILED;
- }
-
- if (NULL == g_conn_sender) {
- MAS_LOGE("[Dbus ERROR] Dbus connection is not available");
- return -1;
- }
-
- DBusMessage* msg = NULL;
-
- /* create a message */
- msg = dbus_message_new_signal(
- MA_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */
- MA_CLIENT_SERVICE_INTERFACE, /* interface name of the signal */
- MAS_METHOD_ERROR); /* name of the signal */
-
- if (NULL == msg) {
- MAS_LOGE("[Dbus ERROR] Fail to create error message");
- return -1;
- }
-
- char* temp_err_msg = NULL;
-
- if (err_msg)
- temp_err_msg = strdup(err_msg);
- else
- temp_err_msg = strdup("#NULL");
-
- dbus_message_append_args(msg,
- DBUS_TYPE_INT32, &reason,
- DBUS_TYPE_STRING, &temp_err_msg,
- DBUS_TYPE_INVALID);
-
- dbus_message_set_no_reply(msg, TRUE);
-
- if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
- MAS_LOGE("[Dbus ERROR] <<<< error message : Out Of Memory !");
- } else {
- MAS_LOGI("<<<< Send error message : reason(%d), err_msg(%s)", reason, temp_err_msg);
- dbus_connection_flush(g_conn_sender);
- }
-
- dbus_message_unref(msg);
-
- if (temp_err_msg)
- free(temp_err_msg);
- return 0;
-}
-
-const char *message_port = "ma_streaming_port";
-
-#define STREAMING_BUFFER_SIZE 4096
-
-typedef enum {
- streaming_data_type_audio_data,
- streaming_data_type_streaming_section
-} streaming_data_type_e;
-
-typedef struct {
- unsigned int streaming_data_size;
- int streaming_data_type;
- int streaming_data_serial;
-} streaming_data_header;
-
-typedef struct {
- int event;
- unsigned int data_size;
-} streaming_data_audio_data_header;
-
-typedef struct {
- int section;
-} streaming_data_streaming_section_header;
-
-void masc_message_port_error(int error)
-{
- MAS_LOGE("message_port error found : %s",
- (MESSAGE_PORT_ERROR_NONE == error) ? "MESSAGE_PORT_ERROR_NONE" :
- (MESSAGE_PORT_ERROR_IO_ERROR == error) ? "MESSAGE_PORT_ERROR_IO_ERROR" :
- (MESSAGE_PORT_ERROR_OUT_OF_MEMORY == error) ? "MESSAGE_PORT_ERROR_OUT_OF_MEMORY" :
- (MESSAGE_PORT_ERROR_INVALID_PARAMETER == error) ? "MESSAGE_PORT_ERROR_INVALID_PARAMETER" :
- (MESSAGE_PORT_ERROR_PORT_NOT_FOUND == error) ? "MESSAGE_PORT_ERROR_PORT_NOT_FOUND" :
- (MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH == error) ? "MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH" :
- (MESSAGE_PORT_ERROR_MAX_EXCEEDED == error) ? "MESSAGE_PORT_ERROR_MAX_EXCEEDED" :
- (MESSAGE_PORT_ERROR_RESOURCE_UNAVAILABLE == error) ? "MESSAGE_PORT_ERROR_RESOURCE_UNAVAILABLE" :
- "MESSAGE_PORT_ERROR_UNKNOWN");
-}
-
-int masc_dbus_send_streaming_audio_data(int pid, int event, void* data, unsigned int data_size)
-{
- static unsigned char pending_buffer[STREAMING_BUFFER_SIZE];
- static unsigned int pending_buffer_size = 0;
-
- streaming_data_header header;
- header.streaming_data_type = 0;
- header.streaming_data_size = sizeof(streaming_data_header) + sizeof(streaming_data_audio_data_header) + data_size;
- header.streaming_data_serial = g_streaming_data_serial++;
-
- streaming_data_audio_data_header audio_data_header;
- audio_data_header.event = event;
- audio_data_header.data_size = data_size;
-
- unsigned char buffer[STREAMING_BUFFER_SIZE];
- size_t total_size = 0;
- memcpy(buffer, &header, sizeof(header));
- total_size += sizeof(header);
- memcpy(buffer + total_size, &audio_data_header, sizeof(audio_data_header));
- total_size += sizeof(audio_data_header);
- memcpy(buffer + total_size, data, data_size);
- total_size += data_size;
-
- static int last_serial_waiting_for_flush = -1;
- if (0 == header.streaming_data_serial % 50) {
- last_serial_waiting_for_flush = header.streaming_data_serial;
- MAS_LOGI("queueing streaming data, serial : %d", last_serial_waiting_for_flush);
- }
- if (pending_buffer_size + total_size > STREAMING_BUFFER_SIZE ||
- MAS_SPEECH_STREAMING_EVENT_FINISH == event) {
- bundle *b = bundle_create();
- if (b) {
- bundle_add_byte(b, "content", pending_buffer, pending_buffer_size);
- int ret = message_port_send_message(
- mas_get_client_appid_by_pid(pid), message_port, b);
- if (MESSAGE_PORT_ERROR_NONE != ret)
- masc_message_port_error(ret);
-
- pending_buffer_size = 0;
- bundle_free(b);
- } else {
- MAS_LOGE("Bundle creation failed!!!");
- }
-
- if (-1 != last_serial_waiting_for_flush) {
- MAS_LOGI("flushing streaming data, serial : %d", last_serial_waiting_for_flush);
- last_serial_waiting_for_flush = -1;
- }
- }
-
- if (MAS_SPEECH_STREAMING_EVENT_FINISH == event) {
- bundle *b = bundle_create();
- if (b) {
- bundle_add_byte(b, "content", buffer, total_size);
- int ret = message_port_send_message(
- mas_get_client_appid_by_pid(pid), message_port, b);
- if (MESSAGE_PORT_ERROR_NONE != ret)
- masc_message_port_error(ret);
-
- bundle_free(b);
- } else {
- MAS_LOGE("Bundle creation failed!!!");
- }
- } else {
- memcpy(pending_buffer + pending_buffer_size, buffer, total_size);
- pending_buffer_size += total_size;
- }
- return 0;
-}
-
-int masc_dbus_active_state_change(int pid, int state)
-{
- if (0 != __dbus_check()) {
- return -1; //MAS_ERROR_OPERATION_FAILED;
- }
-
- DBusMessage* msg;
-
- DBusError err;
- dbus_error_init(&err);
-
- char service_name[64];
- memset(service_name, '\0', 64);
- snprintf(service_name, 64, "%s_%d", MA_CLIENT_SERVICE_NAME, pid);
-
- msg = dbus_message_new_method_call(
- service_name,
- MA_CLIENT_SERVICE_OBJECT_PATH,
- MA_CLIENT_SERVICE_INTERFACE,
- MAS_METHOD_ACTIVE_STATE_CHANGE);
-
- if (NULL == msg) {
- MAS_LOGE(">>>> Request mas send activate message : Fail to make message");
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD(">>>> Request mas send activate message : %s", service_name);
- }
-
- if (true != dbus_message_append_args(msg,
- DBUS_TYPE_INT32, &state,
- DBUS_TYPE_INVALID)) {
- dbus_message_unref(msg);
- MAS_LOGE("[ERROR] Fail to append args");
- return -1;
- }
-
- dbus_message_set_no_reply(msg, TRUE);
-
- if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
- MAS_LOGE("[Dbus ERROR] Fail to Send");
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[Dbus DEBUG] Success to Send activate message : %d %d", pid, state);
- dbus_connection_flush(g_conn_sender);
- }
-
- dbus_message_unref(msg);
- return 0;
-}
-
-int masc_dbus_send_preprocessing_information(int pid, const char* app_id)
-{
- if (0 != __dbus_check()) {
- return -1; //MAS_ERROR_OPERATION_FAILED;
- }
-
- DBusMessage* msg;
-
- DBusError err;
- dbus_error_init(&err);
-
- char service_name[64];
- memset(service_name, '\0', 64);
- snprintf(service_name, 64, "%s_%d", MA_CLIENT_SERVICE_NAME, pid);
-
- msg = dbus_message_new_method_call(
- service_name,
- MA_CLIENT_SERVICE_OBJECT_PATH,
- MA_CLIENT_SERVICE_INTERFACE,
- MAS_METHOD_SEND_PREPROCESSING_INFORMATION);
-
- if (NULL == msg) {
- MAS_LOGE(">>>> Request mas send preprocessing assistant information : Fail to make message");
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD(">>>> Request mas send preprocessing assistant information : %s", service_name);
- }
-
- char* temp_app_id = NULL;
- if (!app_id)
- temp_app_id = strdup("#NULL");
- else
- temp_app_id = strdup(app_id);
-
- if (true != dbus_message_append_args(msg,
- DBUS_TYPE_STRING, &temp_app_id,
- DBUS_TYPE_INVALID)) {
- dbus_message_unref(msg);
- MAS_LOGE("[ERROR] Fail to append args");
- if (temp_app_id)
- free(temp_app_id);
- return -1;
- }
-
- dbus_message_set_no_reply(msg, TRUE);
-
- if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
- MAS_LOGE("[Dbus ERROR] Fail to Send");
- if (temp_app_id)
- free(temp_app_id);
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[Dbus DEBUG] Success to Send preprocessing assistant information : %d %s", pid, app_id);
- dbus_connection_flush(g_conn_sender);
- }
-
- dbus_message_unref(msg);
-
- if (temp_app_id)
- free(temp_app_id);
-
- return 0;
-}
-
-int masc_dbus_send_streaming_section_changed(int pid, int section)
-{
- bundle *b = bundle_create();
-
- streaming_data_header header;
- header.streaming_data_type = 1;
- header.streaming_data_size = sizeof(streaming_data_header) + sizeof(streaming_data_streaming_section_header);
- header.streaming_data_serial = g_streaming_data_serial++;
-
- streaming_data_streaming_section_header streaming_section_header;
- streaming_section_header.section = section;
-
- unsigned char buffer[STREAMING_BUFFER_SIZE];
- size_t total_size = 0;
- memcpy(buffer, &header, sizeof(header));
- total_size += sizeof(header);
- memcpy(buffer + total_size, &streaming_section_header, sizeof(streaming_section_header));
- total_size += sizeof(streaming_section_header);
-
- bundle_add_byte(b, "content", buffer, total_size);
- int ret = message_port_send_message(mas_get_client_appid_by_pid(pid), message_port, b);
- if (MESSAGE_PORT_ERROR_NONE != ret)
- masc_message_port_error(ret);
-
- bundle_free(b);
-
- return 0;
-}
-
-int masc_dbus_send_preprocessing_result(int pid, bool result)
-{
- if (0 != __dbus_check()) {
- return -1; //MAS_ERROR_OPERATION_FAILED;
- }
-
- DBusMessage* msg;
-
- DBusError err;
- dbus_error_init(&err);
-
- char service_name[64];
- memset(service_name, '\0', 64);
- snprintf(service_name, 64, "%s_%d", MA_CLIENT_SERVICE_NAME, pid);
-
- msg = dbus_message_new_method_call(
- service_name,
- MA_CLIENT_SERVICE_OBJECT_PATH,
- MA_CLIENT_SERVICE_INTERFACE,
- MAS_METHOD_SEND_PREPROCESSING_RESULT);
-
- if (NULL == msg) {
- MAS_LOGE(">>>> Request mas send preprocessing result : Fail to make message");
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD(">>>> Request mas send preprocessing result : %s", service_name);
- }
-
- int temp_result = result;
-
- if (true != dbus_message_append_args(msg,
- DBUS_TYPE_INT32, &temp_result,
- DBUS_TYPE_INVALID)) {
- dbus_message_unref(msg);
- MAS_LOGE("[ERROR] Fail to append args");
- return -1;
- }
-
- dbus_message_set_no_reply(msg, TRUE);
-
- if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
- MAS_LOGE("[Dbus ERROR] Fail to Send");
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[Dbus DEBUG] Success to Send preprocessing result : %d %d", pid, temp_result);
- dbus_connection_flush(g_conn_sender);
- }
-
- dbus_message_unref(msg);
-
- return 0;
-}
-
-int masc_dbus_send_wakeup_engine_command(int pid, const char* command)
-{
- if (0 != __dbus_check()) {
- return -1; //MAS_ERROR_OPERATION_FAILED;
- }
-
- DBusMessage* msg;
-
- DBusError err;
- dbus_error_init(&err);
-
- char service_name[64];
- memset(service_name, '\0', 64);
- snprintf(service_name, 64, "%s_%d", MA_CLIENT_SERVICE_NAME, pid);
-
- msg = dbus_message_new_method_call(
- service_name,
- MA_CLIENT_SERVICE_OBJECT_PATH,
- MA_CLIENT_SERVICE_INTERFACE,
- MAS_METHOD_SEND_WAKEUP_ENGINE_COMMAND);
-
- if (NULL == msg) {
- MAS_LOGE(">>>> Request mas send wakeup engine command : Fail to make message");
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD(">>>> Request mas send wakeup engine command : %s", service_name);
- }
-
- char* temp_command = NULL;
- if (!command)
- temp_command = strdup("#NULL");
- else
- temp_command = strdup(command);
-
- if (true != dbus_message_append_args(msg,
- DBUS_TYPE_STRING, &temp_command,
- DBUS_TYPE_INVALID)) {
- dbus_message_unref(msg);
- MAS_LOGE("[ERROR] Fail to append args");
- if (temp_command)
- free(temp_command);
- return -1;
- }
-
- dbus_message_set_no_reply(msg, TRUE);
-
- if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
- MAS_LOGE("[Dbus ERROR] Fail to Send");
- if (temp_command)
- free(temp_command);
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[Dbus DEBUG] Success to Send wakeup_engine_command : %d %s", pid, command);
- dbus_connection_flush(g_conn_sender);
- }
-
- dbus_message_unref(msg);
-
- if (temp_command)
- free(temp_command);
-
- return 0;
-}
-
-int masc_dbus_service_state_change(int pid, int state)
-{
- if (0 != __dbus_check()) {
- return -1; //MAS_ERROR_OPERATION_FAILED;
- }
-
- DBusMessage* msg;
-
- DBusError err;
- dbus_error_init(&err);
-
- char service_name[64];
- memset(service_name, '\0', 64);
- snprintf(service_name, 64, "%s_%d", MA_CLIENT_SERVICE_NAME, pid);
-
- msg = dbus_message_new_method_call(
- service_name,
- MA_CLIENT_SERVICE_OBJECT_PATH,
- MA_CLIENT_SERVICE_INTERFACE,
- MAS_METHOD_SERVICE_STATE_CHANGE);
-
- if (NULL == msg) {
- MAS_LOGE(">>>> Request mas send service state message : Fail to make message");
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD(">>>> Request mas send service state message : %s", service_name);
- }
-
- if (true != dbus_message_append_args(msg,
- DBUS_TYPE_INT32, &state,
- DBUS_TYPE_INVALID)) {
- dbus_message_unref(msg);
- MAS_LOGE("[ERROR] Fail to append args");
- return -1;
- }
-
- dbus_message_set_no_reply(msg, TRUE);
-
- if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
- MAS_LOGE("[Dbus ERROR] Fail to Send");
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[Dbus DEBUG] Success to Send service state message : %d %d", pid, state);
- dbus_connection_flush(g_conn_sender);
- }
-
- dbus_message_unref(msg);
- return 0;
-}
-
-int masc_dbus_voice_key_status_change(int pid, int status)
-{
- if (0 != __dbus_check()) {
- return -1; //MAS_ERROR_OPERATION_FAILED;
- }
-
- DBusMessage* msg;
-
- DBusError err;
- dbus_error_init(&err);
-
- char service_name[64];
- memset(service_name, '\0', 64);
- snprintf(service_name, 64, "%s_%d", MA_CLIENT_SERVICE_NAME, pid);
-
- msg = dbus_message_new_method_call(
- service_name,
- MA_CLIENT_SERVICE_OBJECT_PATH,
- MA_CLIENT_SERVICE_INTERFACE,
- MAS_METHOD_VOICE_KEY_STATUS_CHANGE);
-
- if (NULL == msg) {
- MAS_LOGE(">>>> Request mas send voice key status change message : Fail to make message");
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD(">>>> Request mas send voice key status change message : %s", service_name);
- }
-
- if (true != dbus_message_append_args(msg,
- DBUS_TYPE_INT32, &status,
- DBUS_TYPE_INVALID)) {
- dbus_message_unref(msg);
- MAS_LOGE("[ERROR] Fail to append args");
- return -1;
- }
-
- dbus_message_set_no_reply(msg, TRUE);
-
- if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
- MAS_LOGE("[Dbus ERROR] Fail to Send");
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[Dbus DEBUG] Success to Send voice key status change : %d %d", pid, status);
- dbus_connection_flush(g_conn_sender);
- }
-
- dbus_message_unref(msg);
- return 0;
-}
-
-int masc_ui_dbus_send_hello(void)
-{
- if (0 != __dbus_check()) {
- return -1; //MAS_ERROR_OPERATION_FAILED;
- }
-
- DBusMessage* msg;
-
- DBusError err;
- dbus_error_init(&err);
-
- msg = dbus_message_new_method_call(
- MA_UI_CLIENT_SERVICE_NAME,
- MA_UI_CLIENT_SERVICE_OBJECT_PATH,
- MA_UI_CLIENT_SERVICE_INTERFACE,
- MAS_METHOD_HELLO);
-
- if (NULL == msg) {
- MAS_LOGE("[DBus ERROR] Request masc hello : Fail to make message");
- return -1;
- }
-
- DBusMessage* result_msg = NULL;
- int result = 0;
-
- result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, 500, &err);
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[Dbus ERROR] Dbus Error (%s)", err.message);
- dbus_error_free(&err);
- }
-
- dbus_message_unref(msg);
-
- if (NULL != result_msg) {
- dbus_message_unref(result_msg);
- result = 0;
- } else {
- result = -1; //ERROR_TIMED_OUT;
- }
-
- return result;
-}
-
-int masc_ui_dbus_send_asr_result(int pid, int event, char* asr_result)
-{
- if (0 != __dbus_check()) {
- return -1; //MAS_ERROR_OPERATION_FAILED;
- }
-
- DBusMessage* msg;
-
- msg = dbus_message_new_method_call(
- MA_UI_CLIENT_SERVICE_NAME,
- MA_UI_CLIENT_SERVICE_OBJECT_PATH,
- MA_UI_CLIENT_SERVICE_INTERFACE,
- MAS_UI_METHOD_SEND_ASR_RESULT);
-
- if (NULL == msg) {
- MAS_LOGE("@@ Request multi-assistant send ASR result : Fail to make message");
- return -1; //MA_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD("[DEBUG] multi-assistant send ASR result, asr_result(%p)", asr_result);
- }
-
- char* temp_asr_result = NULL;
- if (!asr_result)
- temp_asr_result = strdup("#NULL");
- else
- temp_asr_result = strdup(asr_result);
-
- dbus_message_append_args(msg,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_INT32, &event,
- DBUS_TYPE_STRING, &temp_asr_result,
- DBUS_TYPE_INVALID);
-
- dbus_message_set_no_reply(msg, TRUE);
-
- if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
- MAS_LOGE("[Dbus ERROR] Fail to Send");
- if (NULL != temp_asr_result) {
- free(temp_asr_result);
- temp_asr_result = NULL;
- }
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD("[Dbus DEBUG] Success to Send ASR result");
- dbus_connection_flush(g_conn_sender);
- }
-
- dbus_message_unref(msg);
-
- if (temp_asr_result)
- free(temp_asr_result);
- return 0;
-}
-
-int masc_ui_dbus_send_result(int pid, const char* display_text, const char* utterance_text, const char* result_json)
-{
- if (0 != __dbus_check()) {
- return -1; //MA_ERROR_OPERATION_FAILED;
- }
-
- DBusMessage* msg;
-
- msg = dbus_message_new_method_call(
- MA_UI_CLIENT_SERVICE_NAME,
- MA_UI_CLIENT_SERVICE_OBJECT_PATH,
- MA_UI_CLIENT_SERVICE_INTERFACE,
- MAS_UI_METHOD_SEND_RESULT);
-
- if (NULL == msg) {
- MAS_LOGE("@@ Request multi-assistant send result : Fail to make message");
- return -1; //MA_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD("[DEBUG] multi-assistant send result");
- }
- char* temp_display_text = NULL;
- char* temp_utterance_text = NULL;
- char* temp_result_json = NULL;
-
-#if 0
- dbus_message_append_args(msg,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_STRING, &display_text,
- DBUS_TYPE_STRING, &utterance_text,
- DBUS_TYPE_STRING, &result_json,
- DBUS_TYPE_INVALID);
-
- dbus_message_set_no_reply(msg, TRUE);
-
- if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
- MAS_LOGE("[Dbus ERROR] Fail to Send");
- return -1; //MA_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD("[Dbus DEBUG] Success to Send result");
- dbus_connection_flush(g_conn_sender);
- }
-
- dbus_message_unref(msg);
-#else
- if (!display_text)
- temp_display_text = strdup("#NULL");
- else
- temp_display_text = strdup(display_text);
- if (!utterance_text)
- temp_utterance_text = strdup("#NULL");
- else
- temp_utterance_text = strdup(utterance_text);
- if (!result_json)
- temp_result_json = strdup("#NULL");
- else
- temp_result_json = strdup(result_json);
-
- dbus_message_append_args(msg,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_STRING, &temp_display_text,
- DBUS_TYPE_STRING, &temp_utterance_text,
- DBUS_TYPE_STRING, &temp_result_json,
- DBUS_TYPE_INVALID);
-
- dbus_message_set_no_reply(msg, TRUE);
-
- if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
- MAS_LOGE("[Dbus ERROR] Fail to Send");
- if (temp_display_text)
- free(temp_display_text);
- if (temp_utterance_text)
- free(temp_utterance_text);
- if (temp_result_json)
- free(temp_result_json);
- return -1; //MA_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD("[Dbus DEBUG] Success to Send result");
- dbus_connection_flush(g_conn_sender);
- }
-
- dbus_message_unref(msg);
-
- if (temp_display_text)
- free(temp_display_text);
- if (temp_utterance_text)
- free(temp_utterance_text);
- if (temp_result_json)
- free(temp_result_json);
-#endif
- return 0;
-}
-
-int masc_ui_dbus_change_assistant(const char* app_id)
-{
- if (0 != __dbus_check()) {
- return -1; //MAS_ERROR_OPERATION_FAILED;
- }
-
- if (NULL == app_id) {
- MAS_LOGE("@@ Request multi-assistant send change assistant request : Fail to make message");
- return -1; //MA_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD("[DEBUG] multi-assistant send change assistant request app_id(%s)", app_id);
- }
-
- DBusMessage* msg;
-
- msg = dbus_message_new_method_call(
- MA_UI_CLIENT_SERVICE_NAME,
- MA_UI_CLIENT_SERVICE_OBJECT_PATH,
- MA_UI_CLIENT_SERVICE_INTERFACE,
- MAS_UI_METHOD_CHANGE_ASSISTANT);
-
- dbus_message_append_args(msg,
- DBUS_TYPE_STRING, &app_id,
- DBUS_TYPE_INVALID);
-
- dbus_message_set_no_reply(msg, TRUE);
-
- if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
- MAS_LOGE("[Dbus ERROR] Fail to Send");
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD("[Dbus DEBUG] Success to Send change assistant request");
- dbus_connection_flush(g_conn_sender);
- }
-
- dbus_message_unref(msg);
-
- return 0;
-}
-
-int masc_ui_dbus_send_error_message(int reason, const char* err_msg)
-{
- if (NULL == g_conn_sender) {
- MAS_LOGE("[Dbus ERROR] Dbus connection is not available");
- return -1;
- }
-
- DBusMessage* msg = NULL;
-
- /* create a message */
- msg = dbus_message_new_signal(
- MA_UI_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */
- MA_UI_CLIENT_SERVICE_INTERFACE, /* interface name of the signal */
- MAS_UI_METHOD_ERROR); /* name of the signal */
-
- if (NULL == msg) {
- MAS_LOGE("[Dbus ERROR] Fail to create error message");
- return -1;
- }
-
- char* temp_err_msg = NULL;
-
- if (err_msg)
- temp_err_msg = strdup(err_msg);
- else
- temp_err_msg = strdup("#NULL");
-
- dbus_message_append_args(msg,
- DBUS_TYPE_INT32, &reason,
- DBUS_TYPE_STRING, &temp_err_msg,
- DBUS_TYPE_INVALID);
-
- dbus_message_set_no_reply(msg, TRUE);
-
- if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
- MAS_LOGE("[Dbus ERROR] <<<< error message : Out Of Memory !");
- } else {
- MAS_LOGD("<<<< Send error message : reason(%d), err_msg(%s)", reason, temp_err_msg);
- dbus_connection_flush(g_conn_sender);
- }
-
- dbus_message_unref(msg);
-
- if (temp_err_msg)
- free(temp_err_msg);
- return 0;
-}
-
-int masc_ui_dbus_send_recognition_result(int pid, int result)
-{
- if (0 != __dbus_check()) {
- return -1; //MAS_ERROR_OPERATION_FAILED;
- }
-
- DBusMessage* msg;
-
- msg = dbus_message_new_method_call(
- MA_UI_CLIENT_SERVICE_NAME,
- MA_UI_CLIENT_SERVICE_OBJECT_PATH,
- MA_UI_CLIENT_SERVICE_INTERFACE,
- MAS_UI_METHOD_SEND_RECOGNITION_RESULT);
-
- if (NULL == msg) {
- MAS_LOGE("@@ Request multi-assistant send recognition result : Fail to make message");
- return -1; //MA_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD("[DEBUG] multi-assistant send recognition result(%d)", result);
- }
-
- dbus_message_append_args(msg,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_INVALID);
-
- dbus_message_set_no_reply(msg, TRUE);
-
- if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
- MAS_LOGE("[Dbus ERROR] Fail to Send");
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD("[Dbus DEBUG] Success to Send ASR result");
- dbus_connection_flush(g_conn_sender);
- }
-
- dbus_message_unref(msg);
-
- return 0;
-}
-
-int masc_ui_dbus_enable_common_ui(int enable)
-{
- if (0 != __dbus_check()) {
- return -1; //MAS_ERROR_OPERATION_FAILED;
- }
-
- DBusMessage* msg;
-
- msg = dbus_message_new_method_call(
- MA_UI_CLIENT_SERVICE_NAME,
- MA_UI_CLIENT_SERVICE_OBJECT_PATH,
- MA_UI_CLIENT_SERVICE_INTERFACE,
- MAS_UI_METHOD_ENABLE_COMMON_UI);
-
- if (NULL == msg) {
- MAS_LOGE("@@ Request multi-assistant enable common ui : Fail to make message");
- return -1; //MA_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD("[DEBUG] multi-assistant enable common ui (%d)", enable);
- }
-
- dbus_message_append_args(msg,
- DBUS_TYPE_INT32, &enable,
- DBUS_TYPE_INVALID);
-
- dbus_message_set_no_reply(msg, TRUE);
-
- if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
- MAS_LOGE("[Dbus ERROR] Fail to Send");
- return -1; // MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD("[Dbus DEBUG] Success to Send ASR result");
- dbus_connection_flush(g_conn_sender);
- }
-
- dbus_message_unref(msg);
-
- return 0;
-}
-
-static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
-{
- if (NULL == g_conn_listener) return ECORE_CALLBACK_RENEW;
-
- dbus_connection_read_write_dispatch(g_conn_listener, 50);
-
- while (1) {
- DBusMessage* msg = NULL;
- msg = dbus_connection_pop_message(g_conn_listener);
-
- if (true != dbus_connection_get_is_connected(g_conn_listener)) {
- MAS_LOGE("[ERROR] Connection is disconnected");
- return ECORE_CALLBACK_RENEW;
- }
-
- /* loop again if we haven't read a message */
- if (NULL == msg) {
- return ECORE_CALLBACK_RENEW;
- }
-
- /* client event */
- if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_HELLO)) {
- ma_service_dbus_hello(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_INITIALIZE)) {
- ma_service_dbus_initialize(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_DEINITIALIZE)) {
- ma_service_dbus_deinitialize(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_GET_RECORDING_AUDIO_FORMAT)) {
- ma_service_dbus_get_audio_format(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_GET_RECORDING_AUDIO_SOURCE_TYPE)) {
- ma_service_dbus_get_audio_source_type(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SEND_ASR_RESULT)) {
- ma_service_dbus_send_asr_result(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SEND_RESULT)) {
- ma_service_dbus_send_result(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SEND_RECOGNITION_RESULT)) {
- ma_service_dbus_send_recognition_result(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_START_STREAMING_AUDIO_DATA)) {
- ma_service_dbus_start_streaming_audio_data(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_STOP_STREAMING_AUDIO_DATA)) {
- ma_service_dbus_stop_streaming_audio_data(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_UPDATE_VOICE_FEEDBACK_STATE)) {
- ma_service_dbus_update_voice_feedback_state(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SEND_ASSISTANT_SPECIFIC_COMMAND)) {
- ma_service_dbus_send_assistant_specific_command(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SET_BACKGROUND_VOLUME)) {
- ma_service_dbus_set_background_volume(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SET_PREPROCESSING_ALLOW_MODE)) {
- ma_service_dbus_set_preprocessing_allow_mode(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SEND_PREPROCESSING_RESULT)) {
- ma_service_dbus_send_preprocessing_result(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG)) {
- ma_service_dbus_set_wake_word_audio_require_flag(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SET_ASSISTANT_LANGUAGE)) {
- ma_service_dbus_set_assistant_language(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_ADD_WAKE_WORD)) {
- ma_service_dbus_add_wake_word(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_REMOVE_WAKE_WORD)) {
- ma_service_dbus_remove_wake_word(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_UI_METHOD_INITIALIZE)) {
- ma_service_ui_dbus_initialize(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_UI_METHOD_DEINITIALIZE)) {
- ma_service_ui_dbus_deinitialize(g_conn_listener, msg);
-
- } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_UI_METHOD_CHANGE_ASSISTANT)) {
- ma_service_ui_dbus_change_assistant(g_conn_listener, msg);
-
- } else {
- MAS_LOGD("Message is NOT valid");
- /* Invalid method */
- }
- /* free the message */
- dbus_message_unref(msg);
- }
-
- return ECORE_CALLBACK_RENEW;
-}
-
-static void __mas_dbus_connection_free()
-{
- if (NULL != g_conn_listener) {
- dbus_connection_close(g_conn_listener);
- dbus_connection_unref(g_conn_listener);
- g_conn_listener = NULL;
- }
- if (NULL != g_conn_sender) {
- dbus_connection_close(g_conn_sender);
- dbus_connection_unref(g_conn_sender);
- g_conn_sender = NULL;
- }
-}
-
-int mas_dbus_open_connection()
-{
- DBusError err;
- dbus_error_init(&err);
-
- int ret;
-
- /* Create connection for sender */
- g_conn_sender = dbus_bus_get_private(DBUS_BUS_SESSION, &err);
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[Dbus ERROR] Fail dbus_bus_get : %s", err.message);
- dbus_error_free(&err);
- }
-
- if (NULL == g_conn_sender) {
- MAS_LOGE("[Dbus ERROR] Fail to get dbus connection");
- return -1;
- }
-
- 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 (dbus_error_is_set(&err)) {
- MAS_LOGE("[Dbus ERROR] Fail dbus_bus_get : %s", err.message);
- dbus_error_free(&err);
- }
-
- if (NULL == g_conn_listener) {
- MAS_LOGE("[Dbus ERROR] Fail to get dbus connection");
- __mas_dbus_connection_free();
- return -1;
- }
-
- dbus_connection_set_exit_on_disconnect(g_conn_listener, false);
-
- /* request our name on the bus and check for errors */
- ret = dbus_bus_request_name(g_conn_listener, MA_SERVER_SERVICE_NAME, DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
-
- if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
- printf("Fail to be primary owner in dbus request.");
- MAS_LOGE("[Dbus ERROR] Fail to be primary owner");
- __mas_dbus_connection_free();
- return -1;
- }
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[Dbus ERROR] dbus_bus_request_name() : %s", err.message);
- dbus_error_free(&err);
- __mas_dbus_connection_free();
- return -1;
- }
-
- /* Flush messages which are received before fd event handler registration */
- while (DBUS_DISPATCH_DATA_REMAINS == dbus_connection_get_dispatch_status(g_conn_listener)) {
- listener_event_callback(NULL, NULL);
- }
-
- /* add a rule for getting signal */
- char rule[128];
- snprintf(rule, 128, "type='signal',interface='%s'", MA_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)) {
- MAS_LOGE("[Dbus ERROR] dbus_bus_add_match() : %s", err.message);
- dbus_error_free(&err);
- __mas_dbus_connection_free();
- return -1;
- }
-
- int fd = 0;
- if (1 != dbus_connection_get_unix_fd(g_conn_listener, &fd)) {
- MAS_LOGE("fail to get fd from dbus ");
- __mas_dbus_connection_free();
- return -1;
- } else {
- MAS_LOGD("Get fd from dbus : %d", fd);
- }
-
- 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) {
- MAS_LOGE("[Dbus ERROR] Fail to get fd handler");
- __mas_dbus_connection_free();
- return -1;
- }
-
- return 0;
-}
-
-int mas_dbus_close_connection()
-{
- DBusError err;
- dbus_error_init(&err);
-
- if (NULL != g_dbus_fd_handler) {
- ecore_main_fd_handler_del(g_dbus_fd_handler);
- g_dbus_fd_handler = NULL;
- }
-
- dbus_bus_release_name(g_conn_listener, MA_SERVER_SERVICE_NAME, &err);
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[Dbus ERROR] dbus_bus_release_name() : %s", err.message);
- dbus_error_free(&err);
- }
-
- __mas_dbus_connection_free();
-
- return 0;
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright 2018-2019 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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 __MULTI_ASSISTANT_DBUS_h__
-#define __MULTI_ASSISTANT_DBUS_h__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int mas_dbus_open_connection();
-
-int mas_dbus_close_connection();
-
-int masc_dbus_send_hello(int pid);
-
-int masc_dbus_send_error_message(int reason, const char* err_msg);
-
-int masc_dbus_send_streaming_audio_data(int pid, int event, void* data, unsigned int data_size);
-
-int masc_dbus_active_state_change(int pid, int state);
-
-int masc_dbus_send_preprocessing_information(int pid, const char* app_id);
-
-int masc_dbus_send_streaming_section_changed(int pid, int section);
-
-int masc_dbus_send_preprocessing_result(int pid, bool result);
-
-int masc_dbus_send_wakeup_engine_command(int pid, const char* command);
-
-int masc_dbus_service_state_change(int pid, int state);
-
-int masc_dbus_voice_key_status_change(int pid, int status);
-
-int masc_ui_dbus_send_hello(void);
-
-int masc_ui_dbus_send_asr_result(int pid, int event, char* asr_result);
-
-int masc_ui_dbus_send_result(int pid, const char* display_text, const char* utterance_text, const char* result_json);
-
-int masc_ui_dbus_change_assistant(const char* app_id);
-
-int masc_ui_dbus_send_error_message(int reason, const char* err_msg);
-
-int masc_ui_dbus_send_recognition_result(int pid, int result);
-
-int masc_ui_dbus_enable_common_ui(int enable);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __MULTI_ASSISTANT_DBUS_h__ */
+++ /dev/null
-/*
- * Copyright 2018-2019 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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.
- */
-
-#include <stdlib.h>
-
-#include "multi_assistant_main.h"
-#include "multi_assistant_dbus.h"
-#include "multi_assistant_dbus_server.h"
-#include "multi_assistant_service_client.h"
-
-/*
-* Dbus Client-Daemon Server
-*/
-int ma_service_dbus_hello(DBusConnection* conn, DBusMessage* msg)
-{
- MAS_LOGD("[DEBUG] MAS HELLO");
-
- DBusMessage* reply;
- reply = dbus_message_new_method_return(msg);
-
- if (NULL != reply) {
- if (!dbus_connection_send(conn, reply, NULL)) {
- MAS_LOGE("[OUT ERROR] Out Of Memory!");
- }
-
- dbus_connection_flush(conn);
- dbus_message_unref(reply);
- } else {
- MAS_LOGE("[OUT ERROR] Fail to create reply message!!");
- }
-
- return 0;
-}
-
-int ma_service_dbus_initialize(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid = -1;
- int ret = 0;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS INITIALIZE");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas initialize : get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD("[IN] mas initialize : pid(%d)", pid);
- ret = mas_client_initialize(pid);
- }
-
- DBusMessage* reply;
- reply = dbus_message_new_method_return(msg);
-
- MAS_LOGI("[OUT] mas initialize : result(%d)", ret);
- if (NULL != reply) {
- dbus_message_append_args(reply,
- DBUS_TYPE_INT32, &ret,
- DBUS_TYPE_INVALID);
-
- if (0 == ret) {
- MAS_LOGD("[OUT] mas initialize : result(%d)", ret);
- } else {
- MAS_LOGE("[OUT ERROR] mas initialize : result(%d)", ret);
- }
-
- if (!dbus_connection_send(conn, reply, NULL)) {
- MAS_LOGE("[OUT ERROR] mas initialize : Out Of Memory!");
- }
-
- dbus_connection_flush(conn);
- dbus_message_unref(reply);
- } else {
- MAS_LOGE("[OUT ERROR] mas initialize : Fail to create reply message!!");
- }
-
- return ret;
-}
-
-int ma_service_dbus_deinitialize(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid = -1;
- int ret = 0;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS DEINITIALIZE");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas deinitialize : get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD("[IN] mas deinitialize : pid(%d)", pid);
- ret = mas_client_deinitialize(pid);
- }
-
- DBusMessage* reply;
- reply = dbus_message_new_method_return(msg);
-
- MAS_LOGI("[OUT] mas deinitialize : result(%d)", ret);
- if (NULL != reply) {
- dbus_message_append_args(reply,
- DBUS_TYPE_INT32, &ret,
- DBUS_TYPE_INVALID);
-
- if (0 == ret) {
- MAS_LOGD("[OUT] mas deinitialize : result(%d)", ret);
- } else {
- MAS_LOGE("[OUT ERROR] mas deinitialize : result(%d)", ret);
- }
-
- if (!dbus_connection_send(conn, reply, NULL)) {
- MAS_LOGE("[OUT ERROR] mas deinitialize : Out Of Memory!");
- }
-
- dbus_connection_flush(conn);
- dbus_message_unref(reply);
- } else {
- MAS_LOGE("[OUT ERROR] mas deinitialize : Fail to create reply message!!");
- }
-
- return 0;
-}
-
-int ma_service_dbus_get_audio_format(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid = -1;
- int rate, channel, audio_type;
- int ret;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS GET AUDIO FORMAT");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas get audio format : Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD("[IN] mas get audio format");
- ret = mas_client_get_audio_format(pid, &rate, &channel, &audio_type);
- }
-
- DBusMessage* reply;
- reply = dbus_message_new_method_return(msg);
-
- if (NULL != reply) {
- /* Append result and voice */
- dbus_message_append_args(reply,
- DBUS_TYPE_INT32, &ret,
- DBUS_TYPE_INT32, &rate,
- DBUS_TYPE_INT32, &channel,
- DBUS_TYPE_INT32, &audio_type,
- DBUS_TYPE_INVALID);
- if (0 == ret) {
- MAS_LOGI("[OUT] mas get audio format : rate(%d), channel(%d), audio_type(%d)", rate, channel, audio_type);
- } else {
- MAS_LOGE("[OUT ERROR] mas get audio format : result(%d)", ret);
- }
-
- if (!dbus_connection_send(conn, reply, NULL)) {
- MAS_LOGE("[OUT ERROR] mas get audio format : Out Of Memory!");
- }
-
- dbus_connection_flush(conn);
- dbus_message_unref(reply);
- } else {
- MAS_LOGE("[OUT ERROR] tts default voice : Fail to create reply message!!");
- }
-
- return ret;
-}
-
-int ma_service_dbus_get_audio_source_type(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid = -1;
- char *type = NULL;
- int ret;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS GET AUDIO SOURCE TYPE");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas get audio source type : Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD("[IN] mas get audio source type");
- ret = mas_client_get_audio_source_type(pid, &type);
- }
-
- DBusMessage* reply;
- reply = dbus_message_new_method_return(msg);
-
- char* temp_type = NULL;
-
- if (type)
- temp_type = strdup(type);
- else
- temp_type = strdup("#NULL");
-
- if (NULL != reply) {
- /* Append result and voice */
- dbus_message_append_args(reply,
- DBUS_TYPE_INT32, &ret,
- DBUS_TYPE_STRING, &temp_type,
- DBUS_TYPE_INVALID);
- if (0 == ret) {
- MAS_LOGI("[OUT] mas get audio source type : type(%s)", temp_type);
- } else {
- MAS_LOGE("[OUT ERROR] mas get audio source type : result(%d)", ret);
- }
-
- if (!dbus_connection_send(conn, reply, NULL)) {
- MAS_LOGE("[OUT ERROR] mas get audio source type : Out Of Memory!");
- }
-
- dbus_connection_flush(conn);
- dbus_message_unref(reply);
- } else {
- MAS_LOGE("[OUT ERROR] mas get audio source type : Fail to create reply message!!");
- }
-
- if (temp_type)
- free(temp_type);
-
- return ret;
-}
-
-int ma_service_dbus_send_asr_result(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid, event;
- char *asr_result;
- int ret = 0;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_INT32, &event,
- DBUS_TYPE_STRING, &asr_result,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS SEND ASR RESULT");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas send asr result : Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[IN] mas send asr result : pid(%d), event(%d), asr_result(%s)", pid, event, asr_result);
- ret = mas_client_send_asr_result(pid, event, asr_result);
- }
-
- DBusMessage* reply;
- reply = dbus_message_new_method_return(msg);
-
- if (NULL != reply) {
- dbus_message_append_args(reply,
- DBUS_TYPE_INT32, &ret,
- DBUS_TYPE_INVALID);
-
- if (0 == ret) {
- MAS_LOGD("[OUT] mas send asr result : result(%d)", ret);
- } else {
- MAS_LOGE("[OUT ERROR] mas send asr result : result(%d)", ret);
- }
-
- if (!dbus_connection_send(conn, reply, NULL)) {
- MAS_LOGE("[OUT ERROR] mas send asr result : Out Of Memory!");
- }
-
- dbus_connection_flush(conn);
- dbus_message_unref(reply);
- } else {
- MAS_LOGE("[OUT ERROR] mas send asr result : Fail to create reply message!!");
- }
-
- MAS_LOGD("<<<<<");
- MAS_LOGD(" ");
-
- return ret;
-}
-
-int ma_service_dbus_send_result(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid;
- char* display_text;
- char* utterance_text;
- char* result_json;
- int ret = 0;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_STRING, &display_text,
- DBUS_TYPE_STRING, &utterance_text,
- DBUS_TYPE_STRING, &result_json,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS SEND RESULT");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas send result : Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[IN] mas send result : pid(%d), display_text(%s), utterance_text(%s), result_json(%s)", pid, display_text, utterance_text, result_json);
- ret = mas_client_send_result(pid, display_text, utterance_text, result_json);
- }
-
- DBusMessage* reply;
- reply = dbus_message_new_method_return(msg);
-
- if (NULL != reply) {
- dbus_message_append_args(reply,
- DBUS_TYPE_INT32, &ret,
- DBUS_TYPE_INVALID);
-
- if (0 == ret) {
- MAS_LOGD("[OUT] mas send result : result(%d)", ret);
- } else {
- MAS_LOGE("[OUT ERROR] mas send result : result(%d)", ret);
- }
-
- if (!dbus_connection_send(conn, reply, NULL)) {
- MAS_LOGE("[OUT ERROR] mas send result : Out Of Memory!");
- }
-
- dbus_connection_flush(conn);
- dbus_message_unref(reply);
- } else {
- MAS_LOGE("[OUT ERROR] mas send result : Fail to create reply message!!");
- }
-
- MAS_LOGD("<<<<<");
- MAS_LOGD(" ");
-
- return ret;
-}
-
-int ma_service_dbus_send_recognition_result(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid;
- int result;
- int ret = 0;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS SEND RECOGNITION RESULT");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas send recognition result : Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[IN] mas send recognition result : pid(%d), result(%d)", pid, result);
- ret = mas_client_send_recognition_result(pid, result);
- }
-
- MAS_LOGD("<<<<<");
- MAS_LOGD(" ");
-
- return ret;
-}
-
-int ma_service_dbus_start_streaming_audio_data(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid;
- int type;
- int ret = 0;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_INT32, &type,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS SEND START STREAMING");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas send start streaming : Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[IN] mas send start streaming : pid(%d), type(%d)", pid, type);
- ret = mas_client_start_streaming_audio_data(pid, type);
- }
-
- MAS_LOGD("<<<<<");
- MAS_LOGD(" ");
-
- return ret;
-}
-
-int ma_service_dbus_stop_streaming_audio_data(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid;
- int type;
- int ret = 0;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_INT32, &type,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS SEND STOP STREAMING");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas stop streaming : Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[IN] mas stop streaming : pid(%d), type(%d)", pid, type);
- ret = mas_client_stop_streaming_audio_data(pid, type);
- }
-
- MAS_LOGD("<<<<<");
- MAS_LOGD(" ");
-
- return ret;
-}
-
-int ma_service_dbus_update_voice_feedback_state(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid;
- int state;
- int ret = 0;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_INT32, &state,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS SEND UPDATE VOICE FEEDBACK");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas update voice feedback : Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[IN] mas update voice feedback : pid(%d), state(%d)", pid, state);
- ret = mas_client_update_voice_feedback_state(pid, state);
- }
-
- MAS_LOGD("<<<<<");
- MAS_LOGD(" ");
-
- return ret;
-}
-
-int ma_service_dbus_send_assistant_specific_command(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid;
- int ret = 0;
- char* command;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_STRING, &command,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS SEND ASSISTANT SPECIFIC COMMAND");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas send assistant specific command : Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[IN] mas send assistant specific command : pid(%d), command(%s)", pid, command);
- ret = mas_client_set_assistant_specific_command(pid, command);
- }
-
- MAS_LOGD("<<<<<");
- MAS_LOGD(" ");
-
- return ret;
-}
-
-int ma_service_dbus_set_background_volume(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid;
- int ret = 0;
- double ratio;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_DOUBLE, &ratio,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS SET BACKGROUND VOLUME");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas set background volume : Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[IN] mas set background volume : pid(%d), ratio(%f)", pid, ratio);
- ret = mas_client_set_background_volume(pid, ratio);
- }
-
- MAS_LOGD("<<<<<");
- MAS_LOGD(" ");
-
- return ret;
-}
-
-int ma_service_dbus_set_preprocessing_allow_mode(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid;
- int ret = 0;
- int mode;
- char* app_id;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_INT32, &mode,
- DBUS_TYPE_STRING, &app_id,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS SET PREPROCESSING ALLOW MODE");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas set preprocessing allow mode : Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- char* temp_app_id = NULL;
- if (NULL != app_id && strcmp("#NULL", app_id)) {
- temp_app_id = strdup(app_id);
- }
- MAS_LOGI("[IN] mas set preprocessing allow mode : pid(%d), mode(%d), app_id(%s)", pid, mode, temp_app_id);
- ret = mas_client_set_preprocessing_allow_mode(pid,
- static_cast<ma_preprocessing_allow_mode_e>(mode), temp_app_id);
- if (NULL != temp_app_id)
- free(temp_app_id);
- }
-
- MAS_LOGD("<<<<<");
- MAS_LOGD(" ");
-
- return ret;
-}
-
-int ma_service_dbus_send_preprocessing_result(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid;
- int ret = 0;
- int result;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_INT32, &result,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS SEND PREPROCESSING RESULT");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas send preprocessing result : Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[IN] mas send preprocessing result : pid(%d), result(%d)", pid, result);
- ret = mas_client_send_preprocessing_result(pid, (bool)result);
- }
-
- MAS_LOGD("<<<<<");
- MAS_LOGD(" ");
-
- return ret;
-}
-
-int ma_service_dbus_set_wake_word_audio_require_flag(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid;
- int ret = 0;
- int require;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_INT32, &require,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS SET WAKE WORD AUDIO REQUIRE FLAG");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas set wake word audio require flag : Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[IN] mas set wake word audio require flag : pid(%d), require(%d)", pid, require);
- ret = mas_client_set_wake_word_audio_require_flag(pid, (bool)require);
- }
-
- MAS_LOGD("<<<<<");
- MAS_LOGD(" ");
-
- return ret;
-}
-
-int ma_service_dbus_set_assistant_language(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid;
- int ret = 0;
- char* language;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_STRING, &language,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS SET ASSISTANT LANGUAGE");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas set assistant language : Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[IN] mas set assistant language : pid(%d), language(%s)", pid, language);
- ret = mas_client_set_assistant_language(pid, language);
- }
-
- MAS_LOGD("<<<<<");
- MAS_LOGD(" ");
-
- return ret;
-}
-
-int ma_service_dbus_add_wake_word(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid;
- int ret = 0;
- char* wake_word;
- char* language;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_STRING, &wake_word,
- DBUS_TYPE_STRING, &language,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS ADD WAKE WORD");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas add wake word : Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[IN] mas add wake word : pid(%d), wake_word(%s) language(%s)", pid, wake_word, language);
- ret = mas_client_add_wake_word(pid, wake_word, language);
- }
-
- MAS_LOGD("<<<<<");
- MAS_LOGD(" ");
-
- return ret;
-}
-
-int ma_service_dbus_remove_wake_word(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid;
- int ret = 0;
- char* wake_word;
- char* language;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_STRING, &wake_word,
- DBUS_TYPE_STRING, &language,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS REMOVE WAKE WORD");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas remove wake word : Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGI("[IN] mas remove wake word : pid(%d), wake_word(%s) language(%s)", pid, wake_word, language);
- ret = mas_client_remove_wake_word(pid, wake_word, language);
- }
-
- MAS_LOGD("<<<<<");
- MAS_LOGD(" ");
-
- return ret;
-}
-
-int ma_service_ui_dbus_initialize(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid = -1;
- int ret = 0;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS UI INITIALIZE");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas ui initialize : get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD("[IN] mas ui initialize : pid(%d)", pid);
- ret = mas_ui_client_initialize(pid);
- }
-
- DBusMessage* reply;
- reply = dbus_message_new_method_return(msg);
-
- MAS_LOGD("[OUT] mas ui initialize : result(%d)", ret);
- if (NULL != reply) {
- dbus_message_append_args(reply,
- DBUS_TYPE_INT32, &ret,
- DBUS_TYPE_INVALID);
-
- if (0 == ret) {
- MAS_LOGD("[OUT] mas ui initialize : result(%d)", ret);
- } else {
- MAS_LOGE("[OUT ERROR] mas ui initialize : result(%d)", ret);
- }
-
- if (!dbus_connection_send(conn, reply, NULL)) {
- MAS_LOGE("[OUT ERROR] mas ui initialize : Out Of Memory!");
- }
-
- dbus_connection_flush(conn);
- dbus_message_unref(reply);
- } else {
- MAS_LOGE("[OUT ERROR] mas ui initialize : Fail to create reply message!!");
- }
-
- return ret;
-}
-
-int ma_service_ui_dbus_deinitialize(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- int pid = -1;
- int ret = 0;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_INT32, &pid,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS UI DEINITIALIZE");
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas ui deinitialize : get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD("[IN] mas ui deinitialize : pid(%d)", pid);
- ret = mas_ui_client_deinitialize(pid);
- }
-
- DBusMessage* reply;
- reply = dbus_message_new_method_return(msg);
-
- MAS_LOGD("[OUT] mas ui deinitialize : result(%d)", ret);
- if (NULL != reply) {
- dbus_message_append_args(reply,
- DBUS_TYPE_INT32, &ret,
- DBUS_TYPE_INVALID);
-
- if (0 == ret) {
- MAS_LOGD("[OUT] mas ui deinitialize : result(%d)", ret);
- } else {
- MAS_LOGE("[OUT ERROR] mas ui deinitialize : result(%d)", ret);
- }
-
- if (!dbus_connection_send(conn, reply, NULL)) {
- MAS_LOGE("[OUT ERROR] mas ui deinitialize : Out Of Memory!");
- }
-
- dbus_connection_flush(conn);
- dbus_message_unref(reply);
- } else {
- MAS_LOGE("[OUT ERROR] mas ui deinitialize : Fail to create reply message!!");
- }
-
- return ret;
-}
-
-int ma_service_ui_dbus_change_assistant(DBusConnection* conn, DBusMessage* msg)
-{
- DBusError err;
- dbus_error_init(&err);
-
- char *app_id;
- int ret = 0;
-
- dbus_message_get_args(msg, &err,
- DBUS_TYPE_STRING, &app_id,
- DBUS_TYPE_INVALID);
-
- MAS_LOGD("[DEBUG] MAS UI CHANGE ASSISTANT : %s", (app_id ? app_id : "NULL"));
-
- if (dbus_error_is_set(&err)) {
- MAS_LOGE("[IN ERROR] mas ui change assisant : Get arguments error (%s)", err.message);
- dbus_error_free(&err);
- ret = -1; //MAS_ERROR_OPERATION_FAILED;
- } else {
- MAS_LOGD("[IN] mas ui change assisant : app_id(%s)", app_id);
- ret = mas_ui_client_change_assistant(app_id);
- }
-
- DBusMessage* reply;
- reply = dbus_message_new_method_return(msg);
-
- if (NULL != reply) {
- dbus_message_append_args(reply,
- DBUS_TYPE_INT32, &ret,
- DBUS_TYPE_INVALID);
-
- if (0 == ret) {
- MAS_LOGD("[OUT] mas ui change assisant : result(%d)", ret);
- } else {
- MAS_LOGE("[OUT ERROR] mas ui change assisant : result(%d)", ret);
- }
-
- if (!dbus_connection_send(conn, reply, NULL)) {
- MAS_LOGE("[OUT ERROR] mas ui change assisant : Out Of Memory!");
- }
-
- dbus_connection_flush(conn);
- dbus_message_unref(reply);
- } else {
- MAS_LOGE("[OUT ERROR] mas ui change assisant : Fail to create reply message!!");
- }
-
- MAS_LOGD("<<<<<");
- MAS_LOGD(" ");
-
- return ret;
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright 2018-2019 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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 __MULTI_ASSISTANT_DBUS_SERVER_H__
-#define __MULTI_ASSISTANT_DBUS_SERVER_H__
-
-#include <dbus/dbus.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int ma_service_dbus_hello(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_dbus_initialize(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_dbus_deinitialize(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_dbus_get_audio_format(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_dbus_get_audio_source_type(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_dbus_send_asr_result(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_dbus_send_result(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_dbus_send_recognition_result(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_dbus_start_streaming_audio_data(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_dbus_stop_streaming_audio_data(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_dbus_update_voice_feedback_state(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_dbus_send_assistant_specific_command(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_dbus_set_background_volume(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_dbus_set_preprocessing_allow_mode(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_dbus_send_preprocessing_result(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_dbus_set_wake_word_audio_require_flag(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_dbus_set_assistant_language(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_dbus_add_wake_word(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_dbus_remove_wake_word(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_ui_dbus_initialize(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_ui_dbus_deinitialize(DBusConnection* conn, DBusMessage* msg);
-
-int ma_service_ui_dbus_change_assistant(DBusConnection* conn, DBusMessage* msg);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* __MULTI_ASSISTANT_DBUS_SERVER_H__ */
+++ /dev/null
-/*
- * Copyright 2018-2019 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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.
- */
-
-#include <tizen.h>
-#include <service_app.h>
-#include <app_manager.h>
-#include <app.h>
-#include <aul.h>
-#include <aul_svc.h>
-#include <malloc.h>
-#include <Ecore.h>
-#include <vconf.h>
-#include <package_manager.h>
-#include <pkgmgr-info.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <glib.h>
-
-#include "multi_assistant_main.h"
-#include "multi_assistant_service_client.h"
-#include "multi_assistant_service_plugin.h"
-#include "multi_assistant_dbus.h"
-#include "multi_assistant_config.h"
-
-static const char *g_current_lang = "en_US";
-
-#define ENABLE_MULTI_ASSISTANT_BY_DEFAULT
-
-#define MULTI_ASSISTANT_SETTINGS_ACTIVATED "db/multi-assistant/activated"
-#define WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID "db/multi-assistant/preprocessing_assistant_appid"
-#define WAKEUP_SETTINGS_KEY_PRELAUNCH_MODE "db/multi-assistant/prelaunch_mode"
-
-#define MAX_MACLIENT_INFO_NUM 16
-typedef struct {
- bool used;
- char appid[MAX_APPID_LEN];
- char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN];
- char wakeup_language[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN];
- char wakeup_engine[MAX_APPID_LEN];
- char supported_language[MAX_SUPPORTED_LANGUAGES_NUM][MAX_SUPPORTED_LANGUAGE_LEN];
- bool custom_ui_option;
- VOICE_KEY_SUPPORT_MODE voice_key_support_mode;
- float voice_key_tap_duration;
-
- ma_preprocessing_allow_mode_e preprocessing_allow_mode;
- char preprocessing_allow_appid[MAX_APPID_LEN];
-} ma_client_info;
-
-static ma_client_info g_maclient_info[MAX_MACLIENT_INFO_NUM];
-
-typedef struct {
- int pid;
- char appid[MAX_APPID_LEN];
-} ma_client_s;
-
-static int g_current_maclient_info = 0;
-static int g_current_preprocessing_maclient_info = -1;
-static const char *g_wakeup_maclient_appid = NULL;
-static package_manager_h g_pkgmgr = NULL;
-
-static PREPROCESSING_STATE g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
-static ma_service_state_e g_current_service_state = MA_SERVICE_STATE_INACTIVE;
-static ma_voice_key_status_e g_last_voice_key_status = MA_VOICE_KEY_STATUS_RELEASED_AFTER_PUSH;
-
-/* client list */
-static GSList* g_client_list = NULL;
-static CConfig g_config;
-
-int ma_client_create(ma_client_s *info)
-{
- if (NULL == info) {
- MAS_LOGE("Input parameter is NULL"); //LCOV_EXCL_LINE
- return -1;
- }
-
- ma_client_s* data = NULL;
-
- data = (ma_client_s*)calloc(1, sizeof(ma_client_s));
- if (NULL == data) {
- MAS_LOGE("[ERROR] Fail to allocate memory"); //LCOV_EXCL_LINE
- return -1;// MA_ERROR_OUT_OF_MEMORY;
- }
-
- *data = *info;
- g_client_list = g_slist_append(g_client_list, data);
-
- return 0;
-}
-
-int ma_client_destroy(ma_client_s *client)
-{
- if (NULL == client) {
- MAS_LOGE("Input parameter is NULL"); //LCOV_EXCL_LINE
- return -1;// MA_ERROR_OPERATION_FAILED;
- }
-
- g_client_list = g_slist_remove(g_client_list, client);
-
- free(client);
- client = NULL;
-
- return 0;
-}
-
-ma_client_s* ma_client_find_by_appid(const char *appid)
-{
- if (NULL == appid) {
- MAS_LOGE("Input parameter is NULL"); //LCOV_EXCL_LINE
- return NULL;
- }
-
- ma_client_s *data = NULL;
-
- int count = g_slist_length(g_client_list);
- int i;
-
- for (i = 0; i < count; i++) {
- data = static_cast<ma_client_s*>(g_slist_nth_data(g_client_list, i));
-
- if (NULL != data) {
- if (0 == strncmp(data->appid, appid, MAX_APPID_LEN)) {
- return data;
- }
- }
- }
-
- MAS_LOGE("[ERROR] client Not found");
-
- return NULL;
-}
-
-ma_client_s* ma_client_find_by_pid(int pid)
-{
- ma_client_s *data = NULL;
-
- int count = g_slist_length(g_client_list);
- int i;
-
- for (i = 0; i < count; i++) {
- data = static_cast<ma_client_s*>(g_slist_nth_data(g_client_list, i));
-
- if (NULL != data) {
- if (data->pid == pid) {
- return data;
- }
- }
- }
-
- MAS_LOGE("[ERROR] client Not found");
-
- return NULL;
-}
-
-bool check_preprocessing_assistant_exists()
-{
- bool ret = false;
-
- char* vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
- if (vconf_str) {
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- if (g_maclient_info[loop].used) {
- if (strncmp(vconf_str, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
- ma_client_s* client = ma_client_find_by_appid(vconf_str);
- if (client && client->pid > 0) {
- ret = true;
- }
- }
- }
- }
- free(vconf_str);
- vconf_str = NULL;
- }
-
- MAS_LOGD("result : %d", ret);
-
- return ret;
-}
-
-bool is_current_preprocessing_assistant(const char* appid)
-{
- if (NULL == appid) return false;
-
- bool ret = false;
-
- char* vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
- if (vconf_str) {
- if (strncmp(vconf_str, appid, MAX_APPID_LEN) == 0) {
- ret = true;
- }
- free(vconf_str);
- vconf_str = NULL;
- }
-
- return ret;
-}
-
-int mas_client_initialize(int pid)
-{
- MAS_LOGD("[Enter] pid(%d)", pid);
-
- char appid[MAX_APPID_LEN] = {'\0',};
- if (AUL_R_OK == aul_app_get_appid_bypid(pid, appid, sizeof(appid))) {
- appid[MAX_APPID_LEN - 1] = '\0';
-
- MAS_LOGD("appid for pid %d is : %s", pid, (appid ? appid : "Unknown"));
-
- /* Remove existing client that has same appid, if there's any */
- ma_client_s *old_client = NULL;
- old_client = ma_client_find_by_appid(appid);
- if (old_client) {
- ma_client_destroy(old_client);
- old_client = NULL;
- }
-
- /* And remove a client that has same pid also */
- old_client = ma_client_find_by_pid(pid);
- if (old_client) {
- ma_client_destroy(old_client);
- old_client = NULL;
- }
-
- ma_client_s new_client;
- new_client.pid = pid;
- strncpy(new_client.appid, appid, MAX_APPID_LEN);
- new_client.appid[MAX_APPID_LEN - 1] = '\0';
- ma_client_create(&new_client);
-
- const char *current_maclient_appid = NULL;
- if (g_current_maclient_info >= 0 && g_current_maclient_info < MAX_MACLIENT_INFO_NUM) {
- current_maclient_appid = g_maclient_info[g_current_maclient_info].appid;
- }
-
- mas_client_send_preprocessing_information(pid);
- if (MA_VOICE_KEY_STATUS_PRESSED == g_last_voice_key_status) {
- mas_client_send_voice_key_status_change(pid, g_last_voice_key_status);
- }
- if (current_maclient_appid && 0 == strncmp(current_maclient_appid, appid, MAX_APPID_LEN)) {
- MAS_LOGD("MA client with current maclient appid connected!");
-
- if (g_wakeup_maclient_appid && strncmp(g_wakeup_maclient_appid, appid, MAX_APPID_LEN) == 0) {
- g_wakeup_maclient_appid = NULL;
- mas_client_activate(pid);
- mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED);
- } else {
- MAS_LOGE("[ERROR] g_wakeup_maclient_appid and appid differ : %s %s",
- (g_wakeup_maclient_appid ? g_wakeup_maclient_appid : "NULL"), appid);
- }
- } else {
- MAS_LOGD("MA client connected, but its appid does not match with current maclient");
- }
-
- masc_dbus_service_state_change(pid, mas_get_current_service_state());
- } else {
- MAS_LOGE("[ERROR] Fail to retrieve appid");
- }
-
- return 0;
-}
-
-int mas_client_deinitialize(int pid)
-{
- MAS_LOGD("[Enter] pid(%d)", pid);
- ma_client_s *client = ma_client_find_by_pid(pid);
- if (client) {
- ma_client_destroy(client);
- client = NULL;
- }
- return 0;
-}
-
-int mas_client_get_audio_format(int pid, int* rate, int* channel, int* audio_type)
-{
- MAS_LOGD("[Enter] pid(%d)", pid);
-
- int ret = multi_assistant_service_plugin_get_recording_audio_format(rate, channel, audio_type);
- if (0 != ret){
- MAS_LOGE("[ERROR] Fail to get recording audio format, ret(%d)", ret);
- }
-
- return ret;
-}
-
-#define MAX_LOCAL_VARIABLE_STRING_LEN 256
-int mas_client_get_audio_source_type(int pid, char** type)
-{
- MAS_LOGD("[Enter] pid(%d)", pid);
-
- if (NULL == type) return -1;
-
- static char cached[MAX_LOCAL_VARIABLE_STRING_LEN] = {'\0'};
- int ret = multi_assistant_service_plugin_get_recording_audio_source_type(type);
- if (0 != ret){
- MAS_LOGE("[ERROR] Fail to get recording audio source type, ret(%d)", ret);
- *type = cached;
- } else if (*type) {
- strncpy(cached, *type, MAX_LOCAL_VARIABLE_STRING_LEN - 1);
- cached[MAX_LOCAL_VARIABLE_STRING_LEN - 1] = '\0';
- }
-
- return ret;
-}
-
-int mas_client_send_preprocessing_information(int pid)
-{
- int ret = -1;
- MAS_LOGD("[Enter] pid(%d)", pid);
-
- char* vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
- MAS_LOGD("preprocessing_assistant_appid : %s", vconf_str);
- if (vconf_str) {
- ret = masc_dbus_send_preprocessing_information(pid, vconf_str);
- free(vconf_str);
- vconf_str = NULL;
- }
-
- return ret;
-}
-
-int mas_client_send_voice_key_status_change(int pid, ma_voice_key_status_e status)
-{
- g_last_voice_key_status = status;
- int ret = masc_dbus_voice_key_status_change(pid, status);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to send voice key status changed information, ret(%d)", ret);
- }
- return ret;
-}
-
-int mas_client_activate(int pid)
-{
- int ret = -1;
- MAS_LOGD("[Enter] pid(%d)", pid);
-
- ret = masc_dbus_active_state_change(pid, MA_ACTIVE_STATE_ACTIVE);
-
- return ret;
-}
-
-int mas_client_deactivate(int pid)
-{
- int ret = -1;
- MAS_LOGD("[Enter] pid(%d)", pid);
-
- ret = masc_dbus_active_state_change(pid, MA_ACTIVE_STATE_INACTIVE);
-
- return ret;
-}
-
-int mas_client_send_asr_result(int pid, int event, char* asr_result)
-{
- MAS_LOGD("[Enter] pid(%d), event(%d), asr_result(%s)", pid, event, asr_result);
- int ret = masc_ui_dbus_send_asr_result(pid, event, asr_result);
- if (0 != ret){
- MAS_LOGE("[ERROR] Fail to send asr result, ret(%d)", ret);
- }
-
- // if final event is , launch assistant app which is invoked with wakeup word.
- /* TO_DO */
- return ret;
-}
-
-int mas_client_send_result(int pid, char* display_text, char* utterance_text, char* result_json)
-{
- MAS_LOGD("[Enter] pid(%d), display_text(%s), utterance_text(%s), result_json(%s)", pid, display_text, utterance_text, result_json);
- int ret = masc_ui_dbus_send_result(pid, display_text, utterance_text, result_json);
- if (0 != ret){
- MAS_LOGE("[ERROR] Fail to send result, ret(%d)", ret);
- }
-
- const char* pid_appid = NULL;
- char buf[MAX_APPID_LEN] = {'\0',};
- if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) {
- buf[MAX_APPID_LEN - 1] = '\0';
- pid_appid = buf;
- }
- multi_assistant_service_plugin_update_recognition_result(pid_appid, MA_RECOGNITION_RESULT_EVENT_SUCCESS);
-
- return ret;
-}
-
-int mas_client_send_recognition_result(int pid, int result)
-{
- MAS_LOGD("[Enter] pid(%d), result(%d)", pid, result);
- int ret = masc_ui_dbus_send_recognition_result(pid, result);
- if (0 != ret){
- MAS_LOGE("[ERROR] Fail to send recognition result, ret(%d)", ret);
- }
-
- const char* pid_appid = NULL;
- char buf[MAX_APPID_LEN] = {'\0',};
- if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) {
- buf[MAX_APPID_LEN - 1] = '\0';
- pid_appid = buf;
- }
- multi_assistant_service_plugin_update_recognition_result(pid_appid, result);
-
- return ret;
-}
-
-int mas_client_start_streaming_audio_data(int pid, int type)
-{
- int ret = -1;
- switch(type) {
- case MA_AUDIO_STREAMING_DATA_TYPE_CURRENT_UTTERANCE:
- ret = multi_assistant_service_plugin_start_streaming_utterance_data();
- mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED);
- break;
- case MA_AUDIO_STREAMING_DATA_TYPE_PREVIOUS_UTTERANCE:
- ret = multi_assistant_service_plugin_start_streaming_previous_utterance_data();
- /* Preprocessing is not required for previous utterance streaming */
- break;
- case MA_AUDIO_STREAMING_DATA_TYPE_FOLLOW_UP_SPEECH:
- ret = multi_assistant_service_plugin_start_streaming_follow_up_data();
- mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED);
- break;
- }
- return ret;
-}
-
-int mas_client_stop_streaming_audio_data(int pid, int type)
-{
- int ret = -1;
- switch(type) {
- case MA_AUDIO_STREAMING_DATA_TYPE_CURRENT_UTTERANCE:
- ret = multi_assistant_service_plugin_stop_streaming_utterance_data();
- break;
- case MA_AUDIO_STREAMING_DATA_TYPE_PREVIOUS_UTTERANCE:
- ret = multi_assistant_service_plugin_stop_streaming_previous_utterance_data();
- break;
- case MA_AUDIO_STREAMING_DATA_TYPE_FOLLOW_UP_SPEECH:
- ret = multi_assistant_service_plugin_stop_streaming_follow_up_data();
- break;
- }
- return ret;
-}
-
-int mas_client_update_voice_feedback_state(int pid, int state)
-{
- const char* pid_appid = NULL;
- char buf[MAX_APPID_LEN] = {'\0',};
- if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) {
- buf[MAX_APPID_LEN - 1] = '\0';
- pid_appid = buf;
- }
- multi_assistant_service_plugin_update_voice_feedback_state(pid_appid, state);
- return 0;
-}
-
-int mas_client_set_assistant_specific_command(int pid, const char *command)
-{
- const char* pid_appid = NULL;
- char buf[MAX_APPID_LEN] = {'\0',};
- if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) {
- buf[MAX_APPID_LEN - 1] = '\0';
- pid_appid = buf;
- }
- multi_assistant_service_plugin_set_assistant_specific_command(pid_appid, command);
- return 0;
-}
-
-int mas_client_set_background_volume(int pid, double ratio)
-{
- const char* pid_appid = NULL;
- char buf[MAX_APPID_LEN] = {'\0',};
- if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) {
- buf[MAX_APPID_LEN - 1] = '\0';
- pid_appid = buf;
- }
- multi_assistant_service_plugin_set_background_volume(pid_appid, ratio);
- return 0;
-}
-
-int mas_client_set_preprocessing_allow_mode(int pid, ma_preprocessing_allow_mode_e mode, const char* appid)
-{
- const char* pid_appid = NULL;
- char buf[MAX_APPID_LEN] = {'\0',};
- if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) {
- buf[MAX_APPID_LEN - 1] = '\0';
- pid_appid = buf;
- }
-
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- if (g_maclient_info[loop].used) {
- if (pid_appid && strncmp(pid_appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
- g_maclient_info[loop].preprocessing_allow_mode = mode;
- if (appid) {
- strncpy(g_maclient_info[loop].preprocessing_allow_appid, appid, MAX_APPID_LEN);
- g_maclient_info[loop].preprocessing_allow_appid[MAX_APPID_LEN - 1] = '\0';
- } else {
- g_maclient_info[loop].preprocessing_allow_appid[0] = '\0';
- }
- }
- }
- }
-
- mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_ALLOW_MODE_CHANGED);
-
- return 0;
-}
-
-int mas_client_send_preprocessing_result(int pid, bool result)
-{
- const char* pid_appid = NULL;
- char buf[MAX_APPID_LEN] = {'\0',};
- if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) {
- buf[MAX_APPID_LEN - 1] = '\0';
- pid_appid = buf;
- }
- if (!is_current_preprocessing_assistant(pid_appid)) return -1;
-
- const char *current_maclient_appid = NULL;
- if (g_current_maclient_info >= 0 && g_current_maclient_info < MAX_MACLIENT_INFO_NUM) {
- current_maclient_appid = g_maclient_info[g_current_maclient_info].appid;
- }
-
- if (result) {
- MAS_LOGD("Preprocessing succeeded, bring (%s) to foreground", pid_appid);
- mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_SUCCEEDED);
- } else {
- MAS_LOGD("Preprocessing failed, bring (%s) to foreground", current_maclient_appid);
- mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_FAILED);
- }
-
- ma_client_s* client = ma_client_find_by_appid(current_maclient_appid);
- if (client) {
- masc_dbus_send_preprocessing_result(client->pid, result);
- }
-
- return 0;
-}
-
-int mas_client_set_wake_word_audio_require_flag(int pid, bool require)
-{
- const char* pid_appid = NULL;
- char buf[MAX_APPID_LEN] = {'\0',};
- if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) {
- buf[MAX_APPID_LEN - 1] = '\0';
- pid_appid = buf;
- }
-
- multi_assistant_service_plugin_set_wake_word_audio_require_flag(pid_appid, require);
- return 0;
-}
-
-int mas_client_set_assistant_language(int pid, const char* language)
-{
- const char* pid_appid = NULL;
- char buf[MAX_APPID_LEN] = {'\0',};
- int ret = aul_app_get_appid_bypid(pid, buf, sizeof(buf));
- if (AUL_R_OK == ret) {
- buf[MAX_APPID_LEN - 1] = '\0';
- pid_appid = buf;
- }
-
- multi_assistant_service_plugin_set_assistant_language(pid_appid, language);
- return 0;
-}
-
-int mas_client_add_wake_word(int pid, const char* wake_word, const char* language)
-{
- const char* pid_appid = NULL;
- char buf[MAX_APPID_LEN] = {'\0',};
- int ret = aul_app_get_appid_bypid(pid, buf, sizeof(buf));
- if (AUL_R_OK == ret) {
- buf[MAX_APPID_LEN - 1] = '\0';
- pid_appid = buf;
- }
-
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- if (g_maclient_info[loop].used &&
- 0 == strncmp(buf, g_maclient_info[loop].appid, MAX_APPID_LEN)) {
- ret = g_config.mas_config_add_custom_wake_word(wake_word, language,
- g_maclient_info[loop].wakeup_word,
- g_maclient_info[loop].wakeup_language);
- if (0 == ret) {
- g_config.mas_config_save_custom_wake_words(pid_appid,
- g_maclient_info[loop].wakeup_word,
- g_maclient_info[loop].wakeup_language);
- } else {
- LOGE("add new wake word failed!");
- return -1;
- }
- }
- }
-
- multi_assistant_service_plugin_add_assistant_wakeup_word(pid_appid, wake_word, language);
- return 0;
-}
-
-int mas_client_remove_wake_word(int pid, const char* wake_word, const char* language)
-{
- const char* pid_appid = NULL;
- char buf[MAX_APPID_LEN] = {'\0',};
- int ret = aul_app_get_appid_bypid(pid, buf, sizeof(buf));
- if (AUL_R_OK == ret) {
- buf[MAX_APPID_LEN - 1] = '\0';
- pid_appid = buf;
- }
-
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- if (g_maclient_info[loop].used &&
- 0 == strncmp(buf, g_maclient_info[loop].appid, MAX_APPID_LEN)) {
- ret = g_config.mas_config_remove_custom_wake_word(wake_word, language,
- g_maclient_info[loop].wakeup_word,
- g_maclient_info[loop].wakeup_language);
- if (0 == ret) {
- g_config.mas_config_save_custom_wake_words(pid_appid,
- g_maclient_info[loop].wakeup_word,
- g_maclient_info[loop].wakeup_language);
- }
- }
- }
-
- multi_assistant_service_plugin_remove_assistant_wakeup_word(pid_appid, wake_word, language);
- return 0;
-}
-
-int mas_ui_client_initialize(int pid)
-{
- MAS_LOGD("[Enter] pid(%d)", pid);
-
- return 0;
-}
-
-int mas_ui_client_deinitialize(int pid)
-{
- MAS_LOGD("[Enter] pid(%d)", pid);
-
- return 0;
-}
-
-int mas_ui_client_change_assistant(const char* appid)
-{
- MAS_LOGD("[Enter]");
-
- if (NULL == appid) {
- MAS_LOGE("NULL parameter");
- return -1;
- }
-
- bool use_custom_ui = mas_get_client_custom_ui_option_by_appid(appid);
- masc_ui_dbus_enable_common_ui(!use_custom_ui);
-
- mas_set_current_client_by_appid(appid);
- int pid = mas_get_client_pid_by_appid(appid);
- if (pid != -1) {
- mas_bring_client_to_foreground(appid);
- mas_client_send_preprocessing_information(pid);
- if (MA_VOICE_KEY_STATUS_PRESSED == g_last_voice_key_status) {
- mas_client_send_voice_key_status_change(pid, g_last_voice_key_status);
- }
-
- mas_client_activate(pid);
- MAS_LOGD("MA Client with appid %s exists, requesting speech data", (appid ? appid : "NULL"));
- /*
- int ret = multi_assistant_service_plugin_start_streaming_utterance_data();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to start streaming utterance data(%d)", ret);
- }
- */
- } else {
- // Appropriate MA Client not available, trying to launch new one
- MAS_LOGD("MA Client with appid %s does not exist, launching client", (appid ? appid : "NULL"));
-
- /* The appid parameter might not exist after this function call, so we use appid string in our g_maclient_info */
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- if (g_maclient_info[loop].used &&
- 0 < strlen(g_maclient_info[loop].appid) &&
- 0 < strlen(g_maclient_info[loop].wakeup_word[0])) {
- if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
- mas_launch_client_by_appid(g_maclient_info[loop].appid, CLIENT_LAUNCH_MODE_ACTIVATION);
- }
- }
- }
- }
-
- return 0;
-}
-
-int __mas_assistant_info_cb(ma_assistant_info_s* info, void* user_data) {
- MAS_LOGD("__mas_assistant_info_cb called");
-
- if (NULL == info) {
- MAS_LOGE("info NULL, returning");
- return -1;
- }
- if (NULL == info->app_id) {
- MAS_LOGE("app_id NULL, returning");
- return -1;
- }
-
- int index = -1;
- int loop = 0;
- while(-1 == index && loop < MAX_MACLIENT_INFO_NUM) {
- if (false == g_maclient_info[loop].used) {
- index = loop;
- }
- loop++;
- }
- if (-1 != index) {
- g_maclient_info[index].used = true;
- g_maclient_info[index].preprocessing_allow_mode = MA_PREPROCESSING_ALLOW_NONE;
- g_maclient_info[index].preprocessing_allow_appid[0] = '\0';
- MAS_LOGD("app_id(%s)", info->app_id);
- strncpy(g_maclient_info[index].appid, info->app_id, MAX_APPID_LEN);
- g_maclient_info[index].appid[MAX_APPID_LEN - 1] = '\0';
-
- if (is_current_preprocessing_assistant(g_maclient_info[index].appid)) {
- g_current_preprocessing_maclient_info = index;
- }
-
- for (loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) {
- if (loop < info->cnt_wakeup && info->wakeup_list[loop]) {
- MAS_LOGD("wakeup_list(%d)(%s)(%s)", loop, info->wakeup_list[loop], info->wakeup_language[loop]);
- strncpy(g_maclient_info[index].wakeup_word[loop], info->wakeup_list[loop], MAX_WAKEUP_WORD_LEN);
- g_maclient_info[index].wakeup_word[loop][MAX_WAKEUP_WORD_LEN - 1] = '\0';
- if (info->wakeup_language[loop]) {
- strncpy(g_maclient_info[index].wakeup_language[loop], info->wakeup_language[loop], MAX_SUPPORTED_LANGUAGE_LEN);
- g_maclient_info[index].wakeup_language[loop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
- } else {
- strncpy(g_maclient_info[index].wakeup_language[loop], "", MAX_SUPPORTED_LANGUAGE_LEN);
- }
- } else {
- strncpy(g_maclient_info[index].wakeup_word[loop], "", MAX_WAKEUP_WORD_LEN);
- }
- }
-
- for (loop = 0;loop < MAX_SUPPORTED_LANGUAGES_NUM;loop++) {
- if (loop < info->cnt_lang && info->supported_lang[loop]) {
- MAS_LOGD("supported_lang(%d)(%s)", loop, info->supported_lang[loop]);
- strncpy(g_maclient_info[index].supported_language[loop], info->supported_lang[loop], MAX_SUPPORTED_LANGUAGE_LEN);
- g_maclient_info[index].supported_language[loop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
- } else {
- strncpy(g_maclient_info[index].supported_language[loop], "", MAX_SUPPORTED_LANGUAGE_LEN);
- }
- }
-
- MAS_LOGD("wakeup_engine(%s)", info->wakeup_engine);
- if (info->wakeup_engine) {
- strncpy(g_maclient_info[index].wakeup_engine, info->wakeup_engine, MAX_APPID_LEN);
- g_maclient_info[index].wakeup_engine[MAX_APPID_LEN - 1] = '\0';
- } else {
- g_maclient_info[index].wakeup_engine[0] = '\0';
- MAS_LOGW("Wakeup engine information not provided for : %s", info->app_id);
- }
- g_maclient_info[index].custom_ui_option = info->custom_ui_option;
-
- MAS_LOGD("voice_key_support_mode(%d)", info->voice_key_support_mode);
- g_maclient_info[index].voice_key_support_mode = info->voice_key_support_mode;
- MAS_LOGD("voice_key_tap_duration(%f)", info->voice_key_tap_duration);
- g_maclient_info[index].voice_key_tap_duration = info->voice_key_tap_duration;
- } else {
- MAS_LOGD("Couldn't find an empty slot for storing assistant info");
- }
-
- MAS_LOGD("__mas_assistant_info_cb end");
-
- return 0;
-}
-
-static void mas_active_state_changed_cb(keynode_t* key, void* data)
-{
- int vconf_value = 0;
- if (vconf_get_bool(MULTI_ASSISTANT_SETTINGS_ACTIVATED, &vconf_value) == 0) {
- MAS_LOGD("multi-assistant active state : %d\n", vconf_value);
-
- if (vconf_value) {
- multi_assistant_service_plugin_activate();
- } else {
- multi_assistant_service_plugin_deactivate();
- }
- }
-}
-
-static int init_plugin(void)
-{
- if (0 != multi_assistant_service_plugin_initialize()) {
- MAS_LOGE("Fail to ws intialize");
- return -1;
- }
-
- if (0 != multi_assistant_service_plugin_set_language(g_current_lang)) {
- MAS_LOGE("Fail to ws set language");
- return -1;
- }
-
- if (0 == g_config.mas_config_get_assistant_info(__mas_assistant_info_cb, NULL)) {
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- int inner_loop;
- if (g_maclient_info[loop].used &&
- 0 < strlen(g_maclient_info[loop].appid)) {
- g_config.mas_config_load_custom_wake_words(g_maclient_info[loop].appid,
- g_maclient_info[loop].wakeup_word, g_maclient_info[loop].wakeup_language);
- if (0 < strlen(g_maclient_info[loop].wakeup_engine)) {
- multi_assistant_service_plugin_set_assistant_wakeup_engine(
- g_maclient_info[loop].appid,
- g_maclient_info[loop].wakeup_engine);
- }
- for (inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
- if (0 < strlen(g_maclient_info[loop].wakeup_word[inner_loop])) {
- MAS_LOGD("Registering wakeup word %s for app %s",
- g_maclient_info[loop].wakeup_word[inner_loop], g_maclient_info[loop].appid);
- if (0 != multi_assistant_service_plugin_add_assistant_wakeup_word(
- g_maclient_info[loop].appid,
- g_maclient_info[loop].wakeup_word[inner_loop],
- g_maclient_info[loop].wakeup_language[inner_loop])) {
- MAS_LOGE("Fail to add assistant's wakeup word");
- }
- }
- }
- for (inner_loop = 0; inner_loop < MAX_SUPPORTED_LANGUAGE_NUM; inner_loop++) {
- if (0 < strlen(g_maclient_info[loop].supported_language[inner_loop])) {
- MAS_LOGD("Adding language %s for app %s",
- g_maclient_info[loop].supported_language[inner_loop], g_maclient_info[loop].appid);
- if (0 != multi_assistant_service_plugin_add_assistant_language(
- g_maclient_info[loop].appid,
- g_maclient_info[loop].supported_language[inner_loop])) {
- MAS_LOGE("Fail to add assistant's language");
- }
- }
- }
- }
- }
- } else {
- MAS_LOGE("Fail to load assistant info");
- }
-
- if (0 != multi_assistant_service_plugin_set_callbacks()) {
- MAS_LOGE("Fail to set callbacks");
- return -1;
- }
-
- return 0;
-}
-
-static int deinit_plugin(void)
-{
- MAS_LOGI("[ENTER]");
- if (0 != multi_assistant_service_plugin_deactivate()) {
- MAS_LOGE("Fail to deactivate");
- }
- if (0 != multi_assistant_service_plugin_deinitialize()) {
- MAS_LOGE("Fail to deinitialize");
- }
- MAS_LOGI("[END]");
- return 0;
-}
-
-static int process_activated_setting()
-{
- if (0 == vconf_notify_key_changed(MULTI_ASSISTANT_SETTINGS_ACTIVATED, mas_active_state_changed_cb, NULL)) {
- /* Activate / deactivate according to the vconf key setting */
- mas_active_state_changed_cb(NULL, NULL);
- } else {
-#ifdef ENABLE_MULTI_ASSISTANT_BY_DEFAULT
- /* Multi-assistant needs to be enabled by default, unless disabled explicitly */
- multi_assistant_service_plugin_activate();
- const char *default_assistant = NULL;
- if (0 == multi_assistant_service_plugin_get_default_assistant(&default_assistant)) {
- if (NULL == default_assistant) {
- if (g_maclient_info[0].used) {
- default_assistant = g_maclient_info[0].appid;
- MAS_LOGW("No default assistant, setting %s as default", default_assistant);
- multi_assistant_service_plugin_set_default_assistant(default_assistant);
- } else {
- MAS_LOGE("No default assistant, and no assistant installed");
- }
- }
- }
-#endif
- }
- return 0;
-}
-
-static int init_wakeup(void)
-{
- MAS_LOGD("[Enter] init_wakeup");
-
- int ret = mas_dbus_open_connection();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to open connection");
- }
-
- init_plugin();
-
- process_activated_setting();
-
- mas_prelaunch_default_assistant();
- mas_update_voice_key_support_mode();
-
- /* For the case of preprocessing assistant, it always have to be launched beforehand */
- char *vconf_str;
- vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
- if (vconf_str) {
- MAS_LOGD("prelaunching preprocessing_assistant_appid : %s", vconf_str);
- mas_launch_client_by_appid(vconf_str, CLIENT_LAUNCH_MODE_PRELAUNCH);
- free(vconf_str);
- vconf_str = NULL;
- }
-
- return 0;
-}
-
-static void deinit_wakeup(void)
-{
- MAS_LOGI("[Enter] deinit_wakeup");
-
-/* if (NULL != g_current_lang) {
- free(g_current_lang);
- g_current_lang = NULL;
- }
-*/
- deinit_plugin();
-
- vconf_ignore_key_changed(MULTI_ASSISTANT_SETTINGS_ACTIVATED, mas_active_state_changed_cb);
-
- int ret = mas_dbus_close_connection();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to close connection");
- }
- MAS_LOGI("[END]");
-}
-
-int mas_get_current_client_pid()
-{
- int ret = -1;
- if (g_current_maclient_info >= 0 && g_current_maclient_info < MAX_MACLIENT_INFO_NUM) {
- const char *appid = g_maclient_info[g_current_maclient_info].appid;
- ma_client_s* client = ma_client_find_by_appid(appid);
- if (client) {
- ret = client->pid;
- }
- }
- return ret;
-}
-
-int mas_get_current_preprocessing_client_pid()
-{
- int ret = -1;
- if (g_current_preprocessing_maclient_info >= 0 && g_current_preprocessing_maclient_info < MAX_MACLIENT_INFO_NUM) {
- const char *appid = g_maclient_info[g_current_preprocessing_maclient_info].appid;
- ma_client_s* client = ma_client_find_by_appid(appid);
- if (client) {
- ret = client->pid;
- }
- }
- return ret;
-}
-
-int mas_get_client_pid_by_appid(const char *appid)
-{
- int ret = -1;
-
- if (appid) {
- ma_client_s *client = NULL;
- client = ma_client_find_by_appid(appid);
- if (client) {
- ret = client->pid;
- }
- }
-
- int status = aul_app_get_status_bypid(ret);
- if (-1 != ret && 0 > status) {
- MAS_LOGE("The PID for %s was %d, but it seems to be terminated : %d",
- (appid ? appid : "NULL"), ret, status);
- mas_client_deinitialize(ret);
- ret = -1;
- }
-
- return ret;
-}
-
-const char* mas_get_client_appid_by_pid(int pid)
-{
- const char* ret = NULL;
-
- ma_client_s *client = NULL;
- client = ma_client_find_by_pid(pid);
- if (client) {
- ret = client->appid;
- }
-
- int status = aul_app_get_status_bypid(pid);
- if (NULL != ret && 0 > status) {
- MAS_LOGE("The appid for %d was %s, but it seems to be terminated : %d",
- pid, (ret ? ret : "NULL"), status);
- mas_client_deinitialize(pid);
- ret = NULL;
- }
-
- return ret;
-}
-
-bool mas_get_client_custom_ui_option_by_appid(const char *appid)
-{
- bool ret = false;
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- if (g_maclient_info[loop].used &&
- 0 < strlen(g_maclient_info[loop].appid) &&
- 0 < strlen(g_maclient_info[loop].wakeup_word[0])) {
- if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
- ret = g_maclient_info[loop].custom_ui_option;
- }
- }
- }
- return ret;
-}
-
-int mas_get_client_pid_by_wakeup_word(const char *wakeup_word)
-{
- const char *appid = mas_get_client_appid_by_wakeup_word(wakeup_word);
- return mas_get_client_pid_by_appid(appid);
-}
-
-const char* mas_get_client_appid_by_wakeup_word(const char *wakeup_word)
-{
- int loop;
- const char *appid = NULL;
-
- if (NULL == wakeup_word) return NULL;
-
- for (loop = 0; loop < MAX_MACLIENT_INFO_NUM && NULL == appid; loop++) {
- if (g_maclient_info[loop].used &&
- 0 < strlen(g_maclient_info[loop].appid)) {
- for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
- if (0 < strlen(g_maclient_info[loop].wakeup_word[inner_loop])) {
- if (0 == strncmp(wakeup_word, g_maclient_info[loop].wakeup_word[inner_loop], MAX_WAKEUP_WORD_LEN)) {
- appid = g_maclient_info[loop].appid;
- }
- }
- }
- }
- }
-
- /* Perform extended search, by eliminating blank characters */
- if (NULL == appid) {
- for (loop = 0; loop < MAX_MACLIENT_INFO_NUM && NULL == appid; loop++) {
- if (g_maclient_info[loop].used &&
- 0 < strlen(g_maclient_info[loop].appid)) {
- for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
- if (0 < strlen(g_maclient_info[loop].wakeup_word[inner_loop])) {
- char comparand[MAX_WAKEUP_WORD_LEN];
- int comparand_index = 0;
- for (int index = 0; index < MAX_WAKEUP_WORD_LEN; index++) {
- if (' ' != g_maclient_info[loop].wakeup_word[inner_loop][index]) {
- comparand[comparand_index++] = g_maclient_info[loop].wakeup_word[inner_loop][index];
- }
- }
- if (0 == strncmp(wakeup_word, comparand, MAX_WAKEUP_WORD_LEN)) {
- appid = g_maclient_info[loop].appid;
- }
- }
- }
- }
- }
- }
-
- return appid;
-}
-
-int mas_set_current_client_by_wakeup_word(const char *wakeup_word)
-{
- int loop;
- int ret = -1;
- int prev_selection = g_current_maclient_info;
-
- for (loop = 0; loop < MAX_MACLIENT_INFO_NUM && -1 == ret; loop++) {
- if (g_maclient_info[loop].used &&
- 0 < strlen(g_maclient_info[loop].appid)) {
- for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
- if (0 < strlen(g_maclient_info[loop].wakeup_word[inner_loop])) {
- if (0 == strncmp(wakeup_word, g_maclient_info[loop].wakeup_word[inner_loop], MAX_WAKEUP_WORD_LEN)) {
- g_current_maclient_info = loop;
- ret = 0;
- }
- }
- }
- }
- }
- /* Perform extended search, by eliminating blank characters */
- if (ret == -1) {
- for (loop = 0; loop < MAX_MACLIENT_INFO_NUM && -1 == ret; loop++) {
- if (g_maclient_info[loop].used &&
- 0 < strlen(g_maclient_info[loop].appid)) {
- for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
- if (0 < strlen(g_maclient_info[loop].wakeup_word[inner_loop])) {
- char comparand[MAX_WAKEUP_WORD_LEN];
- int comparand_index = 0;
- for (int index = 0; index < MAX_WAKEUP_WORD_LEN; index++) {
- if (' ' != g_maclient_info[loop].wakeup_word[inner_loop][index]) {
- comparand[comparand_index++] = g_maclient_info[loop].wakeup_word[inner_loop][index];
- }
- }
- if (0 == strncmp(wakeup_word, comparand, MAX_WAKEUP_WORD_LEN)) {
- g_current_maclient_info = loop;
- ret = 0;
- }
- }
- }
- }
- }
- }
-
- if (g_current_maclient_info != prev_selection) {
- if (prev_selection >= 0 && prev_selection < MAX_MACLIENT_INFO_NUM) {
- mas_client_deactivate(mas_get_client_pid_by_appid(g_maclient_info[prev_selection].appid));
- }
- }
-
- return ret;
-}
-
-int mas_set_current_client_by_appid(const char *appid)
-{
- int ret = -1;
- int prev_selection = g_current_maclient_info;
-
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- if (g_maclient_info[loop].used &&
- 0 < strlen(g_maclient_info[loop].appid) &&
- 0 < strlen(g_maclient_info[loop].wakeup_word[0])) {
- if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
- g_current_maclient_info = loop;
- ret = 0;
- }
- }
- }
-
- if (g_current_maclient_info != prev_selection) {
- if (prev_selection >= 0 && prev_selection < MAX_MACLIENT_INFO_NUM) {
- mas_client_deactivate(mas_get_client_pid_by_appid(g_maclient_info[prev_selection].appid));
- }
- }
-
- return ret;
-}
-
-int mas_launch_client_by_appid(const char *appid, CLIENT_LAUNCH_MODE launch_mode)
-{
- if (NULL == appid || 0 == strlen(appid)) {
- MAS_LOGE("appid invalid, failed launching MA Client");
- return -1;
- }
-
- if (CLIENT_LAUNCH_MODE_PRELAUNCH == launch_mode) {
- if (1 == aul_app_is_running(appid)) {
- MAS_LOGE("appid %s is already running, no need for a prelaunch", appid);
- return -1;
- }
- }
-
- bundle *b = NULL;
- b = bundle_create();
- if (NULL == b) {
- MAS_LOGE("Failed creating bundle for aul operation");
- return -1;
- }
-
- int result = aul_svc_set_background_launch(b,
- (CLIENT_LAUNCH_MODE_PRELAUNCH == launch_mode ? TRUE : FALSE));
- if (result < AUL_R_OK) {
- MAS_LOGE("ERROR : aul_svc_set_background_launch failed. app_id [%s] bundle[%p] result[%d : %s]",
- appid, b, result, get_error_message(result));
- }
-
- result = aul_launch_app_async(appid, b);
- if (result < AUL_R_OK) {
- MAS_LOGE("ERROR : aul_launch_app_async failed. app_id [%s] bundle[%p] result[%d : %s]",
- appid, b, result, get_error_message(result));
- }
-
- if (CLIENT_LAUNCH_MODE_ACTIVATION == launch_mode) {
- bool found = false;
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- if (g_maclient_info[loop].used &&
- 0 < strlen(g_maclient_info[loop].appid)) {
- if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
- g_wakeup_maclient_appid = g_maclient_info[loop].appid;
- found = true;
- }
- }
- }
- MAS_LOGD("g_wakeup_maclient_appid : %s, %d", g_wakeup_maclient_appid, found);
- }
-
- if (b) bundle_free(b);
- b = NULL;
-
- return result;
-}
-
-int mas_bring_client_to_foreground(const char* appid)
-{
- /* Bring MA client to foreground - is there a better way other than launching? */
- if (NULL == appid || 0 == strlen(appid)) {
- MAS_LOGE("appid invalid, failed launching MA Client");
- return -1;
- }
-
- bundle *b = NULL;
- b = bundle_create();
- if (NULL == b) {
- MAS_LOGE("Failed creating bundle for aul operation");
- return -1;
- }
-
- int result = aul_launch_app(appid, b);
- if (result < AUL_R_OK) {
- MAS_LOGE("ERROR : aul_launch_app failed. app_id [%s] bundle[%p] result[%d : %s]",
- appid, b, result, get_error_message(result));
- }
-
- if (b) bundle_free(b);
- b = NULL;
-
- return result;
-}
-
-int mas_launch_client_by_wakeup_word(const char *wakeup_word)
-{
- const char *appid = mas_get_client_appid_by_wakeup_word(wakeup_word);
- return mas_launch_client_by_appid(appid, CLIENT_LAUNCH_MODE_ACTIVATION);
-}
-
-int mas_prelaunch_default_assistant()
-{
- /* CHECK NEEDED : should the code segment below and activation logic above be moved to wakeup manger? */
- int prelaunch_mode;
- int res = vconf_get_bool(WAKEUP_SETTINGS_KEY_PRELAUNCH_MODE, &prelaunch_mode);
- if (0 == res && 0 != prelaunch_mode) {
- const char *default_assistant = NULL;
- if (0 == multi_assistant_service_plugin_get_default_assistant(&default_assistant)) {
- if (0 == aul_app_is_running(default_assistant)) {
- MAS_LOGD("prelaunching default_assistant_appid : %s", default_assistant);
- mas_launch_client_by_appid(default_assistant, CLIENT_LAUNCH_MODE_PRELAUNCH);
- }
- }
- }
- return 0;
-}
-
-int mas_update_voice_key_support_mode()
-{
- /* CHECK NEEDED : should the code segment below and activation logic above be moved to wakeup manger? */
- bool successful = false;
- const char *default_assistant = NULL;
- if (0 == multi_assistant_service_plugin_get_default_assistant(&default_assistant)) {
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- if (g_maclient_info[loop].used) {
- if (default_assistant &&
- strncmp(default_assistant, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
- float duration = g_maclient_info[loop].voice_key_tap_duration;
- if (0.0f < duration) {
- multi_assistant_service_plugin_set_voice_key_tap_duration(duration);
- } else {
- multi_assistant_service_plugin_unset_voice_key_tap_duration();
- }
- multi_assistant_service_plugin_set_voice_key_support_mode(
- g_maclient_info[loop].voice_key_support_mode);
- successful = true;
- }
- }
- }
- }
-
- if (!successful) {
- multi_assistant_service_plugin_unset_voice_key_tap_duration();
- multi_assistant_service_plugin_set_voice_key_support_mode(VOICE_KEY_SUPPORT_MODE_NONE);
- }
- return 0;
-}
-
-ma_preprocessing_allow_mode_e get_preprocessing_allow_mode(const char* appid)
-{
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- if (appid && g_maclient_info[loop].used) {
- if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
- return g_maclient_info[loop].preprocessing_allow_mode;
- }
- }
- }
- return MA_PREPROCESSING_ALLOW_NONE;
-}
-
-/* This might need to be read from settings in the future, but using macro for now */
-//#define BRING_PREPROCESSING_ASSISTANT_TO_FRONT
-
-int mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event)
-{
- const char* current_maclient_appid = NULL;
- const char* preprocessing_allow_appid = NULL;
- if (g_current_maclient_info >= 0 && g_current_maclient_info < MAX_MACLIENT_INFO_NUM) {
- current_maclient_appid = g_maclient_info[g_current_maclient_info].appid;
- preprocessing_allow_appid = g_maclient_info[g_current_maclient_info].preprocessing_allow_appid;
- }
- ma_preprocessing_allow_mode_e mode = get_preprocessing_allow_mode(current_maclient_appid);
-
- switch (event) {
- case PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED:
- {
-#ifndef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
- /* If there is no need to bring preprocessing assistant to front,
- current_maclient should always be brought to front */
- mas_bring_client_to_foreground(current_maclient_appid);
-#endif
- g_current_preprocessing_state = PREPROCESSING_STATE_WAKEUP_PREPROCESS_DISABLED;
- if (check_preprocessing_assistant_exists()) {
- if (MA_PREPROCESSING_ALLOW_UTTERANCE == mode ||
- MA_PREPROCESSING_ALLOW_ALL == mode) {
- if (is_current_preprocessing_assistant(preprocessing_allow_appid)) {
- g_current_preprocessing_state = PREPROCESSING_STATE_WAKEUP_PREPROCESS_ENABLED;
- }
- }
- } else {
-#ifdef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
- /* If preprocessing assistant does not exist, there is no way to enable
- preprocessing assistant, so bring current maclient to front right away */
- mas_bring_client_to_foreground(current_maclient_appid);
-#endif
- }
- }
- break;
- case PREPROCESSING_STATE_EVENT_PREPROCESSING_ALLOW_MODE_CHANGED:
- {
- g_current_preprocessing_state = PREPROCESSING_STATE_WAKEUP_PREPROCESS_DISABLED;
- /* Enable preprocessing mode only if the preprocessing assistant exists */
- if (check_preprocessing_assistant_exists()) {
- if (MA_PREPROCESSING_ALLOW_UTTERANCE == mode ||
- MA_PREPROCESSING_ALLOW_ALL == mode) {
- if (is_current_preprocessing_assistant(preprocessing_allow_appid)) {
- g_current_preprocessing_state = PREPROCESSING_STATE_WAKEUP_PREPROCESS_ENABLED;
- }
- }
- }
- }
- break;
- case PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED:
- {
- if (PREPROCESSING_STATE_WAKEUP_PREPROCESS_ENABLED == g_current_preprocessing_state) {
- g_current_preprocessing_state = PREPROCESSING_STATE_PREPROCESSING_UTTERANCE;
- } else if (PREPROCESSING_STATE_WAKEUP_PREPROCESS_DISABLED == g_current_preprocessing_state) {
- /* If preprocessing assistant does not exist, the current_maclient
- would have been brought to front already on wakeup event */
-#ifdef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
- if (check_preprocessing_assistant_exists()) {
- mas_bring_client_to_foreground(current_maclient_appid);
- }
-#endif
- g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
- }
- }
- break;
- case PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED:
- {
- g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
- if (check_preprocessing_assistant_exists()) {
- if (MA_PREPROCESSING_ALLOW_FOLLOW_UP == mode ||
- MA_PREPROCESSING_ALLOW_ALL == mode) {
- g_current_preprocessing_state = PREPROCESSING_STATE_PREPROCESSING_FOLLOW_UP;
- }
- }
- }
- break;
- case PREPROCESSING_STATE_EVENT_PREPROCESSING_SUCCEEDED:
- {
-#ifdef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
- if (PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED == g_current_preprocessing_state ||
- PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED == g_current_preprocessing_state) {
- char* vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
- MAS_LOGD("preprocessing_assistant_appid : %s", vconf_str);
- if (vconf_str) {
- mas_bring_client_to_foreground(vconf_str);
- free(vconf_str);
- vconf_str = NULL;
- }
- }
-#endif
- g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
- }
- break;
- case PREPROCESSING_STATE_EVENT_PREPROCESSING_FAILED:
- {
-#ifdef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
- if (PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED == g_current_preprocessing_state ||
- PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED == g_current_preprocessing_state) {
- mas_bring_client_to_foreground(current_maclient_appid);
- }
-#endif
- g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
- }
- break;
- }
- return 0;
-}
-
-int mas_set_current_service_state(ma_service_state_e state)
-{
- g_current_service_state = state;
-
- ma_client_s *data = NULL;
-
- int count = g_slist_length(g_client_list);
- int i;
-
- for (i = 0; i < count; i++) {
- data = static_cast<ma_client_s*>(g_slist_nth_data(g_client_list, i));
-
- if (NULL != data && -1 != data->pid) {
- int ret = masc_dbus_service_state_change(data->pid, state);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to send wakeup service state change to %d, ret(%d)",
- data->pid, ret);
- }
- }
- }
- return 0;
-}
-
-ma_service_state_e mas_get_current_service_state()
-{
- return g_current_service_state;
-}
-
-static int pkg_app_list_cb(const pkgmgrinfo_appinfo_h handle, void *user_data)
-{
- char *appid = NULL;
-
- int ret = pkgmgrinfo_appinfo_get_appid (handle, &appid);
- if (PMINFO_R_OK == ret && NULL != appid) {
- int *result = (int*)user_data;
- if (result) {
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM;loop++) {
- if (g_maclient_info[loop].used) {
- LOGD("comparing appid : %s %s", g_maclient_info[loop].wakeup_engine, appid);
- if (0 == strncmp(g_maclient_info[loop].wakeup_engine, appid, MAX_APPID_LEN)) {
- *result = 1;
- }
- }
- }
- }
- } else {
- LOGE("pkgmgrinfo_appinfo_get_appid failed! error code=%d", ret);
- return 0;
- }
-
- return 0;
-}
-
-/*
-INFO: Package install/update/uninstall scenario
-Install and Uninstall are obviously simple.
- Install: just INSTALL
- Uninstall: just UNINSTALL
-Update package (change the source codes and Run As again), there are four scenarios:
-1. UPDATE
- Source code change
-2. UNINSTALL -> INSTALL
- This happens when Tizen IDE Property > Tizen SDK > Rapid Development Support > Check "Enable Project specific settings"
- and change Application ID in tizen-manifest.xml file and Run As.
-3. UPDATE -> INSTALL
- This happens when Tizen IDE Property > Tizen SDK > Rapid Development Support > Uncheck "Enable Project specific settings"
- and change Application ID in tizen-manifest.xml file and Run As.
- At UPDATE event, pkgid (package parameter) is invalid...
-4. UPDATE
- Exceptionally, only UPDATE can be called when Application ID in tizen-manifest.xml file is changed.
- At UPDATE event, pkgid (package parameter) is valid, and only appid is changed; the previous appid is invalid.
-*/
-static void _package_manager_event_cb(const char *type, const char *package, package_manager_event_type_e event_type, package_manager_event_state_e event_state, int progress, package_manager_error_e error, void *user_data)
-{
- int ret = 0;
- uid_t uid = getuid ();
- pkgmgrinfo_pkginfo_h handle = NULL;
- static bool in_progress = false;
- bool should_exit = false;
-
- if (!package || !type)
- return;
-
- if (PACKAGE_MANAGER_EVENT_TYPE_UPDATE != event_type &&
- PACKAGE_MANAGER_EVENT_TYPE_INSTALL != event_type &&
- PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL != event_type)
- return;
-
- if (PACKAGE_MANAGER_EVENT_STATE_STARTED != event_state &&
- PACKAGE_MANAGER_EVENT_STATE_COMPLETED != event_state)
- return;
-
- bool user = false;
- LOGD("type=%s package=%s event_type=%d event_state=%d progress=%d error=%d",
- type, package, event_type, event_state, progress, error);
- ret = pkgmgrinfo_pkginfo_get_pkginfo(package, &handle);
- if (ret != PMINFO_R_OK || NULL == handle) {
- LOGW("Failed to call pkgmgrinfo_pkginfo_get_pkginfo & get_usr_pkginfo(\"%s\",~) returned %d, uid : %d", package, ret, getuid ());
- /* Try to get in user packages */
- user = true;
- ret = pkgmgrinfo_pkginfo_get_usr_pkginfo (package, uid, &handle);
- if (ret != PMINFO_R_OK || NULL == handle) {
- LOGW("Failed to call pkgmgrinfo_pkginfo_get_pkginfo & get_usr_pkginfo(\"%s\",~) returned %d, uid : %d", package, ret, getuid ());
- return;
- }
- }
-
- if (user) {
- /* Try to get in user packages */
- pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, pkg_app_list_cb, (void *)&ret, uid);
- } else {
- /* Try to get in global packages */
- pkgmgrinfo_appinfo_get_list(handle, PMINFO_ALL_APP, pkg_app_list_cb, (void *)&ret);
- }
- if (1 == ret) {
- if (PACKAGE_MANAGER_EVENT_STATE_STARTED == event_state) {
- LOGI("processing PACKAGE_MANAGER_EVENT_STATE_STARTED event : %d", event_type);
- if (false == in_progress) {
- in_progress = true;
- deinit_plugin();
- }
- } else if (PACKAGE_MANAGER_EVENT_STATE_COMPLETED == event_state) {
- LOGI("processing PACKAGE_MANAGER_EVENT_STATE_COMPLETED event : %d", event_type);
- if (false == in_progress) {
- deinit_plugin();
- }
- should_exit = true;
- in_progress = false;
- }
- }
-
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
-
- if (should_exit) {
- LOGI("Now restarting multi-assistant-service for reloading updated modules");
- service_app_exit();
- }
-
- return;
-}
-
-bool app_create(void *data)
-{
- // Todo: add your code here.
-
- MAS_LOGD("[Enter] Service app create");
-
- if (0 != init_wakeup()) {
- MAS_LOGE("Fail to init wakeup service");
- return false;
- }
-
- if (!g_pkgmgr) {
- int ret = package_manager_create(&g_pkgmgr);
- if (ret == PACKAGE_MANAGER_ERROR_NONE) {
- ret = package_manager_set_event_cb(g_pkgmgr, _package_manager_event_cb, NULL);
- if (ret == PACKAGE_MANAGER_ERROR_NONE) {
- LOGD("package_manager_set_event_cb succeeded.");
- }
- else {
- LOGE("package_manager_set_event_cb failed(%d)", ret);
- }
- }
- else {
- LOGE("package_manager_create failed(%d)", ret);
- }
- }
-
- return true;
-}
-
-void app_terminate(void *data)
-{
- MAS_LOGI("[ENTER]");
- if (g_pkgmgr) {
- package_manager_unset_event_cb(g_pkgmgr);
- package_manager_destroy(g_pkgmgr);
- g_pkgmgr = NULL;
- }
-
- // Todo: add your code here.
- deinit_wakeup();
- MAS_LOGI("[END]");
- return;
-}
-
+++ /dev/null
-/*
- * Copyright 2018-2019 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * 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.
- */
-
-#include <tizen.h>
-#include <service_app.h>
-#include <app_manager.h>
-#include <app.h>
-#include <malloc.h>
-#include <Ecore.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <glib.h>
-#include <dlfcn.h>
-
-#include "multi_wakeup_recognizer.h"
-#include "multi_assistant_main.h"
-#include "multi_assistant_service_client.h"
-#include "multi_assistant_service_plugin.h"
-#include "multi_assistant_dbus.h"
-
-/* Sound buf save for test */
-#if 0
-#define BUF_SAVE_MODE
-#endif
-
-#ifdef BUF_SAVE_MODE
-static char g_temp_file_name[128] = {'\0',};
-
-static FILE* g_pFile = NULL;
-
-static int g_count = 1;
-#endif
-
-static void *g_handle = NULL;
-
-static wakeup_manager_interface _wakeup_manager_interface = { NULL, };
-static ma_plugin_settings* g_plugin_settings = NULL;
-
-static bool is_ui_panel_enabled()
-{
- /* By default we assume the ui panel is always enabled unless explicitly turned off */
- bool ret = true;
- if (g_plugin_settings) {
- ret = g_plugin_settings->ui_panel_enabled;
- }
- MAS_LOGD("UI Panel Enabled : %d", ret);
- return ret;
-}
-
-#if 0 /* + TEST_CODE */
-Eina_Bool __send_asr_result(void *data)
-{
- MAS_LOGD("[ENTER]");
-
- if (!strcmp((char*)data, "Today's")) {
- masc_ui_dbus_send_asr_result(-1, 1, "Today's");
- }
- if (!strcmp((char*)data, "weather.")) {
- masc_ui_dbus_send_asr_result(-1, 0, "Today's weather.");
- }
-
- MAS_LOGD("END");
- return EINA_FALSE;
-}
-
-Eina_Bool __send_result(void *data)
-{
- MAS_LOGD("[ENTER]");
-
- int ret = masc_ui_dbus_send_result(-1, (const char*)data, (const char*)data, "test");
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to stop recording(%d)", ret);
- return EINA_TRUE;
- }
-
- MAS_LOGD("END");
- return EINA_FALSE;
-}
-#endif /* -TEST_CODE */
-
-Eina_Bool process_wakeup_event_by_appid_timer(void* data)
-{
- char* appid = static_cast<char*>(data);
- MAS_LOGD("[ENTER] appid(%s)", appid);
-
- int pid = -1;
- if (!appid) return ECORE_CALLBACK_CANCEL;
-
- bool use_custom_ui = mas_get_client_custom_ui_option_by_appid(appid);
- bool ui_panel_enabled = is_ui_panel_enabled();
- if (ui_panel_enabled) masc_ui_dbus_enable_common_ui(!use_custom_ui);
-
- mas_set_current_client_by_appid(appid);
- if (ui_panel_enabled) masc_ui_dbus_change_assistant(appid);
- if ((pid = mas_get_client_pid_by_appid(appid)) != -1) {
- mas_client_send_preprocessing_information(pid);
- mas_client_activate(pid);
- mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED);
- } else {
- // Appropriate MA Client not available, trying to launch new one
- MAS_LOGD("MA Client with appid %s does not exist, launching client", appid);
- mas_launch_client_by_appid(appid, CLIENT_LAUNCH_MODE_ACTIVATION);
- }
-
- if (appid) free(appid);
-
- MAS_LOGD("END");
- return ECORE_CALLBACK_CANCEL;
-}
-
-Eina_Bool process_wakeup_event_by_word_timer(void* data)
-{
- char* wakeup_word = static_cast<char*>(data);
- MAS_LOGD("[ENTER]");
-
- if (!wakeup_word) return EINA_FALSE;
-
- const char* appid = mas_get_client_appid_by_wakeup_word(wakeup_word);
- process_wakeup_event_by_appid_timer(static_cast<void*>(strdup(appid)));
-
- if (wakeup_word) free(wakeup_word);
-
- MAS_LOGD("END");
- return ECORE_CALLBACK_CANCEL;
-}
-
-static void __wakeup_event_cb(mas_wakeup_event_info wakeup_info, const char* wakeup_word, void* user_data)
-{
- MAS_LOGD("[SUCCESS] __wakeup_event_cb is called, wakeup_word(%s)", wakeup_info.wakeup_word);
- int ret = -1;
-
- if (is_ui_panel_enabled()) {
- int retry_cnt = 0;
- while (0 != ret) {
- ret = masc_ui_dbus_send_hello();
- retry_cnt++;
- if (5 < retry_cnt) {
- MAS_LOGE("[ERROR] Fail to receive reply for hello, ret(%d)", ret);
- break;
- }
- }
- }
-
-#ifdef BUF_SAVE_MODE
- if (g_pFile) {
- fclose(g_pFile);
- g_pFile = NULL;
- } else {
- MAS_LOGD("[Recorder Info] File not found!");
- }
-
- while (1) {
- snprintf(g_temp_file_name, sizeof(g_temp_file_name), "/tmp/ma_service_%d_%d", getpid(), g_count);
- int ret = access(g_temp_file_name, 0);
-
- if (0 == ret) {
- MAS_LOGD("[Recorder ERROR] File is already exist");
- if (0 == remove(g_temp_file_name)) {
- MAS_LOGD("[Recorder] Remove file");
- break;
- } else {
- g_count++;
- }
- } else {
- break;
- }
- }
-
- MAS_LOGD("[Recorder] Temp file name=[%s]", g_temp_file_name);
-
- /* open test file */
- g_pFile = fopen(g_temp_file_name, "wb+x");
- if (!g_pFile) {
- MAS_LOGD("[Recorder ERROR] File not found!");
- return;
- }
- g_count++;
-#endif
-
-#if 0 /* + TEST_CODE */
- if (WAKEUP_EVENT_SUCCESS == event) {
- ecore_thread_main_loop_begin();
- ecore_timer_add(1.0, __send_asr_result, "Today's");
- ecore_thread_main_loop_end();
-
- ecore_thread_main_loop_begin();
- ecore_timer_add(2.0, __send_asr_result, "weather.");
- ecore_thread_main_loop_end();
-
- ecore_thread_main_loop_begin();
- ecore_timer_add(3.0, __send_result, "Partly cloudy with temperatures from 75 to 88");
- ecore_thread_main_loop_end();
- }
-#endif /* - TEST_CODE */
- if (wakeup_info.wakeup_appid) {
- ecore_thread_main_loop_begin();
- ecore_timer_add(0.0f, process_wakeup_event_by_appid_timer,
- static_cast<void*>(strdup(wakeup_info.wakeup_appid)));
- ecore_thread_main_loop_end();
- } else if (wakeup_info.wakeup_word) {
- ecore_thread_main_loop_begin();
- ecore_timer_add(0.0f, process_wakeup_event_by_word_timer,
- static_cast<void*>(strdup(wakeup_info.wakeup_word)));
- ecore_thread_main_loop_end();
- }
-
-}
-
-static bool __validate_streaming_event_order(int pid, mas_speech_streaming_event_e *event)
-{
- bool ret = false;
-
- static int previous_pid = -1;
- static mas_speech_streaming_event_e previous_event = MAS_SPEECH_STREAMING_EVENT_FINISH;
-
- if (NULL == event) return false;
-
- mas_speech_streaming_event_e expected_sequence [][2] = {
- {MAS_SPEECH_STREAMING_EVENT_START, MAS_SPEECH_STREAMING_EVENT_CONTINUE},
- {MAS_SPEECH_STREAMING_EVENT_START, MAS_SPEECH_STREAMING_EVENT_FINISH},
- {MAS_SPEECH_STREAMING_EVENT_CONTINUE, MAS_SPEECH_STREAMING_EVENT_CONTINUE},
- {MAS_SPEECH_STREAMING_EVENT_CONTINUE, MAS_SPEECH_STREAMING_EVENT_FINISH},
- {MAS_SPEECH_STREAMING_EVENT_FINISH, MAS_SPEECH_STREAMING_EVENT_START},
- /* If there is no audio data even after the start streaming request */
- {MAS_SPEECH_STREAMING_EVENT_FINISH, MAS_SPEECH_STREAMING_EVENT_FINISH},
- };
-
- if (pid != previous_pid) {
- /* When sending streaming event to a new client, it always sends START message first */
- previous_event = MAS_SPEECH_STREAMING_EVENT_FINISH;
- }
-
- for (int loop = 0;loop < sizeof(expected_sequence) / sizeof(expected_sequence[0]);loop++) {
- if (previous_event == expected_sequence[loop][0] &&
- *event == expected_sequence[loop][1]) {
- ret = true;
- }
- }
- if (!ret) {
- /* In case of FINISH -> CONTINUE without START, simply modify current event value */
- if (MAS_SPEECH_STREAMING_EVENT_FINISH == previous_event &&
- MAS_SPEECH_STREAMING_EVENT_CONTINUE == *event) {
- *event = MAS_SPEECH_STREAMING_EVENT_START;
- ret = true;
-
- MAS_LOGD("[WARNING] forcibly changed CONTINUE to START : %d -> %d (PID %d -> %d)",
- previous_event, *event, previous_pid, pid);
- }
- }
-
- if (ret) {
- previous_pid = pid;
- previous_event = *event;
- } else {
- MAS_LOGE("[ERROR] State sequence validation failed : %d -> %d (PID %d -> %d)",
- previous_event, *event, previous_pid, pid);
- }
- return ret;
-}
-
-static void handle_speech_streaming_event_failure(void *data)
-{
- mas_client_send_recognition_result(0, MA_RECOGNITION_RESULT_EVENT_ERROR);
-}
-
-static void __audio_streaming_cb(mas_speech_streaming_event_e event, unsigned char* buffer, int len, void *user_data)
-{
- if (event == MAS_SPEECH_STREAMING_EVENT_FAIL) {
- ecore_main_loop_thread_safe_call_async(handle_speech_streaming_event_failure, NULL);
- return;
- }
- static int count = 0;
- if (event != MAS_SPEECH_STREAMING_EVENT_CONTINUE || count % 100 == 0) {
- MAS_LOGD( "[SUCCESS] __audio_streaming_cb is called, event(%d), buffer(%p), len(%d)", event, buffer, len);
- }
- ++count;
-
- int pid = mas_get_current_client_pid();
- int preprocessing_pid = mas_get_current_preprocessing_client_pid();
- if (pid == -1) {
- MAS_LOGE("[ERROR] Fail to retrieve pid of current MA client");
- } else {
- if (__validate_streaming_event_order(pid, &event)) {
- int ret = masc_dbus_send_streaming_audio_data(pid, event, buffer, len);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to send speech data, ret(%d)", ret);
- }
- if (pid != preprocessing_pid && -1 != preprocessing_pid) {
- int ret = masc_dbus_send_streaming_audio_data(preprocessing_pid, event, buffer, len);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to send speech data to preprocessing client, ret(%d)", ret);
- }
- }
- }
- }
-
-#ifdef BUF_SAVE_MODE
- /* write pcm buffer */
- if (g_pFile)
- fwrite(buffer, 1, len, g_pFile);
-
- if (MAS_SPEECH_STREAMING_EVENT_FINISH == event) {
- if (g_pFile) {
- MAS_LOGE("[Recorder SUCCESS] File Close");
- fclose(g_pFile);
- g_pFile = NULL;
- } else {
- MAS_LOGE("[Recorder ERROR] File not found!");
- }
- }
-#endif
-}
-
-static void __speech_status_cb(mas_speech_status_e status, void *user_data)
-{
- MAS_LOGD( "[SUCCESS] __speech_status_cb is called, status(%d)", status);
-}
-
-static void __error_cb(int error, const char* err_msg, void* user_data)
-{
- MAS_LOGD( "[SUCCESS] __error_cb is called, error(%d), err_msg(%s)", error, err_msg);
-
- if (is_ui_panel_enabled()) {
- int ret = masc_ui_dbus_send_error_message(error, err_msg);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to send error message, ret(%d)", ret);
- }
- }
-}
-
-static void __setting_changed_cb(void *user_data)
-{
- mas_prelaunch_default_assistant();
- mas_update_voice_key_support_mode();
- MAS_LOGD( "[SUCCESS] __setting_changed_cb is called");
-}
-
-static void __streaming_section_changed_cb(ma_audio_streaming_data_section_e section, void* user_data)
-{
- MAS_LOGD( "[SUCCESS] __streaming_section_changed_cb is called, section(%d)", section);
-
- int pid = mas_get_current_client_pid();
- int ret = masc_dbus_send_streaming_section_changed(pid, (int)section);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to send streaming section changed information, ret(%d)", ret);
- }
-}
-
-static void __wakeup_engine_command_cb(mas_wakeup_engine_command_target_e target, const char* assistant_name, const char* command, void* user_data)
-{
- MAS_LOGD( "[SUCCESS] __wakeup_engine_command_cb is called, command(%s)", command);
-
- int pid = mas_get_client_pid_by_appid(assistant_name);
- if (-1 != pid) {
- int ret = masc_dbus_send_wakeup_engine_command(pid, command);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to send wakeup engine command, ret(%d)", ret);
- }
- }
-}
-
-static void __wakeup_service_state_changed_cb(ma_service_state_e state, void* user_data)
-{
- MAS_LOGD( "[SUCCESS] __wakeup_service_state_changed_cb is called, state(%d)", state);
-
- mas_set_current_service_state(state);
-}
-
-static void __wakeup_service_voice_key_status_changed_cb(ma_voice_key_status_e status, void* user_data)
-{
- MAS_LOGD( "[SUCCESS] __wakeup_service_voice_key_status_changed_cb is called, state(%d)", status);
-
- int pid = mas_get_current_client_pid();
- int ret = mas_client_send_voice_key_status_change(pid, status);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to send voice key status changed information, ret(%d)", ret);
- }
-}
-
-int multi_assistant_service_plugin_initialize(void)
-{
- MAS_LOGD( "[Enter]");
-
- char filepath[512] = {'\0',};
- const char *default_engine_path = MA_WAKEUP_MANAGER_PATH;
- snprintf(filepath, 512, "%s/%s", default_engine_path, MA_DEFAULT_WAKEUP_MANAGER_FILENAME);
-
- char *error;
- g_handle = NULL;
- g_handle = dlopen(filepath, RTLD_LAZY);
- if (NULL != (error = dlerror())) {
- MAS_LOGE("[ERROR] Fail to dlopen(%s), error(%s)", filepath, error);
- return -1; //MAS_ERROR_OPERATION_FAILED;
- }
-
- _wakeup_manager_interface.initialize =
- (wakeup_manager_initialize)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_INITIALIZE);
- _wakeup_manager_interface.deinitialize =
- (wakeup_manager_deinitialize)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE);
- _wakeup_manager_interface.get_settings =
- (wakeup_manager_get_settings)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
- _wakeup_manager_interface.add_assistant_wakeup_word =
- (wakeup_manager_add_assistant_wakeup_word)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_WORD);
- _wakeup_manager_interface.remove_assistant_wakeup_word =
- (wakeup_manager_remove_assistant_wakeup_word)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_REMOVE_ASSISTANT_WAKEUP_WORD);
- _wakeup_manager_interface.add_assistant_language =
- (wakeup_manager_add_assistant_language)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE);
- _wakeup_manager_interface.set_assistant_wakeup_engine =
- (wakeup_manager_set_assistant_wakeup_engine)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE);
- _wakeup_manager_interface.set_default_assistant =
- (wakeup_manager_set_default_assistant)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_DEFAULT_ASSISTANT);
- _wakeup_manager_interface.get_default_assistant =
- (wakeup_manager_get_default_assistant)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_GET_DEFAULT_ASSISTANT);
- _wakeup_manager_interface.set_language =
- (wakeup_manager_set_language)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE);
- _wakeup_manager_interface.activate =
- (wakeup_manager_activate)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_ACTIVATE);
- _wakeup_manager_interface.deactivate =
- (wakeup_manager_deactivate)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_DEACTIVATE);
- _wakeup_manager_interface.update_voice_feedback_state =
- (wakeup_manager_update_voice_feedback_state)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_UPDATE_VOICE_FEEDBACK_STATE);
- _wakeup_manager_interface.set_assistant_specific_command =
- (wakeup_manager_set_assistant_specific_command)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND);
- _wakeup_manager_interface.set_background_volume =
- (wakeup_manager_set_background_volume)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_BACKGROUND_VOLUME);
- _wakeup_manager_interface.update_recognition_result =
- (wakeup_manager_update_recognition_result)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_UPDATE_RECOGNITION_RESULT);
- _wakeup_manager_interface.process_plugin_event =
- (wakeup_manager_process_plugin_event)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_PROCESS_PLUGIN_EVENT);
- _wakeup_manager_interface.start_streaming_utterance_data =
- (wakeup_manager_start_streaming_utterance_data)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_START_STREAMING_UTTERANCE_DATA);
- _wakeup_manager_interface.stop_streaming_utterance_data =
- (wakeup_manager_stop_streaming_utterance_data)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_UTTERANCE_DATA);
- _wakeup_manager_interface.start_streaming_previous_utterance_data =
- (wakeup_manager_start_streaming_previous_utterance_data)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_START_STREAMING_PREVIOUS_UTTERANCE_DATA);
- _wakeup_manager_interface.stop_streaming_previous_utterance_data =
- (wakeup_manager_stop_streaming_previous_utterance_data)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_PREVIOUS_UTTERANCE_DATA);
- _wakeup_manager_interface.start_streaming_follow_up_data =
- (wakeup_manager_start_streaming_follow_up_data)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_START_STREAMING_FOLLOW_UP_DATA);
- _wakeup_manager_interface.stop_streaming_follow_up_data =
- (wakeup_manager_stop_streaming_follow_up_data)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_FOLLOW_UP_DATA);
- _wakeup_manager_interface.get_audio_format =
- (wakeup_manager_get_audio_format)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_FORMAT);
- _wakeup_manager_interface.get_audio_source_type =
- (wakeup_manager_get_audio_source_type)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_SOURCE_TYPE);
- _wakeup_manager_interface.set_wake_word_audio_require_flag =
- (wakeup_manager_set_wake_word_audio_require_flag)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG);
- _wakeup_manager_interface.set_assistant_language =
- (wakeup_manager_set_assistant_language)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_LANGUAGE);
- _wakeup_manager_interface.set_voice_key_tap_duration =
- (wakeup_manager_set_voice_key_tap_duration)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_TAP_DURATION);
- _wakeup_manager_interface.unset_voice_key_tap_duration =
- (wakeup_manager_unset_voice_key_tap_duration)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_UNSET_VOICE_KEY_TAP_DURATION);
- _wakeup_manager_interface.set_voice_key_support_mode =
- (wakeup_manager_set_voice_key_support_mode)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_SUPPORT_MODE);
- _wakeup_manager_interface.set_wakeup_event_callback =
- (wakeup_manager_set_wakeup_event_callback)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_EVENT_CALLBACK);
- _wakeup_manager_interface.set_utterance_streaming_callback =
- (wakeup_manager_set_utterance_streaming_callback)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_UTTERANCE_STREAMING_CALLBACK);
- _wakeup_manager_interface.set_previous_utterance_streaming_callback =
- (wakeup_manager_set_previous_utterance_streaming_callback)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_PREVIOUS_UTTERANCE_STREAMING_CALLBACK);
- _wakeup_manager_interface.set_follow_up_streaming_callback =
- (wakeup_manager_set_follow_up_streaming_callback)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_FOLLOW_UP_STREAMING_CALLBACK);
- _wakeup_manager_interface.set_speech_status_callback =
- (wakeup_manager_set_speech_status_callback)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_SPEECH_STATUS_CALLBACK);
- _wakeup_manager_interface.set_setting_changed_callback =
- (wakeup_manager_set_setting_changed_callback)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_SETTING_CHANGED_CALLBACK);
- _wakeup_manager_interface.set_error_callback =
- (wakeup_manager_set_error_callback)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_ERROR_CALLBACK);
- _wakeup_manager_interface.set_streaming_section_changed_callback =
- (wakeup_manager_set_streaming_section_changed_callback)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_STREAMING_SECTION_CHANGED_CALLBACK);
- _wakeup_manager_interface.set_wakeup_engine_command_callback =
- (wakeup_manager_set_wakeup_engine_command_callback)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_ENGINE_COMMAND_CALLBACK);
- _wakeup_manager_interface.set_wakeup_service_state_changed_callback =
- (wakeup_manager_set_wakeup_service_state_changed_callback)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_SERVICE_STATE_CHANGED_CALLBACK);
- _wakeup_manager_interface.set_voice_key_status_changed_callback =
- (wakeup_manager_set_voice_key_status_changed_callback)dlsym(g_handle,
- MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_STATUS_CHANGED_CALLBACK);
-
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_initialize func = _wakeup_manager_interface.initialize;
-
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_INITIALIZE);
- } else {
- ret = func();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to initialize, ret(%d)", ret);
- }
- }
-
- wakeup_manager_get_settings get_settings_func = _wakeup_manager_interface.get_settings;
-
- if (NULL == get_settings_func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
- } else {
- size_t struct_size;
- ret = get_settings_func(&g_plugin_settings, &struct_size);
- if (0 != ret || struct_size != sizeof(ma_plugin_settings)) {
- MAS_LOGE("[ERROR] Fail to get settings, ret(%d), size %zu", ret, struct_size);
- g_plugin_settings = NULL;
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_deinitialize(void)
-{
-#ifdef BUF_SAVE_MODE
- if (g_pFile) {
- fclose(g_pFile);
- g_pFile = NULL;
- } else {
- MAS_LOGD("[Recorder ERROR] File not found!");
- }
-#endif
-
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_deinitialize func = _wakeup_manager_interface.deinitialize;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE);
- } else {
- ret = func();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to deinitialize, ret(%d)", ret);
- }
- }
-
- dlclose(g_handle);
- g_handle = NULL;
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
-
- return ret;
-}
-
-int multi_assistant_service_plugin_get_settings(ma_plugin_settings **settings, size_t *struct_size)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_get_settings func = _wakeup_manager_interface.get_settings;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
- } else {
- ret = func(settings, struct_size);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to get settings, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_language(const char* language)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_language func = _wakeup_manager_interface.set_language;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE);
- } else {
- ret = func(language);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set langauge(%s), ret(%d)", language, ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_add_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_add_assistant_wakeup_word func = _wakeup_manager_interface.add_assistant_wakeup_word;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_WORD);
- } else {
- ret = func(appid, wakeup_word, language);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to add wakeup word(%s)(%s)(%s), ret(%d)", appid, wakeup_word, language, ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_remove_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_remove_assistant_wakeup_word func = _wakeup_manager_interface.remove_assistant_wakeup_word;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_REMOVE_ASSISTANT_WAKEUP_WORD);
- } else {
- ret = func(appid, wakeup_word, language);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to remove wakeup word(%s)(%s)(%s), ret(%d)", appid, wakeup_word, language, ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_add_assistant_language(const char* appid, const char* language)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_add_assistant_language func = _wakeup_manager_interface.add_assistant_language;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE);
- } else {
- ret = func(appid, language);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set wakeup word(%s)(%s), ret(%d)", appid, language, ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_assistant_wakeup_engine(const char* appid, const char* engine)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_assistant_wakeup_engine func = _wakeup_manager_interface.set_assistant_wakeup_engine;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE);
- } else {
- ret = func(appid, engine);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set wakeup engine(%s)(%s), ret(%d)", appid, engine, ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_default_assistant(const char* appid)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_default_assistant func = _wakeup_manager_interface.set_default_assistant;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_DEFAULT_ASSISTANT);
- } else {
- ret = func(appid);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set default assistant(%s), ret(%d)", appid, ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_get_default_assistant(const char** appid)
-{
- int ret = -1;
- if (NULL == appid) {
- MAS_LOGE("[ERROR] appid is not valid");
- return ret;
- }
- if (NULL != g_handle) {
- wakeup_manager_get_default_assistant func = _wakeup_manager_interface.get_default_assistant;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_DEFAULT_ASSISTANT);
- } else {
- ret = func(appid);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to get default assistant, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_activate(void)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_activate func = _wakeup_manager_interface.activate;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ACTIVATE);
- } else {
- ret = func();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to start recording, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_deactivate(void)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_deactivate func = _wakeup_manager_interface.deactivate;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_DEACTIVATE);
- } else {
- ret = func();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_update_voice_feedback_state(const char* appid, int state)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_update_voice_feedback_state func = _wakeup_manager_interface.update_voice_feedback_state;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UPDATE_VOICE_FEEDBACK_STATE);
- } else {
- ret = func(appid, state);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_assistant_specific_command(const char* appid, const char* command)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_assistant_specific_command func = _wakeup_manager_interface.set_assistant_specific_command;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND);
- } else {
- ret = func(appid, command);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_background_volume(const char* appid, double ratio)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_background_volume func = _wakeup_manager_interface.set_background_volume;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_BACKGROUND_VOLUME);
- } else {
- ret = func(appid, ratio);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set background volume, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_update_recognition_result(const char* appid, int state)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_update_recognition_result func = _wakeup_manager_interface.update_recognition_result;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UPDATE_RECOGNITION_RESULT);
- } else {
- ret = func(appid, state);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to update result state, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_process_event(int event, void *data, int len)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_process_plugin_event func = _wakeup_manager_interface.process_plugin_event;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_PROCESS_PLUGIN_EVENT);
- } else {
- ret = func((mas_plugin_event_e)event, data, len);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_start_streaming_utterance_data(void)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_start_streaming_utterance_data func = _wakeup_manager_interface.start_streaming_utterance_data;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_UTTERANCE_DATA);
- } else {
- ret = func();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_stop_streaming_utterance_data(void)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_stop_streaming_utterance_data func = _wakeup_manager_interface.stop_streaming_utterance_data;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_UTTERANCE_DATA);
- } else {
- ret = func();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_start_streaming_previous_utterance_data(void)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_start_streaming_previous_utterance_data func = _wakeup_manager_interface.start_streaming_previous_utterance_data;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_PREVIOUS_UTTERANCE_DATA);
- } else {
- ret = func();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to request previous speech data, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_stop_streaming_previous_utterance_data(void)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_stop_streaming_previous_utterance_data func = _wakeup_manager_interface.stop_streaming_previous_utterance_data;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_PREVIOUS_UTTERANCE_DATA);
- } else {
- ret = func();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to request previous speech data, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_start_streaming_follow_up_data(void)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_start_streaming_follow_up_data func = _wakeup_manager_interface.start_streaming_follow_up_data;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_FOLLOW_UP_DATA);
- } else {
- ret = func();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_stop_streaming_follow_up_data(void)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_stop_streaming_follow_up_data func = _wakeup_manager_interface.stop_streaming_follow_up_data;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_FOLLOW_UP_DATA);
- } else {
- ret = func();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_get_recording_audio_format(int *rate, int *channel, int *audio_type)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_get_audio_format func = _wakeup_manager_interface.get_audio_format;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_FORMAT);
- } else {
- ret = func(rate, channel, audio_type);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to get recording audio format, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_get_recording_audio_source_type(char** type)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_get_audio_source_type func = _wakeup_manager_interface.get_audio_source_type;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_SOURCE_TYPE);
- } else {
- ret = func(type);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to get recording audio source type, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_voice_key_tap_duration(float duration)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_voice_key_tap_duration func = _wakeup_manager_interface.set_voice_key_tap_duration;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_TAP_DURATION);
- } else {
- ret = func(duration);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set voice key tap duration, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_unset_voice_key_tap_duration()
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_unset_voice_key_tap_duration func = _wakeup_manager_interface.unset_voice_key_tap_duration;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UNSET_VOICE_KEY_TAP_DURATION);
- } else {
- ret = func();
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to unset voice key tap duration, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_voice_key_support_mode(int mode)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_voice_key_support_mode func = _wakeup_manager_interface.set_voice_key_support_mode;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_SUPPORT_MODE);
- } else {
- ret = func(mode);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set voice key support mode, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_wake_word_audio_require_flag(const char* appid, bool require)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_wake_word_audio_require_flag func = _wakeup_manager_interface.set_wake_word_audio_require_flag;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG);
- } else {
- ret = func(require);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set wake word audio require flag, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_assistant_language(const char* appid, const char* language)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_assistant_language func = _wakeup_manager_interface.set_assistant_language;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_LANGUAGE);
- } else {
- ret = func(appid, language);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set assistant language, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_callbacks(void)
-{
- int ret = multi_assistant_service_plugin_set_wakeup_event_callback(__wakeup_event_cb, NULL);
- if (0 != ret) {
- MAS_LOGE("Fail to set wakeup event cb");
- return ret;
- }
-
- ret = multi_assistant_service_plugin_set_utterance_streaming_callback(__audio_streaming_cb, NULL);
- if (0 != ret) {
- MAS_LOGE("Fail to set utterance streaming cb");
- return ret;
- }
-
- ret = multi_assistant_service_plugin_set_previous_utterance_streaming_callback(__audio_streaming_cb, NULL);
- if (0 != ret) {
- MAS_LOGE("Fail to set previous utterance streaming cb");
- return ret;
- }
-
- ret = multi_assistant_service_plugin_set_follow_up_streaming_callback(__audio_streaming_cb, NULL);
- if (0 != ret) {
- MAS_LOGE("Fail to set follow-up streaming cb");
- return ret;
- }
-
- ret = multi_assistant_service_plugin_set_speech_status_callback(__speech_status_cb, NULL);
- if (0 != ret) {
- MAS_LOGE("Fail to set speech status changed cb");
- return ret;
- }
-
- ret = multi_assistant_service_plugin_set_setting_changed_callback(__setting_changed_cb, NULL);
- if (0 != ret) {
- MAS_LOGE("Fail to set setting changed cb");
- return ret;
- }
-
- ret = multi_assistant_service_plugin_set_error_callback(__error_cb, NULL);
- if (0 != ret) {
- MAS_LOGE("Fail to set error cb");
- return ret;
- }
-
- ret = multi_assistant_service_plugin_set_streaming_section_changed_callback(__streaming_section_changed_cb, NULL);
- if (0 != ret) {
- MAS_LOGE("Fail to set streaming section changed cb");
- return ret;
- }
-
- ret = multi_assistant_service_plugin_set_wakeup_engine_command_callback(__wakeup_engine_command_cb, NULL);
- if (0 != ret) {
- MAS_LOGE("Fail to set wakeup engine command cb");
- return ret;
- }
-
- ret = multi_assistant_service_plugin_set_wakeup_service_state_changed_callback(__wakeup_service_state_changed_cb, NULL);
- if (0 != ret) {
- MAS_LOGE("Fail to set wakeup engine command cb");
- return ret;
- }
-
- ret = multi_assistant_service_plugin_set_voice_key_status_changed_callback(__wakeup_service_voice_key_status_changed_cb, NULL);
- if (0 != ret) {
- MAS_LOGE("Fail to set wakeup engine command cb");
- return ret;
- }
-
- return 0;
-}
-
-int multi_assistant_service_plugin_set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_wakeup_event_callback func = _wakeup_manager_interface.set_wakeup_event_callback;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_EVENT_CALLBACK);
- } else {
- ret = func(callback, user_data);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set wakeup event callback, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_utterance_streaming_callback func = _wakeup_manager_interface.set_utterance_streaming_callback;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_UTTERANCE_STREAMING_CALLBACK);
- } else {
- ret = func(callback, user_data);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set utterance streaming callback, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_previous_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_previous_utterance_streaming_callback func = _wakeup_manager_interface.set_previous_utterance_streaming_callback;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_PREVIOUS_UTTERANCE_STREAMING_CALLBACK);
- } else {
- ret = func(callback, user_data);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set utterance streaming callback, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_follow_up_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_follow_up_streaming_callback func = _wakeup_manager_interface.set_follow_up_streaming_callback;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_FOLLOW_UP_STREAMING_CALLBACK);
- } else {
- ret = func(callback, user_data);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set follow-up streaming callback, ret(%d)", ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_speech_status_callback func = _wakeup_manager_interface.set_speech_status_callback;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_SPEECH_STATUS_CALLBACK);
- } else {
- ret = func(callback, user_data);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set speech status callback, ret(%d)", ret);
- }
- }
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_setting_changed_callback(wakeup_service_setting_changed_cb callback, void* user_data)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_setting_changed_callback func = _wakeup_manager_interface.set_setting_changed_callback;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_SETTING_CHANGED_CALLBACK);
- } else {
- ret = func(callback, user_data);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set setting_changed callback, ret(%d)", ret);
- }
- }
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_error_callback(wakeup_service_error_cb callback, void* user_data)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_error_callback func = _wakeup_manager_interface.set_error_callback;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ERROR_CALLBACK);
- } else {
- ret = func(callback, user_data);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
- }
- }
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_streaming_section_changed_callback(wakeup_service_streaming_section_changed_cb callback, void* user_data)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_streaming_section_changed_callback func = _wakeup_manager_interface.set_streaming_section_changed_callback;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_STREAMING_SECTION_CHANGED_CALLBACK);
- } else {
- ret = func(callback, user_data);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set streaming section changed callback, ret(%d)", ret);
- }
- }
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_wakeup_engine_command_callback(wakeup_service_wakeup_engine_command_cb callback, void* user_data)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_wakeup_engine_command_callback func = _wakeup_manager_interface.set_wakeup_engine_command_callback;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_ENGINE_COMMAND_CALLBACK);
- } else {
- ret = func(callback, user_data);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
- }
- }
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_wakeup_service_state_changed_callback(wakeup_service_wakeup_service_state_changed_cb callback, void* user_data)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_wakeup_service_state_changed_callback func = _wakeup_manager_interface.set_wakeup_service_state_changed_callback;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_SERVICE_STATE_CHANGED_CALLBACK);
- } else {
- ret = func(callback, user_data);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
- }
- }
- }
- return ret;
-}
-
-int multi_assistant_service_plugin_set_voice_key_status_changed_callback(wakeup_service_voice_key_status_changed_cb callback, void* user_data)
-{
- int ret = -1;
- if (NULL != g_handle) {
- wakeup_manager_set_voice_key_status_changed_callback func = _wakeup_manager_interface.set_voice_key_status_changed_callback;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_STATUS_CHANGED_CALLBACK);
- } else {
- ret = func(callback, user_data);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
- }
- }
- }
- return ret;
-}
-
--- /dev/null
+/*
+ * Copyright 2018-2019 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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.
+ */
+
+#include <libxml/parser.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <unistd.h>
+
+#include <app_preference.h>
+
+#include "service_config.h"
+#include "service_common.h"
+
+int CServiceConfig::parse_assistant_info(service_config_assistant_info_cb callback,
+ const char *path, void* user_data)
+{
+ xmlDocPtr doc = NULL;
+ xmlNodePtr cur = NULL;
+ xmlChar *key;
+
+ int loop;
+ int retry_count = 0;
+
+ while (NULL == doc) {
+ doc = xmlParseFile(path);
+ if (NULL != doc) {
+ break;
+ }
+
+ if (MA_RETRY_COUNT == retry_count++) {
+ MAS_LOGE("[ERROR] Fail to parse file error : %s", path);
+ xmlCleanupParser();
+ return -1;
+ }
+ usleep(10000);
+ }
+
+ cur = xmlDocGetRootElement(doc);
+ if (cur == NULL) {
+ MAS_LOGE("[ERROR] Empty document");
+ xmlFreeDoc(doc);
+ return -1;
+ }
+
+ if (xmlStrcmp(cur->name, (const xmlChar *) MA_TAG_ASSISTANT_BASE)) {
+ MAS_LOGE("[ERROR] The wrong type, root node is NOT %s", MA_TAG_ASSISTANT_BASE);
+ xmlFreeDoc(doc);
+ return -1;
+ }
+
+ cur = cur->xmlChildrenNode;
+ if (cur == NULL) {
+ MAS_LOGE("[ERROR] Empty document");
+ xmlFreeDoc(doc);
+ return -1;
+ }
+
+ /* alloc assistant info */
+ ma_assistant_info_s temp;
+
+ temp.app_id = NULL;
+ temp.name = NULL;
+ temp.icon_path = NULL;
+ memset(temp.wakeup_list, 0x00, sizeof(temp.wakeup_list));
+ memset(temp.wakeup_language, 0x00, sizeof(temp.wakeup_language));
+ temp.cnt_wakeup = 0;
+ memset(temp.supported_lang, 0x00, sizeof(temp.supported_lang));
+ temp.cnt_lang = 0;
+ temp.wakeup_engine = NULL;
+ temp.custom_ui_option = false;
+ /* TODO: Define these two default values somewhere else */
+ temp.voice_key_support_mode = VOICE_KEY_SUPPORT_MODE_PUSH_TO_TALK;
+ temp.voice_key_tap_duration = 0.0f; /* Meaning not set */
+
+ while (cur != NULL) {
+ if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar *)MA_TAG_ASSISTANT_LANGUAGE_SET)) {
+ xmlNodePtr child_node = cur->xmlChildrenNode;
+ while (child_node != NULL) {
+ if (child_node->name && 0 == xmlStrcmp(child_node->name, (const xmlChar*)MA_TAG_ASSISTANT_LANGUAGE)) {
+ key = xmlNodeGetContent(child_node);
+ if (key) {
+ temp.supported_lang[temp.cnt_lang++] = strdup((const char*)key);
+ MAS_LOGD("Language : %s", key);
+ xmlFree(key);
+ }
+ }
+
+ child_node = child_node->next;
+ }
+ } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar *)MA_TAG_ASSISTANT_WAKEUP_WORD_SET)) {
+ xmlNodePtr child_node = cur->xmlChildrenNode;
+ while (child_node != NULL) {
+ if (child_node->name && 0 == xmlStrcmp(child_node->name, (const xmlChar*)MA_TAG_ASSISTANT_WAKEUP_WORD)) {
+ key = xmlNodeGetContent(child_node);
+ if (key) {
+ temp.wakeup_list[temp.cnt_wakeup] = strdup((const char*)key);
+ MAS_LOGD("Wakeup Word : %s", key);
+ xmlFree(key);
+ }
+ xmlChar* prop = xmlNodeGetLang(child_node);
+ if (prop) {
+ temp.wakeup_language[temp.cnt_wakeup] = strdup((const char*)prop);
+ MAS_LOGD("Wakeup Language for %s : %s", temp.wakeup_list[temp.cnt_wakeup], prop);
+ xmlFree(prop);
+ }
+ temp.cnt_wakeup++;
+ }
+
+ child_node = child_node->next;
+ }
+ } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_NAME)) {
+ key = xmlNodeGetContent(cur);
+ if (key) {
+ temp.name = strdup((const char*)key);
+ MAS_LOGD("Name : %s", key);
+ xmlFree(key);
+ }
+ } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_APPID)) {
+ key = xmlNodeGetContent(cur);
+ if (key) {
+ temp.app_id = strdup((const char*)key);
+ MAS_LOGD("ID : %s", key);
+ xmlFree(key);
+ }
+ } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_ICON_PATH)) {
+ key = xmlNodeGetContent(cur);
+ if (key) {
+ temp.icon_path = strdup((const char*)key);
+ MAS_LOGD("Icon Path : %s", key);
+ xmlFree(key);
+ }
+ } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_WAKEUP_ENGINE_APPID)) {
+ key = xmlNodeGetContent(cur);
+ if (key) {
+ temp.wakeup_engine = strdup((const char*)key);
+ MAS_LOGD("Wakeup Engine : %s", key);
+ xmlFree(key);
+ }
+ } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_CUSTOM_UI)) {
+ key = xmlNodeGetContent(cur);
+ if (key) {
+ if (0 == xmlStrcasecmp(key, reinterpret_cast<const xmlChar*>("true"))) {
+ temp.custom_ui_option = true;
+ }
+ MAS_LOGD("Use custom UI : %d", temp.custom_ui_option);
+ xmlFree(key);
+ }
+ } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_VOICE_KEY_SUPPORT_MODE)) {
+ key = xmlNodeGetContent(cur);
+ if (key) {
+ if (xmlStrcmp(cur->name, (const xmlChar*)VOICE_KEY_SUPPORT_MODE_STRING_ALL)) {
+ temp.voice_key_support_mode = VOICE_KEY_SUPPORT_MODE_ALL;
+ } else if (xmlStrcmp(cur->name, (const xmlChar*)VOICE_KEY_SUPPORT_MODE_STRING_TAP_TO_TALK)) {
+ temp.voice_key_support_mode = VOICE_KEY_SUPPORT_MODE_TAP_TO_TALK;
+ } else if (xmlStrcmp(cur->name, (const xmlChar*)VOICE_KEY_SUPPORT_MODE_STRING_PUSH_TO_TALK)) {
+ temp.voice_key_support_mode = VOICE_KEY_SUPPORT_MODE_PUSH_TO_TALK;
+ } else {
+ temp.voice_key_support_mode = VOICE_KEY_SUPPORT_MODE_NONE;
+ }
+ MAS_LOGD("Voice key support mode : %s", cur->name);
+ xmlFree(key);
+ }
+ } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_VOICE_KEY_TAP_DURATION)) {
+ key = xmlNodeGetContent(cur);
+ if (key) {
+ temp.voice_key_tap_duration = atof((const char*)key);
+ MAS_LOGD("Voice key tap duration : %s", key);
+ xmlFree(key);
+ }
+ }
+
+ cur = cur->next;
+ }
+
+ if (callback) {
+ callback(&temp, user_data);
+ }
+
+ if (temp.app_id) {
+ free((void*)temp.app_id);
+ }
+ if (temp.name) {
+ free((void*)temp.name);
+ }
+ if (temp.icon_path) {
+ free((void*)temp.icon_path);
+ }
+ for (loop = 0; loop < temp.cnt_wakeup; loop++) {
+ if (temp.wakeup_list[loop]) {
+ free((void*)(temp.wakeup_list[loop]));
+ }
+ }
+ for (loop = 0; loop < temp.cnt_lang; loop++) {
+ if (temp.supported_lang[loop]) {
+ free((void*)(temp.supported_lang[loop]));
+ }
+ }
+ if (temp.wakeup_engine) {
+ free((void*)temp.wakeup_engine);
+ }
+
+ xmlFreeDoc(doc);
+
+ return 0;
+}
+
+int CServiceConfig::get_assistant_info(service_config_assistant_info_cb callback, void* user_data)
+{
+ const char *suffix = ".xml";
+
+ DIR *d;
+ struct dirent *dir;
+ d = opendir(MA_ASSISTANT_INFO);
+
+ if (d) {
+ while (NULL != (dir = readdir(d))) {
+ if (suffix && strlen(suffix) <= strlen(dir->d_name)) {
+ if (0 == strcmp(dir->d_name + strlen(dir->d_name) - strlen(suffix), suffix)) {
+ char fullpath[_POSIX_PATH_MAX];
+ snprintf(fullpath, _POSIX_PATH_MAX - 1, "%s/%s", MA_ASSISTANT_INFO, dir->d_name);
+ MAS_LOGD("Parsing file : %s\n", fullpath);
+ parse_assistant_info(callback, fullpath, user_data);
+ }
+ }
+ }
+ closedir(d);
+ }
+
+ return 0;
+}
+
+int CServiceConfig::add_custom_wake_word(const char* wake_word, const char* language,
+ char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
+ char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN])
+{
+ if (nullptr == wake_word || nullptr == language) return -1;
+
+ bool found = false;
+ for (int loop = 0;false == found && loop < MAX_WAKEUP_WORDS_NUM;loop++) {
+ if (0 == strncmp(wakeup_word_storage[loop], wake_word, MAX_WAKEUP_WORD_LEN) &&
+ 0 == strncmp(wakeup_language_storage[loop], language, MAX_SUPPORTED_LANGUAGE_LEN)) {
+ LOGE("The wakeup word already exists!");
+ return -1; /* Already exists */
+ }
+ if (0 == strlen(wakeup_word_storage[loop])) {
+ strncpy(wakeup_word_storage[loop], wake_word, MAX_WAKEUP_WORD_LEN);
+ wakeup_word_storage[loop][MAX_WAKEUP_WORD_LEN - 1] = '\0';
+ strncpy(wakeup_language_storage[loop], language, MAX_SUPPORTED_LANGUAGE_LEN);
+ wakeup_language_storage[loop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
+ found = true;
+ }
+ }
+ if (!found) {
+ LOGE("No empty slot found while trying to add new wake word!");
+ return -1;
+ }
+ return 0;
+}
+
+int CServiceConfig::remove_custom_wake_word(const char* wake_word, const char* language,
+ char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
+ char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN])
+{
+ if (nullptr == wake_word || nullptr == language) return -1;
+
+ bool found = false;
+ for (int loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) {
+ if (0 == strncmp(wakeup_word_storage[loop], wake_word, MAX_WAKEUP_WORD_LEN) &&
+ 0 == strncmp(wakeup_language_storage[loop], language, MAX_SUPPORTED_LANGUAGE_LEN)) {
+ for (int shift = loop;shift < MAX_WAKEUP_WORDS_NUM - 1;shift++) {
+ strncpy(wakeup_word_storage[shift],
+ wakeup_word_storage[shift + 1], MAX_WAKEUP_WORD_LEN);
+ wakeup_word_storage[shift][MAX_WAKEUP_WORD_LEN - 1] = '\0';
+ strncpy(wakeup_language_storage[shift],
+ wakeup_language_storage[shift + 1], MAX_SUPPORTED_LANGUAGE_LEN);
+ wakeup_word_storage[shift][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
+ }
+ memset(wakeup_word_storage[MAX_WAKEUP_WORDS_NUM - 1],
+ 0x00, sizeof(char) * MAX_WAKEUP_WORD_LEN);
+ memset(wakeup_language_storage[MAX_WAKEUP_WORDS_NUM - 1],
+ 0x00, sizeof(char) * MAX_SUPPORTED_LANGUAGE_LEN);
+
+ loop--; /* Just in case there are duplicated items */
+ found = true;
+ }
+ }
+ if (!found) return -1;
+ return 0;
+}
+
+int CServiceConfig::load_custom_wake_words(const char* app_id,
+ char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
+ char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN])
+{
+ /* Add 1 for additional pipe character */
+ char wakeup_words[MAX_WAKEUP_WORDS_NUM * (MAX_WAKEUP_WORD_LEN + 1)];
+ char wakeup_languages[MAX_WAKEUP_WORDS_NUM * (MAX_SUPPORTED_LANGUAGE_LEN + 1)];
+ memset(wakeup_words, 0x00, sizeof(wakeup_words));
+ memset(wakeup_languages, 0x00, sizeof(wakeup_languages));
+
+ bool existing = false;
+ preference_is_existing("custom_wakeup_words", &existing);
+ if (!existing) return -1;
+ preference_is_existing("custom_wakeup_languages", &existing);
+ if (!existing) return -1;
+
+ char* value = NULL;
+ preference_get_string("custom_wakeup_words", &value);
+ if (NULL == value) return -1;
+ strncpy(wakeup_words, value, sizeof(wakeup_words) - 1);
+ wakeup_words[sizeof(wakeup_words) - 1] = '\0';
+ LOGD("Custom wakeup words loaded : %s", wakeup_words);
+ free(value);
+
+ preference_get_string("custom_wakeup_languages", &value);
+ if (NULL == value) return -1;
+ strncpy(wakeup_languages, value, sizeof(wakeup_languages) - 1);
+ wakeup_languages[sizeof(wakeup_languages) - 1] = '\0';
+ LOGD("Custom wakeup languages loaded : %s", wakeup_languages);
+ free(value);
+
+ char *word_start = wakeup_words;
+ char *language_start = wakeup_languages;
+ char *word_end = NULL;
+ char *language_end = NULL;
+ int index = 0;
+ while (index < MAX_WAKEUP_WORDS_NUM) {
+ word_end = strchrnul(word_start, '|');
+ language_end = strchrnul(language_start, '|');
+ if ('\0' == *word_end || '\0' == *language_end) break;
+ *word_end = '\0';
+ *language_end = '\0';
+ if (0 == strlen(word_start)) break;
+ strncpy(wakeup_word_storage[index], word_start, MAX_WAKEUP_WORD_LEN - 1);
+ strncpy(wakeup_language_storage[index], language_start, MAX_WAKEUP_WORD_LEN - 1);
+ word_start = word_end + 1;
+ language_start = language_end + 1;
+ LOGD("Added custom wakeup word : (%s) (%s)",
+ wakeup_word_storage[index], wakeup_language_storage[index]);
+ index++;
+ }
+
+ return 0;
+}
+
+int CServiceConfig::save_custom_wake_words(const char* app_id,
+ char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
+ char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN])
+{
+ /* Add 1 for additional pipe character */
+ char wakeup_words[MAX_WAKEUP_WORDS_NUM * (MAX_WAKEUP_WORD_LEN + 1)];
+ char wakeup_languages[MAX_WAKEUP_WORDS_NUM * (MAX_SUPPORTED_LANGUAGE_LEN + 1)];
+ memset(wakeup_words, 0x00, sizeof(wakeup_words));
+ memset(wakeup_languages, 0x00, sizeof(wakeup_languages));
+ for (int loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) {
+ if (strlen(wakeup_word_storage[loop]) > 0) {
+ int wakeup_words_len = strlen(wakeup_words);
+ strncat(wakeup_words, wakeup_word_storage[loop],
+ sizeof(wakeup_words) - wakeup_words_len - 1);
+ strcat(wakeup_words, "|");
+ int wakeup_languages_len = strlen(wakeup_languages);
+ strncat(wakeup_languages, wakeup_language_storage[loop],
+ sizeof(wakeup_languages) - wakeup_languages_len - 1);
+ strcat(wakeup_languages, "|");
+ }
+ }
+ wakeup_words[sizeof(wakeup_words) - 1] = '\0';
+ wakeup_languages[sizeof(wakeup_languages) - 1] = '\0';
+ preference_set_string("custom_wakeup_words", wakeup_words);
+ preference_set_string("custom_wakeup_languages", wakeup_languages);
+ return 0;
+}
+
+int CServiceConfig::get_custom_wake_word_num(
+ char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
+ char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN])
+{
+ int num = 0;
+ for (int loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) {
+ if (0 < strlen(wakeup_word_storage[loop])) {
+ num++;
+ }
+ }
+ return num;
+}
+
+bool CServiceConfig::has_custom_wake_word(const char* wake_word, const char* language,
+ char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
+ char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN])
+{
+ if (nullptr == wake_word || nullptr == language) return false;
+
+ for (int loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) {
+ if (0 == strncmp(wakeup_word_storage[loop], wake_word, MAX_WAKEUP_WORD_LEN) &&
+ 0 == strncmp(wakeup_language_storage[loop], language, MAX_SUPPORTED_LANGUAGE_LEN)) {
+ return true;
+ }
+ }
+ return false;
+}
--- /dev/null
+/*
+ * Copyright 2018-2019 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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.
+ */
+
+
+#include <dirent.h>
+#include <dlfcn.h>
+#include <message_port.h>
+
+#include "service_common.h"
+#include "service_main.h"
+#include "service_ipc_dbus.h"
+
+int CServiceIpcDbus::reconnect()
+{
+ if (!g_conn_sender || !g_conn_listener) {
+ close_connection();
+
+ if (0 != open_connection()) {
+ MAS_LOGE("[ERROR] Fail to reconnect");
+ return -1;
+ }
+
+ MAS_LOGD("[DBUS] Reconnect");
+ return 0;
+ }
+
+ bool sender_connected = dbus_connection_get_is_connected(g_conn_sender);
+ bool listener_connected = dbus_connection_get_is_connected(g_conn_listener);
+ MAS_LOGW("[DBUS] Sender(%s) Listener(%s)",
+ sender_connected ? "Connected" : "Not connected", listener_connected ? "Connected" : "Not connected");
+
+ if (false == sender_connected || false == listener_connected) {
+ close_connection();
+
+ if (0 != open_connection()) {
+ MAS_LOGE("[ERROR] Fail to reconnect");
+ return -1;
+ }
+
+ MAS_LOGD("[DBUS] Reconnect");
+ }
+
+ return 0;
+}
+
+int CServiceIpcDbus::__dbus_check()
+{
+ if (NULL == g_conn_sender || NULL == g_conn_listener) {
+ MAS_LOGE("[ERROR] NULL connection");
+ return reconnect();
+ }
+ return 0;
+}
+
+int CServiceIpcDbus::mas_check_dbus_connection()
+{
+ if (NULL == g_conn_sender || NULL == g_conn_listener) {
+ MAS_LOGE("[ERROR] NULL connection sender(%p), listener(%p)", g_conn_sender, g_conn_listener);
+ return -1;
+ }
+ return 0;
+}
+
+int CServiceIpcDbus::send_hello(int pid)
+{
+ if (0 != __dbus_check()) {
+ return -1; //MAS_ERROR_OPERATION_FAILED;
+ }
+
+ DBusMessage* msg;
+ DBusError err;
+ dbus_error_init(&err);
+
+ msg = dbus_message_new_method_call(
+ MA_CLIENT_SERVICE_NAME,
+ MA_CLIENT_SERVICE_OBJECT_PATH,
+ MA_CLIENT_SERVICE_INTERFACE,
+ MAS_METHOD_HELLO);
+
+ if (NULL == msg) {
+ MAS_LOGE("[DBus ERROR] Request masc hello : Fail to make message");
+ return -1;
+ }
+
+ int result = -1;
+ DBusMessage* result_msg = NULL;
+ result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, 500, &err);
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[Dbus ERROR] Dbus Error (%s)", err.message);
+ dbus_error_free(&err);
+ }
+
+ dbus_message_unref(msg);
+
+ if (NULL != result_msg) {
+ dbus_message_unref(result_msg);
+ result = 0;
+ } else {
+ result = -1; //MAS_ERROR_TIMED_OUT;
+ }
+
+ return result;
+}
+
+int CServiceIpcDbus::send_error_message(int reason, const char* err_msg)
+{
+ if (0 != __dbus_check()) {
+ return -1; //MAS_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == g_conn_sender) {
+ MAS_LOGE("[Dbus ERROR] Dbus connection is not available");
+ return -1;
+ }
+
+ DBusMessage* msg = NULL;
+
+ /* create a message */
+ msg = dbus_message_new_signal(
+ MA_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */
+ MA_CLIENT_SERVICE_INTERFACE, /* interface name of the signal */
+ MAS_METHOD_ERROR); /* name of the signal */
+
+ if (NULL == msg) {
+ MAS_LOGE("[Dbus ERROR] Fail to create error message");
+ return -1;
+ }
+
+ char* temp_err_msg = NULL;
+
+ if (err_msg)
+ temp_err_msg = strdup(err_msg);
+ else
+ temp_err_msg = strdup("#NULL");
+
+ dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &reason,
+ DBUS_TYPE_STRING, &temp_err_msg,
+ DBUS_TYPE_INVALID);
+
+ dbus_message_set_no_reply(msg, TRUE);
+
+ if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
+ MAS_LOGE("[Dbus ERROR] <<<< error message : Out Of Memory !");
+ } else {
+ MAS_LOGI("<<<< Send error message : reason(%d), err_msg(%s)", reason, temp_err_msg);
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+
+ if (temp_err_msg)
+ free(temp_err_msg);
+ return 0;
+}
+
+const char *message_port = "ma_streaming_port";
+
+#define STREAMING_BUFFER_SIZE 4096
+
+typedef enum {
+ streaming_data_type_audio_data,
+ streaming_data_type_streaming_section
+} streaming_data_type_e;
+
+typedef struct {
+ unsigned int streaming_data_size;
+ int streaming_data_type;
+ int streaming_data_serial;
+} streaming_data_header;
+
+typedef struct {
+ int event;
+ unsigned int data_size;
+} streaming_data_audio_data_header;
+
+typedef struct {
+ int section;
+} streaming_data_streaming_section_header;
+
+static void masc_message_port_error(int error)
+{
+ MAS_LOGE("message_port error found : %s",
+ (MESSAGE_PORT_ERROR_NONE == error) ? "MESSAGE_PORT_ERROR_NONE" :
+ (MESSAGE_PORT_ERROR_IO_ERROR == error) ? "MESSAGE_PORT_ERROR_IO_ERROR" :
+ (MESSAGE_PORT_ERROR_OUT_OF_MEMORY == error) ? "MESSAGE_PORT_ERROR_OUT_OF_MEMORY" :
+ (MESSAGE_PORT_ERROR_INVALID_PARAMETER == error) ? "MESSAGE_PORT_ERROR_INVALID_PARAMETER" :
+ (MESSAGE_PORT_ERROR_PORT_NOT_FOUND == error) ? "MESSAGE_PORT_ERROR_PORT_NOT_FOUND" :
+ (MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH == error) ? "MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH" :
+ (MESSAGE_PORT_ERROR_MAX_EXCEEDED == error) ? "MESSAGE_PORT_ERROR_MAX_EXCEEDED" :
+ (MESSAGE_PORT_ERROR_RESOURCE_UNAVAILABLE == error) ? "MESSAGE_PORT_ERROR_RESOURCE_UNAVAILABLE" :
+ "MESSAGE_PORT_ERROR_UNKNOWN");
+}
+
+int CServiceIpcDbus::send_streaming_audio_data(int pid, int event, void* data, unsigned int data_size)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ static unsigned char pending_buffer[STREAMING_BUFFER_SIZE];
+ static unsigned int pending_buffer_size = 0;
+
+ streaming_data_header header;
+ header.streaming_data_type = 0;
+ header.streaming_data_size = sizeof(streaming_data_header) + sizeof(streaming_data_audio_data_header) + data_size;
+ header.streaming_data_serial = g_streaming_data_serial++;
+
+ streaming_data_audio_data_header audio_data_header;
+ audio_data_header.event = event;
+ audio_data_header.data_size = data_size;
+
+ unsigned char buffer[STREAMING_BUFFER_SIZE];
+ size_t total_size = 0;
+ memcpy(buffer, &header, sizeof(header));
+ total_size += sizeof(header);
+ memcpy(buffer + total_size, &audio_data_header, sizeof(audio_data_header));
+ total_size += sizeof(audio_data_header);
+ memcpy(buffer + total_size, data, data_size);
+ total_size += data_size;
+
+ static int last_serial_waiting_for_flush = -1;
+ if (0 == header.streaming_data_serial % 50) {
+ last_serial_waiting_for_flush = header.streaming_data_serial;
+ MAS_LOGI("queueing streaming data, serial : %d", last_serial_waiting_for_flush);
+ }
+ if (pending_buffer_size + total_size > STREAMING_BUFFER_SIZE ||
+ MAS_SPEECH_STREAMING_EVENT_FINISH == event) {
+ bundle *b = bundle_create();
+ if (b) {
+ bundle_add_byte(b, "content", pending_buffer, pending_buffer_size);
+ int ret = message_port_send_message(
+ mServiceMain->mas_get_client_appid_by_pid(pid), message_port, b);
+ if (MESSAGE_PORT_ERROR_NONE != ret)
+ masc_message_port_error(ret);
+
+ pending_buffer_size = 0;
+ bundle_free(b);
+ } else {
+ MAS_LOGE("Bundle creation failed!!!");
+ }
+
+ if (-1 != last_serial_waiting_for_flush) {
+ MAS_LOGI("flushing streaming data, serial : %d", last_serial_waiting_for_flush);
+ last_serial_waiting_for_flush = -1;
+ }
+ }
+
+ if (MAS_SPEECH_STREAMING_EVENT_FINISH == event) {
+ bundle *b = bundle_create();
+ if (b) {
+ bundle_add_byte(b, "content", buffer, total_size);
+ int ret = message_port_send_message(
+ mServiceMain->mas_get_client_appid_by_pid(pid), message_port, b);
+ if (MESSAGE_PORT_ERROR_NONE != ret)
+ masc_message_port_error(ret);
+
+ bundle_free(b);
+ } else {
+ MAS_LOGE("Bundle creation failed!!!");
+ }
+ } else {
+ memcpy(pending_buffer + pending_buffer_size, buffer, total_size);
+ pending_buffer_size += total_size;
+ }
+ return 0;
+}
+
+int CServiceIpcDbus::active_state_change(int pid, int state)
+{
+ if (0 != __dbus_check()) {
+ return -1; //MAS_ERROR_OPERATION_FAILED;
+ }
+
+ DBusMessage* msg;
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ char service_name[64];
+ memset(service_name, '\0', 64);
+ snprintf(service_name, 64, "%s_%d", MA_CLIENT_SERVICE_NAME, pid);
+
+ msg = dbus_message_new_method_call(
+ service_name,
+ MA_CLIENT_SERVICE_OBJECT_PATH,
+ MA_CLIENT_SERVICE_INTERFACE,
+ MAS_METHOD_ACTIVE_STATE_CHANGE);
+
+ if (NULL == msg) {
+ MAS_LOGE(">>>> Request mas send activate message : Fail to make message");
+ return -1; // MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD(">>>> Request mas send activate message : %s", service_name);
+ }
+
+ if (true != dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &state,
+ DBUS_TYPE_INVALID)) {
+ dbus_message_unref(msg);
+ MAS_LOGE("[ERROR] Fail to append args");
+ return -1;
+ }
+
+ dbus_message_set_no_reply(msg, TRUE);
+
+ if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
+ MAS_LOGE("[Dbus ERROR] Fail to Send");
+ return -1; // MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGI("[Dbus DEBUG] Success to Send activate message : %d %d", pid, state);
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+ return 0;
+}
+
+int CServiceIpcDbus::send_preprocessing_information(int pid, const char* app_id)
+{
+ if (0 != __dbus_check()) {
+ return -1; //MAS_ERROR_OPERATION_FAILED;
+ }
+
+ DBusMessage* msg;
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ char service_name[64];
+ memset(service_name, '\0', 64);
+ snprintf(service_name, 64, "%s_%d", MA_CLIENT_SERVICE_NAME, pid);
+
+ msg = dbus_message_new_method_call(
+ service_name,
+ MA_CLIENT_SERVICE_OBJECT_PATH,
+ MA_CLIENT_SERVICE_INTERFACE,
+ MAS_METHOD_SEND_PREPROCESSING_INFORMATION);
+
+ if (NULL == msg) {
+ MAS_LOGE(">>>> Request mas send preprocessing assistant information : Fail to make message");
+ return -1; // MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD(">>>> Request mas send preprocessing assistant information : %s", service_name);
+ }
+
+ char* temp_app_id = NULL;
+ if (!app_id)
+ temp_app_id = strdup("#NULL");
+ else
+ temp_app_id = strdup(app_id);
+
+ if (true != dbus_message_append_args(msg,
+ DBUS_TYPE_STRING, &temp_app_id,
+ DBUS_TYPE_INVALID)) {
+ dbus_message_unref(msg);
+ MAS_LOGE("[ERROR] Fail to append args");
+ if (temp_app_id)
+ free(temp_app_id);
+ return -1;
+ }
+
+ dbus_message_set_no_reply(msg, TRUE);
+
+ if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
+ MAS_LOGE("[Dbus ERROR] Fail to Send");
+ if (temp_app_id)
+ free(temp_app_id);
+ return -1; // MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGI("[Dbus DEBUG] Success to Send preprocessing assistant information : %d %s", pid, app_id);
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+
+ if (temp_app_id)
+ free(temp_app_id);
+
+ return 0;
+}
+
+int CServiceIpcDbus::send_streaming_section_changed(int pid, int section)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ bundle *b = bundle_create();
+
+ streaming_data_header header;
+ header.streaming_data_type = 1;
+ header.streaming_data_size = sizeof(streaming_data_header) + sizeof(streaming_data_streaming_section_header);
+ header.streaming_data_serial = g_streaming_data_serial++;
+
+ streaming_data_streaming_section_header streaming_section_header;
+ streaming_section_header.section = section;
+
+ unsigned char buffer[STREAMING_BUFFER_SIZE];
+ size_t total_size = 0;
+ memcpy(buffer, &header, sizeof(header));
+ total_size += sizeof(header);
+ memcpy(buffer + total_size, &streaming_section_header, sizeof(streaming_section_header));
+ total_size += sizeof(streaming_section_header);
+
+ bundle_add_byte(b, "content", buffer, total_size);
+ int ret = message_port_send_message(mServiceMain->mas_get_client_appid_by_pid(pid), message_port, b);
+ if (MESSAGE_PORT_ERROR_NONE != ret)
+ masc_message_port_error(ret);
+
+ bundle_free(b);
+
+ return 0;
+}
+
+int CServiceIpcDbus::send_preprocessing_result(int pid, bool result)
+{
+ if (0 != __dbus_check()) {
+ return -1; //MAS_ERROR_OPERATION_FAILED;
+ }
+
+ DBusMessage* msg;
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ char service_name[64];
+ memset(service_name, '\0', 64);
+ snprintf(service_name, 64, "%s_%d", MA_CLIENT_SERVICE_NAME, pid);
+
+ msg = dbus_message_new_method_call(
+ service_name,
+ MA_CLIENT_SERVICE_OBJECT_PATH,
+ MA_CLIENT_SERVICE_INTERFACE,
+ MAS_METHOD_SEND_PREPROCESSING_RESULT);
+
+ if (NULL == msg) {
+ MAS_LOGE(">>>> Request mas send preprocessing result : Fail to make message");
+ return -1; // MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD(">>>> Request mas send preprocessing result : %s", service_name);
+ }
+
+ int temp_result = result;
+
+ if (true != dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &temp_result,
+ DBUS_TYPE_INVALID)) {
+ dbus_message_unref(msg);
+ MAS_LOGE("[ERROR] Fail to append args");
+ return -1;
+ }
+
+ dbus_message_set_no_reply(msg, TRUE);
+
+ if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
+ MAS_LOGE("[Dbus ERROR] Fail to Send");
+ return -1; // MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGI("[Dbus DEBUG] Success to Send preprocessing result : %d %d", pid, temp_result);
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+
+ return 0;
+}
+
+int CServiceIpcDbus::send_wakeup_engine_command(int pid, const char* command)
+{
+ if (0 != __dbus_check()) {
+ return -1; //MAS_ERROR_OPERATION_FAILED;
+ }
+
+ DBusMessage* msg;
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ char service_name[64];
+ memset(service_name, '\0', 64);
+ snprintf(service_name, 64, "%s_%d", MA_CLIENT_SERVICE_NAME, pid);
+
+ msg = dbus_message_new_method_call(
+ service_name,
+ MA_CLIENT_SERVICE_OBJECT_PATH,
+ MA_CLIENT_SERVICE_INTERFACE,
+ MAS_METHOD_SEND_WAKEUP_ENGINE_COMMAND);
+
+ if (NULL == msg) {
+ MAS_LOGE(">>>> Request mas send wakeup engine command : Fail to make message");
+ return -1; // MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD(">>>> Request mas send wakeup engine command : %s", service_name);
+ }
+
+ char* temp_command = NULL;
+ if (!command)
+ temp_command = strdup("#NULL");
+ else
+ temp_command = strdup(command);
+
+ if (true != dbus_message_append_args(msg,
+ DBUS_TYPE_STRING, &temp_command,
+ DBUS_TYPE_INVALID)) {
+ dbus_message_unref(msg);
+ MAS_LOGE("[ERROR] Fail to append args");
+ if (temp_command)
+ free(temp_command);
+ return -1;
+ }
+
+ dbus_message_set_no_reply(msg, TRUE);
+
+ if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
+ MAS_LOGE("[Dbus ERROR] Fail to Send");
+ if (temp_command)
+ free(temp_command);
+ return -1; // MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGI("[Dbus DEBUG] Success to Send wakeup_engine_command : %d %s", pid, command);
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+
+ if (temp_command)
+ free(temp_command);
+
+ return 0;
+}
+
+int CServiceIpcDbus::service_state_change(int pid, int state)
+{
+ if (0 != __dbus_check()) {
+ return -1; //MAS_ERROR_OPERATION_FAILED;
+ }
+
+ DBusMessage* msg;
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ char service_name[64];
+ memset(service_name, '\0', 64);
+ snprintf(service_name, 64, "%s_%d", MA_CLIENT_SERVICE_NAME, pid);
+
+ msg = dbus_message_new_method_call(
+ service_name,
+ MA_CLIENT_SERVICE_OBJECT_PATH,
+ MA_CLIENT_SERVICE_INTERFACE,
+ MAS_METHOD_SERVICE_STATE_CHANGE);
+
+ if (NULL == msg) {
+ MAS_LOGE(">>>> Request mas send service state message : Fail to make message");
+ return -1; // MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD(">>>> Request mas send service state message : %s", service_name);
+ }
+
+ if (true != dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &state,
+ DBUS_TYPE_INVALID)) {
+ dbus_message_unref(msg);
+ MAS_LOGE("[ERROR] Fail to append args");
+ return -1;
+ }
+
+ dbus_message_set_no_reply(msg, TRUE);
+
+ if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
+ MAS_LOGE("[Dbus ERROR] Fail to Send");
+ return -1; // MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGI("[Dbus DEBUG] Success to Send service state message : %d %d", pid, state);
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+ return 0;
+}
+
+int CServiceIpcDbus::voice_key_status_change(int pid, int status)
+{
+ if (0 != __dbus_check()) {
+ return -1; //MAS_ERROR_OPERATION_FAILED;
+ }
+
+ DBusMessage* msg;
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ char service_name[64];
+ memset(service_name, '\0', 64);
+ snprintf(service_name, 64, "%s_%d", MA_CLIENT_SERVICE_NAME, pid);
+
+ msg = dbus_message_new_method_call(
+ service_name,
+ MA_CLIENT_SERVICE_OBJECT_PATH,
+ MA_CLIENT_SERVICE_INTERFACE,
+ MAS_METHOD_VOICE_KEY_STATUS_CHANGE);
+
+ if (NULL == msg) {
+ MAS_LOGE(">>>> Request mas send voice key status change message : Fail to make message");
+ return -1; // MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD(">>>> Request mas send voice key status change message : %s", service_name);
+ }
+
+ if (true != dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &status,
+ DBUS_TYPE_INVALID)) {
+ dbus_message_unref(msg);
+ MAS_LOGE("[ERROR] Fail to append args");
+ return -1;
+ }
+
+ dbus_message_set_no_reply(msg, TRUE);
+
+ if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
+ MAS_LOGE("[Dbus ERROR] Fail to Send");
+ return -1; // MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGI("[Dbus DEBUG] Success to Send voice key status change : %d %d", pid, status);
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+ return 0;
+}
+
+int CServiceIpcDbus::masc_ui_dbus_send_hello(void)
+{
+ if (0 != __dbus_check()) {
+ return -1; //MAS_ERROR_OPERATION_FAILED;
+ }
+
+ DBusMessage* msg;
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ msg = dbus_message_new_method_call(
+ MA_UI_CLIENT_SERVICE_NAME,
+ MA_UI_CLIENT_SERVICE_OBJECT_PATH,
+ MA_UI_CLIENT_SERVICE_INTERFACE,
+ MAS_METHOD_HELLO);
+
+ if (NULL == msg) {
+ MAS_LOGE("[DBus ERROR] Request masc hello : Fail to make message");
+ return -1;
+ }
+
+ DBusMessage* result_msg = NULL;
+ int result = 0;
+
+ result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, 500, &err);
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[Dbus ERROR] Dbus Error (%s)", err.message);
+ dbus_error_free(&err);
+ }
+
+ dbus_message_unref(msg);
+
+ if (NULL != result_msg) {
+ dbus_message_unref(result_msg);
+ result = 0;
+ } else {
+ result = -1; //ERROR_TIMED_OUT;
+ }
+
+ return result;
+}
+
+int CServiceIpcDbus::masc_ui_dbus_send_asr_result(int pid, int event, char* asr_result)
+{
+ if (0 != __dbus_check()) {
+ return -1; //MAS_ERROR_OPERATION_FAILED;
+ }
+
+ DBusMessage* msg;
+
+ msg = dbus_message_new_method_call(
+ MA_UI_CLIENT_SERVICE_NAME,
+ MA_UI_CLIENT_SERVICE_OBJECT_PATH,
+ MA_UI_CLIENT_SERVICE_INTERFACE,
+ MAS_UI_METHOD_SEND_ASR_RESULT);
+
+ if (NULL == msg) {
+ MAS_LOGE("@@ Request multi-assistant send ASR result : Fail to make message");
+ return -1; //MA_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD("[DEBUG] multi-assistant send ASR result, asr_result(%p)", asr_result);
+ }
+
+ char* temp_asr_result = NULL;
+ if (!asr_result)
+ temp_asr_result = strdup("#NULL");
+ else
+ temp_asr_result = strdup(asr_result);
+
+ dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INT32, &event,
+ DBUS_TYPE_STRING, &temp_asr_result,
+ DBUS_TYPE_INVALID);
+
+ dbus_message_set_no_reply(msg, TRUE);
+
+ if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
+ MAS_LOGE("[Dbus ERROR] Fail to Send");
+ if (NULL != temp_asr_result) {
+ free(temp_asr_result);
+ temp_asr_result = NULL;
+ }
+ return -1; // MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD("[Dbus DEBUG] Success to Send ASR result");
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+
+ if (temp_asr_result)
+ free(temp_asr_result);
+ return 0;
+}
+
+int CServiceIpcDbus::masc_ui_dbus_send_result(int pid, const char* display_text, const char* utterance_text, const char* result_json)
+{
+ if (0 != __dbus_check()) {
+ return -1; //MA_ERROR_OPERATION_FAILED;
+ }
+
+ DBusMessage* msg;
+
+ msg = dbus_message_new_method_call(
+ MA_UI_CLIENT_SERVICE_NAME,
+ MA_UI_CLIENT_SERVICE_OBJECT_PATH,
+ MA_UI_CLIENT_SERVICE_INTERFACE,
+ MAS_UI_METHOD_SEND_RESULT);
+
+ if (NULL == msg) {
+ MAS_LOGE("@@ Request multi-assistant send result : Fail to make message");
+ return -1; //MA_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD("[DEBUG] multi-assistant send result");
+ }
+ char* temp_display_text = NULL;
+ char* temp_utterance_text = NULL;
+ char* temp_result_json = NULL;
+
+#if 0
+ dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &display_text,
+ DBUS_TYPE_STRING, &utterance_text,
+ DBUS_TYPE_STRING, &result_json,
+ DBUS_TYPE_INVALID);
+
+ dbus_message_set_no_reply(msg, TRUE);
+
+ if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
+ MAS_LOGE("[Dbus ERROR] Fail to Send");
+ return -1; //MA_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD("[Dbus DEBUG] Success to Send result");
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+#else
+ if (!display_text)
+ temp_display_text = strdup("#NULL");
+ else
+ temp_display_text = strdup(display_text);
+ if (!utterance_text)
+ temp_utterance_text = strdup("#NULL");
+ else
+ temp_utterance_text = strdup(utterance_text);
+ if (!result_json)
+ temp_result_json = strdup("#NULL");
+ else
+ temp_result_json = strdup(result_json);
+
+ dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &temp_display_text,
+ DBUS_TYPE_STRING, &temp_utterance_text,
+ DBUS_TYPE_STRING, &temp_result_json,
+ DBUS_TYPE_INVALID);
+
+ dbus_message_set_no_reply(msg, TRUE);
+
+ if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
+ MAS_LOGE("[Dbus ERROR] Fail to Send");
+ if (temp_display_text)
+ free(temp_display_text);
+ if (temp_utterance_text)
+ free(temp_utterance_text);
+ if (temp_result_json)
+ free(temp_result_json);
+ return -1; //MA_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD("[Dbus DEBUG] Success to Send result");
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+
+ if (temp_display_text)
+ free(temp_display_text);
+ if (temp_utterance_text)
+ free(temp_utterance_text);
+ if (temp_result_json)
+ free(temp_result_json);
+#endif
+ return 0;
+}
+
+int CServiceIpcDbus::masc_ui_dbus_change_assistant(const char* app_id)
+{
+ if (0 != __dbus_check()) {
+ return -1; //MAS_ERROR_OPERATION_FAILED;
+ }
+
+ if (NULL == app_id) {
+ MAS_LOGE("@@ Request multi-assistant send change assistant request : Fail to make message");
+ return -1; //MA_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD("[DEBUG] multi-assistant send change assistant request app_id(%s)", app_id);
+ }
+
+ DBusMessage* msg;
+
+ msg = dbus_message_new_method_call(
+ MA_UI_CLIENT_SERVICE_NAME,
+ MA_UI_CLIENT_SERVICE_OBJECT_PATH,
+ MA_UI_CLIENT_SERVICE_INTERFACE,
+ MAS_UI_METHOD_CHANGE_ASSISTANT);
+
+ dbus_message_append_args(msg,
+ DBUS_TYPE_STRING, &app_id,
+ DBUS_TYPE_INVALID);
+
+ dbus_message_set_no_reply(msg, TRUE);
+
+ if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
+ MAS_LOGE("[Dbus ERROR] Fail to Send");
+ return -1; // MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD("[Dbus DEBUG] Success to Send change assistant request");
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+
+ return 0;
+}
+
+int CServiceIpcDbus::masc_ui_dbus_send_error_message(int reason, const char* err_msg)
+{
+ if (NULL == g_conn_sender) {
+ MAS_LOGE("[Dbus ERROR] Dbus connection is not available");
+ return -1;
+ }
+
+ DBusMessage* msg = NULL;
+
+ /* create a message */
+ msg = dbus_message_new_signal(
+ MA_UI_CLIENT_SERVICE_OBJECT_PATH, /* object name of the signal */
+ MA_UI_CLIENT_SERVICE_INTERFACE, /* interface name of the signal */
+ MAS_UI_METHOD_ERROR); /* name of the signal */
+
+ if (NULL == msg) {
+ MAS_LOGE("[Dbus ERROR] Fail to create error message");
+ return -1;
+ }
+
+ char* temp_err_msg = NULL;
+
+ if (err_msg)
+ temp_err_msg = strdup(err_msg);
+ else
+ temp_err_msg = strdup("#NULL");
+
+ dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &reason,
+ DBUS_TYPE_STRING, &temp_err_msg,
+ DBUS_TYPE_INVALID);
+
+ dbus_message_set_no_reply(msg, TRUE);
+
+ if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
+ MAS_LOGE("[Dbus ERROR] <<<< error message : Out Of Memory !");
+ } else {
+ MAS_LOGD("<<<< Send error message : reason(%d), err_msg(%s)", reason, temp_err_msg);
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+
+ if (temp_err_msg)
+ free(temp_err_msg);
+ return 0;
+}
+
+int CServiceIpcDbus::masc_ui_dbus_send_recognition_result(int pid, int result)
+{
+ if (0 != __dbus_check()) {
+ return -1; //MAS_ERROR_OPERATION_FAILED;
+ }
+
+ DBusMessage* msg;
+
+ msg = dbus_message_new_method_call(
+ MA_UI_CLIENT_SERVICE_NAME,
+ MA_UI_CLIENT_SERVICE_OBJECT_PATH,
+ MA_UI_CLIENT_SERVICE_INTERFACE,
+ MAS_UI_METHOD_SEND_RECOGNITION_RESULT);
+
+ if (NULL == msg) {
+ MAS_LOGE("@@ Request multi-assistant send recognition result : Fail to make message");
+ return -1; //MA_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD("[DEBUG] multi-assistant send recognition result(%d)", result);
+ }
+
+ dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INT32, &result,
+ DBUS_TYPE_INVALID);
+
+ dbus_message_set_no_reply(msg, TRUE);
+
+ if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
+ MAS_LOGE("[Dbus ERROR] Fail to Send");
+ return -1; // MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD("[Dbus DEBUG] Success to Send ASR result");
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+
+ return 0;
+}
+
+int CServiceIpcDbus::masc_ui_dbus_enable_common_ui(int enable)
+{
+ if (0 != __dbus_check()) {
+ return -1; //MAS_ERROR_OPERATION_FAILED;
+ }
+
+ DBusMessage* msg;
+
+ msg = dbus_message_new_method_call(
+ MA_UI_CLIENT_SERVICE_NAME,
+ MA_UI_CLIENT_SERVICE_OBJECT_PATH,
+ MA_UI_CLIENT_SERVICE_INTERFACE,
+ MAS_UI_METHOD_ENABLE_COMMON_UI);
+
+ if (NULL == msg) {
+ MAS_LOGE("@@ Request multi-assistant enable common ui : Fail to make message");
+ return -1; //MA_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD("[DEBUG] multi-assistant enable common ui (%d)", enable);
+ }
+
+ dbus_message_append_args(msg,
+ DBUS_TYPE_INT32, &enable,
+ DBUS_TYPE_INVALID);
+
+ dbus_message_set_no_reply(msg, TRUE);
+
+ if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) {
+ MAS_LOGE("[Dbus ERROR] Fail to Send");
+ return -1; // MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD("[Dbus DEBUG] Success to Send ASR result");
+ dbus_connection_flush(g_conn_sender);
+ }
+
+ dbus_message_unref(msg);
+
+ return 0;
+}
+
+static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler)
+{
+ CServiceIpcDbus* service_ipc = static_cast<CServiceIpcDbus*>(data);
+ if (NULL == service_ipc) {
+ MAS_LOGE("Error : service_ipc NULL");
+ return ECORE_CALLBACK_RENEW;
+ }
+
+ DBusConnection* g_conn_listener = service_ipc->get_connection_listener();
+ if (NULL == g_conn_listener) {
+ MAS_LOGE("Error : g_conn_listener NULL");
+ return ECORE_CALLBACK_RENEW;
+ }
+
+ CServiceIpcDbusDispatcher* dispatcher = service_ipc->get_dispatcher();
+ if (NULL == dispatcher) {
+ MAS_LOGE("Error : dispatcher NULL");
+ return ECORE_CALLBACK_RENEW;
+ }
+
+ dbus_connection_read_write_dispatch(g_conn_listener, 50);
+
+ while (1) {
+ DBusMessage* msg = NULL;
+ msg = dbus_connection_pop_message(g_conn_listener);
+
+ if (true != dbus_connection_get_is_connected(g_conn_listener)) {
+ MAS_LOGE("[ERROR] Connection is disconnected");
+ return ECORE_CALLBACK_RENEW;
+ }
+
+ /* loop again if we haven't read a message */
+ if (NULL == msg) {
+ return ECORE_CALLBACK_RENEW;
+ }
+
+ /* client event */
+ if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_HELLO)) {
+ dispatcher->on_hello(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_INITIALIZE)) {
+ dispatcher->on_initialize(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_DEINITIALIZE)) {
+ dispatcher->on_deinitialize(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_GET_RECORDING_AUDIO_FORMAT)) {
+ dispatcher->on_get_audio_format(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_GET_RECORDING_AUDIO_SOURCE_TYPE)) {
+ dispatcher->on_get_audio_source_type(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SEND_ASR_RESULT)) {
+ dispatcher->on_send_asr_result(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SEND_RESULT)) {
+ dispatcher->on_send_result(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SEND_RECOGNITION_RESULT)) {
+ dispatcher->on_send_recognition_result(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_START_STREAMING_AUDIO_DATA)) {
+ dispatcher->on_start_streaming_audio_data(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_STOP_STREAMING_AUDIO_DATA)) {
+ dispatcher->on_stop_streaming_audio_data(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_UPDATE_VOICE_FEEDBACK_STATE)) {
+ dispatcher->on_update_voice_feedback_state(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SEND_ASSISTANT_SPECIFIC_COMMAND)) {
+ dispatcher->on_send_assistant_specific_command(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SET_BACKGROUND_VOLUME)) {
+ dispatcher->on_set_background_volume(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SET_PREPROCESSING_ALLOW_MODE)) {
+ dispatcher->on_set_preprocessing_allow_mode(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SEND_PREPROCESSING_RESULT)) {
+ dispatcher->on_send_preprocessing_result(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG)) {
+ dispatcher->on_set_wake_word_audio_require_flag(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_SET_ASSISTANT_LANGUAGE)) {
+ dispatcher->on_set_assistant_language(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_ADD_WAKE_WORD)) {
+ dispatcher->on_add_wake_word(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_REMOVE_WAKE_WORD)) {
+ dispatcher->on_remove_wake_word(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_UI_METHOD_INITIALIZE)) {
+ dispatcher->on_ui_initialize(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_UI_METHOD_DEINITIALIZE)) {
+ dispatcher->on_ui_deinitialize(g_conn_listener, msg);
+
+ } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_UI_METHOD_CHANGE_ASSISTANT)) {
+ dispatcher->on_ui_change_assistant(g_conn_listener, msg);
+
+ } else {
+ MAS_LOGD("Message is NOT valid");
+ /* Invalid method */
+ }
+ /* free the message */
+ dbus_message_unref(msg);
+ }
+
+ return ECORE_CALLBACK_RENEW;
+}
+
+void CServiceIpcDbus::connection_free()
+{
+ if (NULL != g_conn_listener) {
+ dbus_connection_close(g_conn_listener);
+ dbus_connection_unref(g_conn_listener);
+ g_conn_listener = NULL;
+ }
+ if (NULL != g_conn_sender) {
+ dbus_connection_close(g_conn_sender);
+ dbus_connection_unref(g_conn_sender);
+ g_conn_sender = NULL;
+ }
+}
+
+int CServiceIpcDbus::open_connection()
+{
+ DBusError err;
+ dbus_error_init(&err);
+
+ int ret;
+
+ /* Create connection for sender */
+ g_conn_sender = dbus_bus_get_private(DBUS_BUS_SESSION, &err);
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[Dbus ERROR] Fail dbus_bus_get : %s", err.message);
+ dbus_error_free(&err);
+ }
+
+ if (NULL == g_conn_sender) {
+ MAS_LOGE("[Dbus ERROR] Fail to get dbus connection");
+ return -1;
+ }
+
+ 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 (dbus_error_is_set(&err)) {
+ MAS_LOGE("[Dbus ERROR] Fail dbus_bus_get : %s", err.message);
+ dbus_error_free(&err);
+ }
+
+ if (NULL == g_conn_listener) {
+ MAS_LOGE("[Dbus ERROR] Fail to get dbus connection");
+ connection_free();
+ return -1;
+ }
+
+ dbus_connection_set_exit_on_disconnect(g_conn_listener, false);
+
+ /* request our name on the bus and check for errors */
+ ret = dbus_bus_request_name(g_conn_listener, MA_SERVER_SERVICE_NAME, DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
+
+ if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
+ printf("Fail to be primary owner in dbus request.");
+ MAS_LOGE("[Dbus ERROR] Fail to be primary owner");
+ connection_free();
+ return -1;
+ }
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[Dbus ERROR] dbus_bus_request_name() : %s", err.message);
+ dbus_error_free(&err);
+ connection_free();
+ return -1;
+ }
+
+ /* Flush messages which are received before fd event handler registration */
+ while (DBUS_DISPATCH_DATA_REMAINS == dbus_connection_get_dispatch_status(g_conn_listener)) {
+ listener_event_callback(this, NULL);
+ }
+
+ /* add a rule for getting signal */
+ char rule[128];
+ snprintf(rule, 128, "type='signal',interface='%s'", MA_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)) {
+ MAS_LOGE("[Dbus ERROR] dbus_bus_add_match() : %s", err.message);
+ dbus_error_free(&err);
+ connection_free();
+ return -1;
+ }
+
+ int fd = 0;
+ if (1 != dbus_connection_get_unix_fd(g_conn_listener, &fd)) {
+ MAS_LOGE("fail to get fd from dbus ");
+ connection_free();
+ return -1;
+ } else {
+ MAS_LOGD("Get fd from dbus : %d", fd);
+ }
+
+ g_dbus_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, this, NULL, NULL);
+
+ if (NULL == g_dbus_fd_handler) {
+ MAS_LOGE("[Dbus ERROR] Fail to get fd handler");
+ connection_free();
+ return -1;
+ }
+
+ return 0;
+}
+
+int CServiceIpcDbus::close_connection()
+{
+ DBusError err;
+ dbus_error_init(&err);
+
+ if (NULL != g_dbus_fd_handler) {
+ ecore_main_fd_handler_del(g_dbus_fd_handler);
+ g_dbus_fd_handler = NULL;
+ }
+
+ dbus_bus_release_name(g_conn_listener, MA_SERVER_SERVICE_NAME, &err);
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[Dbus ERROR] dbus_bus_release_name() : %s", err.message);
+ dbus_error_free(&err);
+ }
+
+ connection_free();
+
+ return 0;
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2018-2019 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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.
+ */
+
+#include <stdlib.h>
+
+#include "service_common.h"
+#include "service_ipc_dbus_dispatcher.h"
+#include "service_main.h"
+
+/*
+* Dbus Client-Daemon Server
+*/
+int CServiceIpcDbusDispatcher::on_hello(DBusConnection* conn, DBusMessage* msg)
+{
+ MAS_LOGD("[DEBUG] MAS HELLO");
+
+ DBusMessage* reply;
+ reply = dbus_message_new_method_return(msg);
+
+ if (NULL != reply) {
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ MAS_LOGE("[OUT ERROR] Out Of Memory!");
+ }
+
+ dbus_connection_flush(conn);
+ dbus_message_unref(reply);
+ } else {
+ MAS_LOGE("[OUT ERROR] Fail to create reply message!!");
+ }
+
+ return 0;
+}
+
+int CServiceIpcDbusDispatcher::on_initialize(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid = -1;
+ int ret = 0;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS INITIALIZE");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas initialize : get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD("[IN] mas initialize : pid(%d)", pid);
+ ret = mServiceMain->mas_client_initialize(pid);
+ }
+
+ DBusMessage* reply;
+ reply = dbus_message_new_method_return(msg);
+
+ MAS_LOGI("[OUT] mas initialize : result(%d)", ret);
+ if (NULL != reply) {
+ dbus_message_append_args(reply,
+ DBUS_TYPE_INT32, &ret,
+ DBUS_TYPE_INVALID);
+
+ if (0 == ret) {
+ MAS_LOGD("[OUT] mas initialize : result(%d)", ret);
+ } else {
+ MAS_LOGE("[OUT ERROR] mas initialize : result(%d)", ret);
+ }
+
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ MAS_LOGE("[OUT ERROR] mas initialize : Out Of Memory!");
+ }
+
+ dbus_connection_flush(conn);
+ dbus_message_unref(reply);
+ } else {
+ MAS_LOGE("[OUT ERROR] mas initialize : Fail to create reply message!!");
+ }
+
+ return ret;
+}
+
+int CServiceIpcDbusDispatcher::on_deinitialize(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid = -1;
+ int ret = 0;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS DEINITIALIZE");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas deinitialize : get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD("[IN] mas deinitialize : pid(%d)", pid);
+ ret = mServiceMain->mas_client_deinitialize(pid);
+ }
+
+ DBusMessage* reply;
+ reply = dbus_message_new_method_return(msg);
+
+ MAS_LOGI("[OUT] mas deinitialize : result(%d)", ret);
+ if (NULL != reply) {
+ dbus_message_append_args(reply,
+ DBUS_TYPE_INT32, &ret,
+ DBUS_TYPE_INVALID);
+
+ if (0 == ret) {
+ MAS_LOGD("[OUT] mas deinitialize : result(%d)", ret);
+ } else {
+ MAS_LOGE("[OUT ERROR] mas deinitialize : result(%d)", ret);
+ }
+
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ MAS_LOGE("[OUT ERROR] mas deinitialize : Out Of Memory!");
+ }
+
+ dbus_connection_flush(conn);
+ dbus_message_unref(reply);
+ } else {
+ MAS_LOGE("[OUT ERROR] mas deinitialize : Fail to create reply message!!");
+ }
+
+ return 0;
+}
+
+int CServiceIpcDbusDispatcher::on_get_audio_format(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid = -1;
+ int rate, channel, audio_type;
+ int ret;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS GET AUDIO FORMAT");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas get audio format : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD("[IN] mas get audio format");
+ ret = mServiceMain->mas_client_get_audio_format(pid, &rate, &channel, &audio_type);
+ }
+
+ DBusMessage* reply;
+ reply = dbus_message_new_method_return(msg);
+
+ if (NULL != reply) {
+ /* Append result and voice */
+ dbus_message_append_args(reply,
+ DBUS_TYPE_INT32, &ret,
+ DBUS_TYPE_INT32, &rate,
+ DBUS_TYPE_INT32, &channel,
+ DBUS_TYPE_INT32, &audio_type,
+ DBUS_TYPE_INVALID);
+ if (0 == ret) {
+ MAS_LOGI("[OUT] mas get audio format : rate(%d), channel(%d), audio_type(%d)", rate, channel, audio_type);
+ } else {
+ MAS_LOGE("[OUT ERROR] mas get audio format : result(%d)", ret);
+ }
+
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ MAS_LOGE("[OUT ERROR] mas get audio format : Out Of Memory!");
+ }
+
+ dbus_connection_flush(conn);
+ dbus_message_unref(reply);
+ } else {
+ MAS_LOGE("[OUT ERROR] tts default voice : Fail to create reply message!!");
+ }
+
+ return ret;
+}
+
+int CServiceIpcDbusDispatcher::on_get_audio_source_type(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid = -1;
+ char *type = NULL;
+ int ret;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS GET AUDIO SOURCE TYPE");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas get audio source type : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD("[IN] mas get audio source type");
+ ret = mServiceMain->mas_client_get_audio_source_type(pid, &type);
+ }
+
+ DBusMessage* reply;
+ reply = dbus_message_new_method_return(msg);
+
+ char* temp_type = NULL;
+
+ if (type)
+ temp_type = strdup(type);
+ else
+ temp_type = strdup("#NULL");
+
+ if (NULL != reply) {
+ /* Append result and voice */
+ dbus_message_append_args(reply,
+ DBUS_TYPE_INT32, &ret,
+ DBUS_TYPE_STRING, &temp_type,
+ DBUS_TYPE_INVALID);
+ if (0 == ret) {
+ MAS_LOGI("[OUT] mas get audio source type : type(%s)", temp_type);
+ } else {
+ MAS_LOGE("[OUT ERROR] mas get audio source type : result(%d)", ret);
+ }
+
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ MAS_LOGE("[OUT ERROR] mas get audio source type : Out Of Memory!");
+ }
+
+ dbus_connection_flush(conn);
+ dbus_message_unref(reply);
+ } else {
+ MAS_LOGE("[OUT ERROR] mas get audio source type : Fail to create reply message!!");
+ }
+
+ if (temp_type)
+ free(temp_type);
+
+ return ret;
+}
+
+int CServiceIpcDbusDispatcher::on_send_asr_result(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid, event;
+ char *asr_result;
+ int ret = 0;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INT32, &event,
+ DBUS_TYPE_STRING, &asr_result,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS SEND ASR RESULT");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas send asr result : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGI("[IN] mas send asr result : pid(%d), event(%d), asr_result(%s)", pid, event, asr_result);
+ ret = mServiceMain->mas_client_send_asr_result(pid, event, asr_result);
+ }
+
+ DBusMessage* reply;
+ reply = dbus_message_new_method_return(msg);
+
+ if (NULL != reply) {
+ dbus_message_append_args(reply,
+ DBUS_TYPE_INT32, &ret,
+ DBUS_TYPE_INVALID);
+
+ if (0 == ret) {
+ MAS_LOGD("[OUT] mas send asr result : result(%d)", ret);
+ } else {
+ MAS_LOGE("[OUT ERROR] mas send asr result : result(%d)", ret);
+ }
+
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ MAS_LOGE("[OUT ERROR] mas send asr result : Out Of Memory!");
+ }
+
+ dbus_connection_flush(conn);
+ dbus_message_unref(reply);
+ } else {
+ MAS_LOGE("[OUT ERROR] mas send asr result : Fail to create reply message!!");
+ }
+
+ MAS_LOGD("<<<<<");
+ MAS_LOGD(" ");
+
+ return ret;
+}
+
+int CServiceIpcDbusDispatcher::on_send_result(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid;
+ char* display_text;
+ char* utterance_text;
+ char* result_json;
+ int ret = 0;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &display_text,
+ DBUS_TYPE_STRING, &utterance_text,
+ DBUS_TYPE_STRING, &result_json,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS SEND RESULT");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas send result : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGI("[IN] mas send result : pid(%d), display_text(%s), utterance_text(%s), result_json(%s)", pid, display_text, utterance_text, result_json);
+ ret = mServiceMain->mas_client_send_result(pid, display_text, utterance_text, result_json);
+ }
+
+ DBusMessage* reply;
+ reply = dbus_message_new_method_return(msg);
+
+ if (NULL != reply) {
+ dbus_message_append_args(reply,
+ DBUS_TYPE_INT32, &ret,
+ DBUS_TYPE_INVALID);
+
+ if (0 == ret) {
+ MAS_LOGD("[OUT] mas send result : result(%d)", ret);
+ } else {
+ MAS_LOGE("[OUT ERROR] mas send result : result(%d)", ret);
+ }
+
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ MAS_LOGE("[OUT ERROR] mas send result : Out Of Memory!");
+ }
+
+ dbus_connection_flush(conn);
+ dbus_message_unref(reply);
+ } else {
+ MAS_LOGE("[OUT ERROR] mas send result : Fail to create reply message!!");
+ }
+
+ MAS_LOGD("<<<<<");
+ MAS_LOGD(" ");
+
+ return ret;
+}
+
+int CServiceIpcDbusDispatcher::on_send_recognition_result(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid;
+ int result;
+ int ret = 0;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INT32, &result,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS SEND RECOGNITION RESULT");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas send recognition result : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGI("[IN] mas send recognition result : pid(%d), result(%d)", pid, result);
+ ret = mServiceMain->mas_client_send_recognition_result(pid, result);
+ }
+
+ MAS_LOGD("<<<<<");
+ MAS_LOGD(" ");
+
+ return ret;
+}
+
+int CServiceIpcDbusDispatcher::on_start_streaming_audio_data(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid;
+ int type;
+ int ret = 0;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INT32, &type,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS SEND START STREAMING");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas send start streaming : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGI("[IN] mas send start streaming : pid(%d), type(%d)", pid, type);
+ ret = mServiceMain->mas_client_start_streaming_audio_data(pid, type);
+ }
+
+ MAS_LOGD("<<<<<");
+ MAS_LOGD(" ");
+
+ return ret;
+}
+
+int CServiceIpcDbusDispatcher::on_stop_streaming_audio_data(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid;
+ int type;
+ int ret = 0;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INT32, &type,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS SEND STOP STREAMING");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas stop streaming : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGI("[IN] mas stop streaming : pid(%d), type(%d)", pid, type);
+ ret = mServiceMain->mas_client_stop_streaming_audio_data(pid, type);
+ }
+
+ MAS_LOGD("<<<<<");
+ MAS_LOGD(" ");
+
+ return ret;
+}
+
+int CServiceIpcDbusDispatcher::on_update_voice_feedback_state(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid;
+ int state;
+ int ret = 0;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INT32, &state,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS SEND UPDATE VOICE FEEDBACK");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas update voice feedback : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGI("[IN] mas update voice feedback : pid(%d), state(%d)", pid, state);
+ ret = mServiceMain->mas_client_update_voice_feedback_state(pid, state);
+ }
+
+ MAS_LOGD("<<<<<");
+ MAS_LOGD(" ");
+
+ return ret;
+}
+
+int CServiceIpcDbusDispatcher::on_send_assistant_specific_command(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid;
+ int ret = 0;
+ char* command;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &command,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS SEND ASSISTANT SPECIFIC COMMAND");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas send assistant specific command : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGI("[IN] mas send assistant specific command : pid(%d), command(%s)", pid, command);
+ ret = mServiceMain->mas_client_set_assistant_specific_command(pid, command);
+ }
+
+ MAS_LOGD("<<<<<");
+ MAS_LOGD(" ");
+
+ return ret;
+}
+
+int CServiceIpcDbusDispatcher::on_set_background_volume(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid;
+ int ret = 0;
+ double ratio;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_DOUBLE, &ratio,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS SET BACKGROUND VOLUME");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas set background volume : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGI("[IN] mas set background volume : pid(%d), ratio(%f)", pid, ratio);
+ ret = mServiceMain->mas_client_set_background_volume(pid, ratio);
+ }
+
+ MAS_LOGD("<<<<<");
+ MAS_LOGD(" ");
+
+ return ret;
+}
+
+int CServiceIpcDbusDispatcher::on_set_preprocessing_allow_mode(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid;
+ int ret = 0;
+ int mode;
+ char* app_id;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INT32, &mode,
+ DBUS_TYPE_STRING, &app_id,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS SET PREPROCESSING ALLOW MODE");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas set preprocessing allow mode : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ char* temp_app_id = NULL;
+ if (NULL != app_id && strcmp("#NULL", app_id)) {
+ temp_app_id = strdup(app_id);
+ }
+ MAS_LOGI("[IN] mas set preprocessing allow mode : pid(%d), mode(%d), app_id(%s)", pid, mode, temp_app_id);
+ ret = mServiceMain->mas_client_set_preprocessing_allow_mode(pid,
+ static_cast<ma_preprocessing_allow_mode_e>(mode), temp_app_id);
+ if (NULL != temp_app_id)
+ free(temp_app_id);
+ }
+
+ MAS_LOGD("<<<<<");
+ MAS_LOGD(" ");
+
+ return ret;
+}
+
+int CServiceIpcDbusDispatcher::on_send_preprocessing_result(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid;
+ int ret = 0;
+ int result;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INT32, &result,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS SEND PREPROCESSING RESULT");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas send preprocessing result : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGI("[IN] mas send preprocessing result : pid(%d), result(%d)", pid, result);
+ ret = mServiceMain->mas_client_send_preprocessing_result(pid, (bool)result);
+ }
+
+ MAS_LOGD("<<<<<");
+ MAS_LOGD(" ");
+
+ return ret;
+}
+
+int CServiceIpcDbusDispatcher::on_set_wake_word_audio_require_flag(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid;
+ int ret = 0;
+ int require;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INT32, &require,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS SET WAKE WORD AUDIO REQUIRE FLAG");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas set wake word audio require flag : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGI("[IN] mas set wake word audio require flag : pid(%d), require(%d)", pid, require);
+ ret = mServiceMain->mas_client_set_wake_word_audio_require_flag(pid, (bool)require);
+ }
+
+ MAS_LOGD("<<<<<");
+ MAS_LOGD(" ");
+
+ return ret;
+}
+
+int CServiceIpcDbusDispatcher::on_set_assistant_language(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid;
+ int ret = 0;
+ char* language;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &language,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS SET ASSISTANT LANGUAGE");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas set assistant language : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGI("[IN] mas set assistant language : pid(%d), language(%s)", pid, language);
+ ret = mServiceMain->mas_client_set_assistant_language(pid, language);
+ }
+
+ MAS_LOGD("<<<<<");
+ MAS_LOGD(" ");
+
+ return ret;
+}
+
+int CServiceIpcDbusDispatcher::on_add_wake_word(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid;
+ int ret = 0;
+ char* wake_word;
+ char* language;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &wake_word,
+ DBUS_TYPE_STRING, &language,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS ADD WAKE WORD");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas add wake word : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGI("[IN] mas add wake word : pid(%d), wake_word(%s) language(%s)", pid, wake_word, language);
+ ret = mServiceMain->mas_client_add_wake_word(pid, wake_word, language);
+ }
+
+ MAS_LOGD("<<<<<");
+ MAS_LOGD(" ");
+
+ return ret;
+}
+
+int CServiceIpcDbusDispatcher::on_remove_wake_word(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid;
+ int ret = 0;
+ char* wake_word;
+ char* language;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_STRING, &wake_word,
+ DBUS_TYPE_STRING, &language,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS REMOVE WAKE WORD");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas remove wake word : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGI("[IN] mas remove wake word : pid(%d), wake_word(%s) language(%s)", pid, wake_word, language);
+ ret = mServiceMain->mas_client_remove_wake_word(pid, wake_word, language);
+ }
+
+ MAS_LOGD("<<<<<");
+ MAS_LOGD(" ");
+
+ return ret;
+}
+
+int CServiceIpcDbusDispatcher::on_ui_initialize(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid = -1;
+ int ret = 0;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS UI INITIALIZE");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas ui initialize : get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD("[IN] mas ui initialize : pid(%d)", pid);
+ ret = mServiceMain->mas_ui_client_initialize(pid);
+ }
+
+ DBusMessage* reply;
+ reply = dbus_message_new_method_return(msg);
+
+ MAS_LOGD("[OUT] mas ui initialize : result(%d)", ret);
+ if (NULL != reply) {
+ dbus_message_append_args(reply,
+ DBUS_TYPE_INT32, &ret,
+ DBUS_TYPE_INVALID);
+
+ if (0 == ret) {
+ MAS_LOGD("[OUT] mas ui initialize : result(%d)", ret);
+ } else {
+ MAS_LOGE("[OUT ERROR] mas ui initialize : result(%d)", ret);
+ }
+
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ MAS_LOGE("[OUT ERROR] mas ui initialize : Out Of Memory!");
+ }
+
+ dbus_connection_flush(conn);
+ dbus_message_unref(reply);
+ } else {
+ MAS_LOGE("[OUT ERROR] mas ui initialize : Fail to create reply message!!");
+ }
+
+ return ret;
+}
+
+int CServiceIpcDbusDispatcher::on_ui_deinitialize(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ int pid = -1;
+ int ret = 0;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_INT32, &pid,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS UI DEINITIALIZE");
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas ui deinitialize : get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD("[IN] mas ui deinitialize : pid(%d)", pid);
+ ret = mServiceMain->mas_ui_client_deinitialize(pid);
+ }
+
+ DBusMessage* reply;
+ reply = dbus_message_new_method_return(msg);
+
+ MAS_LOGD("[OUT] mas ui deinitialize : result(%d)", ret);
+ if (NULL != reply) {
+ dbus_message_append_args(reply,
+ DBUS_TYPE_INT32, &ret,
+ DBUS_TYPE_INVALID);
+
+ if (0 == ret) {
+ MAS_LOGD("[OUT] mas ui deinitialize : result(%d)", ret);
+ } else {
+ MAS_LOGE("[OUT ERROR] mas ui deinitialize : result(%d)", ret);
+ }
+
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ MAS_LOGE("[OUT ERROR] mas ui deinitialize : Out Of Memory!");
+ }
+
+ dbus_connection_flush(conn);
+ dbus_message_unref(reply);
+ } else {
+ MAS_LOGE("[OUT ERROR] mas ui deinitialize : Fail to create reply message!!");
+ }
+
+ return ret;
+}
+
+int CServiceIpcDbusDispatcher::on_ui_change_assistant(DBusConnection* conn, DBusMessage* msg)
+{
+ if (nullptr == mServiceMain) {
+ MAS_LOGE("mServiceMain variable is NULL");
+ return -1;
+ }
+
+ DBusError err;
+ dbus_error_init(&err);
+
+ char *app_id;
+ int ret = 0;
+
+ dbus_message_get_args(msg, &err,
+ DBUS_TYPE_STRING, &app_id,
+ DBUS_TYPE_INVALID);
+
+ MAS_LOGD("[DEBUG] MAS UI CHANGE ASSISTANT : %s", (app_id ? app_id : "NULL"));
+
+ if (dbus_error_is_set(&err)) {
+ MAS_LOGE("[IN ERROR] mas ui change assisant : Get arguments error (%s)", err.message);
+ dbus_error_free(&err);
+ ret = -1; //MAS_ERROR_OPERATION_FAILED;
+ } else {
+ MAS_LOGD("[IN] mas ui change assisant : app_id(%s)", app_id);
+ ret = mServiceMain->mas_ui_client_change_assistant(app_id);
+ }
+
+ DBusMessage* reply;
+ reply = dbus_message_new_method_return(msg);
+
+ if (NULL != reply) {
+ dbus_message_append_args(reply,
+ DBUS_TYPE_INT32, &ret,
+ DBUS_TYPE_INVALID);
+
+ if (0 == ret) {
+ MAS_LOGD("[OUT] mas ui change assisant : result(%d)", ret);
+ } else {
+ MAS_LOGE("[OUT ERROR] mas ui change assisant : result(%d)", ret);
+ }
+
+ if (!dbus_connection_send(conn, reply, NULL)) {
+ MAS_LOGE("[OUT ERROR] mas ui change assisant : Out Of Memory!");
+ }
+
+ dbus_connection_flush(conn);
+ dbus_message_unref(reply);
+ } else {
+ MAS_LOGE("[OUT ERROR] mas ui change assisant : Fail to create reply message!!");
+ }
+
+ MAS_LOGD("<<<<<");
+ MAS_LOGD(" ");
+
+ return ret;
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2018-2019 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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.
+ */
+
+#include <tizen.h>
+#include <service_app.h>
+#include <app_manager.h>
+#include <app.h>
+#include <aul.h>
+#include <aul_svc.h>
+#include <malloc.h>
+#include <Ecore.h>
+#include <vconf.h>
+#include <pkgmgr-info.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <glib.h>
+
+#include "service_common.h"
+#include "service_main.h"
+#include "service_plugin.h"
+#include "service_ipc_dbus.h"
+#include "service_config.h"
+
+static CServiceMain* g_service_main = nullptr;
+
+int CServiceMain::ma_client_create(ma_client_s *info)
+{
+ if (NULL == info) {
+ MAS_LOGE("Input parameter is NULL"); //LCOV_EXCL_LINE
+ return -1;
+ }
+
+ ma_client_s* data = NULL;
+
+ data = (ma_client_s*)calloc(1, sizeof(ma_client_s));
+ if (NULL == data) {
+ MAS_LOGE("[ERROR] Fail to allocate memory"); //LCOV_EXCL_LINE
+ return -1;// MA_ERROR_OUT_OF_MEMORY;
+ }
+
+ *data = *info;
+ g_client_list = g_slist_append(g_client_list, data);
+
+ return 0;
+}
+
+int CServiceMain::ma_client_destroy(ma_client_s *client)
+{
+ if (NULL == client) {
+ MAS_LOGE("Input parameter is NULL"); //LCOV_EXCL_LINE
+ return -1;// MA_ERROR_OPERATION_FAILED;
+ }
+
+ g_client_list = g_slist_remove(g_client_list, client);
+
+ free(client);
+ client = NULL;
+
+ return 0;
+}
+
+ma_client_s* CServiceMain::ma_client_find_by_appid(const char *appid)
+{
+ if (NULL == appid) {
+ MAS_LOGE("Input parameter is NULL"); //LCOV_EXCL_LINE
+ return NULL;
+ }
+
+ ma_client_s *data = NULL;
+
+ int count = g_slist_length(g_client_list);
+ int i;
+
+ for (i = 0; i < count; i++) {
+ data = static_cast<ma_client_s*>(g_slist_nth_data(g_client_list, i));
+
+ if (NULL != data) {
+ if (0 == strncmp(data->appid, appid, MAX_APPID_LEN)) {
+ return data;
+ }
+ }
+ }
+
+ MAS_LOGE("[ERROR] client Not found");
+
+ return NULL;
+}
+
+ma_client_s* CServiceMain::ma_client_find_by_pid(int pid)
+{
+ ma_client_s *data = NULL;
+
+ int count = g_slist_length(g_client_list);
+ int i;
+
+ for (i = 0; i < count; i++) {
+ data = static_cast<ma_client_s*>(g_slist_nth_data(g_client_list, i));
+
+ if (NULL != data) {
+ if (data->pid == pid) {
+ return data;
+ }
+ }
+ }
+
+ MAS_LOGE("[ERROR] client Not found");
+
+ return NULL;
+}
+
+bool CServiceMain::check_preprocessing_assistant_exists()
+{
+ bool ret = false;
+
+ char* vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
+ if (vconf_str) {
+ for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+ if (g_maclient_info[loop].used) {
+ if (strncmp(vconf_str, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
+ ma_client_s* client = ma_client_find_by_appid(vconf_str);
+ if (client && client->pid > 0) {
+ ret = true;
+ }
+ }
+ }
+ }
+ free(vconf_str);
+ vconf_str = NULL;
+ }
+
+ MAS_LOGD("result : %d", ret);
+
+ return ret;
+}
+
+bool CServiceMain::is_current_preprocessing_assistant(const char* appid)
+{
+ if (NULL == appid) return false;
+
+ bool ret = false;
+
+ char* vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
+ if (vconf_str) {
+ if (strncmp(vconf_str, appid, MAX_APPID_LEN) == 0) {
+ ret = true;
+ }
+ free(vconf_str);
+ vconf_str = NULL;
+ }
+
+ return ret;
+}
+
+int CServiceMain::mas_client_initialize(int pid)
+{
+ MAS_LOGD("[Enter] pid(%d)", pid);
+
+ char appid[MAX_APPID_LEN] = {'\0', };
+ if (AUL_R_OK == aul_app_get_appid_bypid(pid, appid, sizeof(appid))) {
+ appid[MAX_APPID_LEN - 1] = '\0';
+
+ MAS_LOGD("appid for pid %d is : %s", pid, (appid ? appid : "Unknown"));
+
+ /* Remove existing client that has same appid, if there's any */
+ ma_client_s *old_client = NULL;
+ old_client = ma_client_find_by_appid(appid);
+ if (old_client) {
+ ma_client_destroy(old_client);
+ old_client = NULL;
+ }
+
+ /* And remove a client that has same pid also */
+ old_client = ma_client_find_by_pid(pid);
+ if (old_client) {
+ ma_client_destroy(old_client);
+ old_client = NULL;
+ }
+
+ ma_client_s new_client;
+ new_client.pid = pid;
+ strncpy(new_client.appid, appid, MAX_APPID_LEN);
+ new_client.appid[MAX_APPID_LEN - 1] = '\0';
+ ma_client_create(&new_client);
+
+ const char *current_maclient_appid = NULL;
+ if (g_current_maclient_info >= 0 && g_current_maclient_info < MAX_MACLIENT_INFO_NUM) {
+ current_maclient_appid = g_maclient_info[g_current_maclient_info].appid;
+ }
+
+ mas_client_send_preprocessing_information(pid);
+ if (MA_VOICE_KEY_STATUS_PRESSED == mLastVoiceKeyStatus) {
+ mas_client_send_voice_key_status_change(pid, mLastVoiceKeyStatus);
+ }
+ if (current_maclient_appid && 0 == strncmp(current_maclient_appid, appid, MAX_APPID_LEN)) {
+ MAS_LOGD("MA client with current maclient appid connected!");
+
+ if (0 == g_wakeup_maclient_appid.compare(appid)) {
+ g_wakeup_maclient_appid.clear();
+ mas_client_activate(pid);
+ mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED);
+ } else {
+ MAS_LOGE("[ERROR] g_wakeup_maclient_appid and appid differ : %s %s",
+ g_wakeup_maclient_appid.c_str(), appid);
+ }
+ } else {
+ MAS_LOGD("MA client connected, but its appid does not match with current maclient");
+ }
+
+ mServiceIpc.service_state_change(pid, mas_get_current_service_state());
+ } else {
+ MAS_LOGE("[ERROR] Fail to retrieve appid");
+ }
+
+ return 0;
+}
+
+int CServiceMain::mas_client_deinitialize(int pid)
+{
+ MAS_LOGD("[Enter] pid(%d)", pid);
+ ma_client_s *client = ma_client_find_by_pid(pid);
+ if (client) {
+ ma_client_destroy(client);
+ client = NULL;
+ }
+ return 0;
+}
+
+int CServiceMain::mas_client_get_audio_format(int pid, int* rate, int* channel, int* audio_type)
+{
+ MAS_LOGD("[Enter] pid(%d)", pid);
+
+ int ret = mServicePlugin.get_recording_audio_format(rate, channel, audio_type);
+ if (0 != ret){
+ MAS_LOGE("[ERROR] Fail to get recording audio format, ret(%d)", ret);
+ }
+
+ return ret;
+}
+
+#define MAX_LOCAL_VARIABLE_STRING_LEN 256
+int CServiceMain::mas_client_get_audio_source_type(int pid, char** type)
+{
+ MAS_LOGD("[Enter] pid(%d)", pid);
+
+ if (NULL == type) return -1;
+
+ static char cached[MAX_LOCAL_VARIABLE_STRING_LEN] = {'\0'};
+ int ret = mServicePlugin.get_recording_audio_source_type(type);
+ if (0 != ret){
+ MAS_LOGE("[ERROR] Fail to get recording audio source type, ret(%d)", ret);
+ *type = cached;
+ } else if (*type) {
+ strncpy(cached, *type, MAX_LOCAL_VARIABLE_STRING_LEN - 1);
+ cached[MAX_LOCAL_VARIABLE_STRING_LEN - 1] = '\0';
+ }
+
+ return ret;
+}
+
+int CServiceMain::mas_client_send_preprocessing_information(int pid)
+{
+ int ret = -1;
+ MAS_LOGD("[Enter] pid(%d)", pid);
+
+ char* vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
+ MAS_LOGD("preprocessing_assistant_appid : %s", vconf_str);
+ if (vconf_str) {
+ ret = mServiceIpc.send_preprocessing_information(pid, vconf_str);
+ free(vconf_str);
+ vconf_str = NULL;
+ }
+
+ return ret;
+}
+
+int CServiceMain::mas_client_send_voice_key_status_change(int pid, ma_voice_key_status_e status)
+{
+ int ret = -1;
+ MAS_LOGD("[Enter] pid(%d)", pid);
+
+ ret = mServiceIpc.voice_key_status_change(pid, status);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to send voice key status changed information, ret(%d)", ret);
+ }
+ mLastVoiceKeyStatus = status;
+
+ return ret;
+}
+
+int CServiceMain::mas_client_activate(int pid)
+{
+ int ret = -1;
+ MAS_LOGD("[Enter] pid(%d)", pid);
+
+ ret = mServiceIpc.active_state_change(pid, MA_ACTIVE_STATE_ACTIVE);
+
+ return ret;
+}
+
+int CServiceMain::mas_client_deactivate(int pid)
+{
+ int ret = -1;
+ MAS_LOGD("[Enter] pid(%d)", pid);
+
+ ret = mServiceIpc.active_state_change(pid, MA_ACTIVE_STATE_INACTIVE);
+
+ return ret;
+}
+
+int CServiceMain::mas_client_send_asr_result(int pid, int event, char* asr_result)
+{
+ MAS_LOGD("[Enter] pid(%d), event(%d), asr_result(%s)", pid, event, asr_result);
+ int ret = mServiceIpc.masc_ui_dbus_send_asr_result(pid, event, asr_result);
+ if (0 != ret){
+ MAS_LOGE("[ERROR] Fail to send asr result, ret(%d)", ret);
+ }
+
+ // if final event is , launch assistant app which is invoked with wakeup word.
+ /* TO_DO */
+ return ret;
+}
+
+int CServiceMain::mas_client_send_result(int pid, char* display_text, char* utterance_text, char* result_json)
+{
+ MAS_LOGD("[Enter] pid(%d), display_text(%s), utterance_text(%s), result_json(%s)", pid, display_text, utterance_text, result_json);
+ int ret = mServiceIpc.masc_ui_dbus_send_result(pid, display_text, utterance_text, result_json);
+ if (0 != ret){
+ MAS_LOGE("[ERROR] Fail to send result, ret(%d)", ret);
+ }
+
+ const char* pid_appid = NULL;
+ char buf[MAX_APPID_LEN] = {'\0', };
+ if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) {
+ buf[MAX_APPID_LEN - 1] = '\0';
+ pid_appid = buf;
+ }
+ mServicePlugin.update_recognition_result(pid_appid, MA_RECOGNITION_RESULT_EVENT_SUCCESS);
+
+ return ret;
+}
+
+int CServiceMain::mas_client_send_recognition_result(int pid, int result)
+{
+ MAS_LOGD("[Enter] pid(%d), result(%d)", pid, result);
+ int ret = mServiceIpc.masc_ui_dbus_send_recognition_result(pid, result);
+ if (0 != ret){
+ MAS_LOGE("[ERROR] Fail to send recognition result, ret(%d)", ret);
+ }
+
+ const char* pid_appid = NULL;
+ char buf[MAX_APPID_LEN] = {'\0', };
+ if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) {
+ buf[MAX_APPID_LEN - 1] = '\0';
+ pid_appid = buf;
+ }
+ mServicePlugin.update_recognition_result(pid_appid, result);
+
+ return ret;
+}
+
+int CServiceMain::mas_client_start_streaming_audio_data(int pid, int type)
+{
+ int ret = -1;
+ switch(type) {
+ case MA_AUDIO_STREAMING_DATA_TYPE_CURRENT_UTTERANCE:
+ ret = mServicePlugin.start_streaming_utterance_data();
+ mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED);
+ break;
+ case MA_AUDIO_STREAMING_DATA_TYPE_PREVIOUS_UTTERANCE:
+ ret = mServicePlugin.start_streaming_previous_utterance_data();
+ /* Preprocessing is not required for previous utterance streaming */
+ break;
+ case MA_AUDIO_STREAMING_DATA_TYPE_FOLLOW_UP_SPEECH:
+ ret = mServicePlugin.start_streaming_follow_up_data();
+ mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED);
+ break;
+ }
+ return ret;
+}
+
+int CServiceMain::mas_client_stop_streaming_audio_data(int pid, int type)
+{
+ int ret = -1;
+ switch(type) {
+ case MA_AUDIO_STREAMING_DATA_TYPE_CURRENT_UTTERANCE:
+ ret = mServicePlugin.stop_streaming_utterance_data();
+ break;
+ case MA_AUDIO_STREAMING_DATA_TYPE_PREVIOUS_UTTERANCE:
+ ret = mServicePlugin.stop_streaming_previous_utterance_data();
+ break;
+ case MA_AUDIO_STREAMING_DATA_TYPE_FOLLOW_UP_SPEECH:
+ ret = mServicePlugin.stop_streaming_follow_up_data();
+ break;
+ }
+ return ret;
+}
+
+int CServiceMain::mas_client_update_voice_feedback_state(int pid, int state)
+{
+ const char* pid_appid = NULL;
+ char buf[MAX_APPID_LEN] = {'\0', };
+ if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) {
+ buf[MAX_APPID_LEN - 1] = '\0';
+ pid_appid = buf;
+ }
+ mServicePlugin.update_voice_feedback_state(pid_appid, state);
+ return 0;
+}
+
+int CServiceMain::mas_client_set_assistant_specific_command(int pid, const char *command)
+{
+ const char* pid_appid = NULL;
+ char buf[MAX_APPID_LEN] = {'\0', };
+ if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) {
+ buf[MAX_APPID_LEN - 1] = '\0';
+ pid_appid = buf;
+ }
+ mServicePlugin.set_assistant_specific_command(pid_appid, command);
+ return 0;
+}
+
+int CServiceMain::mas_client_set_background_volume(int pid, double ratio)
+{
+ const char* pid_appid = NULL;
+ char buf[MAX_APPID_LEN] = {'\0', };
+ if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) {
+ buf[MAX_APPID_LEN - 1] = '\0';
+ pid_appid = buf;
+ }
+ mServicePlugin.set_background_volume(pid_appid, ratio);
+ return 0;
+}
+
+int CServiceMain::mas_client_set_preprocessing_allow_mode(int pid, ma_preprocessing_allow_mode_e mode, const char* appid)
+{
+ const char* pid_appid = NULL;
+ char buf[MAX_APPID_LEN] = {'\0', };
+ if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) {
+ buf[MAX_APPID_LEN - 1] = '\0';
+ pid_appid = buf;
+ }
+
+ for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+ if (g_maclient_info[loop].used) {
+ if (pid_appid && strncmp(pid_appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
+ g_maclient_info[loop].preprocessing_allow_mode = mode;
+ if (appid) {
+ strncpy(g_maclient_info[loop].preprocessing_allow_appid, appid, MAX_APPID_LEN);
+ g_maclient_info[loop].preprocessing_allow_appid[MAX_APPID_LEN - 1] = '\0';
+ } else {
+ g_maclient_info[loop].preprocessing_allow_appid[0] = '\0';
+ }
+ }
+ }
+ }
+
+ mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_ALLOW_MODE_CHANGED);
+
+ return 0;
+}
+
+int CServiceMain::mas_client_send_preprocessing_result(int pid, bool result)
+{
+ const char* pid_appid = NULL;
+ char buf[MAX_APPID_LEN] = {'\0', };
+ if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) {
+ buf[MAX_APPID_LEN - 1] = '\0';
+ pid_appid = buf;
+ }
+ if (!is_current_preprocessing_assistant(pid_appid)) return -1;
+
+ const char *current_maclient_appid = NULL;
+ if (g_current_maclient_info >= 0 && g_current_maclient_info < MAX_MACLIENT_INFO_NUM) {
+ current_maclient_appid = g_maclient_info[g_current_maclient_info].appid;
+ }
+
+ if (result) {
+ MAS_LOGD("Preprocessing succeeded, bring (%s) to foreground", pid_appid);
+ mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_SUCCEEDED);
+ } else {
+ MAS_LOGD("Preprocessing failed, bring (%s) to foreground", current_maclient_appid);
+ mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_FAILED);
+ }
+
+ ma_client_s* client = ma_client_find_by_appid(current_maclient_appid);
+ if (client) {
+ mServiceIpc.send_preprocessing_result(client->pid, result);
+ }
+
+ return 0;
+}
+
+int CServiceMain::mas_client_set_wake_word_audio_require_flag(int pid, bool require)
+{
+ const char* pid_appid = NULL;
+ char buf[MAX_APPID_LEN] = {'\0', };
+ if (AUL_R_OK == aul_app_get_appid_bypid(pid, buf, sizeof(buf))) {
+ buf[MAX_APPID_LEN - 1] = '\0';
+ pid_appid = buf;
+ }
+
+ mServicePlugin.set_wake_word_audio_require_flag(pid_appid, require);
+ return 0;
+}
+
+int CServiceMain::mas_client_set_assistant_language(int pid, const char* language)
+{
+ const char* pid_appid = NULL;
+ char buf[MAX_APPID_LEN] = {'\0', };
+ int ret = aul_app_get_appid_bypid(pid, buf, sizeof(buf));
+ if (AUL_R_OK == ret) {
+ buf[MAX_APPID_LEN - 1] = '\0';
+ pid_appid = buf;
+ }
+
+ mServicePlugin.set_assistant_language(pid_appid, language);
+ return 0;
+}
+
+int CServiceMain::mas_client_add_wake_word(int pid, const char* wake_word, const char* language)
+{
+ const char* pid_appid = NULL;
+ char buf[MAX_APPID_LEN] = {'\0', };
+ int ret = aul_app_get_appid_bypid(pid, buf, sizeof(buf));
+ if (AUL_R_OK == ret) {
+ buf[MAX_APPID_LEN - 1] = '\0';
+ pid_appid = buf;
+ }
+
+ for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+ if (g_maclient_info[loop].used &&
+ 0 == strncmp(buf, g_maclient_info[loop].appid, MAX_APPID_LEN)) {
+ ret = mServiceConfig.add_custom_wake_word(wake_word, language,
+ g_maclient_info[loop].wakeup_word,
+ g_maclient_info[loop].wakeup_language);
+ if (0 == ret) {
+ mServiceConfig.save_custom_wake_words(pid_appid,
+ g_maclient_info[loop].wakeup_word,
+ g_maclient_info[loop].wakeup_language);
+ } else {
+ LOGE("add new wake word failed!");
+ return -1;
+ }
+ }
+ }
+
+ mServicePlugin.add_assistant_wakeup_word(pid_appid, wake_word, language);
+ return 0;
+}
+
+int CServiceMain::mas_client_remove_wake_word(int pid, const char* wake_word, const char* language)
+{
+ const char* pid_appid = NULL;
+ char buf[MAX_APPID_LEN] = {'\0', };
+ int ret = aul_app_get_appid_bypid(pid, buf, sizeof(buf));
+ if (AUL_R_OK == ret) {
+ buf[MAX_APPID_LEN - 1] = '\0';
+ pid_appid = buf;
+ }
+
+ for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+ if (g_maclient_info[loop].used &&
+ 0 == strncmp(buf, g_maclient_info[loop].appid, MAX_APPID_LEN)) {
+ ret = mServiceConfig.remove_custom_wake_word(wake_word, language,
+ g_maclient_info[loop].wakeup_word,
+ g_maclient_info[loop].wakeup_language);
+ if (0 == ret) {
+ mServiceConfig.save_custom_wake_words(pid_appid,
+ g_maclient_info[loop].wakeup_word,
+ g_maclient_info[loop].wakeup_language);
+ }
+ }
+ }
+
+ mServicePlugin.remove_assistant_wakeup_word(pid_appid, wake_word, language);
+ return 0;
+}
+
+int CServiceMain::mas_ui_client_initialize(int pid)
+{
+ MAS_LOGD("[Enter] pid(%d)", pid);
+
+ return 0;
+}
+
+int CServiceMain::mas_ui_client_deinitialize(int pid)
+{
+ MAS_LOGD("[Enter] pid(%d)", pid);
+
+ return 0;
+}
+
+int CServiceMain::mas_ui_client_change_assistant(const char* appid)
+{
+ MAS_LOGD("[Enter]");
+
+ if (NULL == appid) {
+ MAS_LOGE("NULL parameter");
+ return -1;
+ }
+
+ bool use_custom_ui = mas_get_client_custom_ui_option_by_appid(appid);
+ mServiceIpc.masc_ui_dbus_enable_common_ui(!use_custom_ui);
+
+ mas_set_current_client_by_appid(appid);
+ int pid = mas_get_client_pid_by_appid(appid);
+ if (pid != -1) {
+ mas_bring_client_to_foreground(appid);
+ mas_client_send_preprocessing_information(pid);
+ if (MA_VOICE_KEY_STATUS_PRESSED == mLastVoiceKeyStatus) {
+ mas_client_send_voice_key_status_change(pid, mLastVoiceKeyStatus);
+ }
+
+ mas_client_activate(pid);
+ MAS_LOGD("MA Client with appid %s exists, requesting speech data", (appid ? appid : "NULL"));
+ /*
+ int ret = mServicePlugin.start_streaming_utterance_data();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to start streaming utterance data(%d)", ret);
+ }
+ */
+ } else {
+ // Appropriate MA Client not available, trying to launch new one
+ MAS_LOGD("MA Client with appid %s does not exist, launching client", (appid ? appid : "NULL"));
+
+ /* The appid parameter might not exist after this function call, so we use appid string in our g_maclient_info */
+ for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+ if (g_maclient_info[loop].used &&
+ 0 < strlen(g_maclient_info[loop].appid) &&
+ 0 < strlen(g_maclient_info[loop].wakeup_word[0])) {
+ if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
+ mas_launch_client_by_appid(g_maclient_info[loop].appid, CLIENT_LAUNCH_MODE_ACTIVATION);
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int mas_assistant_info_cb(ma_assistant_info_s* info, void* user_data) {
+ int ret = -1;
+ CServiceMain* service_main = static_cast<CServiceMain*>(user_data);
+ if (service_main) {
+ ret = service_main->add_assistant_info(info);
+ }
+ return ret;
+}
+
+int CServiceMain::add_assistant_info(ma_assistant_info_s* info) {
+ MAS_LOGD("__mas_assistant_info_cb called");
+
+ if (NULL == info) {
+ MAS_LOGE("info NULL, returning");
+ return -1;
+ }
+ if (NULL == info->app_id) {
+ MAS_LOGE("app_id NULL, returning");
+ return -1;
+ }
+
+ int index = -1;
+ int loop = 0;
+ while(-1 == index && loop < MAX_MACLIENT_INFO_NUM) {
+ if (false == g_maclient_info[loop].used) {
+ index = loop;
+ }
+ loop++;
+ }
+ if (-1 != index) {
+ g_maclient_info[index].used = true;
+ g_maclient_info[index].preprocessing_allow_mode = MA_PREPROCESSING_ALLOW_NONE;
+ g_maclient_info[index].preprocessing_allow_appid[0] = '\0';
+ MAS_LOGD("app_id(%s)", info->app_id);
+ strncpy(g_maclient_info[index].appid, info->app_id, MAX_APPID_LEN);
+ g_maclient_info[index].appid[MAX_APPID_LEN - 1] = '\0';
+
+ if (is_current_preprocessing_assistant(g_maclient_info[index].appid)) {
+ g_current_preprocessing_maclient_info = index;
+ }
+
+ for (loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) {
+ if (loop < info->cnt_wakeup && info->wakeup_list[loop]) {
+ MAS_LOGD("wakeup_list(%d)(%s)(%s)", loop, info->wakeup_list[loop], info->wakeup_language[loop]);
+ strncpy(g_maclient_info[index].wakeup_word[loop], info->wakeup_list[loop], MAX_WAKEUP_WORD_LEN);
+ g_maclient_info[index].wakeup_word[loop][MAX_WAKEUP_WORD_LEN - 1] = '\0';
+ if (info->wakeup_language[loop]) {
+ strncpy(g_maclient_info[index].wakeup_language[loop], info->wakeup_language[loop], MAX_SUPPORTED_LANGUAGE_LEN);
+ g_maclient_info[index].wakeup_language[loop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
+ } else {
+ strncpy(g_maclient_info[index].wakeup_language[loop], "", MAX_SUPPORTED_LANGUAGE_LEN);
+ }
+ } else {
+ strncpy(g_maclient_info[index].wakeup_word[loop], "", MAX_WAKEUP_WORD_LEN);
+ }
+ }
+
+ for (loop = 0;loop < MAX_SUPPORTED_LANGUAGES_NUM;loop++) {
+ if (loop < info->cnt_lang && info->supported_lang[loop]) {
+ MAS_LOGD("supported_lang(%d)(%s)", loop, info->supported_lang[loop]);
+ strncpy(g_maclient_info[index].supported_language[loop], info->supported_lang[loop], MAX_SUPPORTED_LANGUAGE_LEN);
+ g_maclient_info[index].supported_language[loop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
+ } else {
+ strncpy(g_maclient_info[index].supported_language[loop], "", MAX_SUPPORTED_LANGUAGE_LEN);
+ }
+ }
+
+ MAS_LOGD("wakeup_engine(%s)", info->wakeup_engine);
+ if (info->wakeup_engine) {
+ strncpy(g_maclient_info[index].wakeup_engine, info->wakeup_engine, MAX_APPID_LEN);
+ g_maclient_info[index].wakeup_engine[MAX_APPID_LEN - 1] = '\0';
+ } else {
+ g_maclient_info[index].wakeup_engine[0] = '\0';
+ MAS_LOGW("Wakeup engine information not provided for : %s", info->app_id);
+ }
+ g_maclient_info[index].custom_ui_option = info->custom_ui_option;
+
+ MAS_LOGD("voice_key_support_mode(%d)", info->voice_key_support_mode);
+ g_maclient_info[index].voice_key_support_mode = info->voice_key_support_mode;
+ MAS_LOGD("voice_key_tap_duration(%f)", info->voice_key_tap_duration);
+ g_maclient_info[index].voice_key_tap_duration = info->voice_key_tap_duration;
+ } else {
+ MAS_LOGD("Couldn't find an empty slot for storing assistant info");
+ }
+
+ MAS_LOGD("__mas_assistant_info_cb end");
+
+ return 0;
+}
+
+static void active_state_changed_cb(keynode_t* key, void* data)
+{
+ int vconf_value = 0;
+ if (vconf_get_bool(MULTI_ASSISTANT_SETTINGS_ACTIVATED, &vconf_value) == 0) {
+ MAS_LOGD("multi-assistant active state : %d\n", vconf_value);
+
+ CServicePlugin *plugin = nullptr;
+ if (g_service_main) {
+ plugin = g_service_main->get_service_plugin();
+ }
+ if (plugin) {
+ if (vconf_value) {
+ plugin->activate();
+ } else {
+ plugin->deactivate();
+ }
+ } else {
+ MAS_LOGE("Could not change plugin state : %p %p", g_service_main, plugin);
+ }
+ }
+}
+
+int CServiceMain::initialize_service_plugin(void)
+{
+ if (0 != mServicePlugin.initialize()) {
+ MAS_LOGE("Fail to ws intialize");
+ return -1;
+ }
+
+ if (0 != mServicePlugin.set_language(g_current_lang.c_str())) {
+ MAS_LOGE("Fail to ws set language");
+ return -1;
+ }
+
+ if (0 == mServiceConfig.get_assistant_info(mas_assistant_info_cb, this)) {
+ for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+ int inner_loop;
+ if (g_maclient_info[loop].used &&
+ 0 < strlen(g_maclient_info[loop].appid)) {
+ mServiceConfig.load_custom_wake_words(g_maclient_info[loop].appid,
+ g_maclient_info[loop].wakeup_word, g_maclient_info[loop].wakeup_language);
+ if (0 < strlen(g_maclient_info[loop].wakeup_engine)) {
+ mServicePlugin.set_assistant_wakeup_engine(
+ g_maclient_info[loop].appid,
+ g_maclient_info[loop].wakeup_engine);
+ }
+ for (inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
+ if (0 < strlen(g_maclient_info[loop].wakeup_word[inner_loop])) {
+ MAS_LOGD("Registering wakeup word %s for app %s",
+ g_maclient_info[loop].wakeup_word[inner_loop], g_maclient_info[loop].appid);
+ if (0 != mServicePlugin.add_assistant_wakeup_word(
+ g_maclient_info[loop].appid,
+ g_maclient_info[loop].wakeup_word[inner_loop],
+ g_maclient_info[loop].wakeup_language[inner_loop])) {
+ MAS_LOGE("Fail to add assistant's wakeup word");
+ }
+ }
+ }
+ for (inner_loop = 0; inner_loop < MAX_SUPPORTED_LANGUAGE_NUM; inner_loop++) {
+ if (0 < strlen(g_maclient_info[loop].supported_language[inner_loop])) {
+ MAS_LOGD("Adding language %s for app %s",
+ g_maclient_info[loop].supported_language[inner_loop], g_maclient_info[loop].appid);
+ if (0 != mServicePlugin.add_assistant_language(
+ g_maclient_info[loop].appid,
+ g_maclient_info[loop].supported_language[inner_loop])) {
+ MAS_LOGE("Fail to add assistant's language");
+ }
+ }
+ }
+ }
+ }
+ } else {
+ MAS_LOGE("Fail to load assistant info");
+ }
+
+ if (0 != mServicePlugin.set_callbacks()) {
+ MAS_LOGE("Fail to set callbacks");
+ return -1;
+ }
+
+ return 0;
+}
+
+int CServiceMain::deinitialize_service_plugin(void)
+{
+ MAS_LOGI("[ENTER]");
+ if (0 != mServicePlugin.deactivate()) {
+ MAS_LOGE("Fail to deactivate");
+ }
+ if (0 != mServicePlugin.deinitialize()) {
+ MAS_LOGE("Fail to deinitialize");
+ }
+ MAS_LOGI("[END]");
+ return 0;
+}
+
+int CServiceMain::process_activated_setting()
+{
+ if (0 == vconf_notify_key_changed(MULTI_ASSISTANT_SETTINGS_ACTIVATED, active_state_changed_cb, NULL)) {
+ /* Activate / deactivate according to the vconf key setting */
+ active_state_changed_cb(NULL, NULL);
+ } else {
+#ifdef ENABLE_MULTI_ASSISTANT_BY_DEFAULT
+ /* Multi-assistant needs to be enabled by default, unless disabled explicitly */
+ mServicePlugin.activate();
+ const char *default_assistant = NULL;
+ if (0 == mServicePlugin.get_default_assistant(&default_assistant)) {
+ if (NULL == default_assistant) {
+ if (g_maclient_info[0].used) {
+ default_assistant = g_maclient_info[0].appid;
+ MAS_LOGW("No default assistant, setting %s as default", default_assistant);
+ mServicePlugin.set_default_assistant(default_assistant);
+ } else {
+ MAS_LOGE("No default assistant, and no assistant installed");
+ }
+ }
+ }
+#endif
+ }
+ return 0;
+}
+
+int CServiceMain::mas_get_current_client_pid()
+{
+ int ret = -1;
+ if (g_current_maclient_info >= 0 && g_current_maclient_info < MAX_MACLIENT_INFO_NUM) {
+ const char *appid = g_maclient_info[g_current_maclient_info].appid;
+ ma_client_s* client = ma_client_find_by_appid(appid);
+ if (client) {
+ ret = client->pid;
+ }
+ }
+ return ret;
+}
+
+int CServiceMain::mas_get_current_preprocessing_client_pid()
+{
+ int ret = -1;
+ if (g_current_preprocessing_maclient_info >= 0 && g_current_preprocessing_maclient_info < MAX_MACLIENT_INFO_NUM) {
+ const char *appid = g_maclient_info[g_current_preprocessing_maclient_info].appid;
+ ma_client_s* client = ma_client_find_by_appid(appid);
+ if (client) {
+ ret = client->pid;
+ }
+ }
+ return ret;
+}
+
+int CServiceMain::mas_get_client_pid_by_appid(const char *appid)
+{
+ int ret = -1;
+
+ if (appid) {
+ ma_client_s *client = NULL;
+ client = ma_client_find_by_appid(appid);
+ if (client) {
+ ret = client->pid;
+ }
+ }
+
+ int status = aul_app_get_status_bypid(ret);
+ if (-1 != ret && 0 > status) {
+ MAS_LOGE("The PID for %s was %d, but it seems to be terminated : %d",
+ (appid ? appid : "NULL"), ret, status);
+ mas_client_deinitialize(ret);
+ ret = -1;
+ }
+
+ return ret;
+}
+
+const char* CServiceMain::mas_get_client_appid_by_pid(int pid)
+{
+ const char* ret = NULL;
+
+ ma_client_s *client = NULL;
+ client = ma_client_find_by_pid(pid);
+ if (client) {
+ ret = client->appid;
+ }
+
+ int status = aul_app_get_status_bypid(pid);
+ if (NULL != ret && 0 > status) {
+ MAS_LOGE("The appid for %d was %s, but it seems to be terminated : %d",
+ pid, (ret ? ret : "NULL"), status);
+ mas_client_deinitialize(pid);
+ ret = NULL;
+ }
+
+ return ret;
+}
+
+bool CServiceMain::mas_get_client_custom_ui_option_by_appid(const char *appid)
+{
+ bool ret = false;
+ for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+ if (g_maclient_info[loop].used &&
+ 0 < strlen(g_maclient_info[loop].appid) &&
+ 0 < strlen(g_maclient_info[loop].wakeup_word[0])) {
+ if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
+ ret = g_maclient_info[loop].custom_ui_option;
+ }
+ }
+ }
+ return ret;
+}
+
+int CServiceMain::mas_get_client_pid_by_wakeup_word(const char *wakeup_word)
+{
+ const char *appid = mas_get_client_appid_by_wakeup_word(wakeup_word);
+ return mas_get_client_pid_by_appid(appid);
+}
+
+const char* CServiceMain::mas_get_client_appid_by_wakeup_word(const char *wakeup_word)
+{
+ int loop;
+ const char *appid = NULL;
+
+ if (NULL == wakeup_word) return NULL;
+
+ for (loop = 0; loop < MAX_MACLIENT_INFO_NUM && NULL == appid; loop++) {
+ if (g_maclient_info[loop].used &&
+ 0 < strlen(g_maclient_info[loop].appid)) {
+ for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
+ if (0 < strlen(g_maclient_info[loop].wakeup_word[inner_loop])) {
+ if (0 == strncmp(wakeup_word, g_maclient_info[loop].wakeup_word[inner_loop], MAX_WAKEUP_WORD_LEN)) {
+ appid = g_maclient_info[loop].appid;
+ }
+ }
+ }
+ }
+ }
+
+ /* Perform extended search, by eliminating blank characters */
+ if (NULL == appid) {
+ for (loop = 0; loop < MAX_MACLIENT_INFO_NUM && NULL == appid; loop++) {
+ if (g_maclient_info[loop].used &&
+ 0 < strlen(g_maclient_info[loop].appid)) {
+ for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
+ if (0 < strlen(g_maclient_info[loop].wakeup_word[inner_loop])) {
+ char comparand[MAX_WAKEUP_WORD_LEN];
+ int comparand_index = 0;
+ for (int index = 0; index < MAX_WAKEUP_WORD_LEN; index++) {
+ if (' ' != g_maclient_info[loop].wakeup_word[inner_loop][index]) {
+ comparand[comparand_index++] = g_maclient_info[loop].wakeup_word[inner_loop][index];
+ }
+ }
+ if (0 == strncmp(wakeup_word, comparand, MAX_WAKEUP_WORD_LEN)) {
+ appid = g_maclient_info[loop].appid;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return appid;
+}
+
+int CServiceMain::mas_set_current_client_by_wakeup_word(const char *wakeup_word)
+{
+ int loop;
+ int ret = -1;
+ int prev_selection = g_current_maclient_info;
+
+ for (loop = 0; loop < MAX_MACLIENT_INFO_NUM && -1 == ret; loop++) {
+ if (g_maclient_info[loop].used &&
+ 0 < strlen(g_maclient_info[loop].appid)) {
+ for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
+ if (0 < strlen(g_maclient_info[loop].wakeup_word[inner_loop])) {
+ if (0 == strncmp(wakeup_word, g_maclient_info[loop].wakeup_word[inner_loop], MAX_WAKEUP_WORD_LEN)) {
+ g_current_maclient_info = loop;
+ ret = 0;
+ }
+ }
+ }
+ }
+ }
+ /* Perform extended search, by eliminating blank characters */
+ if (ret == -1) {
+ for (loop = 0; loop < MAX_MACLIENT_INFO_NUM && -1 == ret; loop++) {
+ if (g_maclient_info[loop].used &&
+ 0 < strlen(g_maclient_info[loop].appid)) {
+ for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
+ if (0 < strlen(g_maclient_info[loop].wakeup_word[inner_loop])) {
+ char comparand[MAX_WAKEUP_WORD_LEN];
+ int comparand_index = 0;
+ for (int index = 0; index < MAX_WAKEUP_WORD_LEN; index++) {
+ if (' ' != g_maclient_info[loop].wakeup_word[inner_loop][index]) {
+ comparand[comparand_index++] = g_maclient_info[loop].wakeup_word[inner_loop][index];
+ }
+ }
+ if (0 == strncmp(wakeup_word, comparand, MAX_WAKEUP_WORD_LEN)) {
+ g_current_maclient_info = loop;
+ ret = 0;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (g_current_maclient_info != prev_selection) {
+ if (prev_selection >= 0 && prev_selection < MAX_MACLIENT_INFO_NUM) {
+ mas_client_deactivate(mas_get_client_pid_by_appid(g_maclient_info[prev_selection].appid));
+ }
+ }
+
+ return ret;
+}
+
+int CServiceMain::mas_set_current_client_by_appid(const char *appid)
+{
+ int ret = -1;
+ int prev_selection = g_current_maclient_info;
+
+ for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+ if (g_maclient_info[loop].used &&
+ 0 < strlen(g_maclient_info[loop].appid) &&
+ 0 < strlen(g_maclient_info[loop].wakeup_word[0])) {
+ if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
+ g_current_maclient_info = loop;
+ ret = 0;
+ }
+ }
+ }
+
+ if (g_current_maclient_info != prev_selection) {
+ if (prev_selection >= 0 && prev_selection < MAX_MACLIENT_INFO_NUM) {
+ mas_client_deactivate(mas_get_client_pid_by_appid(g_maclient_info[prev_selection].appid));
+ }
+ }
+
+ return ret;
+}
+
+int CServiceMain::mas_launch_client_by_appid(const char *appid, CLIENT_LAUNCH_MODE launch_mode)
+{
+ if (NULL == appid || 0 == strlen(appid)) {
+ MAS_LOGE("appid invalid, failed launching MA Client");
+ return -1;
+ }
+
+ if (CLIENT_LAUNCH_MODE_PRELAUNCH == launch_mode) {
+ if (1 == aul_app_is_running(appid)) {
+ MAS_LOGE("appid %s is already running, no need for a prelaunch", appid);
+ return -1;
+ }
+ }
+
+ bundle *b = NULL;
+ b = bundle_create();
+ if (NULL == b) {
+ MAS_LOGE("Failed creating bundle for aul operation");
+ return -1;
+ }
+
+ int result = aul_svc_set_background_launch(b,
+ (CLIENT_LAUNCH_MODE_PRELAUNCH == launch_mode ? TRUE : FALSE));
+ if (result < AUL_R_OK) {
+ MAS_LOGE("ERROR : aul_svc_set_background_launch failed. app_id [%s] bundle[%p] result[%d : %s]",
+ appid, b, result, get_error_message(result));
+ }
+
+ result = aul_launch_app_async(appid, b);
+ if (result < AUL_R_OK) {
+ MAS_LOGE("ERROR : aul_launch_app_async failed. app_id [%s] bundle[%p] result[%d : %s]",
+ appid, b, result, get_error_message(result));
+ }
+
+ if (CLIENT_LAUNCH_MODE_ACTIVATION == launch_mode) {
+ bool found = false;
+ for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+ if (g_maclient_info[loop].used &&
+ 0 < strlen(g_maclient_info[loop].appid)) {
+ if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
+ g_wakeup_maclient_appid = g_maclient_info[loop].appid;
+ found = true;
+ }
+ }
+ }
+ MAS_LOGD("g_wakeup_maclient_appid : %s, %d", g_wakeup_maclient_appid.c_str(), found);
+ }
+
+ if (b) bundle_free(b);
+ b = NULL;
+
+ return result;
+}
+
+int CServiceMain::mas_bring_client_to_foreground(const char* appid)
+{
+ /* Bring MA client to foreground - is there a better way other than launching? */
+ if (NULL == appid || 0 == strlen(appid)) {
+ MAS_LOGE("appid invalid, failed launching MA Client");
+ return -1;
+ }
+
+ bundle *b = NULL;
+ b = bundle_create();
+ if (NULL == b) {
+ MAS_LOGE("Failed creating bundle for aul operation");
+ return -1;
+ }
+
+ int result = aul_launch_app(appid, b);
+ if (result < AUL_R_OK) {
+ MAS_LOGE("ERROR : aul_launch_app failed. app_id [%s] bundle[%p] result[%d : %s]",
+ appid, b, result, get_error_message(result));
+ }
+
+ if (b) bundle_free(b);
+ b = NULL;
+
+ return result;
+}
+
+int CServiceMain::mas_launch_client_by_wakeup_word(const char *wakeup_word)
+{
+ const char *appid = mas_get_client_appid_by_wakeup_word(wakeup_word);
+ return mas_launch_client_by_appid(appid, CLIENT_LAUNCH_MODE_ACTIVATION);
+}
+
+int CServiceMain::mas_prelaunch_default_assistant()
+{
+ /* CHECK NEEDED : should the code segment below and activation logic above be moved to wakeup manger? */
+ int prelaunch_mode;
+ int res = vconf_get_bool(WAKEUP_SETTINGS_KEY_PRELAUNCH_MODE, &prelaunch_mode);
+ if (0 == res && 0 != prelaunch_mode) {
+ const char *default_assistant = NULL;
+ if (0 == mServicePlugin.get_default_assistant(&default_assistant)) {
+ if (0 == aul_app_is_running(default_assistant)) {
+ MAS_LOGD("prelaunching default_assistant_appid : %s", default_assistant);
+ mas_launch_client_by_appid(default_assistant, CLIENT_LAUNCH_MODE_PRELAUNCH);
+ }
+ }
+ }
+ return 0;
+}
+
+int CServiceMain::mas_update_voice_key_support_mode()
+{
+ /* CHECK NEEDED : should the code segment below and activation logic above be moved to wakeup manger? */
+ bool successful = false;
+ const char *default_assistant = NULL;
+ if (0 == mServicePlugin.get_default_assistant(&default_assistant)) {
+ for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+ if (g_maclient_info[loop].used) {
+ if (default_assistant &&
+ strncmp(default_assistant, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
+ float duration = g_maclient_info[loop].voice_key_tap_duration;
+ if (0.0f < duration) {
+ mServicePlugin.set_voice_key_tap_duration(duration);
+ } else {
+ mServicePlugin.unset_voice_key_tap_duration();
+ }
+ mServicePlugin.set_voice_key_support_mode(
+ g_maclient_info[loop].voice_key_support_mode);
+ successful = true;
+ }
+ }
+ }
+ }
+
+ if (!successful) {
+ mServicePlugin.unset_voice_key_tap_duration();
+ mServicePlugin.set_voice_key_support_mode(VOICE_KEY_SUPPORT_MODE_NONE);
+ }
+ return 0;
+}
+
+ma_preprocessing_allow_mode_e CServiceMain::get_preprocessing_allow_mode(const char* appid)
+{
+ for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+ if (appid && g_maclient_info[loop].used) {
+ if (strncmp(appid, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) {
+ return g_maclient_info[loop].preprocessing_allow_mode;
+ }
+ }
+ }
+ return MA_PREPROCESSING_ALLOW_NONE;
+}
+
+/* This might need to be read from settings in the future, but using macro for now */
+//#define BRING_PREPROCESSING_ASSISTANT_TO_FRONT
+
+int CServiceMain::mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event)
+{
+ const char* current_maclient_appid = NULL;
+ const char* preprocessing_allow_appid = NULL;
+ if (g_current_maclient_info >= 0 && g_current_maclient_info < MAX_MACLIENT_INFO_NUM) {
+ current_maclient_appid = g_maclient_info[g_current_maclient_info].appid;
+ preprocessing_allow_appid = g_maclient_info[g_current_maclient_info].preprocessing_allow_appid;
+ }
+ ma_preprocessing_allow_mode_e mode = get_preprocessing_allow_mode(current_maclient_appid);
+
+ switch (event) {
+ case PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED:
+ {
+#ifndef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
+ /* If there is no need to bring preprocessing assistant to front,
+ current_maclient should always be brought to front */
+ mas_bring_client_to_foreground(current_maclient_appid);
+#endif
+ g_current_preprocessing_state = PREPROCESSING_STATE_WAKEUP_PREPROCESS_DISABLED;
+ if (check_preprocessing_assistant_exists()) {
+ if (MA_PREPROCESSING_ALLOW_UTTERANCE == mode ||
+ MA_PREPROCESSING_ALLOW_ALL == mode) {
+ if (is_current_preprocessing_assistant(preprocessing_allow_appid)) {
+ g_current_preprocessing_state = PREPROCESSING_STATE_WAKEUP_PREPROCESS_ENABLED;
+ }
+ }
+ } else {
+#ifdef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
+ /* If preprocessing assistant does not exist, there is no way to enable
+ preprocessing assistant, so bring current maclient to front right away */
+ mas_bring_client_to_foreground(current_maclient_appid);
+#endif
+ }
+ }
+ break;
+ case PREPROCESSING_STATE_EVENT_PREPROCESSING_ALLOW_MODE_CHANGED:
+ {
+ g_current_preprocessing_state = PREPROCESSING_STATE_WAKEUP_PREPROCESS_DISABLED;
+ /* Enable preprocessing mode only if the preprocessing assistant exists */
+ if (check_preprocessing_assistant_exists()) {
+ if (MA_PREPROCESSING_ALLOW_UTTERANCE == mode ||
+ MA_PREPROCESSING_ALLOW_ALL == mode) {
+ if (is_current_preprocessing_assistant(preprocessing_allow_appid)) {
+ g_current_preprocessing_state = PREPROCESSING_STATE_WAKEUP_PREPROCESS_ENABLED;
+ }
+ }
+ }
+ }
+ break;
+ case PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED:
+ {
+ if (PREPROCESSING_STATE_WAKEUP_PREPROCESS_ENABLED == g_current_preprocessing_state) {
+ g_current_preprocessing_state = PREPROCESSING_STATE_PREPROCESSING_UTTERANCE;
+ } else if (PREPROCESSING_STATE_WAKEUP_PREPROCESS_DISABLED == g_current_preprocessing_state) {
+ /* If preprocessing assistant does not exist, the current_maclient
+ would have been brought to front already on wakeup event */
+#ifdef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
+ if (check_preprocessing_assistant_exists()) {
+ mas_bring_client_to_foreground(current_maclient_appid);
+ }
+#endif
+ g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
+ }
+ }
+ break;
+ case PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED:
+ {
+ g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
+ if (check_preprocessing_assistant_exists()) {
+ if (MA_PREPROCESSING_ALLOW_FOLLOW_UP == mode ||
+ MA_PREPROCESSING_ALLOW_ALL == mode) {
+ g_current_preprocessing_state = PREPROCESSING_STATE_PREPROCESSING_FOLLOW_UP;
+ }
+ }
+ }
+ break;
+ case PREPROCESSING_STATE_EVENT_PREPROCESSING_SUCCEEDED:
+ {
+#ifdef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
+ if (PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED == g_current_preprocessing_state ||
+ PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED == g_current_preprocessing_state) {
+ char* vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
+ MAS_LOGD("preprocessing_assistant_appid : %s", vconf_str);
+ if (vconf_str) {
+ mas_bring_client_to_foreground(vconf_str);
+ free(vconf_str);
+ vconf_str = NULL;
+ }
+ }
+#endif
+ g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
+ }
+ break;
+ case PREPROCESSING_STATE_EVENT_PREPROCESSING_FAILED:
+ {
+#ifdef BRING_PREPROCESSING_ASSISTANT_TO_FRONT
+ if (PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED == g_current_preprocessing_state ||
+ PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED == g_current_preprocessing_state) {
+ mas_bring_client_to_foreground(current_maclient_appid);
+ }
+#endif
+ g_current_preprocessing_state = PREPROCESSING_STATE_NONE;
+ }
+ break;
+ }
+ return 0;
+}
+
+int CServiceMain::mas_set_current_service_state(ma_service_state_e state)
+{
+ g_current_service_state = state;
+
+ ma_client_s *data = NULL;
+
+ int count = g_slist_length(g_client_list);
+ int i;
+
+ for (i = 0; i < count; i++) {
+ data = static_cast<ma_client_s*>(g_slist_nth_data(g_client_list, i));
+
+ if (NULL != data && -1 != data->pid) {
+ int ret = mServiceIpc.service_state_change(data->pid, state);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to send wakeup service state change to %d, ret(%d)",
+ data->pid, ret);
+ }
+ }
+ }
+ return 0;
+}
+
+ma_service_state_e CServiceMain::mas_get_current_service_state()
+{
+ return g_current_service_state;
+}
+
+bool CServiceMain::is_valid_wakeup_engine(const char* appid)
+{
+ for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM;loop++) {
+ if (g_maclient_info[loop].used) {
+ LOGD("comparing appid : %s %s", g_maclient_info[loop].wakeup_engine, appid);
+ if (0 == strncmp(g_maclient_info[loop].wakeup_engine, appid, MAX_APPID_LEN)) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+int pkg_app_list_cb(const pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+ if (nullptr == g_service_main) return -1;
+
+ char *appid = NULL;
+
+ int ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
+ if (PMINFO_R_OK == ret && NULL != appid) {
+ int *result = (int*)user_data;
+ if (result) {
+ bool exists = g_service_main->is_valid_wakeup_engine(appid);
+ if (exists) {
+ *result = 1;
+ }
+ }
+ } else {
+ LOGE("pkgmgrinfo_appinfo_get_appid failed! error code=%d", ret);
+ }
+
+ return 0;
+}
+
+/*
+INFO: Package install/update/uninstall scenario
+Install and Uninstall are obviously simple.
+ Install: just INSTALL
+ Uninstall: just UNINSTALL
+Update package (change the source codes and Run As again), there are four scenarios:
+1. UPDATE
+ Source code change
+2. UNINSTALL -> INSTALL
+ This happens when Tizen IDE Property > Tizen SDK > Rapid Development Support > Check "Enable Project specific settings"
+ and change Application ID in tizen-manifest.xml file and Run As.
+3. UPDATE -> INSTALL
+ This happens when Tizen IDE Property > Tizen SDK > Rapid Development Support > Uncheck "Enable Project specific settings"
+ and change Application ID in tizen-manifest.xml file and Run As.
+ At UPDATE event, pkgid (package parameter) is invalid...
+4. UPDATE
+ Exceptionally, only UPDATE can be called when Application ID in tizen-manifest.xml file is changed.
+ At UPDATE event, pkgid (package parameter) is valid, and only appid is changed; the previous appid is invalid.
+*/
+static void _package_manager_event_cb(const char *type, const char *package, package_manager_event_type_e event_type, package_manager_event_state_e event_state, int progress, package_manager_error_e error, void *user_data)
+{
+ CServiceMain* service_main = static_cast<CServiceMain*>(user_data);
+
+ int ret = 0;
+ uid_t uid = getuid();
+ pkgmgrinfo_pkginfo_h handle = NULL;
+ static bool in_progress = false;
+ bool should_exit = false;
+
+ if (!package || !type)
+ return;
+
+ if (PACKAGE_MANAGER_EVENT_TYPE_UPDATE != event_type &&
+ PACKAGE_MANAGER_EVENT_TYPE_INSTALL != event_type &&
+ PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL != event_type)
+ return;
+
+ if (PACKAGE_MANAGER_EVENT_STATE_STARTED != event_state &&
+ PACKAGE_MANAGER_EVENT_STATE_COMPLETED != event_state)
+ return;
+
+ bool user = false;
+ MAS_LOGD("type=%s package=%s event_type=%d event_state=%d progress=%d error=%d",
+ type, package, event_type, event_state, progress, error);
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(package, &handle);
+ if (ret != PMINFO_R_OK || NULL == handle) {
+ MAS_LOGW("Failed to call pkgmgrinfo_pkginfo_get_pkginfo & get_usr_pkginfo(\"%s\",~) returned %d, uid : %d", package, ret, getuid());
+ /* Try to get in user packages */
+ user = true;
+ ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(package, uid, &handle);
+ if (ret != PMINFO_R_OK || NULL == handle) {
+ MAS_LOGW("Failed to call pkgmgrinfo_pkginfo_get_pkginfo & get_usr_pkginfo(\"%s\",~) returned %d, uid : %d", package, ret, getuid());
+ return;
+ }
+ }
+
+ if (user) {
+ /* Try to get in user packages */
+ pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, pkg_app_list_cb, (void *)&ret, uid);
+ } else {
+ /* Try to get in global packages */
+ pkgmgrinfo_appinfo_get_list(handle, PMINFO_ALL_APP, pkg_app_list_cb, (void *)&ret);
+ }
+ if (1 == ret) {
+ if (PACKAGE_MANAGER_EVENT_STATE_STARTED == event_state) {
+ MAS_LOGI("processing PACKAGE_MANAGER_EVENT_STATE_STARTED event : %d", event_type);
+ if (false == in_progress) {
+ in_progress = true;
+ if (service_main) {
+ service_main->deinitialize_service_plugin();
+ } else {
+ MAS_LOGE("service_main is NULL");
+ }
+ }
+ } else if (PACKAGE_MANAGER_EVENT_STATE_COMPLETED == event_state) {
+ MAS_LOGI("processing PACKAGE_MANAGER_EVENT_STATE_COMPLETED event : %d", event_type);
+ if (false == in_progress) {
+ if (service_main) {
+ service_main->deinitialize_service_plugin();
+ } else {
+ MAS_LOGE("service_main is NULL");
+ }
+ }
+ /*
+ if (service_main) {
+ service_main->initialize_service_plugin();
+ service_main->process_activated_setting();
+ } else {
+ MAS_LOGE("service_main is NULL");
+ }
+ */
+ should_exit = true;
+ in_progress = false;
+ }
+ }
+
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+ if (should_exit) {
+ LOGI("Now restarting multi-assistant-service for reloading updated modules");
+ service_app_exit();
+ }
+
+ return;
+}
+
+bool CServiceMain::app_create(void *data)
+{
+ // Todo: add your code here.
+ MAS_LOGD("[Enter] Service app create");
+
+ g_service_main = this;
+
+ mServiceIpc.set_service_main(this);
+
+ mServicePlugin.set_service_ipc(&mServiceIpc);
+ mServicePlugin.set_service_main(this);
+
+ int ret = mServiceIpc.open_connection();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to open connection");
+ }
+
+ initialize_service_plugin();
+
+ process_activated_setting();
+
+ mas_prelaunch_default_assistant();
+ mas_update_voice_key_support_mode();
+
+ /* For the case of preprocessing assistant, it always have to be launched beforehand */
+ char *vconf_str;
+ vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
+ if (vconf_str) {
+ MAS_LOGD("prelaunching preprocessing_assistant_appid : %s", vconf_str);
+ mas_launch_client_by_appid(vconf_str, CLIENT_LAUNCH_MODE_PRELAUNCH);
+ free(vconf_str);
+ vconf_str = NULL;
+ }
+
+ if (!g_pkgmgr) {
+ int ret = package_manager_create(&g_pkgmgr);
+ if (ret == PACKAGE_MANAGER_ERROR_NONE) {
+ ret = package_manager_set_event_cb(g_pkgmgr, _package_manager_event_cb, this);
+ if (ret == PACKAGE_MANAGER_ERROR_NONE) {
+ LOGD("package_manager_set_event_cb succeeded.");
+ } else {
+ LOGE("package_manager_set_event_cb failed(%d)", ret);
+ }
+ } else {
+ LOGE("package_manager_create failed(%d)", ret);
+ }
+ }
+
+ return true;
+}
+
+void CServiceMain::app_terminate(void *data)
+{
+ MAS_LOGI("[ENTER]");
+ if (g_pkgmgr) {
+ package_manager_unset_event_cb(g_pkgmgr);
+ package_manager_destroy(g_pkgmgr);
+ g_pkgmgr = NULL;
+ }
+
+ deinitialize_service_plugin();
+
+ vconf_ignore_key_changed(MULTI_ASSISTANT_SETTINGS_ACTIVATED, active_state_changed_cb);
+
+ int ret = mServiceIpc.close_connection();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to close connection");
+ }
+
+ g_service_main = nullptr;
+
+ MAS_LOGI("[END]");
+ return;
+}
+
--- /dev/null
+/*
+ * Copyright 2018-2019 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * 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.
+ */
+
+#include <tizen.h>
+#include <service_app.h>
+#include <app_manager.h>
+#include <app.h>
+#include <malloc.h>
+#include <Ecore.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <glib.h>
+#include <dlfcn.h>
+#include <new>
+
+#include "service_main.h"
+#include "service_plugin.h"
+#include "service_ipc_dbus.h"
+
+/* Sound buf save for test */
+#if 0
+#define BUF_SAVE_MODE
+#endif
+
+typedef struct {
+ void* data;
+ CServicePlugin* plugin;
+} AsyncParam;
+
+bool CServicePlugin::is_ui_panel_enabled()
+{
+ /* By default we assume the ui panel is always enabled unless explicitly turned off */
+ bool ret = true;
+ if (g_plugin_settings) {
+ ret = g_plugin_settings->ui_panel_enabled;
+ }
+ MAS_LOGD("UI Panel Enabled : %d", ret);
+ return ret;
+}
+
+#if 0 /* + TEST_CODE */
+Eina_Bool __send_asr_result(void *data)
+{
+ MAS_LOGD("[ENTER]");
+
+ if (!strcmp((char*)data, "Today's")) {
+ masc_ui_dbus_send_asr_result(-1, 1, "Today's");
+ }
+ if (!strcmp((char*)data, "weather.")) {
+ masc_ui_dbus_send_asr_result(-1, 0, "Today's weather.");
+ }
+
+ MAS_LOGD("END");
+ return EINA_FALSE;
+}
+
+Eina_Bool __send_result(void *data)
+{
+ MAS_LOGD("[ENTER]");
+
+ int ret = masc_ui_dbus_send_result(-1, (const char*)data, (const char*)data, "test");
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to stop recording(%d)", ret);
+ return EINA_TRUE;
+ }
+
+ MAS_LOGD("END");
+ return EINA_FALSE;
+}
+#endif /* -TEST_CODE */
+
+static Eina_Bool process_wakeup_event_by_appid_timer(void* data)
+{
+ if (NULL == data) return ECORE_CALLBACK_CANCEL;
+ AsyncParam* param = static_cast<AsyncParam*>(data);
+
+ char* appid = static_cast<char*>(param->data);
+ MAS_LOGD("[ENTER] appid(%s)", appid);
+
+ int pid = -1;
+ if (!appid) return ECORE_CALLBACK_CANCEL;
+
+ CServicePlugin* plugin = param->plugin;
+ CServiceIpcDbus* service_ipc = nullptr;
+ CServiceMain* service_main = nullptr;
+ if (plugin) {
+ service_ipc = plugin->get_service_ipc();
+ service_main = plugin->get_service_main();
+ }
+ if (service_ipc && service_main) {
+ bool use_custom_ui = service_main->mas_get_client_custom_ui_option_by_appid(appid);
+ bool ui_panel_enabled = false;
+ if (param->plugin) ui_panel_enabled = param->plugin->is_ui_panel_enabled();
+ if (ui_panel_enabled) {
+ service_ipc->masc_ui_dbus_enable_common_ui(!use_custom_ui);
+ service_ipc->masc_ui_dbus_change_assistant(appid);
+ }
+
+ service_main->mas_set_current_client_by_appid(appid);
+ if ((pid = service_main->mas_get_client_pid_by_appid(appid)) != -1) {
+ service_main->mas_client_send_preprocessing_information(pid);
+ service_main->mas_client_activate(pid);
+ service_main->mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED);
+ } else {
+ // Appropriate MA Client not available, trying to launch new one
+ MAS_LOGD("MA Client with appid %s does not exist, launching client", appid);
+ service_main->mas_launch_client_by_appid(appid, CLIENT_LAUNCH_MODE_ACTIVATION);
+ }
+ }
+
+ if (appid) free(appid);
+ delete param;
+
+ MAS_LOGD("END");
+ return ECORE_CALLBACK_CANCEL;
+}
+
+static Eina_Bool process_wakeup_event_by_word_timer(void* data)
+{
+ MAS_LOGD("[ENTER]");
+
+ if (NULL == data) return ECORE_CALLBACK_CANCEL;
+ AsyncParam* param = static_cast<AsyncParam*>(data);
+
+ char* wakeup_word = static_cast<char*>(param->data);
+ CServicePlugin* plugin = param->plugin;
+ CServiceMain* service_main = nullptr;
+
+ if (plugin) {
+ service_main = plugin->get_service_main();
+ }
+
+ delete param;
+ param = nullptr;
+
+ if (service_main) {
+ const char* appid = service_main->mas_get_client_appid_by_wakeup_word(wakeup_word);
+ if (appid) {
+ param = new(std::nothrow) AsyncParam;
+ if (param) {
+ param->data = static_cast<void*>(strdup(appid));
+ param->plugin = plugin;
+ process_wakeup_event_by_appid_timer(static_cast<void*>(param));
+ }
+ }
+ }
+
+ if (wakeup_word) free(wakeup_word);
+
+ MAS_LOGD("END");
+ return ECORE_CALLBACK_CANCEL;
+}
+
+static void __wakeup_event_cb(mas_wakeup_event_info wakeup_info, void* user_data)
+{
+ MAS_LOGD("dalton debug : %p", user_data);
+ MAS_LOGD("[SUCCESS] __wakeup_event_cb is called, wakeup_word(%s)", wakeup_info.wakeup_word);
+ int ret = -1;
+
+ CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
+ if (plugin) {
+ CServiceIpcDbus* service_ipc = plugin->get_service_ipc();
+ if (plugin->is_ui_panel_enabled() && service_ipc) {
+ int retry_cnt = 0;
+ while (0 != ret) {
+ ret = service_ipc->masc_ui_dbus_send_hello();
+ retry_cnt++;
+ if (5 < retry_cnt) {
+ MAS_LOGE("[ERROR] Fail to receive reply for hello, ret(%d)", ret);
+ break;
+ }
+ }
+ }
+ }
+
+#ifdef BUF_SAVE_MODE
+ if (g_pFile) {
+ fclose(g_pFile);
+ g_pFile = NULL;
+ } else {
+ MAS_LOGD("[Recorder Info] File not found!");
+ }
+
+ while (1) {
+ snprintf(g_temp_file_name, sizeof(g_temp_file_name), "/tmp/ma_service_%d_%d", getpid(), g_count);
+ int ret = access(g_temp_file_name, 0);
+
+ if (0 == ret) {
+ MAS_LOGD("[Recorder ERROR] File is already exist");
+ if (0 == remove(g_temp_file_name)) {
+ MAS_LOGD("[Recorder] Remove file");
+ break;
+ } else {
+ g_count++;
+ }
+ } else {
+ break;
+ }
+ }
+
+ MAS_LOGD("[Recorder] Temp file name=[%s]", g_temp_file_name);
+
+ /* open test file */
+ g_pFile = fopen(g_temp_file_name, "wb+x");
+ if (!g_pFile) {
+ MAS_LOGD("[Recorder ERROR] File not found!");
+ return;
+ }
+ g_count++;
+#endif
+
+#if 0 /* + TEST_CODE */
+ if (WAKEUP_EVENT_SUCCESS == event) {
+ ecore_thread_main_loop_begin();
+ ecore_timer_add(1.0, __send_asr_result, "Today's");
+ ecore_thread_main_loop_end();
+
+ ecore_thread_main_loop_begin();
+ ecore_timer_add(2.0, __send_asr_result, "weather.");
+ ecore_thread_main_loop_end();
+
+ ecore_thread_main_loop_begin();
+ ecore_timer_add(3.0, __send_result, "Partly cloudy with temperatures from 75 to 88");
+ ecore_thread_main_loop_end();
+ }
+#endif /* - TEST_CODE */
+ if (wakeup_info.wakeup_appid) {
+ AsyncParam* param = new(std::nothrow) AsyncParam;
+ if (param) {
+ param->data = static_cast<void*>(strdup(wakeup_info.wakeup_appid));
+ param->plugin = static_cast<CServicePlugin*>(user_data);
+ ecore_thread_main_loop_begin();
+ ecore_timer_add(0.0f, process_wakeup_event_by_appid_timer,
+ static_cast<void*>(param));
+ ecore_thread_main_loop_end();
+ }
+ } else if (wakeup_info.wakeup_word) {
+ AsyncParam* param = new(std::nothrow) AsyncParam;
+ if (param) {
+ param->data = static_cast<void*>(strdup(wakeup_info.wakeup_word));
+ param->plugin = static_cast<CServicePlugin*>(user_data);
+ ecore_thread_main_loop_begin();
+ ecore_timer_add(0.0f, process_wakeup_event_by_word_timer,
+ static_cast<void*>(param));
+ ecore_thread_main_loop_end();
+ }
+ }
+}
+
+static bool __validate_streaming_event_order(int pid, mas_speech_streaming_event_e *event)
+{
+ bool ret = false;
+
+ static int previous_pid = -1;
+ static mas_speech_streaming_event_e previous_event = MAS_SPEECH_STREAMING_EVENT_FINISH;
+
+ if (NULL == event) return false;
+
+ mas_speech_streaming_event_e expected_sequence[][2] = {
+ {MAS_SPEECH_STREAMING_EVENT_START, MAS_SPEECH_STREAMING_EVENT_CONTINUE},
+ {MAS_SPEECH_STREAMING_EVENT_START, MAS_SPEECH_STREAMING_EVENT_FINISH},
+ {MAS_SPEECH_STREAMING_EVENT_CONTINUE, MAS_SPEECH_STREAMING_EVENT_CONTINUE},
+ {MAS_SPEECH_STREAMING_EVENT_CONTINUE, MAS_SPEECH_STREAMING_EVENT_FINISH},
+ {MAS_SPEECH_STREAMING_EVENT_FINISH, MAS_SPEECH_STREAMING_EVENT_START},
+ /* If there is no audio data even after the start streaming request */
+ {MAS_SPEECH_STREAMING_EVENT_FINISH, MAS_SPEECH_STREAMING_EVENT_FINISH},
+ };
+
+ if (pid != previous_pid) {
+ /* When sending streaming event to a new client, it always sends START message first */
+ previous_event = MAS_SPEECH_STREAMING_EVENT_FINISH;
+ }
+
+ for (int loop = 0;loop < sizeof(expected_sequence) / sizeof(expected_sequence[0]);loop++) {
+ if (previous_event == expected_sequence[loop][0] &&
+ *event == expected_sequence[loop][1]) {
+ ret = true;
+ }
+ }
+ if (!ret) {
+ /* In case of FINISH -> CONTINUE without START, simply modify current event value */
+ if (MAS_SPEECH_STREAMING_EVENT_FINISH == previous_event &&
+ MAS_SPEECH_STREAMING_EVENT_CONTINUE == *event) {
+ *event = MAS_SPEECH_STREAMING_EVENT_START;
+ ret = true;
+
+ MAS_LOGD("[WARNING] forcibly changed CONTINUE to START : %d -> %d (PID %d -> %d)",
+ previous_event, *event, previous_pid, pid);
+ }
+ }
+
+ if (ret) {
+ previous_pid = pid;
+ previous_event = *event;
+ } else {
+ MAS_LOGE("[ERROR] State sequence validation failed : %d -> %d (PID %d -> %d)",
+ previous_event, *event, previous_pid, pid);
+ }
+ return ret;
+}
+
+void handle_speech_streaming_event_failure(void* data)
+{
+ AsyncParam* param = static_cast<AsyncParam*>(data);
+ if (NULL == param) return;
+
+ CServicePlugin* plugin = param->plugin;
+ CServiceMain* service_main = nullptr;
+ if (plugin) service_main = plugin->get_service_main();
+
+ if (service_main) {
+ service_main->mas_client_send_recognition_result(0, MA_RECOGNITION_RESULT_EVENT_ERROR);
+ }
+
+ delete param;
+}
+
+static void __audio_streaming_cb(mas_speech_streaming_event_e event, void* buffer, int len, void *user_data)
+{
+ if (event == MAS_SPEECH_STREAMING_EVENT_FAIL) {
+ ecore_main_loop_thread_safe_call_async(handle_speech_streaming_event_failure, NULL);
+ return;
+ }
+ static int count = 0;
+ if (event != MAS_SPEECH_STREAMING_EVENT_CONTINUE || count % 100 == 0) {
+ MAS_LOGD("[SUCCESS] __audio_streaming_cb is called, event(%d), buffer(%p), len(%d)",
+ event, buffer, len);
+ }
+ ++count;
+
+ CServicePlugin* plugin = static_cast<CServicePlugin*>(user_data);
+ CServiceIpcDbus* service_ipc = nullptr;
+ CServiceMain* service_main = nullptr;
+ if (plugin) {
+ service_ipc = plugin->get_service_ipc();
+ service_main = plugin->get_service_main();
+ }
+
+ if (service_ipc && service_main) {
+ int pid = service_main->mas_get_current_client_pid();
+ int preprocessing_pid = service_main->mas_get_current_preprocessing_client_pid();
+ if (pid == -1) {
+ MAS_LOGE("[ERROR] Fail to retrieve pid of current MA client");
+ } else {
+ if (__validate_streaming_event_order(pid, &event)) {
+ int ret = service_ipc->send_streaming_audio_data(pid,
+ event, buffer, len);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to send speech data, ret(%d)", ret);
+ }
+ if (pid != preprocessing_pid && -1 != preprocessing_pid) {
+ int ret = service_ipc->send_streaming_audio_data(preprocessing_pid,
+ event, buffer, len);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to send speech data to preprocessing client, ret(%d)", ret);
+ }
+ }
+ }
+ }
+ }
+#ifdef BUF_SAVE_MODE
+ /* write pcm buffer */
+ if (g_pFile)
+ fwrite(buffer, 1, len, g_pFile);
+
+ if (MAS_SPEECH_STREAMING_EVENT_FINISH == event) {
+ if (g_pFile) {
+ MAS_LOGE("[Recorder SUCCESS] File Close");
+ fclose(g_pFile);
+ g_pFile = NULL;
+ } else {
+ MAS_LOGE("[Recorder ERROR] File not found!");
+ }
+ }
+#endif
+}
+
+static void __speech_status_cb(mas_speech_status_e status, void *user_data)
+{
+ MAS_LOGD("[SUCCESS] __speech_status_cb is called, status(%d)", status);
+}
+
+static void __error_cb(int error, const char* err_msg, void* user_data)
+{
+ MAS_LOGD("[SUCCESS] __error_cb is called, error(%d), err_msg(%s)", error, err_msg);
+
+ CServiceIpcDbus* service_ipc = nullptr;
+ CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
+ if (plugin) {
+ service_ipc = plugin->get_service_ipc();
+ }
+ if (plugin->is_ui_panel_enabled() && service_ipc) {
+ int ret = service_ipc->masc_ui_dbus_send_error_message(error, err_msg);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to send error message, ret(%d)", ret);
+ }
+ }
+}
+
+static void __setting_changed_cb(void *user_data)
+{
+ CServiceMain* service_main = nullptr;
+ CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
+ if (plugin) {
+ service_main = plugin->get_service_main();
+ }
+ if (service_main) {
+ service_main->mas_prelaunch_default_assistant();
+ service_main->mas_update_voice_key_support_mode();
+ }
+ MAS_LOGD("[SUCCESS] __setting_changed_cb is called");
+}
+
+static void __streaming_section_changed_cb(ma_audio_streaming_data_section_e section, void* user_data)
+{
+ MAS_LOGD("[SUCCESS] __streaming_section_changed_cb is called, section(%d)", section);
+
+ CServiceIpcDbus *service_ipc = nullptr;
+ CServiceMain* service_main = nullptr;
+ CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
+ if (plugin) {
+ service_ipc = plugin->get_service_ipc();
+ service_main = plugin->get_service_main();
+ }
+ if (service_ipc && service_main) {
+ int pid = service_main->mas_get_current_client_pid();
+ int ret = service_ipc->send_streaming_section_changed(pid, (int)section);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to send streaming section changed information, ret(%d)", ret);
+ }
+ }
+}
+
+static void __wakeup_engine_command_cb(mas_wakeup_engine_command_target_e target, const char* assistant_name, const char* command, void* user_data)
+{
+ MAS_LOGD("[SUCCESS] __wakeup_engine_command_cb is called, command(%s)", command);
+
+ CServiceIpcDbus *service_ipc = nullptr;
+ CServiceMain* service_main = nullptr;
+ CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
+ if (plugin) {
+ service_ipc = plugin->get_service_ipc();
+ service_main = plugin->get_service_main();
+ }
+ if (service_ipc && service_main) {
+ int pid = service_main->mas_get_client_pid_by_appid(assistant_name);
+ if (-1 != pid) {
+ int ret = service_ipc->send_wakeup_engine_command(pid, command);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to send wakeup engine command, ret(%d)", ret);
+ }
+ }
+ }
+}
+
+static void __wakeup_service_state_changed_cb(ma_service_state_e state, void* user_data)
+{
+ MAS_LOGD("[SUCCESS] __wakeup_service_state_changed_cb is called, state(%d)", state);
+
+ CServiceMain* service_main = nullptr;
+ CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
+ if (plugin) {
+ service_main = plugin->get_service_main();
+ }
+ if (service_main) {
+ service_main->mas_set_current_service_state(state);
+ }
+}
+
+static void __wakeup_service_voice_key_status_changed_cb(ma_voice_key_status_e status, void* user_data)
+{
+ MAS_LOGD("[SUCCESS] __wakeup_service_voice_key_status_changed_cb is called, state(%d)", status);
+
+ CServiceIpcDbus *service_ipc = nullptr;
+ CServiceMain* service_main = nullptr;
+ CServicePlugin *plugin = static_cast<CServicePlugin*>(user_data);
+ if (plugin) {
+ service_ipc = plugin->get_service_ipc();
+ service_main = plugin->get_service_main();
+ }
+ if (service_ipc && service_main) {
+ int pid = service_main->mas_get_current_client_pid();
+ int ret = service_ipc->voice_key_status_change(pid, status);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to send voice key status changed information, ret(%d)", ret);
+ }
+ }
+}
+
+int CServicePlugin::initialize(void)
+{
+ MAS_LOGD("[Enter]");
+
+ char filepath[512] = {'\0', };
+ const char *default_engine_path = MA_WAKEUP_MANAGER_PATH;
+ snprintf(filepath, 512, "%s/%s", default_engine_path, MA_DEFAULT_WAKEUP_MANAGER_FILENAME);
+
+ char *error;
+ g_handle = NULL;
+ g_handle = dlopen(filepath, RTLD_LAZY);
+ if (NULL != (error = dlerror())) {
+ MAS_LOGE("[ERROR] Fail to dlopen(%s), error(%s)", filepath, error);
+ return -1; //MAS_ERROR_OPERATION_FAILED;
+ }
+
+ _wakeup_manager_interface.initialize =
+ (wakeup_manager_initialize)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_INITIALIZE);
+ _wakeup_manager_interface.deinitialize =
+ (wakeup_manager_deinitialize)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE);
+ _wakeup_manager_interface.get_settings =
+ (wakeup_manager_get_settings)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
+ _wakeup_manager_interface.add_assistant_wakeup_word =
+ (wakeup_manager_add_assistant_wakeup_word)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_WORD);
+ _wakeup_manager_interface.remove_assistant_wakeup_word =
+ (wakeup_manager_remove_assistant_wakeup_word)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_REMOVE_ASSISTANT_WAKEUP_WORD);
+ _wakeup_manager_interface.add_assistant_language =
+ (wakeup_manager_add_assistant_language)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE);
+ _wakeup_manager_interface.set_assistant_wakeup_engine =
+ (wakeup_manager_set_assistant_wakeup_engine)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE);
+ _wakeup_manager_interface.set_default_assistant =
+ (wakeup_manager_set_default_assistant)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_DEFAULT_ASSISTANT);
+ _wakeup_manager_interface.get_default_assistant =
+ (wakeup_manager_get_default_assistant)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_GET_DEFAULT_ASSISTANT);
+ _wakeup_manager_interface.set_language =
+ (wakeup_manager_set_language)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE);
+ _wakeup_manager_interface.activate =
+ (wakeup_manager_activate)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_ACTIVATE);
+ _wakeup_manager_interface.deactivate =
+ (wakeup_manager_deactivate)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_DEACTIVATE);
+ _wakeup_manager_interface.update_voice_feedback_state =
+ (wakeup_manager_update_voice_feedback_state)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_UPDATE_VOICE_FEEDBACK_STATE);
+ _wakeup_manager_interface.set_assistant_specific_command =
+ (wakeup_manager_set_assistant_specific_command)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND);
+ _wakeup_manager_interface.set_background_volume =
+ (wakeup_manager_set_background_volume)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_BACKGROUND_VOLUME);
+ _wakeup_manager_interface.update_recognition_result =
+ (wakeup_manager_update_recognition_result)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_UPDATE_RECOGNITION_RESULT);
+ _wakeup_manager_interface.process_plugin_event =
+ (wakeup_manager_process_plugin_event)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_PROCESS_PLUGIN_EVENT);
+ _wakeup_manager_interface.start_streaming_utterance_data =
+ (wakeup_manager_start_streaming_utterance_data)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_START_STREAMING_UTTERANCE_DATA);
+ _wakeup_manager_interface.stop_streaming_utterance_data =
+ (wakeup_manager_stop_streaming_utterance_data)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_UTTERANCE_DATA);
+ _wakeup_manager_interface.start_streaming_previous_utterance_data =
+ (wakeup_manager_start_streaming_previous_utterance_data)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_START_STREAMING_PREVIOUS_UTTERANCE_DATA);
+ _wakeup_manager_interface.stop_streaming_previous_utterance_data =
+ (wakeup_manager_stop_streaming_previous_utterance_data)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_PREVIOUS_UTTERANCE_DATA);
+ _wakeup_manager_interface.start_streaming_follow_up_data =
+ (wakeup_manager_start_streaming_follow_up_data)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_START_STREAMING_FOLLOW_UP_DATA);
+ _wakeup_manager_interface.stop_streaming_follow_up_data =
+ (wakeup_manager_stop_streaming_follow_up_data)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_FOLLOW_UP_DATA);
+ _wakeup_manager_interface.get_audio_format =
+ (wakeup_manager_get_audio_format)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_FORMAT);
+ _wakeup_manager_interface.get_audio_source_type =
+ (wakeup_manager_get_audio_source_type)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_SOURCE_TYPE);
+ _wakeup_manager_interface.set_wake_word_audio_require_flag =
+ (wakeup_manager_set_wake_word_audio_require_flag)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG);
+ _wakeup_manager_interface.set_assistant_language =
+ (wakeup_manager_set_assistant_language)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_LANGUAGE);
+ _wakeup_manager_interface.set_voice_key_tap_duration =
+ (wakeup_manager_set_voice_key_tap_duration)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_TAP_DURATION);
+ _wakeup_manager_interface.unset_voice_key_tap_duration =
+ (wakeup_manager_unset_voice_key_tap_duration)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_UNSET_VOICE_KEY_TAP_DURATION);
+ _wakeup_manager_interface.set_voice_key_support_mode =
+ (wakeup_manager_set_voice_key_support_mode)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_SUPPORT_MODE);
+ _wakeup_manager_interface.set_wakeup_event_callback =
+ (wakeup_manager_set_wakeup_event_callback)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_EVENT_CALLBACK);
+ _wakeup_manager_interface.set_utterance_streaming_callback =
+ (wakeup_manager_set_utterance_streaming_callback)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_UTTERANCE_STREAMING_CALLBACK);
+ _wakeup_manager_interface.set_previous_utterance_streaming_callback =
+ (wakeup_manager_set_previous_utterance_streaming_callback)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_PREVIOUS_UTTERANCE_STREAMING_CALLBACK);
+ _wakeup_manager_interface.set_follow_up_streaming_callback =
+ (wakeup_manager_set_follow_up_streaming_callback)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_FOLLOW_UP_STREAMING_CALLBACK);
+ _wakeup_manager_interface.set_speech_status_callback =
+ (wakeup_manager_set_speech_status_callback)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_SPEECH_STATUS_CALLBACK);
+ _wakeup_manager_interface.set_setting_changed_callback =
+ (wakeup_manager_set_setting_changed_callback)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_SETTING_CHANGED_CALLBACK);
+ _wakeup_manager_interface.set_error_callback =
+ (wakeup_manager_set_error_callback)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_ERROR_CALLBACK);
+ _wakeup_manager_interface.set_streaming_section_changed_callback =
+ (wakeup_manager_set_streaming_section_changed_callback)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_STREAMING_SECTION_CHANGED_CALLBACK);
+ _wakeup_manager_interface.set_wakeup_engine_command_callback =
+ (wakeup_manager_set_wakeup_engine_command_callback)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_ENGINE_COMMAND_CALLBACK);
+ _wakeup_manager_interface.set_wakeup_service_state_changed_callback =
+ (wakeup_manager_set_wakeup_service_state_changed_callback)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_SERVICE_STATE_CHANGED_CALLBACK);
+ _wakeup_manager_interface.set_voice_key_status_changed_callback =
+ (wakeup_manager_set_voice_key_status_changed_callback)dlsym(g_handle,
+ MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_STATUS_CHANGED_CALLBACK);
+
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_initialize func = _wakeup_manager_interface.initialize;
+
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_INITIALIZE);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to initialize, ret(%d)", ret);
+ }
+ }
+
+ wakeup_manager_get_settings get_settings_func = _wakeup_manager_interface.get_settings;
+
+ if (NULL == get_settings_func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
+ } else {
+ size_t struct_size;
+ ret = get_settings_func(&g_plugin_settings, &struct_size);
+ if (0 != ret || struct_size != sizeof(ma_plugin_settings)) {
+ MAS_LOGE("[ERROR] Fail to get settings, ret(%d), size %zu", ret, struct_size);
+ g_plugin_settings = NULL;
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::deinitialize(void)
+{
+#ifdef BUF_SAVE_MODE
+ if (g_pFile) {
+ fclose(g_pFile);
+ g_pFile = NULL;
+ } else {
+ MAS_LOGD("[Recorder ERROR] File not found!");
+ }
+#endif
+
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_deinitialize func = _wakeup_manager_interface.deinitialize;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to deinitialize, ret(%d)", ret);
+ }
+ }
+
+ dlclose(g_handle);
+ g_handle = NULL;
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+
+ return ret;
+}
+
+int CServicePlugin::get_settings(ma_plugin_settings **settings, size_t *struct_size)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_get_settings func = _wakeup_manager_interface.get_settings;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS);
+ } else {
+ ret = func(settings, struct_size);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to get settings, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_language(const char* language)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_language func = _wakeup_manager_interface.set_language;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE);
+ } else {
+ ret = func(language);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set langauge(%s), ret(%d)", language, ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::add_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_add_assistant_wakeup_word func = _wakeup_manager_interface.add_assistant_wakeup_word;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_WORD);
+ } else {
+ ret = func(appid, wakeup_word, language);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to add wakeup word(%s)(%s)(%s), ret(%d)", appid, wakeup_word, language, ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::remove_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_remove_assistant_wakeup_word func = _wakeup_manager_interface.remove_assistant_wakeup_word;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_REMOVE_ASSISTANT_WAKEUP_WORD);
+ } else {
+ ret = func(appid, wakeup_word, language);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to remove wakeup word(%s)(%s)(%s), ret(%d)", appid, wakeup_word, language, ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::add_assistant_language(const char* appid, const char* language)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_add_assistant_language func = _wakeup_manager_interface.add_assistant_language;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE);
+ } else {
+ ret = func(appid, language);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set wakeup word(%s)(%s), ret(%d)", appid, language, ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_assistant_wakeup_engine(const char* appid, const char* engine)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_assistant_wakeup_engine func = _wakeup_manager_interface.set_assistant_wakeup_engine;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE);
+ } else {
+ ret = func(appid, engine);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set wakeup engine(%s)(%s), ret(%d)", appid, engine, ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_default_assistant(const char* appid)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_default_assistant func = _wakeup_manager_interface.set_default_assistant;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_DEFAULT_ASSISTANT);
+ } else {
+ ret = func(appid);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set default assistant(%s), ret(%d)", appid, ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::get_default_assistant(const char** appid)
+{
+ int ret = -1;
+ if (NULL == appid) {
+ MAS_LOGE("[ERROR] appid is not valid");
+ return ret;
+ }
+ if (NULL != g_handle) {
+ wakeup_manager_get_default_assistant func = _wakeup_manager_interface.get_default_assistant;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_DEFAULT_ASSISTANT);
+ } else {
+ ret = func(appid);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to get default assistant, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::activate(void)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_activate func = _wakeup_manager_interface.activate;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ACTIVATE);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to start recording, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::deactivate(void)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_deactivate func = _wakeup_manager_interface.deactivate;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_DEACTIVATE);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::update_voice_feedback_state(const char* appid, int state)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_update_voice_feedback_state func = _wakeup_manager_interface.update_voice_feedback_state;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UPDATE_VOICE_FEEDBACK_STATE);
+ } else {
+ ret = func(appid, state);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_assistant_specific_command(const char* appid, const char* command)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_assistant_specific_command func = _wakeup_manager_interface.set_assistant_specific_command;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND);
+ } else {
+ ret = func(appid, command);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_background_volume(const char* appid, double ratio)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_background_volume func = _wakeup_manager_interface.set_background_volume;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_BACKGROUND_VOLUME);
+ } else {
+ ret = func(appid, ratio);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set background volume, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::update_recognition_result(const char* appid, int state)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_update_recognition_result func = _wakeup_manager_interface.update_recognition_result;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UPDATE_RECOGNITION_RESULT);
+ } else {
+ ret = func(appid, state);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to update result state, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::process_event(int event, void *data, int len)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_process_plugin_event func = _wakeup_manager_interface.process_plugin_event;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_PROCESS_PLUGIN_EVENT);
+ } else {
+ ret = func((mas_plugin_event_e)event, data, len);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::start_streaming_utterance_data(void)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_start_streaming_utterance_data func = _wakeup_manager_interface.start_streaming_utterance_data;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_UTTERANCE_DATA);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::stop_streaming_utterance_data(void)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_stop_streaming_utterance_data func = _wakeup_manager_interface.stop_streaming_utterance_data;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_UTTERANCE_DATA);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::start_streaming_previous_utterance_data(void)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_start_streaming_previous_utterance_data func = _wakeup_manager_interface.start_streaming_previous_utterance_data;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_PREVIOUS_UTTERANCE_DATA);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to request previous speech data, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::stop_streaming_previous_utterance_data(void)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_stop_streaming_previous_utterance_data func = _wakeup_manager_interface.stop_streaming_previous_utterance_data;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_PREVIOUS_UTTERANCE_DATA);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to request previous speech data, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::start_streaming_follow_up_data(void)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_start_streaming_follow_up_data func = _wakeup_manager_interface.start_streaming_follow_up_data;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_FOLLOW_UP_DATA);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::stop_streaming_follow_up_data(void)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_stop_streaming_follow_up_data func = _wakeup_manager_interface.stop_streaming_follow_up_data;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_FOLLOW_UP_DATA);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to request speech data, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::get_recording_audio_format(int *rate, int *channel, int *audio_type)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_get_audio_format func = _wakeup_manager_interface.get_audio_format;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_FORMAT);
+ } else {
+ ret = func(rate, channel, audio_type);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to get recording audio format, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::get_recording_audio_source_type(char** type)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_get_audio_source_type func = _wakeup_manager_interface.get_audio_source_type;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_SOURCE_TYPE);
+ } else {
+ ret = func(type);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to get recording audio source type, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_voice_key_tap_duration(float duration)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_voice_key_tap_duration func = _wakeup_manager_interface.set_voice_key_tap_duration;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_TAP_DURATION);
+ } else {
+ ret = func(duration);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set voice key tap duration, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::unset_voice_key_tap_duration()
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_unset_voice_key_tap_duration func = _wakeup_manager_interface.unset_voice_key_tap_duration;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UNSET_VOICE_KEY_TAP_DURATION);
+ } else {
+ ret = func();
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to unset voice key tap duration, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_voice_key_support_mode(int mode)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_voice_key_support_mode func = _wakeup_manager_interface.set_voice_key_support_mode;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_SUPPORT_MODE);
+ } else {
+ ret = func(mode);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set voice key support mode, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_wake_word_audio_require_flag(const char* appid, bool require)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_wake_word_audio_require_flag func = _wakeup_manager_interface.set_wake_word_audio_require_flag;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG);
+ } else {
+ ret = func(require);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set wake word audio require flag, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_assistant_language(const char* appid, const char* language)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_assistant_language func = _wakeup_manager_interface.set_assistant_language;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_LANGUAGE);
+ } else {
+ ret = func(appid, language);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set assistant language, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_callbacks(void)
+{
+ int ret = set_wakeup_event_callback(__wakeup_event_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set wakeup event cb");
+ return ret;
+ }
+
+ ret = set_utterance_streaming_callback(__audio_streaming_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set utterance streaming cb");
+ return ret;
+ }
+
+ ret = set_previous_utterance_streaming_callback(__audio_streaming_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set previous utterance streaming cb");
+ return ret;
+ }
+
+ ret = set_follow_up_streaming_callback(__audio_streaming_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set follow-up streaming cb");
+ return ret;
+ }
+
+ ret = set_speech_status_callback(__speech_status_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set speech status changed cb");
+ return ret;
+ }
+
+ ret = set_setting_changed_callback(__setting_changed_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set setting changed cb");
+ return ret;
+ }
+
+ ret = set_error_callback(__error_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set error cb");
+ return ret;
+ }
+
+ ret = set_streaming_section_changed_callback(__streaming_section_changed_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set streaming section changed cb");
+ return ret;
+ }
+
+ ret = set_wakeup_engine_command_callback(__wakeup_engine_command_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set wakeup engine command cb");
+ return ret;
+ }
+
+ ret = set_wakeup_service_state_changed_callback(__wakeup_service_state_changed_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set wakeup engine command cb");
+ return ret;
+ }
+
+ ret = set_voice_key_status_changed_callback(__wakeup_service_voice_key_status_changed_cb, this);
+ if (0 != ret) {
+ MAS_LOGE("Fail to set wakeup engine command cb");
+ return ret;
+ }
+
+ return 0;
+}
+
+int CServicePlugin::set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_wakeup_event_callback func = _wakeup_manager_interface.set_wakeup_event_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_EVENT_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ MAS_LOGD("dalton debug : %p", user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set wakeup event callback, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_utterance_streaming_callback func = _wakeup_manager_interface.set_utterance_streaming_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_UTTERANCE_STREAMING_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set utterance streaming callback, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_previous_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_previous_utterance_streaming_callback func = _wakeup_manager_interface.set_previous_utterance_streaming_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_PREVIOUS_UTTERANCE_STREAMING_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set utterance streaming callback, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_follow_up_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_follow_up_streaming_callback func = _wakeup_manager_interface.set_follow_up_streaming_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_FOLLOW_UP_STREAMING_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set follow-up streaming callback, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+ return ret;
+}
+
+int CServicePlugin::set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_speech_status_callback func = _wakeup_manager_interface.set_speech_status_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_SPEECH_STATUS_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set speech status callback, ret(%d)", ret);
+ }
+ }
+ }
+ return ret;
+}
+
+int CServicePlugin::set_setting_changed_callback(wakeup_service_setting_changed_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_setting_changed_callback func = _wakeup_manager_interface.set_setting_changed_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_SETTING_CHANGED_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set setting_changed callback, ret(%d)", ret);
+ }
+ }
+ }
+ return ret;
+}
+
+int CServicePlugin::set_error_callback(wakeup_service_error_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_error_callback func = _wakeup_manager_interface.set_error_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ERROR_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
+ }
+ }
+ }
+ return ret;
+}
+
+int CServicePlugin::set_streaming_section_changed_callback(wakeup_service_streaming_section_changed_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_streaming_section_changed_callback func = _wakeup_manager_interface.set_streaming_section_changed_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_STREAMING_SECTION_CHANGED_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set streaming section changed callback, ret(%d)", ret);
+ }
+ }
+ }
+ return ret;
+}
+
+int CServicePlugin::set_wakeup_engine_command_callback(wakeup_service_wakeup_engine_command_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_wakeup_engine_command_callback func = _wakeup_manager_interface.set_wakeup_engine_command_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_ENGINE_COMMAND_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
+ }
+ }
+ }
+ return ret;
+}
+
+int CServicePlugin::set_wakeup_service_state_changed_callback(wakeup_service_wakeup_service_state_changed_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_wakeup_service_state_changed_callback func = _wakeup_manager_interface.set_wakeup_service_state_changed_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_SERVICE_STATE_CHANGED_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
+ }
+ }
+ }
+ return ret;
+}
+
+int CServicePlugin::set_voice_key_status_changed_callback(wakeup_service_voice_key_status_changed_cb callback, void* user_data)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ wakeup_manager_set_voice_key_status_changed_callback func = _wakeup_manager_interface.set_voice_key_status_changed_callback;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_VOICE_KEY_STATUS_CHANGED_CALLBACK);
+ } else {
+ ret = func(callback, user_data);
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to set error callback, ret(%d)", ret);
+ }
+ }
+ }
+ return ret;
+}
+
SET(TEST_SOURCES
test_config.cpp
- ${CMAKE_SOURCE_DIR}/src/multi_assistant_config.cpp
+ ${CMAKE_SOURCE_DIR}/src/service_config.cpp
)
# Find Packages
#include <gtest/gtest.h>
-#include "multi_assistant_config.h"
+#include "service_config.h"
#include <string>
}
void TearDown() override {
}
- CConfig config;
+ CServiceConfig config;
char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN];
char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN];
};
memset(wakeup_word_storage, 0x0, sizeof(wakeup_word_storage));
memset(wakeup_language_storage, 0x0, sizeof(wakeup_language_storage));
- config.mas_config_add_custom_wake_word(
+ config.add_custom_wake_word(
preloaded_wake_word.c_str(), preloaded_language.c_str(),
wakeup_word_storage,
wakeup_language_storage);
}
const std::string preloaded_wake_word{"Hi Preloaded"};
const std::string preloaded_language{"pr_LD"};
- CConfig config;
+ CServiceConfig config;
char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN];
char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN];
};
const std::string arbitrary_wake_word{"Hi Tizen"};
const std::string arbitrary_language{"ar_LA"};
- config.mas_config_add_custom_wake_word(
+ config.add_custom_wake_word(
arbitrary_wake_word.c_str(), arbitrary_language.c_str(),
wakeup_word_storage,
wakeup_language_storage);
- int wake_word_num = config.mas_config_get_custom_wake_word_num(
+ int wake_word_num = config.get_custom_wake_word_num(
wakeup_word_storage, wakeup_language_storage);
ASSERT_EQ(wake_word_num, 1);
}
const std::string arbitrary_wake_word{"Hi Tizen"};
const std::string arbitrary_language1{"ar_LA1"};
const std::string arbitrary_language2{"ar_LA2"};
- config.mas_config_add_custom_wake_word(
+ config.add_custom_wake_word(
arbitrary_wake_word.c_str(), arbitrary_language1.c_str(),
wakeup_word_storage,
wakeup_language_storage);
- config.mas_config_add_custom_wake_word(
+ config.add_custom_wake_word(
arbitrary_wake_word.c_str(), arbitrary_language2.c_str(),
wakeup_word_storage,
wakeup_language_storage);
- int wake_word_num = config.mas_config_get_custom_wake_word_num(
+ int wake_word_num = config.get_custom_wake_word_num(
wakeup_word_storage, wakeup_language_storage);
ASSERT_EQ(wake_word_num, 2);
}
const std::string arbitrary_wake_word{"Hi Tizen"};
const std::string arbitrary_language{"ar_LA"};
- int ret = config.mas_config_remove_custom_wake_word(
+ int ret = config.remove_custom_wake_word(
arbitrary_wake_word.c_str(), arbitrary_language.c_str(),
wakeup_word_storage,
wakeup_language_storage);
}
TEST_F(StorageWithAnArbitraryWakeWord, StillHasOneWakeWordAfterDuplicatedAdd) {
- config.mas_config_add_custom_wake_word(
+ config.add_custom_wake_word(
preloaded_wake_word.c_str(), preloaded_language.c_str(),
wakeup_word_storage,
wakeup_language_storage);
- int wake_word_num = config.mas_config_get_custom_wake_word_num(
+ int wake_word_num = config.get_custom_wake_word_num(
wakeup_word_storage, wakeup_language_storage);
ASSERT_EQ(wake_word_num, 1);
}
TEST_F(StorageWithAnArbitraryWakeWord, HasZeroWakeWordAfterRemoval) {
- config.mas_config_remove_custom_wake_word(
+ config.remove_custom_wake_word(
preloaded_wake_word.c_str(), preloaded_language.c_str(),
wakeup_word_storage,
wakeup_language_storage);
- int wake_word_num = config.mas_config_get_custom_wake_word_num(
+ int wake_word_num = config.get_custom_wake_word_num(
wakeup_word_storage, wakeup_language_storage);
ASSERT_EQ(wake_word_num, 0);
}
TEST_F(StorageWithAnArbitraryWakeWord, RemovesItemRequestedForRemoval) {
const std::string arbitrary_wake_word{"Hi Tizen"};
const std::string arbitrary_language{"ar_LA"};
- config.mas_config_add_custom_wake_word(
+ config.add_custom_wake_word(
arbitrary_wake_word.c_str(), arbitrary_language.c_str(),
wakeup_word_storage,
wakeup_language_storage);
- config.mas_config_remove_custom_wake_word(
+ config.remove_custom_wake_word(
preloaded_wake_word.c_str(), preloaded_language.c_str(),
wakeup_word_storage,
wakeup_language_storage);
- bool exists = config.mas_config_has_custom_wake_word(
+ bool exists = config.has_custom_wake_word(
preloaded_wake_word.c_str(), preloaded_language.c_str(),
wakeup_word_storage,
wakeup_language_storage);
TEST_F(StorageWithAnArbitraryWakeWord, PreservesItemNotRequestedForRemoval) {
const std::string arbitrary_wake_word{"Hi Tizen"};
const std::string arbitrary_language{"ar_LA"};
- config.mas_config_add_custom_wake_word(
+ config.add_custom_wake_word(
arbitrary_wake_word.c_str(), arbitrary_language.c_str(),
wakeup_word_storage,
wakeup_language_storage);
- config.mas_config_remove_custom_wake_word(
+ config.remove_custom_wake_word(
preloaded_wake_word.c_str(), preloaded_language.c_str(),
wakeup_word_storage,
wakeup_language_storage);
- bool exists = config.mas_config_has_custom_wake_word(
+ bool exists = config.has_custom_wake_word(
arbitrary_wake_word.c_str(), arbitrary_language.c_str(),
wakeup_word_storage,
wakeup_language_storage);