const char* name;
const char* icon_path;
const char* wakeup_list[MAX_WAKEUP_LIST_NUM];
+ const char* wakeup_language[MAX_WAKEUP_LIST_NUM];
int cnt_wakeup;
const char* supported_lang[MAX_SUPPORTED_LANGUAGE_NUM];
int cnt_lang;
bool custom_ui_option;
} 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, const char* wakeup_engine, bool custom_ui_option, void* user_data);
+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);
int mas_config_get_assistant_info(mas_config_assistant_info_cb callback, void* user_data);
#ifdef __cplusplus
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);
int multi_assistant_service_plugin_deactivate(void);
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"
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;
#include <string>
#include <thread>
#include <vector>
+#include <set>
namespace multiassistant
{
bool get_audio_data_required();
void set_selected_wakeup_info(wakeup_event_info info);
+ bool set_language(string language);
+ void set_assistant_activated(string appid, bool activated);
+
void start_streaming_current_utterance_data();
void stop_streaming_current_utterance_data();
private:
typedef struct {
string engine_name;
- bool active{false};
- bool enabled{false};
+ bool activated{false};
bool audio_data_require_status{false};
string engine_path;
wakeup_engine_interface interface{nullptr, };
vector<string> assistant_list;
+ set<string> activated_assistants;
void *engine_handle{nullptr};
} EngineInfo;
#include "wakeup_policy_default.h"
#include <memory>
+#include <map>
namespace multiassistant
{
bool add_assistant_language(string appid, string language);
bool add_assistant_wakeup_word(string appid, string wakeup_word, string language);
bool set_assistant_wakeup_engine(string appid, string engine);
- bool set_assistant_enabled(string appid, bool enabled);
bool update_voice_feedback_state(string appid, bool state);
bool send_assistant_specific_command(string appid, string command);
CWakeupManager *mWakeupManager{nullptr};
CWakeupEngineManager *mEngineManager{nullptr};
};
+
+ class CSettingsEventObserver : public ISettingsEventObserver
+ {
+ public:
+ bool on_voice_input_language_changed(const char* language) override;
+
+ void set_wakeup_manager(CWakeupManager *manager) { mWakeupManager = manager; }
+ private:
+ CWakeupManager *mWakeupManager{nullptr};
+ };
+
+ void initialize_wakeup_policy();
+
typedef struct {
string appid;
vector<string> languageList;
- } LanguageInfo;
-
- void initialize_wakeup_policy();
+ } AssistantLanguageInfo;
+ vector<AssistantLanguageInfo> mAssistantLanguageInfo;
+ map<string, bool> mAssistantActivated;
- vector<LanguageInfo> mLanguageInfo;
vector<IWakeupEventObserver*> mObservers;
unique_ptr<CWakeupPolicy> mWakeupPolicy;
CAudioEventObserver mAudioEventObserver;
CEngineEventObserver mEngineEventObserver;
CPolicyEventObserver mPolicyEventObserver;
+ CSettingsEventObserver mSettingsEventObserver;
thread mEngineDataThread;
atomic_bool mStopEngineDataThread{false};
EXPORT_API int wakeup_manager_set_assistant_wakeup_engine(const char* appid, const char *engine);
-EXPORT_API int wakeup_manager_set_assistant_enabled(const char* appid, int enabled);
-
EXPORT_API int wakeup_manager_set_language(const char* language);
EXPORT_API int wakeup_manager_activate(void);
#include <string>
#include <vector>
+#include <vconf.h>
+
+typedef void (*input_language_changed_cb)(void* data);
namespace multiassistant
{
#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"
#define WAKEUP_SETTINGS_KEY_STREAMING_DURATION_MAX "db/multi-assistant/streaming_duration_max"
+#define WAKEUP_SETTINGS_KEY_VOICE_INPUT_LANGUAGE "db/multi-assistant/voice_input_language"
+
+class ISettingsEventObserver
+{
+public:
+ virtual ~ISettingsEventObserver() = default;
+ virtual bool on_voice_input_language_changed(const char* language) = 0;
+};
class CWakeupSettings
{
void initialize();
void deinitialize();
+ void subscribe(ISettingsEventObserver *observer);
+ void unsubscribe(ISettingsEventObserver *observer);
+ vector<ISettingsEventObserver*> get_observers();
+
string get_default_assistant_appid();
bool get_ui_panel_enabled();
float get_conversation_timeout();
float get_wakeup_policy_delay();
vector<string> get_wakeup_policy_priority();
float get_streaming_duration_max();
- void set_assistant_enabled(string appid, bool enabled);
+ string get_current_language(void);
private:
+ vector<ISettingsEventObserver*> mObservers;
+
string mDefaultAssistantAppid{DEFAULT_ASSISTANT_APPID};
bool mUiPanelEnabled{true};
float mConversationTimeout{5.0};
template<class C, class T>
static auto contains(const C& v, const T& x) -> decltype(end(v), true)
{
- return end(v) != find(begin(v), end(v), x);
+ return end(v) != find(begin(v), end(v), x);
}
CWakeupEngineManager::CWakeupEngineManager()
}
}
+bool CWakeupEngineManager::set_language(string language)
+{
+ for (const auto& info : mEngineInfo) {
+ if (info.interface.set_language) {
+ info.interface.set_language(language.c_str());
+ }
+ }
+}
+
+void CWakeupEngineManager::set_assistant_activated(string appid, bool activated)
+{
+ MWR_LOGD("[ENTER] : %s %d", appid.c_str(), activated);
+ for (auto& info : mEngineInfo) {
+ const auto& iter = find_if(info.assistant_list.begin(), info.assistant_list.end(),
+ [appid](const string& assistant) {
+ return (0 == assistant.compare(appid));
+ });
+
+ /* If the appid is in the assistant list */
+ if (info.assistant_list.end() != iter) {
+ bool previously_activated = info.activated;
+ if (activated) {
+ info.activated_assistants.insert(appid);
+ } else {
+ info.activated_assistants.erase(appid);
+ }
+ info.activated = (info.activated_assistants.size() > 0);
+ if (previously_activated != info.activated) {
+ if (info.activated) {
+ info.interface.activate();
+ } else {
+ info.interface.deactivate();
+ }
+ /* Activated status changed, need to update audio_data_require_status too */
+ on_audio_data_require_status(info.engine_name, info.audio_data_require_status);
+ }
+ }
+ }
+}
+
void CWakeupEngineManager::streaming_speech_data_thread_func()
{
MWR_LOGD("[ENTER]");
bool CWakeupEngineManager::on_audio_data_require_status(string engine_name, bool require)
{
- MWR_LOGD("[ENTER]");
+ MWR_LOGD("[ENTER] %s, %d", engine_name.c_str(), require);
bool found = false;
// LOCK REQUIRED
found = true;
info.audio_data_require_status = require;
}
- if (info.enabled && info.audio_data_require_status) {
+ if (info.activated && info.audio_data_require_status) {
count++;
}
}
info.engine_path = path;
info.engine_name = name;
- info.active = false;
- /* We'll need to check vconf for enabled wakeup engines */
- info.enabled = true;
+ info.activated = false;
info.audio_data_require_status = false;
/* All the necessary information has already been set properly */
#include "dependency_resolver.h"
#include <algorithm>
-
namespace multiassistant
{
namespace wakeup
mPolicyEventObserver.set_wakeup_manager(this);
mEngineEventObserver.set_wakeup_manager(this);
mAudioEventObserver.set_wakeup_manager(this);
+ mSettingsEventObserver.set_wakeup_manager(this);
mWakeupSettings.initialize();
dependency_resolver_initialize(interface);
+ mWakeupSettings.subscribe(&mSettingsEventObserver);
+
MWR_LOGD("[END]");
return true;
}
mAudioManager.deinitialize();
mWakeupSettings.deinitialize();
- mLanguageInfo.clear();
+ mAssistantLanguageInfo.clear();
+
MWR_LOGD("[END]");
return true;
}
if (WAKEUP_MANAGER_STATE_INACTIVE != mWakeupManagerState)
return false;
+ /* Activate assistants that supports current voice input language */
+ set_language(mWakeupSettings.get_current_language());
+
change_manager_state(WAKEUP_MANAGER_STATE_LISTENING);
if (mWakeupEngineManager.get_audio_data_required()) {
mAudioManager.start_recording();
{
MWR_LOGD("[ENTER]");
bool found = false;
- for (auto& info : mLanguageInfo) {
+ for (auto& info : mAssistantLanguageInfo) {
if(0 == info.appid.compare(appid)) {
info.languageList.push_back(language);
found = true;
}
}
if(false == found) {
- LanguageInfo info;
+ AssistantLanguageInfo info;
info.appid = appid;
info.languageList.push_back(language);
- mLanguageInfo.push_back(info);
+ mAssistantLanguageInfo.push_back(info);
}
MWR_LOGD("[END]");
return true;
return true;
}
-bool CWakeupManager::set_assistant_enabled(string appid, bool enabled)
-{
- MWR_LOGD("[ENTER]");
- mWakeupSettings.set_assistant_enabled(appid, enabled);
- MWR_LOGD("[END]");
- return true;
-}
-
bool CWakeupManager::set_language(string language)
{
bool ret = false;
- MWR_LOGD("[ENTER]");
+ MWR_LOGD("[ENTER] : %s", language.c_str());
if (check_language_valid(language)) {
mCurrentLanguage = language;
+
+ bool found = false;
+ for (auto& info : mAssistantLanguageInfo) {
+ found = false;
+ for(auto it = info.languageList.begin(); it != info.languageList.end(); it++) {
+ if(language == *it) {
+ found = true;
+ break;
+ }
+ }
+ if(false == found) {
+ mAssistantActivated[info.appid] = false;
+ } else {
+ mAssistantActivated[info.appid] = true;
+ }
+
+ mWakeupEngineManager.set_assistant_activated(info.appid, found);
+ }
+
+ mWakeupEngineManager.set_language(language);
ret = true;
} else {
MWR_LOGE("[ERROR] Not supported language (%s)", language.c_str());
return true;
}
+bool CWakeupManager::CSettingsEventObserver::on_voice_input_language_changed(
+ const char* language)
+{
+ if (nullptr == mWakeupManager || nullptr == language) return false;
+ mWakeupManager->set_language(std::string(language));
+ return true;
+}
+
} // wakeup
} // multiassistant
return 0;
}
-int wakeup_manager_set_assistant_enabled(const char* appid, int enabled)
-{
- MWR_LOGD("[ENTER]");
-
- if (NULL == appid) {
- MWR_LOGD("[ERROR] Parameter is invalid, appid(%s)", appid);
- return -1;
- }
-
- g_wakeup_manager.set_assistant_enabled(string{appid}, enabled);
-
- MWR_LOGD("[END]");
-
- return 0;
-}
-
int wakeup_manager_set_language(const char* language)
{
MWR_LOGD("[ENTER]");
#include "wakeup_settings.h"
#include "wakeup_manager_main.h"
-#include <vconf.h>
#include <sstream>
+#include <algorithm>
namespace multiassistant
{
{
}
+static void wakeup_setting_input_language_changed_cb(keynode_t *node, void* data)
+{
+ if (nullptr == node) return;
+
+ CWakeupSettings* settings = static_cast<CWakeupSettings*>(data);
+ if (nullptr == settings) return;
+
+ if (VCONF_TYPE_STRING == node->type) {
+ const char* value = static_cast<const char*>(node->value.s);
+ vector<ISettingsEventObserver*> observers = settings->get_observers();
+ for (const auto& observer : observers) {
+ if (observer) {
+ if (!observer->on_voice_input_language_changed(value)) {
+ LOGW("[Settings WARNING] One of the observer returned false");
+ }
+ }
+ }
+ } else {
+ LOGE("[Settings ERROR] the value type is not string : %d", node->type);
+ }
+}
+
void CWakeupSettings::initialize()
{
int vconf_ret;
mStreamingDurationMax = vconf_double;
MWR_LOGD("streaming_duration_max : %f", mStreamingDurationMax);
}
+
+ vconf_notify_key_changed(WAKEUP_SETTINGS_KEY_VOICE_INPUT_LANGUAGE,
+ wakeup_setting_input_language_changed_cb, this);
}
void CWakeupSettings::deinitialize()
{
+ vconf_ignore_key_changed(WAKEUP_SETTINGS_KEY_VOICE_INPUT_LANGUAGE, NULL);
+}
+
+void CWakeupSettings::subscribe(ISettingsEventObserver *observer)
+{
+ mObservers.push_back(observer);
+}
+
+void CWakeupSettings::unsubscribe(ISettingsEventObserver *observer)
+{
+ auto iter = find(mObservers.begin(), mObservers.end(), observer);
+ if (iter != mObservers.end()) {
+ mObservers.erase(iter);
+ }
+}
+
+vector<ISettingsEventObserver*> CWakeupSettings::get_observers()
+{
+ return mObservers;
}
string CWakeupSettings::get_default_assistant_appid()
return mStreamingDurationMax;
}
-void CWakeupSettings::set_assistant_enabled(string appid, bool enabled)
+std::string CWakeupSettings::get_current_language(void)
{
- int found = 0;
- for(auto it = mEnabledAssistants.begin(); it != mEnabledAssistants.end(); it++) {
- if(appid == *it) {
- if(false == enabled) {
- mEnabledAssistants.erase(it);
- }
- found = 1;
- break;
- }
- }
- if((0 == found) && (true == enabled)) {
- mEnabledAssistants.push_back(appid);
+ std::string result{"en_US"};
+ char* language = vconf_get_str(WAKEUP_SETTINGS_KEY_VOICE_INPUT_LANGUAGE);
+ if (language) {
+ result = language;
+ free(language);
}
+ return result;
}
+
} // wakeup
} // multiassistant
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;
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);
+ xmlFree(prop);
+ }
+ temp->cnt_wakeup++;
}
child_node = child_node->next;
if (callback) {
callback(temp->app_id, temp->name, temp->icon_path,
- temp->wakeup_list, temp->cnt_wakeup, temp->supported_lang,
- temp->cnt_lang, temp->wakeup_engine, temp->custom_ui_option, user_data);
+ temp->wakeup_list, temp->wakeup_language, temp->cnt_wakeup,
+ temp->supported_lang, temp->cnt_lang,
+ temp->wakeup_engine, temp->custom_ui_option, user_data);
}
if (temp->app_id) {
#define MULTI_ASSISTANT_SETTINGS_ACTIVATED "db/multi-assistant/activated"
#define MAX_MACLIENT_INFO_NUM 16
-#define MAX_WAKEUP_WORDS_NUM 4
-#define MAX_WAKEUP_WORD_LEN 255
+#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];
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;
} ma_client_info;
return 0;
}
-int __mas_assistant_info_cb(const char* appid, const char* name,
- const char* icon_path, const char* wakeup_list[], int cnt_wakeup,
+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) {
MAS_LOGD("__mas_assistant_info_cb called");
for (loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) {
if (loop < cnt_wakeup && wakeup_list[loop]) {
- MAS_LOGD("wakeup_list(%d)(%s)", loop, 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);
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);
+ g_maclient_info[index].wakeup_language[loop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
+ } else {
+ strncpy(g_maclient_info[index].wakeup_language[loop], "", MAX_SUPPORTED_LANGUAGE_LEN);
+ }
} else {
strncpy(g_maclient_info[index].wakeup_word[loop], "", MAX_WAKEUP_WORD_LEN);
}
}
+ for (loop = 0;loop < MAX_SUPPORTED_LANGUAGES_NUM;loop++) {
+ if (loop < 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);
+ 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);
if (0 == 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)) {
if (0 < strlen(g_maclient_info[loop].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++) {
+ for (inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
if (0 < strlen(g_maclient_info[loop].wakeup_word[inner_loop])) {
MAS_LOGD("Registering wakeup word %s for app %s",
g_maclient_info[loop].wakeup_word[inner_loop], g_maclient_info[loop].appid);
if (0 != multi_assistant_service_plugin_add_assistant_wakeup_word(
g_maclient_info[loop].appid,
- g_maclient_info[loop].wakeup_word[inner_loop], "en_US")) {
+ g_maclient_info[loop].wakeup_word[inner_loop],
+ g_maclient_info[loop].wakeup_language[inner_loop])) {
MAS_LOGE("Fail to add assistant's wakeup word");
}
}
}
+ for (inner_loop = 0; inner_loop < MAX_SUPPORTED_LANGUAGE_NUM; inner_loop++) {
+ if (0 < strlen(g_maclient_info[loop].supported_language[inner_loop])) {
+ MAS_LOGD("Adding language %s for app %s",
+ g_maclient_info[loop].supported_language[inner_loop], g_maclient_info[loop].appid);
+ if (0 != multi_assistant_service_plugin_add_assistant_language(
+ g_maclient_info[loop].appid,
+ g_maclient_info[loop].supported_language[inner_loop])) {
+ MAS_LOGE("Fail to add assistant's language");
+ }
+ }
+ }
}
}
} else {
_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);
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_assistant_enabled func = _wakeup_manager_interface.set_assistant_enabled;
- if (NULL == func) {
- MAS_LOGE("[ERROR] symbol lookup failed : %s", MA_WAKEUP_MANAGER_FUNC_SET_ASSISTANT_ENABLED);
- } else {
- ret = func(appid, enabled);
- if (0 != ret) {
- MAS_LOGE("[ERROR] Fail to set wakeup word(%s)(%d), ret(%d)", appid, enabled, ret);
- }
- }
- } else {
- MAS_LOGE("[ERROR] g_handle is not valid");
- }
- return ret;
-}
-
int multi_assistant_service_plugin_activate(void)
{
int ret = -1;