From a4f8faa5e5f8a17bc3927d1dec0c9f2677c53075 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 9 Jan 2020 11:14:27 +0900 Subject: [PATCH 01/16] Send voice key status events according to configuration values This patch includes some future features. Change-Id: I1448d2b871286f1ac071cacea5196951e622d40d Signed-off-by: Suyeon Hwang (cherry picked from commit a489247511f0439a67ca4f742d308851a0a6b56d) --- inc/multi_assistant_config.h | 21 ++- inc/multi_assistant_main.h | 1 + inc/multi_assistant_service_client.h | 47 ++++--- inc/multi_assistant_service_plugin.h | 16 +++ inc/multi_wakeup_recognizer.h | 2 + .../dependency-default/inc/dependency_default.h | 2 + .../inc/dependency_default_button.h | 2 + .../dependency-default/src/dependency_default.cpp | 12 ++ .../src/dependency_default_button.cpp | 32 ++++- plugins/wakeup-manager/inc/dependency_resolver.h | 9 ++ plugins/wakeup-manager/inc/wakeup_manager.h | 8 ++ .../wakeup-manager/inc/wakeup_manager_wrapper.h | 10 ++ plugins/wakeup-manager/src/dependency_resolver.cpp | 56 ++++++++ plugins/wakeup-manager/src/wakeup_manager.cpp | 149 ++++++++++++++------- .../wakeup-manager/src/wakeup_manager_wrapper.cpp | 63 +++++++++ src/multi_assistant_config.c | 111 ++++++++------- src/multi_assistant_dbus.c | 53 +++++++- src/multi_assistant_dbus.h | 2 + src/multi_assistant_service.c | 99 +++++++++++--- src/multi_assistant_service_plugin.c | 106 +++++++++++++++ 20 files changed, 649 insertions(+), 152 deletions(-) diff --git a/inc/multi_assistant_config.h b/inc/multi_assistant_config.h index e0b9f20..a5810ac 100644 --- a/inc/multi_assistant_config.h +++ b/inc/multi_assistant_config.h @@ -42,6 +42,8 @@ extern "C" #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 @@ -50,6 +52,18 @@ extern "C" #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 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; @@ -61,12 +75,11 @@ typedef struct { 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)(const char* appid, const char* name, const char* icon_path, - const char* wakeup_list[], const char* wakeup_language[], int cnt_wakeup, - const char* supported_lang[], int cnt_lang, - const char* wakeup_engine, bool custom_ui_option, void* user_data); +typedef int (*mas_config_assistant_info_cb)(ma_assistant_info_s* info, void* user_data); int mas_config_get_assistant_info(mas_config_assistant_info_cb callback, void* user_data); #ifdef __cplusplus diff --git a/inc/multi_assistant_main.h b/inc/multi_assistant_main.h index 8adc1c0..81018ac 100644 --- a/inc/multi_assistant_main.h +++ b/inc/multi_assistant_main.h @@ -83,6 +83,7 @@ #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" diff --git a/inc/multi_assistant_service_client.h b/inc/multi_assistant_service_client.h index bba7085..be2e984 100644 --- a/inc/multi_assistant_service_client.h +++ b/inc/multi_assistant_service_client.h @@ -27,6 +27,28 @@ extern "C" { #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); @@ -57,6 +79,8 @@ int mas_client_set_preprocessing_allow_mode(int pid, int mode, const char* appid int mas_client_send_preprocessing_result(int pid, bool result); +int mas_client_send_voice_key_status_change(int pid, ma_voice_key_status_e status); + int mas_ui_client_initialize(int pid); int mas_ui_client_deinitialize(int pid); @@ -89,31 +113,12 @@ int mas_set_current_service_state(ma_service_state_e state); ma_service_state_e mas_get_current_service_state(); -typedef enum { - CLIENT_LAUNCH_MODE_ACTIVATION, - CLIENT_LAUNCH_MODE_PRELAUNCH, -} CLIENT_LAUNCH_MODE; int mas_launch_client_by_appid(const char *appid, CLIENT_LAUNCH_MODE 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_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event); +int mas_update_voice_key_support_mode(); + #ifdef __cplusplus } diff --git a/inc/multi_assistant_service_plugin.h b/inc/multi_assistant_service_plugin.h index 4f431e6..db1b6df 100644 --- a/inc/multi_assistant_service_plugin.h +++ b/inc/multi_assistant_service_plugin.h @@ -83,6 +83,10 @@ int multi_assistant_service_plugin_get_recording_audio_format(int* rate, int* ch int multi_assistant_service_plugin_get_recording_audio_source_type(char **type); +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); @@ -151,6 +155,12 @@ typedef int (*wakeup_manager_stop_streaming_follow_up_data)(void); 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" @@ -175,6 +185,8 @@ typedef int (*wakeup_manager_set_streaming_section_changed_callback)(wakeup_serv 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; @@ -201,6 +213,9 @@ typedef struct { 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; @@ -213,6 +228,7 @@ typedef struct { 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 diff --git a/inc/multi_wakeup_recognizer.h b/inc/multi_wakeup_recognizer.h index cdd8140..d5f8fb0 100644 --- a/inc/multi_wakeup_recognizer.h +++ b/inc/multi_wakeup_recognizer.h @@ -44,6 +44,8 @@ typedef void (*wakeup_service_wakeup_engine_command_cb)(mas_wakeup_engine_comman 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 diff --git a/plugins/wakeup-manager/dependency-default/inc/dependency_default.h b/plugins/wakeup-manager/dependency-default/inc/dependency_default.h index bdd2b18..8469a64 100644 --- a/plugins/wakeup-manager/dependency-default/inc/dependency_default.h +++ b/plugins/wakeup-manager/dependency-default/inc/dependency_default.h @@ -40,6 +40,8 @@ EXPORT_API int mas_dependency_set_background_volume(double ratio); EXPORT_API int mas_dependency_get_audio_format(int* rate, int* channel, int* audio_type); EXPORT_API int mas_dependency_get_audio_source_type(char** type); EXPORT_API int mas_dependency_process_wakeup_engine_command(const char* engine_name, const char* command); +EXPORT_API int mas_dependency_set_voice_key_tap_duration(float duration); +EXPORT_API int mas_dependency_unset_voice_key_tap_duration(void); #ifdef __cplusplus } diff --git a/plugins/wakeup-manager/dependency-default/inc/dependency_default_button.h b/plugins/wakeup-manager/dependency-default/inc/dependency_default_button.h index 9c5b3c9..aa50c94 100644 --- a/plugins/wakeup-manager/dependency-default/inc/dependency_default_button.h +++ b/plugins/wakeup-manager/dependency-default/inc/dependency_default_button.h @@ -21,5 +21,7 @@ void dependency_default_button_initialize(mas_dependency_plugin_proxy_interface interface); void dependency_default_button_deinitialize(); +void dependency_default_button_set_voice_key_tap_duration(float duration); +void dependency_default_button_unset_voice_key_tap_duration(void); #endif //_DEPENDENCY_DEFAULT_BUTTON_H_ diff --git a/plugins/wakeup-manager/dependency-default/src/dependency_default.cpp b/plugins/wakeup-manager/dependency-default/src/dependency_default.cpp index 7ca62bc..25f1252 100644 --- a/plugins/wakeup-manager/dependency-default/src/dependency_default.cpp +++ b/plugins/wakeup-manager/dependency-default/src/dependency_default.cpp @@ -93,4 +93,16 @@ int mas_dependency_process_wakeup_engine_command(const char* engine_name, const { LOGD("Wakeup Engine %s has sent a command : %s", engine_name, command); return 0; +} + +int mas_dependency_set_voice_key_tap_duration(float duration) +{ + dependency_default_button_set_voice_key_tap_duration(duration); + return 0; +} + +int mas_dependency_unset_voice_key_tap_duration(void) +{ + dependency_default_button_unset_voice_key_tap_duration(); + return 0; } \ No newline at end of file diff --git a/plugins/wakeup-manager/dependency-default/src/dependency_default_button.cpp b/plugins/wakeup-manager/dependency-default/src/dependency_default_button.cpp index 3b85756..f3684a8 100644 --- a/plugins/wakeup-manager/dependency-default/src/dependency_default_button.cpp +++ b/plugins/wakeup-manager/dependency-default/src/dependency_default_button.cpp @@ -16,8 +16,10 @@ static mas_dependency_plugin_proxy_interface g_proxy_interface; static Ecore_Event_Handler* g_key_down_handler = NULL; static Ecore_Event_Handler* g_key_up_handler = NULL; -static chrono::time_point g_last_time_point; +static chrono::time_point g_last_key_pressed; static bool g_voice_key_pressed = false; +const float DEFAULT_KEY_TAP_DURATION = 0.3f * 1000; +static float g_voice_key_tap_duration = DEFAULT_KEY_TAP_DURATION; #define VOICE_KEY "XF86AudioPlayPause" @@ -30,7 +32,7 @@ static Eina_Bool _key_down_cb(void* data, int type, void* event) if (ev->keyname && strncmp(ev->keyname, VOICE_KEY, strlen(VOICE_KEY)) == 0 ) { chrono::time_point current_time_point; current_time_point = chrono::system_clock::now(); - auto diff = current_time_point - g_last_time_point; + auto diff = current_time_point - g_last_key_pressed; auto milliseconds = chrono::duration_cast(diff).count(); /* If double click detected within 500 msec */ if (milliseconds < 500) { @@ -39,7 +41,7 @@ static Eina_Bool _key_down_cb(void* data, int type, void* event) g_voice_key_pressed = true; } } - g_last_time_point = current_time_point; + g_last_key_pressed = current_time_point; } } @@ -54,7 +56,17 @@ static Eina_Bool _key_up_cb(void* data, int type, void* event) if (g_voice_key_pressed && ev->keyname && strncmp(ev->keyname, VOICE_KEY, strlen(VOICE_KEY)) == 0) { - mas_plugin_event_e event = MAS_PLUGIN_EVENT_VOICE_KEY_RELEASED_AFTER_PUSH; + chrono::time_point current_time_point; + current_time_point = chrono::system_clock::now(); + auto diff = current_time_point - g_last_key_pressed; + auto milliseconds = chrono::duration_cast(diff).count(); + LOGD("milliseconds : %lld", milliseconds); + mas_plugin_event_e event; + if (milliseconds < g_voice_key_tap_duration) { + event = MAS_PLUGIN_EVENT_VOICE_KEY_RELEASED_AFTER_TAP; + } else { + event = MAS_PLUGIN_EVENT_VOICE_KEY_RELEASED_AFTER_PUSH; + } if (g_proxy_interface.process_event) { g_proxy_interface.process_event(event, NULL, 0); } @@ -129,7 +141,7 @@ void dependency_default_button_initialize(mas_dependency_plugin_proxy_interface _ecore_wl2_display = ecore_wl2_display_connect(NULL); LOGD("_ecore_wl2_display: %p", _ecore_wl2_display); - g_last_time_point = chrono::system_clock::now(); + g_last_key_pressed = chrono::system_clock::now(); _grab_voice_key(); _add_key_cb(); } @@ -138,4 +150,14 @@ void dependency_default_button_deinitialize() { _delete_key_cb(); _ungrab_voice_key(); +} + +void dependency_default_button_set_voice_key_tap_duration(float duration) +{ + g_voice_key_tap_duration = duration * 1000.0f; // in milliseconds +} + +void dependency_default_button_unset_voice_key_tap_duration(void) +{ + g_voice_key_tap_duration = DEFAULT_KEY_TAP_DURATION; } \ No newline at end of file diff --git a/plugins/wakeup-manager/inc/dependency_resolver.h b/plugins/wakeup-manager/inc/dependency_resolver.h index 75d882e..1804803 100644 --- a/plugins/wakeup-manager/inc/dependency_resolver.h +++ b/plugins/wakeup-manager/inc/dependency_resolver.h @@ -54,6 +54,11 @@ typedef int (*mas_dependency_get_audio_source_type)(char** type); typedef int (*mas_dependency_process_wakeup_engine_command)(const char* engine_name, const char* command); #define MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_CANDIDATE "mas_dependency_process_wakeup_candidate" typedef int (*mas_dependency_process_wakeup_candidate)(const mas_wakeup_event_info* info); +#define MAS_DEPENDENCY_FUNC_SET_VOICE_KEY_TAP_DURATION "mas_dependency_set_voice_key_tap_duration" +typedef int (*mas_dependency_set_voice_key_tap_duration)(float duration); +#define MAS_DEPENDENCY_FUNC_UNSET_VOICE_KEY_TAP_DURATION "mas_dependency_unset_voice_key_tap_duration" +typedef int (*mas_dependency_unset_voice_key_tap_duration)(void); + typedef struct { mas_dependency_initialize initialize; @@ -67,6 +72,8 @@ typedef struct { mas_dependency_get_audio_source_type get_audio_source_type; mas_dependency_process_wakeup_engine_command process_wakeup_engine_command; mas_dependency_process_wakeup_candidate process_wakeup_candidate; + mas_dependency_set_voice_key_tap_duration set_voice_key_tap_duration; + mas_dependency_unset_voice_key_tap_duration unset_voice_key_tap_duration; } mas_dependency_module_interface; int dependency_resolver_initialize(mas_dependency_plugin_proxy_interface interface); @@ -80,6 +87,8 @@ int dependency_resolver_get_audio_format(int* rate, int* channel, int* audio_typ int dependency_resolver_get_audio_source_type(char** type); int dependency_resolver_process_wakeup_engine_command(const char* engine, const char* command); int dependency_resolver_process_wakeup_candidate(mas_wakeup_event_info* info); +int dependency_resolver_set_voice_key_tap_duration(float duration); +int dependency_resolver_unset_voice_key_tap_duration(); mas_dependency_module_interface* dependency_resolver_get_interface(); diff --git a/plugins/wakeup-manager/inc/wakeup_manager.h b/plugins/wakeup-manager/inc/wakeup_manager.h index b010453..0f2d6ed 100644 --- a/plugins/wakeup-manager/inc/wakeup_manager.h +++ b/plugins/wakeup-manager/inc/wakeup_manager.h @@ -18,6 +18,7 @@ #ifndef _WAKEUP_MANAGER_H_ #define _WAKEUP_MANAGER_H_ +#include "multi_assistant_config.h" #include "wakeup_manager_wrapper.h" #include "wakeup_settings.h" #include "wakeup_engine_manager.h" @@ -52,6 +53,7 @@ public: virtual void on_wakeup_engine_command( mas_wakeup_engine_command_target_e target, const char* name, const char* command) = 0; virtual void on_wakeup_service_state_changed(ma_service_state_e state) = 0; + virtual void on_voice_key_status_changed(ma_voice_key_status_e status) = 0; }; class ISettingValueObserver { @@ -104,6 +106,9 @@ public: bool get_audio_source_type(char** type); bool set_language(string language); bool get_voice_key_pressed(); + bool set_voice_key_tap_duration(float duration); + bool unset_voice_key_tap_duration(); + bool set_voice_key_support_mode(VOICE_KEY_SUPPORT_MODE mode); bool set_wake_word_audio_require_flag(bool require); STREAMING_MODE get_streaming_mode(); @@ -132,6 +137,8 @@ public: void feed_audio_data(mas_speech_streaming_event_e event, void* buffer, int len); void set_dependency_module_command(string engine_name, string command); private: + bool change_voice_key_status(ma_voice_key_status_e status); + class CEngineEventObserver : public IEngineEventObserver { public: @@ -218,6 +225,7 @@ private: bool mVoiceKeyPressed{false}; string mCurrentLanguage; string mCurrentDefaultAssistant; + VOICE_KEY_SUPPORT_MODE mCurrentVoiceKeySupportMode; STREAMING_MODE mStreamingMode{STREAMING_MODE::NONE}; Ecore_Timer* mStreamingDurationTimer{nullptr}; diff --git a/plugins/wakeup-manager/inc/wakeup_manager_wrapper.h b/plugins/wakeup-manager/inc/wakeup_manager_wrapper.h index 7857664..cdcaa08 100644 --- a/plugins/wakeup-manager/inc/wakeup_manager_wrapper.h +++ b/plugins/wakeup-manager/inc/wakeup_manager_wrapper.h @@ -58,6 +58,8 @@ typedef void (*wakeup_service_engine_command_cb)(mas_wakeup_engine_command_targe typedef void (*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 state, void* user_data); + typedef struct { int plugin_version; bool ui_panel_enabled; @@ -111,6 +113,12 @@ EXPORT_API int wakeup_manager_get_audio_format(int *rate, int *channel, int *aud EXPORT_API int wakeup_manager_get_audio_source_type(char** type); +EXPORT_API int wakeup_manager_set_voice_key_tap_duration(float duration); + +EXPORT_API int wakeup_manager_unset_voice_key_tap_duration(); + +EXPORT_API int wakeup_manager_set_voice_key_support_mode(int mode); + EXPORT_API int wakeup_manager_set_wake_word_audio_require_flag(bool require); EXPORT_API int wakeup_manager_set_assistant_language(const char* appid, const char *language); @@ -135,6 +143,8 @@ EXPORT_API int wakeup_manager_set_wakeup_engine_command_callback(wakeup_service_ EXPORT_API int wakeup_manager_set_wakeup_service_state_changed_callback(wakeup_service_state_changed_cb callback, void* user_data); +EXPORT_API int wakeup_manager_set_voice_key_status_changed_callback(wakeup_service_voice_key_status_changed_cb callback, void* user_data); + /* Internal API declarations for dependency modules */ int wakeup_manager_feed_audio_data(mas_speech_streaming_event_e event, void* buffer, int len); diff --git a/plugins/wakeup-manager/src/dependency_resolver.cpp b/plugins/wakeup-manager/src/dependency_resolver.cpp index c2537d6..3b2ef19 100644 --- a/plugins/wakeup-manager/src/dependency_resolver.cpp +++ b/plugins/wakeup-manager/src/dependency_resolver.cpp @@ -97,6 +97,12 @@ int dependency_resolver_initialize(mas_dependency_plugin_proxy_interface interfa g_mas_dependency.process_wakeup_candidate = (mas_dependency_process_wakeup_candidate)dlsym(g_handle, MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_CANDIDATE); + g_mas_dependency.set_voice_key_tap_duration = + (mas_dependency_set_voice_key_tap_duration)dlsym(g_handle, + MAS_DEPENDENCY_FUNC_SET_VOICE_KEY_TAP_DURATION); + g_mas_dependency.unset_voice_key_tap_duration = + (mas_dependency_unset_voice_key_tap_duration)dlsym(g_handle, + MAS_DEPENDENCY_FUNC_UNSET_VOICE_KEY_TAP_DURATION); int ret = -1; int dependency_version = 0; @@ -377,3 +383,53 @@ int dependency_resolver_process_wakeup_candidate(mas_wakeup_event_info* info) return ret; } + +int dependency_resolver_set_voice_key_tap_duration(float duration) +{ + int ret = -1; + if (NULL != g_handle) { + mas_dependency_set_voice_key_tap_duration func = g_mas_dependency.set_voice_key_tap_duration; + if (NULL == func) { + MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_SET_VOICE_KEY_TAP_DURATION); + } else { + try { + ret = func(duration); + } catch (const std::exception& e) { + MAS_LOGE("[ERROR] %s of dependency module threw exception : %s", + MAS_DEPENDENCY_FUNC_SET_VOICE_KEY_TAP_DURATION, e.what()); + } + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to set voice key tap duration to %f, ret(%d)", duration, ret); + } + } + } else { + MAS_LOGE("[ERROR] g_handle is not valid"); + } + + return ret; +} + +int dependency_resolver_unset_voice_key_tap_duration() +{ + int ret = -1; + if (NULL != g_handle) { + mas_dependency_unset_voice_key_tap_duration func = g_mas_dependency.unset_voice_key_tap_duration; + if (NULL == func) { + MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_UNSET_VOICE_KEY_TAP_DURATION); + } else { + try { + ret = func(); + } catch (const std::exception& e) { + MAS_LOGE("[ERROR] %s of dependency module threw exception : %s", + MAS_DEPENDENCY_FUNC_UNSET_VOICE_KEY_TAP_DURATION, e.what()); + } + 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; +} \ No newline at end of file diff --git a/plugins/wakeup-manager/src/wakeup_manager.cpp b/plugins/wakeup-manager/src/wakeup_manager.cpp index 25e4e60..d4a0ed3 100644 --- a/plugins/wakeup-manager/src/wakeup_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager.cpp @@ -488,75 +488,94 @@ static long get_current_milliseconds_after_epoch() return value.count(); } +bool CWakeupManager::change_voice_key_status(ma_voice_key_status_e status) { + for (const auto& observer : mWakeupObservers) { + observer->on_voice_key_status_changed(status); + } + if (MA_VOICE_KEY_STATUS_PRESSED == status) { + mVoiceKeyPressed = true; + } else if ( + MA_VOICE_KEY_STATUS_RELEASED_AFTER_PUSH == status || + MA_VOICE_KEY_STATUS_RELEASED_AFTER_TAP == status) { + mVoiceKeyPressed = false; + } +} + bool CWakeupManager::process_plugin_event(mas_plugin_event_e event, void* data, int len) { MWR_LOGD("[ENTER] : %d", event); if (WAKEUP_MANAGER_STATE_INACTIVE == mWakeupManagerState) return false; - // LOCK REQUIRED + bool start_recording = false; + bool stop_recording = false; + if (MAS_PLUGIN_EVENT_VOICE_KEY_PRESSED == event) { - if (mVoiceKeyPressed != true) { - mAudioManager.stop_recording(true); + if (VOICE_KEY_SUPPORT_MODE_NONE != mCurrentVoiceKeySupportMode) { + start_recording = true; + } + change_voice_key_status(MA_VOICE_KEY_STATUS_PRESSED); + } else if (MAS_PLUGIN_EVENT_VOICE_KEY_RELEASED_AFTER_PUSH == event) { + if (VOICE_KEY_SUPPORT_MODE_PUSH_TO_TALK == mCurrentVoiceKeySupportMode || + VOICE_KEY_SUPPORT_MODE_ALL == mCurrentVoiceKeySupportMode) { + stop_recording = true; + } + change_voice_key_status(MA_VOICE_KEY_STATUS_RELEASED_AFTER_PUSH); + } else if (MAS_PLUGIN_EVENT_VOICE_KEY_RELEASED_AFTER_TAP == event) { + if (VOICE_KEY_SUPPORT_MODE_PUSH_TO_TALK == mCurrentVoiceKeySupportMode) { + stop_recording = true; + } + change_voice_key_status(MA_VOICE_KEY_STATUS_RELEASED_AFTER_TAP); + } - stop_streaming_utterance_data(); - stop_streaming_previous_utterance_data(); - stop_streaming_follow_up_data(); + if (start_recording) { + mAudioManager.stop_recording(true); - mAudioManager.clear_audio_data(); - change_manager_state(WAKEUP_MANAGER_STATE_UTTERANCE); + stop_streaming_utterance_data(); + stop_streaming_previous_utterance_data(); + stop_streaming_follow_up_data(); - mVoiceKeyPressed = true; + mAudioManager.clear_audio_data(); + change_manager_state(WAKEUP_MANAGER_STATE_UTTERANCE); - /* Start recorder thread using appropriate recording device */ - mAudioManager.set_recording_session(RECORDING_SESSION_UTTERANCE); - mAudioManager.start_recording(true); + /* Start recorder thread using appropriate recording device */ + mAudioManager.set_recording_session(RECORDING_SESSION_UTTERANCE); + mAudioManager.start_recording(true); - /* Wakeup default assistant */ - /* TODO: apply conversation timeout for selecting assistant here */ - mas_wakeup_event_info wakeup_info; - initialize_wakeup_event_info(&wakeup_info); - /* Make sure to use background data */ - wakeup_info.wakeup_time_valid = true; - wakeup_info.wakeup_end_time = get_current_milliseconds_after_epoch(); - wakeup_info.wakeup_engine = WAKEUP_ENGINE_VOICE_KEY; - - string appid = mWakeupSettings.get_default_assistant_appid(); - wakeup_info.wakeup_appid = appid.c_str(); - MWR_LOGD("wakeup_appid : %s", wakeup_info.wakeup_appid); - - set_last_wakeup_event_info(wakeup_info); - mWakeupEngineManager.set_selected_wakeup_info(wakeup_info); - for (const auto& observer : mWakeupObservers) { - observer->on_wakeup(wakeup_info); - } + /* Wakeup default assistant */ + /* TODO: apply conversation timeout for selecting assistant here */ + mas_wakeup_event_info wakeup_info; + initialize_wakeup_event_info(&wakeup_info); + /* Make sure to use background data */ + wakeup_info.wakeup_time_valid = true; + wakeup_info.wakeup_end_time = get_current_milliseconds_after_epoch(); + wakeup_info.wakeup_engine = WAKEUP_ENGINE_VOICE_KEY; + + wakeup_info.wakeup_appid = mCurrentDefaultAssistant.c_str(); + MWR_LOGD("wakeup_appid : %s", wakeup_info.wakeup_appid); + + set_last_wakeup_event_info(wakeup_info); + mWakeupEngineManager.set_selected_wakeup_info(wakeup_info); + for (const auto& observer : mWakeupObservers) { + observer->on_wakeup(wakeup_info); } - } else if (MAS_PLUGIN_EVENT_VOICE_KEY_RELEASED_AFTER_PUSH == event) { - if (mVoiceKeyPressed != false) { - mAudioManager.finalize_audio_data(); - mVoiceKeyPressed = false; - - if (STREAMING_MODE::UTTERANCE == mStreamingMode) { - change_manager_state(WAKEUP_MANAGER_STATE_PROCESSING); - } else { - change_manager_state(WAKEUP_MANAGER_STATE_LISTENING); - } + } + if (stop_recording) { + mAudioManager.finalize_audio_data(); - if (mWakeupEngineManager.get_audio_data_required()) { - /* Restart recorder thread using appropriate recording device */ - mAudioManager.stop_recording(true); - mAudioManager.set_recording_session(RECORDING_SESSION_WAKE_WORD); - mAudioManager.start_recording(true); - } else { - mAudioManager.stop_recording(true); - } + if (STREAMING_MODE::UTTERANCE == mStreamingMode) { + change_manager_state(WAKEUP_MANAGER_STATE_PROCESSING); + } else { + change_manager_state(WAKEUP_MANAGER_STATE_LISTENING); } - } else if (MAS_PLUGIN_EVENT_VOICE_KEY_RELEASED_AFTER_TAP == event) { - if (mVoiceKeyPressed != false) { - mVoiceKeyPressed = false; + + mAudioManager.stop_recording(true); + mAudioManager.set_recording_session(RECORDING_SESSION_WAKE_WORD); + if (mWakeupEngineManager.get_audio_data_required()) { + /* Restart recorder thread using appropriate recording device */ + mAudioManager.start_recording(true); } } - // UNLOCK REQUIRED MWR_LOGD("[END]"); return true; @@ -830,6 +849,32 @@ bool CWakeupManager::set_wake_word_audio_require_flag(bool require) return true; } +bool CWakeupManager::set_voice_key_tap_duration(float duration) +{ + MWR_LOGD("[ENTER]"); + + dependency_resolver_set_voice_key_tap_duration(duration); + + MWR_LOGD("[END]"); + return true; +} + +bool CWakeupManager::unset_voice_key_tap_duration() +{ + MWR_LOGD("[ENTER]"); + + dependency_resolver_unset_voice_key_tap_duration(); + + MWR_LOGD("[END]"); + return true; +} + +bool CWakeupManager::set_voice_key_support_mode(VOICE_KEY_SUPPORT_MODE mode) +{ + mCurrentVoiceKeySupportMode = mode; + return true; +} + CWakeupPolicy* CWakeupManager::get_wakeup_policy() { return mWakeupPolicy.get(); diff --git a/plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp b/plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp index 5e0b31a..b2395e5 100644 --- a/plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp @@ -51,6 +51,9 @@ static void* g_wakeup_engine_command_user_data; static wakeup_service_state_changed_cb g_wakeup_service_state_changed_cb; static void *g_wakeup_service_state_changed_user_data; +static wakeup_service_voice_key_status_changed_cb g_wakeup_service_voice_key_status_changed_cb; +static void *g_wakeup_service_voice_key_status_changed_user_data; + class CWakeupEventObserver : public IWakeupEventObserver { void on_wakeup(mas_wakeup_event_info wakeup_info) override; @@ -60,6 +63,7 @@ class CWakeupEventObserver : public IWakeupEventObserver void on_wakeup_engine_command( mas_wakeup_engine_command_target_e target, const char* assistant_name, const char* command) override; void on_wakeup_service_state_changed(ma_service_state_e state) override; + void on_voice_key_status_changed(ma_voice_key_status_e status) override; }; class CSettingValueObserver : public ISettingValueObserver @@ -117,6 +121,9 @@ int wakeup_manager_initialize(void) g_wakeup_service_state_changed_cb = NULL; g_wakeup_service_state_changed_user_data = NULL; + g_wakeup_service_voice_key_status_changed_cb = NULL; + g_wakeup_service_voice_key_status_changed_user_data = NULL; + g_wakeup_manager->initialize(); MWR_LOGD("[END]"); @@ -476,6 +483,39 @@ int wakeup_manager_get_audio_source_type(char** type) return 0; } +int wakeup_manager_set_voice_key_tap_duration(float duration) +{ + MWR_LOGD("[ENTER]"); + + if (nullptr == g_wakeup_manager) return -1; + g_wakeup_manager->set_voice_key_tap_duration(duration); + + MWR_LOGD("[END] duration(%f)", duration); + return 0; +} + +int wakeup_manager_unset_voice_key_tap_duration() +{ + MWR_LOGD("[ENTER]"); + + if (nullptr == g_wakeup_manager) return -1; + g_wakeup_manager->unset_voice_key_tap_duration(); + + MWR_LOGD("[END]"); + return 0; +} + +int wakeup_manager_set_voice_key_support_mode(int mode) +{ + MWR_LOGD("[ENTER] : %d", mode); + + if (nullptr == g_wakeup_manager) return -1; + g_wakeup_manager->set_voice_key_support_mode(static_cast(mode)); + + MWR_LOGD("[END]"); + return 0; +} + int wakeup_manager_set_wake_word_audio_require_flag(bool require) { MWR_LOGD("[ENTER] : %d", require); @@ -667,6 +707,22 @@ int wakeup_manager_set_wakeup_service_state_changed_callback(wakeup_service_stat return 0; } +int wakeup_manager_set_voice_key_status_changed_callback(wakeup_service_voice_key_status_changed_cb callback, void* user_data) +{ + MWR_LOGD("[ENTER]"); + + if (NULL == callback) { + MWR_LOGE("[ERROR] Input parameter is NULL"); + return -1; + } + + g_wakeup_service_voice_key_status_changed_cb = callback; + g_wakeup_service_voice_key_status_changed_user_data = user_data; + + MWR_LOGD("[END]"); + return 0; +} + int wakeup_manager_feed_audio_data(mas_speech_streaming_event_e event, void* buffer, int len) { if (nullptr == g_wakeup_manager) return -1; @@ -736,6 +792,13 @@ void CWakeupEventObserver::on_wakeup_service_state_changed(ma_service_state_e st } } +void CWakeupEventObserver::on_voice_key_status_changed(ma_voice_key_status_e status) +{ + if (g_wakeup_service_voice_key_status_changed_cb) { + g_wakeup_service_voice_key_status_changed_cb(status, g_wakeup_service_voice_key_status_changed_user_data); + } +} + void CSettingValueObserver::on_value_changed() { if (g_setting_changed_cb) { diff --git a/src/multi_assistant_config.c b/src/multi_assistant_config.c index 5e7dd0f..c138d89 100644 --- a/src/multi_assistant_config.c +++ b/src/multi_assistant_config.c @@ -65,24 +65,21 @@ int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const } /* alloc assistant info */ - ma_assistant_info_s* temp; - temp = (ma_assistant_info_s*)calloc(1, sizeof(ma_assistant_info_s)); - if (NULL == temp) { - MAS_LOGE("[ERROR] Fail to allocate memory"); - xmlFreeDoc(doc); - return -1; - } - - 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; + 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)) { @@ -91,7 +88,7 @@ int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const 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); + temp.supported_lang[temp.cnt_lang++] = strdup((const char*)key); MAS_LOGD("Language : %s", key); xmlFree(key); } @@ -105,17 +102,17 @@ int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const 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); + 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); + 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++; + temp.cnt_wakeup++; } child_node = child_node->next; @@ -123,28 +120,28 @@ int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const } 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); + 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); + 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); + 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); + temp.wakeup_engine = strdup((const char*)key); MAS_LOGD("Wakeup Engine : %s", key); xmlFree(key); } @@ -152,9 +149,31 @@ int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const key = xmlNodeGetContent(cur); if (key) { if (0 == xmlStrcasecmp(key, "true")) { - temp->custom_ui_option = true; + temp.custom_ui_option = true; } - MAS_LOGD("Use custom UI : %d", temp->custom_ui_option); + 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); } } @@ -163,36 +182,32 @@ int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const } if (callback) { - callback(temp->app_id, temp->name, temp->icon_path, - temp->wakeup_list, temp->wakeup_language, temp->cnt_wakeup, - temp->supported_lang, temp->cnt_lang, - temp->wakeup_engine, temp->custom_ui_option, user_data); + callback(&temp, user_data); } - if (temp->app_id) { - free((void*)temp->app_id); + if (temp.app_id) { + free((void*)temp.app_id); } - if (temp->name) { - free((void*)temp->name); + if (temp.name) { + free((void*)temp.name); } - if (temp->icon_path) { - free((void*)temp->icon_path); + 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_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])); + 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); + if (temp.wakeup_engine) { + free((void*)temp.wakeup_engine); } - free(temp); xmlFreeDoc(doc); return 0; diff --git a/src/multi_assistant_dbus.c b/src/multi_assistant_dbus.c index a09d82d..a7f567c 100644 --- a/src/multi_assistant_dbus.c +++ b/src/multi_assistant_dbus.c @@ -592,7 +592,58 @@ int masc_dbus_service_state_change(int pid, int state) 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); + 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); + + static int count = 0; + 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); } diff --git a/src/multi_assistant_dbus.h b/src/multi_assistant_dbus.h index 4c38cd2..5fa9681 100644 --- a/src/multi_assistant_dbus.h +++ b/src/multi_assistant_dbus.h @@ -43,6 +43,8 @@ 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); diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index 72ef66f..14ed502 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -57,6 +57,8 @@ typedef struct { 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]; @@ -76,6 +78,7 @@ 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; @@ -245,6 +248,9 @@ int mas_client_initialize(int pid) } 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!"); @@ -327,6 +333,16 @@ int mas_client_send_preprocessing_information(int pid) 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; @@ -588,6 +604,10 @@ int mas_ui_client_change_assistant(const char* 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")); /* @@ -615,14 +635,15 @@ int mas_ui_client_change_assistant(const char* appid) return 0; } -int __mas_assistant_info_cb(const char* appid, const char* name, const char* icon_path, - const char* wakeup_list[], const char* wakeup_language[], int cnt_wakeup, - const char* supported_lang[], int cnt_lang, const char* wakeup_engine, - bool custom_ui_option, void* user_data) { +int __mas_assistant_info_cb(ma_assistant_info_s* info, void* user_data) { MAS_LOGD("__mas_assistant_info_cb called"); - if (NULL == appid) { - MAS_LOGD("app_id NULL, returning"); + if (NULL == info) { + MAS_LOGE("info NULL, returning"); + return -1; + } + if (NULL == info->app_id) { + MAS_LOGE("app_id NULL, returning"); return -1; } @@ -638,8 +659,8 @@ int __mas_assistant_info_cb(const char* appid, const char* name, const char* ico 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)", appid); - strncpy(g_maclient_info[index].appid, appid, MAX_APPID_LEN); + 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)) { @@ -647,12 +668,12 @@ int __mas_assistant_info_cb(const char* appid, const char* name, const char* ico } for (loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) { - if (loop < cnt_wakeup && wakeup_list[loop]) { - MAS_LOGD("wakeup_list(%d)(%s)(%s)", loop, wakeup_list[loop], wakeup_language[loop]); - strncpy(g_maclient_info[index].wakeup_word[loop], wakeup_list[loop], MAX_WAKEUP_WORD_LEN); + 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 (wakeup_language[loop]) { - strncpy(g_maclient_info[index].wakeup_language[loop], wakeup_language[loop], MAX_SUPPORTED_LANGUAGE_LEN); + 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); @@ -663,24 +684,29 @@ int __mas_assistant_info_cb(const char* appid, const char* name, const char* ico } for (loop = 0;loop < MAX_SUPPORTED_LANGUAGES_NUM;loop++) { - if (loop < cnt_lang && supported_lang[loop]) { - MAS_LOGD("supported_lang(%d)(%s)", loop, supported_lang[loop]); - strncpy(g_maclient_info[index].supported_language[loop], supported_lang[loop], MAX_SUPPORTED_LANGUAGE_LEN); + 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)", wakeup_engine); - if (wakeup_engine) { - strncpy(g_maclient_info[index].wakeup_engine, wakeup_engine, MAX_APPID_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", appid); + MAS_LOGW("Wakeup engine information not provided for : %s", info->app_id); } - g_maclient_info[index].custom_ui_option = custom_ui_option; + 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"); } @@ -816,6 +842,7 @@ static int init_wakeup(void) 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; @@ -1168,6 +1195,36 @@ int mas_prelaunch_default_assistant() 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 (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++) { diff --git a/src/multi_assistant_service_plugin.c b/src/multi_assistant_service_plugin.c index 6eed1f5..6dedaf4 100644 --- a/src/multi_assistant_service_plugin.c +++ b/src/multi_assistant_service_plugin.c @@ -232,6 +232,8 @@ static bool __validate_streaming_event_order(int pid, mas_speech_streaming_event {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) { @@ -340,6 +342,7 @@ static void __error_cb(int error, const char* err_msg, void* user_data) 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"); } @@ -374,6 +377,17 @@ static void __wakeup_service_state_changed_cb(ma_service_state_e state, void* us 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]"); @@ -468,6 +482,15 @@ int multi_assistant_service_plugin_initialize(void) _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); @@ -498,6 +521,9 @@ int multi_assistant_service_plugin_initialize(void) _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) { @@ -984,6 +1010,63 @@ int multi_assistant_service_plugin_get_recording_audio_source_type(char** type) 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; @@ -1084,6 +1167,12 @@ int multi_assistant_service_plugin_set_callbacks(void) 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; } @@ -1265,3 +1354,20 @@ int multi_assistant_service_plugin_set_wakeup_service_state_changed_callback(wak 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; +} + -- 2.7.4 From e6e5b7b696e329342a55f03e5cc3e8782ff076ae Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Thu, 19 Mar 2020 19:14:04 +0900 Subject: [PATCH 02/16] Bump version to 0.2.28 Related commit - Send voice key status events according to configuration values Change-Id: Ib91ef6e6d00a06ea5067ba74cdf8aea0375c3bfd Signed-off-by: Suyeon Hwang --- org.tizen.multi-assistant-service.xml | 2 +- packaging/org.tizen.multi-assistant-service.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.tizen.multi-assistant-service.xml b/org.tizen.multi-assistant-service.xml index 1af46bc..90b60c8 100644 --- a/org.tizen.multi-assistant-service.xml +++ b/org.tizen.multi-assistant-service.xml @@ -1,5 +1,5 @@ - + Won Nam Jang Sooyeon Kim diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index 31188d2..57438b7 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -1,6 +1,6 @@ Name: org.tizen.multi-assistant-service Summary: Multi assistant service -Version: 0.2.27 +Version: 0.2.28 Release: 1 Group: Graphics & UI Framework/Voice Framework License: Flora-1.1 -- 2.7.4 From 7a442d9eeee22329a9d67fadf570ec6668cc62b3 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 26 Mar 2020 17:59:36 +0900 Subject: [PATCH 03/16] Restart service on package update event for dependent modules Change-Id: I7dd06809a375e5410f9911197d6c409249077961 --- src/multi_assistant_service.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index 14ed502..1375661 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -1426,6 +1426,7 @@ static void _package_manager_event_cb(const char *type, const char *package, pac uid_t uid = getuid (); pkgmgrinfo_pkginfo_h handle = NULL; static bool in_progress = false; + bool should_exit = false; if (!package || !type) return; @@ -1463,23 +1464,28 @@ static void _package_manager_event_cb(const char *type, const char *package, pac } if (1 == ret) { if (PACKAGE_MANAGER_EVENT_STATE_STARTED == event_state) { - LOGD("processing PACKAGE_MANAGER_EVENT_STATE_STARTED event"); + 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) { - LOGD("processing PACKAGE_MANAGER_EVENT_STATE_COMPLETED event"); - if (true == in_progress) { - init_plugin(); - process_activated_setting(); - in_progress = false; + 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; } -- 2.7.4 From 8859fc4df46b066e807970fed7961477770f221d Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Fri, 7 Feb 2020 13:49:44 +0900 Subject: [PATCH 04/16] Add missing function prototypes and also fix incorrect ones Change-Id: I475f1c3db4b01b5f19c421ede74c5e01958448e0 --- inc/multi_assistant_service_client.h | 4 ++++ inc/multi_assistant_service_plugin.h | 4 ++++ src/multi_assistant_dbus_server.h | 4 ++++ src/multi_assistant_service.c | 2 +- src/multi_assistant_service_plugin.c | 2 +- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/inc/multi_assistant_service_client.h b/inc/multi_assistant_service_client.h index bba7085..ecfed68 100644 --- a/inc/multi_assistant_service_client.h +++ b/inc/multi_assistant_service_client.h @@ -57,6 +57,10 @@ int mas_client_set_preprocessing_allow_mode(int pid, int 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_ui_client_initialize(int pid); int mas_ui_client_deinitialize(int pid); diff --git a/inc/multi_assistant_service_plugin.h b/inc/multi_assistant_service_plugin.h index 4f431e6..dc30af4 100644 --- a/inc/multi_assistant_service_plugin.h +++ b/inc/multi_assistant_service_plugin.h @@ -83,6 +83,10 @@ int multi_assistant_service_plugin_get_recording_audio_format(int* rate, int* ch 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_callbacks(void); int multi_assistant_service_plugin_set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data); diff --git a/src/multi_assistant_dbus_server.h b/src/multi_assistant_dbus_server.h index c77c356..b1a52a8 100644 --- a/src/multi_assistant_dbus_server.h +++ b/src/multi_assistant_dbus_server.h @@ -53,6 +53,10 @@ int ma_service_dbus_set_preprocessing_allow_mode(DBusConnection* conn, DBusMessa 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_ui_dbus_initialize(DBusConnection* conn, DBusMessage* msg); int ma_service_ui_dbus_deinitialize(DBusConnection* conn, DBusMessage* msg); diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index 7fb2f3e..a74630a 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -545,7 +545,7 @@ int mas_client_set_assistant_language(int pid, const char* language) pid_appid = buf; } - multi_assistant_service_plugin_assistant_language(pid_appid, language); + multi_assistant_service_plugin_set_assistant_language(pid_appid, language); return 0; } diff --git a/src/multi_assistant_service_plugin.c b/src/multi_assistant_service_plugin.c index bd9de18..123b34b 100644 --- a/src/multi_assistant_service_plugin.c +++ b/src/multi_assistant_service_plugin.c @@ -1027,7 +1027,7 @@ int multi_assistant_service_plugin_set_wake_word_audio_require_flag(const char* return ret; } -int multi_assistant_service_plugin_assistant_language(const char* appid, const char* language) +int multi_assistant_service_plugin_set_assistant_language(const char* appid, const char* language) { int ret = -1; if (NULL != g_handle) { -- 2.7.4 From 50ac9761a2a296d78992aee966b32c205b3411fd Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Wed, 1 Apr 2020 14:28:20 +0900 Subject: [PATCH 05/16] Add missing NULL check for c-string variable Change-Id: I2493b8760fb18132bb1d47cf961be706d226defe --- src/multi_assistant_service.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index 1375661..4f8ef69 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -1203,7 +1203,8 @@ int mas_update_voice_key_support_mode() 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 (strncmp(default_assistant, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) { + 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); -- 2.7.4 From 2c8f1322349059f801ff83fcd07011edd6d87c51 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Fri, 7 Feb 2020 13:52:35 +0900 Subject: [PATCH 06/16] Implement features for adding/removing wake words Change-Id: Ida57e6abd6d0c8b28b79efe84803087035a48a45 --- CMakeLists.txt | 1 + inc/multi_assistant_config.h | 11 +++ inc/multi_assistant_main.h | 2 + inc/multi_assistant_service_client.h | 4 + inc/multi_assistant_service_plugin.h | 5 ++ plugins/wakeup-manager/inc/wakeup_engine_manager.h | 4 + plugins/wakeup-manager/inc/wakeup_manager.h | 1 + .../wakeup-manager/inc/wakeup_manager_wrapper.h | 2 + .../wakeup-manager/src/wakeup_engine_manager.cpp | 24 ++++++ plugins/wakeup-manager/src/wakeup_manager.cpp | 10 +++ .../wakeup-manager/src/wakeup_manager_wrapper.cpp | 17 ++++ src/multi_assistant_config.c | 80 ++++++++++++++++++ src/multi_assistant_dbus.c | 6 ++ src/multi_assistant_dbus_server.c | 66 +++++++++++++++ src/multi_assistant_dbus_server.h | 4 + src/multi_assistant_service.c | 96 +++++++++++++++++++++- src/multi_assistant_service_plugin.c | 24 +++++- 17 files changed, 352 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e4df5c..78e573c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ pkg_check_modules(pkgs REQUIRED capi-appfw-application capi-appfw-app-manager capi-appfw-package-manager + capi-appfw-preference capi-appfw-service-application capi-media-audio-io capi-network-connection diff --git a/inc/multi_assistant_config.h b/inc/multi_assistant_config.h index a5810ac..1cffe06 100644 --- a/inc/multi_assistant_config.h +++ b/inc/multi_assistant_config.h @@ -57,6 +57,11 @@ extern "C" #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, @@ -81,6 +86,12 @@ typedef struct { typedef int (*mas_config_assistant_info_cb)(ma_assistant_info_s* info, void* user_data); int mas_config_get_assistant_info(mas_config_assistant_info_cb callback, void* user_data); +int mas_config_load_custom_wake_words(const char* app_id, + char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN], + char wakeup_language[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]); +int mas_config_save_custom_wake_words(const char* app_id, + char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN], + char wakeup_language[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]); #ifdef __cplusplus } diff --git a/inc/multi_assistant_main.h b/inc/multi_assistant_main.h index 81018ac..32ab00b 100644 --- a/inc/multi_assistant_main.h +++ b/inc/multi_assistant_main.h @@ -67,6 +67,8 @@ #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" diff --git a/inc/multi_assistant_service_client.h b/inc/multi_assistant_service_client.h index 0c93cf6..82b0424 100644 --- a/inc/multi_assistant_service_client.h +++ b/inc/multi_assistant_service_client.h @@ -85,6 +85,10 @@ 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); diff --git a/inc/multi_assistant_service_plugin.h b/inc/multi_assistant_service_plugin.h index de04670..f7009c2 100644 --- a/inc/multi_assistant_service_plugin.h +++ b/inc/multi_assistant_service_plugin.h @@ -43,6 +43,8 @@ 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); @@ -119,6 +121,8 @@ typedef int (*wakeup_manager_deinitialize)(void); 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" @@ -197,6 +201,7 @@ typedef struct { 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; diff --git a/plugins/wakeup-manager/inc/wakeup_engine_manager.h b/plugins/wakeup-manager/inc/wakeup_engine_manager.h index fb668a9..4729dc5 100644 --- a/plugins/wakeup-manager/inc/wakeup_engine_manager.h +++ b/plugins/wakeup-manager/inc/wakeup_engine_manager.h @@ -50,6 +50,8 @@ typedef int (*wakeup_engine_activate)(void); typedef int (*wakeup_engine_deactivate)(void); #define MA_WAKEUP_ENGINE_FUNC_ADD_WAKEUP_WORD "wakeup_engine_add_wakeup_word" typedef int (*wakeup_engine_add_wakeup_word)(const char* appid, const char* wakeup_word, const char* language); +#define MA_WAKEUP_ENGINE_FUNC_REMOVE_WAKEUP_WORD "wakeup_engine_remove_wakeup_word" +typedef int (*wakeup_engine_remove_wakeup_word)(const char* appid, const char* wakeup_word, const char* language); #define MA_WAKEUP_ENGINE_FUNC_ADD_LANGUAGE "wakeup_engine_add_language" typedef int (*wakeup_engine_add_language)(const char* appid, const char* language); #define MA_WAKEUP_ENGINE_FUNC_SET_LANGUAGE "wakeup_engine_set_language" @@ -99,6 +101,7 @@ typedef struct { wakeup_engine_activate activate; wakeup_engine_deactivate deactivate; wakeup_engine_add_wakeup_word add_wakeup_word; + wakeup_engine_remove_wakeup_word remove_wakeup_word; wakeup_engine_add_language add_language; wakeup_engine_set_language set_language; wakeup_engine_update_manager_state update_manager_state; @@ -170,6 +173,7 @@ public: void engine_add_target_assistant(string engine_name, string appid); void engine_add_wakeup_word(string appid, string wakeup_word, string language); + void engine_remove_wakeup_word(string appid, string wakeup_word, string language); void engine_set_assistant_specific_command(string appid, string command); void engine_set_dependency_module_command(string engine_name, string command); void engine_feed_audio_data(long time, void* data, int len); diff --git a/plugins/wakeup-manager/inc/wakeup_manager.h b/plugins/wakeup-manager/inc/wakeup_manager.h index 0f2d6ed..8b52f89 100644 --- a/plugins/wakeup-manager/inc/wakeup_manager.h +++ b/plugins/wakeup-manager/inc/wakeup_manager.h @@ -89,6 +89,7 @@ public: bool add_assistant_language(string appid, string language); bool add_assistant_wakeup_word(string appid, string wakeup_word, string language); + bool remove_assistant_wakeup_word(string appid, string wakeup_word, string language); bool set_assistant_wakeup_engine(string appid, string engine); bool set_assistant_language(string appid, string language); diff --git a/plugins/wakeup-manager/inc/wakeup_manager_wrapper.h b/plugins/wakeup-manager/inc/wakeup_manager_wrapper.h index cdcaa08..45ac567 100644 --- a/plugins/wakeup-manager/inc/wakeup_manager_wrapper.h +++ b/plugins/wakeup-manager/inc/wakeup_manager_wrapper.h @@ -73,6 +73,8 @@ EXPORT_API int wakeup_manager_get_settings(ma_plugin_settings **settings, size_t EXPORT_API int wakeup_manager_add_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language); +EXPORT_API int wakeup_manager_remove_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language); + EXPORT_API int wakeup_manager_add_assistant_language(const char* appid, const char* language); EXPORT_API int wakeup_manager_set_assistant_wakeup_engine(const char* appid, const char *engine); diff --git a/plugins/wakeup-manager/src/wakeup_engine_manager.cpp b/plugins/wakeup-manager/src/wakeup_engine_manager.cpp index 642b0f8..1b06f8b 100644 --- a/plugins/wakeup-manager/src/wakeup_engine_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_engine_manager.cpp @@ -569,6 +569,27 @@ void CWakeupEngineManager::engine_add_wakeup_word(string appid, string wakeup_wo MWR_LOGE("[ERROR] wakeup engine %s threw exception : %s", info.engine_name.c_str(), e.what()); } + } else { + MWR_LOGE("Wakeup Engine does not provide add_wakeup_word"); + } + } + } +} + +void CWakeupEngineManager::engine_remove_wakeup_word(string appid, string wakeup_word, string language) +{ + for (const auto& info : mEngineInfo) { + bool found = contains(info.assistant_list, appid); + if (found) { + if (info.interface.remove_wakeup_word) { + try { + info.interface.remove_wakeup_word(appid.c_str(), wakeup_word.c_str(), language.c_str()); + } catch (const std::exception& e) { + MWR_LOGE("[ERROR] wakeup engine %s threw exception : %s", + info.engine_name.c_str(), e.what()); + } + } else { + MWR_LOGE("Wakeup Engine does not provide remove_wakeup_word"); } } } @@ -776,6 +797,9 @@ void CWakeupEngineManager::add_engine(string name, string path) info.interface.add_wakeup_word = (wakeup_engine_add_wakeup_word)dlsym(info.engine_handle, MA_WAKEUP_ENGINE_FUNC_ADD_WAKEUP_WORD); + info.interface.remove_wakeup_word = + (wakeup_engine_remove_wakeup_word)dlsym(info.engine_handle, + MA_WAKEUP_ENGINE_FUNC_REMOVE_WAKEUP_WORD); info.interface.add_language = (wakeup_engine_add_language)dlsym(info.engine_handle, MA_WAKEUP_ENGINE_FUNC_ADD_LANGUAGE); diff --git a/plugins/wakeup-manager/src/wakeup_manager.cpp b/plugins/wakeup-manager/src/wakeup_manager.cpp index ab2b8a4..bce479c 100644 --- a/plugins/wakeup-manager/src/wakeup_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager.cpp @@ -259,6 +259,16 @@ bool CWakeupManager::add_assistant_wakeup_word(string appid, string wakeup_word, return true; } +bool CWakeupManager::remove_assistant_wakeup_word(string appid, string wakeup_word, string language) +{ + MWR_LOGD("[ENTER]"); + + mWakeupEngineManager.engine_remove_wakeup_word(appid, wakeup_word, language); + + MWR_LOGD("[END]"); + return true; +} + bool CWakeupManager::set_assistant_wakeup_engine(string appid, string engine) { MWR_LOGD("[ENTER]"); diff --git a/plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp b/plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp index 6e30433..dd51979 100644 --- a/plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager_wrapper.cpp @@ -189,6 +189,23 @@ int wakeup_manager_add_assistant_wakeup_word(const char* appid, const char* wake return 0; } +int wakeup_manager_remove_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language) +{ + MWR_LOGD("[ENTER]"); + + if (NULL == appid || NULL == wakeup_word) { + MWR_LOGD("[ERROR] Parameter is invalid, appid(%s), wakeup_word(%s), language(%s)", appid, wakeup_word, language); + return -1; + } + + if (nullptr == g_wakeup_manager) return -1; + g_wakeup_manager->remove_assistant_wakeup_word( + string{appid}, string{wakeup_word}, (language ? string{language} : string{})); + + MWR_LOGD("[END]"); + return 0; +} + int wakeup_manager_add_assistant_language(const char* appid, const char* language) { MWR_LOGD("[ENTER]"); diff --git a/src/multi_assistant_config.c b/src/multi_assistant_config.c index c138d89..056987f 100644 --- a/src/multi_assistant_config.c +++ b/src/multi_assistant_config.c @@ -237,3 +237,83 @@ int mas_config_get_assistant_info(mas_config_assistant_info_cb callback, void* u return 0; } + +int mas_config_load_custom_wake_words(const char* app_id, + char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN], + char wakeup_language[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[index], word_start, MAX_WAKEUP_WORD_LEN - 1); + strncpy(wakeup_language[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[index], wakeup_language[index]); + index++; + } + + return 0; +} + +int mas_config_save_custom_wake_words(const char* app_id, + char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN], + char wakeup_language[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[loop]) > 0) { + int wakeup_words_len = strlen(wakeup_words); + strncat(wakeup_words, wakeup_word[loop], sizeof(wakeup_words) - wakeup_words_len - 1); + strcat(wakeup_words, "|"); + int wakeup_languages_len = strlen(wakeup_languages); + strncat(wakeup_languages, wakeup_language[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; +} diff --git a/src/multi_assistant_dbus.c b/src/multi_assistant_dbus.c index a7f567c..fde0cde 100644 --- a/src/multi_assistant_dbus.c +++ b/src/multi_assistant_dbus.c @@ -1082,6 +1082,12 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle } 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); diff --git a/src/multi_assistant_dbus_server.c b/src/multi_assistant_dbus_server.c index 136606b..d4a3767 100644 --- a/src/multi_assistant_dbus_server.c +++ b/src/multi_assistant_dbus_server.c @@ -694,6 +694,72 @@ int ma_service_dbus_set_assistant_language(DBusConnection* conn, DBusMessage* ms return 0; } +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 0; +} + +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 0; +} + int ma_service_ui_dbus_initialize(DBusConnection* conn, DBusMessage* msg) { DBusError err; diff --git a/src/multi_assistant_dbus_server.h b/src/multi_assistant_dbus_server.h index b1a52a8..24d1759 100644 --- a/src/multi_assistant_dbus_server.h +++ b/src/multi_assistant_dbus_server.h @@ -57,6 +57,10 @@ int ma_service_dbus_set_wake_word_audio_require_flag(DBusConnection* conn, DBusM 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); diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index 2ca3a8c..dde11d9 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -45,10 +45,6 @@ static const char *g_current_lang = "en_US"; #define WAKEUP_SETTINGS_KEY_PRELAUNCH_MODE "db/multi-assistant/prelaunch_mode" #define MAX_MACLIENT_INFO_NUM 16 -#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 struct { bool used; char appid[MAX_APPID_LEN]; @@ -573,6 +569,96 @@ int mas_client_set_assistant_language(int pid, const char* 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)) { + bool found = false; + bool duplicated = false; + for (int innerLoop = 0;false == found && false == duplicated && + innerLoop < MAX_WAKEUP_WORDS_NUM;innerLoop++) { + if (0 == strncmp(g_maclient_info[loop].wakeup_word[innerLoop], wake_word, MAX_WAKEUP_WORD_LEN) && + 0 == strncmp(g_maclient_info[loop].wakeup_language[innerLoop], language, MAX_SUPPORTED_LANGUAGE_LEN)) { + duplicated = true; + } + if (0 == strlen(g_maclient_info[loop].wakeup_word[innerLoop])) { + strncpy(g_maclient_info[loop].wakeup_word[innerLoop], wake_word, MAX_WAKEUP_WORD_LEN); + g_maclient_info[loop].wakeup_word[innerLoop][MAX_WAKEUP_WORD_LEN - 1] = '\0'; + strncpy(g_maclient_info[loop].wakeup_language[innerLoop], language, MAX_SUPPORTED_LANGUAGE_LEN); + g_maclient_info[loop].wakeup_word[innerLoop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0'; + found = true; + } + } + if (found && !duplicated) { + mas_config_save_custom_wake_words(pid_appid, + g_maclient_info[loop].wakeup_word, + g_maclient_info[loop].wakeup_language); + } else { + if (duplicated) { + LOGE("The wakeup word already exists!"); + } else { + LOGE("No empty slot found while trying to add new wake word!"); + } + 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)) { + for (int innerLoop = 0;innerLoop < MAX_WAKEUP_WORDS_NUM;innerLoop++) { + if (0 == strncmp(g_maclient_info[loop].wakeup_word[innerLoop], wake_word, MAX_WAKEUP_WORD_LEN) && + 0 == strncmp(g_maclient_info[loop].wakeup_language[innerLoop], language, MAX_SUPPORTED_LANGUAGE_LEN)) { + for (int shift = innerLoop;shift < MAX_WAKEUP_WORDS_NUM - 1;shift++) { + strncpy(g_maclient_info[loop].wakeup_word[shift], + g_maclient_info[loop].wakeup_word[shift + 1], MAX_WAKEUP_WORD_LEN); + g_maclient_info[loop].wakeup_word[shift][MAX_WAKEUP_WORD_LEN - 1] = '\0'; + strncpy(g_maclient_info[loop].wakeup_language[shift], + g_maclient_info[loop].wakeup_language[shift + 1], MAX_SUPPORTED_LANGUAGE_LEN); + g_maclient_info[loop].wakeup_word[shift][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0'; + } + memset(g_maclient_info[loop].wakeup_word[MAX_WAKEUP_WORDS_NUM - 1], + 0x00, sizeof(g_maclient_info[loop].wakeup_word)); + memset(g_maclient_info[loop].wakeup_language[MAX_WAKEUP_WORDS_NUM - 1], + 0x00, sizeof(g_maclient_info[loop].wakeup_language)); + + innerLoop--; /* Just in case there are duplicated items */ + } + } + 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); @@ -747,6 +833,8 @@ static int init_plugin(void) int inner_loop; if (g_maclient_info[loop].used && 0 < strlen(g_maclient_info[loop].appid)) { + 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, diff --git a/src/multi_assistant_service_plugin.c b/src/multi_assistant_service_plugin.c index 7a73513..afc7ecb 100644 --- a/src/multi_assistant_service_plugin.c +++ b/src/multi_assistant_service_plugin.c @@ -416,6 +416,9 @@ int multi_assistant_service_plugin_initialize(void) _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); @@ -636,7 +639,26 @@ int multi_assistant_service_plugin_add_assistant_wakeup_word(const char* appid, } else { ret = func(appid, wakeup_word, language); if (0 != ret) { - MAS_LOGE("[ERROR] Fail to set wakeup word(%s)(%s)(%s), ret(%d)", appid, wakeup_word, language, 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 { -- 2.7.4 From 24755398976c62971b423523131de7c4993636ee Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Wed, 13 Nov 2019 15:43:13 +0900 Subject: [PATCH 07/16] Change c files to cpp files and fix build errors Change-Id: Ifd15030aa1579c2cfe8a780a77537656fda2fee9 --- CMakeLists.txt | 11 +-- inc/multi_assistant_config.h | 1 + inc/multi_assistant_main.h | 18 ++--- inc/multi_assistant_service_client.h | 16 ++++- inc/multi_assistant_service_plugin.h | 11 +++ packaging/org.tizen.multi-assistant-service.spec | 5 +- src/main.cpp | 78 ++++++++++++++++++++++ ...sistant_config.c => multi_assistant_config.cpp} | 7 +- ...i_assistant_dbus.c => multi_assistant_dbus.cpp} | 14 ++-- src/multi_assistant_dbus.h | 4 +- ...us_server.c => multi_assistant_dbus_server.cpp} | 47 +++++++------ ...stant_service.c => multi_assistant_service.cpp} | 65 +++--------------- ...plugin.c => multi_assistant_service_plugin.cpp} | 16 +++-- 13 files changed, 175 insertions(+), 118 deletions(-) create mode 100644 src/main.cpp rename src/{multi_assistant_config.c => multi_assistant_config.cpp} (98%) rename src/{multi_assistant_dbus.c => multi_assistant_dbus.cpp} (99%) rename src/{multi_assistant_dbus_server.c => multi_assistant_dbus_server.cpp} (98%) rename src/{multi_assistant_service.c => multi_assistant_service.cpp} (96%) rename src/{multi_assistant_service_plugin.c => multi_assistant_service_plugin.cpp} (98%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 78e573c..e874905 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,11 +62,12 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc) SET(SRCS - src/multi_assistant_config.c - src/multi_assistant_service.c - src/multi_assistant_service_plugin.c - src/multi_assistant_dbus.c - src/multi_assistant_dbus_server.c + 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 ) ADD_EXECUTABLE(${BINNAME} ${SRCS}) diff --git a/inc/multi_assistant_config.h b/inc/multi_assistant_config.h index 1cffe06..c073792 100644 --- a/inc/multi_assistant_config.h +++ b/inc/multi_assistant_config.h @@ -85,6 +85,7 @@ typedef struct { } ma_assistant_info_s; typedef int (*mas_config_assistant_info_cb)(ma_assistant_info_s* info, void* user_data); + int mas_config_get_assistant_info(mas_config_assistant_info_cb callback, void* user_data); int mas_config_load_custom_wake_words(const char* app_id, char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN], diff --git a/inc/multi_assistant_main.h b/inc/multi_assistant_main.h index 32ab00b..643d75b 100644 --- a/inc/multi_assistant_main.h +++ b/inc/multi_assistant_main.h @@ -34,17 +34,17 @@ /************************************************************************************** *** 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_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_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" +#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 diff --git a/inc/multi_assistant_service_client.h b/inc/multi_assistant_service_client.h index 82b0424..9127e3a 100644 --- a/inc/multi_assistant_service_client.h +++ b/inc/multi_assistant_service_client.h @@ -19,7 +19,8 @@ #define _MULTI_ASSISTANT_SERVICE_H_ #include - +#include +#include #ifdef __cplusplus extern "C" { @@ -57,6 +58,12 @@ int mas_client_get_audio_format(int pid, int* rate, int* channel, int* audio_typ 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); @@ -75,7 +82,7 @@ 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, int mode, const char* appid); +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); @@ -119,6 +126,8 @@ 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); @@ -127,6 +136,9 @@ 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 } diff --git a/inc/multi_assistant_service_plugin.h b/inc/multi_assistant_service_plugin.h index f7009c2..1639e45 100644 --- a/inc/multi_assistant_service_plugin.h +++ b/inc/multi_assistant_service_plugin.h @@ -18,6 +18,7 @@ #ifndef _MULTI_ASSISTANT_SERVICE_PLUGIN_H_ #define _MULTI_ASSISTANT_SERVICE_PLUGIN_H_ +#include #include #include @@ -105,8 +106,18 @@ int multi_assistant_service_plugin_set_follow_up_streaming_callback(wakeup_servi 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/") diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index 2cf2589..4a5faeb 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -26,7 +26,6 @@ BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(multi-assistant) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(pkgmgr-info) - BuildRequires: boost-system BuildRequires: boost-thread BuildRequires: cmake @@ -52,8 +51,8 @@ LDFLAGS="$LDFLAGS -Wl,-z -Wl,nodelete" export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" %endif -export CFLAGS+=" -Wno-format-truncation -Wno-format-overflow" -export CXXFLAGS+=" -Wno-format-truncation -Wno-format-overflow" +export CFLAGS+=" -Wno-format-truncation -Wno-stringop-truncation -Wno-format-overflow" +export CXXFLAGS+=" -Wno-format-truncation -Wno-stringop-truncation -Wno-format-overflow" export LDFLAGS %cmake \ diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..6422575 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,78 @@ +/* + * 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 +#include + +#include "multi_assistant_service_client.h" + +static bool service_app_create(void *data) +{ + return app_create(data); +} + +static void service_app_terminate(void *data) +{ + + return app_terminate(data); +} + +static void service_app_control(app_control_h app_control, void *data) +{ + // Todo: add your code here. + return; +} + +static void service_app_lang_changed(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_LANGUAGE_CHANGED*/ + return; +} + +static void service_app_region_changed(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_REGION_FORMAT_CHANGED*/ +} + +static void service_app_low_battery(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_LOW_BATTERY*/ +} + +static void service_app_low_memory(app_event_info_h event_info, void *user_data) +{ + /*APP_EVENT_LOW_MEMORY*/ +} + +int main(int argc, char* argv[]) +{ + char ad[50] = {0,}; + service_app_lifecycle_callback_s event_callback; + app_event_handler_h handlers[5] = {NULL, }; + + event_callback.create = service_app_create; + event_callback.terminate = service_app_terminate; + event_callback.app_control = service_app_control; + + service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad); + service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad); + service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad); + service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad); + + int ret = service_app_main(argc, argv, &event_callback, ad); + LOGI("Main function exits with : %d", ret); + return ret; +} diff --git a/src/multi_assistant_config.c b/src/multi_assistant_config.cpp similarity index 98% rename from src/multi_assistant_config.c rename to src/multi_assistant_config.cpp index 056987f..ba72431 100644 --- a/src/multi_assistant_config.c +++ b/src/multi_assistant_config.cpp @@ -17,6 +17,9 @@ #include #include #include +#include + +#include #include "multi_assistant_config.h" #include "multi_assistant_main.h" @@ -148,7 +151,7 @@ int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_CUSTOM_UI)) { key = xmlNodeGetContent(cur); if (key) { - if (0 == xmlStrcasecmp(key, "true")) { + if (0 == xmlStrcasecmp(key, reinterpret_cast("true"))) { temp.custom_ui_option = true; } MAS_LOGD("Use custom UI : %d", temp.custom_ui_option); @@ -316,4 +319,4 @@ int mas_config_save_custom_wake_words(const char* app_id, preference_set_string("custom_wakeup_words", wakeup_words); preference_set_string("custom_wakeup_languages", wakeup_languages); return 0; -} +} \ No newline at end of file diff --git a/src/multi_assistant_dbus.c b/src/multi_assistant_dbus.cpp similarity index 99% rename from src/multi_assistant_dbus.c rename to src/multi_assistant_dbus.cpp index fde0cde..4f04de3 100644 --- a/src/multi_assistant_dbus.c +++ b/src/multi_assistant_dbus.cpp @@ -21,6 +21,7 @@ #include #include "multi_assistant_main.h" +#include "multi_assistant_service_client.h" #include "multi_assistant_dbus_server.h" #include "multi_assistant_dbus.h" @@ -214,7 +215,7 @@ void masc_message_port_error(int error) "MESSAGE_PORT_ERROR_UNKNOWN"); } -int masc_dbus_send_streaming_audio_data(int pid, int event, unsigned char* data, unsigned int data_size) +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; @@ -305,7 +306,6 @@ int masc_dbus_active_state_change(int pid, int state) MA_CLIENT_SERVICE_INTERFACE, MAS_METHOD_ACTIVE_STATE_CHANGE); - static int count = 0; if (NULL == msg) { MAS_LOGE(">>>> Request mas send activate message : Fail to make message"); return -1; // MAS_ERROR_OPERATION_FAILED; @@ -356,7 +356,6 @@ int masc_dbus_send_preprocessing_information(int pid, const char* app_id) MA_CLIENT_SERVICE_INTERFACE, MAS_METHOD_SEND_PREPROCESSING_INFORMATION); - static int count = 0; if (NULL == msg) { MAS_LOGE(">>>> Request mas send preprocessing assistant information : Fail to make message"); return -1; // MAS_ERROR_OPERATION_FAILED; @@ -402,7 +401,6 @@ int masc_dbus_send_preprocessing_information(int pid, const char* app_id) int masc_dbus_send_streaming_section_changed(int pid, int section) { - static int serial = 0; bundle *b = bundle_create(); streaming_data_header header; @@ -451,7 +449,6 @@ int masc_dbus_send_preprocessing_result(int pid, bool result) MA_CLIENT_SERVICE_INTERFACE, MAS_METHOD_SEND_PREPROCESSING_RESULT); - static int count = 0; if (NULL == msg) { MAS_LOGE(">>>> Request mas send preprocessing result : Fail to make message"); return -1; // MAS_ERROR_OPERATION_FAILED; @@ -505,7 +502,6 @@ int masc_dbus_send_wakeup_engine_command(int pid, const char* command) MA_CLIENT_SERVICE_INTERFACE, MAS_METHOD_SEND_WAKEUP_ENGINE_COMMAND); - static int count = 0; if (NULL == msg) { MAS_LOGE(">>>> Request mas send wakeup engine command : Fail to make message"); return -1; // MAS_ERROR_OPERATION_FAILED; @@ -570,7 +566,6 @@ int masc_dbus_service_state_change(int pid, int state) MA_CLIENT_SERVICE_INTERFACE, MAS_METHOD_SERVICE_STATE_CHANGE); - static int count = 0; if (NULL == msg) { MAS_LOGE(">>>> Request mas send service state message : Fail to make message"); return -1; // MAS_ERROR_OPERATION_FAILED; @@ -621,7 +616,6 @@ int masc_dbus_voice_key_status_change(int pid, int status) MA_CLIENT_SERVICE_INTERFACE, MAS_METHOD_VOICE_KEY_STATUS_CHANGE); - static int count = 0; if (NULL == msg) { MAS_LOGE(">>>> Request mas send voice key status change message : Fail to make message"); return -1; // MAS_ERROR_OPERATION_FAILED; @@ -841,7 +835,7 @@ int masc_ui_dbus_send_result(int pid, const char* display_text, const char* utte return 0; } -int masc_ui_dbus_change_assistant(char* app_id) +int masc_ui_dbus_change_assistant(const char* app_id) { if (0 != __dbus_check()) { return -1; //MAS_ERROR_OPERATION_FAILED; @@ -1236,4 +1230,4 @@ int mas_dbus_close_connection() __mas_dbus_connection_free(); return 0; -} +} \ No newline at end of file diff --git a/src/multi_assistant_dbus.h b/src/multi_assistant_dbus.h index 5fa9681..6d20348 100644 --- a/src/multi_assistant_dbus.h +++ b/src/multi_assistant_dbus.h @@ -29,7 +29,7 @@ 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, unsigned char* data, unsigned int data_size); +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); @@ -51,7 +51,7 @@ 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(char* app_id); +int masc_ui_dbus_change_assistant(const char* app_id); int masc_ui_dbus_send_error_message(int reason, const char* err_msg); diff --git a/src/multi_assistant_dbus_server.c b/src/multi_assistant_dbus_server.cpp similarity index 98% rename from src/multi_assistant_dbus_server.c rename to src/multi_assistant_dbus_server.cpp index d4a3767..ae97bd2 100644 --- a/src/multi_assistant_dbus_server.c +++ b/src/multi_assistant_dbus_server.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include + #include "multi_assistant_main.h" #include "multi_assistant_dbus.h" #include "multi_assistant_dbus_server.h" @@ -91,7 +93,7 @@ int ma_service_dbus_initialize(DBusConnection* conn, DBusMessage* msg) MAS_LOGE("[OUT ERROR] mas initialize : Fail to create reply message!!"); } - return 0; + return ret; } int ma_service_dbus_deinitialize(DBusConnection* conn, DBusMessage* msg) @@ -196,7 +198,7 @@ int ma_service_dbus_get_audio_format(DBusConnection* conn, DBusMessage* msg) MAS_LOGE("[OUT ERROR] tts default voice : Fail to create reply message!!"); } - return 0; + return ret; } int ma_service_dbus_get_audio_source_type(DBusConnection* conn, DBusMessage* msg) @@ -258,7 +260,7 @@ int ma_service_dbus_get_audio_source_type(DBusConnection* conn, DBusMessage* msg if (temp_type) free(temp_type); - return 0; + return ret; } int ma_service_dbus_send_asr_result(DBusConnection* conn, DBusMessage* msg) @@ -314,7 +316,7 @@ int ma_service_dbus_send_asr_result(DBusConnection* conn, DBusMessage* msg) MAS_LOGD("<<<<<"); MAS_LOGD(" "); - return 0; + return ret; } int ma_service_dbus_send_result(DBusConnection* conn, DBusMessage* msg) @@ -373,7 +375,7 @@ int ma_service_dbus_send_result(DBusConnection* conn, DBusMessage* msg) MAS_LOGD("<<<<<"); MAS_LOGD(" "); - return 0; + return ret; } int ma_service_dbus_send_recognition_result(DBusConnection* conn, DBusMessage* msg) @@ -404,7 +406,7 @@ int ma_service_dbus_send_recognition_result(DBusConnection* conn, DBusMessage* m MAS_LOGD("<<<<<"); MAS_LOGD(" "); - return 0; + return ret; } int ma_service_dbus_start_streaming_audio_data(DBusConnection* conn, DBusMessage* msg) @@ -435,7 +437,7 @@ int ma_service_dbus_start_streaming_audio_data(DBusConnection* conn, DBusMessage MAS_LOGD("<<<<<"); MAS_LOGD(" "); - return 0; + return ret; } int ma_service_dbus_stop_streaming_audio_data(DBusConnection* conn, DBusMessage* msg) @@ -466,7 +468,7 @@ int ma_service_dbus_stop_streaming_audio_data(DBusConnection* conn, DBusMessage* MAS_LOGD("<<<<<"); MAS_LOGD(" "); - return 0; + return ret; } int ma_service_dbus_update_voice_feedback_state(DBusConnection* conn, DBusMessage* msg) @@ -497,7 +499,7 @@ int ma_service_dbus_update_voice_feedback_state(DBusConnection* conn, DBusMessag MAS_LOGD("<<<<<"); MAS_LOGD(" "); - return 0; + return ret; } int ma_service_dbus_send_assistant_specific_command(DBusConnection* conn, DBusMessage* msg) @@ -528,7 +530,7 @@ int ma_service_dbus_send_assistant_specific_command(DBusConnection* conn, DBusMe MAS_LOGD("<<<<<"); MAS_LOGD(" "); - return 0; + return ret; } int ma_service_dbus_set_background_volume(DBusConnection* conn, DBusMessage* msg) @@ -559,7 +561,7 @@ int ma_service_dbus_set_background_volume(DBusConnection* conn, DBusMessage* msg MAS_LOGD("<<<<<"); MAS_LOGD(" "); - return 0; + return ret; } int ma_service_dbus_set_preprocessing_allow_mode(DBusConnection* conn, DBusMessage* msg) @@ -590,7 +592,8 @@ int ma_service_dbus_set_preprocessing_allow_mode(DBusConnection* conn, DBusMessa 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, mode, temp_app_id); + ret = mas_client_set_preprocessing_allow_mode(pid, + static_cast(mode), temp_app_id); if (NULL != temp_app_id) free(temp_app_id); } @@ -598,7 +601,7 @@ int ma_service_dbus_set_preprocessing_allow_mode(DBusConnection* conn, DBusMessa MAS_LOGD("<<<<<"); MAS_LOGD(" "); - return 0; + return ret; } int ma_service_dbus_send_preprocessing_result(DBusConnection* conn, DBusMessage* msg) @@ -629,7 +632,7 @@ int ma_service_dbus_send_preprocessing_result(DBusConnection* conn, DBusMessage* MAS_LOGD("<<<<<"); MAS_LOGD(" "); - return 0; + return ret; } int ma_service_dbus_set_wake_word_audio_require_flag(DBusConnection* conn, DBusMessage* msg) @@ -660,7 +663,7 @@ int ma_service_dbus_set_wake_word_audio_require_flag(DBusConnection* conn, DBusM MAS_LOGD("<<<<<"); MAS_LOGD(" "); - return 0; + return ret; } int ma_service_dbus_set_assistant_language(DBusConnection* conn, DBusMessage* msg) @@ -691,7 +694,7 @@ int ma_service_dbus_set_assistant_language(DBusConnection* conn, DBusMessage* ms MAS_LOGD("<<<<<"); MAS_LOGD(" "); - return 0; + return ret; } int ma_service_dbus_add_wake_word(DBusConnection* conn, DBusMessage* msg) @@ -724,7 +727,7 @@ int ma_service_dbus_add_wake_word(DBusConnection* conn, DBusMessage* msg) MAS_LOGD("<<<<<"); MAS_LOGD(" "); - return 0; + return ret; } int ma_service_dbus_remove_wake_word(DBusConnection* conn, DBusMessage* msg) @@ -757,7 +760,7 @@ int ma_service_dbus_remove_wake_word(DBusConnection* conn, DBusMessage* msg) MAS_LOGD("<<<<<"); MAS_LOGD(" "); - return 0; + return ret; } int ma_service_ui_dbus_initialize(DBusConnection* conn, DBusMessage* msg) @@ -808,7 +811,7 @@ int ma_service_ui_dbus_initialize(DBusConnection* conn, DBusMessage* msg) MAS_LOGE("[OUT ERROR] mas ui initialize : Fail to create reply message!!"); } - return 0; + return ret; } int ma_service_ui_dbus_deinitialize(DBusConnection* conn, DBusMessage* msg) @@ -859,7 +862,7 @@ int ma_service_ui_dbus_deinitialize(DBusConnection* conn, DBusMessage* msg) MAS_LOGE("[OUT ERROR] mas ui deinitialize : Fail to create reply message!!"); } - return 0; + return ret; } int ma_service_ui_dbus_change_assistant(DBusConnection* conn, DBusMessage* msg) @@ -912,5 +915,5 @@ int ma_service_ui_dbus_change_assistant(DBusConnection* conn, DBusMessage* msg) MAS_LOGD("<<<<<"); MAS_LOGD(" "); - return 0; -} + return ret; +} \ No newline at end of file diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.cpp similarity index 96% rename from src/multi_assistant_service.c rename to src/multi_assistant_service.cpp index dde11d9..34df15f 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -128,7 +129,7 @@ ma_client_s* ma_client_find_by_appid(const char *appid) int i; for (i = 0; i < count; i++) { - data = g_slist_nth_data(g_client_list, i); + data = static_cast(g_slist_nth_data(g_client_list, i)); if (NULL != data) { if (0 == strncmp(data->appid, appid, MAX_APPID_LEN)) { @@ -150,7 +151,7 @@ ma_client_s* ma_client_find_by_pid(int pid) int i; for (i = 0; i < count; i++) { - data = g_slist_nth_data(g_client_list, i); + data = static_cast(g_slist_nth_data(g_client_list, i)); if (NULL != data) { if (data->pid == pid) { @@ -483,7 +484,7 @@ int mas_client_set_background_volume(int pid, double ratio) return 0; } -int mas_client_set_preprocessing_allow_mode(int pid, int mode, const char* appid) +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',}; @@ -1025,7 +1026,7 @@ const char* mas_get_client_appid_by_pid(int pid) } int status = aul_app_get_status_bypid(pid); - if (-1 != ret && 0 > status) { + 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); @@ -1447,7 +1448,7 @@ int mas_set_current_service_state(ma_service_state_e state) int i; for (i = 0; i < count; i++) { - data = g_slist_nth_data(g_client_list, i); + data = static_cast(g_slist_nth_data(g_client_list, i)); if (NULL != data && -1 != data->pid) { int ret = masc_dbus_service_state_change(data->pid, state); @@ -1578,7 +1579,7 @@ static void _package_manager_event_cb(const char *type, const char *package, pac return; } -bool service_app_create(void *data) +bool app_create(void *data) { // Todo: add your code here. @@ -1608,7 +1609,7 @@ bool service_app_create(void *data) return true; } -void service_app_terminate(void *data) +void app_terminate(void *data) { MAS_LOGI("[ENTER]"); if (g_pkgmgr) { @@ -1623,53 +1624,3 @@ void service_app_terminate(void *data) return; } -void service_app_control(app_control_h app_control, void *data) -{ - // Todo: add your code here. - return; -} - -static void -service_app_lang_changed(app_event_info_h event_info, void *user_data) -{ - /*APP_EVENT_LANGUAGE_CHANGED*/ - return; -} - -static void -service_app_region_changed(app_event_info_h event_info, void *user_data) -{ - /*APP_EVENT_REGION_FORMAT_CHANGED*/ -} - -static void -service_app_low_battery(app_event_info_h event_info, void *user_data) -{ - /*APP_EVENT_LOW_BATTERY*/ -} - -static void -service_app_low_memory(app_event_info_h event_info, void *user_data) -{ - /*APP_EVENT_LOW_MEMORY*/ -} - -int main(int argc, char* argv[]) -{ - char ad[50] = {0,}; - service_app_lifecycle_callback_s event_callback; - app_event_handler_h handlers[5] = {NULL, }; - - event_callback.create = service_app_create; - event_callback.terminate = service_app_terminate; - event_callback.app_control = service_app_control; - - service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad); - service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad); - service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad); - service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad); - - int ret = service_app_main(argc, argv, &event_callback, ad); - LOGI("Main function exits with : %d", ret); - return ret; -} diff --git a/src/multi_assistant_service_plugin.c b/src/multi_assistant_service_plugin.cpp similarity index 98% rename from src/multi_assistant_service_plugin.c rename to src/multi_assistant_service_plugin.cpp index afc7ecb..a9f41bd 100644 --- a/src/multi_assistant_service_plugin.c +++ b/src/multi_assistant_service_plugin.cpp @@ -93,8 +93,9 @@ Eina_Bool __send_result(void *data) } #endif /* -TEST_CODE */ -Eina_Bool process_wakeup_event_by_appid_timer(char* appid) +Eina_Bool process_wakeup_event_by_appid_timer(void* data) { + char* appid = static_cast(data); MAS_LOGD("[ENTER] appid(%s)", appid); int pid = -1; @@ -122,14 +123,15 @@ Eina_Bool process_wakeup_event_by_appid_timer(char* appid) return ECORE_CALLBACK_CANCEL; } -Eina_Bool process_wakeup_event_by_word_timer(char* wakeup_word) +Eina_Bool process_wakeup_event_by_word_timer(void* data) { + char* wakeup_word = static_cast(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(strdup(appid)); + process_wakeup_event_by_appid_timer(static_cast(strdup(appid))); if (wakeup_word) free(wakeup_word); @@ -137,7 +139,7 @@ Eina_Bool process_wakeup_event_by_word_timer(char* wakeup_word) return ECORE_CALLBACK_CANCEL; } -static void __wakeup_event_cb(mas_wakeup_event_info wakeup_info, void* user_data) +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; @@ -207,11 +209,13 @@ static void __wakeup_event_cb(mas_wakeup_event_info wakeup_info, void* user_data #endif /* - TEST_CODE */ if (wakeup_info.wakeup_appid) { ecore_thread_main_loop_begin(); - ecore_timer_add(0.0f, process_wakeup_event_by_appid_timer, (void*)strdup(wakeup_info.wakeup_appid)); + ecore_timer_add(0.0f, process_wakeup_event_by_appid_timer, + static_cast(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, (void*)strdup(wakeup_info.wakeup_word)); + ecore_timer_add(0.0f, process_wakeup_event_by_word_timer, + static_cast(strdup(wakeup_info.wakeup_word))); ecore_thread_main_loop_end(); } -- 2.7.4 From 3d77fde30bd1d77c5c46174d187f6e74137a3de1 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 10 Feb 2020 17:10:07 +0900 Subject: [PATCH 08/16] Introduce compile-time unit tests Change-Id: Id2c98124a993c60f8519fbb48b052664b0922769 --- CMakeLists.txt | 5 +++ packaging/org.tizen.multi-assistant-service.spec | 13 +++++++ tests/CMakeLists.txt | 3 ++ tests/utc/CMakeLists.txt | 3 ++ tests/utc/service/CMakeLists.txt | 47 ++++++++++++++++++++++++ tests/utc/service/main.cpp | 45 +++++++++++++++++++++++ 6 files changed, 116 insertions(+) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/utc/CMakeLists.txt create mode 100644 tests/utc/service/CMakeLists.txt create mode 100644 tests/utc/service/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e874905..f92c5fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,3 +78,8 @@ INSTALL(TARGETS ${BINNAME} DESTINATION ${BINDIR}) TARGET_LINK_LIBRARIES(${BINNAME} -ldl ${pkgs_LDFLAGS} ${EXTRA_LDFLAGS}) ADD_SUBDIRECTORY(plugins) + +IF(NOT "${TEST_TYPE}" STREQUAL "none") +ENABLE_TESTING() +ADD_SUBDIRECTORY(tests) +ENDIF() diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index 4a5faeb..bb4d60b 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -26,6 +26,9 @@ BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(multi-assistant) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(pkgmgr-info) +%if %{defined _test_type} +BuildRequires: gtest-devel +%endif BuildRequires: boost-system BuildRequires: boost-thread BuildRequires: cmake @@ -58,6 +61,11 @@ export LDFLAGS %cmake \ -DCMAKE_INSTALL_PREFIX=%{_appdir} \ -DTZ_SYS_RO_SHARE=%TZ_SYS_RO_SHARE \ +%if %{defined _test_type} + -DTEST_TYPE="%{_test_type}" \ +%else + -DTEST_TYPE="none" \ +%endif make %{?jobs:-j%jobs} @@ -68,6 +76,11 @@ cp LICENSE.Flora %{buildroot}%{TZ_SYS_RO_SHARE}/license/%{name} %make_install +%check +%if "%{_ctest_enable}" == "true" +ctest --output-on-failure %{?_smp_mflags} +%endif + %post mkdir -p %{_appbindir} mkdir -p %{_libdir}/multiassistant/ma/1.0/engine diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..e70c66e --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,3 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +ADD_SUBDIRECTORY(utc) diff --git a/tests/utc/CMakeLists.txt b/tests/utc/CMakeLists.txt new file mode 100644 index 0000000..2c2f631 --- /dev/null +++ b/tests/utc/CMakeLists.txt @@ -0,0 +1,3 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +ADD_SUBDIRECTORY(service) diff --git a/tests/utc/service/CMakeLists.txt b/tests/utc/service/CMakeLists.txt new file mode 100644 index 0000000..b9d543b --- /dev/null +++ b/tests/utc/service/CMakeLists.txt @@ -0,0 +1,47 @@ +LINK_DIRECTORIES(${CMAKE_BINARY_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wno-unused-function -Wno-sign-compare") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs" ) +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIE") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -std=c++11") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") + +ADD_DEFINITIONS("-DFULLVER=\"${FULLVER}\"") + +SET(TEST_SOURCES + main.cpp + ${CMAKE_SOURCE_DIR}/src/multi_assistant_config.cpp +) + +# Find Packages +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED + capi-appfw-application + capi-appfw-preference + multi-assistant + dlog + libxml-2.0 +) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +FIND_PACKAGE(GTest REQUIRED) +INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS}) +LINK_DIRECTORIES(${GTEST_LIBRARY_DIRS}) + +SET(TEST_SERVICE test-service) +ADD_EXECUTABLE(${TEST_SERVICE} + ${TEST_SOURCES} + ) + +TARGET_LINK_LIBRARIES(${TEST_SERVICE} -ldl ${GTEST_LIBRARIES} pthread + ${EXTRA_LDFLAGS} ${pkgs_LDFLAGS}) + +INSTALL(TARGETS ${TEST_SERVICE} DESTINATION bin) + +ADD_TEST(NAME ${TEST_SERVICE} COMMAND ${TEST_SERVICE}) diff --git a/tests/utc/service/main.cpp b/tests/utc/service/main.cpp new file mode 100644 index 0000000..24271c9 --- /dev/null +++ b/tests/utc/service/main.cpp @@ -0,0 +1,45 @@ +/* + * Copyright 2018 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 + +class ServiceWithEmptyWakeWord : public testing::Test { +public: + ServiceWithEmptyWakeWord() { + } + virtual ~ServiceWithEmptyWakeWord() { + } +}; + +class ServiceWithAnArbitraryWakeWord : public testing::Test { +public: + ServiceWithAnArbitraryWakeWord() { + } + virtual ~ServiceWithAnArbitraryWakeWord() { + } +}; + +TEST_F(ServiceWithEmptyWakeWord, HasOneWakeWordAfterAdd) { +} + +TEST_F(ServiceWithAnArbitraryWakeWord, HasTwoWakeWordsAfterAdd) { +} + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + return ret; +} -- 2.7.4 From bf487e5e3f016c4d50d8dc0ef4f761ac936fe8ec Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 10 Feb 2020 20:00:48 +0900 Subject: [PATCH 09/16] Make a class for mas_config and add tests for it Change-Id: I1fc6eef26828353fde70a9bda74d09814887af4a --- inc/multi_assistant_config.h | 33 ++++++++--- inc/multi_assistant_service_plugin.h | 2 + src/multi_assistant_config.cpp | 106 ++++++++++++++++++++++++++++++----- src/multi_assistant_service.cpp | 60 +++++--------------- tests/utc/service/main.cpp | 49 ++++++++++++++++ 5 files changed, 183 insertions(+), 67 deletions(-) diff --git a/inc/multi_assistant_config.h b/inc/multi_assistant_config.h index c073792..cec7c12 100644 --- a/inc/multi_assistant_config.h +++ b/inc/multi_assistant_config.h @@ -86,13 +86,32 @@ typedef struct { typedef int (*mas_config_assistant_info_cb)(ma_assistant_info_s* info, void* user_data); -int mas_config_get_assistant_info(mas_config_assistant_info_cb callback, void* user_data); -int mas_config_load_custom_wake_words(const char* app_id, - char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN], - char wakeup_language[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]); -int mas_config_save_custom_wake_words(const char* app_id, - char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN], - char wakeup_language[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]); +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]); +private: + int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, + const char *path, void* user_data); +}; #ifdef __cplusplus } diff --git a/inc/multi_assistant_service_plugin.h b/inc/multi_assistant_service_plugin.h index 1639e45..a8efc61 100644 --- a/inc/multi_assistant_service_plugin.h +++ b/inc/multi_assistant_service_plugin.h @@ -90,6 +90,8 @@ int multi_assistant_service_plugin_set_wake_word_audio_require_flag(const char* 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); diff --git a/src/multi_assistant_config.cpp b/src/multi_assistant_config.cpp index ba72431..243740f 100644 --- a/src/multi_assistant_config.cpp +++ b/src/multi_assistant_config.cpp @@ -24,7 +24,8 @@ #include "multi_assistant_config.h" #include "multi_assistant_main.h" -int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const char *path, void* user_data) +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; @@ -216,7 +217,7 @@ int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const return 0; } -int mas_config_get_assistant_info(mas_config_assistant_info_cb callback, void* user_data) +int CConfig::mas_config_get_assistant_info(mas_config_assistant_info_cb callback, void* user_data) { const char *suffix = ".xml"; @@ -241,9 +242,68 @@ int mas_config_get_assistant_info(mas_config_assistant_info_cb callback, void* u return 0; } -int mas_config_load_custom_wake_words(const char* app_id, - char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN], - char wakeup_language[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]) +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)]; @@ -284,20 +344,21 @@ int mas_config_load_custom_wake_words(const char* app_id, *word_end = '\0'; *language_end = '\0'; if (0 == strlen(word_start)) break; - strncpy(wakeup_word[index], word_start, MAX_WAKEUP_WORD_LEN - 1); - strncpy(wakeup_language[index], language_start, MAX_WAKEUP_WORD_LEN - 1); + 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[index], wakeup_language[index]); + LOGD("Added custom wakeup word : (%s) (%s)", + wakeup_word_storage[index], wakeup_language_storage[index]); index++; } return 0; } -int mas_config_save_custom_wake_words(const char* app_id, - char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN], - char wakeup_language[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]) +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)]; @@ -305,12 +366,14 @@ int mas_config_save_custom_wake_words(const char* app_id, 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[loop]) > 0) { + if (strlen(wakeup_word_storage[loop]) > 0) { int wakeup_words_len = strlen(wakeup_words); - strncat(wakeup_words, wakeup_word[loop], sizeof(wakeup_words) - wakeup_words_len - 1); + 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[loop], sizeof(wakeup_languages) - wakeup_languages_len - 1); + strncat(wakeup_languages, wakeup_language_storage[loop], + sizeof(wakeup_languages) - wakeup_languages_len - 1); strcat(wakeup_languages, "|"); } } @@ -319,4 +382,17 @@ int mas_config_save_custom_wake_words(const char* app_id, preference_set_string("custom_wakeup_words", wakeup_words); preference_set_string("custom_wakeup_languages", wakeup_languages); return 0; -} \ No newline at end of file +} + +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 (strlen(wakeup_word_storage[loop]) > 0) { + num++; + } + } + return num; +} diff --git a/src/multi_assistant_service.cpp b/src/multi_assistant_service.cpp index 34df15f..56f5ed3 100644 --- a/src/multi_assistant_service.cpp +++ b/src/multi_assistant_service.cpp @@ -79,6 +79,7 @@ static ma_voice_key_status_e g_last_voice_key_status = MA_VOICE_KEY_STATUS_RELEA /* client list */ static GSList* g_client_list = NULL; +static CConfig g_config; int ma_client_create(ma_client_s *info) { @@ -583,32 +584,15 @@ int mas_client_add_wake_word(int pid, const char* wake_word, const char* languag 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)) { - bool found = false; - bool duplicated = false; - for (int innerLoop = 0;false == found && false == duplicated && - innerLoop < MAX_WAKEUP_WORDS_NUM;innerLoop++) { - if (0 == strncmp(g_maclient_info[loop].wakeup_word[innerLoop], wake_word, MAX_WAKEUP_WORD_LEN) && - 0 == strncmp(g_maclient_info[loop].wakeup_language[innerLoop], language, MAX_SUPPORTED_LANGUAGE_LEN)) { - duplicated = true; - } - if (0 == strlen(g_maclient_info[loop].wakeup_word[innerLoop])) { - strncpy(g_maclient_info[loop].wakeup_word[innerLoop], wake_word, MAX_WAKEUP_WORD_LEN); - g_maclient_info[loop].wakeup_word[innerLoop][MAX_WAKEUP_WORD_LEN - 1] = '\0'; - strncpy(g_maclient_info[loop].wakeup_language[innerLoop], language, MAX_SUPPORTED_LANGUAGE_LEN); - g_maclient_info[loop].wakeup_word[innerLoop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0'; - found = true; - } - } - if (found && !duplicated) { - mas_config_save_custom_wake_words(pid_appid, + 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 { - if (duplicated) { - LOGE("The wakeup word already exists!"); - } else { - LOGE("No empty slot found while trying to add new wake word!"); - } + LOGE("add new wake word failed!"); return -1; } } @@ -631,28 +615,14 @@ int mas_client_remove_wake_word(int pid, const char* wake_word, const char* lang 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)) { - for (int innerLoop = 0;innerLoop < MAX_WAKEUP_WORDS_NUM;innerLoop++) { - if (0 == strncmp(g_maclient_info[loop].wakeup_word[innerLoop], wake_word, MAX_WAKEUP_WORD_LEN) && - 0 == strncmp(g_maclient_info[loop].wakeup_language[innerLoop], language, MAX_SUPPORTED_LANGUAGE_LEN)) { - for (int shift = innerLoop;shift < MAX_WAKEUP_WORDS_NUM - 1;shift++) { - strncpy(g_maclient_info[loop].wakeup_word[shift], - g_maclient_info[loop].wakeup_word[shift + 1], MAX_WAKEUP_WORD_LEN); - g_maclient_info[loop].wakeup_word[shift][MAX_WAKEUP_WORD_LEN - 1] = '\0'; - strncpy(g_maclient_info[loop].wakeup_language[shift], - g_maclient_info[loop].wakeup_language[shift + 1], MAX_SUPPORTED_LANGUAGE_LEN); - g_maclient_info[loop].wakeup_word[shift][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0'; - } - memset(g_maclient_info[loop].wakeup_word[MAX_WAKEUP_WORDS_NUM - 1], - 0x00, sizeof(g_maclient_info[loop].wakeup_word)); - memset(g_maclient_info[loop].wakeup_language[MAX_WAKEUP_WORDS_NUM - 1], - 0x00, sizeof(g_maclient_info[loop].wakeup_language)); - - innerLoop--; /* Just in case there are duplicated items */ - } - } - mas_config_save_custom_wake_words(pid_appid, + 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); + } } } @@ -829,12 +799,12 @@ static int init_plugin(void) return -1; } - if (0 == mas_config_get_assistant_info(__mas_assistant_info_cb, NULL)) { + 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)) { - mas_config_load_custom_wake_words(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( diff --git a/tests/utc/service/main.cpp b/tests/utc/service/main.cpp index 24271c9..1be2dc0 100644 --- a/tests/utc/service/main.cpp +++ b/tests/utc/service/main.cpp @@ -16,12 +16,25 @@ #include +#include "multi_assistant_config.h" + +#include + class ServiceWithEmptyWakeWord : public testing::Test { public: ServiceWithEmptyWakeWord() { } virtual ~ServiceWithEmptyWakeWord() { } + void SetUp() override { + memset(wakeup_word_storage, 0x0, sizeof(wakeup_word_storage)); + memset(wakeup_language_storage, 0x0, sizeof(wakeup_language_storage)); + } + void TearDown() override { + } + CConfig 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]; }; class ServiceWithAnArbitraryWakeWord : public testing::Test { @@ -30,12 +43,48 @@ public: } virtual ~ServiceWithAnArbitraryWakeWord() { } + void SetUp() override { + memset(wakeup_word_storage, 0x0, sizeof(wakeup_word_storage)); + memset(wakeup_language_storage, 0x0, sizeof(wakeup_language_storage)); + + strncpy(wakeup_word_storage[0], preloaded_wake_word.c_str(), sizeof(wakeup_word_storage[0])); + wakeup_word_storage[0][sizeof(wakeup_word_storage[0]) - 1] = '\0'; + } + void TearDown() override { + } + const std::string preloaded_wake_word{"Hi Preloaded"}; + const std::string preloaded_language{"pr_LD"}; + CConfig 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]; }; TEST_F(ServiceWithEmptyWakeWord, HasOneWakeWordAfterAdd) { + const std::string arbitrary_wake_word{"Hi Tizen"}; + const std::string arbitrary_language{"ar_LA"}; + + config.mas_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( + wakeup_word_storage, wakeup_language_storage); + ASSERT_EQ(wake_word_num, 1); } TEST_F(ServiceWithAnArbitraryWakeWord, HasTwoWakeWordsAfterAdd) { + const std::string arbitrary_wake_word{"Hi Tizen"}; + const std::string arbitrary_language{"ar_LA"}; + + config.mas_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( + wakeup_word_storage, wakeup_language_storage); + ASSERT_EQ(wake_word_num, 2); } int main(int argc, char** argv) { -- 2.7.4 From 9c0873e3200d94d48c54211c6edb52490109a4ec Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 10 Feb 2020 21:32:29 +0900 Subject: [PATCH 10/16] Rename test_service to test_config and add more tests Change-Id: I9ffd7137081d1b61f9049f6b8371463ffc1cebca --- inc/multi_assistant_config.h | 3 + src/multi_assistant_config.cpp | 17 ++- tests/utc/CMakeLists.txt | 2 +- tests/utc/{service => config}/CMakeLists.txt | 12 +- tests/utc/config/test_config.cpp | 173 +++++++++++++++++++++++++++ tests/utc/service/main.cpp | 94 --------------- 6 files changed, 199 insertions(+), 102 deletions(-) rename tests/utc/{service => config}/CMakeLists.txt (80%) create mode 100644 tests/utc/config/test_config.cpp delete mode 100644 tests/utc/service/main.cpp diff --git a/inc/multi_assistant_config.h b/inc/multi_assistant_config.h index cec7c12..a84c54d 100644 --- a/inc/multi_assistant_config.h +++ b/inc/multi_assistant_config.h @@ -108,6 +108,9 @@ public: 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); diff --git a/src/multi_assistant_config.cpp b/src/multi_assistant_config.cpp index 243740f..f636d01 100644 --- a/src/multi_assistant_config.cpp +++ b/src/multi_assistant_config.cpp @@ -390,9 +390,24 @@ int CConfig::mas_config_get_custom_wake_word_num( { int num = 0; for (int loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) { - if (strlen(wakeup_word_storage[loop]) > 0) { + 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; +} diff --git a/tests/utc/CMakeLists.txt b/tests/utc/CMakeLists.txt index 2c2f631..145e97a 100644 --- a/tests/utc/CMakeLists.txt +++ b/tests/utc/CMakeLists.txt @@ -1,3 +1,3 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -ADD_SUBDIRECTORY(service) +ADD_SUBDIRECTORY(config) diff --git a/tests/utc/service/CMakeLists.txt b/tests/utc/config/CMakeLists.txt similarity index 80% rename from tests/utc/service/CMakeLists.txt rename to tests/utc/config/CMakeLists.txt index b9d543b..ad3d302 100644 --- a/tests/utc/service/CMakeLists.txt +++ b/tests/utc/config/CMakeLists.txt @@ -12,7 +12,7 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") ADD_DEFINITIONS("-DFULLVER=\"${FULLVER}\"") SET(TEST_SOURCES - main.cpp + test_config.cpp ${CMAKE_SOURCE_DIR}/src/multi_assistant_config.cpp ) @@ -34,14 +34,14 @@ FIND_PACKAGE(GTest REQUIRED) INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS}) LINK_DIRECTORIES(${GTEST_LIBRARY_DIRS}) -SET(TEST_SERVICE test-service) -ADD_EXECUTABLE(${TEST_SERVICE} +SET(TEST_CONFIG test-config) +ADD_EXECUTABLE(${TEST_CONFIG} ${TEST_SOURCES} ) -TARGET_LINK_LIBRARIES(${TEST_SERVICE} -ldl ${GTEST_LIBRARIES} pthread +TARGET_LINK_LIBRARIES(${TEST_CONFIG} -ldl ${GTEST_LIBRARIES} pthread ${EXTRA_LDFLAGS} ${pkgs_LDFLAGS}) -INSTALL(TARGETS ${TEST_SERVICE} DESTINATION bin) +INSTALL(TARGETS ${TEST_CONFIG} DESTINATION bin) -ADD_TEST(NAME ${TEST_SERVICE} COMMAND ${TEST_SERVICE}) +ADD_TEST(NAME ${TEST_CONFIG} COMMAND ${TEST_CONFIG}) diff --git a/tests/utc/config/test_config.cpp b/tests/utc/config/test_config.cpp new file mode 100644 index 0000000..6a92495 --- /dev/null +++ b/tests/utc/config/test_config.cpp @@ -0,0 +1,173 @@ +/* + * Copyright 2018 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 + +#include "multi_assistant_config.h" + +#include + +class StorageWithEmptyWakeWord : public testing::Test { +public: + StorageWithEmptyWakeWord() { + } + virtual ~StorageWithEmptyWakeWord() { + } + void SetUp() override { + memset(wakeup_word_storage, 0x0, sizeof(wakeup_word_storage)); + memset(wakeup_language_storage, 0x0, sizeof(wakeup_language_storage)); + } + void TearDown() override { + } + CConfig 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]; +}; + +class StorageWithAnArbitraryWakeWord : public testing::Test { +public: + StorageWithAnArbitraryWakeWord() { + } + virtual ~StorageWithAnArbitraryWakeWord() { + } + void SetUp() override { + 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( + preloaded_wake_word.c_str(), preloaded_language.c_str(), + wakeup_word_storage, + wakeup_language_storage); + } + void TearDown() override { + } + const std::string preloaded_wake_word{"Hi Preloaded"}; + const std::string preloaded_language{"pr_LD"}; + CConfig 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]; +}; + +TEST_F(StorageWithEmptyWakeWord, HasOneWakeWordAfterAdd) { + const std::string arbitrary_wake_word{"Hi Tizen"}; + const std::string arbitrary_language{"ar_LA"}; + + config.mas_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( + wakeup_word_storage, wakeup_language_storage); + ASSERT_EQ(wake_word_num, 1); +} + +TEST_F(StorageWithEmptyWakeWord, HasTwoWakeWordsWhenDifferentLanguageAdded) { + 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( + arbitrary_wake_word.c_str(), arbitrary_language1.c_str(), + wakeup_word_storage, + wakeup_language_storage); + + config.mas_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( + wakeup_word_storage, wakeup_language_storage); + ASSERT_EQ(wake_word_num, 2); +} + +TEST_F(StorageWithEmptyWakeWord, RemovalFailsWhenNoMatchingEntryExists) { + const std::string arbitrary_wake_word{"Hi Tizen"}; + const std::string arbitrary_language{"ar_LA"}; + + int ret = config.mas_config_remove_custom_wake_word( + arbitrary_wake_word.c_str(), arbitrary_language.c_str(), + wakeup_word_storage, + wakeup_language_storage); + + ASSERT_EQ(ret, -1); +} + +TEST_F(StorageWithAnArbitraryWakeWord, StillHasOneWakeWordAfterDuplicatedAdd) { + config.mas_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( + wakeup_word_storage, wakeup_language_storage); + ASSERT_EQ(wake_word_num, 1); +} + +TEST_F(StorageWithAnArbitraryWakeWord, HasZeroWakeWordAfterRemoval) { + config.mas_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( + 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( + arbitrary_wake_word.c_str(), arbitrary_language.c_str(), + wakeup_word_storage, + wakeup_language_storage); + config.mas_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( + preloaded_wake_word.c_str(), preloaded_language.c_str(), + wakeup_word_storage, + wakeup_language_storage); + ASSERT_EQ(exists, false); +} + +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( + arbitrary_wake_word.c_str(), arbitrary_language.c_str(), + wakeup_word_storage, + wakeup_language_storage); + config.mas_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( + arbitrary_wake_word.c_str(), arbitrary_language.c_str(), + wakeup_word_storage, + wakeup_language_storage); + ASSERT_EQ(exists, true); +} + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + return ret; +} diff --git a/tests/utc/service/main.cpp b/tests/utc/service/main.cpp deleted file mode 100644 index 1be2dc0..0000000 --- a/tests/utc/service/main.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2018 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 - -#include "multi_assistant_config.h" - -#include - -class ServiceWithEmptyWakeWord : public testing::Test { -public: - ServiceWithEmptyWakeWord() { - } - virtual ~ServiceWithEmptyWakeWord() { - } - void SetUp() override { - memset(wakeup_word_storage, 0x0, sizeof(wakeup_word_storage)); - memset(wakeup_language_storage, 0x0, sizeof(wakeup_language_storage)); - } - void TearDown() override { - } - CConfig 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]; -}; - -class ServiceWithAnArbitraryWakeWord : public testing::Test { -public: - ServiceWithAnArbitraryWakeWord() { - } - virtual ~ServiceWithAnArbitraryWakeWord() { - } - void SetUp() override { - memset(wakeup_word_storage, 0x0, sizeof(wakeup_word_storage)); - memset(wakeup_language_storage, 0x0, sizeof(wakeup_language_storage)); - - strncpy(wakeup_word_storage[0], preloaded_wake_word.c_str(), sizeof(wakeup_word_storage[0])); - wakeup_word_storage[0][sizeof(wakeup_word_storage[0]) - 1] = '\0'; - } - void TearDown() override { - } - const std::string preloaded_wake_word{"Hi Preloaded"}; - const std::string preloaded_language{"pr_LD"}; - CConfig 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]; -}; - -TEST_F(ServiceWithEmptyWakeWord, HasOneWakeWordAfterAdd) { - const std::string arbitrary_wake_word{"Hi Tizen"}; - const std::string arbitrary_language{"ar_LA"}; - - config.mas_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( - wakeup_word_storage, wakeup_language_storage); - ASSERT_EQ(wake_word_num, 1); -} - -TEST_F(ServiceWithAnArbitraryWakeWord, HasTwoWakeWordsAfterAdd) { - const std::string arbitrary_wake_word{"Hi Tizen"}; - const std::string arbitrary_language{"ar_LA"}; - - config.mas_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( - wakeup_word_storage, wakeup_language_storage); - ASSERT_EQ(wake_word_num, 2); -} - -int main(int argc, char** argv) { - testing::InitGoogleTest(&argc, argv); - int ret = RUN_ALL_TESTS(); - return ret; -} -- 2.7.4 From 80f5984d20ef2a55f8719987afbec39874c1277b Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Wed, 19 Feb 2020 20:30:48 +0900 Subject: [PATCH 11/16] Encapsulate functions and data into classes Change-Id: I03489e7713649cb20f54eac0f968bdf96c5ad786 --- CMakeLists.txt | 10 +- inc/multi_assistant_service_client.h | 147 ------ inc/multi_wakeup_recognizer.h | 53 --- inc/{multi_assistant_main.h => service_common.h} | 40 +- inc/{multi_assistant_config.h => service_config.h} | 44 +- inc/service_ipc_dbus.h | 86 ++++ inc/service_ipc_dbus_dispatcher.h | 66 +++ inc/service_main.h | 187 ++++++++ inc/service_plugin.h | 109 +++++ ...service_plugin.h => service_plugin_interface.h} | 99 +--- plugins/wakeup-manager/inc/wakeup_manager.h | 2 +- plugins/wakeup-manager/src/dependency_resolver.cpp | 2 +- src/main.cpp | 11 +- src/multi_assistant_dbus.h | 66 --- src/multi_assistant_dbus_server.h | 75 --- ...lti_assistant_config.cpp => service_config.cpp} | 22 +- ...lti_assistant_dbus.cpp => service_ipc_dbus.cpp} | 171 ++++--- ..._server.cpp => service_ipc_dbus_dispatcher.cpp} | 197 ++++++-- ...ulti_assistant_service.cpp => service_main.cpp} | 517 ++++++++++----------- ...stant_service_plugin.cpp => service_plugin.cpp} | 427 ++++++++++------- tests/utc/config/CMakeLists.txt | 2 +- tests/utc/config/test_config.cpp | 40 +- 22 files changed, 1314 insertions(+), 1059 deletions(-) delete mode 100644 inc/multi_assistant_service_client.h delete mode 100644 inc/multi_wakeup_recognizer.h rename inc/{multi_assistant_main.h => service_common.h} (77%) rename inc/{multi_assistant_config.h => service_config.h} (75%) create mode 100644 inc/service_ipc_dbus.h create mode 100644 inc/service_ipc_dbus_dispatcher.h create mode 100644 inc/service_main.h create mode 100644 inc/service_plugin.h rename inc/{multi_assistant_service_plugin.h => service_plugin_interface.h} (72%) delete mode 100644 src/multi_assistant_dbus.h delete mode 100644 src/multi_assistant_dbus_server.h rename src/{multi_assistant_config.cpp => service_config.cpp} (94%) rename src/{multi_assistant_dbus.cpp => service_ipc_dbus.cpp} (87%) rename src/{multi_assistant_dbus_server.cpp => service_ipc_dbus_dispatcher.cpp} (77%) rename src/{multi_assistant_service.cpp => service_main.cpp} (76%) rename src/{multi_assistant_service_plugin.cpp => service_plugin.cpp} (74%) diff --git a/CMakeLists.txt b/CMakeLists.txt index f92c5fb..aca1239 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,11 +63,11 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc) 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}) diff --git a/inc/multi_assistant_service_client.h b/inc/multi_assistant_service_client.h deleted file mode 100644 index 9127e3a..0000000 --- a/inc/multi_assistant_service_client.h +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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 -#include -#include - -#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_ */ diff --git a/inc/multi_wakeup_recognizer.h b/inc/multi_wakeup_recognizer.h deleted file mode 100644 index d5f8fb0..0000000 --- a/inc/multi_wakeup_recognizer.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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 - -#include -#include -#include - -#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_ */ diff --git a/inc/multi_assistant_main.h b/inc/service_common.h similarity index 77% rename from inc/multi_assistant_main.h rename to inc/service_common.h index 643d75b..ca86cc8 100644 --- a/inc/multi_assistant_main.h +++ b/inc/service_common.h @@ -1,9 +1,11 @@ -#ifndef __MULTI_ASSISTANT_SERVICE_H__ -#define __MULTI_ASSISTANT_SERVICE_H__ +#ifndef __SERVICE_COMMON_H__ +#define __SERVICE_COMMON_H__ #include #include -#include "multi_wakeup_recognizer.h" +#include +#include +#include #ifdef LOG_TAG #undef LOG_TAG @@ -94,4 +96,34 @@ #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__ */ +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__ */ diff --git a/inc/multi_assistant_config.h b/inc/service_config.h similarity index 75% rename from inc/multi_assistant_config.h rename to inc/service_config.h index a84c54d..18fccbc 100644 --- a/inc/multi_assistant_config.h +++ b/inc/service_config.h @@ -15,12 +15,14 @@ */ -#ifndef __MULTI_ASSISTANT_CONFIG_H__ -#define __MULTI_ASSISTANT_CONFIG_H__ +#ifndef __SERVICE_CONFIG_H__ +#define __SERVICE_CONFIG_H__ #include #include +#include "service_common.h" + #ifdef __cplusplus extern "C" { @@ -57,18 +59,6 @@ extern "C" #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; @@ -84,35 +74,35 @@ typedef struct { float voice_key_tap_duration; } ma_assistant_info_s; -typedef int (*mas_config_assistant_info_cb)(ma_assistant_info_s* info, void* user_data); +typedef int (*service_config_assistant_info_cb)(ma_assistant_info_s* info, void* user_data); -class CConfig { +class CServiceConfig { public: - CConfig() {}; - virtual ~CConfig() {}; + CServiceConfig() {}; + virtual ~CServiceConfig() {}; - int mas_config_get_assistant_info(mas_config_assistant_info_cb callback, void* user_data); + int get_assistant_info(service_config_assistant_info_cb callback, void* user_data); - int mas_config_add_custom_wake_word(const char* wake_word, const char* language, + 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 mas_config_remove_custom_wake_word(const char* wake_word, const char* language, + 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 mas_config_load_custom_wake_words(const char* app_id, + 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 mas_config_save_custom_wake_words(const char* app_id, + 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 mas_config_get_custom_wake_word_num( + 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 mas_config_has_custom_wake_word(const char* wake_word, const char* language, + 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 mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, + int parse_assistant_info(service_config_assistant_info_cb callback, const char *path, void* user_data); }; @@ -124,4 +114,4 @@ private: * @} */ -#endif /* __MULTI_ASSISTANT_CONFIG_H__ */ +#endif /* __SERVICE_CONFIG_H__ */ diff --git a/inc/service_ipc_dbus.h b/inc/service_ipc_dbus.h new file mode 100644 index 0000000..7242f12 --- /dev/null +++ b/inc/service_ipc_dbus.h @@ -0,0 +1,86 @@ +/* + * 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 +#include + +#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__ */ diff --git a/inc/service_ipc_dbus_dispatcher.h b/inc/service_ipc_dbus_dispatcher.h new file mode 100644 index 0000000..45d06fe --- /dev/null +++ b/inc/service_ipc_dbus_dispatcher.h @@ -0,0 +1,66 @@ +/* + * 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 + +#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__ */ diff --git a/inc/service_main.h b/inc/service_main.h new file mode 100644 index 0000000..61e4853 --- /dev/null +++ b/inc/service_main.h @@ -0,0 +1,187 @@ +/* + * 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 + +#include +#include +#include +#include + +#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__ */ diff --git a/inc/service_plugin.h b/inc/service_plugin.h new file mode 100644 index 0000000..b4d9da8 --- /dev/null +++ b/inc/service_plugin.h @@ -0,0 +1,109 @@ +/* + * 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 + +#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__ */ diff --git a/inc/multi_assistant_service_plugin.h b/inc/service_plugin_interface.h similarity index 72% rename from inc/multi_assistant_service_plugin.h rename to inc/service_plugin_interface.h index a8efc61..5d622d4 100644 --- a/inc/multi_assistant_service_plugin.h +++ b/inc/service_plugin_interface.h @@ -15,15 +15,10 @@ */ -#ifndef _MULTI_ASSISTANT_SERVICE_PLUGIN_H_ -#define _MULTI_ASSISTANT_SERVICE_PLUGIN_H_ +#ifndef __SERVICE_PLUGIN_INTERFACE_H__ +#define __SERVICE_PLUGIN_INTERFACE_H__ #include -#include -#include - -#include "multi_wakeup_recognizer.h" -#include "multi_assistant_main.h" #ifdef __cplusplus extern "C" { @@ -34,98 +29,10 @@ typedef struct { 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" @@ -257,4 +164,4 @@ typedef struct { } #endif -#endif /* _MULTI_ASSISTANT_SERVICE_PLUGIN_H_ */ +#endif /* __SERVICE_PLUGIN_INTERFACE_H__ */ diff --git a/plugins/wakeup-manager/inc/wakeup_manager.h b/plugins/wakeup-manager/inc/wakeup_manager.h index 8b52f89..3b6a00b 100644 --- a/plugins/wakeup-manager/inc/wakeup_manager.h +++ b/plugins/wakeup-manager/inc/wakeup_manager.h @@ -18,7 +18,7 @@ #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" diff --git a/plugins/wakeup-manager/src/dependency_resolver.cpp b/plugins/wakeup-manager/src/dependency_resolver.cpp index 3b2ef19..7ebd3d6 100644 --- a/plugins/wakeup-manager/src/dependency_resolver.cpp +++ b/plugins/wakeup-manager/src/dependency_resolver.cpp @@ -24,7 +24,7 @@ #include -#include "multi_assistant_main.h" +#include "service_common.h" #include "dependency_resolver.h" #ifdef LOG_TAG diff --git a/src/main.cpp b/src/main.cpp index 6422575..951d933 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,17 +17,18 @@ #include #include -#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) @@ -59,7 +60,7 @@ static void service_app_low_memory(app_event_info_h event_info, void *user_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, }; diff --git a/src/multi_assistant_dbus.h b/src/multi_assistant_dbus.h deleted file mode 100644 index 6d20348..0000000 --- a/src/multi_assistant_dbus.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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__ */ diff --git a/src/multi_assistant_dbus_server.h b/src/multi_assistant_dbus_server.h deleted file mode 100644 index 24d1759..0000000 --- a/src/multi_assistant_dbus_server.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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 - -#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__ */ diff --git a/src/multi_assistant_config.cpp b/src/service_config.cpp similarity index 94% rename from src/multi_assistant_config.cpp rename to src/service_config.cpp index f636d01..44c4eaa 100644 --- a/src/multi_assistant_config.cpp +++ b/src/service_config.cpp @@ -21,10 +21,10 @@ #include -#include "multi_assistant_config.h" -#include "multi_assistant_main.h" +#include "service_config.h" +#include "service_common.h" -int CConfig::mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, +int CServiceConfig::parse_assistant_info(service_config_assistant_info_cb callback, const char *path, void* user_data) { xmlDocPtr doc = NULL; @@ -217,7 +217,7 @@ int CConfig::mas_config_parse_assistant_info(mas_config_assistant_info_cb callba return 0; } -int CConfig::mas_config_get_assistant_info(mas_config_assistant_info_cb callback, void* user_data) +int CServiceConfig::get_assistant_info(service_config_assistant_info_cb callback, void* user_data) { const char *suffix = ".xml"; @@ -232,7 +232,7 @@ int CConfig::mas_config_get_assistant_info(mas_config_assistant_info_cb callback 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); + parse_assistant_info(callback, fullpath, user_data); } } } @@ -242,7 +242,7 @@ int CConfig::mas_config_get_assistant_info(mas_config_assistant_info_cb callback return 0; } -int CConfig::mas_config_add_custom_wake_word(const char* wake_word, const char* language, +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]) { @@ -270,7 +270,7 @@ int CConfig::mas_config_add_custom_wake_word(const char* wake_word, const char* return 0; } -int CConfig::mas_config_remove_custom_wake_word(const char* wake_word, const char* language, +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]) { @@ -301,7 +301,7 @@ int CConfig::mas_config_remove_custom_wake_word(const char* wake_word, const cha return 0; } -int CConfig::mas_config_load_custom_wake_words(const char* app_id, +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]) { @@ -356,7 +356,7 @@ int CConfig::mas_config_load_custom_wake_words(const char* app_id, return 0; } -int CConfig::mas_config_save_custom_wake_words(const char* app_id, +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]) { @@ -384,7 +384,7 @@ int CConfig::mas_config_save_custom_wake_words(const char* app_id, return 0; } -int CConfig::mas_config_get_custom_wake_word_num( +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]) { @@ -397,7 +397,7 @@ int CConfig::mas_config_get_custom_wake_word_num( return num; } -bool CConfig::mas_config_has_custom_wake_word(const char* wake_word, const char* language, +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]) { diff --git a/src/multi_assistant_dbus.cpp b/src/service_ipc_dbus.cpp similarity index 87% rename from src/multi_assistant_dbus.cpp rename to src/service_ipc_dbus.cpp index 4f04de3..1a7558b 100644 --- a/src/multi_assistant_dbus.cpp +++ b/src/service_ipc_dbus.cpp @@ -14,30 +14,21 @@ * limitations under the License. */ -#include + #include #include -#include #include -#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; +#include "service_common.h" +#include "service_main.h" +#include "service_ipc_dbus.h" -int mas_dbus_reconnect() +int CServiceIpcDbus::reconnect() { if (!g_conn_sender || !g_conn_listener) { - mas_dbus_close_connection(); + close_connection(); - if (0 != mas_dbus_open_connection()) { + if (0 != open_connection()) { MAS_LOGE("[ERROR] Fail to reconnect"); return -1; } @@ -52,9 +43,9 @@ int mas_dbus_reconnect() sender_connected ? "Connected" : "Not connected", listener_connected ? "Connected" : "Not connected"); if (false == sender_connected || false == listener_connected) { - mas_dbus_close_connection(); + close_connection(); - if (0 != mas_dbus_open_connection()) { + if (0 != open_connection()) { MAS_LOGE("[ERROR] Fail to reconnect"); return -1; } @@ -65,16 +56,16 @@ int mas_dbus_reconnect() return 0; } -static int __dbus_check() +int CServiceIpcDbus::__dbus_check() { if (NULL == g_conn_sender || NULL == g_conn_listener) { MAS_LOGE("[ERROR] NULL connection"); - return mas_dbus_reconnect(); + return reconnect(); } return 0; } -int mas_check_dbus_connection() +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); @@ -83,7 +74,7 @@ int mas_check_dbus_connection() return 0; } -int masc_dbus_send_hello(int pid) +int CServiceIpcDbus::send_hello(int pid) { if (0 != __dbus_check()) { return -1; //MAS_ERROR_OPERATION_FAILED; @@ -125,7 +116,7 @@ int masc_dbus_send_hello(int pid) return result; } -int masc_dbus_send_error_message(int reason, const char* err_msg) +int CServiceIpcDbus::send_error_message(int reason, const char* err_msg) { if (0 != __dbus_check()) { return -1; //MAS_ERROR_OPERATION_FAILED; @@ -201,7 +192,7 @@ typedef struct { int section; } streaming_data_streaming_section_header; -void masc_message_port_error(int error) +static void masc_message_port_error(int error) { MAS_LOGE("message_port error found : %s", (MESSAGE_PORT_ERROR_NONE == error) ? "MESSAGE_PORT_ERROR_NONE" : @@ -215,8 +206,13 @@ void masc_message_port_error(int error) "MESSAGE_PORT_ERROR_UNKNOWN"); } -int masc_dbus_send_streaming_audio_data(int pid, int event, void* data, unsigned int data_size) +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; @@ -249,7 +245,7 @@ int masc_dbus_send_streaming_audio_data(int pid, int event, void* data, unsigned 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); + mServiceMain->mas_get_client_appid_by_pid(pid), message_port, b); if (MESSAGE_PORT_ERROR_NONE != ret) masc_message_port_error(ret); @@ -270,7 +266,7 @@ int masc_dbus_send_streaming_audio_data(int pid, int event, void* data, unsigned 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); + mServiceMain->mas_get_client_appid_by_pid(pid), message_port, b); if (MESSAGE_PORT_ERROR_NONE != ret) masc_message_port_error(ret); @@ -285,7 +281,7 @@ int masc_dbus_send_streaming_audio_data(int pid, int event, void* data, unsigned return 0; } -int masc_dbus_active_state_change(int pid, int state) +int CServiceIpcDbus::active_state_change(int pid, int state) { if (0 != __dbus_check()) { return -1; //MAS_ERROR_OPERATION_FAILED; @@ -335,7 +331,7 @@ int masc_dbus_active_state_change(int pid, int state) return 0; } -int masc_dbus_send_preprocessing_information(int pid, const char* app_id) +int CServiceIpcDbus::send_preprocessing_information(int pid, const char* app_id) { if (0 != __dbus_check()) { return -1; //MAS_ERROR_OPERATION_FAILED; @@ -399,8 +395,13 @@ int masc_dbus_send_preprocessing_information(int pid, const char* app_id) return 0; } -int masc_dbus_send_streaming_section_changed(int pid, int section) +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; @@ -419,7 +420,7 @@ int masc_dbus_send_streaming_section_changed(int pid, int section) 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); + 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); @@ -428,7 +429,7 @@ int masc_dbus_send_streaming_section_changed(int pid, int section) return 0; } -int masc_dbus_send_preprocessing_result(int pid, bool result) +int CServiceIpcDbus::send_preprocessing_result(int pid, bool result) { if (0 != __dbus_check()) { return -1; //MAS_ERROR_OPERATION_FAILED; @@ -481,7 +482,7 @@ int masc_dbus_send_preprocessing_result(int pid, bool result) return 0; } -int masc_dbus_send_wakeup_engine_command(int pid, const char* command) +int CServiceIpcDbus::send_wakeup_engine_command(int pid, const char* command) { if (0 != __dbus_check()) { return -1; //MAS_ERROR_OPERATION_FAILED; @@ -545,7 +546,7 @@ int masc_dbus_send_wakeup_engine_command(int pid, const char* command) return 0; } -int masc_dbus_service_state_change(int pid, int state) +int CServiceIpcDbus::service_state_change(int pid, int state) { if (0 != __dbus_check()) { return -1; //MAS_ERROR_OPERATION_FAILED; @@ -595,7 +596,7 @@ int masc_dbus_service_state_change(int pid, int state) return 0; } -int masc_dbus_voice_key_status_change(int pid, int status) +int CServiceIpcDbus::voice_key_status_change(int pid, int status) { if (0 != __dbus_check()) { return -1; //MAS_ERROR_OPERATION_FAILED; @@ -645,7 +646,7 @@ int masc_dbus_voice_key_status_change(int pid, int status) return 0; } -int masc_ui_dbus_send_hello(void) +int CServiceIpcDbus::masc_ui_dbus_send_hello(void) { if (0 != __dbus_check()) { return -1; //MAS_ERROR_OPERATION_FAILED; @@ -689,7 +690,7 @@ int masc_ui_dbus_send_hello(void) return result; } -int masc_ui_dbus_send_asr_result(int pid, int event, char* asr_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; @@ -743,7 +744,7 @@ int masc_ui_dbus_send_asr_result(int pid, int event, char* asr_result) return 0; } -int masc_ui_dbus_send_result(int pid, const char* display_text, const char* utterance_text, const char* result_json) +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; @@ -835,7 +836,7 @@ int masc_ui_dbus_send_result(int pid, const char* display_text, const char* utte return 0; } -int masc_ui_dbus_change_assistant(const char* app_id) +int CServiceIpcDbus::masc_ui_dbus_change_assistant(const char* app_id) { if (0 != __dbus_check()) { return -1; //MAS_ERROR_OPERATION_FAILED; @@ -875,7 +876,7 @@ int masc_ui_dbus_change_assistant(const char* app_id) return 0; } -int masc_ui_dbus_send_error_message(int reason, const char* err_msg) +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"); @@ -923,7 +924,7 @@ int masc_ui_dbus_send_error_message(int reason, const char* err_msg) return 0; } -int masc_ui_dbus_send_recognition_result(int pid, int result) +int CServiceIpcDbus::masc_ui_dbus_send_recognition_result(int pid, int result) { if (0 != __dbus_check()) { return -1; //MAS_ERROR_OPERATION_FAILED; @@ -964,7 +965,7 @@ int masc_ui_dbus_send_recognition_result(int pid, int result) return 0; } -int masc_ui_dbus_enable_common_ui(int enable) +int CServiceIpcDbus::masc_ui_dbus_enable_common_ui(int enable) { if (0 != __dbus_check()) { return -1; //MAS_ERROR_OPERATION_FAILED; @@ -1006,7 +1007,23 @@ int masc_ui_dbus_enable_common_ui(int enable) static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handler) { - if (NULL == g_conn_listener) return ECORE_CALLBACK_RENEW; + CServiceIpcDbus* service_ipc = static_cast(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); @@ -1026,70 +1043,70 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle /* client event */ if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_HELLO)) { - ma_service_dbus_hello(g_conn_listener, msg); + dispatcher->on_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); + dispatcher->on_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); + 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)) { - ma_service_dbus_get_audio_format(g_conn_listener, msg); + 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)) { - ma_service_dbus_get_audio_source_type(g_conn_listener, msg); + 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)) { - ma_service_dbus_send_asr_result(g_conn_listener, msg); + 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)) { - ma_service_dbus_send_result(g_conn_listener, msg); + 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)) { - ma_service_dbus_send_recognition_result(g_conn_listener, msg); + 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)) { - ma_service_dbus_start_streaming_audio_data(g_conn_listener, msg); + 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)) { - ma_service_dbus_stop_streaming_audio_data(g_conn_listener, msg); + 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)) { - ma_service_dbus_update_voice_feedback_state(g_conn_listener, msg); + 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)) { - ma_service_dbus_send_assistant_specific_command(g_conn_listener, msg); + 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)) { - ma_service_dbus_set_background_volume(g_conn_listener, msg); + 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)) { - ma_service_dbus_set_preprocessing_allow_mode(g_conn_listener, msg); + 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)) { - ma_service_dbus_send_preprocessing_result(g_conn_listener, msg); + 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)) { - ma_service_dbus_set_wake_word_audio_require_flag(g_conn_listener, msg); + 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)) { - ma_service_dbus_set_assistant_language(g_conn_listener, msg); + 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)) { - ma_service_dbus_add_wake_word(g_conn_listener, msg); + 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)) { - ma_service_dbus_remove_wake_word(g_conn_listener, msg); + 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)) { - ma_service_ui_dbus_initialize(g_conn_listener, msg); + dispatcher->on_ui_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); + 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)) { - ma_service_ui_dbus_change_assistant(g_conn_listener, msg); + dispatcher->on_ui_change_assistant(g_conn_listener, msg); } else { MAS_LOGD("Message is NOT valid"); @@ -1102,7 +1119,7 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle return ECORE_CALLBACK_RENEW; } -static void __mas_dbus_connection_free() +void CServiceIpcDbus::connection_free() { if (NULL != g_conn_listener) { dbus_connection_close(g_conn_listener); @@ -1116,7 +1133,7 @@ static void __mas_dbus_connection_free() } } -int mas_dbus_open_connection() +int CServiceIpcDbus::open_connection() { DBusError err; dbus_error_init(&err); @@ -1148,7 +1165,7 @@ int mas_dbus_open_connection() if (NULL == g_conn_listener) { MAS_LOGE("[Dbus ERROR] Fail to get dbus connection"); - __mas_dbus_connection_free(); + connection_free(); return -1; } @@ -1160,20 +1177,20 @@ int mas_dbus_open_connection() 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(); + 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(); + 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); + listener_event_callback(this, NULL); } /* add a rule for getting signal */ @@ -1186,31 +1203,31 @@ int mas_dbus_open_connection() 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(); + 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(); + 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); + 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"); - __mas_dbus_connection_free(); + connection_free(); return -1; } return 0; } -int mas_dbus_close_connection() +int CServiceIpcDbus::close_connection() { DBusError err; dbus_error_init(&err); @@ -1227,7 +1244,7 @@ int mas_dbus_close_connection() dbus_error_free(&err); } - __mas_dbus_connection_free(); + connection_free(); return 0; } \ No newline at end of file diff --git a/src/multi_assistant_dbus_server.cpp b/src/service_ipc_dbus_dispatcher.cpp similarity index 77% rename from src/multi_assistant_dbus_server.cpp rename to src/service_ipc_dbus_dispatcher.cpp index ae97bd2..76d40b0 100644 --- a/src/multi_assistant_dbus_server.cpp +++ b/src/service_ipc_dbus_dispatcher.cpp @@ -16,15 +16,14 @@ #include -#include "multi_assistant_main.h" -#include "multi_assistant_dbus.h" -#include "multi_assistant_dbus_server.h" -#include "multi_assistant_service_client.h" +#include "service_common.h" +#include "service_ipc_dbus_dispatcher.h" +#include "service_main.h" /* * Dbus Client-Daemon Server */ -int ma_service_dbus_hello(DBusConnection* conn, DBusMessage* msg) +int CServiceIpcDbusDispatcher::on_hello(DBusConnection* conn, DBusMessage* msg) { MAS_LOGD("[DEBUG] MAS HELLO"); @@ -45,8 +44,13 @@ int ma_service_dbus_hello(DBusConnection* conn, DBusMessage* msg) return 0; } -int ma_service_dbus_initialize(DBusConnection* conn, DBusMessage* msg) +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); @@ -65,7 +69,7 @@ int ma_service_dbus_initialize(DBusConnection* conn, DBusMessage* msg) ret = -1; //MAS_ERROR_OPERATION_FAILED; } else { MAS_LOGD("[IN] mas initialize : pid(%d)", pid); - ret = mas_client_initialize(pid); + ret = mServiceMain->mas_client_initialize(pid); } DBusMessage* reply; @@ -96,8 +100,13 @@ int ma_service_dbus_initialize(DBusConnection* conn, DBusMessage* msg) return ret; } -int ma_service_dbus_deinitialize(DBusConnection* conn, DBusMessage* msg) +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); @@ -116,7 +125,7 @@ int ma_service_dbus_deinitialize(DBusConnection* conn, DBusMessage* msg) ret = -1; //MAS_ERROR_OPERATION_FAILED; } else { MAS_LOGD("[IN] mas deinitialize : pid(%d)", pid); - ret = mas_client_deinitialize(pid); + ret = mServiceMain->mas_client_deinitialize(pid); } DBusMessage* reply; @@ -147,8 +156,13 @@ int ma_service_dbus_deinitialize(DBusConnection* conn, DBusMessage* msg) return 0; } -int ma_service_dbus_get_audio_format(DBusConnection* conn, DBusMessage* msg) +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); @@ -168,7 +182,7 @@ int ma_service_dbus_get_audio_format(DBusConnection* conn, DBusMessage* msg) 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); + ret = mServiceMain->mas_client_get_audio_format(pid, &rate, &channel, &audio_type); } DBusMessage* reply; @@ -201,8 +215,13 @@ int ma_service_dbus_get_audio_format(DBusConnection* conn, DBusMessage* msg) return ret; } -int ma_service_dbus_get_audio_source_type(DBusConnection* conn, DBusMessage* msg) +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); @@ -222,7 +241,7 @@ int ma_service_dbus_get_audio_source_type(DBusConnection* conn, DBusMessage* msg ret = -1; //MAS_ERROR_OPERATION_FAILED; } else { MAS_LOGD("[IN] mas get audio source type"); - ret = mas_client_get_audio_source_type(pid, &type); + ret = mServiceMain->mas_client_get_audio_source_type(pid, &type); } DBusMessage* reply; @@ -263,8 +282,13 @@ int ma_service_dbus_get_audio_source_type(DBusConnection* conn, DBusMessage* msg return ret; } -int ma_service_dbus_send_asr_result(DBusConnection* conn, DBusMessage* msg) +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); @@ -286,7 +310,7 @@ int ma_service_dbus_send_asr_result(DBusConnection* conn, DBusMessage* msg) 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); + ret = mServiceMain->mas_client_send_asr_result(pid, event, asr_result); } DBusMessage* reply; @@ -319,8 +343,13 @@ int ma_service_dbus_send_asr_result(DBusConnection* conn, DBusMessage* msg) return ret; } -int ma_service_dbus_send_result(DBusConnection* conn, DBusMessage* msg) +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); @@ -345,7 +374,7 @@ int ma_service_dbus_send_result(DBusConnection* conn, DBusMessage* msg) 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); + ret = mServiceMain->mas_client_send_result(pid, display_text, utterance_text, result_json); } DBusMessage* reply; @@ -378,8 +407,13 @@ int ma_service_dbus_send_result(DBusConnection* conn, DBusMessage* msg) return ret; } -int ma_service_dbus_send_recognition_result(DBusConnection* conn, DBusMessage* msg) +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); @@ -400,7 +434,7 @@ int ma_service_dbus_send_recognition_result(DBusConnection* conn, DBusMessage* m 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); + ret = mServiceMain->mas_client_send_recognition_result(pid, result); } MAS_LOGD("<<<<<"); @@ -409,8 +443,13 @@ int ma_service_dbus_send_recognition_result(DBusConnection* conn, DBusMessage* m return ret; } -int ma_service_dbus_start_streaming_audio_data(DBusConnection* conn, DBusMessage* msg) +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); @@ -431,7 +470,7 @@ int ma_service_dbus_start_streaming_audio_data(DBusConnection* conn, DBusMessage 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); + ret = mServiceMain->mas_client_start_streaming_audio_data(pid, type); } MAS_LOGD("<<<<<"); @@ -440,8 +479,13 @@ int ma_service_dbus_start_streaming_audio_data(DBusConnection* conn, DBusMessage return ret; } -int ma_service_dbus_stop_streaming_audio_data(DBusConnection* conn, DBusMessage* msg) +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); @@ -462,7 +506,7 @@ int ma_service_dbus_stop_streaming_audio_data(DBusConnection* conn, DBusMessage* 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); + ret = mServiceMain->mas_client_stop_streaming_audio_data(pid, type); } MAS_LOGD("<<<<<"); @@ -471,8 +515,13 @@ int ma_service_dbus_stop_streaming_audio_data(DBusConnection* conn, DBusMessage* return ret; } -int ma_service_dbus_update_voice_feedback_state(DBusConnection* conn, DBusMessage* msg) +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); @@ -493,7 +542,7 @@ int ma_service_dbus_update_voice_feedback_state(DBusConnection* conn, DBusMessag 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); + ret = mServiceMain->mas_client_update_voice_feedback_state(pid, state); } MAS_LOGD("<<<<<"); @@ -502,8 +551,13 @@ int ma_service_dbus_update_voice_feedback_state(DBusConnection* conn, DBusMessag return ret; } -int ma_service_dbus_send_assistant_specific_command(DBusConnection* conn, DBusMessage* msg) +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); @@ -524,7 +578,7 @@ int ma_service_dbus_send_assistant_specific_command(DBusConnection* conn, DBusMe 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); + ret = mServiceMain->mas_client_set_assistant_specific_command(pid, command); } MAS_LOGD("<<<<<"); @@ -533,8 +587,13 @@ int ma_service_dbus_send_assistant_specific_command(DBusConnection* conn, DBusMe return ret; } -int ma_service_dbus_set_background_volume(DBusConnection* conn, DBusMessage* msg) +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); @@ -555,7 +614,7 @@ int ma_service_dbus_set_background_volume(DBusConnection* conn, DBusMessage* msg 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); + ret = mServiceMain->mas_client_set_background_volume(pid, ratio); } MAS_LOGD("<<<<<"); @@ -564,8 +623,13 @@ int ma_service_dbus_set_background_volume(DBusConnection* conn, DBusMessage* msg return ret; } -int ma_service_dbus_set_preprocessing_allow_mode(DBusConnection* conn, DBusMessage* msg) +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); @@ -592,7 +656,7 @@ int ma_service_dbus_set_preprocessing_allow_mode(DBusConnection* conn, DBusMessa 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, + ret = mServiceMain->mas_client_set_preprocessing_allow_mode(pid, static_cast(mode), temp_app_id); if (NULL != temp_app_id) free(temp_app_id); @@ -604,8 +668,13 @@ int ma_service_dbus_set_preprocessing_allow_mode(DBusConnection* conn, DBusMessa return ret; } -int ma_service_dbus_send_preprocessing_result(DBusConnection* conn, DBusMessage* msg) +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); @@ -626,7 +695,7 @@ int ma_service_dbus_send_preprocessing_result(DBusConnection* conn, DBusMessage* 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); + ret = mServiceMain->mas_client_send_preprocessing_result(pid, (bool)result); } MAS_LOGD("<<<<<"); @@ -635,8 +704,13 @@ int ma_service_dbus_send_preprocessing_result(DBusConnection* conn, DBusMessage* return ret; } -int ma_service_dbus_set_wake_word_audio_require_flag(DBusConnection* conn, DBusMessage* msg) +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); @@ -657,7 +731,7 @@ int ma_service_dbus_set_wake_word_audio_require_flag(DBusConnection* conn, DBusM 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); + ret = mServiceMain->mas_client_set_wake_word_audio_require_flag(pid, (bool)require); } MAS_LOGD("<<<<<"); @@ -666,8 +740,13 @@ int ma_service_dbus_set_wake_word_audio_require_flag(DBusConnection* conn, DBusM return ret; } -int ma_service_dbus_set_assistant_language(DBusConnection* conn, DBusMessage* msg) +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); @@ -688,7 +767,7 @@ int ma_service_dbus_set_assistant_language(DBusConnection* conn, DBusMessage* ms 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); + ret = mServiceMain->mas_client_set_assistant_language(pid, language); } MAS_LOGD("<<<<<"); @@ -697,8 +776,13 @@ int ma_service_dbus_set_assistant_language(DBusConnection* conn, DBusMessage* ms return ret; } -int ma_service_dbus_add_wake_word(DBusConnection* conn, DBusMessage* msg) +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); @@ -721,7 +805,7 @@ int ma_service_dbus_add_wake_word(DBusConnection* conn, DBusMessage* msg) 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); + ret = mServiceMain->mas_client_add_wake_word(pid, wake_word, language); } MAS_LOGD("<<<<<"); @@ -730,8 +814,12 @@ int ma_service_dbus_add_wake_word(DBusConnection* conn, DBusMessage* msg) return ret; } -int ma_service_dbus_remove_wake_word(DBusConnection* conn, DBusMessage* msg) +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); @@ -754,7 +842,7 @@ int ma_service_dbus_remove_wake_word(DBusConnection* conn, DBusMessage* msg) 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); + ret = mServiceMain->mas_client_remove_wake_word(pid, wake_word, language); } MAS_LOGD("<<<<<"); @@ -763,8 +851,13 @@ int ma_service_dbus_remove_wake_word(DBusConnection* conn, DBusMessage* msg) return ret; } -int ma_service_ui_dbus_initialize(DBusConnection* conn, DBusMessage* msg) +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); @@ -783,7 +876,7 @@ int ma_service_ui_dbus_initialize(DBusConnection* conn, DBusMessage* msg) ret = -1; //MAS_ERROR_OPERATION_FAILED; } else { MAS_LOGD("[IN] mas ui initialize : pid(%d)", pid); - ret = mas_ui_client_initialize(pid); + ret = mServiceMain->mas_ui_client_initialize(pid); } DBusMessage* reply; @@ -814,8 +907,13 @@ int ma_service_ui_dbus_initialize(DBusConnection* conn, DBusMessage* msg) return ret; } -int ma_service_ui_dbus_deinitialize(DBusConnection* conn, DBusMessage* msg) +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); @@ -834,7 +932,7 @@ int ma_service_ui_dbus_deinitialize(DBusConnection* conn, DBusMessage* msg) ret = -1; //MAS_ERROR_OPERATION_FAILED; } else { MAS_LOGD("[IN] mas ui deinitialize : pid(%d)", pid); - ret = mas_ui_client_deinitialize(pid); + ret = mServiceMain->mas_ui_client_deinitialize(pid); } DBusMessage* reply; @@ -865,8 +963,13 @@ int ma_service_ui_dbus_deinitialize(DBusConnection* conn, DBusMessage* msg) return ret; } -int ma_service_ui_dbus_change_assistant(DBusConnection* conn, DBusMessage* msg) +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); @@ -885,7 +988,7 @@ int ma_service_ui_dbus_change_assistant(DBusConnection* conn, DBusMessage* msg) 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); + ret = mServiceMain->mas_ui_client_change_assistant(app_id); } DBusMessage* reply; diff --git a/src/multi_assistant_service.cpp b/src/service_main.cpp similarity index 76% rename from src/multi_assistant_service.cpp rename to src/service_main.cpp index 56f5ed3..54c2368 100644 --- a/src/multi_assistant_service.cpp +++ b/src/service_main.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -31,57 +30,15 @@ #include #include -#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) +#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 @@ -102,7 +59,7 @@ int ma_client_create(ma_client_s *info) return 0; } -int ma_client_destroy(ma_client_s *client) +int CServiceMain::ma_client_destroy(ma_client_s *client) { if (NULL == client) { MAS_LOGE("Input parameter is NULL"); //LCOV_EXCL_LINE @@ -117,7 +74,7 @@ int ma_client_destroy(ma_client_s *client) return 0; } -ma_client_s* ma_client_find_by_appid(const char *appid) +ma_client_s* CServiceMain::ma_client_find_by_appid(const char *appid) { if (NULL == appid) { MAS_LOGE("Input parameter is NULL"); //LCOV_EXCL_LINE @@ -144,7 +101,7 @@ ma_client_s* ma_client_find_by_appid(const char *appid) return NULL; } -ma_client_s* ma_client_find_by_pid(int pid) +ma_client_s* CServiceMain::ma_client_find_by_pid(int pid) { ma_client_s *data = NULL; @@ -166,7 +123,7 @@ ma_client_s* ma_client_find_by_pid(int pid) return NULL; } -bool check_preprocessing_assistant_exists() +bool CServiceMain::check_preprocessing_assistant_exists() { bool ret = false; @@ -191,7 +148,7 @@ bool check_preprocessing_assistant_exists() return ret; } -bool is_current_preprocessing_assistant(const char* appid) +bool CServiceMain::is_current_preprocessing_assistant(const char* appid) { if (NULL == appid) return false; @@ -209,11 +166,11 @@ bool is_current_preprocessing_assistant(const char* appid) return ret; } -int mas_client_initialize(int pid) +int CServiceMain::mas_client_initialize(int pid) { MAS_LOGD("[Enter] pid(%d)", pid); - char appid[MAX_APPID_LEN] = {'\0',}; + 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'; @@ -246,25 +203,25 @@ int mas_client_initialize(int pid) } 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 (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 (g_wakeup_maclient_appid && strncmp(g_wakeup_maclient_appid, appid, MAX_APPID_LEN) == 0) { - g_wakeup_maclient_appid = NULL; + 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 ? g_wakeup_maclient_appid : "NULL"), appid); + g_wakeup_maclient_appid.c_str(), 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()); + mServiceIpc.service_state_change(pid, mas_get_current_service_state()); } else { MAS_LOGE("[ERROR] Fail to retrieve appid"); } @@ -272,7 +229,7 @@ int mas_client_initialize(int pid) return 0; } -int mas_client_deinitialize(int pid) +int CServiceMain::mas_client_deinitialize(int pid) { MAS_LOGD("[Enter] pid(%d)", pid); ma_client_s *client = ma_client_find_by_pid(pid); @@ -283,11 +240,11 @@ int mas_client_deinitialize(int pid) return 0; } -int mas_client_get_audio_format(int pid, int* rate, int* channel, int* audio_type) +int CServiceMain::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); + 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); } @@ -296,14 +253,14 @@ int mas_client_get_audio_format(int pid, int* rate, int* channel, int* audio_typ } #define MAX_LOCAL_VARIABLE_STRING_LEN 256 -int mas_client_get_audio_source_type(int pid, char** type) +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 = multi_assistant_service_plugin_get_recording_audio_source_type(type); + 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; @@ -315,7 +272,7 @@ int mas_client_get_audio_source_type(int pid, char** type) return ret; } -int mas_client_send_preprocessing_information(int pid) +int CServiceMain::mas_client_send_preprocessing_information(int pid) { int ret = -1; MAS_LOGD("[Enter] pid(%d)", pid); @@ -323,7 +280,7 @@ int mas_client_send_preprocessing_information(int 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); + ret = mServiceIpc.send_preprocessing_information(pid, vconf_str); free(vconf_str); vconf_str = NULL; } @@ -331,40 +288,44 @@ int mas_client_send_preprocessing_information(int pid) return ret; } -int mas_client_send_voice_key_status_change(int pid, ma_voice_key_status_e status) +int CServiceMain::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); + 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 mas_client_activate(int pid) +int CServiceMain::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); + ret = mServiceIpc.active_state_change(pid, MA_ACTIVE_STATE_ACTIVE); return ret; } -int mas_client_deactivate(int pid) +int CServiceMain::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); + ret = mServiceIpc.active_state_change(pid, MA_ACTIVE_STATE_INACTIVE); return ret; } -int mas_client_send_asr_result(int pid, int event, char* asr_result) +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 = masc_ui_dbus_send_asr_result(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); } @@ -374,121 +335,121 @@ int mas_client_send_asr_result(int pid, int event, char* asr_result) return ret; } -int mas_client_send_result(int pid, char* display_text, char* utterance_text, char* result_json) +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 = masc_ui_dbus_send_result(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',}; + 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); + mServicePlugin.update_recognition_result(pid_appid, MA_RECOGNITION_RESULT_EVENT_SUCCESS); return ret; } -int mas_client_send_recognition_result(int pid, int result) +int CServiceMain::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); + 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',}; + 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); + mServicePlugin.update_recognition_result(pid_appid, result); return ret; } -int mas_client_start_streaming_audio_data(int pid, int type) +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 = multi_assistant_service_plugin_start_streaming_utterance_data(); + 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 = multi_assistant_service_plugin_start_streaming_previous_utterance_data(); + 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 = multi_assistant_service_plugin_start_streaming_follow_up_data(); + ret = mServicePlugin.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 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 = multi_assistant_service_plugin_stop_streaming_utterance_data(); + ret = mServicePlugin.stop_streaming_utterance_data(); break; case MA_AUDIO_STREAMING_DATA_TYPE_PREVIOUS_UTTERANCE: - ret = multi_assistant_service_plugin_stop_streaming_previous_utterance_data(); + ret = mServicePlugin.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(); + ret = mServicePlugin.stop_streaming_follow_up_data(); break; } return ret; } -int mas_client_update_voice_feedback_state(int pid, int state) +int CServiceMain::mas_client_update_voice_feedback_state(int pid, int state) { const char* pid_appid = NULL; - char buf[MAX_APPID_LEN] = {'\0',}; + 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); + mServicePlugin.update_voice_feedback_state(pid_appid, state); return 0; } -int mas_client_set_assistant_specific_command(int pid, const char *command) +int CServiceMain::mas_client_set_assistant_specific_command(int pid, const char *command) { const char* pid_appid = NULL; - char buf[MAX_APPID_LEN] = {'\0',}; + 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); + mServicePlugin.set_assistant_specific_command(pid_appid, command); return 0; } -int mas_client_set_background_volume(int pid, double ratio) +int CServiceMain::mas_client_set_background_volume(int pid, double ratio) { const char* pid_appid = NULL; - char buf[MAX_APPID_LEN] = {'\0',}; + 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); + mServicePlugin.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) +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',}; + 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; @@ -513,10 +474,10 @@ int mas_client_set_preprocessing_allow_mode(int pid, ma_preprocessing_allow_mode return 0; } -int mas_client_send_preprocessing_result(int pid, bool result) +int CServiceMain::mas_client_send_preprocessing_result(int pid, bool result) { const char* pid_appid = NULL; - char buf[MAX_APPID_LEN] = {'\0',}; + 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; @@ -538,43 +499,43 @@ int mas_client_send_preprocessing_result(int pid, bool result) ma_client_s* client = ma_client_find_by_appid(current_maclient_appid); if (client) { - masc_dbus_send_preprocessing_result(client->pid, result); + mServiceIpc.send_preprocessing_result(client->pid, result); } return 0; } -int mas_client_set_wake_word_audio_require_flag(int pid, bool require) +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',}; + 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); + mServicePlugin.set_wake_word_audio_require_flag(pid_appid, require); return 0; } -int mas_client_set_assistant_language(int pid, const char* language) +int CServiceMain::mas_client_set_assistant_language(int pid, const char* language) { const char* pid_appid = NULL; - char buf[MAX_APPID_LEN] = {'\0',}; + 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); + mServicePlugin.set_assistant_language(pid_appid, language); return 0; } -int mas_client_add_wake_word(int pid, const char* wake_word, const char* language) +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',}; + 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'; @@ -584,11 +545,11 @@ int mas_client_add_wake_word(int pid, const char* wake_word, const char* languag 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, + ret = mServiceConfig.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, + mServiceConfig.save_custom_wake_words(pid_appid, g_maclient_info[loop].wakeup_word, g_maclient_info[loop].wakeup_language); } else { @@ -598,14 +559,14 @@ int mas_client_add_wake_word(int pid, const char* wake_word, const char* languag } } - multi_assistant_service_plugin_add_assistant_wakeup_word(pid_appid, wake_word, language); + mServicePlugin.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) +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',}; + 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'; @@ -615,36 +576,36 @@ int mas_client_remove_wake_word(int pid, const char* wake_word, const char* lang 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, + ret = mServiceConfig.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, + mServiceConfig.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); + mServicePlugin.remove_assistant_wakeup_word(pid_appid, wake_word, language); return 0; } -int mas_ui_client_initialize(int pid) +int CServiceMain::mas_ui_client_initialize(int pid) { MAS_LOGD("[Enter] pid(%d)", pid); return 0; } -int mas_ui_client_deinitialize(int pid) +int CServiceMain::mas_ui_client_deinitialize(int pid) { MAS_LOGD("[Enter] pid(%d)", pid); return 0; } -int mas_ui_client_change_assistant(const char* appid) +int CServiceMain::mas_ui_client_change_assistant(const char* appid) { MAS_LOGD("[Enter]"); @@ -654,21 +615,21 @@ int mas_ui_client_change_assistant(const char* appid) } bool use_custom_ui = mas_get_client_custom_ui_option_by_appid(appid); - masc_ui_dbus_enable_common_ui(!use_custom_ui); + 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 == g_last_voice_key_status) { - mas_client_send_voice_key_status_change(pid, g_last_voice_key_status); + 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 = multi_assistant_service_plugin_start_streaming_utterance_data(); + int ret = mServicePlugin.start_streaming_utterance_data(); if (0 != ret) { MAS_LOGE("[ERROR] Fail to start streaming utterance data(%d)", ret); } @@ -692,7 +653,16 @@ int mas_ui_client_change_assistant(const char* appid) return 0; } -int __mas_assistant_info_cb(ma_assistant_info_s* info, void* user_data) { +static int mas_assistant_info_cb(ma_assistant_info_s* info, void* user_data) { + int ret = -1; + CServiceMain* service_main = static_cast(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) { @@ -773,41 +743,49 @@ int __mas_assistant_info_cb(ma_assistant_info_s* info, void* user_data) { return 0; } -static void mas_active_state_changed_cb(keynode_t* key, void* data) +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); - if (vconf_value) { - multi_assistant_service_plugin_activate(); + 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 { - multi_assistant_service_plugin_deactivate(); + MAS_LOGE("Could not change plugin state : %p %p", g_service_main, plugin); } } } -static int init_plugin(void) +int CServiceMain::initialize_service_plugin(void) { - if (0 != multi_assistant_service_plugin_initialize()) { + if (0 != mServicePlugin.initialize()) { MAS_LOGE("Fail to ws intialize"); return -1; } - if (0 != multi_assistant_service_plugin_set_language(g_current_lang)) { + if (0 != mServicePlugin.set_language(g_current_lang.c_str())) { MAS_LOGE("Fail to ws set language"); return -1; } - if (0 == g_config.mas_config_get_assistant_info(__mas_assistant_info_cb, NULL)) { + 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)) { - g_config.mas_config_load_custom_wake_words(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)) { - multi_assistant_service_plugin_set_assistant_wakeup_engine( + mServicePlugin.set_assistant_wakeup_engine( g_maclient_info[loop].appid, g_maclient_info[loop].wakeup_engine); } @@ -815,7 +793,7 @@ static int init_plugin(void) 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( + 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])) { @@ -827,7 +805,7 @@ static int init_plugin(void) 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( + 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"); @@ -840,7 +818,7 @@ static int init_plugin(void) MAS_LOGE("Fail to load assistant info"); } - if (0 != multi_assistant_service_plugin_set_callbacks()) { + if (0 != mServicePlugin.set_callbacks()) { MAS_LOGE("Fail to set callbacks"); return -1; } @@ -848,35 +826,35 @@ static int init_plugin(void) return 0; } -static int deinit_plugin(void) +int CServiceMain::deinitialize_service_plugin(void) { MAS_LOGI("[ENTER]"); - if (0 != multi_assistant_service_plugin_deactivate()) { + if (0 != mServicePlugin.deactivate()) { MAS_LOGE("Fail to deactivate"); } - if (0 != multi_assistant_service_plugin_deinitialize()) { + if (0 != mServicePlugin.deinitialize()) { MAS_LOGE("Fail to deinitialize"); } MAS_LOGI("[END]"); return 0; } -static int process_activated_setting() +int CServiceMain::process_activated_setting() { - if (0 == vconf_notify_key_changed(MULTI_ASSISTANT_SETTINGS_ACTIVATED, mas_active_state_changed_cb, NULL)) { + if (0 == vconf_notify_key_changed(MULTI_ASSISTANT_SETTINGS_ACTIVATED, active_state_changed_cb, NULL)) { /* Activate / deactivate according to the vconf key setting */ - mas_active_state_changed_cb(NULL, NULL); + 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(); + mServicePlugin.activate(); const char *default_assistant = NULL; - if (0 == multi_assistant_service_plugin_get_default_assistant(&default_assistant)) { + 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); - multi_assistant_service_plugin_set_default_assistant(default_assistant); + mServicePlugin.set_default_assistant(default_assistant); } else { MAS_LOGE("No default assistant, and no assistant installed"); } @@ -887,56 +865,7 @@ static int process_activated_setting() 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 CServiceMain::mas_get_current_client_pid() { int ret = -1; if (g_current_maclient_info >= 0 && g_current_maclient_info < MAX_MACLIENT_INFO_NUM) { @@ -949,7 +878,7 @@ int mas_get_current_client_pid() return ret; } -int mas_get_current_preprocessing_client_pid() +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) { @@ -962,7 +891,7 @@ int mas_get_current_preprocessing_client_pid() return ret; } -int mas_get_client_pid_by_appid(const char *appid) +int CServiceMain::mas_get_client_pid_by_appid(const char *appid) { int ret = -1; @@ -985,7 +914,7 @@ int mas_get_client_pid_by_appid(const char *appid) return ret; } -const char* mas_get_client_appid_by_pid(int pid) +const char* CServiceMain::mas_get_client_appid_by_pid(int pid) { const char* ret = NULL; @@ -1006,7 +935,7 @@ const char* mas_get_client_appid_by_pid(int pid) return ret; } -bool mas_get_client_custom_ui_option_by_appid(const char *appid) +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++) { @@ -1021,13 +950,13 @@ bool mas_get_client_custom_ui_option_by_appid(const char *appid) return ret; } -int mas_get_client_pid_by_wakeup_word(const char *wakeup_word) +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* mas_get_client_appid_by_wakeup_word(const char *wakeup_word) +const char* CServiceMain::mas_get_client_appid_by_wakeup_word(const char *wakeup_word) { int loop; const char *appid = NULL; @@ -1073,7 +1002,7 @@ const char* mas_get_client_appid_by_wakeup_word(const char *wakeup_word) return appid; } -int mas_set_current_client_by_wakeup_word(const char *wakeup_word) +int CServiceMain::mas_set_current_client_by_wakeup_word(const char *wakeup_word) { int loop; int ret = -1; @@ -1125,7 +1054,7 @@ int mas_set_current_client_by_wakeup_word(const char *wakeup_word) return ret; } -int mas_set_current_client_by_appid(const char *appid) +int CServiceMain::mas_set_current_client_by_appid(const char *appid) { int ret = -1; int prev_selection = g_current_maclient_info; @@ -1150,7 +1079,7 @@ int mas_set_current_client_by_appid(const char *appid) return ret; } -int mas_launch_client_by_appid(const char *appid, CLIENT_LAUNCH_MODE launch_mode) +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"); @@ -1195,7 +1124,7 @@ int mas_launch_client_by_appid(const char *appid, CLIENT_LAUNCH_MODE launch_mode } } } - MAS_LOGD("g_wakeup_maclient_appid : %s, %d", g_wakeup_maclient_appid, found); + MAS_LOGD("g_wakeup_maclient_appid : %s, %d", g_wakeup_maclient_appid.c_str(), found); } if (b) bundle_free(b); @@ -1204,7 +1133,7 @@ int mas_launch_client_by_appid(const char *appid, CLIENT_LAUNCH_MODE launch_mode return result; } -int mas_bring_client_to_foreground(const char* appid) +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)) { @@ -1231,20 +1160,20 @@ int mas_bring_client_to_foreground(const char* appid) return result; } -int mas_launch_client_by_wakeup_word(const char *wakeup_word) +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 mas_prelaunch_default_assistant() +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 == multi_assistant_service_plugin_get_default_assistant(&default_assistant)) { + 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); @@ -1254,23 +1183,23 @@ int mas_prelaunch_default_assistant() return 0; } -int mas_update_voice_key_support_mode() +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 == multi_assistant_service_plugin_get_default_assistant(&default_assistant)) { + 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) { - multi_assistant_service_plugin_set_voice_key_tap_duration(duration); + mServicePlugin.set_voice_key_tap_duration(duration); } else { - multi_assistant_service_plugin_unset_voice_key_tap_duration(); + mServicePlugin.unset_voice_key_tap_duration(); } - multi_assistant_service_plugin_set_voice_key_support_mode( + mServicePlugin.set_voice_key_support_mode( g_maclient_info[loop].voice_key_support_mode); successful = true; } @@ -1279,13 +1208,13 @@ int mas_update_voice_key_support_mode() } 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); + mServicePlugin.unset_voice_key_tap_duration(); + mServicePlugin.set_voice_key_support_mode(VOICE_KEY_SUPPORT_MODE_NONE); } return 0; } -ma_preprocessing_allow_mode_e get_preprocessing_allow_mode(const char* appid) +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) { @@ -1300,7 +1229,7 @@ ma_preprocessing_allow_mode_e get_preprocessing_allow_mode(const char* appid) /* 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) +int CServiceMain::mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event) { const char* current_maclient_appid = NULL; const char* preprocessing_allow_appid = NULL; @@ -1408,7 +1337,7 @@ int mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event) return 0; } -int mas_set_current_service_state(ma_service_state_e state) +int CServiceMain::mas_set_current_service_state(ma_service_state_e state) { g_current_service_state = state; @@ -1421,7 +1350,7 @@ int mas_set_current_service_state(ma_service_state_e state) data = static_cast(g_slist_nth_data(g_client_list, i)); if (NULL != data && -1 != data->pid) { - int ret = masc_dbus_service_state_change(data->pid, state); + 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); @@ -1431,31 +1360,41 @@ int mas_set_current_service_state(ma_service_state_e state) return 0; } -ma_service_state_e mas_get_current_service_state() +ma_service_state_e CServiceMain::mas_get_current_service_state() { return g_current_service_state; } -static int pkg_app_list_cb(const pkgmgrinfo_appinfo_h handle, void *user_data) +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); + 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; - } - } + 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; } return 0; @@ -1482,8 +1421,10 @@ Update package (change the source codes and Run As again), there are four scenar */ 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(user_data); + int ret = 0; - uid_t uid = getuid (); + uid_t uid = getuid(); pkgmgrinfo_pkginfo_h handle = NULL; static bool in_progress = false; bool should_exit = false; @@ -1501,16 +1442,16 @@ static void _package_manager_event_cb(const char *type, const char *package, pac return; bool user = false; - LOGD("type=%s package=%s event_type=%d event_state=%d progress=%d error=%d", + 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) { - LOGW("Failed to call pkgmgrinfo_pkginfo_get_pkginfo & get_usr_pkginfo(\"%s\",~) returned %d, uid : %d", package, ret, getuid ()); + 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); + 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 ()); + MAS_LOGW("Failed to call pkgmgrinfo_pkginfo_get_pkginfo & get_usr_pkginfo(\"%s\",~) returned %d, uid : %d", package, ret, getuid()); return; } } @@ -1524,16 +1465,32 @@ static void _package_manager_event_cb(const char *type, const char *package, pac } if (1 == ret) { if (PACKAGE_MANAGER_EVENT_STATE_STARTED == event_state) { - LOGI("processing PACKAGE_MANAGER_EVENT_STATE_STARTED event : %d", event_type); + MAS_LOGI("processing PACKAGE_MANAGER_EVENT_STATE_STARTED event : %d", event_type); if (false == in_progress) { in_progress = true; - deinit_plugin(); + if (service_main) { + service_main->deinitialize_service_plugin(); + } else { + MAS_LOGE("service_main is NULL"); + } } } else if (PACKAGE_MANAGER_EVENT_STATE_COMPLETED == event_state) { - LOGI("processing PACKAGE_MANAGER_EVENT_STATE_COMPLETED event : %d", event_type); + MAS_LOGI("processing PACKAGE_MANAGER_EVENT_STATE_COMPLETED event : %d", event_type); if (false == in_progress) { - deinit_plugin(); + 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; } @@ -1549,29 +1506,50 @@ static void _package_manager_event_cb(const char *type, const char *package, pac return; } -bool app_create(void *data) +bool CServiceMain::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; + 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, NULL); + 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 { + } else { LOGE("package_manager_set_event_cb failed(%d)", ret); } - } - else { + } else { LOGE("package_manager_create failed(%d)", ret); } } @@ -1579,7 +1557,7 @@ bool app_create(void *data) return true; } -void app_terminate(void *data) +void CServiceMain::app_terminate(void *data) { MAS_LOGI("[ENTER]"); if (g_pkgmgr) { @@ -1588,8 +1566,17 @@ void app_terminate(void *data) g_pkgmgr = NULL; } - // Todo: add your code here. - deinit_wakeup(); + 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; } diff --git a/src/multi_assistant_service_plugin.cpp b/src/service_plugin.cpp similarity index 74% rename from src/multi_assistant_service_plugin.cpp rename to src/service_plugin.cpp index a9f41bd..7f1b4ef 100644 --- a/src/multi_assistant_service_plugin.cpp +++ b/src/service_plugin.cpp @@ -26,32 +26,23 @@ #include #include #include +#include -#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" +#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 -#ifdef BUF_SAVE_MODE -static char g_temp_file_name[128] = {'\0',}; - -static FILE* g_pFile = NULL; - -static int g_count = 1; -#endif +typedef struct { + void* data; + CServicePlugin* plugin; +} AsyncParam; -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() +bool CServicePlugin::is_ui_panel_enabled() { /* By default we assume the ui panel is always enabled unless explicitly turned off */ bool ret = true; @@ -93,45 +84,81 @@ Eina_Bool __send_result(void *data) } #endif /* -TEST_CODE */ -Eina_Bool process_wakeup_event_by_appid_timer(void* data) +static Eina_Bool process_wakeup_event_by_appid_timer(void* data) { - char* appid = static_cast(data); + if (NULL == data) return ECORE_CALLBACK_CANCEL; + AsyncParam* param = static_cast(data); + + char* appid = static_cast(param->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); + 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); + } - 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); + 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; } -Eina_Bool process_wakeup_event_by_word_timer(void* data) +static Eina_Bool process_wakeup_event_by_word_timer(void* data) { - char* wakeup_word = static_cast(data); MAS_LOGD("[ENTER]"); - if (!wakeup_word) return EINA_FALSE; + if (NULL == data) return ECORE_CALLBACK_CANCEL; + AsyncParam* param = static_cast(data); + + char* wakeup_word = static_cast(param->data); + CServicePlugin* plugin = param->plugin; + CServiceMain* service_main = nullptr; + + if (plugin) { + service_main = plugin->get_service_main(); + } + + delete param; + param = nullptr; - const char* appid = mas_get_client_appid_by_wakeup_word(wakeup_word); - process_wakeup_event_by_appid_timer(static_cast(strdup(appid))); + 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(strdup(appid)); + param->plugin = plugin; + process_wakeup_event_by_appid_timer(static_cast(param)); + } + } + } if (wakeup_word) free(wakeup_word); @@ -139,19 +166,24 @@ Eina_Bool process_wakeup_event_by_word_timer(void* data) return ECORE_CALLBACK_CANCEL; } -static void __wakeup_event_cb(mas_wakeup_event_info wakeup_info, const char* wakeup_word, void* user_data) +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; - 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; + CServicePlugin *plugin = static_cast(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; + } } } } @@ -208,17 +240,26 @@ static void __wakeup_event_cb(mas_wakeup_event_info wakeup_info, const char* wak } #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(strdup(wakeup_info.wakeup_appid))); - ecore_thread_main_loop_end(); + AsyncParam* param = new(std::nothrow) AsyncParam; + if (param) { + param->data = static_cast(strdup(wakeup_info.wakeup_appid)); + param->plugin = static_cast(user_data); + ecore_thread_main_loop_begin(); + ecore_timer_add(0.0f, process_wakeup_event_by_appid_timer, + static_cast(param)); + 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(strdup(wakeup_info.wakeup_word))); - ecore_thread_main_loop_end(); + AsyncParam* param = new(std::nothrow) AsyncParam; + if (param) { + param->data = static_cast(strdup(wakeup_info.wakeup_word)); + param->plugin = static_cast(user_data); + ecore_thread_main_loop_begin(); + ecore_timer_add(0.0f, process_wakeup_event_by_word_timer, + static_cast(param)); + ecore_thread_main_loop_end(); + } } - } static bool __validate_streaming_event_order(int pid, mas_speech_streaming_event_e *event) @@ -230,7 +271,7 @@ static bool __validate_streaming_event_order(int pid, mas_speech_streaming_event if (NULL == event) return false; - mas_speech_streaming_event_e expected_sequence [][2] = { + 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}, @@ -273,12 +314,23 @@ static bool __validate_streaming_event_order(int pid, mas_speech_streaming_event return ret; } -static void handle_speech_streaming_event_failure(void *data) +void handle_speech_streaming_event_failure(void* data) { - mas_client_send_recognition_result(0, MA_RECOGNITION_RESULT_EVENT_ERROR); + AsyncParam* param = static_cast(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, unsigned char* buffer, int len, void *user_data) +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); @@ -286,29 +338,41 @@ static void __audio_streaming_cb(mas_speech_streaming_event_e event, unsigned ch } 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); + 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); + CServicePlugin* plugin = static_cast(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 to preprocessing client, ret(%d)", 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) @@ -328,15 +392,20 @@ static void __audio_streaming_cb(mas_speech_streaming_event_e event, unsigned ch static void __speech_status_cb(mas_speech_status_e status, void *user_data) { - MAS_LOGD( "[SUCCESS] __speech_status_cb is called, status(%d)", status); + 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); + 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); + CServiceIpcDbus* service_ipc = nullptr; + CServicePlugin *plugin = static_cast(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); } @@ -345,58 +414,99 @@ static void __error_cb(int error, const char* err_msg, void* user_data) 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"); + CServiceMain* service_main = nullptr; + CServicePlugin *plugin = static_cast(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); - - 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); + MAS_LOGD("[SUCCESS] __streaming_section_changed_cb is called, section(%d)", section); + + CServiceIpcDbus *service_ipc = nullptr; + CServiceMain* service_main = nullptr; + CServicePlugin *plugin = static_cast(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); - - 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); + MAS_LOGD("[SUCCESS] __wakeup_engine_command_cb is called, command(%s)", command); + + CServiceIpcDbus *service_ipc = nullptr; + CServiceMain* service_main = nullptr; + CServicePlugin *plugin = static_cast(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); + MAS_LOGD("[SUCCESS] __wakeup_service_state_changed_cb is called, state(%d)", state); - mas_set_current_service_state(state); + CServiceMain* service_main = nullptr; + CServicePlugin *plugin = static_cast(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); - - 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); + 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(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 multi_assistant_service_plugin_initialize(void) +int CServicePlugin::initialize(void) { - MAS_LOGD( "[Enter]"); + MAS_LOGD("[Enter]"); - char filepath[512] = {'\0',}; + 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); @@ -563,7 +673,7 @@ int multi_assistant_service_plugin_initialize(void) return ret; } -int multi_assistant_service_plugin_deinitialize(void) +int CServicePlugin::deinitialize(void) { #ifdef BUF_SAVE_MODE if (g_pFile) { @@ -595,7 +705,7 @@ int multi_assistant_service_plugin_deinitialize(void) return ret; } -int multi_assistant_service_plugin_get_settings(ma_plugin_settings **settings, size_t *struct_size) +int CServicePlugin::get_settings(ma_plugin_settings **settings, size_t *struct_size) { int ret = -1; if (NULL != g_handle) { @@ -614,7 +724,7 @@ int multi_assistant_service_plugin_get_settings(ma_plugin_settings **settings, s return ret; } -int multi_assistant_service_plugin_set_language(const char* language) +int CServicePlugin::set_language(const char* language) { int ret = -1; if (NULL != g_handle) { @@ -633,7 +743,7 @@ int multi_assistant_service_plugin_set_language(const char* language) return ret; } -int multi_assistant_service_plugin_add_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language) +int CServicePlugin::add_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language) { int ret = -1; if (NULL != g_handle) { @@ -652,7 +762,7 @@ int multi_assistant_service_plugin_add_assistant_wakeup_word(const char* appid, return ret; } -int multi_assistant_service_plugin_remove_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language) +int CServicePlugin::remove_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language) { int ret = -1; if (NULL != g_handle) { @@ -671,7 +781,7 @@ int multi_assistant_service_plugin_remove_assistant_wakeup_word(const char* appi return ret; } -int multi_assistant_service_plugin_add_assistant_language(const char* appid, const char* language) +int CServicePlugin::add_assistant_language(const char* appid, const char* language) { int ret = -1; if (NULL != g_handle) { @@ -690,7 +800,7 @@ int multi_assistant_service_plugin_add_assistant_language(const char* appid, con return ret; } -int multi_assistant_service_plugin_set_assistant_wakeup_engine(const char* appid, const char* engine) +int CServicePlugin::set_assistant_wakeup_engine(const char* appid, const char* engine) { int ret = -1; if (NULL != g_handle) { @@ -709,7 +819,7 @@ int multi_assistant_service_plugin_set_assistant_wakeup_engine(const char* appid return ret; } -int multi_assistant_service_plugin_set_default_assistant(const char* appid) +int CServicePlugin::set_default_assistant(const char* appid) { int ret = -1; if (NULL != g_handle) { @@ -728,7 +838,7 @@ int multi_assistant_service_plugin_set_default_assistant(const char* appid) return ret; } -int multi_assistant_service_plugin_get_default_assistant(const char** appid) +int CServicePlugin::get_default_assistant(const char** appid) { int ret = -1; if (NULL == appid) { @@ -751,7 +861,7 @@ int multi_assistant_service_plugin_get_default_assistant(const char** appid) return ret; } -int multi_assistant_service_plugin_activate(void) +int CServicePlugin::activate(void) { int ret = -1; if (NULL != g_handle) { @@ -770,7 +880,7 @@ int multi_assistant_service_plugin_activate(void) return ret; } -int multi_assistant_service_plugin_deactivate(void) +int CServicePlugin::deactivate(void) { int ret = -1; if (NULL != g_handle) { @@ -789,7 +899,7 @@ int multi_assistant_service_plugin_deactivate(void) return ret; } -int multi_assistant_service_plugin_update_voice_feedback_state(const char* appid, int state) +int CServicePlugin::update_voice_feedback_state(const char* appid, int state) { int ret = -1; if (NULL != g_handle) { @@ -808,7 +918,7 @@ int multi_assistant_service_plugin_update_voice_feedback_state(const char* appid return ret; } -int multi_assistant_service_plugin_set_assistant_specific_command(const char* appid, const char* command) +int CServicePlugin::set_assistant_specific_command(const char* appid, const char* command) { int ret = -1; if (NULL != g_handle) { @@ -827,7 +937,7 @@ int multi_assistant_service_plugin_set_assistant_specific_command(const char* ap return ret; } -int multi_assistant_service_plugin_set_background_volume(const char* appid, double ratio) +int CServicePlugin::set_background_volume(const char* appid, double ratio) { int ret = -1; if (NULL != g_handle) { @@ -846,7 +956,7 @@ int multi_assistant_service_plugin_set_background_volume(const char* appid, doub return ret; } -int multi_assistant_service_plugin_update_recognition_result(const char* appid, int state) +int CServicePlugin::update_recognition_result(const char* appid, int state) { int ret = -1; if (NULL != g_handle) { @@ -865,7 +975,7 @@ int multi_assistant_service_plugin_update_recognition_result(const char* appid, return ret; } -int multi_assistant_service_plugin_process_event(int event, void *data, int len) +int CServicePlugin::process_event(int event, void *data, int len) { int ret = -1; if (NULL != g_handle) { @@ -884,7 +994,7 @@ int multi_assistant_service_plugin_process_event(int event, void *data, int len) return ret; } -int multi_assistant_service_plugin_start_streaming_utterance_data(void) +int CServicePlugin::start_streaming_utterance_data(void) { int ret = -1; if (NULL != g_handle) { @@ -903,7 +1013,7 @@ int multi_assistant_service_plugin_start_streaming_utterance_data(void) return ret; } -int multi_assistant_service_plugin_stop_streaming_utterance_data(void) +int CServicePlugin::stop_streaming_utterance_data(void) { int ret = -1; if (NULL != g_handle) { @@ -922,7 +1032,7 @@ int multi_assistant_service_plugin_stop_streaming_utterance_data(void) return ret; } -int multi_assistant_service_plugin_start_streaming_previous_utterance_data(void) +int CServicePlugin::start_streaming_previous_utterance_data(void) { int ret = -1; if (NULL != g_handle) { @@ -941,7 +1051,7 @@ int multi_assistant_service_plugin_start_streaming_previous_utterance_data(void) return ret; } -int multi_assistant_service_plugin_stop_streaming_previous_utterance_data(void) +int CServicePlugin::stop_streaming_previous_utterance_data(void) { int ret = -1; if (NULL != g_handle) { @@ -960,7 +1070,7 @@ int multi_assistant_service_plugin_stop_streaming_previous_utterance_data(void) return ret; } -int multi_assistant_service_plugin_start_streaming_follow_up_data(void) +int CServicePlugin::start_streaming_follow_up_data(void) { int ret = -1; if (NULL != g_handle) { @@ -979,7 +1089,7 @@ int multi_assistant_service_plugin_start_streaming_follow_up_data(void) return ret; } -int multi_assistant_service_plugin_stop_streaming_follow_up_data(void) +int CServicePlugin::stop_streaming_follow_up_data(void) { int ret = -1; if (NULL != g_handle) { @@ -998,7 +1108,7 @@ int multi_assistant_service_plugin_stop_streaming_follow_up_data(void) return ret; } -int multi_assistant_service_plugin_get_recording_audio_format(int *rate, int *channel, int *audio_type) +int CServicePlugin::get_recording_audio_format(int *rate, int *channel, int *audio_type) { int ret = -1; if (NULL != g_handle) { @@ -1017,7 +1127,7 @@ int multi_assistant_service_plugin_get_recording_audio_format(int *rate, int *ch return ret; } -int multi_assistant_service_plugin_get_recording_audio_source_type(char** type) +int CServicePlugin::get_recording_audio_source_type(char** type) { int ret = -1; if (NULL != g_handle) { @@ -1036,7 +1146,7 @@ int multi_assistant_service_plugin_get_recording_audio_source_type(char** type) return ret; } -int multi_assistant_service_plugin_set_voice_key_tap_duration(float duration) +int CServicePlugin::set_voice_key_tap_duration(float duration) { int ret = -1; if (NULL != g_handle) { @@ -1055,7 +1165,7 @@ int multi_assistant_service_plugin_set_voice_key_tap_duration(float duration) return ret; } -int multi_assistant_service_plugin_unset_voice_key_tap_duration() +int CServicePlugin::unset_voice_key_tap_duration() { int ret = -1; if (NULL != g_handle) { @@ -1074,7 +1184,7 @@ int multi_assistant_service_plugin_unset_voice_key_tap_duration() return ret; } -int multi_assistant_service_plugin_set_voice_key_support_mode(int mode) +int CServicePlugin::set_voice_key_support_mode(int mode) { int ret = -1; if (NULL != g_handle) { @@ -1093,7 +1203,7 @@ int multi_assistant_service_plugin_set_voice_key_support_mode(int mode) return ret; } -int multi_assistant_service_plugin_set_wake_word_audio_require_flag(const char* appid, bool require) +int CServicePlugin::set_wake_word_audio_require_flag(const char* appid, bool require) { int ret = -1; if (NULL != g_handle) { @@ -1112,7 +1222,7 @@ int multi_assistant_service_plugin_set_wake_word_audio_require_flag(const char* return ret; } -int multi_assistant_service_plugin_set_assistant_language(const char* appid, const char* language) +int CServicePlugin::set_assistant_language(const char* appid, const char* language) { int ret = -1; if (NULL != g_handle) { @@ -1131,69 +1241,69 @@ int multi_assistant_service_plugin_set_assistant_language(const char* appid, con return ret; } -int multi_assistant_service_plugin_set_callbacks(void) +int CServicePlugin::set_callbacks(void) { - int ret = multi_assistant_service_plugin_set_wakeup_event_callback(__wakeup_event_cb, NULL); + int ret = set_wakeup_event_callback(__wakeup_event_cb, this); 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); + ret = set_utterance_streaming_callback(__audio_streaming_cb, this); 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); + 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 = multi_assistant_service_plugin_set_follow_up_streaming_callback(__audio_streaming_cb, NULL); + 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 = multi_assistant_service_plugin_set_speech_status_callback(__speech_status_cb, NULL); + ret = set_speech_status_callback(__speech_status_cb, this); 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); + ret = set_setting_changed_callback(__setting_changed_cb, this); if (0 != ret) { MAS_LOGE("Fail to set setting changed cb"); return ret; } - ret = multi_assistant_service_plugin_set_error_callback(__error_cb, NULL); + ret = set_error_callback(__error_cb, this); 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); + 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 = multi_assistant_service_plugin_set_wakeup_engine_command_callback(__wakeup_engine_command_cb, NULL); + 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 = multi_assistant_service_plugin_set_wakeup_service_state_changed_callback(__wakeup_service_state_changed_cb, NULL); + 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 = multi_assistant_service_plugin_set_voice_key_status_changed_callback(__wakeup_service_voice_key_status_changed_cb, NULL); + 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; @@ -1202,7 +1312,7 @@ int multi_assistant_service_plugin_set_callbacks(void) return 0; } -int multi_assistant_service_plugin_set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data) +int CServicePlugin::set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data) { int ret = -1; if (NULL != g_handle) { @@ -1211,6 +1321,7 @@ int multi_assistant_service_plugin_set_wakeup_event_callback(wakeup_service_wake 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); } @@ -1221,7 +1332,7 @@ int multi_assistant_service_plugin_set_wakeup_event_callback(wakeup_service_wake return ret; } -int multi_assistant_service_plugin_set_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data) +int CServicePlugin::set_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data) { int ret = -1; if (NULL != g_handle) { @@ -1240,7 +1351,7 @@ int multi_assistant_service_plugin_set_utterance_streaming_callback(wakeup_servi return ret; } -int multi_assistant_service_plugin_set_previous_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data) +int CServicePlugin::set_previous_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data) { int ret = -1; if (NULL != g_handle) { @@ -1259,7 +1370,7 @@ int multi_assistant_service_plugin_set_previous_utterance_streaming_callback(wak return ret; } -int multi_assistant_service_plugin_set_follow_up_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data) +int CServicePlugin::set_follow_up_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data) { int ret = -1; if (NULL != g_handle) { @@ -1278,7 +1389,7 @@ int multi_assistant_service_plugin_set_follow_up_streaming_callback(wakeup_servi return ret; } -int multi_assistant_service_plugin_set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data) +int CServicePlugin::set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data) { int ret = -1; if (NULL != g_handle) { @@ -1295,7 +1406,7 @@ int multi_assistant_service_plugin_set_speech_status_callback(wakeup_service_spe return ret; } -int multi_assistant_service_plugin_set_setting_changed_callback(wakeup_service_setting_changed_cb callback, void* user_data) +int CServicePlugin::set_setting_changed_callback(wakeup_service_setting_changed_cb callback, void* user_data) { int ret = -1; if (NULL != g_handle) { @@ -1312,7 +1423,7 @@ int multi_assistant_service_plugin_set_setting_changed_callback(wakeup_service_s return ret; } -int multi_assistant_service_plugin_set_error_callback(wakeup_service_error_cb callback, void* user_data) +int CServicePlugin::set_error_callback(wakeup_service_error_cb callback, void* user_data) { int ret = -1; if (NULL != g_handle) { @@ -1329,7 +1440,7 @@ int multi_assistant_service_plugin_set_error_callback(wakeup_service_error_cb ca return ret; } -int multi_assistant_service_plugin_set_streaming_section_changed_callback(wakeup_service_streaming_section_changed_cb callback, void* user_data) +int CServicePlugin::set_streaming_section_changed_callback(wakeup_service_streaming_section_changed_cb callback, void* user_data) { int ret = -1; if (NULL != g_handle) { @@ -1346,7 +1457,7 @@ int multi_assistant_service_plugin_set_streaming_section_changed_callback(wakeup return ret; } -int multi_assistant_service_plugin_set_wakeup_engine_command_callback(wakeup_service_wakeup_engine_command_cb callback, void* user_data) +int CServicePlugin::set_wakeup_engine_command_callback(wakeup_service_wakeup_engine_command_cb callback, void* user_data) { int ret = -1; if (NULL != g_handle) { @@ -1363,7 +1474,7 @@ int multi_assistant_service_plugin_set_wakeup_engine_command_callback(wakeup_ser 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 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) { @@ -1380,7 +1491,7 @@ int multi_assistant_service_plugin_set_wakeup_service_state_changed_callback(wak 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 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) { diff --git a/tests/utc/config/CMakeLists.txt b/tests/utc/config/CMakeLists.txt index ad3d302..f874261 100644 --- a/tests/utc/config/CMakeLists.txt +++ b/tests/utc/config/CMakeLists.txt @@ -13,7 +13,7 @@ ADD_DEFINITIONS("-DFULLVER=\"${FULLVER}\"") SET(TEST_SOURCES test_config.cpp - ${CMAKE_SOURCE_DIR}/src/multi_assistant_config.cpp + ${CMAKE_SOURCE_DIR}/src/service_config.cpp ) # Find Packages diff --git a/tests/utc/config/test_config.cpp b/tests/utc/config/test_config.cpp index 6a92495..d9b6299 100644 --- a/tests/utc/config/test_config.cpp +++ b/tests/utc/config/test_config.cpp @@ -16,7 +16,7 @@ #include -#include "multi_assistant_config.h" +#include "service_config.h" #include @@ -32,7 +32,7 @@ public: } 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]; }; @@ -47,7 +47,7 @@ public: 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); @@ -56,7 +56,7 @@ public: } 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]; }; @@ -65,12 +65,12 @@ TEST_F(StorageWithEmptyWakeWord, HasOneWakeWordAfterAdd) { 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); } @@ -79,17 +79,17 @@ TEST_F(StorageWithEmptyWakeWord, HasTwoWakeWordsWhenDifferentLanguageAdded) { 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); } @@ -98,7 +98,7 @@ TEST_F(StorageWithEmptyWakeWord, RemovalFailsWhenNoMatchingEntryExists) { 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); @@ -107,23 +107,23 @@ TEST_F(StorageWithEmptyWakeWord, RemovalFailsWhenNoMatchingEntryExists) { } 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); } @@ -131,16 +131,16 @@ TEST_F(StorageWithAnArbitraryWakeWord, HasZeroWakeWordAfterRemoval) { 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); @@ -150,16 +150,16 @@ TEST_F(StorageWithAnArbitraryWakeWord, RemovesItemRequestedForRemoval) { 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); -- 2.7.4 From e0c387570874ef0ba9dfc77f6214ae03b8d3e1b4 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Fri, 21 Feb 2020 20:09:51 +0900 Subject: [PATCH 12/16] Extract some of existing logic into separate classes Change-Id: I125779f5ed85d2f4a7609b43fcb21f9d43c74404 --- CMakeLists.txt | 2 + inc/application_manager.h | 36 ++ inc/application_manager_aul.h | 38 +++ inc/client_manager.h | 67 ++++ inc/service_ipc_dbus.h | 12 +- inc/service_ipc_dbus_dispatcher.h | 33 +- inc/service_main.h | 57 ++-- src/application_manager_aul.cpp | 30 ++ src/client_manager.cpp | 188 +++++++++++ src/service_ipc_dbus.cpp | 17 +- src/service_ipc_dbus_dispatcher.cpp | 156 ++++----- src/service_main.cpp | 411 ++++++++++------------- src/service_plugin.cpp | 2 +- tests/utc/CMakeLists.txt | 1 + tests/utc/client-manager/CMakeLists.txt | 47 +++ tests/utc/client-manager/test_client_manager.cpp | 195 +++++++++++ 16 files changed, 947 insertions(+), 345 deletions(-) create mode 100644 inc/application_manager.h create mode 100644 inc/application_manager_aul.h create mode 100644 inc/client_manager.h create mode 100644 src/application_manager_aul.cpp create mode 100644 src/client_manager.cpp create mode 100644 tests/utc/client-manager/CMakeLists.txt create mode 100644 tests/utc/client-manager/test_client_manager.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index aca1239..be36924 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,8 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc) SET(SRCS src/main.cpp src/service_config.cpp + src/application_manager_aul.cpp + src/client_manager.cpp src/service_main.cpp src/service_plugin.cpp src/service_ipc_dbus.cpp diff --git a/inc/application_manager.h b/inc/application_manager.h new file mode 100644 index 0000000..f6733fc --- /dev/null +++ b/inc/application_manager.h @@ -0,0 +1,36 @@ +/* + * 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 __APPLICATION_MANAGER_H__ +#define __APPLICATION_MANAGER_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +class IApplicationManager { +public: + virtual bool is_application_running(int pid) = 0; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* __APPLICATION_MANAGER_H__ */ diff --git a/inc/application_manager_aul.h b/inc/application_manager_aul.h new file mode 100644 index 0000000..2c47dc2 --- /dev/null +++ b/inc/application_manager_aul.h @@ -0,0 +1,38 @@ +/* + * 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 __APPLICATION_MANAGER_AUL_H__ +#define __APPLICATION_MANAGER_AUL_H__ + +#include "application_manager.h" + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +class CApplicationManagerAul : public IApplicationManager { +public: + virtual bool is_application_running(int pid) override; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* __APPLICATION_MANAGER_AUL_H__ */ diff --git a/inc/client_manager.h b/inc/client_manager.h new file mode 100644 index 0000000..d2c51e2 --- /dev/null +++ b/inc/client_manager.h @@ -0,0 +1,67 @@ +/* + * 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 __CLIENT_MANAGER_H__ +#define __CLIENT_MANAGER_H__ + +#include "application_manager.h" + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + int pid; + std::string appid; +} ma_client_s; + +class CClientManager { +public: + CClientManager() {} + virtual ~CClientManager() {} + + int set_application_manager(IApplicationManager* manager); + int create_client(int pid, std::string appid); + int destroy_client_by_pid(int pid); + int destroy_client_by_appid(std::string appid); + + int get_client_num(); + int find_client_pid_by_index(unsigned int index); + + int find_client_pid_by_appid(std::string appid); + std::string find_client_appid_by_pid(int pid); + + bool check_client_validity_by_appid(std::string appid); +private: + ma_client_s* find_client_by_appid(std::string appid); + ma_client_s* find_client_by_pid(int pid); + ma_client_s* get_client_by_index(unsigned int index); + int destroy_client(ma_client_s* client); + +private: + IApplicationManager* mApplicationManager{nullptr}; + GSList* g_client_list{nullptr}; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* __CLIENT_MANAGER_H__ */ diff --git a/inc/service_ipc_dbus.h b/inc/service_ipc_dbus.h index 7242f12..8bd33de 100644 --- a/inc/service_ipc_dbus.h +++ b/inc/service_ipc_dbus.h @@ -46,7 +46,7 @@ public: 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_asr_result(int pid, int event, const 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); @@ -56,9 +56,11 @@ public: 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); + void set_client_manager(CClientManager* manager) { + mClientManager = manager; + } + void set_service_ipc_observer(IServiceIpcObserver* observer) { + mDispatcher.set_ipc_observer(observer); } private: int __dbus_check(); @@ -76,7 +78,7 @@ private: int g_streaming_data_serial{0}; - CServiceMain* mServiceMain{nullptr}; + CClientManager* mClientManager{nullptr}; }; #ifdef __cplusplus diff --git a/inc/service_ipc_dbus_dispatcher.h b/inc/service_ipc_dbus_dispatcher.h index 45d06fe..70a5f5d 100644 --- a/inc/service_ipc_dbus_dispatcher.h +++ b/inc/service_ipc_dbus_dispatcher.h @@ -17,6 +17,8 @@ #ifndef __SERVICE_IPC_DBUS_DISPATCHER_H__ #define __SERVICE_IPC_DBUS_DISPATCHER_H__ +#include + #include #ifdef __cplusplus @@ -25,6 +27,33 @@ extern "C" { class CServiceMain; +class IServiceIpcObserver { +public: + virtual int on_initialize(int pid) = 0; + virtual int on_deinitialize(int pid) = 0; + virtual int on_get_audio_format(int pid, int& rate, int& channel, int& audio_type) = 0; + virtual int on_get_audio_source_type(int pid, std::string& type) = 0; + virtual int on_send_asr_result(int pid, int event, std::string asr_result) = 0; + virtual int on_send_result(int pid, + std::string display_text, std::string utterance_text, std::string result_json) = 0; + virtual int on_send_recognition_result(int pid, int result) = 0; + virtual int on_start_streaming_audio_data(int pid, int type) = 0; + virtual int on_stop_streaming_audio_data(int pid, int type) = 0; + virtual int on_update_voice_feedback_state(int pid, int state) = 0; + virtual int on_send_assistant_specific_command(int pid, std::string command) = 0; + virtual int on_set_background_volume(int pid, double ratio) = 0; + virtual int on_set_preprocessing_allow_mode(int pid, int mode, std::string app_id) = 0; + virtual int on_send_preprocessing_result(int pid, int result) = 0; + virtual int on_set_wake_word_audio_require_flag(int pid, int require) = 0; + virtual int on_set_assistant_language(int pid, std::string language) = 0; + virtual int on_add_wake_word(int pid, std::string wake_word, std::string language) = 0; + virtual int on_remove_wake_word(int pid, std::string wake_word, std::string language) = 0; + + virtual int on_ui_initialize(int pid) = 0; + virtual int on_ui_deinitialize(int pid) = 0; + virtual int on_ui_change_assistant(std::string app_id) = 0; +}; + class CServiceIpcDbusDispatcher { public: CServiceIpcDbusDispatcher() {} @@ -53,9 +82,9 @@ public: 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; } + void set_ipc_observer(IServiceIpcObserver* observer) { mIpcObserver = observer; } private: - CServiceMain* mServiceMain{nullptr}; + IServiceIpcObserver *mIpcObserver{nullptr}; }; #ifdef __cplusplus diff --git a/inc/service_main.h b/inc/service_main.h index 61e4853..5101be5 100644 --- a/inc/service_main.h +++ b/inc/service_main.h @@ -27,8 +27,10 @@ #include "service_common.h" #include "service_config.h" +#include "client_manager.h" #include "service_plugin.h" #include "service_ipc_dbus.h" +#include "application_manager_aul.h" #ifdef __cplusplus extern "C" { @@ -66,27 +68,19 @@ typedef enum { #define MAX_MACLIENT_INFO_NUM 16 -typedef struct { - int pid; - char appid[MAX_APPID_LEN]; -} ma_client_s; - -class CServiceMain { +class CServiceMain : public IServiceIpcObserver { 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_asr_result(int pid, int event, const char* asr_result); + int mas_client_send_result(int pid, const char* display_text, + const char* utterance_text, const 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); @@ -106,7 +100,7 @@ public: 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); + std::string 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); @@ -120,6 +114,30 @@ public: int mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event); int mas_update_voice_key_support_mode(); + virtual int on_initialize(int pid) override; + virtual int on_deinitialize(int pid) override; + virtual int on_get_audio_format(int pid, int& rate, int& channel, int& audio_type) override; + virtual int on_get_audio_source_type(int pid, std::string& type) override; + virtual int on_send_asr_result(int pid, int event, std::string asr_result) override; + virtual int on_send_result(int pid, std::string display_text, + std::string utterance_text, std::string result_json) override; + virtual int on_send_recognition_result(int pid, int result) override; + virtual int on_start_streaming_audio_data(int pid, int type) override; + virtual int on_stop_streaming_audio_data(int pid, int type) override; + virtual int on_update_voice_feedback_state(int pid, int state) override; + virtual int on_send_assistant_specific_command(int pid, std::string command) override; + virtual int on_set_background_volume(int pid, double ratio) override; + virtual int on_set_preprocessing_allow_mode(int pid, int mode, std::string app_id) override; + virtual int on_send_preprocessing_result(int pid, int result) override; + virtual int on_set_wake_word_audio_require_flag(int pid, int require) override; + virtual int on_set_assistant_language(int pid, std::string language) override; + virtual int on_add_wake_word(int pid, std::string wake_word, std::string language) override; + virtual int on_remove_wake_word(int pid, std::string wake_word, std::string language) override; + + virtual int on_ui_initialize(int pid) override; + virtual int on_ui_deinitialize(int pid) override; + virtual int on_ui_change_assistant(std::string app_id) override; + bool app_create(void *data); void app_terminate(void *data); @@ -133,11 +151,6 @@ public: 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); @@ -170,14 +183,16 @@ private: 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}; + + CClientManager mClientManager; + + CApplicationManagerAul mApplicationManager; + }; #ifdef __cplusplus diff --git a/src/application_manager_aul.cpp b/src/application_manager_aul.cpp new file mode 100644 index 0000000..2553c93 --- /dev/null +++ b/src/application_manager_aul.cpp @@ -0,0 +1,30 @@ +/* + * 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 "application_manager_aul.h" +#include "service_common.h" + +#include + +bool CApplicationManagerAul::is_application_running(int pid) +{ + int status = aul_app_get_status_bypid(pid); + if (0 > status) { + MAS_LOGE("The process %d does not exist : %d", pid, status); + return false; + } + return true; +} \ No newline at end of file diff --git a/src/client_manager.cpp b/src/client_manager.cpp new file mode 100644 index 0000000..8175bb0 --- /dev/null +++ b/src/client_manager.cpp @@ -0,0 +1,188 @@ +/* + * 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 "client_manager.h" +#include "service_common.h" + +int CClientManager::set_application_manager(IApplicationManager* manager) +{ + mApplicationManager = manager; + return 0; +} + +int CClientManager::create_client(int pid, std::string appid) +{ + ma_client_s* data = NULL; + + try { + data = new ma_client_s; + } catch(const std::bad_alloc& e) { + MAS_LOGE("[ERROR] Fail to allocate memory : %s", e.what()); + return -1;// MA_ERROR_OUT_OF_MEMORY; + } + + if (data) { + data->pid = pid; + data->appid = appid; + g_client_list = g_slist_append(g_client_list, data); + } else { + MAS_LOGE("[ERROR] data is NULL"); + return -1;// MA_ERROR_OUT_OF_MEMORY; + } + + return 0; +} + +int CClientManager::destroy_client(ma_client_s* client) +{ + if (nullptr == client) { + MAS_LOGE("Input parameter is NULL"); + return -1;// MA_ERROR_OPERATION_FAILED; + } + + g_client_list = g_slist_remove(g_client_list, client); + + delete client; + + return 0; +} + +int CClientManager::destroy_client_by_pid(int pid) +{ + ma_client_s* client = find_client_by_pid(pid); + return destroy_client(client); +} + +int CClientManager::destroy_client_by_appid(std::string appid) +{ + ma_client_s* client = find_client_by_appid(appid); + return destroy_client(client); +} + +ma_client_s* CClientManager::find_client_by_appid(std::string appid) +{ + ma_client_s *data = NULL; + + int count = g_slist_length(g_client_list); + int i; + + for (i = 0; i < count; i++) { + data = static_cast(g_slist_nth_data(g_client_list, i)); + + if (NULL != data) { + if (0 == appid.compare(data->appid)) { + return data; + } + } + } + + MAS_LOGE("[ERROR] client Not found"); + + return NULL; +} + +ma_client_s* CClientManager::find_client_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(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; +} + +int CClientManager::get_client_num() +{ + return g_slist_length(g_client_list); +} + +ma_client_s* CClientManager::get_client_by_index(unsigned int index) +{ + return static_cast(g_slist_nth_data(g_client_list, index)); +} + +int CClientManager::find_client_pid_by_index(unsigned int index) +{ + int pid = -1; + ma_client_s* client = get_client_by_index(index); + if (client) { + pid = client->pid; + } + return pid; +} + +int CClientManager::find_client_pid_by_appid(std::string appid) +{ + int pid = -1; + + if (nullptr == mApplicationManager) { + MAS_LOGE("ApplicationManager is NULL, can't check if app is running or not"); + return pid; + } + + ma_client_s* client = find_client_by_appid(appid); + if (client) { + bool running = mApplicationManager->is_application_running(pid); + if (false == running) { + MAS_LOGE("The PID for %s was %d, but it seems to be terminated", + appid.c_str(), client->pid); + } else { + pid = client->pid; + } + } + return pid; +} + +std::string CClientManager::find_client_appid_by_pid(int pid) +{ + std::string appid; + + if (nullptr == mApplicationManager) { + MAS_LOGE("ApplicationManager is NULL, can't check if app is running or not"); + return appid; + } + + ma_client_s* client = find_client_by_pid(pid); + if (client) { + bool running = mApplicationManager->is_application_running(pid); + if (false == running) { + MAS_LOGE("The appid for %d was %s, but it seems to be terminated", + pid, client->appid.c_str()); + } else { + appid = client->appid; + } + } + return appid; +} + +bool CClientManager::check_client_validity_by_appid(std::string appid) +{ + int pid = find_client_pid_by_appid(appid); + if (0 < pid) return true; + return false; +} diff --git a/src/service_ipc_dbus.cpp b/src/service_ipc_dbus.cpp index 1a7558b..6888d0b 100644 --- a/src/service_ipc_dbus.cpp +++ b/src/service_ipc_dbus.cpp @@ -208,8 +208,8 @@ static void masc_message_port_error(int error) 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"); + if (nullptr == mClientManager) { + MAS_LOGE("mClientManager variable is NULL"); return -1; } @@ -245,7 +245,7 @@ int CServiceIpcDbus::send_streaming_audio_data(int pid, int event, void* data, u 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); + mClientManager->find_client_appid_by_pid(pid).c_str(), message_port, b); if (MESSAGE_PORT_ERROR_NONE != ret) masc_message_port_error(ret); @@ -266,7 +266,7 @@ int CServiceIpcDbus::send_streaming_audio_data(int pid, int event, void* data, u 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); + mClientManager->find_client_appid_by_pid(pid).c_str(), message_port, b); if (MESSAGE_PORT_ERROR_NONE != ret) masc_message_port_error(ret); @@ -397,8 +397,8 @@ int CServiceIpcDbus::send_preprocessing_information(int pid, const char* app_id) int CServiceIpcDbus::send_streaming_section_changed(int pid, int section) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mClientManager) { + MAS_LOGE("mClientManager variable is NULL"); return -1; } @@ -420,7 +420,8 @@ int CServiceIpcDbus::send_streaming_section_changed(int pid, int section) 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); + int ret = message_port_send_message( + mClientManager->find_client_appid_by_pid(pid).c_str(), message_port, b); if (MESSAGE_PORT_ERROR_NONE != ret) masc_message_port_error(ret); @@ -690,7 +691,7 @@ int CServiceIpcDbus::masc_ui_dbus_send_hello(void) return result; } -int CServiceIpcDbus::masc_ui_dbus_send_asr_result(int pid, int event, char* asr_result) +int CServiceIpcDbus::masc_ui_dbus_send_asr_result(int pid, int event, const char* asr_result) { if (0 != __dbus_check()) { return -1; //MAS_ERROR_OPERATION_FAILED; diff --git a/src/service_ipc_dbus_dispatcher.cpp b/src/service_ipc_dbus_dispatcher.cpp index 76d40b0..df43612 100644 --- a/src/service_ipc_dbus_dispatcher.cpp +++ b/src/service_ipc_dbus_dispatcher.cpp @@ -46,8 +46,8 @@ int CServiceIpcDbusDispatcher::on_hello(DBusConnection* conn, DBusMessage* msg) int CServiceIpcDbusDispatcher::on_initialize(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -69,7 +69,7 @@ int CServiceIpcDbusDispatcher::on_initialize(DBusConnection* conn, DBusMessage* ret = -1; //MAS_ERROR_OPERATION_FAILED; } else { MAS_LOGD("[IN] mas initialize : pid(%d)", pid); - ret = mServiceMain->mas_client_initialize(pid); + ret = mIpcObserver->on_initialize(pid); } DBusMessage* reply; @@ -102,8 +102,8 @@ int CServiceIpcDbusDispatcher::on_initialize(DBusConnection* conn, DBusMessage* int CServiceIpcDbusDispatcher::on_deinitialize(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -125,7 +125,7 @@ int CServiceIpcDbusDispatcher::on_deinitialize(DBusConnection* conn, DBusMessage ret = -1; //MAS_ERROR_OPERATION_FAILED; } else { MAS_LOGD("[IN] mas deinitialize : pid(%d)", pid); - ret = mServiceMain->mas_client_deinitialize(pid); + ret = mIpcObserver->on_deinitialize(pid); } DBusMessage* reply; @@ -158,8 +158,8 @@ int CServiceIpcDbusDispatcher::on_deinitialize(DBusConnection* conn, DBusMessage int CServiceIpcDbusDispatcher::on_get_audio_format(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -182,7 +182,7 @@ int CServiceIpcDbusDispatcher::on_get_audio_format(DBusConnection* conn, DBusMes 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); + ret = mIpcObserver->on_get_audio_format(pid, rate, channel, audio_type); } DBusMessage* reply; @@ -217,8 +217,8 @@ int CServiceIpcDbusDispatcher::on_get_audio_format(DBusConnection* conn, DBusMes int CServiceIpcDbusDispatcher::on_get_audio_source_type(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -226,7 +226,7 @@ int CServiceIpcDbusDispatcher::on_get_audio_source_type(DBusConnection* conn, DB dbus_error_init(&err); int pid = -1; - char *type = NULL; + std::string type; int ret; dbus_message_get_args(msg, &err, @@ -241,7 +241,7 @@ int CServiceIpcDbusDispatcher::on_get_audio_source_type(DBusConnection* conn, DB 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); + ret = mIpcObserver->on_get_audio_source_type(pid, type); } DBusMessage* reply; @@ -249,10 +249,10 @@ int CServiceIpcDbusDispatcher::on_get_audio_source_type(DBusConnection* conn, DB char* temp_type = NULL; - if (type) - temp_type = strdup(type); - else + if (-1 == ret) temp_type = strdup("#NULL"); + else + temp_type = strdup(type.c_str()); if (NULL != reply) { /* Append result and voice */ @@ -284,8 +284,8 @@ int CServiceIpcDbusDispatcher::on_get_audio_source_type(DBusConnection* conn, DB int CServiceIpcDbusDispatcher::on_send_asr_result(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -310,7 +310,8 @@ int CServiceIpcDbusDispatcher::on_send_asr_result(DBusConnection* conn, DBusMess 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); + ret = mIpcObserver->on_send_asr_result(pid, event, + asr_result ? std::string{asr_result} : std::string{}); } DBusMessage* reply; @@ -345,8 +346,8 @@ int CServiceIpcDbusDispatcher::on_send_asr_result(DBusConnection* conn, DBusMess int CServiceIpcDbusDispatcher::on_send_result(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -374,7 +375,10 @@ int CServiceIpcDbusDispatcher::on_send_result(DBusConnection* conn, DBusMessage* 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); + ret = mIpcObserver->on_send_result(pid, + display_text ? std::string{display_text} : std::string{}, + utterance_text ? std::string{utterance_text} : std::string{}, + result_json ? std::string{result_json} : std::string{}); } DBusMessage* reply; @@ -409,8 +413,8 @@ int CServiceIpcDbusDispatcher::on_send_result(DBusConnection* conn, DBusMessage* int CServiceIpcDbusDispatcher::on_send_recognition_result(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -434,7 +438,7 @@ int CServiceIpcDbusDispatcher::on_send_recognition_result(DBusConnection* conn, 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); + ret = mIpcObserver->on_send_recognition_result(pid, result); } MAS_LOGD("<<<<<"); @@ -445,8 +449,8 @@ int CServiceIpcDbusDispatcher::on_send_recognition_result(DBusConnection* conn, int CServiceIpcDbusDispatcher::on_start_streaming_audio_data(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -470,7 +474,7 @@ int CServiceIpcDbusDispatcher::on_start_streaming_audio_data(DBusConnection* con 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); + ret = mIpcObserver->on_start_streaming_audio_data(pid, type); } MAS_LOGD("<<<<<"); @@ -481,8 +485,8 @@ int CServiceIpcDbusDispatcher::on_start_streaming_audio_data(DBusConnection* con int CServiceIpcDbusDispatcher::on_stop_streaming_audio_data(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -506,7 +510,7 @@ int CServiceIpcDbusDispatcher::on_stop_streaming_audio_data(DBusConnection* conn 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); + ret = mIpcObserver->on_stop_streaming_audio_data(pid, type); } MAS_LOGD("<<<<<"); @@ -517,8 +521,8 @@ int CServiceIpcDbusDispatcher::on_stop_streaming_audio_data(DBusConnection* conn int CServiceIpcDbusDispatcher::on_update_voice_feedback_state(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -542,7 +546,7 @@ int CServiceIpcDbusDispatcher::on_update_voice_feedback_state(DBusConnection* co 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); + ret = mIpcObserver->on_update_voice_feedback_state(pid, state); } MAS_LOGD("<<<<<"); @@ -553,8 +557,8 @@ int CServiceIpcDbusDispatcher::on_update_voice_feedback_state(DBusConnection* co int CServiceIpcDbusDispatcher::on_send_assistant_specific_command(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -578,7 +582,8 @@ int CServiceIpcDbusDispatcher::on_send_assistant_specific_command(DBusConnection 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); + ret = mIpcObserver->on_send_assistant_specific_command(pid, + command ? std::string{command} : std::string{}); } MAS_LOGD("<<<<<"); @@ -589,8 +594,8 @@ int CServiceIpcDbusDispatcher::on_send_assistant_specific_command(DBusConnection int CServiceIpcDbusDispatcher::on_set_background_volume(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -614,7 +619,7 @@ int CServiceIpcDbusDispatcher::on_set_background_volume(DBusConnection* conn, DB 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); + ret = mIpcObserver->on_set_background_volume(pid, ratio); } MAS_LOGD("<<<<<"); @@ -625,8 +630,8 @@ int CServiceIpcDbusDispatcher::on_set_background_volume(DBusConnection* conn, DB int CServiceIpcDbusDispatcher::on_set_preprocessing_allow_mode(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -651,15 +656,10 @@ int CServiceIpcDbusDispatcher::on_set_preprocessing_allow_mode(DBusConnection* c 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(mode), temp_app_id); - if (NULL != temp_app_id) - free(temp_app_id); + MAS_LOGI("[IN] mas set preprocessing allow mode : pid(%d), mode(%d), app_id(%s)", pid, mode, app_id); + ret = mIpcObserver->on_set_preprocessing_allow_mode(pid, + static_cast(mode), + app_id ? std::string{app_id} : std::string{}); } MAS_LOGD("<<<<<"); @@ -670,8 +670,8 @@ int CServiceIpcDbusDispatcher::on_set_preprocessing_allow_mode(DBusConnection* c int CServiceIpcDbusDispatcher::on_send_preprocessing_result(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -695,7 +695,7 @@ int CServiceIpcDbusDispatcher::on_send_preprocessing_result(DBusConnection* conn 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); + ret = mIpcObserver->on_send_preprocessing_result(pid, result); } MAS_LOGD("<<<<<"); @@ -706,8 +706,8 @@ int CServiceIpcDbusDispatcher::on_send_preprocessing_result(DBusConnection* conn int CServiceIpcDbusDispatcher::on_set_wake_word_audio_require_flag(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -731,7 +731,7 @@ int CServiceIpcDbusDispatcher::on_set_wake_word_audio_require_flag(DBusConnectio 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); + ret = mIpcObserver->on_set_wake_word_audio_require_flag(pid, require); } MAS_LOGD("<<<<<"); @@ -742,8 +742,8 @@ int CServiceIpcDbusDispatcher::on_set_wake_word_audio_require_flag(DBusConnectio int CServiceIpcDbusDispatcher::on_set_assistant_language(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -767,7 +767,8 @@ int CServiceIpcDbusDispatcher::on_set_assistant_language(DBusConnection* conn, D 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); + ret = mIpcObserver->on_set_assistant_language(pid, + language ? std::string{language} : std::string{}); } MAS_LOGD("<<<<<"); @@ -778,8 +779,8 @@ int CServiceIpcDbusDispatcher::on_set_assistant_language(DBusConnection* conn, D int CServiceIpcDbusDispatcher::on_add_wake_word(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -805,7 +806,9 @@ int CServiceIpcDbusDispatcher::on_add_wake_word(DBusConnection* conn, DBusMessag 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); + ret = mIpcObserver->on_add_wake_word(pid, + wake_word ? std::string{wake_word} : std::string{}, + language ? std::string{language} : std::string{}); } MAS_LOGD("<<<<<"); @@ -816,8 +819,8 @@ int CServiceIpcDbusDispatcher::on_add_wake_word(DBusConnection* conn, DBusMessag int CServiceIpcDbusDispatcher::on_remove_wake_word(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); } DBusError err; @@ -842,7 +845,9 @@ int CServiceIpcDbusDispatcher::on_remove_wake_word(DBusConnection* conn, DBusMes 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); + ret = mIpcObserver->on_remove_wake_word(pid, + wake_word ? std::string{wake_word} : std::string{}, + language ? std::string{language} : std::string{}); } MAS_LOGD("<<<<<"); @@ -853,8 +858,8 @@ int CServiceIpcDbusDispatcher::on_remove_wake_word(DBusConnection* conn, DBusMes int CServiceIpcDbusDispatcher::on_ui_initialize(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -876,7 +881,7 @@ int CServiceIpcDbusDispatcher::on_ui_initialize(DBusConnection* conn, DBusMessag ret = -1; //MAS_ERROR_OPERATION_FAILED; } else { MAS_LOGD("[IN] mas ui initialize : pid(%d)", pid); - ret = mServiceMain->mas_ui_client_initialize(pid); + ret = mIpcObserver->on_ui_initialize(pid); } DBusMessage* reply; @@ -909,8 +914,8 @@ int CServiceIpcDbusDispatcher::on_ui_initialize(DBusConnection* conn, DBusMessag int CServiceIpcDbusDispatcher::on_ui_deinitialize(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -932,7 +937,7 @@ int CServiceIpcDbusDispatcher::on_ui_deinitialize(DBusConnection* conn, DBusMess ret = -1; //MAS_ERROR_OPERATION_FAILED; } else { MAS_LOGD("[IN] mas ui deinitialize : pid(%d)", pid); - ret = mServiceMain->mas_ui_client_deinitialize(pid); + ret = mIpcObserver->on_ui_deinitialize(pid); } DBusMessage* reply; @@ -965,8 +970,8 @@ int CServiceIpcDbusDispatcher::on_ui_deinitialize(DBusConnection* conn, DBusMess int CServiceIpcDbusDispatcher::on_ui_change_assistant(DBusConnection* conn, DBusMessage* msg) { - if (nullptr == mServiceMain) { - MAS_LOGE("mServiceMain variable is NULL"); + if (nullptr == mIpcObserver) { + MAS_LOGE("mIpcObserver variable is NULL"); return -1; } @@ -988,7 +993,8 @@ int CServiceIpcDbusDispatcher::on_ui_change_assistant(DBusConnection* conn, DBus 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); + ret = mIpcObserver->on_ui_change_assistant( + app_id ? std::string{app_id} : std::string{}); } DBusMessage* reply; diff --git a/src/service_main.cpp b/src/service_main.cpp index 54c2368..6af73f6 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -38,91 +38,6 @@ 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(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(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; @@ -130,12 +45,10 @@ bool CServiceMain::check_preprocessing_assistant_exists() 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; - } + if (g_maclient_info[loop].used && + strncmp(vconf_str, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) { + if (mClientManager.check_client_validity_by_appid(std::string{vconf_str})) { + ret = true; } } } @@ -166,80 +79,6 @@ bool CServiceMain::is_current_preprocessing_assistant(const char* appid) 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); @@ -302,27 +141,7 @@ int CServiceMain::mas_client_send_voice_key_status_change(int pid, ma_voice_key_ 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) +int CServiceMain::mas_client_send_asr_result(int pid, int event, const 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); @@ -335,7 +154,8 @@ int CServiceMain::mas_client_send_asr_result(int pid, int event, char* asr_resul return ret; } -int CServiceMain::mas_client_send_result(int pid, char* display_text, char* utterance_text, char* result_json) +int CServiceMain::mas_client_send_result(int pid, const char* display_text, + const char* utterance_text, const 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); @@ -497,9 +317,10 @@ int CServiceMain::mas_client_send_preprocessing_result(int pid, bool result) 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); + if (current_maclient_appid) { + int pid = mClientManager.find_client_pid_by_appid( + std::string{current_maclient_appid}); + mServiceIpc.send_preprocessing_result(pid, result); } return 0; @@ -626,7 +447,7 @@ int CServiceMain::mas_ui_client_change_assistant(const char* appid) mas_client_send_voice_key_status_change(pid, mLastVoiceKeyStatus); } - mas_client_activate(pid); + mServiceIpc.active_state_change(pid, MA_ACTIVE_STATE_ACTIVE); MAS_LOGD("MA Client with appid %s exists, requesting speech data", (appid ? appid : "NULL")); /* int ret = mServicePlugin.start_streaming_utterance_data(); @@ -870,9 +691,8 @@ 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; + if (appid) { + ret = mClientManager.find_client_pid_by_appid(std::string{appid}); } } return ret; @@ -883,9 +703,8 @@ 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; + if (appid) { + ret = mClientManager.find_client_pid_by_appid(std::string{appid}); } } return ret; @@ -896,45 +715,20 @@ 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; - } + ret = mClientManager.find_client_pid_by_appid(std::string{appid}); } 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); + on_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; @@ -1047,7 +841,8 @@ int CServiceMain::mas_set_current_client_by_wakeup_word(const char *wakeup_word) 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)); + int pid = mas_get_client_pid_by_appid(g_maclient_info[prev_selection].appid); + mServiceIpc.active_state_change(pid, MA_ACTIVE_STATE_INACTIVE); } } @@ -1072,7 +867,8 @@ int CServiceMain::mas_set_current_client_by_appid(const char *appid) 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)); + int pid = mas_get_client_pid_by_appid(g_maclient_info[prev_selection].appid); + mServiceIpc.active_state_change(pid, MA_ACTIVE_STATE_INACTIVE); } } @@ -1343,17 +1139,16 @@ int CServiceMain::mas_set_current_service_state(ma_service_state_e state) ma_client_s *data = NULL; - int count = g_slist_length(g_client_list); + int count = mClientManager.get_client_num(); int i; for (i = 0; i < count; i++) { - data = static_cast(g_slist_nth_data(g_client_list, i)); + int pid = mClientManager.find_client_pid_by_index(i); - if (NULL != data && -1 != data->pid) { - int ret = mServiceIpc.service_state_change(data->pid, state); + if (-1 != pid) { + int ret = mServiceIpc.service_state_change(pid, state); if (0 != ret) { - MAS_LOGE("[ERROR] Fail to send wakeup service state change to %d, ret(%d)", - data->pid, ret); + MAS_LOGE("[ERROR] Fail to set service state change to %d, ret(%d)", pid, ret); } } } @@ -1513,7 +1308,10 @@ bool CServiceMain::app_create(void *data) g_service_main = this; - mServiceIpc.set_service_main(this); + mClientManager.set_application_manager(&mApplicationManager); + + mServiceIpc.set_client_manager(&mClientManager); + mServiceIpc.set_service_ipc_observer(this); mServicePlugin.set_service_ipc(&mServiceIpc); mServicePlugin.set_service_main(this); @@ -1581,3 +1379,150 @@ void CServiceMain::app_terminate(void *data) return; } +int CServiceMain::on_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 */ + mClientManager.destroy_client_by_appid(appid); + + /* And remove a client that has same pid also */ + mClientManager.destroy_client_by_pid(pid); + + mClientManager.create_client(pid, appid); + + 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(); + mServiceIpc.active_state_change(pid, MA_ACTIVE_STATE_ACTIVE); + 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::on_deinitialize(int pid) { + MAS_LOGD("[Enter] pid(%d)", pid); + mClientManager.destroy_client_by_pid(pid); + return 0; +} + +int CServiceMain::on_get_audio_format(int pid, int& rate, int& channel, int& audio_type) { + int main_rate, main_channel, main_audio_type; + int ret = mas_client_get_audio_format(pid, + &main_rate, &main_channel, &main_audio_type); + rate = main_rate; + channel = main_channel; + audio_type = main_audio_type; + return ret; +} + +int CServiceMain::on_get_audio_source_type(int pid, std::string& type) { + char *main_type = nullptr; + int ret = mas_client_get_audio_source_type(pid, &main_type); + if (0 == ret && main_type) { + type = std::string{main_type}; + } + return ret; +} + +int CServiceMain::on_send_asr_result(int pid, int event, std::string asr_result) { + return mas_client_send_asr_result(pid, event, asr_result.c_str()); +} + +int CServiceMain::on_send_result(int pid, std::string display_text, + std::string utterance_text, std::string result_json) { + return mas_client_send_result(pid, + display_text.c_str(), utterance_text.c_str(), result_json.c_str()); +} + +int CServiceMain::on_send_recognition_result(int pid, int result) { + return mas_client_send_recognition_result(pid, result); +} + +int CServiceMain::on_start_streaming_audio_data(int pid, int type) { + return mas_client_start_streaming_audio_data(pid, type); +} + +int CServiceMain::on_stop_streaming_audio_data(int pid, int type) { + return mas_client_stop_streaming_audio_data(pid, type); +} + +int CServiceMain::on_update_voice_feedback_state(int pid, int state) { + return mas_client_update_voice_feedback_state(pid, state); +} + +int CServiceMain::on_send_assistant_specific_command(int pid, std::string command) { + return mas_client_set_assistant_specific_command(pid, command.c_str()); +} + +int CServiceMain::on_set_background_volume(int pid, double ratio) { + return mas_client_set_background_volume(pid, ratio); +} + +int CServiceMain::on_set_preprocessing_allow_mode(int pid, int mode, std::string app_id) { + return mas_client_set_preprocessing_allow_mode(pid, + static_cast(mode), app_id.c_str()); +} + +int CServiceMain::on_send_preprocessing_result(int pid, int result) { + return mas_client_send_preprocessing_result(pid, result); +} + +int CServiceMain::on_set_wake_word_audio_require_flag(int pid, int require) { + return mas_client_set_wake_word_audio_require_flag(pid, require); +} + +int CServiceMain::on_set_assistant_language(int pid, std::string language) { + return mas_client_set_assistant_language(pid, language.c_str()); +} + +int CServiceMain::on_add_wake_word(int pid, std::string wake_word, std::string language) { + return mas_client_add_wake_word(pid, wake_word.c_str(), language.c_str()); +} + +int CServiceMain::on_remove_wake_word(int pid, std::string wake_word, std::string language) { + return mas_client_remove_wake_word(pid, wake_word.c_str(), language.c_str()); +} + +int CServiceMain::on_ui_initialize(int pid) +{ + return mas_ui_client_initialize(pid); +} + +int CServiceMain::on_ui_deinitialize(int pid) +{ + return mas_ui_client_deinitialize(pid); +} + +int CServiceMain::on_ui_change_assistant(std::string app_id) +{ + return mas_ui_client_change_assistant(app_id.c_str()); +} diff --git a/src/service_plugin.cpp b/src/service_plugin.cpp index 7f1b4ef..b552823 100644 --- a/src/service_plugin.cpp +++ b/src/service_plugin.cpp @@ -114,7 +114,7 @@ static Eina_Bool process_wakeup_event_by_appid_timer(void* data) 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_ipc->active_state_change(pid, MA_ACTIVE_STATE_ACTIVE); service_main->mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED); } else { // Appropriate MA Client not available, trying to launch new one diff --git a/tests/utc/CMakeLists.txt b/tests/utc/CMakeLists.txt index 145e97a..e968034 100644 --- a/tests/utc/CMakeLists.txt +++ b/tests/utc/CMakeLists.txt @@ -1,3 +1,4 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) ADD_SUBDIRECTORY(config) +ADD_SUBDIRECTORY(client-manager) diff --git a/tests/utc/client-manager/CMakeLists.txt b/tests/utc/client-manager/CMakeLists.txt new file mode 100644 index 0000000..ed114d9 --- /dev/null +++ b/tests/utc/client-manager/CMakeLists.txt @@ -0,0 +1,47 @@ +LINK_DIRECTORIES(${CMAKE_BINARY_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wno-unused-function -Wno-sign-compare") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs" ) +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIE") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -std=c++11") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") + +ADD_DEFINITIONS("-DFULLVER=\"${FULLVER}\"") + +SET(TEST_SOURCES + test_client_manager.cpp + ${CMAKE_SOURCE_DIR}/src/client_manager.cpp +) + +# Find Packages +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED + capi-appfw-application + capi-appfw-preference + multi-assistant + dlog + libxml-2.0 +) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +FIND_PACKAGE(GTest REQUIRED) +INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS}) +LINK_DIRECTORIES(${GTEST_LIBRARY_DIRS}) + +SET(TEST_CLIENT_MANAGER test-client-manager) +ADD_EXECUTABLE(${TEST_CLIENT_MANAGER} + ${TEST_SOURCES} + ) + +TARGET_LINK_LIBRARIES(${TEST_CLIENT_MANAGER} -ldl ${GTEST_LIBRARIES} pthread + ${EXTRA_LDFLAGS} ${pkgs_LDFLAGS}) + +INSTALL(TARGETS ${TEST_CLIENT_MANAGER} DESTINATION bin) + +ADD_TEST(NAME ${TEST_CLIENT_MANAGER} COMMAND ${TEST_CLIENT_MANAGER}) diff --git a/tests/utc/client-manager/test_client_manager.cpp b/tests/utc/client-manager/test_client_manager.cpp new file mode 100644 index 0000000..e77ded9 --- /dev/null +++ b/tests/utc/client-manager/test_client_manager.cpp @@ -0,0 +1,195 @@ +/* + * Copyright 2018 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 + +#include "client_manager.h" + +#include + +class CDummyApplicationManager : public IApplicationManager +{ +public: + CDummyApplicationManager() {}; + virtual ~CDummyApplicationManager() {}; + + bool is_application_running(int pid) { return true; } +}; + +class StorageWithNoClient : public testing::Test +{ +public: + StorageWithNoClient() { + } + virtual ~StorageWithNoClient() { + } + void SetUp() override { + client_manager.set_application_manager(&application_manager); + } + void TearDown() override { + } + CClientManager client_manager; + CDummyApplicationManager application_manager; +}; + +TEST_F(StorageWithNoClient, HasOneClientAfterCreate) { + const std::string arbitrary_client_appid{"Client1"}; + const int arbitrary_client_pid{1}; + + client_manager.create_client(arbitrary_client_pid, arbitrary_client_appid); + + int client_num = client_manager.get_client_num(); + + ASSERT_EQ(client_num, 1); +} + +TEST_F(StorageWithNoClient, ValidityReturnsTrueForCreatedClient) { + const std::string arbitrary_client_appid{"Client1"}; + const int arbitrary_client_pid{1}; + + client_manager.create_client(arbitrary_client_pid, arbitrary_client_appid); + + bool validity = client_manager.check_client_validity_by_appid(arbitrary_client_appid); + + ASSERT_TRUE(validity); +} + +TEST_F(StorageWithNoClient, ValidityReturnsFalseForNotCreatedClient) { + const std::string arbitrary_client_appid{"Client1"}; + const int arbitrary_client_pid{1}; + + const std::string noexist_client_appid{"Client987654321"}; + + client_manager.create_client(arbitrary_client_pid, arbitrary_client_appid); + + bool validity = client_manager.check_client_validity_by_appid(noexist_client_appid); + + ASSERT_FALSE(validity); +} + +class StorageWithOneClient : public testing::Test { +public: + StorageWithOneClient() { + } + virtual ~StorageWithOneClient() { + } + void SetUp() override { + client_manager.set_application_manager(&application_manager); + client_manager.create_client(preloaded_client_pid_1, preloaded_client_appid_1); + } + void TearDown() override { + } + const std::string preloaded_client_appid_1{"Client1"}; + const int preloaded_client_pid_1{1}; + CClientManager client_manager; + CDummyApplicationManager application_manager; +}; + +TEST_F(StorageWithOneClient, ReturnsExistingPIDByIndex) { + const std::string arbitrary_client_appid{"Client2"}; + const int arbitrary_client_pid{2}; + + client_manager.create_client(arbitrary_client_pid, arbitrary_client_appid); + + int pid = client_manager.find_client_pid_by_index(0); + + ASSERT_EQ(pid, preloaded_client_pid_1); +} + +TEST_F(StorageWithOneClient, ReturnsCreatedPIDByIndex) { + const std::string arbitrary_client_appid{"Client2"}; + const int arbitrary_client_pid{2}; + + client_manager.create_client(arbitrary_client_pid, arbitrary_client_appid); + + int pid = client_manager.find_client_pid_by_index(1); + + ASSERT_EQ(pid, arbitrary_client_pid); +} + +TEST_F(StorageWithOneClient, PreservesExistingItemNotRequestedForRemoval) { + const std::string arbitrary_client_appid{"Client2"}; + const int arbitrary_client_pid{2}; + + client_manager.create_client(arbitrary_client_pid, arbitrary_client_appid); + client_manager.destroy_client_by_pid(arbitrary_client_pid); + + int pid = client_manager.find_client_pid_by_index(0); + + ASSERT_EQ(pid, preloaded_client_pid_1); +} + +TEST_F(StorageWithOneClient, PreservesCreatedItemNotRequestedForRemoval) { + const std::string arbitrary_client_appid{"Client2"}; + const int arbitrary_client_pid{2}; + + client_manager.create_client(arbitrary_client_pid, arbitrary_client_appid); + client_manager.destroy_client_by_pid(preloaded_client_pid_1); + + int pid = client_manager.find_client_pid_by_index(0); + + ASSERT_EQ(pid, arbitrary_client_pid); +} + +TEST_F(StorageWithOneClient, ReturnsCorrectExistingPIDByAppID) { + const std::string arbitrary_client_appid{"Client2"}; + const int arbitrary_client_pid{2}; + + client_manager.create_client(arbitrary_client_pid, arbitrary_client_appid); + + int pid = client_manager.find_client_pid_by_appid(preloaded_client_appid_1); + + ASSERT_EQ(pid, preloaded_client_pid_1); +} + +TEST_F(StorageWithOneClient, ReturnsCorrectCreatedPIDByAppID) { + const std::string arbitrary_client_appid{"Client2"}; + const int arbitrary_client_pid{2}; + + client_manager.create_client(arbitrary_client_pid, arbitrary_client_appid); + + int pid = client_manager.find_client_pid_by_appid(arbitrary_client_appid); + + ASSERT_EQ(pid, arbitrary_client_pid); +} + +TEST_F(StorageWithOneClient, ReturnsCorrectExistingAppIDByPID) { + const std::string arbitrary_client_appid{"Client2"}; + const int arbitrary_client_pid{2}; + + client_manager.create_client(arbitrary_client_pid, arbitrary_client_appid); + + std::string appid = client_manager.find_client_appid_by_pid(preloaded_client_pid_1); + + ASSERT_EQ(appid, preloaded_client_appid_1); +} + +TEST_F(StorageWithOneClient, ReturnsCorrectCreatedPIDAppIDByPID) { + const std::string arbitrary_client_appid{"Client2"}; + const int arbitrary_client_pid{2}; + + client_manager.create_client(arbitrary_client_pid, arbitrary_client_appid); + + std::string appid = client_manager.find_client_appid_by_pid(arbitrary_client_pid); + + ASSERT_EQ(appid, arbitrary_client_appid); +} + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + return ret; +} -- 2.7.4 From dd0bf6b7cad981e328f48d4c574c31d67aec06f0 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Tue, 25 Feb 2020 21:56:39 +0900 Subject: [PATCH 13/16] Add sample unit test for CAudioManager Change-Id: Ide587f7a43f553b10839bd77ba76ea8125c5c51a --- CMakeLists.txt | 5 ++ inc/service_common.h | 6 ++ plugins/wakeup-manager/inc/wakeup_audio_manager.h | 8 +-- .../wakeup-manager/src/wakeup_audio_manager.cpp | 6 +- tests/utc/CMakeLists.txt | 1 + tests/utc/audio-manager/CMakeLists.txt | 54 ++++++++++++++ tests/utc/audio-manager/test_audio_manager.cpp | 83 ++++++++++++++++++++++ 7 files changed, 156 insertions(+), 7 deletions(-) create mode 100644 tests/utc/audio-manager/CMakeLists.txt create mode 100644 tests/utc/audio-manager/test_audio_manager.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index be36924..529f152 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,11 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fstack-protector-strong -D_ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") +IF(NOT "${TEST_TYPE}" STREQUAL "none") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTEST_TYPE=${TEST_TYPE}") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_TYPE=${TEST_TYPE}") +ENDIF() + # OPTION DEBUG ----------------------------------------------------------------------------------- IF("${_SDEBUG}" MATCHES "debug") MESSAGE("Building in debug mode.") diff --git a/inc/service_common.h b/inc/service_common.h index ca86cc8..ecef87d 100644 --- a/inc/service_common.h +++ b/inc/service_common.h @@ -12,6 +12,12 @@ #endif #define LOG_TAG "multi-assistant" +#ifdef TEST_TYPE +#define conditional_public public +#else +#define conditional_public private +#endif + #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); \ diff --git a/plugins/wakeup-manager/inc/wakeup_audio_manager.h b/plugins/wakeup-manager/inc/wakeup_audio_manager.h index fdae382..7f870ae 100644 --- a/plugins/wakeup-manager/inc/wakeup_audio_manager.h +++ b/plugins/wakeup-manager/inc/wakeup_audio_manager.h @@ -18,6 +18,8 @@ #ifndef _WAKEUP_AUDIO_MANAGER_H_ #define _WAKEUP_AUDIO_MANAGER_H_ +#include "service_common.h" + #include #include #include @@ -25,9 +27,6 @@ #include #include -#include -#include -#include namespace multiassistant { @@ -89,13 +88,14 @@ public: void stop_streaming_follow_up_data(); void set_background_volume(double ratio); -private: +conditional_public: void add_audio_data(mas_speech_data& data, long long time); void notify_audio_data_recording(long time, void* data, int len); void streaming_previous_audio_data_thread_func(); void streaming_audio_data_thread_func(long long start_time); +private: int mSoundFocusWatchId{0}; bool mRecordingRequired{false}; bool mIsRecording{false}; diff --git a/plugins/wakeup-manager/src/wakeup_audio_manager.cpp b/plugins/wakeup-manager/src/wakeup_audio_manager.cpp index a69e567..8646a88 100644 --- a/plugins/wakeup-manager/src/wakeup_audio_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_audio_manager.cpp @@ -6,6 +6,9 @@ #include #include +#include +#include +#include namespace multiassistant { @@ -170,9 +173,6 @@ void CAudioManager::streaming_previous_audio_data_thread_func() unique_lock lock(mMutex, defer_lock); - int ret = -1; - int cnt = 0; - /* get feedback data */ size_t audio_data_size = 0; lock.lock(); diff --git a/tests/utc/CMakeLists.txt b/tests/utc/CMakeLists.txt index e968034..887d8a3 100644 --- a/tests/utc/CMakeLists.txt +++ b/tests/utc/CMakeLists.txt @@ -2,3 +2,4 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) ADD_SUBDIRECTORY(config) ADD_SUBDIRECTORY(client-manager) +ADD_SUBDIRECTORY(audio-manager) diff --git a/tests/utc/audio-manager/CMakeLists.txt b/tests/utc/audio-manager/CMakeLists.txt new file mode 100644 index 0000000..a523148 --- /dev/null +++ b/tests/utc/audio-manager/CMakeLists.txt @@ -0,0 +1,54 @@ +LINK_DIRECTORIES(${CMAKE_BINARY_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/plugins/wakeup-manager/inc + ) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wno-unused-function -Wno-sign-compare") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs" ) +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fPIE") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Werror") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -std=c++11") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") + +ADD_DEFINITIONS("-DFULLVER=\"${FULLVER}\"") + +SET(TEST_SOURCES + test_audio_manager.cpp + ${CMAKE_SOURCE_DIR}/plugins/wakeup-manager/src/wakeup_audio_manager.cpp + ${CMAKE_SOURCE_DIR}/plugins/wakeup-manager/src/dependency_resolver.cpp + ${CMAKE_SOURCE_DIR}/plugins/wakeup-manager/src/heap_tracer.cpp +) + +# Find Packages +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED + capi-appfw-application + capi-appfw-preference + multi-assistant + dlog + libxml-2.0 + capi-media-audio-io + vconf + ecore +) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +FIND_PACKAGE(GTest REQUIRED) +INCLUDE_DIRECTORIES(${GTEST_INCLUDE_DIRS}) +LINK_DIRECTORIES(${GTEST_LIBRARY_DIRS}) + +SET(TEST_AUDIO_MANAGER test-audio-manager) +ADD_EXECUTABLE(${TEST_AUDIO_MANAGER} + ${TEST_SOURCES} + ) + +TARGET_LINK_LIBRARIES(${TEST_AUDIO_MANAGER} -ldl ${GTEST_LIBRARIES} pthread + ${EXTRA_LDFLAGS} ${pkgs_LDFLAGS}) + +INSTALL(TARGETS ${TEST_AUDIO_MANAGER} DESTINATION bin) + +ADD_TEST(NAME ${TEST_AUDIO_MANAGER} COMMAND ${TEST_AUDIO_MANAGER}) diff --git a/tests/utc/audio-manager/test_audio_manager.cpp b/tests/utc/audio-manager/test_audio_manager.cpp new file mode 100644 index 0000000..999a1d9 --- /dev/null +++ b/tests/utc/audio-manager/test_audio_manager.cpp @@ -0,0 +1,83 @@ +/* + * Copyright 2018 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 + +#include "wakeup_audio_manager.h" + +#include +#include + +class CAudioEventObserver : public multiassistant::wakeup::IAudioEventObserver +{ +public: + virtual bool on_recording_audio_data(long time, void* data, int len) override + { + return true; + } + virtual bool on_streaming_audio_data( + mas_speech_streaming_event_e event, void* buffer, unsigned int len) override + { + std::string data = std::string{reinterpret_cast(buffer), len}; + mStreamingData.push_back(data); + return true; + } + std::vector mStreamingData; +}; + +class DefaultFixture : public testing::Test +{ +public: + DefaultFixture() { + } + virtual ~DefaultFixture() { + } + void SetUp() override { + } + void TearDown() override { + } + CAudioEventObserver mAudioEventObserver; + multiassistant::wakeup::CAudioManager audio_manager{&mAudioEventObserver}; +}; + +TEST_F(DefaultFixture, StreamsAllDataFed) { + std::string arbitrary_data{"arbitrary_data"}; + size_t data_feed_num = 10; + for (int loop = 0;loop < data_feed_num;loop++) { + /* CONTINUE by default */ + mas_speech_streaming_event_e event = MAS_SPEECH_STREAMING_EVENT_CONTINUE; + if (0 == loop) event = MAS_SPEECH_STREAMING_EVENT_START; + else if (data_feed_num - 1 == loop) event = MAS_SPEECH_STREAMING_EVENT_FINISH; + audio_manager.feed_audio_data(event, + (void*)(arbitrary_data.c_str()), arbitrary_data.size()); + } + + audio_manager.streaming_audio_data_thread_func(std::numeric_limits::min()); + + int count = 0; + for (std::string data : mAudioEventObserver.mStreamingData) { + if (0 == data.compare(arbitrary_data)) { + count++; + } + } + ASSERT_EQ(count, data_feed_num); +} + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + return ret; +} -- 2.7.4 From b7a929bb3fc1f65450f0d30b98842d8f38eb4630 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Tue, 31 Mar 2020 11:28:30 +0900 Subject: [PATCH 14/16] Change the name of variables moved into classes Change-Id: I4255ecf45266065f3333f4b141c5f1b59ab4412a --- inc/client_manager.h | 2 +- inc/service_ipc_dbus.h | 10 +- inc/service_main.h | 16 +- inc/service_plugin.h | 12 +- src/client_manager.cpp | 16 +- src/service_ipc_dbus.cpp | 186 +++++++++---------- src/service_main.cpp | 322 ++++++++++++++++----------------- src/service_plugin.cpp | 453 +++++++++++++++++++++++------------------------ 8 files changed, 508 insertions(+), 509 deletions(-) diff --git a/inc/client_manager.h b/inc/client_manager.h index d2c51e2..abcb770 100644 --- a/inc/client_manager.h +++ b/inc/client_manager.h @@ -57,7 +57,7 @@ private: private: IApplicationManager* mApplicationManager{nullptr}; - GSList* g_client_list{nullptr}; + GSList* mClientList{nullptr}; }; #ifdef __cplusplus diff --git a/inc/service_ipc_dbus.h b/inc/service_ipc_dbus.h index 8bd33de..8b29954 100644 --- a/inc/service_ipc_dbus.h +++ b/inc/service_ipc_dbus.h @@ -53,7 +53,7 @@ public: 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; } + DBusConnection* get_connection_listener() { return mConnectionListener; } CServiceIpcDbusDispatcher* get_dispatcher() { return &mDispatcher; } void set_client_manager(CClientManager* manager) { @@ -71,12 +71,12 @@ private: private: CServiceIpcDbusDispatcher mDispatcher; - DBusConnection* g_conn_sender{NULL}; - DBusConnection* g_conn_listener{NULL}; + DBusConnection* mConnectionSender{NULL}; + DBusConnection* mConnectionListener{NULL}; - Ecore_Fd_Handler* g_dbus_fd_handler{NULL}; + Ecore_Fd_Handler* mFdHandler{NULL}; - int g_streaming_data_serial{0}; + int mStreamingDataSerial{0}; CClientManager* mClientManager{nullptr}; }; diff --git a/inc/service_main.h b/inc/service_main.h index 5101be5..d97e68a 100644 --- a/inc/service_main.h +++ b/inc/service_main.h @@ -156,7 +156,7 @@ private: bool is_current_preprocessing_assistant(const char* appid); private: - std::string g_current_lang{"en_US"}; + std::string mCurrentLanguage{"en_US"}; typedef struct { bool used; @@ -173,15 +173,15 @@ private: char preprocessing_allow_appid[MAX_APPID_LEN]; } ma_client_info; - ma_client_info g_maclient_info[MAX_MACLIENT_INFO_NUM]; + ma_client_info mClientInfo[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}; + int mCurrentClientInfo{0}; + int mCurrentPreprocessingClientInfo{-1}; + std::string mWakeupClientAppId; + package_manager_h mPackageManagerHandle{NULL}; - PREPROCESSING_STATE g_current_preprocessing_state{PREPROCESSING_STATE_NONE}; - ma_service_state_e g_current_service_state{MA_SERVICE_STATE_INACTIVE}; + PREPROCESSING_STATE mCurrentPreprocessingState{PREPROCESSING_STATE_NONE}; + ma_service_state_e mCurrentServiceState{MA_SERVICE_STATE_INACTIVE}; CServiceConfig mServiceConfig; CServicePlugin mServicePlugin; diff --git a/inc/service_plugin.h b/inc/service_plugin.h index b4d9da8..36ffd78 100644 --- a/inc/service_plugin.h +++ b/inc/service_plugin.h @@ -88,15 +88,15 @@ public: 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; + char mDumpFilename[128]{'\0', }; + FILE* mDumpFile{NULL}; + int mDumpCount{1}; #endif - void *g_handle = NULL; + void* mPluginHandle{NULL}; - wakeup_manager_interface _wakeup_manager_interface{NULL, }; - ma_plugin_settings* g_plugin_settings{NULL}; + wakeup_manager_interface mWakeupManagerInterface{NULL, }; + ma_plugin_settings* mPluginSettings{NULL}; CServiceIpcDbus* mServiceIpc{nullptr}; CServiceMain* mServiceMain{nullptr}; diff --git a/src/client_manager.cpp b/src/client_manager.cpp index 8175bb0..b91ab4a 100644 --- a/src/client_manager.cpp +++ b/src/client_manager.cpp @@ -37,7 +37,7 @@ int CClientManager::create_client(int pid, std::string appid) if (data) { data->pid = pid; data->appid = appid; - g_client_list = g_slist_append(g_client_list, data); + mClientList = g_slist_append(mClientList, data); } else { MAS_LOGE("[ERROR] data is NULL"); return -1;// MA_ERROR_OUT_OF_MEMORY; @@ -53,7 +53,7 @@ int CClientManager::destroy_client(ma_client_s* client) return -1;// MA_ERROR_OPERATION_FAILED; } - g_client_list = g_slist_remove(g_client_list, client); + mClientList = g_slist_remove(mClientList, client); delete client; @@ -76,11 +76,11 @@ ma_client_s* CClientManager::find_client_by_appid(std::string appid) { ma_client_s *data = NULL; - int count = g_slist_length(g_client_list); + int count = g_slist_length(mClientList); int i; for (i = 0; i < count; i++) { - data = static_cast(g_slist_nth_data(g_client_list, i)); + data = static_cast(g_slist_nth_data(mClientList, i)); if (NULL != data) { if (0 == appid.compare(data->appid)) { @@ -98,11 +98,11 @@ ma_client_s* CClientManager::find_client_by_pid(int pid) { ma_client_s *data = NULL; - int count = g_slist_length(g_client_list); + int count = g_slist_length(mClientList); int i; for (i = 0; i < count; i++) { - data = static_cast(g_slist_nth_data(g_client_list, i)); + data = static_cast(g_slist_nth_data(mClientList, i)); if (NULL != data) { if (data->pid == pid) { @@ -118,12 +118,12 @@ ma_client_s* CClientManager::find_client_by_pid(int pid) int CClientManager::get_client_num() { - return g_slist_length(g_client_list); + return g_slist_length(mClientList); } ma_client_s* CClientManager::get_client_by_index(unsigned int index) { - return static_cast(g_slist_nth_data(g_client_list, index)); + return static_cast(g_slist_nth_data(mClientList, index)); } int CClientManager::find_client_pid_by_index(unsigned int index) diff --git a/src/service_ipc_dbus.cpp b/src/service_ipc_dbus.cpp index 6888d0b..7848880 100644 --- a/src/service_ipc_dbus.cpp +++ b/src/service_ipc_dbus.cpp @@ -25,7 +25,7 @@ int CServiceIpcDbus::reconnect() { - if (!g_conn_sender || !g_conn_listener) { + if (!mConnectionSender || !mConnectionListener) { close_connection(); if (0 != open_connection()) { @@ -37,8 +37,8 @@ int CServiceIpcDbus::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); + bool sender_connected = dbus_connection_get_is_connected(mConnectionSender); + bool listener_connected = dbus_connection_get_is_connected(mConnectionListener); MAS_LOGW("[DBUS] Sender(%s) Listener(%s)", sender_connected ? "Connected" : "Not connected", listener_connected ? "Connected" : "Not connected"); @@ -58,7 +58,7 @@ int CServiceIpcDbus::reconnect() int CServiceIpcDbus::__dbus_check() { - if (NULL == g_conn_sender || NULL == g_conn_listener) { + if (NULL == mConnectionSender || NULL == mConnectionListener) { MAS_LOGE("[ERROR] NULL connection"); return reconnect(); } @@ -67,8 +67,8 @@ int CServiceIpcDbus::__dbus_check() 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); + if (NULL == mConnectionSender || NULL == mConnectionListener) { + MAS_LOGE("[ERROR] NULL connection sender(%p), listener(%p)", mConnectionSender, mConnectionListener); return -1; } return 0; @@ -97,7 +97,7 @@ int CServiceIpcDbus::send_hello(int pid) int result = -1; DBusMessage* result_msg = NULL; - result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, 500, &err); + result_msg = dbus_connection_send_with_reply_and_block(mConnectionSender, msg, 500, &err); if (dbus_error_is_set(&err)) { MAS_LOGE("[Dbus ERROR] Dbus Error (%s)", err.message); @@ -122,7 +122,7 @@ int CServiceIpcDbus::send_error_message(int reason, const char* err_msg) return -1; //MAS_ERROR_OPERATION_FAILED; } - if (NULL == g_conn_sender) { + if (NULL == mConnectionSender) { MAS_LOGE("[Dbus ERROR] Dbus connection is not available"); return -1; } @@ -154,11 +154,11 @@ int CServiceIpcDbus::send_error_message(int reason, const char* err_msg) dbus_message_set_no_reply(msg, TRUE); - if (!dbus_connection_send(g_conn_sender, msg, NULL)) { + if (!dbus_connection_send(mConnectionSender, 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_connection_flush(mConnectionSender); } dbus_message_unref(msg); @@ -219,7 +219,7 @@ int CServiceIpcDbus::send_streaming_audio_data(int pid, int event, void* data, u 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++; + header.streaming_data_serial = mStreamingDataSerial++; streaming_data_audio_data_header audio_data_header; audio_data_header.event = event; @@ -319,12 +319,12 @@ int CServiceIpcDbus::active_state_change(int pid, int state) dbus_message_set_no_reply(msg, TRUE); - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + if (1 != dbus_connection_send(mConnectionSender, 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_connection_flush(mConnectionSender); } dbus_message_unref(msg); @@ -377,14 +377,14 @@ int CServiceIpcDbus::send_preprocessing_information(int pid, const char* app_id) dbus_message_set_no_reply(msg, TRUE); - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + if (1 != dbus_connection_send(mConnectionSender, 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_connection_flush(mConnectionSender); } dbus_message_unref(msg); @@ -407,7 +407,7 @@ int CServiceIpcDbus::send_streaming_section_changed(int pid, int section) 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++; + header.streaming_data_serial = mStreamingDataSerial++; streaming_data_streaming_section_header streaming_section_header; streaming_section_header.section = section; @@ -470,12 +470,12 @@ int CServiceIpcDbus::send_preprocessing_result(int pid, bool result) dbus_message_set_no_reply(msg, TRUE); - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + if (1 != dbus_connection_send(mConnectionSender, 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_connection_flush(mConnectionSender); } dbus_message_unref(msg); @@ -529,14 +529,14 @@ int CServiceIpcDbus::send_wakeup_engine_command(int pid, const char* command) dbus_message_set_no_reply(msg, TRUE); - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + if (1 != dbus_connection_send(mConnectionSender, 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_connection_flush(mConnectionSender); } dbus_message_unref(msg); @@ -585,12 +585,12 @@ int CServiceIpcDbus::service_state_change(int pid, int state) dbus_message_set_no_reply(msg, TRUE); - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + if (1 != dbus_connection_send(mConnectionSender, 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_connection_flush(mConnectionSender); } dbus_message_unref(msg); @@ -635,12 +635,12 @@ int CServiceIpcDbus::voice_key_status_change(int pid, int status) dbus_message_set_no_reply(msg, TRUE); - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + if (1 != dbus_connection_send(mConnectionSender, 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_connection_flush(mConnectionSender); } dbus_message_unref(msg); @@ -672,7 +672,7 @@ int CServiceIpcDbus::masc_ui_dbus_send_hello(void) DBusMessage* result_msg = NULL; int result = 0; - result_msg = dbus_connection_send_with_reply_and_block(g_conn_sender, msg, 500, &err); + result_msg = dbus_connection_send_with_reply_and_block(mConnectionSender, msg, 500, &err); if (dbus_error_is_set(&err)) { MAS_LOGE("[Dbus ERROR] Dbus Error (%s)", err.message); @@ -726,7 +726,7 @@ int CServiceIpcDbus::masc_ui_dbus_send_asr_result(int pid, int event, const char dbus_message_set_no_reply(msg, TRUE); - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + if (1 != dbus_connection_send(mConnectionSender, msg, NULL)) { MAS_LOGE("[Dbus ERROR] Fail to Send"); if (NULL != temp_asr_result) { free(temp_asr_result); @@ -735,7 +735,7 @@ int CServiceIpcDbus::masc_ui_dbus_send_asr_result(int pid, int event, const char return -1; // MAS_ERROR_OPERATION_FAILED; } else { MAS_LOGD("[Dbus DEBUG] Success to Send ASR result"); - dbus_connection_flush(g_conn_sender); + dbus_connection_flush(mConnectionSender); } dbus_message_unref(msg); @@ -779,12 +779,12 @@ int CServiceIpcDbus::masc_ui_dbus_send_result(int pid, const char* display_text, dbus_message_set_no_reply(msg, TRUE); - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + if (1 != dbus_connection_send(mConnectionSender, 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_connection_flush(mConnectionSender); } dbus_message_unref(msg); @@ -811,7 +811,7 @@ int CServiceIpcDbus::masc_ui_dbus_send_result(int pid, const char* display_text, dbus_message_set_no_reply(msg, TRUE); - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + if (1 != dbus_connection_send(mConnectionSender, msg, NULL)) { MAS_LOGE("[Dbus ERROR] Fail to Send"); if (temp_display_text) free(temp_display_text); @@ -822,7 +822,7 @@ int CServiceIpcDbus::masc_ui_dbus_send_result(int pid, const char* display_text, return -1; //MA_ERROR_OPERATION_FAILED; } else { MAS_LOGD("[Dbus DEBUG] Success to Send result"); - dbus_connection_flush(g_conn_sender); + dbus_connection_flush(mConnectionSender); } dbus_message_unref(msg); @@ -864,12 +864,12 @@ int CServiceIpcDbus::masc_ui_dbus_change_assistant(const char* app_id) dbus_message_set_no_reply(msg, TRUE); - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + if (1 != dbus_connection_send(mConnectionSender, 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_connection_flush(mConnectionSender); } dbus_message_unref(msg); @@ -879,7 +879,7 @@ int CServiceIpcDbus::masc_ui_dbus_change_assistant(const char* app_id) int CServiceIpcDbus::masc_ui_dbus_send_error_message(int reason, const char* err_msg) { - if (NULL == g_conn_sender) { + if (NULL == mConnectionSender) { MAS_LOGE("[Dbus ERROR] Dbus connection is not available"); return -1; } @@ -911,11 +911,11 @@ int CServiceIpcDbus::masc_ui_dbus_send_error_message(int reason, const char* err dbus_message_set_no_reply(msg, TRUE); - if (!dbus_connection_send(g_conn_sender, msg, NULL)) { + if (!dbus_connection_send(mConnectionSender, 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_connection_flush(mConnectionSender); } dbus_message_unref(msg); @@ -953,12 +953,12 @@ int CServiceIpcDbus::masc_ui_dbus_send_recognition_result(int pid, int result) dbus_message_set_no_reply(msg, TRUE); - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + if (1 != dbus_connection_send(mConnectionSender, 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_connection_flush(mConnectionSender); } dbus_message_unref(msg); @@ -993,12 +993,12 @@ int CServiceIpcDbus::masc_ui_dbus_enable_common_ui(int enable) dbus_message_set_no_reply(msg, TRUE); - if (1 != dbus_connection_send(g_conn_sender, msg, NULL)) { + if (1 != dbus_connection_send(mConnectionSender, 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_connection_flush(mConnectionSender); } dbus_message_unref(msg); @@ -1014,9 +1014,9 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle 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"); + DBusConnection* mConnectionListener = service_ipc->get_connection_listener(); + if (NULL == mConnectionListener) { + MAS_LOGE("Error : mConnectionListener NULL"); return ECORE_CALLBACK_RENEW; } @@ -1026,13 +1026,13 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle return ECORE_CALLBACK_RENEW; } - dbus_connection_read_write_dispatch(g_conn_listener, 50); + dbus_connection_read_write_dispatch(mConnectionListener, 50); while (1) { DBusMessage* msg = NULL; - msg = dbus_connection_pop_message(g_conn_listener); + msg = dbus_connection_pop_message(mConnectionListener); - if (true != dbus_connection_get_is_connected(g_conn_listener)) { + if (true != dbus_connection_get_is_connected(mConnectionListener)) { MAS_LOGE("[ERROR] Connection is disconnected"); return ECORE_CALLBACK_RENEW; } @@ -1044,70 +1044,70 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle /* client event */ if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_HELLO)) { - dispatcher->on_hello(g_conn_listener, msg); + dispatcher->on_hello(mConnectionListener, msg); } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_INITIALIZE)) { - dispatcher->on_initialize(g_conn_listener, msg); + dispatcher->on_initialize(mConnectionListener, msg); } else if (dbus_message_is_method_call(msg, MA_SERVER_SERVICE_INTERFACE, MA_METHOD_DEINITIALIZE)) { - dispatcher->on_deinitialize(g_conn_listener, msg); + dispatcher->on_deinitialize(mConnectionListener, 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); + dispatcher->on_get_audio_format(mConnectionListener, 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); + dispatcher->on_get_audio_source_type(mConnectionListener, 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); + dispatcher->on_send_asr_result(mConnectionListener, 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); + dispatcher->on_send_result(mConnectionListener, 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); + dispatcher->on_send_recognition_result(mConnectionListener, 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); + dispatcher->on_start_streaming_audio_data(mConnectionListener, 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); + dispatcher->on_stop_streaming_audio_data(mConnectionListener, 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); + dispatcher->on_update_voice_feedback_state(mConnectionListener, 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); + dispatcher->on_send_assistant_specific_command(mConnectionListener, 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); + dispatcher->on_set_background_volume(mConnectionListener, 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); + dispatcher->on_set_preprocessing_allow_mode(mConnectionListener, 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); + dispatcher->on_send_preprocessing_result(mConnectionListener, 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); + dispatcher->on_set_wake_word_audio_require_flag(mConnectionListener, 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); + dispatcher->on_set_assistant_language(mConnectionListener, 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); + dispatcher->on_add_wake_word(mConnectionListener, 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); + dispatcher->on_remove_wake_word(mConnectionListener, 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); + dispatcher->on_ui_initialize(mConnectionListener, 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); + dispatcher->on_ui_deinitialize(mConnectionListener, 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); + dispatcher->on_ui_change_assistant(mConnectionListener, msg); } else { MAS_LOGD("Message is NOT valid"); @@ -1122,15 +1122,15 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle 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 != mConnectionListener) { + dbus_connection_close(mConnectionListener); + dbus_connection_unref(mConnectionListener); + mConnectionListener = NULL; } - if (NULL != g_conn_sender) { - dbus_connection_close(g_conn_sender); - dbus_connection_unref(g_conn_sender); - g_conn_sender = NULL; + if (NULL != mConnectionSender) { + dbus_connection_close(mConnectionSender); + dbus_connection_unref(mConnectionSender); + mConnectionSender = NULL; } } @@ -1142,38 +1142,38 @@ int CServiceIpcDbus::open_connection() int ret; /* Create connection for sender */ - g_conn_sender = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + mConnectionSender = 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) { + if (NULL == mConnectionSender) { MAS_LOGE("[Dbus ERROR] Fail to get dbus connection"); return -1; } - dbus_connection_set_exit_on_disconnect(g_conn_sender, false); + dbus_connection_set_exit_on_disconnect(mConnectionSender, false); /* connect to the bus and check for errors */ - g_conn_listener = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + mConnectionListener = 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) { + if (NULL == mConnectionListener) { MAS_LOGE("[Dbus ERROR] Fail to get dbus connection"); connection_free(); return -1; } - dbus_connection_set_exit_on_disconnect(g_conn_listener, false); + dbus_connection_set_exit_on_disconnect(mConnectionListener, 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); + ret = dbus_bus_request_name(mConnectionListener, 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."); @@ -1190,7 +1190,7 @@ int CServiceIpcDbus::open_connection() } /* Flush messages which are received before fd event handler registration */ - while (DBUS_DISPATCH_DATA_REMAINS == dbus_connection_get_dispatch_status(g_conn_listener)) { + while (DBUS_DISPATCH_DATA_REMAINS == dbus_connection_get_dispatch_status(mConnectionListener)) { listener_event_callback(this, NULL); } @@ -1199,7 +1199,7 @@ int CServiceIpcDbus::open_connection() 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 */ + dbus_bus_add_match(mConnectionListener, 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); @@ -1209,7 +1209,7 @@ int CServiceIpcDbus::open_connection() } int fd = 0; - if (1 != dbus_connection_get_unix_fd(g_conn_listener, &fd)) { + if (1 != dbus_connection_get_unix_fd(mConnectionListener, &fd)) { MAS_LOGE("fail to get fd from dbus "); connection_free(); return -1; @@ -1217,9 +1217,9 @@ int CServiceIpcDbus::open_connection() 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); + mFdHandler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, this, NULL, NULL); - if (NULL == g_dbus_fd_handler) { + if (NULL == mFdHandler) { MAS_LOGE("[Dbus ERROR] Fail to get fd handler"); connection_free(); return -1; @@ -1233,12 +1233,12 @@ 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; + if (NULL != mFdHandler) { + ecore_main_fd_handler_del(mFdHandler); + mFdHandler = NULL; } - dbus_bus_release_name(g_conn_listener, MA_SERVER_SERVICE_NAME, &err); + dbus_bus_release_name(mConnectionListener, MA_SERVER_SERVICE_NAME, &err); if (dbus_error_is_set(&err)) { MAS_LOGE("[Dbus ERROR] dbus_bus_release_name() : %s", err.message); @@ -1248,4 +1248,4 @@ int CServiceIpcDbus::close_connection() connection_free(); return 0; -} \ No newline at end of file +} diff --git a/src/service_main.cpp b/src/service_main.cpp index 6af73f6..0abb443 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -45,8 +45,8 @@ bool CServiceMain::check_preprocessing_assistant_exists() 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 && - strncmp(vconf_str, g_maclient_info[loop].appid, MAX_APPID_LEN) == 0) { + if (mClientInfo[loop].used && + strncmp(vconf_str, mClientInfo[loop].appid, MAX_APPID_LEN) == 0) { if (mClientManager.check_client_validity_by_appid(std::string{vconf_str})) { ret = true; } @@ -276,14 +276,14 @@ int CServiceMain::mas_client_set_preprocessing_allow_mode(int pid, ma_preprocess } 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 (mClientInfo[loop].used) { + if (pid_appid && strncmp(pid_appid, mClientInfo[loop].appid, MAX_APPID_LEN) == 0) { + mClientInfo[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'; + strncpy(mClientInfo[loop].preprocessing_allow_appid, appid, MAX_APPID_LEN); + mClientInfo[loop].preprocessing_allow_appid[MAX_APPID_LEN - 1] = '\0'; } else { - g_maclient_info[loop].preprocessing_allow_appid[0] = '\0'; + mClientInfo[loop].preprocessing_allow_appid[0] = '\0'; } } } @@ -305,8 +305,8 @@ int CServiceMain::mas_client_send_preprocessing_result(int pid, bool result) 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 (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) { + current_maclient_appid = mClientInfo[mCurrentClientInfo].appid; } if (result) { @@ -364,15 +364,15 @@ int CServiceMain::mas_client_add_wake_word(int pid, const char* wake_word, const } 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)) { + if (mClientInfo[loop].used && + 0 == strncmp(buf, mClientInfo[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); + mClientInfo[loop].wakeup_word, + mClientInfo[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); + mClientInfo[loop].wakeup_word, + mClientInfo[loop].wakeup_language); } else { LOGE("add new wake word failed!"); return -1; @@ -395,15 +395,15 @@ int CServiceMain::mas_client_remove_wake_word(int pid, const char* wake_word, co } 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)) { + if (mClientInfo[loop].used && + 0 == strncmp(buf, mClientInfo[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); + mClientInfo[loop].wakeup_word, + mClientInfo[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); + mClientInfo[loop].wakeup_word, + mClientInfo[loop].wakeup_language); } } } @@ -459,13 +459,13 @@ int CServiceMain::mas_ui_client_change_assistant(const char* appid) // 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 */ + /* The appid parameter might not exist after this function call, so we use appid string in our mClientInfo */ 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); + if (mClientInfo[loop].used && + 0 < strlen(mClientInfo[loop].appid) && + 0 < strlen(mClientInfo[loop].wakeup_word[0])) { + if (strncmp(appid, mClientInfo[loop].appid, MAX_APPID_LEN) == 0) { + mas_launch_client_by_appid(mClientInfo[loop].appid, CLIENT_LAUNCH_MODE_ACTIVATION); } } } @@ -498,63 +498,63 @@ int CServiceMain::add_assistant_info(ma_assistant_info_s* info) { int index = -1; int loop = 0; while(-1 == index && loop < MAX_MACLIENT_INFO_NUM) { - if (false == g_maclient_info[loop].used) { + if (false == mClientInfo[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'; + mClientInfo[index].used = true; + mClientInfo[index].preprocessing_allow_mode = MA_PREPROCESSING_ALLOW_NONE; + mClientInfo[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'; + strncpy(mClientInfo[index].appid, info->app_id, MAX_APPID_LEN); + mClientInfo[index].appid[MAX_APPID_LEN - 1] = '\0'; - if (is_current_preprocessing_assistant(g_maclient_info[index].appid)) { - g_current_preprocessing_maclient_info = index; + if (is_current_preprocessing_assistant(mClientInfo[index].appid)) { + mCurrentPreprocessingClientInfo = 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'; + strncpy(mClientInfo[index].wakeup_word[loop], info->wakeup_list[loop], MAX_WAKEUP_WORD_LEN); + mClientInfo[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'; + strncpy(mClientInfo[index].wakeup_language[loop], info->wakeup_language[loop], MAX_SUPPORTED_LANGUAGE_LEN); + mClientInfo[index].wakeup_language[loop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0'; } else { - strncpy(g_maclient_info[index].wakeup_language[loop], "", MAX_SUPPORTED_LANGUAGE_LEN); + strncpy(mClientInfo[index].wakeup_language[loop], "", MAX_SUPPORTED_LANGUAGE_LEN); } } else { - strncpy(g_maclient_info[index].wakeup_word[loop], "", MAX_WAKEUP_WORD_LEN); + strncpy(mClientInfo[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'; + strncpy(mClientInfo[index].supported_language[loop], info->supported_lang[loop], MAX_SUPPORTED_LANGUAGE_LEN); + mClientInfo[index].supported_language[loop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0'; } else { - strncpy(g_maclient_info[index].supported_language[loop], "", MAX_SUPPORTED_LANGUAGE_LEN); + strncpy(mClientInfo[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'; + strncpy(mClientInfo[index].wakeup_engine, info->wakeup_engine, MAX_APPID_LEN); + mClientInfo[index].wakeup_engine[MAX_APPID_LEN - 1] = '\0'; } else { - g_maclient_info[index].wakeup_engine[0] = '\0'; + mClientInfo[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; + mClientInfo[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; + mClientInfo[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; + mClientInfo[index].voice_key_tap_duration = info->voice_key_tap_duration; } else { MAS_LOGD("Couldn't find an empty slot for storing assistant info"); } @@ -593,7 +593,7 @@ int CServiceMain::initialize_service_plugin(void) return -1; } - if (0 != mServicePlugin.set_language(g_current_lang.c_str())) { + if (0 != mServicePlugin.set_language(mCurrentLanguage.c_str())) { MAS_LOGE("Fail to ws set language"); return -1; } @@ -601,34 +601,34 @@ int CServiceMain::initialize_service_plugin(void) 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)) { + if (mClientInfo[loop].used && + 0 < strlen(mClientInfo[loop].appid)) { + mServiceConfig.load_custom_wake_words(mClientInfo[loop].appid, + mClientInfo[loop].wakeup_word, mClientInfo[loop].wakeup_language); + if (0 < strlen(mClientInfo[loop].wakeup_engine)) { mServicePlugin.set_assistant_wakeup_engine( - g_maclient_info[loop].appid, - g_maclient_info[loop].wakeup_engine); + mClientInfo[loop].appid, + mClientInfo[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])) { + if (0 < strlen(mClientInfo[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); + mClientInfo[loop].wakeup_word[inner_loop], mClientInfo[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])) { + mClientInfo[loop].appid, + mClientInfo[loop].wakeup_word[inner_loop], + mClientInfo[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])) { + if (0 < strlen(mClientInfo[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); + mClientInfo[loop].supported_language[inner_loop], mClientInfo[loop].appid); if (0 != mServicePlugin.add_assistant_language( - g_maclient_info[loop].appid, - g_maclient_info[loop].supported_language[inner_loop])) { + mClientInfo[loop].appid, + mClientInfo[loop].supported_language[inner_loop])) { MAS_LOGE("Fail to add assistant's language"); } } @@ -672,8 +672,8 @@ int CServiceMain::process_activated_setting() 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; + if (mClientInfo[0].used) { + default_assistant = mClientInfo[0].appid; MAS_LOGW("No default assistant, setting %s as default", default_assistant); mServicePlugin.set_default_assistant(default_assistant); } else { @@ -689,8 +689,8 @@ int CServiceMain::process_activated_setting() 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; + if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) { + const char *appid = mClientInfo[mCurrentClientInfo].appid; if (appid) { ret = mClientManager.find_client_pid_by_appid(std::string{appid}); } @@ -701,8 +701,8 @@ int CServiceMain::mas_get_current_client_pid() 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; + if (mCurrentPreprocessingClientInfo >= 0 && mCurrentPreprocessingClientInfo < MAX_MACLIENT_INFO_NUM) { + const char *appid = mClientInfo[mCurrentPreprocessingClientInfo].appid; if (appid) { ret = mClientManager.find_client_pid_by_appid(std::string{appid}); } @@ -733,11 +733,11 @@ 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; + if (mClientInfo[loop].used && + 0 < strlen(mClientInfo[loop].appid) && + 0 < strlen(mClientInfo[loop].wakeup_word[0])) { + if (strncmp(appid, mClientInfo[loop].appid, MAX_APPID_LEN) == 0) { + ret = mClientInfo[loop].custom_ui_option; } } } @@ -758,12 +758,12 @@ const char* CServiceMain::mas_get_client_appid_by_wakeup_word(const char *wakeup 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)) { + if (mClientInfo[loop].used && + 0 < strlen(mClientInfo[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; + if (0 < strlen(mClientInfo[loop].wakeup_word[inner_loop])) { + if (0 == strncmp(wakeup_word, mClientInfo[loop].wakeup_word[inner_loop], MAX_WAKEUP_WORD_LEN)) { + appid = mClientInfo[loop].appid; } } } @@ -773,19 +773,19 @@ const char* CServiceMain::mas_get_client_appid_by_wakeup_word(const char *wakeup /* 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)) { + if (mClientInfo[loop].used && + 0 < strlen(mClientInfo[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 < strlen(mClientInfo[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 (' ' != mClientInfo[loop].wakeup_word[inner_loop][index]) { + comparand[comparand_index++] = mClientInfo[loop].wakeup_word[inner_loop][index]; } } if (0 == strncmp(wakeup_word, comparand, MAX_WAKEUP_WORD_LEN)) { - appid = g_maclient_info[loop].appid; + appid = mClientInfo[loop].appid; } } } @@ -800,15 +800,15 @@ 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; + int prev_selection = mCurrentClientInfo; for (loop = 0; loop < MAX_MACLIENT_INFO_NUM && -1 == ret; loop++) { - if (g_maclient_info[loop].used && - 0 < strlen(g_maclient_info[loop].appid)) { + if (mClientInfo[loop].used && + 0 < strlen(mClientInfo[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; + if (0 < strlen(mClientInfo[loop].wakeup_word[inner_loop])) { + if (0 == strncmp(wakeup_word, mClientInfo[loop].wakeup_word[inner_loop], MAX_WAKEUP_WORD_LEN)) { + mCurrentClientInfo = loop; ret = 0; } } @@ -818,19 +818,19 @@ int CServiceMain::mas_set_current_client_by_wakeup_word(const char *wakeup_word) /* 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)) { + if (mClientInfo[loop].used && + 0 < strlen(mClientInfo[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 < strlen(mClientInfo[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 (' ' != mClientInfo[loop].wakeup_word[inner_loop][index]) { + comparand[comparand_index++] = mClientInfo[loop].wakeup_word[inner_loop][index]; } } if (0 == strncmp(wakeup_word, comparand, MAX_WAKEUP_WORD_LEN)) { - g_current_maclient_info = loop; + mCurrentClientInfo = loop; ret = 0; } } @@ -839,9 +839,9 @@ int CServiceMain::mas_set_current_client_by_wakeup_word(const char *wakeup_word) } } - if (g_current_maclient_info != prev_selection) { + if (mCurrentClientInfo != prev_selection) { if (prev_selection >= 0 && prev_selection < MAX_MACLIENT_INFO_NUM) { - int pid = mas_get_client_pid_by_appid(g_maclient_info[prev_selection].appid); + int pid = mas_get_client_pid_by_appid(mClientInfo[prev_selection].appid); mServiceIpc.active_state_change(pid, MA_ACTIVE_STATE_INACTIVE); } } @@ -852,22 +852,22 @@ int CServiceMain::mas_set_current_client_by_wakeup_word(const char *wakeup_word) int CServiceMain::mas_set_current_client_by_appid(const char *appid) { int ret = -1; - int prev_selection = g_current_maclient_info; + int prev_selection = mCurrentClientInfo; 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; + if (mClientInfo[loop].used && + 0 < strlen(mClientInfo[loop].appid) && + 0 < strlen(mClientInfo[loop].wakeup_word[0])) { + if (strncmp(appid, mClientInfo[loop].appid, MAX_APPID_LEN) == 0) { + mCurrentClientInfo = loop; ret = 0; } } } - if (g_current_maclient_info != prev_selection) { + if (mCurrentClientInfo != prev_selection) { if (prev_selection >= 0 && prev_selection < MAX_MACLIENT_INFO_NUM) { - int pid = mas_get_client_pid_by_appid(g_maclient_info[prev_selection].appid); + int pid = mas_get_client_pid_by_appid(mClientInfo[prev_selection].appid); mServiceIpc.active_state_change(pid, MA_ACTIVE_STATE_INACTIVE); } } @@ -912,15 +912,15 @@ int CServiceMain::mas_launch_client_by_appid(const char *appid, CLIENT_LAUNCH_MO 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; + if (mClientInfo[loop].used && + 0 < strlen(mClientInfo[loop].appid)) { + if (strncmp(appid, mClientInfo[loop].appid, MAX_APPID_LEN) == 0) { + mWakeupClientAppId = mClientInfo[loop].appid; found = true; } } } - MAS_LOGD("g_wakeup_maclient_appid : %s, %d", g_wakeup_maclient_appid.c_str(), found); + MAS_LOGD("mWakeupClientAppId : %s, %d", mWakeupClientAppId.c_str(), found); } if (b) bundle_free(b); @@ -986,17 +986,17 @@ int CServiceMain::mas_update_voice_key_support_mode() 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 (mClientInfo[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; + strncmp(default_assistant, mClientInfo[loop].appid, MAX_APPID_LEN) == 0) { + float duration = mClientInfo[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); + mClientInfo[loop].voice_key_support_mode); successful = true; } } @@ -1013,9 +1013,9 @@ int CServiceMain::mas_update_voice_key_support_mode() 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; + if (appid && mClientInfo[loop].used) { + if (strncmp(appid, mClientInfo[loop].appid, MAX_APPID_LEN) == 0) { + return mClientInfo[loop].preprocessing_allow_mode; } } } @@ -1029,9 +1029,9 @@ int CServiceMain::mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVEN { 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; + if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) { + current_maclient_appid = mClientInfo[mCurrentClientInfo].appid; + preprocessing_allow_appid = mClientInfo[mCurrentClientInfo].preprocessing_allow_appid; } ma_preprocessing_allow_mode_e mode = get_preprocessing_allow_mode(current_maclient_appid); @@ -1043,12 +1043,12 @@ int CServiceMain::mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVEN 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; + mCurrentPreprocessingState = 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; + mCurrentPreprocessingState = PREPROCESSING_STATE_WAKEUP_PREPROCESS_ENABLED; } } } else { @@ -1062,13 +1062,13 @@ int CServiceMain::mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVEN break; case PREPROCESSING_STATE_EVENT_PREPROCESSING_ALLOW_MODE_CHANGED: { - g_current_preprocessing_state = PREPROCESSING_STATE_WAKEUP_PREPROCESS_DISABLED; + mCurrentPreprocessingState = 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; + mCurrentPreprocessingState = PREPROCESSING_STATE_WAKEUP_PREPROCESS_ENABLED; } } } @@ -1076,9 +1076,9 @@ int CServiceMain::mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVEN 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_STATE_WAKEUP_PREPROCESS_ENABLED == mCurrentPreprocessingState) { + mCurrentPreprocessingState = PREPROCESSING_STATE_PREPROCESSING_UTTERANCE; + } else if (PREPROCESSING_STATE_WAKEUP_PREPROCESS_DISABLED == mCurrentPreprocessingState) { /* 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 @@ -1086,17 +1086,17 @@ int CServiceMain::mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVEN mas_bring_client_to_foreground(current_maclient_appid); } #endif - g_current_preprocessing_state = PREPROCESSING_STATE_NONE; + mCurrentPreprocessingState = PREPROCESSING_STATE_NONE; } } break; case PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED: { - g_current_preprocessing_state = PREPROCESSING_STATE_NONE; + mCurrentPreprocessingState = 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; + mCurrentPreprocessingState = PREPROCESSING_STATE_PREPROCESSING_FOLLOW_UP; } } } @@ -1104,8 +1104,8 @@ int CServiceMain::mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVEN 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) { + if (PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED == mCurrentPreprocessingState || + PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED == mCurrentPreprocessingState) { char* vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID); MAS_LOGD("preprocessing_assistant_appid : %s", vconf_str); if (vconf_str) { @@ -1115,18 +1115,18 @@ int CServiceMain::mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVEN } } #endif - g_current_preprocessing_state = PREPROCESSING_STATE_NONE; + mCurrentPreprocessingState = 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) { + if (PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED == mCurrentPreprocessingState || + PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED == mCurrentPreprocessingState) { mas_bring_client_to_foreground(current_maclient_appid); } #endif - g_current_preprocessing_state = PREPROCESSING_STATE_NONE; + mCurrentPreprocessingState = PREPROCESSING_STATE_NONE; } break; } @@ -1135,7 +1135,7 @@ int CServiceMain::mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVEN int CServiceMain::mas_set_current_service_state(ma_service_state_e state) { - g_current_service_state = state; + mCurrentServiceState = state; ma_client_s *data = NULL; @@ -1157,15 +1157,15 @@ int CServiceMain::mas_set_current_service_state(ma_service_state_e state) ma_service_state_e CServiceMain::mas_get_current_service_state() { - return g_current_service_state; + return mCurrentServiceState; } 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)) { + if (mClientInfo[loop].used) { + LOGD("comparing appid : %s %s", mClientInfo[loop].wakeup_engine, appid); + if (0 == strncmp(mClientInfo[loop].wakeup_engine, appid, MAX_APPID_LEN)) { return true; } } @@ -1338,10 +1338,10 @@ bool CServiceMain::app_create(void *data) vconf_str = NULL; } - if (!g_pkgmgr) { - int ret = package_manager_create(&g_pkgmgr); + if (!mPackageManagerHandle) { + int ret = package_manager_create(&mPackageManagerHandle); if (ret == PACKAGE_MANAGER_ERROR_NONE) { - ret = package_manager_set_event_cb(g_pkgmgr, _package_manager_event_cb, this); + ret = package_manager_set_event_cb(mPackageManagerHandle, _package_manager_event_cb, this); if (ret == PACKAGE_MANAGER_ERROR_NONE) { LOGD("package_manager_set_event_cb succeeded."); } else { @@ -1358,10 +1358,10 @@ bool CServiceMain::app_create(void *data) 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; + if (mPackageManagerHandle) { + package_manager_unset_event_cb(mPackageManagerHandle); + package_manager_destroy(mPackageManagerHandle); + mPackageManagerHandle = NULL; } deinitialize_service_plugin(); @@ -1397,8 +1397,8 @@ int CServiceMain::on_initialize(int pid) { mClientManager.create_client(pid, appid); 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 (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) { + current_maclient_appid = mClientInfo[mCurrentClientInfo].appid; } mas_client_send_preprocessing_information(pid); @@ -1408,13 +1408,13 @@ int CServiceMain::on_initialize(int pid) { 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(); + if (0 == mWakeupClientAppId.compare(appid)) { + mWakeupClientAppId.clear(); mServiceIpc.active_state_change(pid, MA_ACTIVE_STATE_ACTIVE); 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); + MAS_LOGE("[ERROR] mWakeupClientAppId and appid differ : %s %s", + mWakeupClientAppId.c_str(), appid); } } else { MAS_LOGD("MA client connected, but its appid does not match with current maclient"); diff --git a/src/service_plugin.cpp b/src/service_plugin.cpp index b552823..6348c8a 100644 --- a/src/service_plugin.cpp +++ b/src/service_plugin.cpp @@ -46,8 +46,8 @@ 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; + if (mPluginSettings) { + ret = mPluginSettings->ui_panel_enabled; } MAS_LOGD("UI Panel Enabled : %d", ret); return ret; @@ -189,39 +189,39 @@ static void __wakeup_event_cb(mas_wakeup_event_info wakeup_info, void* user_data } #ifdef BUF_SAVE_MODE - if (g_pFile) { - fclose(g_pFile); - g_pFile = NULL; + if (mDumpFile) { + fclose(mDumpFile); + mDumpFile = 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); + snprintf(mDumpFilename, sizeof(mDumpFilename), "/tmp/ma_service_%d_%d", getpid(), mDumpCount); + int ret = access(mDumpFilename, 0); if (0 == ret) { MAS_LOGD("[Recorder ERROR] File is already exist"); - if (0 == remove(g_temp_file_name)) { + if (0 == remove(mDumpFilename)) { MAS_LOGD("[Recorder] Remove file"); break; } else { - g_count++; + mDumpCount++; } } else { break; } } - MAS_LOGD("[Recorder] Temp file name=[%s]", g_temp_file_name); + MAS_LOGD("[Recorder] Temp file name=[%s]", mDumpFilename); /* open test file */ - g_pFile = fopen(g_temp_file_name, "wb+x"); - if (!g_pFile) { + mDumpFile = fopen(mDumpFilename, "wb+x"); + if (!mDumpFile) { MAS_LOGD("[Recorder ERROR] File not found!"); return; } - g_count++; + mDumpCount++; #endif #if 0 /* + TEST_CODE */ @@ -374,15 +374,14 @@ static void __audio_streaming_cb(mas_speech_streaming_event_e event, void* buffe } } #ifdef BUF_SAVE_MODE - /* write pcm buffer */ - if (g_pFile) - fwrite(buffer, 1, len, g_pFile); + if (mDumpFile) + fwrite(speech_data->buffer, 1, speech_data->len, mDumpFile); if (MAS_SPEECH_STREAMING_EVENT_FINISH == event) { - if (g_pFile) { + if (mDumpFile) { MAS_LOGE("[Recorder SUCCESS] File Close"); - fclose(g_pFile); - g_pFile = NULL; + fclose(mDumpFile); + mDumpFile = NULL; } else { MAS_LOGE("[Recorder ERROR] File not found!"); } @@ -511,140 +510,140 @@ int CServicePlugin::initialize(void) snprintf(filepath, 512, "%s/%s", default_engine_path, MA_DEFAULT_WAKEUP_MANAGER_FILENAME); char *error; - g_handle = NULL; - g_handle = dlopen(filepath, RTLD_LAZY); + mPluginHandle = NULL; + mPluginHandle = 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, + mWakeupManagerInterface.initialize = + (wakeup_manager_initialize)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_INITIALIZE); - _wakeup_manager_interface.deinitialize = - (wakeup_manager_deinitialize)dlsym(g_handle, + mWakeupManagerInterface.deinitialize = + (wakeup_manager_deinitialize)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE); - _wakeup_manager_interface.get_settings = - (wakeup_manager_get_settings)dlsym(g_handle, + mWakeupManagerInterface.get_settings = + (wakeup_manager_get_settings)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS); - _wakeup_manager_interface.add_assistant_wakeup_word = - (wakeup_manager_add_assistant_wakeup_word)dlsym(g_handle, + mWakeupManagerInterface.add_assistant_wakeup_word = + (wakeup_manager_add_assistant_wakeup_word)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_WORD); - _wakeup_manager_interface.remove_assistant_wakeup_word = - (wakeup_manager_remove_assistant_wakeup_word)dlsym(g_handle, + mWakeupManagerInterface.remove_assistant_wakeup_word = + (wakeup_manager_remove_assistant_wakeup_word)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_REMOVE_ASSISTANT_WAKEUP_WORD); - _wakeup_manager_interface.add_assistant_language = - (wakeup_manager_add_assistant_language)dlsym(g_handle, + mWakeupManagerInterface.add_assistant_language = + (wakeup_manager_add_assistant_language)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE); - _wakeup_manager_interface.set_assistant_wakeup_engine = - (wakeup_manager_set_assistant_wakeup_engine)dlsym(g_handle, + mWakeupManagerInterface.set_assistant_wakeup_engine = + (wakeup_manager_set_assistant_wakeup_engine)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE); - _wakeup_manager_interface.set_default_assistant = - (wakeup_manager_set_default_assistant)dlsym(g_handle, + mWakeupManagerInterface.set_default_assistant = + (wakeup_manager_set_default_assistant)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_SET_DEFAULT_ASSISTANT); - _wakeup_manager_interface.get_default_assistant = - (wakeup_manager_get_default_assistant)dlsym(g_handle, + mWakeupManagerInterface.get_default_assistant = + (wakeup_manager_get_default_assistant)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_GET_DEFAULT_ASSISTANT); - _wakeup_manager_interface.set_language = - (wakeup_manager_set_language)dlsym(g_handle, + mWakeupManagerInterface.set_language = + (wakeup_manager_set_language)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE); - _wakeup_manager_interface.activate = - (wakeup_manager_activate)dlsym(g_handle, + mWakeupManagerInterface.activate = + (wakeup_manager_activate)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_ACTIVATE); - _wakeup_manager_interface.deactivate = - (wakeup_manager_deactivate)dlsym(g_handle, + mWakeupManagerInterface.deactivate = + (wakeup_manager_deactivate)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_DEACTIVATE); - _wakeup_manager_interface.update_voice_feedback_state = - (wakeup_manager_update_voice_feedback_state)dlsym(g_handle, + mWakeupManagerInterface.update_voice_feedback_state = + (wakeup_manager_update_voice_feedback_state)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_UPDATE_VOICE_FEEDBACK_STATE); - _wakeup_manager_interface.set_assistant_specific_command = - (wakeup_manager_set_assistant_specific_command)dlsym(g_handle, + mWakeupManagerInterface.set_assistant_specific_command = + (wakeup_manager_set_assistant_specific_command)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND); - _wakeup_manager_interface.set_background_volume = - (wakeup_manager_set_background_volume)dlsym(g_handle, + mWakeupManagerInterface.set_background_volume = + (wakeup_manager_set_background_volume)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_SET_BACKGROUND_VOLUME); - _wakeup_manager_interface.update_recognition_result = - (wakeup_manager_update_recognition_result)dlsym(g_handle, + mWakeupManagerInterface.update_recognition_result = + (wakeup_manager_update_recognition_result)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_UPDATE_RECOGNITION_RESULT); - _wakeup_manager_interface.process_plugin_event = - (wakeup_manager_process_plugin_event)dlsym(g_handle, + mWakeupManagerInterface.process_plugin_event = + (wakeup_manager_process_plugin_event)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_PROCESS_PLUGIN_EVENT); - _wakeup_manager_interface.start_streaming_utterance_data = - (wakeup_manager_start_streaming_utterance_data)dlsym(g_handle, + mWakeupManagerInterface.start_streaming_utterance_data = + (wakeup_manager_start_streaming_utterance_data)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_START_STREAMING_UTTERANCE_DATA); - _wakeup_manager_interface.stop_streaming_utterance_data = - (wakeup_manager_stop_streaming_utterance_data)dlsym(g_handle, + mWakeupManagerInterface.stop_streaming_utterance_data = + (wakeup_manager_stop_streaming_utterance_data)dlsym(mPluginHandle, 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, + mWakeupManagerInterface.start_streaming_previous_utterance_data = + (wakeup_manager_start_streaming_previous_utterance_data)dlsym(mPluginHandle, 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, + mWakeupManagerInterface.stop_streaming_previous_utterance_data = + (wakeup_manager_stop_streaming_previous_utterance_data)dlsym(mPluginHandle, 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, + mWakeupManagerInterface.start_streaming_follow_up_data = + (wakeup_manager_start_streaming_follow_up_data)dlsym(mPluginHandle, 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, + mWakeupManagerInterface.stop_streaming_follow_up_data = + (wakeup_manager_stop_streaming_follow_up_data)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_FOLLOW_UP_DATA); - _wakeup_manager_interface.get_audio_format = - (wakeup_manager_get_audio_format)dlsym(g_handle, + mWakeupManagerInterface.get_audio_format = + (wakeup_manager_get_audio_format)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_FORMAT); - _wakeup_manager_interface.get_audio_source_type = - (wakeup_manager_get_audio_source_type)dlsym(g_handle, + mWakeupManagerInterface.get_audio_source_type = + (wakeup_manager_get_audio_source_type)dlsym(mPluginHandle, 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, + mWakeupManagerInterface.set_wake_word_audio_require_flag = + (wakeup_manager_set_wake_word_audio_require_flag)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_SET_WAKE_WORD_AUDIO_REQUIRE_FLAG); - _wakeup_manager_interface.set_assistant_language = - (wakeup_manager_set_assistant_language)dlsym(g_handle, + mWakeupManagerInterface.set_assistant_language = + (wakeup_manager_set_assistant_language)dlsym(mPluginHandle, 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, + mWakeupManagerInterface.set_voice_key_tap_duration = + (wakeup_manager_set_voice_key_tap_duration)dlsym(mPluginHandle, 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, + mWakeupManagerInterface.unset_voice_key_tap_duration = + (wakeup_manager_unset_voice_key_tap_duration)dlsym(mPluginHandle, 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, + mWakeupManagerInterface.set_voice_key_support_mode = + (wakeup_manager_set_voice_key_support_mode)dlsym(mPluginHandle, 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, + mWakeupManagerInterface.set_wakeup_event_callback = + (wakeup_manager_set_wakeup_event_callback)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_EVENT_CALLBACK); - _wakeup_manager_interface.set_utterance_streaming_callback = - (wakeup_manager_set_utterance_streaming_callback)dlsym(g_handle, + mWakeupManagerInterface.set_utterance_streaming_callback = + (wakeup_manager_set_utterance_streaming_callback)dlsym(mPluginHandle, 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, + mWakeupManagerInterface.set_previous_utterance_streaming_callback = + (wakeup_manager_set_previous_utterance_streaming_callback)dlsym(mPluginHandle, 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, + mWakeupManagerInterface.set_follow_up_streaming_callback = + (wakeup_manager_set_follow_up_streaming_callback)dlsym(mPluginHandle, 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, + mWakeupManagerInterface.set_speech_status_callback = + (wakeup_manager_set_speech_status_callback)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_SET_SPEECH_STATUS_CALLBACK); - _wakeup_manager_interface.set_setting_changed_callback = - (wakeup_manager_set_setting_changed_callback)dlsym(g_handle, + mWakeupManagerInterface.set_setting_changed_callback = + (wakeup_manager_set_setting_changed_callback)dlsym(mPluginHandle, MA_WAKEUP_MANAGER_FUNC_SET_SETTING_CHANGED_CALLBACK); - _wakeup_manager_interface.set_error_callback = - (wakeup_manager_set_error_callback)dlsym(g_handle, + mWakeupManagerInterface.set_error_callback = + (wakeup_manager_set_error_callback)dlsym(mPluginHandle, 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, + mWakeupManagerInterface.set_streaming_section_changed_callback = + (wakeup_manager_set_streaming_section_changed_callback)dlsym(mPluginHandle, 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, + mWakeupManagerInterface.set_wakeup_engine_command_callback = + (wakeup_manager_set_wakeup_engine_command_callback)dlsym(mPluginHandle, 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, + mWakeupManagerInterface.set_wakeup_service_state_changed_callback = + (wakeup_manager_set_wakeup_service_state_changed_callback)dlsym(mPluginHandle, 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, + mWakeupManagerInterface.set_voice_key_status_changed_callback = + (wakeup_manager_set_voice_key_status_changed_callback)dlsym(mPluginHandle, 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 != mPluginHandle) { + wakeup_manager_initialize func = mWakeupManagerInterface.initialize; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_INITIALIZE); @@ -655,20 +654,20 @@ int CServicePlugin::initialize(void) } } - wakeup_manager_get_settings get_settings_func = _wakeup_manager_interface.get_settings; + wakeup_manager_get_settings get_settings_func = mWakeupManagerInterface.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); + ret = get_settings_func(&mPluginSettings, &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; + mPluginSettings = NULL; } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -676,17 +675,17 @@ int CServicePlugin::initialize(void) int CServicePlugin::deinitialize(void) { #ifdef BUF_SAVE_MODE - if (g_pFile) { - fclose(g_pFile); - g_pFile = NULL; + if (mDumpFile) { + fclose(mDumpFile); + mDumpFile = 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 != mPluginHandle) { + wakeup_manager_deinitialize func = mWakeupManagerInterface.deinitialize; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE); } else { @@ -696,10 +695,10 @@ int CServicePlugin::deinitialize(void) } } - dlclose(g_handle); - g_handle = NULL; + dlclose(mPluginHandle); + mPluginHandle = NULL; } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; @@ -708,8 +707,8 @@ int CServicePlugin::deinitialize(void) 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 != mPluginHandle) { + wakeup_manager_get_settings func = mWakeupManagerInterface.get_settings; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_SETTINGS); } else { @@ -719,7 +718,7 @@ int CServicePlugin::get_settings(ma_plugin_settings **settings, size_t *struct_s } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -727,8 +726,8 @@ int CServicePlugin::get_settings(ma_plugin_settings **settings, size_t *struct_s 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 != mPluginHandle) { + wakeup_manager_set_language func = mWakeupManagerInterface.set_language; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE); } else { @@ -738,7 +737,7 @@ int CServicePlugin::set_language(const char* language) } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -746,8 +745,8 @@ int CServicePlugin::set_language(const char* language) 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 != mPluginHandle) { + wakeup_manager_add_assistant_wakeup_word func = mWakeupManagerInterface.add_assistant_wakeup_word; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_WORD); } else { @@ -757,7 +756,7 @@ int CServicePlugin::add_assistant_wakeup_word(const char* appid, const char* wak } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -765,8 +764,8 @@ int CServicePlugin::add_assistant_wakeup_word(const char* appid, const char* wak 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 != mPluginHandle) { + wakeup_manager_remove_assistant_wakeup_word func = mWakeupManagerInterface.remove_assistant_wakeup_word; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_REMOVE_ASSISTANT_WAKEUP_WORD); } else { @@ -776,7 +775,7 @@ int CServicePlugin::remove_assistant_wakeup_word(const char* appid, const char* } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -784,8 +783,8 @@ int CServicePlugin::remove_assistant_wakeup_word(const char* appid, const char* 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 != mPluginHandle) { + wakeup_manager_add_assistant_language func = mWakeupManagerInterface.add_assistant_language; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE); } else { @@ -795,7 +794,7 @@ int CServicePlugin::add_assistant_language(const char* appid, const char* langua } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -803,8 +802,8 @@ int CServicePlugin::add_assistant_language(const char* appid, const char* langua 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 != mPluginHandle) { + wakeup_manager_set_assistant_wakeup_engine func = mWakeupManagerInterface.set_assistant_wakeup_engine; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE); } else { @@ -814,7 +813,7 @@ int CServicePlugin::set_assistant_wakeup_engine(const char* appid, const char* e } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -822,8 +821,8 @@ int CServicePlugin::set_assistant_wakeup_engine(const char* appid, const char* e 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 != mPluginHandle) { + wakeup_manager_set_default_assistant func = mWakeupManagerInterface.set_default_assistant; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_DEFAULT_ASSISTANT); } else { @@ -833,7 +832,7 @@ int CServicePlugin::set_default_assistant(const char* appid) } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -845,8 +844,8 @@ int CServicePlugin::get_default_assistant(const char** 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 != mPluginHandle) { + wakeup_manager_get_default_assistant func = mWakeupManagerInterface.get_default_assistant; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_DEFAULT_ASSISTANT); } else { @@ -856,7 +855,7 @@ int CServicePlugin::get_default_assistant(const char** appid) } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -864,8 +863,8 @@ int CServicePlugin::get_default_assistant(const char** appid) int CServicePlugin::activate(void) { int ret = -1; - if (NULL != g_handle) { - wakeup_manager_activate func = _wakeup_manager_interface.activate; + if (NULL != mPluginHandle) { + wakeup_manager_activate func = mWakeupManagerInterface.activate; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ACTIVATE); } else { @@ -875,7 +874,7 @@ int CServicePlugin::activate(void) } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -883,8 +882,8 @@ int CServicePlugin::activate(void) int CServicePlugin::deactivate(void) { int ret = -1; - if (NULL != g_handle) { - wakeup_manager_deactivate func = _wakeup_manager_interface.deactivate; + if (NULL != mPluginHandle) { + wakeup_manager_deactivate func = mWakeupManagerInterface.deactivate; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_DEACTIVATE); } else { @@ -894,7 +893,7 @@ int CServicePlugin::deactivate(void) } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -902,8 +901,8 @@ int CServicePlugin::deactivate(void) 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 != mPluginHandle) { + wakeup_manager_update_voice_feedback_state func = mWakeupManagerInterface.update_voice_feedback_state; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UPDATE_VOICE_FEEDBACK_STATE); } else { @@ -913,7 +912,7 @@ int CServicePlugin::update_voice_feedback_state(const char* appid, int state) } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -921,8 +920,8 @@ int CServicePlugin::update_voice_feedback_state(const char* appid, int state) 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 != mPluginHandle) { + wakeup_manager_set_assistant_specific_command func = mWakeupManagerInterface.set_assistant_specific_command; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_SPECIFIC_COMMAND); } else { @@ -932,7 +931,7 @@ int CServicePlugin::set_assistant_specific_command(const char* appid, const char } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -940,8 +939,8 @@ int CServicePlugin::set_assistant_specific_command(const char* appid, const char 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 != mPluginHandle) { + wakeup_manager_set_background_volume func = mWakeupManagerInterface.set_background_volume; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_BACKGROUND_VOLUME); } else { @@ -951,7 +950,7 @@ int CServicePlugin::set_background_volume(const char* appid, double ratio) } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -959,8 +958,8 @@ int CServicePlugin::set_background_volume(const char* appid, double ratio) 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 != mPluginHandle) { + wakeup_manager_update_recognition_result func = mWakeupManagerInterface.update_recognition_result; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_UPDATE_RECOGNITION_RESULT); } else { @@ -970,7 +969,7 @@ int CServicePlugin::update_recognition_result(const char* appid, int state) } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -978,8 +977,8 @@ int CServicePlugin::update_recognition_result(const char* appid, int state) 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 != mPluginHandle) { + wakeup_manager_process_plugin_event func = mWakeupManagerInterface.process_plugin_event; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_PROCESS_PLUGIN_EVENT); } else { @@ -989,7 +988,7 @@ int CServicePlugin::process_event(int event, void *data, int len) } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -997,8 +996,8 @@ int CServicePlugin::process_event(int event, void *data, int len) 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 != mPluginHandle) { + wakeup_manager_start_streaming_utterance_data func = mWakeupManagerInterface.start_streaming_utterance_data; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_START_STREAMING_UTTERANCE_DATA); } else { @@ -1008,7 +1007,7 @@ int CServicePlugin::start_streaming_utterance_data(void) } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -1016,8 +1015,8 @@ int CServicePlugin::start_streaming_utterance_data(void) 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 != mPluginHandle) { + wakeup_manager_stop_streaming_utterance_data func = mWakeupManagerInterface.stop_streaming_utterance_data; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_STOP_STREAMING_UTTERANCE_DATA); } else { @@ -1027,7 +1026,7 @@ int CServicePlugin::stop_streaming_utterance_data(void) } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -1035,8 +1034,8 @@ int CServicePlugin::stop_streaming_utterance_data(void) 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 != mPluginHandle) { + wakeup_manager_start_streaming_previous_utterance_data func = mWakeupManagerInterface.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 { @@ -1046,7 +1045,7 @@ int CServicePlugin::start_streaming_previous_utterance_data(void) } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -1054,8 +1053,8 @@ int CServicePlugin::start_streaming_previous_utterance_data(void) 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 != mPluginHandle) { + wakeup_manager_stop_streaming_previous_utterance_data func = mWakeupManagerInterface.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 { @@ -1065,7 +1064,7 @@ int CServicePlugin::stop_streaming_previous_utterance_data(void) } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -1073,8 +1072,8 @@ int CServicePlugin::stop_streaming_previous_utterance_data(void) 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 != mPluginHandle) { + wakeup_manager_start_streaming_follow_up_data func = mWakeupManagerInterface.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 { @@ -1084,7 +1083,7 @@ int CServicePlugin::start_streaming_follow_up_data(void) } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -1092,8 +1091,8 @@ int CServicePlugin::start_streaming_follow_up_data(void) 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 != mPluginHandle) { + wakeup_manager_stop_streaming_follow_up_data func = mWakeupManagerInterface.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 { @@ -1103,7 +1102,7 @@ int CServicePlugin::stop_streaming_follow_up_data(void) } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -1111,8 +1110,8 @@ int CServicePlugin::stop_streaming_follow_up_data(void) 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 != mPluginHandle) { + wakeup_manager_get_audio_format func = mWakeupManagerInterface.get_audio_format; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_FORMAT); } else { @@ -1122,7 +1121,7 @@ int CServicePlugin::get_recording_audio_format(int *rate, int *channel, int *aud } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -1130,8 +1129,8 @@ int CServicePlugin::get_recording_audio_format(int *rate, int *channel, int *aud 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 != mPluginHandle) { + wakeup_manager_get_audio_source_type func = mWakeupManagerInterface.get_audio_source_type; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_GET_AUDIO_SOURCE_TYPE); } else { @@ -1141,7 +1140,7 @@ int CServicePlugin::get_recording_audio_source_type(char** type) } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -1149,8 +1148,8 @@ int CServicePlugin::get_recording_audio_source_type(char** type) 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 != mPluginHandle) { + wakeup_manager_set_voice_key_tap_duration func = mWakeupManagerInterface.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 { @@ -1160,7 +1159,7 @@ int CServicePlugin::set_voice_key_tap_duration(float duration) } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -1168,8 +1167,8 @@ int CServicePlugin::set_voice_key_tap_duration(float duration) 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 != mPluginHandle) { + wakeup_manager_unset_voice_key_tap_duration func = mWakeupManagerInterface.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 { @@ -1179,7 +1178,7 @@ int CServicePlugin::unset_voice_key_tap_duration() } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -1187,8 +1186,8 @@ int CServicePlugin::unset_voice_key_tap_duration() 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 != mPluginHandle) { + wakeup_manager_set_voice_key_support_mode func = mWakeupManagerInterface.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 { @@ -1198,7 +1197,7 @@ int CServicePlugin::set_voice_key_support_mode(int mode) } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -1206,8 +1205,8 @@ int CServicePlugin::set_voice_key_support_mode(int mode) 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 != mPluginHandle) { + wakeup_manager_set_wake_word_audio_require_flag func = mWakeupManagerInterface.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 { @@ -1217,7 +1216,7 @@ int CServicePlugin::set_wake_word_audio_require_flag(const char* appid, bool req } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -1225,8 +1224,8 @@ int CServicePlugin::set_wake_word_audio_require_flag(const char* appid, bool req 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 != mPluginHandle) { + wakeup_manager_set_assistant_language func = mWakeupManagerInterface.set_assistant_language; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_LANGUAGE); } else { @@ -1236,7 +1235,7 @@ int CServicePlugin::set_assistant_language(const char* appid, const char* langua } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -1315,8 +1314,8 @@ int CServicePlugin::set_callbacks(void) 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 != mPluginHandle) { + wakeup_manager_set_wakeup_event_callback func = mWakeupManagerInterface.set_wakeup_event_callback; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_EVENT_CALLBACK); } else { @@ -1327,7 +1326,7 @@ int CServicePlugin::set_wakeup_event_callback(wakeup_service_wakeup_event_cb cal } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -1335,8 +1334,8 @@ int CServicePlugin::set_wakeup_event_callback(wakeup_service_wakeup_event_cb cal 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 != mPluginHandle) { + wakeup_manager_set_utterance_streaming_callback func = mWakeupManagerInterface.set_utterance_streaming_callback; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_UTTERANCE_STREAMING_CALLBACK); } else { @@ -1346,7 +1345,7 @@ int CServicePlugin::set_utterance_streaming_callback(wakeup_service_speech_strea } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -1354,8 +1353,8 @@ int CServicePlugin::set_utterance_streaming_callback(wakeup_service_speech_strea 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 != mPluginHandle) { + wakeup_manager_set_previous_utterance_streaming_callback func = mWakeupManagerInterface.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 { @@ -1365,7 +1364,7 @@ int CServicePlugin::set_previous_utterance_streaming_callback(wakeup_service_spe } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -1373,8 +1372,8 @@ int CServicePlugin::set_previous_utterance_streaming_callback(wakeup_service_spe 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 != mPluginHandle) { + wakeup_manager_set_follow_up_streaming_callback func = mWakeupManagerInterface.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 { @@ -1384,7 +1383,7 @@ int CServicePlugin::set_follow_up_streaming_callback(wakeup_service_speech_strea } } } else { - MAS_LOGE("[ERROR] g_handle is not valid"); + MAS_LOGE("[ERROR] mPluginHandle is not valid"); } return ret; } @@ -1392,8 +1391,8 @@ int CServicePlugin::set_follow_up_streaming_callback(wakeup_service_speech_strea 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 != mPluginHandle) { + wakeup_manager_set_speech_status_callback func = mWakeupManagerInterface.set_speech_status_callback; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_SPEECH_STATUS_CALLBACK); } else { @@ -1409,8 +1408,8 @@ int CServicePlugin::set_speech_status_callback(wakeup_service_speech_status_cb c 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 != mPluginHandle) { + wakeup_manager_set_setting_changed_callback func = mWakeupManagerInterface.set_setting_changed_callback; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_SETTING_CHANGED_CALLBACK); } else { @@ -1426,8 +1425,8 @@ int CServicePlugin::set_setting_changed_callback(wakeup_service_setting_changed_ 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 != mPluginHandle) { + wakeup_manager_set_error_callback func = mWakeupManagerInterface.set_error_callback; if (NULL == func) { MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ERROR_CALLBACK); } else { @@ -1443,8 +1442,8 @@ int CServicePlugin::set_error_callback(wakeup_service_error_cb callback, void* u 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 != mPluginHandle) { + wakeup_manager_set_streaming_section_changed_callback func = mWakeupManagerInterface.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 { @@ -1460,8 +1459,8 @@ int CServicePlugin::set_streaming_section_changed_callback(wakeup_service_stream 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 != mPluginHandle) { + wakeup_manager_set_wakeup_engine_command_callback func = mWakeupManagerInterface.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 { @@ -1477,8 +1476,8 @@ int CServicePlugin::set_wakeup_engine_command_callback(wakeup_service_wakeup_eng 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 != mPluginHandle) { + wakeup_manager_set_wakeup_service_state_changed_callback func = mWakeupManagerInterface.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 { @@ -1494,8 +1493,8 @@ int CServicePlugin::set_wakeup_service_state_changed_callback(wakeup_service_wak 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 != mPluginHandle) { + wakeup_manager_set_voice_key_status_changed_callback func = mWakeupManagerInterface.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 { -- 2.7.4 From 8143783075abe7b092ccc923ea69826295f1082d Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Wed, 1 Apr 2020 11:42:18 +0900 Subject: [PATCH 15/16] Extract vconf dependency from service_main.cpp Change-Id: I1ef3458ccbd2a298319068d27fca8bcced170512 --- CMakeLists.txt | 1 + inc/preference_manager.h | 46 +++++++ inc/preference_manager_vconf.h | 59 +++++++++ inc/service_main.h | 12 +- packaging/org.tizen.multi-assistant-service.spec | 1 + src/main.cpp | 6 +- src/preference_manager_vconf.cpp | 148 +++++++++++++++++++++++ src/service_main.cpp | 82 ++++++------- 8 files changed, 309 insertions(+), 46 deletions(-) create mode 100644 inc/preference_manager.h create mode 100644 inc/preference_manager_vconf.h create mode 100644 src/preference_manager_vconf.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 529f152..61c3363 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,7 @@ SET(SRCS src/main.cpp src/service_config.cpp src/application_manager_aul.cpp + src/preference_manager_vconf.cpp src/client_manager.cpp src/service_main.cpp src/service_plugin.cpp diff --git a/inc/preference_manager.h b/inc/preference_manager.h new file mode 100644 index 0000000..fa33d7f --- /dev/null +++ b/inc/preference_manager.h @@ -0,0 +1,46 @@ +/* + * 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 __PREFERENCE_MANAGER_H__ +#define __PREFERENCE_MANAGER_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*preference_changed_cb)(std::string key, void* user_data); + +class IPreferenceManager { +public: + virtual boost::optional get_string(const std::string& key) = 0; + virtual boost::optional get_int(const std::string& key) = 0; + virtual boost::optional get_bool(const std::string& key) = 0; + + virtual bool register_changed_callback( + const std::string& key, preference_changed_cb calback, void* user_data) = 0; + virtual bool unregister_changed_callback( + const std::string& key, preference_changed_cb callback) = 0; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* __PREFERENCE_MANAGER_H__ */ diff --git a/inc/preference_manager_vconf.h b/inc/preference_manager_vconf.h new file mode 100644 index 0000000..bae3670 --- /dev/null +++ b/inc/preference_manager_vconf.h @@ -0,0 +1,59 @@ +/* + * 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 __PREFERENCE_MANAGER_VCONF_H__ +#define __PREFERENCE_MANAGER_VCONF_H__ + +#include "preference_manager.h" + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef std::tuple CallbackEntry; + +class CPreferenceManagerVconf : public IPreferenceManager { +public: + CPreferenceManagerVconf(); + ~CPreferenceManagerVconf(); + + boost::optional get_string(const std::string& key) override; + boost::optional get_int(const std::string& key) override; + boost::optional get_bool(const std::string& key) override; + + bool register_changed_callback( + const std::string& key, preference_changed_cb calback, void* user_data) override; + bool unregister_changed_callback( + const std::string& key, preference_changed_cb callback) override; + + const std::map>& get_callbacks() { + return mCallbackEntries; + } + +private: + std::map> mCallbackEntries; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* __PREFERENCE_MANAGER_VCONF_H__ */ diff --git a/inc/service_main.h b/inc/service_main.h index d97e68a..4bfaddd 100644 --- a/inc/service_main.h +++ b/inc/service_main.h @@ -30,7 +30,8 @@ #include "client_manager.h" #include "service_plugin.h" #include "service_ipc_dbus.h" -#include "application_manager_aul.h" +#include "application_manager.h" +#include "preference_manager.h" #ifdef __cplusplus extern "C" { @@ -70,7 +71,10 @@ typedef enum { class CServiceMain : public IServiceIpcObserver { public: - CServiceMain() {} + CServiceMain(IApplicationManager& applicationManager, IPreferenceManager& preferenceManager) : + mApplicationManager{applicationManager}, + mPreferenceManager{preferenceManager} + {} virtual ~CServiceMain() {} int mas_client_get_audio_format(int pid, int* rate, int* channel, int* audio_type); @@ -191,8 +195,8 @@ private: CClientManager mClientManager; - CApplicationManagerAul mApplicationManager; - + IApplicationManager& mApplicationManager; + IPreferenceManager& mPreferenceManager; }; #ifdef __cplusplus diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index bb4d60b..ee68c66 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -26,6 +26,7 @@ BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(multi-assistant) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(pkgmgr-info) +BuildRequires: boost-devel %if %{defined _test_type} BuildRequires: gtest-devel %endif diff --git a/src/main.cpp b/src/main.cpp index 951d933..c7e4dae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,8 +18,12 @@ #include #include "service_main.h" +#include "application_manager_aul.h" +#include "preference_manager_vconf.h" -CServiceMain g_service_main; +CApplicationManagerAul g_application_manager_aul; +CPreferenceManagerVconf g_preference_manager_vconf; +CServiceMain g_service_main{g_application_manager_aul, g_preference_manager_vconf}; static bool service_app_create(void *data) { diff --git a/src/preference_manager_vconf.cpp b/src/preference_manager_vconf.cpp new file mode 100644 index 0000000..823cbad --- /dev/null +++ b/src/preference_manager_vconf.cpp @@ -0,0 +1,148 @@ +/* + * 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 "preference_manager_vconf.h" + +#include + +CPreferenceManagerVconf::CPreferenceManagerVconf() +{ +} + +CPreferenceManagerVconf::~CPreferenceManagerVconf() +{ +} + +boost::optional CPreferenceManagerVconf::get_string(const std::string& key) +{ + boost::optional ret; + + char* vconf_str = vconf_get_str(key.c_str()); + if (vconf_str) { + ret = std::string{vconf_str}; + free(vconf_str); + vconf_str = NULL; + } + + return ret; +} + +boost::optional CPreferenceManagerVconf::get_int(const std::string& key) +{ + boost::optional ret; + + int vconf_value = 0; + int succeeded = vconf_get_int(key.c_str(), &vconf_value); + if (0 == succeeded) { + ret = vconf_value; + } + + return ret; +} + +boost::optional CPreferenceManagerVconf::get_bool(const std::string& key) +{ + boost::optional ret; + + int vconf_value = 0; + int succeeded = vconf_get_bool(key.c_str(), &vconf_value); + if (0 == succeeded) { + /* Non-zero means true */ + ret = (vconf_value != 0); + } + + return ret; +} + +static void vconf_key_changed(keynode_t* key, void* data) +{ + if (nullptr == key) return; + + const char* name = vconf_keynode_get_name(key); + if (nullptr == name) return; + + CPreferenceManagerVconf* preference_manager = + static_cast(data); + if (nullptr == preference_manager) return; + + const std::map>& entries_map = + preference_manager->get_callbacks(); + + std::map>::const_iterator iter = + entries_map.find(name); + + if (iter != entries_map.end()) { + std::list entries = iter->second; + /* Iterate through list */ + for (const auto& entry : entries) { + preference_changed_cb callback = std::get<0>(entry); + void* user_data = std::get<1>(entry); + callback(std::string{name}, user_data); + } + } +} + +bool CPreferenceManagerVconf::register_changed_callback( + const std::string& key, preference_changed_cb callback, void* user_data) +{ + bool ret = false; + + std::list entries; + CallbackEntry entry = std::make_tuple(callback, user_data); + std::map>::iterator iter = + mCallbackEntries.find(key); + + bool registered = false; + if (iter != mCallbackEntries.end()) { + entries = iter->second; + registered = true; + } + + /* Avoid registering vconf_key_changed() for the same key */ + if (!registered) { + if (0 == vconf_notify_key_changed(key.c_str(), vconf_key_changed, this)) { + registered = true; + } + } + if (registered) { + entries.push_back(entry); + mCallbackEntries[key] = entries; + ret = true; + } + return ret; +} + +bool CPreferenceManagerVconf::unregister_changed_callback(const std::string& key, preference_changed_cb callback) +{ + std::map>::iterator map_iter = + mCallbackEntries.find(key); + + if (map_iter != mCallbackEntries.end()) { + bool found = false; + for (const auto& entry : map_iter->second) { + if (callback == std::get<0>(entry)) { + if (!found) { + map_iter->second.remove(entry); + found = true; + } + } + } + if (map_iter->second.empty()) { + vconf_ignore_key_changed(key.c_str(), vconf_key_changed); + } + } + return true; +} diff --git a/src/service_main.cpp b/src/service_main.cpp index 0abb443..cad2c4a 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -42,18 +42,17 @@ bool CServiceMain::check_preprocessing_assistant_exists() { bool ret = false; - char* vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID); - if (vconf_str) { + boost::optional preprocessing_appid = + mPreferenceManager.get_string(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID); + if (preprocessing_appid) { for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) { if (mClientInfo[loop].used && - strncmp(vconf_str, mClientInfo[loop].appid, MAX_APPID_LEN) == 0) { - if (mClientManager.check_client_validity_by_appid(std::string{vconf_str})) { + strncmp((*preprocessing_appid).c_str(), mClientInfo[loop].appid, MAX_APPID_LEN) == 0) { + if (mClientManager.check_client_validity_by_appid(*preprocessing_appid)) { ret = true; } } } - free(vconf_str); - vconf_str = NULL; } MAS_LOGD("result : %d", ret); @@ -67,13 +66,12 @@ bool CServiceMain::is_current_preprocessing_assistant(const char* appid) 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) { + boost::optional preprocessing_appid = + mPreferenceManager.get_string(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID); + if (preprocessing_appid) { + if (strncmp((*preprocessing_appid).c_str(), appid, MAX_APPID_LEN) == 0) { ret = true; } - free(vconf_str); - vconf_str = NULL; } return ret; @@ -116,12 +114,11 @@ 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; + boost::optional preprocessing_appid = + mPreferenceManager.get_string(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID); + if (preprocessing_appid) { + MAS_LOGD("preprocessing_assistant_appid : %s", (*preprocessing_appid).c_str()); + ret = mServiceIpc.send_preprocessing_information(pid, (*preprocessing_appid).c_str()); } return ret; @@ -564,18 +561,22 @@ int CServiceMain::add_assistant_info(ma_assistant_info_s* info) { return 0; } -static void active_state_changed_cb(keynode_t* key, void* data) +static void active_state_changed_cb(std::string key, void* user_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); + IPreferenceManager* manager = static_cast(user_data); + if (nullptr == manager) return; + + boost::optional activated = + manager->get_bool(MULTI_ASSISTANT_SETTINGS_ACTIVATED); + if (activated) { + MAS_LOGD("multi-assistant active state : %d\n", *activated); CServicePlugin *plugin = nullptr; if (g_service_main) { plugin = g_service_main->get_service_plugin(); } if (plugin) { - if (vconf_value) { + if (*activated) { plugin->activate(); } else { plugin->deactivate(); @@ -662,9 +663,10 @@ int CServiceMain::deinitialize_service_plugin(void) int CServiceMain::process_activated_setting() { - if (0 == vconf_notify_key_changed(MULTI_ASSISTANT_SETTINGS_ACTIVATED, active_state_changed_cb, NULL)) { + if (mPreferenceManager.register_changed_callback( + MULTI_ASSISTANT_SETTINGS_ACTIVATED, active_state_changed_cb, &mPreferenceManager)) { /* Activate / deactivate according to the vconf key setting */ - active_state_changed_cb(NULL, NULL); + active_state_changed_cb(std::string{}, &mPreferenceManager); } else { #ifdef ENABLE_MULTI_ASSISTANT_BY_DEFAULT /* Multi-assistant needs to be enabled by default, unless disabled explicitly */ @@ -965,9 +967,9 @@ int CServiceMain::mas_launch_client_by_wakeup_word(const char *wakeup_word) 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) { + boost::optional prelaunch_mode = + mPreferenceManager.get_bool(WAKEUP_SETTINGS_KEY_PRELAUNCH_MODE); + if (prelaunch_mode && *prelaunch_mode) { const char *default_assistant = NULL; if (0 == mServicePlugin.get_default_assistant(&default_assistant)) { if (0 == aul_app_is_running(default_assistant)) { @@ -1106,12 +1108,11 @@ int CServiceMain::mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVEN #ifdef BRING_PREPROCESSING_ASSISTANT_TO_FRONT if (PREPROCESSING_STATE_EVENT_UTTERANCE_STREAMING_STARTED == mCurrentPreprocessingState || PREPROCESSING_STATE_EVENT_FOLLOW_UP_STREAMING_STARTED == mCurrentPreprocessingState) { - 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; + boost::optional preprocessing_assistant = + mPreferenceManager.get_bool(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID); + if (preprocessing_assistant) { + MAS_LOGD("preprocessing_assistant_appid : %s", (*preprocessing_assistant).c_str()); + mas_bring_client_to_foreground((*preprocessing_assistant).c_str()); } } #endif @@ -1329,13 +1330,11 @@ bool CServiceMain::app_create(void *data) 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; + boost::optional preprocessing_assistant = + mPreferenceManager.get_string(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID); + if (preprocessing_assistant) { + MAS_LOGD("prelaunching preprocessing_assistant_appid : %s", (*preprocessing_assistant).c_str()); + mas_launch_client_by_appid((*preprocessing_assistant).c_str(), CLIENT_LAUNCH_MODE_PRELAUNCH); } if (!mPackageManagerHandle) { @@ -1366,7 +1365,8 @@ void CServiceMain::app_terminate(void *data) deinitialize_service_plugin(); - vconf_ignore_key_changed(MULTI_ASSISTANT_SETTINGS_ACTIVATED, active_state_changed_cb); + mPreferenceManager.unregister_changed_callback( + MULTI_ASSISTANT_SETTINGS_ACTIVATED, active_state_changed_cb); int ret = mServiceIpc.close_connection(); if (0 != ret) { -- 2.7.4 From 68f452ad396d89e55a647e0025fd7aba0aeecf1e Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Thu, 2 Apr 2020 00:03:59 +0900 Subject: [PATCH 16/16] Extract aul dependency from service_main.cpp Change-Id: Ifd796751933776c0153e8c78d345b94542ac37da --- inc/application_manager.h | 5 + inc/application_manager_aul.h | 6 +- inc/service_common.h | 2 + inc/service_main.h | 2 - src/application_manager_aul.cpp | 76 +++++++- src/service_main.cpp | 218 +++++++++-------------- tests/utc/client-manager/test_client_manager.cpp | 4 + 7 files changed, 176 insertions(+), 137 deletions(-) diff --git a/inc/application_manager.h b/inc/application_manager.h index f6733fc..08b2586 100644 --- a/inc/application_manager.h +++ b/inc/application_manager.h @@ -18,6 +18,7 @@ #ifndef __APPLICATION_MANAGER_H__ #define __APPLICATION_MANAGER_H__ +#include #include #ifdef __cplusplus @@ -27,6 +28,10 @@ extern "C" { class IApplicationManager { public: virtual bool is_application_running(int pid) = 0; + virtual bool is_application_running(const std::string& appid) = 0; + virtual bool bring_app_to_foreground(const std::string& appid) = 0; + virtual bool launch_app_async(const std::string& appid, bool background) = 0; + virtual boost::optional get_appid_by_pid(int pid) = 0; }; #ifdef __cplusplus diff --git a/inc/application_manager_aul.h b/inc/application_manager_aul.h index 2c47dc2..b0b3dd3 100644 --- a/inc/application_manager_aul.h +++ b/inc/application_manager_aul.h @@ -20,8 +20,6 @@ #include "application_manager.h" -#include - #ifdef __cplusplus extern "C" { #endif @@ -29,6 +27,10 @@ extern "C" { class CApplicationManagerAul : public IApplicationManager { public: virtual bool is_application_running(int pid) override; + virtual bool is_application_running(const std::string& appid) override; + virtual bool bring_app_to_foreground(const std::string& appid) override; + virtual bool launch_app_async(const std::string& appid, bool background) override; + virtual boost::optional get_appid_by_pid(int pid) override; }; #ifdef __cplusplus diff --git a/inc/service_common.h b/inc/service_common.h index ecef87d..747b57a 100644 --- a/inc/service_common.h +++ b/inc/service_common.h @@ -125,6 +125,8 @@ typedef void (*wakeup_service_voice_key_status_changed_cb)(ma_voice_key_status_e #define MAX_SUPPORTED_LANGUAGES_NUM 255 #define MAX_SUPPORTED_LANGUAGE_LEN 16 +#define MAX_APPID_LEN 255 + typedef enum { VOICE_KEY_SUPPORT_MODE_NONE, VOICE_KEY_SUPPORT_MODE_PUSH_TO_TALK, diff --git a/inc/service_main.h b/inc/service_main.h index 4bfaddd..4a6ddfa 100644 --- a/inc/service_main.h +++ b/inc/service_main.h @@ -37,8 +37,6 @@ extern "C" { #endif -#define MAX_APPID_LEN 255 - typedef enum { CLIENT_LAUNCH_MODE_ACTIVATION, CLIENT_LAUNCH_MODE_PRELAUNCH, diff --git a/src/application_manager_aul.cpp b/src/application_manager_aul.cpp index 2553c93..5cf8855 100644 --- a/src/application_manager_aul.cpp +++ b/src/application_manager_aul.cpp @@ -18,6 +18,7 @@ #include "service_common.h" #include +#include bool CApplicationManagerAul::is_application_running(int pid) { @@ -27,4 +28,77 @@ bool CApplicationManagerAul::is_application_running(int pid) return false; } return true; -} \ No newline at end of file +} + +bool CApplicationManagerAul::is_application_running(const std::string& appid) +{ + return (!!aul_app_is_running(appid.c_str())); +} + +bool CApplicationManagerAul::bring_app_to_foreground(const std::string& appid) +{ + bool ret = true; + + /* Bring MA client to foreground - is there a better way other than launching? */ + 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.c_str(), b); + if (result < AUL_R_OK) { + MAS_LOGE("ERROR : aul_launch_app failed. app_id [%s] bundle[%p] result[%d : %s]", + appid.c_str(), b, result, get_error_message(result)); + ret = false; + } + + if (b) bundle_free(b); + b = NULL; + + return ret; +} + +bool CApplicationManagerAul::launch_app_async(const std::string& appid, bool background) +{ + bool ret = true; + + bundle *b = NULL; + b = bundle_create(); + if (NULL == b) { + MAS_LOGE("Failed creating bundle for aul operation"); + return false; + } + + int result = aul_svc_set_background_launch(b, background); + if (result < AUL_R_OK) { + MAS_LOGE("ERROR : aul_svc_set_background_launch failed. app_id [%s] bundle[%p] result[%d : %s]", + appid.c_str(), b, result, get_error_message(result)); + } + + result = aul_launch_app_async(appid.c_str(), b); + if (result < AUL_R_OK) { + MAS_LOGE("ERROR : aul_launch_app_async failed. app_id [%s] bundle[%p] result[%d : %s]", + appid.c_str(), b, result, get_error_message(result)); + ret = false; + } + + if (b) bundle_free(b); + b = NULL; + + return ret; +} + +boost::optional CApplicationManagerAul::get_appid_by_pid(int pid) +{ + boost::optional ret; + + 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'; + ret = std::string{appid}; + } + + return ret; +} diff --git a/src/service_main.cpp b/src/service_main.cpp index cad2c4a..5e660f9 100644 --- a/src/service_main.cpp +++ b/src/service_main.cpp @@ -18,8 +18,6 @@ #include #include #include -#include -#include #include #include #include @@ -160,13 +158,12 @@ int CServiceMain::mas_client_send_result(int pid, const char* display_text, 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; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } - mServicePlugin.update_recognition_result(pid_appid, MA_RECOGNITION_RESULT_EVENT_SUCCESS); + mServicePlugin.update_recognition_result(pid_appid.c_str(), MA_RECOGNITION_RESULT_EVENT_SUCCESS); return ret; } @@ -179,13 +176,12 @@ int CServiceMain::mas_client_send_recognition_result(int pid, int result) 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; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } - mServicePlugin.update_recognition_result(pid_appid, result); + mServicePlugin.update_recognition_result(pid_appid.c_str(), result); return ret; } @@ -229,52 +225,48 @@ int CServiceMain::mas_client_stop_streaming_audio_data(int pid, int type) 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; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } - mServicePlugin.update_voice_feedback_state(pid_appid, state); + mServicePlugin.update_voice_feedback_state(pid_appid.c_str(), 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; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } - mServicePlugin.set_assistant_specific_command(pid_appid, command); + mServicePlugin.set_assistant_specific_command(pid_appid.c_str(), 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; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } - mServicePlugin.set_background_volume(pid_appid, ratio); + mServicePlugin.set_background_volume(pid_appid.c_str(), 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; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) { if (mClientInfo[loop].used) { - if (pid_appid && strncmp(pid_appid, mClientInfo[loop].appid, MAX_APPID_LEN) == 0) { + if (0 == pid_appid.compare(mClientInfo[loop].appid)) { mClientInfo[loop].preprocessing_allow_mode = mode; if (appid) { strncpy(mClientInfo[loop].preprocessing_allow_appid, appid, MAX_APPID_LEN); @@ -293,13 +285,12 @@ int CServiceMain::mas_client_set_preprocessing_allow_mode(int pid, ma_preprocess 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; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } - if (!is_current_preprocessing_assistant(pid_appid)) return -1; + if (!is_current_preprocessing_assistant(pid_appid.c_str())) return -1; const char *current_maclient_appid = NULL; if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) { @@ -307,7 +298,7 @@ int CServiceMain::mas_client_send_preprocessing_result(int pid, bool result) } if (result) { - MAS_LOGD("Preprocessing succeeded, bring (%s) to foreground", pid_appid); + MAS_LOGD("Preprocessing succeeded, bring (%s) to foreground", pid_appid.c_str()); mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_SUCCEEDED); } else { MAS_LOGD("Preprocessing failed, bring (%s) to foreground", current_maclient_appid); @@ -325,49 +316,44 @@ int CServiceMain::mas_client_send_preprocessing_result(int pid, bool result) 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; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } - mServicePlugin.set_wake_word_audio_require_flag(pid_appid, require); + mServicePlugin.set_wake_word_audio_require_flag(pid_appid.c_str(), 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; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } - mServicePlugin.set_assistant_language(pid_appid, language); + mServicePlugin.set_assistant_language(pid_appid.c_str(), 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; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) { if (mClientInfo[loop].used && - 0 == strncmp(buf, mClientInfo[loop].appid, MAX_APPID_LEN)) { - ret = mServiceConfig.add_custom_wake_word(wake_word, language, + 0 == pid_appid.compare(mClientInfo[loop].appid)) { + int ret = mServiceConfig.add_custom_wake_word(wake_word, language, mClientInfo[loop].wakeup_word, mClientInfo[loop].wakeup_language); if (0 == ret) { - mServiceConfig.save_custom_wake_words(pid_appid, + mServiceConfig.save_custom_wake_words(pid_appid.c_str(), mClientInfo[loop].wakeup_word, mClientInfo[loop].wakeup_language); } else { @@ -377,35 +363,33 @@ int CServiceMain::mas_client_add_wake_word(int pid, const char* wake_word, const } } - mServicePlugin.add_assistant_wakeup_word(pid_appid, wake_word, language); + mServicePlugin.add_assistant_wakeup_word(pid_appid.c_str(), 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; + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; } for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) { if (mClientInfo[loop].used && - 0 == strncmp(buf, mClientInfo[loop].appid, MAX_APPID_LEN)) { - ret = mServiceConfig.remove_custom_wake_word(wake_word, language, + 0 == pid_appid.compare(mClientInfo[loop].appid)) { + int ret = mServiceConfig.remove_custom_wake_word(wake_word, language, mClientInfo[loop].wakeup_word, mClientInfo[loop].wakeup_language); if (0 == ret) { - mServiceConfig.save_custom_wake_words(pid_appid, + mServiceConfig.save_custom_wake_words(pid_appid.c_str(), mClientInfo[loop].wakeup_word, mClientInfo[loop].wakeup_language); } } } - mServicePlugin.remove_assistant_wakeup_word(pid_appid, wake_word, language); + mServicePlugin.remove_assistant_wakeup_word(pid_appid.c_str(), wake_word, language); return 0; } @@ -720,10 +704,8 @@ int CServiceMain::mas_get_client_pid_by_appid(const char *appid) ret = mClientManager.find_client_pid_by_appid(std::string{appid}); } - 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); + if (-1 != ret && !mApplicationManager.is_application_running(ret)) { + MAS_LOGE("The PID for %s was %d, but it seems to be terminated", appid, ret); on_deinitialize(ret); ret = -1; } @@ -879,36 +861,22 @@ int CServiceMain::mas_set_current_client_by_appid(const char *appid) int CServiceMain::mas_launch_client_by_appid(const char *appid, CLIENT_LAUNCH_MODE launch_mode) { + int result = 0; + 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)) { + if (mApplicationManager.is_application_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)); + result = mApplicationManager.launch_app_async(appid, true); + } else { + result = mApplicationManager.launch_app_async(appid, false); } if (CLIENT_LAUNCH_MODE_ACTIVATION == launch_mode) { @@ -925,37 +893,23 @@ int CServiceMain::mas_launch_client_by_appid(const char *appid, CLIENT_LAUNCH_MO MAS_LOGD("mWakeupClientAppId : %s, %d", mWakeupClientAppId.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? */ + int ret = 0; + 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 (!mApplicationManager.bring_app_to_foreground(appid)) { + ret = -1; } - if (b) bundle_free(b); - b = NULL; - - return result; + return ret; } int CServiceMain::mas_launch_client_by_wakeup_word(const char *wakeup_word) @@ -972,7 +926,7 @@ int CServiceMain::mas_prelaunch_default_assistant() if (prelaunch_mode && *prelaunch_mode) { const char *default_assistant = NULL; if (0 == mServicePlugin.get_default_assistant(&default_assistant)) { - if (0 == aul_app_is_running(default_assistant)) { + if (!(mApplicationManager.is_application_running(default_assistant))) { MAS_LOGD("prelaunching default_assistant_appid : %s", default_assistant); mas_launch_client_by_appid(default_assistant, CLIENT_LAUNCH_MODE_PRELAUNCH); } @@ -1382,19 +1336,19 @@ void CServiceMain::app_terminate(void *data) int CServiceMain::on_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")); + std::string pid_appid; + boost::optional appid_by_pid = mApplicationManager.get_appid_by_pid(pid); + if (appid_by_pid) { + pid_appid = *appid_by_pid; + MAS_LOGD("appid for pid %d is : %s", pid, pid_appid.c_str()); /* Remove existing client that has same appid, if there's any */ - mClientManager.destroy_client_by_appid(appid); + mClientManager.destroy_client_by_appid(pid_appid.c_str()); /* And remove a client that has same pid also */ mClientManager.destroy_client_by_pid(pid); - mClientManager.create_client(pid, appid); + mClientManager.create_client(pid, pid_appid.c_str()); const char *current_maclient_appid = NULL; if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) { @@ -1405,16 +1359,16 @@ int CServiceMain::on_initialize(int 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)) { + if (current_maclient_appid && 0 == pid_appid.compare(current_maclient_appid)) { MAS_LOGD("MA client with current maclient appid connected!"); - if (0 == mWakeupClientAppId.compare(appid)) { + if (0 == mWakeupClientAppId.compare(pid_appid)) { mWakeupClientAppId.clear(); mServiceIpc.active_state_change(pid, MA_ACTIVE_STATE_ACTIVE); mas_process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_ASSISTANT_ACTIVATED); } else { MAS_LOGE("[ERROR] mWakeupClientAppId and appid differ : %s %s", - mWakeupClientAppId.c_str(), appid); + mWakeupClientAppId.c_str(), pid_appid.c_str()); } } else { MAS_LOGD("MA client connected, but its appid does not match with current maclient"); diff --git a/tests/utc/client-manager/test_client_manager.cpp b/tests/utc/client-manager/test_client_manager.cpp index e77ded9..ef1357f 100644 --- a/tests/utc/client-manager/test_client_manager.cpp +++ b/tests/utc/client-manager/test_client_manager.cpp @@ -27,6 +27,10 @@ public: virtual ~CDummyApplicationManager() {}; bool is_application_running(int pid) { return true; } + bool is_application_running(const std::string& appid) { return true; } + bool bring_app_to_foreground(const std::string& appid) { return true; } + bool launch_app_async(const std::string& appid, bool background) { return true; } + boost::optional get_appid_by_pid(int pid) { return boost::optional{}; } }; class StorageWithNoClient : public testing::Test -- 2.7.4