From: Ji-hoon Lee Date: Fri, 15 Mar 2019 07:33:19 +0000 (+0900) Subject: Implement default wakeup policy X-Git-Tag: submit/tizen/20190418.072452~28 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=616c27beaf176c08edf9a919d89d5ba4e2b7e6ed;p=platform%2Fcore%2Fuifw%2Fwakeup-engine-default.git Implement default wakeup policy Change-Id: Ic12713be95009606110696cf153ad5a39cdd8599 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d450a2..6bf6f95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,15 +29,13 @@ pkg_check_modules(pkgs REQUIRED multi-assistant ) - - # SET FLAG --------------------------------------------------------------------------------------- FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -fPIE -std=gnu++0x -fvisibility=hidden -fvisibility-inlines-hidden") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -fPIE -std=c++11 -fvisibility=hidden -fvisibility-inlines-hidden") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIE -fvisibility=hidden") # SET WARNNING OPTION ---------------------------------------------------------------------------- diff --git a/inc/multi_assistant_config.h b/inc/multi_assistant_config.h index 8f3d7eb..72e4a8b 100644 --- a/inc/multi_assistant_config.h +++ b/inc/multi_assistant_config.h @@ -31,14 +31,16 @@ extern "C" /************************************************************************************** *** Definitions for xml file *************************************************************************************/ -#define MA_TAG_ASSISTANT_BASE "multi-assistant" -#define MA_TAG_ASSISTANT_NAME "name" -#define MA_TAG_ASSISTANT_ID "id" -#define MA_TAG_ASSISTANT_ICON_PATH "icon-path" -#define MA_TAG_ASSISTANT_LANGUAGE_SET "languages" -#define MA_TAG_ASSISTANT_LANGUAGE "lang" -#define MA_TAG_ASSISTANT_WAKEUP_WORD_SET "wakeup-words" -#define MA_TAG_ASSISTANT_WAKEUP_WORD "wakeup-word" +#define MA_TAG_ASSISTANT_BASE "multi-assistant" +#define MA_TAG_ASSISTANT_NAME "name" +#define MA_TAG_ASSISTANT_APPID "appid" +#define MA_TAG_ASSISTANT_ICON_PATH "icon-path" +#define MA_TAG_ASSISTANT_LANGUAGE_SET "languages" +#define MA_TAG_ASSISTANT_LANGUAGE "language" +#define MA_TAG_ASSISTANT_WAKEUP_WORD_SET "wakeup-words" +#define MA_TAG_ASSISTANT_WAKEUP_WORD "wakeup-word" +#define MA_TAG_ASSISTANT_WAKEUP_ENGINE_APPID "wakeup-engine-appid" +#define MA_TAG_ASSISTANT_CUSTOM_UI "custom-ui" /************************************************************************************** *** Definitions for ETC @@ -55,9 +57,10 @@ typedef struct { int cnt_wakeup; const char* supported_lang[MAX_SUPPORTED_LANGUAGE_NUM]; int cnt_lang; + const char* wakeup_engine; } 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[], int cnt_wakeup, const char* supported_lang[], int cnt_lang, void* user_data); +typedef int (*mas_config_assistant_info_cb)(const char* appid, const char* name, const char* icon_path, const char* wakeup_list[], int cnt_wakeup, const char* supported_lang[], int cnt_lang, const char* wakeup_engine, 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 e134529..fa0f751 100644 --- a/inc/multi_assistant_main.h +++ b/inc/multi_assistant_main.h @@ -70,6 +70,7 @@ #define MAS_METHOD_HELLO "mas_method_hello" #define MAS_METHOD_ACTIVE_STATE_CHANGE "mas_method_active_state_change" #define MAS_METHOD_STREAMING_AUDIO_DATA "mas_method_streaming_audio_data" +#define MAS_METHOD_WAKEUP_ENGINE_COMMAND "mas_method_wakeup_engine_command" #define MAS_METHOD_ERROR "mas_method_error" #define MAS_UI_METHOD_SEND_ASR_RESULT "mas_ui_method_send_asr_result" diff --git a/inc/multi_assistant_service_plugin.h b/inc/multi_assistant_service_plugin.h index 1984547..796e5cc 100644 --- a/inc/multi_assistant_service_plugin.h +++ b/inc/multi_assistant_service_plugin.h @@ -38,7 +38,13 @@ int multi_assistant_service_plugin_deinitialize(void); int multi_assistant_service_plugin_set_language(const char* language); -int multi_assistant_service_plugin_set_wakeup_word(const char* language, const char* wakeup_word); +int multi_assistant_service_plugin_add_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_assistant_enabled(const char* appid, int enabled); int multi_assistant_service_plugin_activate(void); @@ -89,8 +95,14 @@ int multi_assistant_service_plugin_set_error_callback(wakeup_service_error_cb ca typedef int (*wakeup_manager_initialize)(void); #define MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE "wakeup_manager_deinitialize" typedef int (*wakeup_manager_deinitialize)(void); -#define MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_WORD "wakeup_manager_set_wakeup_word" -typedef int (*wakeup_manager_set_wakeup_word)(const char* language, const char* wakeup_word); +#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_ADD_ASSISTANT_LANGUAGE "wakeup_manager_add_assistant_language" +typedef int (*wakeup_manager_add_assistant_language)(const char* appid, const char* language); +#define MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE "wakeup_manager_set_assistant_wakeup_engine" +typedef int (*wakeup_manager_set_assistant_wakeup_engine)(const char* appid, const char* engine); +#define MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_ENABLED "wakeup_manager_set_assistant_enabled" +typedef int (*wakeup_manager_set_assistant_enabled)(const char* appid, int enabled); #define MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE "wakeup_manager_set_language" typedef int (*wakeup_manager_set_language)(const char* language); #define MA_WAKEUP_MANAGER_FUNC_ACTIVATE "wakeup_manager_activate" @@ -135,7 +147,10 @@ typedef int (*wakeup_manager_set_error_callback)(wakeup_service_error_cb callbac typedef struct { wakeup_manager_initialize initialize; wakeup_manager_deinitialize deinitialize; - wakeup_manager_set_wakeup_word set_wakeup_word; + wakeup_manager_add_assistant_wakeup_word add_assistant_wakeup_word; + wakeup_manager_add_assistant_language add_assistant_language; + wakeup_manager_set_assistant_wakeup_engine set_assistant_wakeup_engine; + wakeup_manager_set_assistant_enabled set_assistant_enabled; wakeup_manager_set_language set_language; wakeup_manager_activate activate; wakeup_manager_deactivate deactivate; diff --git a/inc/multi_wakeup_recognizer.h b/inc/multi_wakeup_recognizer.h index 58a6b6c..344b4d6 100644 --- a/inc/multi_wakeup_recognizer.h +++ b/inc/multi_wakeup_recognizer.h @@ -25,11 +25,20 @@ extern "C" { #endif -typedef enum { - WAKEUP_EVENT_ERROR = -1, /**< Event when the wakeup recognition has failed */ - WAKEUP_EVENT_SUCCESS = 1, /**< Event when the wakeup word is matched succesfully */ - WAKEUP_EVENT_REJECTED = 2 /**< Event when the wakeup word is not matched */ -} wakeup_service_wakeup_event_e; +typedef struct { + const char *wakeup_appid; + const char *wakeup_word; + const char *wakeup_language; + const char *wakeup_voice_id; + float wakeup_confidence_score; + + long wakeup_start_time; + long wakeup_end_time; + + const void *extra_data; + int extra_data_length; + const char *extra_data_description; +} wakeup_event_info; typedef enum { WAKEUP_SPEECH_STREAMING_EVENT_FAIL = -1, /**< Failed */ @@ -51,7 +60,7 @@ typedef enum { } wakeup_asr_result_event_e; -typedef void (*wakeup_service_wakeup_event_cb)(wakeup_service_wakeup_event_e event, const char* wakeup_word, void* user_data); +typedef void (*wakeup_service_wakeup_event_cb)(wakeup_event_info event, const char* wakeup_word, void* user_data); typedef void (*wakeup_service_speech_streaming_cb)(wakeup_service_speech_streaming_event_e event, unsigned char* buffer, int len, void *user_data); diff --git a/packaging/org.tizen.multi-assistant-service.spec b/packaging/org.tizen.multi-assistant-service.spec index fb765ac..0ea34be 100644 --- a/packaging/org.tizen.multi-assistant-service.spec +++ b/packaging/org.tizen.multi-assistant-service.spec @@ -22,6 +22,7 @@ BuildRequires: pkgconfig(dbus-1) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(multi-assistant) +BuildRequires: pkgconfig(vconf) %if "%{tizen_profile_name}" == "tv" BuildRequires: pkgconfig(vd-win-util) BuildRequires: pkgconfig(capi-network-bluetooth) diff --git a/plugins/wakeup-manager/CMakeLists.txt b/plugins/wakeup-manager/CMakeLists.txt index eb8ed08..5efc20f 100644 --- a/plugins/wakeup-manager/CMakeLists.txt +++ b/plugins/wakeup-manager/CMakeLists.txt @@ -21,6 +21,7 @@ SET(WMPKG_CHECK_MODULES capi-media-audio-io capi-media-sound-manager eina + vconf ) IF("${_TV_PRODUCT}" STREQUAL "TRUE") @@ -45,6 +46,9 @@ ADD_DEFINITIONS("-DPACKAGE=\"${PACKAGE}\"") SET(SRCS src/wakeup_manager.cpp + src/wakeup_policy.cpp + src/wakeup_policy_default.cpp + src/wakeup_manager_audio.cpp ) FOREACH(flag ${wmpkgs_CFLAGS}) @@ -52,13 +56,12 @@ FOREACH(flag ${wmpkgs_CFLAGS}) ENDFOREACH(flag) -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS} -fPIC -std=c++11 -fvisibility=hidden") SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} -fPIC -Wall" ) IF("${_TV_PRODUCT}" STREQUAL "TRUE") SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} -DTV_PRODUCT") ENDIF() -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS}") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS} -fPIC -std=c++11 -fvisibility=hidden") SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS} ) diff --git a/plugins/wakeup-manager/inc/wakeup_interfaces.h b/plugins/wakeup-manager/inc/wakeup_interfaces.h new file mode 100644 index 0000000..c50e63d --- /dev/null +++ b/plugins/wakeup-manager/inc/wakeup_interfaces.h @@ -0,0 +1,35 @@ +/* + * 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. + */ + +#ifndef _WAKEUP_INTERFACES_H_ +#define _WAKEUP_INTERFACES_H_ + +typedef struct { + const char *wakeup_appid; + const char *wakeup_word; + const char *wakeup_language; + const char *wakeup_voice_id; + float wakeup_confidence_score; + + long wakeup_start_time; + long wakeup_end_time; + + const void *extra_data; + int extra_data_length; + const char *extra_data_description; +} wakeup_event_info; + +#endif /* _WAKEUP_INTERFACES_H_ */ \ No newline at end of file diff --git a/plugins/wakeup-manager/inc/wakeup_manager.h b/plugins/wakeup-manager/inc/wakeup_manager.h index a79a335..6350933 100644 --- a/plugins/wakeup-manager/inc/wakeup_manager.h +++ b/plugins/wakeup-manager/inc/wakeup_manager.h @@ -15,48 +15,46 @@ */ -#ifndef _MULTI_WAKEUP_RECOGNIZER_H_ -#define _MULTI_WAKEUP_RECOGNIZER_H_ +#ifndef _WAKEUP_MANAGER_H_ +#define _WAKEUP_MANAGER_H_ #include #include #include +#include "wakeup_interfaces.h" + #ifdef __cplusplus extern "C" { #endif -#if defined _WIN32 || defined __CYGWIN__ - #ifdef BUILDING_DLL - #ifdef __GNUC__ - #define DLL_PUBLIC __attribute__ ((dllexport)) - #else - #define DLL_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. - #endif - #else - #ifdef __GNUC__ - #define DLL_PUBLIC __attribute__ ((dllimport)) - #else - #define DLL_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax. - #endif - #endif - #define DLL_LOCAL -#else - #if __GNUC__ >= 4 - #define DLL_PUBLIC __attribute__ ((visibility ("default"))) - #define DLL_LOCAL __attribute__ ((visibility ("hidden"))) - #else - #define DLL_PUBLIC - #define DLL_LOCAL - #endif +#ifndef EXPORT_API + #if defined _WIN32 || defined __CYGWIN__ + #ifdef BUILDING_DLL + #ifdef __GNUC__ + #define EXPORT_API __attribute__ ((dllexport)) + #else + #define EXPORT_API __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. + #endif + #else + #ifdef __GNUC__ + #define EXPORT_API __attribute__ ((dllimport)) + #else + #define EXPORT_API __declspec(dllimport) // Note: actually gcc seems to also supports this syntax. + #endif + #endif + #define DLL_LOCAL + #else + #if __GNUC__ >= 4 + #define EXPORT_API __attribute__ ((visibility ("default"))) + #define DLL_LOCAL __attribute__ ((visibility ("hidden"))) + #else + #define EXPORT_API + #define DLL_LOCAL + #endif + #endif #endif -typedef enum { - WAKEUP_EVENT_ERROR = -1, /**< Event when the wakeup recognition has failed */ - WAKEUP_EVENT_SUCCESS = 1, /**< Event when the wakeup word is matched succesfully */ - WAKEUP_EVENT_REJECTED = 2 /**< Event when the wakeup word is not matched */ -} wakeup_service_wakeup_event_e; - typedef enum { WAKEUP_SPEECH_STREAMING_EVENT_FAIL = -1, /**< Failed */ WAKEUP_SPEECH_STREAMING_EVENT_START = 1, /**< Start event */ @@ -78,7 +76,7 @@ typedef enum { WAKEUP_MANAGER_STATE_VOICE_FEEDBACK = 4 } wakeup_manager_state_e; -typedef void (*wakeup_service_wakeup_event_cb)(wakeup_service_wakeup_event_e event, const char* wakeup_word, void* user_data); +typedef void (*wakeup_service_wakeup_event_cb)(wakeup_event_info info, void* user_data); typedef void (*wakeup_service_speech_streaming_cb)(wakeup_service_speech_streaming_event_e event, void* buffer, int len, void *user_data); @@ -88,51 +86,57 @@ typedef void (*wakeup_service_error_cb)(int error, const char* err_msg, void* us typedef void (*wakeup_service_audio_data_require_status_cb)(bool require, void* user_data); -DLL_PUBLIC int wakeup_manager_initialize(void); +EXPORT_API int wakeup_manager_initialize(void); + +EXPORT_API int wakeup_manager_deinitialize(void); + +EXPORT_API int wakeup_manager_add_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); -DLL_PUBLIC int wakeup_manager_deinitialize(void); +EXPORT_API int wakeup_manager_set_assistant_wakeup_engine(const char* appid, const char *engine); -DLL_PUBLIC int wakeup_manager_set_wakeup_word(const char* language, const char* wakeup_word); +EXPORT_API int wakeup_manager_set_assistant_enabled(const char* appid, int enabled); -DLL_PUBLIC int wakeup_manager_set_language(const char* language); +EXPORT_API int wakeup_manager_set_language(const char* language); -DLL_PUBLIC int wakeup_manager_activate(void); +EXPORT_API int wakeup_manager_activate(void); -DLL_PUBLIC int wakeup_manager_deactivate(void); +EXPORT_API int wakeup_manager_deactivate(void); -DLL_PUBLIC int wakeup_manager_update_voice_feedback_state(const char *appid, int state); +EXPORT_API int wakeup_manager_update_voice_feedback_state(const char *appid, int state); -DLL_PUBLIC int wakeup_manager_send_assistant_specific_command(const char* appid, const char* command); +EXPORT_API int wakeup_manager_send_assistant_specific_command(const char* appid, const char* command); -DLL_PUBLIC int wakeup_manager_update_result_state(const char *appid, int state); +EXPORT_API int wakeup_manager_update_result_state(const char *appid, int state); -DLL_PUBLIC int wakeup_manager_process_event(int event, void* data, int len); +EXPORT_API int wakeup_manager_process_event(int event, void* data, int len); -DLL_PUBLIC int wakeup_manager_start_streaming_utterance_data(void); +EXPORT_API int wakeup_manager_start_streaming_utterance_data(void); -DLL_PUBLIC int wakeup_manager_stop_streaming_utterance_data(void); +EXPORT_API int wakeup_manager_stop_streaming_utterance_data(void); -DLL_PUBLIC int wakeup_manager_start_streaming_previous_utterance_data(void); +EXPORT_API int wakeup_manager_start_streaming_previous_utterance_data(void); -DLL_PUBLIC int wakeup_manager_stop_streaming_previous_utterance_data(void); +EXPORT_API int wakeup_manager_stop_streaming_previous_utterance_data(void); -DLL_PUBLIC int wakeup_manager_start_streaming_follow_up_data(void); +EXPORT_API int wakeup_manager_start_streaming_follow_up_data(void); -DLL_PUBLIC int wakeup_manager_stop_streaming_follow_up_data(void); +EXPORT_API int wakeup_manager_stop_streaming_follow_up_data(void); -DLL_PUBLIC int wakeup_manager_get_audio_format(int *rate, int *channel, int *audio_type); +EXPORT_API int wakeup_manager_get_audio_format(int *rate, int *channel, int *audio_type); -DLL_PUBLIC int wakeup_manager_set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data); +EXPORT_API int wakeup_manager_set_wakeup_event_callback(wakeup_service_wakeup_event_cb callback, void* user_data); -DLL_PUBLIC int wakeup_manager_set_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data); +EXPORT_API int wakeup_manager_set_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data); -DLL_PUBLIC int wakeup_manager_set_previous_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data); +EXPORT_API int wakeup_manager_set_previous_utterance_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data); -DLL_PUBLIC int wakeup_manager_set_follow_up_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data); +EXPORT_API int wakeup_manager_set_follow_up_streaming_callback(wakeup_service_speech_streaming_cb callback, void* user_data); -DLL_PUBLIC int wakeup_manager_set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data); +EXPORT_API int wakeup_manager_set_speech_status_callback(wakeup_service_speech_status_cb callback, void* user_data); -DLL_PUBLIC int wakeup_manager_set_error_callback(wakeup_service_error_cb callback, void* user_data); +EXPORT_API int wakeup_manager_set_error_callback(wakeup_service_error_cb callback, void* user_data); /************************************************************************************** *** Definitions for wakeup engine interface @@ -158,8 +162,10 @@ typedef int (*wakeup_engine_deinitialize)(void); typedef int (*wakeup_engine_activate)(void); #define MA_WAKEUP_ENGINE_FUNC_DEACTIVATE "wakeup_engine_deactivate" typedef int (*wakeup_engine_deactivate)(void); -#define MA_WAKEUP_ENGINE_FUNC_SET_WAKEUP_WORD "wakeup_engine_set_wakeup_word" -typedef int (*wakeup_engine_set_wakeup_word)(const char* language, const char* wakeup_word); +#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_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" typedef int (*wakeup_engine_set_language)(const char* language); #define MA_WAKEUP_ENGINE_FUNC_UPDATE_MANAGER_STATE "wakeup_engine_update_manager_state" @@ -190,7 +196,8 @@ typedef struct { wakeup_engine_deinitialize deinitialize; wakeup_engine_activate activate; wakeup_engine_deactivate deactivate; - wakeup_engine_set_wakeup_word set_wakeup_word; + wakeup_engine_add_wakeup_word add_wakeup_word; + wakeup_engine_add_language add_language; wakeup_engine_set_language set_language; wakeup_engine_update_manager_state update_manager_state; wakeup_engine_set_audio_format set_audio_format; @@ -209,4 +216,4 @@ typedef struct { } #endif -#endif /* _MULTI_WAKEUP_RECOGNIZER_H_ */ +#endif /* _WAKEUP_MANAGER_H_ */ diff --git a/plugins/wakeup-manager/inc/wakeup_manager_audio.h b/plugins/wakeup-manager/inc/wakeup_manager_audio.h new file mode 100644 index 0000000..6516e73 --- /dev/null +++ b/plugins/wakeup-manager/inc/wakeup_manager_audio.h @@ -0,0 +1,24 @@ +/* + * 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. + */ + + +#ifndef _WAKEUP_MANAGER_AUDIO_H_ +#define _WAKEUP_MANAGER_AUDIO_H_ + +int wakeup_manager_audio_initialize(void); +int wakeup_manager_audio_deinitialize(void); + +#endif /* _WAKEUP_MANAGER_AUDIO_H_ */ diff --git a/plugins/wakeup-manager/inc/wakeup_policy.h b/plugins/wakeup-manager/inc/wakeup_policy.h new file mode 100644 index 0000000..b9ac87f --- /dev/null +++ b/plugins/wakeup-manager/inc/wakeup_policy.h @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#ifndef _WAKEUP_POLICY_H_ +#define _WAKEUP_POLICY_H_ + +#include +#include + +#include "wakeup_interfaces.h" + +class IWakeupEventObserver +{ +public: + virtual ~IWakeupEventObserver() {} + virtual void on_wakeup(wakeup_event_info info) = 0; +}; + +class CWakeupPolicyImpl; + +class CWakeupPolicy +{ +public: + CWakeupPolicy(); + virtual ~CWakeupPolicy(); + + CWakeupPolicy(const CWakeupPolicy&) = delete; + CWakeupPolicy& operator=(const CWakeupPolicy&) = delete; + + void subscribe(IWakeupEventObserver *observer); + void unsubscribe(IWakeupEventObserver *observer); + + virtual void wakeup_candidate(wakeup_event_info info) = 0; +protected: + std::unique_ptr mImpl; +}; + +#endif /* _WAKEUP_POLICY_H_ */ diff --git a/plugins/wakeup-manager/inc/wakeup_policy_default.h b/plugins/wakeup-manager/inc/wakeup_policy_default.h new file mode 100644 index 0000000..6b0a092 --- /dev/null +++ b/plugins/wakeup-manager/inc/wakeup_policy_default.h @@ -0,0 +1,51 @@ +/* + * 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. + */ + +#ifndef _WAKEUP_POLICY_DEFAULT_H_ +#define _WAKEUP_POLICY_DEFAULT_H_ + +#include "wakeup_policy.h" + +#include +#include + +#include + +class CWakeupPolicyDefault : public CWakeupPolicy +{ +public: + CWakeupPolicyDefault(); + ~CWakeupPolicyDefault(); + + void set_assistant_priority(std::string appid, int priority); + void set_delay(float seconds); + + void wakeup_candidate(wakeup_event_info info); + void timer_expired(); +private: + typedef struct { + std::string appid; + int priority{0}; + } PRIORITY_INFO; + + float mDelaySeconds{0.0f}; + std::vector mPriorityInfos; + std::vector mWakeupInfos; + + Ecore_Timer *mTimer{nullptr}; +}; + +#endif /* _WAKEUP_POLICY_H_ */ diff --git a/plugins/wakeup-manager/inc/wakeup_policy_impl.h b/plugins/wakeup-manager/inc/wakeup_policy_impl.h new file mode 100644 index 0000000..dc57aff --- /dev/null +++ b/plugins/wakeup-manager/inc/wakeup_policy_impl.h @@ -0,0 +1,38 @@ +/* + * 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. + */ + +#ifndef _WAKEUP_POLICY_IMPL_H_ +#define _WAKEUP_POLICY_IMPL_H_ + +#include "wakeup_policy.h" +#include +#include + +class CWakeupPolicyImpl +{ +public: + CWakeupPolicyImpl() {} + ~CWakeupPolicyImpl() {} + + void subscribe(IWakeupEventObserver *observer); + void unsubscribe(IWakeupEventObserver *observer); + + void wakeup(wakeup_event_info info); +private: + std::vector mObservers; +}; + +#endif /* _WAKEUP_POLICY_IMPL_H_ */ diff --git a/plugins/wakeup-manager/src/wakeup_manager.cpp b/plugins/wakeup-manager/src/wakeup_manager.cpp index e9ec931..8ba4dc4 100644 --- a/plugins/wakeup-manager/src/wakeup_manager.cpp +++ b/plugins/wakeup-manager/src/wakeup_manager.cpp @@ -13,25 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include -#include #include #include +#include #include #include #include +#include +#include #include #include - -#include "ctype.h" +#include #include "wakeup_manager_main.h" #include "wakeup_manager.h" - -#define RECOGNITION_TYPE_FREE_PARTIAL "stt.recognition.type.FREE.PARTIAL" +#include "wakeup_manager_audio.h" +#include "wakeup_policy_default.h" static wakeup_service_wakeup_event_cb g_wakeup_event_cb; static void* g_wakeup_event_user_data; @@ -60,17 +60,18 @@ static int g_engine_count = 0; #endif typedef struct { - bool active; - bool enabled; - bool audio_data_require_status; + bool active{false}; + bool enabled{false}; + bool audio_data_require_status{false}; char engine_name[_POSIX_PATH_MAX]; char engine_path[_POSIX_PATH_MAX]; - wakeup_engine_interface interface; + wakeup_engine_interface interface{nullptr, }; + std::vector assistant_list; } wakeup_engine_info; //static int g_wakeup_engine_selected = -1; static int g_wakeup_engine_selected = 0; -static wakeup_engine_info g_wakeup_engine_info[MAX_WAKEUP_ENGINE_NUM] = { NULL, }; +static wakeup_engine_info g_wakeup_engine_info[MAX_WAKEUP_ENGINE_NUM]; static char* g_current_language = NULL; static wakeup_manager_state_e g_wakeup_manager_state; @@ -88,6 +89,36 @@ static std::atomic_bool g_speech_data_thread_should_stop; static bool g_voice_key_pressed = false; static std::vector g_speech_data; +#define DEFAULT_ASSISTANT_APPID "com.samsung.bixby-voice" + +#define WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID "db/multi-assistant/default_assistant_appid" +#define WAKEUP_SETTINGS_KEY_UI_PANEL_ENABLED "db/multi-assistant/ui_panel_enabled" +#define WAKEUP_SETTINGS_KEY_CONVERSATION_TIMEOUT "db/multi-assistant/conversation_timeout" +#define WAKEUP_SETTINGS_KEY_MULTIPLE_MODE "db/multi-assistant/multiple_mode" +#define WAKEUP_SETTINGS_KEY_ENABLED_ASSISTANTS "db/multi-assistant/enabled_assistants" +#define WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_DELAY "db/multi-assistant/wakeup_policy_delay" +#define WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_PRIORITY "db/multi-assistant/wakeup_policy_priority" + +typedef struct { + std::string default_assistant_appid{DEFAULT_ASSISTANT_APPID}; + bool ui_panel_enabled{true}; + float conversation_timeout{5.0}; + bool multiple_mode{true}; + std::vector enabled_assistants{DEFAULT_ASSISTANT_APPID}; + float wakeup_policy_delay{0.1}; + std::vector wakeup_policy_priority; // No priority by default +} wakeup_settings; + +static wakeup_settings g_wakeup_settings; + +class CWakeupEventObserver : public IWakeupEventObserver +{ +public: + void on_wakeup(wakeup_event_info info) override; +}; +static std::unique_ptr g_wakeup_policy; +static CWakeupEventObserver g_wakeup_event_observer; + #ifdef TV_BT_MODE #define EFL_BETA_API_SUPPORT @@ -239,7 +270,7 @@ static void _bt_hid_audio_data_receive_cb(bt_hid_voice_data_s *voice_data, void } #endif -static int recorder_initialize() +static int recorder_initialize(void) { const int rate = 16000; const audio_channel_e channel = AUDIO_CHANNEL_MONO; @@ -394,7 +425,7 @@ static void recorder_thread_func() } } -static void wakeup_engine_wakeup_event_cb(wakeup_service_wakeup_event_e event, const char* wakeup_word, void* user_data) +static void wakeup_engine_wakeup_event_cb(wakeup_event_info info, void* user_data) { MWR_LOGD("[ENTER]"); if (NULL == user_data) return; @@ -403,7 +434,10 @@ static void wakeup_engine_wakeup_event_cb(wakeup_service_wakeup_event_e event, c if (NULL != g_wakeup_engine_info[loop].engine_name && strncmp(g_wakeup_engine_info[loop].engine_name, (const char*)user_data, _POSIX_PATH_MAX) == 0) { - g_wakeup_event_cb(event, wakeup_word, g_wakeup_event_user_data); + if (g_wakeup_policy) { + g_wakeup_policy->wakeup_candidate(info); + } + //g_wakeup_event_cb(event, g_wakeup_event_user_data); } } } @@ -571,9 +605,12 @@ static void wakeup_engine_add_directory(const char* name, const char* path) g_wakeup_engine_info[g_engine_count].interface.deactivate = (wakeup_engine_deactivate)dlsym(handle, MA_WAKEUP_ENGINE_FUNC_DEACTIVATE); - g_wakeup_engine_info[g_engine_count].interface.set_wakeup_word = - (wakeup_engine_set_wakeup_word)dlsym(handle, - MA_WAKEUP_ENGINE_FUNC_SET_WAKEUP_WORD); + g_wakeup_engine_info[g_engine_count].interface.add_wakeup_word = + (wakeup_engine_add_wakeup_word)dlsym(handle, + MA_WAKEUP_ENGINE_FUNC_ADD_WAKEUP_WORD); + g_wakeup_engine_info[g_engine_count].interface.add_language = + (wakeup_engine_add_language)dlsym(handle, + MA_WAKEUP_ENGINE_FUNC_ADD_LANGUAGE); g_wakeup_engine_info[g_engine_count].interface.set_language = (wakeup_engine_set_language)dlsym(handle, MA_WAKEUP_ENGINE_FUNC_SET_LANGUAGE); @@ -684,6 +721,32 @@ static int wakeup_engine_info_initialize() return 0; } +void CWakeupEventObserver::on_wakeup(wakeup_event_info info) +{ + g_wakeup_event_cb(info, g_wakeup_event_user_data); +} + +void wakeup_policy_initialize(void) +{ + g_wakeup_policy.reset(new CWakeupPolicyDefault); + if (g_wakeup_policy) { + g_wakeup_policy->subscribe(&g_wakeup_event_observer); + } + + /* Default Policy specific initialization */ + CWakeupPolicyDefault *default_policy = dynamic_cast(g_wakeup_policy.get()); + if (default_policy) { + int priority = 0; + + default_policy->set_delay(g_wakeup_settings.wakeup_policy_delay); + MWR_LOGD("Setting Delay : %f", g_wakeup_settings.wakeup_policy_delay); + for (const auto& assistant : g_wakeup_settings.wakeup_policy_priority) { + default_policy->set_assistant_priority(assistant, ++priority); + MWR_LOGD("Setting Priority : %d %s", priority, assistant.c_str()); + } + } +} + int wakeup_manager_initialize(void) { MWR_LOGD("[ENTER]"); @@ -705,6 +768,65 @@ int wakeup_manager_initialize(void) g_engine_count = 0; + int vconf_ret; + char *vconf_str; + int vconf_bool; + double vconf_double; + + vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_DEFAULT_ASSISTANT_APPID); + if (vconf_str) { + g_wakeup_settings.default_assistant_appid = vconf_str; + MWR_LOGD("default_assistant_appid : %s", g_wakeup_settings.default_assistant_appid.c_str()); + free(vconf_str); + vconf_str = nullptr; + } + vconf_ret = vconf_get_bool(WAKEUP_SETTINGS_KEY_UI_PANEL_ENABLED, &vconf_bool); + if (0 == vconf_ret) { + g_wakeup_settings.ui_panel_enabled = vconf_bool; + MWR_LOGD("ui_panel_enabled : %s", (g_wakeup_settings.ui_panel_enabled ? "true" : "false")); + } + vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_CONVERSATION_TIMEOUT, &vconf_double); + if (0 == vconf_ret) { + g_wakeup_settings.conversation_timeout = vconf_double; + MWR_LOGD("conversation_timeout : %f", g_wakeup_settings.conversation_timeout); + } + vconf_ret = vconf_get_bool(WAKEUP_SETTINGS_KEY_MULTIPLE_MODE, &vconf_bool); + if (0 == vconf_ret) { + g_wakeup_settings.multiple_mode = vconf_bool; + MWR_LOGD("multiple_mode : %s", (g_wakeup_settings.multiple_mode ? "true" : "false")); + } + vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_ENABLED_ASSISTANTS); + if (vconf_str) { + std::string token; + std::istringstream iss(vconf_str); + g_wakeup_settings.enabled_assistants.clear(); + while (std::getline(iss, token, ';')) { + g_wakeup_settings.enabled_assistants.push_back(token); + MWR_LOGD("enabled_assistants : %s", token.c_str()); + } + free(vconf_str); + vconf_str = nullptr; + } + vconf_ret = vconf_get_dbl(WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_DELAY, &vconf_double); + if (0 == vconf_ret) { + g_wakeup_settings.wakeup_policy_delay = vconf_double; + MWR_LOGD("conversation_timeout : %f", g_wakeup_settings.wakeup_policy_delay); + } + vconf_str = vconf_get_str(WAKEUP_SETTINGS_KEY_WAKEUP_POLICY_PRIORITY); + if (vconf_str) { + std::string token; + std::istringstream iss(vconf_str); + g_wakeup_settings.wakeup_policy_priority.clear(); + while (std::getline(iss, token, ';')) { + g_wakeup_settings.wakeup_policy_priority.push_back(token); + MWR_LOGD("wakeup_policy_priority : %s", token.c_str()); + } + free(vconf_str); + vconf_str = nullptr; + } + + wakeup_policy_initialize(); + recorder_initialize(); wakeup_engine_info_initialize(); @@ -746,12 +868,39 @@ static int _is_valid_language(const char* language, bool* is_valid) return 0; } -int wakeup_manager_set_wakeup_word(const char* language, const char* wakeup_word) +int wakeup_manager_add_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; + } + + MWR_LOGD("[DEBUG] appid(%s), wakeup word(%s),language(%s)", appid, wakeup_word, language); + for (int loop = 0;loop < g_engine_count;loop++) { + auto iter = std::find( + g_wakeup_engine_info[loop].assistant_list.begin(), + g_wakeup_engine_info[loop].assistant_list.end(), + std::string{appid}); + if (iter != g_wakeup_engine_info[loop].assistant_list.end()) { + if (g_wakeup_engine_info[loop].interface.add_wakeup_word) { + g_wakeup_engine_info[loop].interface.add_wakeup_word( + appid, wakeup_word, language); + } + } + } + + MWR_LOGD("[END]"); + return 0; +} + +int wakeup_manager_add_assistant_language(const char* appid, const char* language) { MWR_LOGD("[ENTER]"); - if (NULL == language || NULL == wakeup_word) { - MWR_LOGD("[ERROR] Parameter is invalid, language(%s), wakeup_word(%s)", language, wakeup_word); + if (NULL == appid || NULL == language) { + MWR_LOGD("[ERROR] Parameter is invalid, appid(%s), language(%s)", appid, language); return -1; } @@ -766,12 +915,41 @@ int wakeup_manager_set_wakeup_word(const char* language, const char* wakeup_word return -1; } - MWR_LOGD("[DEBUG] language(%s), wakeup word(%s)", language, wakeup_word); + MWR_LOGD("[DEBUG] language(%s)", language); MWR_LOGD("[END]"); return 0; } +int wakeup_manager_set_assistant_wakeup_engine(const char* appid, const char* engine) +{ + MWR_LOGD("[ENTER]"); + + if (NULL == appid || NULL == engine) { + MWR_LOGD("[ERROR] Parameter is invalid, appid(%s), wakeup engine(%s)", appid, engine); + return -1; + } + + MWR_LOGD("[DEBUG] appid(%s), wakeup engine(%s)", appid, engine); + for (int loop = 0;loop < g_engine_count;loop++) { + if (0 == strncmp(g_wakeup_engine_info[loop].engine_name, engine, _POSIX_PATH_MAX)) { + g_wakeup_engine_info[loop].assistant_list.push_back(std::string{appid}); + } + } + + MWR_LOGD("[END]"); + return 0; +} + +int wakeup_manager_set_assistant_enabled(const char* appid, int enabbled) +{ + MWR_LOGD("[ENTER]"); + + MWR_LOGD("[END]"); + + return 0; +} + int wakeup_manager_set_language(const char* language) { MWR_LOGD("[ENTER]"); @@ -928,8 +1106,10 @@ int wakeup_manager_process_event(int event, void* data, int len) for (int loop = 0;loop < g_engine_count;loop++) { /* Need to find the default assistant, for now assuming 0 is the one */ if(loop == 0) { - g_wakeup_event_cb(WAKEUP_EVENT_SUCCESS, - "hi bixby", g_wakeup_event_user_data); + wakeup_event_info event; + event.wakeup_word = "hi bixby"; + event.wakeup_appid = g_wakeup_engine_info[loop].assistant_list.at(0).c_str(); + g_wakeup_event_cb(event, g_wakeup_event_user_data); } } } diff --git a/plugins/wakeup-manager/src/wakeup_manager_audio.cpp b/plugins/wakeup-manager/src/wakeup_manager_audio.cpp new file mode 100644 index 0000000..08ce1ca --- /dev/null +++ b/plugins/wakeup-manager/src/wakeup_manager_audio.cpp @@ -0,0 +1,3 @@ +#include "wakeup_manager_audio.h" +#include "wakeup_manager_main.h" + diff --git a/plugins/wakeup-manager/src/wakeup_policy.cpp b/plugins/wakeup-manager/src/wakeup_policy.cpp new file mode 100644 index 0000000..73110c2 --- /dev/null +++ b/plugins/wakeup-manager/src/wakeup_policy.cpp @@ -0,0 +1,46 @@ +#include "wakeup_policy.h" +#include "wakeup_policy_impl.h" + +#include +#include + +void CWakeupPolicyImpl::subscribe(IWakeupEventObserver *observer) +{ + mObservers.push_back(observer); +} + +void CWakeupPolicyImpl::unsubscribe(IWakeupEventObserver *observer) +{ + auto iter = std::find(mObservers.begin(), mObservers.end(), observer); + if (iter != mObservers.end()) { + mObservers.erase(iter); + } +} + +void CWakeupPolicyImpl::wakeup(wakeup_event_info info) +{ + for (const auto& observer : mObservers) { + if (observer) { + observer->on_wakeup(info); + } + } +} + +CWakeupPolicy::CWakeupPolicy() +{ + mImpl.reset(new CWakeupPolicyImpl); +} + +CWakeupPolicy::~CWakeupPolicy() +{ +} + +void CWakeupPolicy::subscribe(IWakeupEventObserver *observer) +{ + if (mImpl) mImpl->subscribe(observer); +} + +void CWakeupPolicy::unsubscribe(IWakeupEventObserver *observer) +{ + if (mImpl) mImpl->unsubscribe(observer); +} diff --git a/plugins/wakeup-manager/src/wakeup_policy_default.cpp b/plugins/wakeup-manager/src/wakeup_policy_default.cpp new file mode 100644 index 0000000..48a6e2e --- /dev/null +++ b/plugins/wakeup-manager/src/wakeup_policy_default.cpp @@ -0,0 +1,93 @@ +#include "wakeup_policy_default.h" +#include "wakeup_policy_impl.h" + +#include + +#include +#include + +#ifndef LOG_TAG +#define LOG_TAG "WakeupPolicyDefault" +#endif + +CWakeupPolicyDefault::CWakeupPolicyDefault() +{ +} + +CWakeupPolicyDefault::~CWakeupPolicyDefault() +{ + if (mTimer) { + ecore_timer_del(mTimer); + mTimer = nullptr; + } +} + +void CWakeupPolicyDefault::set_assistant_priority(std::string appid, int priority) +{ + PRIORITY_INFO info; + info.appid = appid; + info.priority = priority; + + LOGD("Setting assistant priority : %s %d", appid.c_str(), priority); + mPriorityInfos.push_back(info); +} + +void CWakeupPolicyDefault::set_delay(float seconds) +{ + LOGD("Setting delay : %f", seconds); + mDelaySeconds = seconds; +} + +static Eina_Bool timer_func(void *data) +{ + LOGD("[ENTER]"); + if (data) { + CWakeupPolicyDefault *policy = static_cast(data); + policy->timer_expired(); + } + return ECORE_CALLBACK_CANCEL; +} + +void CWakeupPolicyDefault::wakeup_candidate(wakeup_event_info info) +{ + for (const auto &assistant : mPriorityInfos) { + if (info.wakeup_appid && + 0 == assistant.appid.compare(info.wakeup_appid)) { + mWakeupInfos.push_back(info); + if (nullptr == mTimer) { + ecore_thread_main_loop_begin(); + mTimer = ecore_timer_add(mDelaySeconds, timer_func, this); + ecore_thread_main_loop_end(); + } + } + } +} + +void CWakeupPolicyDefault::timer_expired() +{ + LOGD("[ENTER]"); + if (0 == mWakeupInfos.size()) return; + + wakeup_event_info selected = mWakeupInfos.front(); + int selected_priority = -1; + for (const auto &wakeup : mWakeupInfos) { + for (const auto &info : mPriorityInfos) { + if (0 == info.appid.compare(wakeup.wakeup_appid)) { + if (info.priority > selected_priority || -1 == selected_priority) { + LOGD("Wakeup with higher priority found : %s, %d", + info.appid.c_str(), info.priority); + selected = wakeup; + selected_priority = info.priority; + } + } + } + } + if (mImpl) mImpl->wakeup(selected); + mWakeupInfos.clear(); + + if (mTimer) { + LOGD("Now deleting timer"); + ecore_timer_del(mTimer); + mTimer = nullptr; + } +} diff --git a/src/multi_assistant_config.c b/src/multi_assistant_config.c index c32b2fc..1c3f9ab 100644 --- a/src/multi_assistant_config.c +++ b/src/multi_assistant_config.c @@ -80,6 +80,7 @@ int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const temp->cnt_wakeup = 0; memset(temp->supported_lang, 0x00, sizeof(temp->supported_lang)); temp->cnt_lang = 0; + temp->wakeup_engine = NULL; while (cur != NULL) { if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar *)MA_TAG_ASSISTANT_LANGUAGE_SET)) { @@ -117,7 +118,7 @@ int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const MAS_LOGD("Name : %s", key); xmlFree(key); } - } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_ID)) { + } 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); @@ -131,6 +132,13 @@ int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const MAS_LOGD("Icon Path : %s", key); xmlFree(key); } + } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_WAKEUP_ENGINE_APPID)) { + key = xmlNodeGetContent(cur); + if (key) { + temp->wakeup_engine = strdup((const char*)key); + MAS_LOGD("Wakeup Engine : %s", key); + xmlFree(key); + } } cur = cur->next; @@ -138,7 +146,8 @@ 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->cnt_wakeup, temp->supported_lang, temp->cnt_lang, user_data); + temp->wakeup_list, temp->cnt_wakeup, temp->supported_lang, + temp->cnt_lang, temp->wakeup_engine, user_data); } if (temp->app_id) { @@ -160,6 +169,9 @@ int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const free((void*)(temp->supported_lang[loop])); } } + if (temp->wakeup_engine) { + free((void*)temp->wakeup_engine); + } free(temp); xmlFreeDoc(doc); diff --git a/src/multi_assistant_service.c b/src/multi_assistant_service.c index f4af1f6..e92bf48 100644 --- a/src/multi_assistant_service.c +++ b/src/multi_assistant_service.c @@ -44,6 +44,7 @@ typedef struct { Eina_Bool used; char appid[MAX_APPID_LEN]; char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN]; + char wakeup_engine[MAX_APPID_LEN]; } ma_client_info; static ma_client_info g_maclient_info[MAX_MACLIENT_INFO_NUM]; @@ -409,7 +410,8 @@ int mas_ui_client_change_assistant(const char* appid) int __mas_assistant_info_cb(const char* appid, const char* name, const char* icon_path, const char* wakeup_list[], int cnt_wakeup, - const char* supported_lang[], int cnt_lang, void* user_data) { + const char* supported_lang[], int cnt_lang, const char* wakeup_engine, + void* user_data) { MAS_LOGD("__mas_assistant_info_cb called"); if (NULL == appid) { @@ -440,6 +442,10 @@ int __mas_assistant_info_cb(const char* appid, const char* name, strncpy(g_maclient_info[index].wakeup_word[loop], "", MAX_WAKEUP_WORD_LEN); } } + + MAS_LOGD("wakeup_engine(%s)", wakeup_engine); + strncpy(g_maclient_info[index].wakeup_engine, wakeup_engine, MAX_APPID_LEN); + g_maclient_info[index].wakeup_engine[MAX_APPID_LEN - 1] = '\0'; } else { MAS_LOGD("Couldn't find an empty slot for storing assistant info"); } @@ -472,13 +478,19 @@ static int init_wakeup(void) for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) { if (g_maclient_info[loop].used && 0 < strlen(g_maclient_info[loop].appid)) { + if (g_maclient_info[loop].wakeup_engine) { + multi_assistant_service_plugin_set_assistant_wakeup_engine( + g_maclient_info[loop].appid, + g_maclient_info[loop].wakeup_engine); + } for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) { if (0 < strlen(g_maclient_info[loop].wakeup_word[inner_loop])) { MAS_LOGD("Registering wakeup word %s for app %s", g_maclient_info[loop].wakeup_word[inner_loop], g_maclient_info[loop].appid); - if (0 != multi_assistant_service_plugin_set_wakeup_word( - "en_US", g_maclient_info[loop].wakeup_word[inner_loop])) { - MAS_LOGE("Fail to stt wakeup word"); + if (0 != multi_assistant_service_plugin_add_assistant_wakeup_word( + g_maclient_info[loop].appid, + g_maclient_info[loop].wakeup_word[inner_loop], "en_US")) { + MAS_LOGE("Fail to add assistant's wakeup word"); } } } diff --git a/src/multi_assistant_service_plugin.c b/src/multi_assistant_service_plugin.c index 1762c84..f6ac2c1 100644 --- a/src/multi_assistant_service_plugin.c +++ b/src/multi_assistant_service_plugin.c @@ -126,9 +126,9 @@ Eina_Bool __launch_assistant_by_wakeup_word(void *data) return EINA_FALSE; } -static void __wakeup_event_cb(wakeup_service_wakeup_event_e event, const char* wakeup_word, void* user_data) +static void __wakeup_event_cb(wakeup_event_info event, void* user_data) { - MAS_LOGD("[SUCCESS] __wakeup_event_cb is called, event(%d), wakeup_word(%s)", event, wakeup_word); + MAS_LOGD("[SUCCESS] __wakeup_event_cb is called, wakeup_word(%s)", event.wakeup_word); int ret = -1; int retry_cnt = 0; while (0 != ret) { @@ -141,41 +141,39 @@ static void __wakeup_event_cb(wakeup_service_wakeup_event_e event, const char* w } #ifdef BUF_SAVE_MODE - if (WAKEUP_EVENT_SUCCESS == event) { - if (g_pFile) { - fclose(g_pFile); - g_pFile = NULL; - } else { - MAS_LOGD("[Recorder Info] File not found!"); - } + if (g_pFile) { + fclose(g_pFile); + g_pFile = NULL; + } else { + MAS_LOGD("[Recorder Info] File not found!"); + } - while (1) { - snprintf(g_temp_file_name, sizeof(g_temp_file_name), "/tmp/ma_service_%d_%d", getpid(), g_count); - int ret = access(g_temp_file_name, 0); - - if (0 == ret) { - MAS_LOGD("[Recorder ERROR] File is already exist"); - if (0 == remove(g_temp_file_name)) { - MAS_LOGD("[Recorder] Remove file"); - break; - } else { - g_count++; - } - } else { + while (1) { + snprintf(g_temp_file_name, sizeof(g_temp_file_name), "/tmp/ma_service_%d_%d", getpid(), g_count); + int ret = access(g_temp_file_name, 0); + + if (0 == ret) { + MAS_LOGD("[Recorder ERROR] File is already exist"); + if (0 == remove(g_temp_file_name)) { + MAS_LOGD("[Recorder] Remove file"); break; + } else { + g_count++; } + } else { + break; } + } - MAS_LOGD("[Recorder] Temp file name=[%s]", g_temp_file_name); + MAS_LOGD("[Recorder] Temp file name=[%s]", g_temp_file_name); - /* open test file */ - g_pFile = fopen(g_temp_file_name, "wb+x"); - if (!g_pFile) { - MAS_LOGD("[Recorder ERROR] File not found!"); - return; - } - g_count++; + /* open test file */ + g_pFile = fopen(g_temp_file_name, "wb+x"); + if (!g_pFile) { + MAS_LOGD("[Recorder ERROR] File not found!"); + return; } + g_count++; #endif #if 0 /* + TEST_CODE */ @@ -193,9 +191,9 @@ static void __wakeup_event_cb(wakeup_service_wakeup_event_e event, const char* w ecore_thread_main_loop_end(); } #endif /* - TEST_CODE */ - if (WAKEUP_EVENT_SUCCESS == event && wakeup_word) { + if (event.wakeup_word) { ecore_thread_main_loop_begin(); - ecore_timer_add(0.0f, __launch_assistant_by_wakeup_word, (void*)strdup(wakeup_word)); + ecore_timer_add(0.0f, __launch_assistant_by_wakeup_word, (void*)strdup(event.wakeup_word)); ecore_thread_main_loop_end(); } @@ -272,9 +270,18 @@ int multi_assistant_service_plugin_initialize(void) _wakeup_manager_interface.deinitialize = (wakeup_manager_deinitialize)dlsym(g_handle, MA_WAKEUP_MANAGER_FUNC_DEINITIALIZE); - _wakeup_manager_interface.set_wakeup_word = - (wakeup_manager_set_wakeup_word)dlsym(g_handle, - MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_WORD); + _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.add_assistant_language = + (wakeup_manager_add_assistant_language)dlsym(g_handle, + MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE); + _wakeup_manager_interface.set_assistant_wakeup_engine = + (wakeup_manager_set_assistant_wakeup_engine)dlsym(g_handle, + MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE); + _wakeup_manager_interface.set_assistant_enabled = + (wakeup_manager_set_assistant_enabled)dlsym(g_handle, + MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_ENABLED); _wakeup_manager_interface.set_language = (wakeup_manager_set_language)dlsym(g_handle, MA_WAKEUP_MANAGER_FUNC_SET_LANGUAGE); @@ -404,17 +411,74 @@ int multi_assistant_service_plugin_set_language(const char* language) return ret; } -int multi_assistant_service_plugin_set_wakeup_word(const char* language, const char* wakeup_word) +int multi_assistant_service_plugin_add_assistant_wakeup_word(const char* appid, const char* wakeup_word, const char* language) +{ + int ret = -1; + if (NULL != g_handle) { + wakeup_manager_add_assistant_wakeup_word func = _wakeup_manager_interface.add_assistant_wakeup_word; + if (NULL == func) { + MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_WAKEUP_WORD); + } else { + ret = func(appid, wakeup_word, language); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to set wakeup word(%s)(%s)(%s), ret(%d)", appid, wakeup_word, language, ret); + } + } + } else { + MAS_LOGE("[ERROR] g_handle is not valid"); + } + return ret; +} + +int multi_assistant_service_plugin_add_assistant_language(const char* appid, const char* language) +{ + int ret = -1; + if (NULL != g_handle) { + wakeup_manager_add_assistant_language func = _wakeup_manager_interface.add_assistant_language; + if (NULL == func) { + MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_ADD_ASSISTANT_LANGUAGE); + } else { + ret = func(appid, language); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to set wakeup word(%s)(%s), ret(%d)", appid, language, ret); + } + } + } else { + MAS_LOGE("[ERROR] g_handle is not valid"); + } + return ret; +} + +int multi_assistant_service_plugin_set_assistant_wakeup_engine(const char* appid, const char* engine) +{ + int ret = -1; + if (NULL != g_handle) { + wakeup_manager_set_assistant_wakeup_engine func = _wakeup_manager_interface.set_assistant_wakeup_engine; + if (NULL == func) { + MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_WAKEUP_ENGINE); + } else { + ret = func(appid, engine); + if (0 != ret) { + MAS_LOGE("[ERROR] Fail to set wakeup engine(%s)(%s), ret(%d)", appid, engine, ret); + } + } + } else { + MAS_LOGE("[ERROR] g_handle is not valid"); + } + return ret; +} + +int multi_assistant_service_plugin_set_assistant_enabled(const char* appid, int enabled) { int ret = -1; if (NULL != g_handle) { - wakeup_manager_set_wakeup_word func = _wakeup_manager_interface.set_wakeup_word; + wakeup_manager_set_assistant_enabled func = _wakeup_manager_interface.set_assistant_enabled; if (NULL == func) { - MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_WAKEUP_WORD); + MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_ENABLED); } else { - ret = func(language, wakeup_word); + ret = func(appid, enabled); if (0 != ret) { - MAS_LOGE("[ERROR] Fail to set wakeup word(%s)(%s), ret(%d)", language, wakeup_word, ret); + MAS_LOGE("[ERROR] Fail to set wakeup word(%s)(%d), ret(%d)", appid, enabled, ret); } } } else {