src/wakeup_settings.cpp
src/wakeup_policy.cpp
src/wakeup_policy_default.cpp
+ src/wakeup_policy_external.cpp
src/wakeup_audio_manager.cpp
src/wakeup_engine_manager.cpp
src/wakeup_manager_wrapper.cpp
extern "C" {
#endif
-int dependency_resolver_initialize(mas_dependency_plugin_proxy_interface interface);
-int dependency_resolver_deinitialize(void);
-int dependency_resolver_set_error_callback(mas_error_cb callback, void* user_data);
-int dependency_resolver_start_recording();
-int dependency_resolver_stop_recording();
-int dependency_resolver_set_recording_session(unsigned int);
-int dependency_resolver_set_background_volume(double ratio);
-int dependency_resolver_get_audio_format(int* rate, int* channel, int* audio_type);
-int dependency_resolver_get_audio_source_type(char** type);
-int dependency_resolver_process_wakeup_engine_command(const char* engine, const char* command);
-
/**************************************************************************************
*** Definitions for dependencies
*************************************************************************************/
typedef int (*mas_dependency_get_audio_source_type)(char** type);
#define MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_ENGINE_COMMAND "mas_dependency_process_wakeup_engine_command"
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);
typedef struct {
mas_dependency_initialize initialize;
mas_dependency_get_audio_format get_audio_format;
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_module_interface;
+int dependency_resolver_initialize(mas_dependency_plugin_proxy_interface interface);
+int dependency_resolver_deinitialize(void);
+int dependency_resolver_set_error_callback(mas_error_cb callback, void* user_data);
+int dependency_resolver_start_recording();
+int dependency_resolver_stop_recording();
+int dependency_resolver_set_recording_session(unsigned int);
+int dependency_resolver_set_background_volume(double ratio);
+int dependency_resolver_get_audio_format(int* rate, int* channel, int* audio_type);
+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);
+
+mas_dependency_module_interface* dependency_resolver_get_interface();
+
#ifdef __cplusplus
}
#endif
int wakeup_manager_send_dependency_module_command(const char* engine_name, const char* command);
+int wakeup_manager_wakeup_assistant(const mas_wakeup_event_info* wakeup_info);
+
#ifdef __cplusplus
}
#endif
CWakeupPolicy(const CWakeupPolicy&) = delete;
CWakeupPolicy& operator=(const CWakeupPolicy&) = delete;
+ virtual bool valid() = 0;
+
void subscribe(IPolicyEventObserver *observer);
void unsubscribe(IPolicyEventObserver *observer);
virtual void wakeup_candidate(mas_wakeup_event_info wakeup_info) = 0;
+ virtual void select_candidate(mas_wakeup_event_info wakeup_info) = 0;
protected:
unique_ptr<CWakeupPolicyImpl> mImpl;
};
class CWakeupPolicyDefault : public CWakeupPolicy
{
public:
- CWakeupPolicyDefault();
CWakeupPolicyDefault(IPolicyEventObserver *observer);
~CWakeupPolicyDefault();
+ bool valid() override;
+
void set_assistant_priority(string appid, int priority);
void set_delay(float seconds);
- void wakeup_candidate(mas_wakeup_event_info wakeup_info);
+ void wakeup_candidate(mas_wakeup_event_info wakeup_info) override;
+ void select_candidate(mas_wakeup_event_info wakeup_info) override;
+
void timer_expired();
private:
typedef struct {
--- /dev/null
+/*
+ * 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_EXTERNAL_H_
+#define _WAKEUP_POLICY_EXTERNAL_H_
+
+#include "wakeup_policy.h"
+
+namespace multiassistant
+{
+namespace wakeup
+{
+
+using namespace std;
+
+class CWakeupPolicyExternal : public CWakeupPolicy
+{
+public:
+ CWakeupPolicyExternal(IPolicyEventObserver *observer);
+ ~CWakeupPolicyExternal();
+
+ bool valid() override;
+
+ void wakeup_candidate(mas_wakeup_event_info wakeup_info) override;
+ void select_candidate(mas_wakeup_event_info wakeup_info) override;
+};
+
+} // wakeup
+} // multiassistant
+
+#endif /* _WAKEUP_POLICY_EXTERNAL_H_ */
static void *g_handle = NULL;
static mas_dependency_module_interface g_mas_dependency = { NULL, };
+mas_dependency_module_interface* dependency_resolver_get_interface()
+{
+ return &g_mas_dependency;
+}
+
int dependency_resolver_initialize(mas_dependency_plugin_proxy_interface interface)
{
MAS_LOGD("[Enter]");
g_mas_dependency.process_wakeup_engine_command =
(mas_dependency_process_wakeup_engine_command)dlsym(g_handle,
MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_ENGINE_COMMAND);
+ g_mas_dependency.process_wakeup_candidate =
+ (mas_dependency_process_wakeup_candidate)dlsym(g_handle,
+ MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_CANDIDATE);
int ret = -1;
int dependency_version = 0;
return ret;
}
+
+int dependency_resolver_process_wakeup_candidate(mas_wakeup_event_info* info)
+{
+ int ret = -1;
+ if (NULL != g_handle) {
+ mas_dependency_process_wakeup_candidate func = g_mas_dependency.process_wakeup_candidate;
+ if (NULL == func) {
+ MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_CANDIDATE);
+ } else {
+ try {
+ ret = func(info);
+ } catch (const std::exception& e) {
+ MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+ MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_CANDIDATE, e.what());
+ }
+ if (0 != ret) {
+ MAS_LOGE("[ERROR] Fail to process wakeup candidate, ret(%d)", ret);
+ }
+ }
+ } else {
+ MAS_LOGE("[ERROR] g_handle is not valid");
+ }
+
+ return ret;
+}
#include "wakeup_manager.h"
#include "wakeup_manager_main.h"
#include "wakeup_policy_default.h"
+#include "wakeup_policy_external.h"
#include "dependency_resolver.h"
#include <algorithm>
void CWakeupManager::initialize_wakeup_policy()
{
- mWakeupPolicy.reset(new CWakeupPolicyDefault{&mPolicyEventObserver});
-
- /* Default Policy specific initialization */
- CWakeupPolicyDefault *policy =
- dynamic_cast<CWakeupPolicyDefault*>(mWakeupPolicy.get());
- if (policy) {
- int priority = 0;
-
- policy->set_delay(mWakeupSettings.get_wakeup_policy_delay());
- MWR_LOGD("Setting Delay : %f", mWakeupSettings.get_wakeup_policy_delay());
- for (const auto& assistant : mWakeupSettings.get_wakeup_policy_priority()) {
- policy->set_assistant_priority(assistant, ++priority);
- MWR_LOGD("Setting Priority : %d %s", priority, assistant.c_str());
+ mWakeupPolicy.reset(new CWakeupPolicyExternal{&mPolicyEventObserver});
+ if (nullptr == mWakeupPolicy || !(mWakeupPolicy->valid())) {
+ mWakeupPolicy.reset(new CWakeupPolicyDefault{&mPolicyEventObserver});
+
+ /* Default Policy specific initialization */
+ CWakeupPolicyDefault *policy =
+ dynamic_cast<CWakeupPolicyDefault*>(mWakeupPolicy.get());
+ if (policy) {
+ int priority = 0;
+
+ policy->set_delay(mWakeupSettings.get_wakeup_policy_delay());
+ MWR_LOGD("Setting Delay : %f", mWakeupSettings.get_wakeup_policy_delay());
+ for (const auto& assistant : mWakeupSettings.get_wakeup_policy_priority()) {
+ policy->set_assistant_priority(assistant, ++priority);
+ MWR_LOGD("Setting Priority : %d %s", priority, assistant.c_str());
+ }
}
}
}
mAudioManager.subscribe(&mAudioEventObserver);
mAudioManager.initialize();
- initialize_wakeup_policy();
-
mWakeupEngineManager.subscribe(&mEngineEventObserver);
mWakeupEngineManager.initialize();
interface.process_event = wakeup_manager_process_event;
interface.feed_audio_data = wakeup_manager_feed_audio_data;
//interface.send_dependency_module_command = wakeup_manager_send_dependency_module_command;
+ interface.wakeup_assistant = wakeup_manager_wakeup_assistant;
dependency_resolver_initialize(interface);
+ initialize_wakeup_policy();
+
MWR_LOGD("[END]");
return true;
}
return 0;
}
+int wakeup_manager_wakeup_assistant(const mas_wakeup_event_info* wakeup_info)
+{
+ if (nullptr == g_wakeup_manager) return -1;
+ CWakeupPolicy* policy = g_wakeup_manager->get_wakeup_policy();
+ if (policy) policy->select_candidate(*wakeup_info);
+}
+
void CWakeupEventObserver::on_wakeup(mas_wakeup_event_info wakeup_info)
{
if (NULL != g_wakeup_event_cb) {
#include <Eina.h>
#include <dlog.h>
-#ifndef LOG_TAG
-#define LOG_TAG "WakeupPolicyDefault"
-#endif
-
namespace multiassistant
{
namespace wakeup
{
-CWakeupPolicyDefault::CWakeupPolicyDefault()
-{
-}
-
CWakeupPolicyDefault::CWakeupPolicyDefault(IPolicyEventObserver *observer)
: CWakeupPolicy(observer)
{
}
}
+bool CWakeupPolicyDefault::valid()
+{
+ return true;
+}
+
void CWakeupPolicyDefault::set_assistant_priority(string appid, int priority)
{
PRIORITY_INFO info;
}
}
+void CWakeupPolicyDefault::select_candidate(mas_wakeup_event_info wakeup_info)
+{
+ LOGE("Default wakeup policy does not support selecting candidate");
+}
+
void CWakeupPolicyDefault::timer_expired()
{
LOGD("[ENTER]");
--- /dev/null
+#include "wakeup_policy_external.h"
+#include "wakeup_policy_impl.h"
+
+#include "dependency_resolver.h"
+
+#include <dlog.h>
+
+#ifndef LOG_TAG
+#define LOG_TAG "WakeupPolicyExternal"
+#endif
+
+namespace multiassistant
+{
+namespace wakeup
+{
+
+CWakeupPolicyExternal::CWakeupPolicyExternal(IPolicyEventObserver *observer)
+ : CWakeupPolicy(observer)
+{
+}
+
+CWakeupPolicyExternal::~CWakeupPolicyExternal()
+{
+}
+
+bool CWakeupPolicyExternal::valid()
+{
+ bool ret = false;
+ mas_dependency_module_interface* interface = dependency_resolver_get_interface();
+ if (interface) {
+ if (interface->process_wakeup_candidate) {
+ ret = true;
+ }
+ }
+ return ret;
+}
+
+void CWakeupPolicyExternal::wakeup_candidate(mas_wakeup_event_info wakeup_info)
+{
+ dependency_resolver_process_wakeup_candidate(&wakeup_info);
+}
+
+void CWakeupPolicyExternal::select_candidate(mas_wakeup_event_info wakeup_info)
+{
+ if (mImpl) mImpl->wakeup(wakeup_info);
+}
+
+} // wakeup
+} // multiassistant