}
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])
+ std::vector<std::string> &wakeup_word_storage,
+ std::vector<std::string> &wakeup_language_storage)
{
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)) {
+ if (0 == wakeup_word_storage[loop].compare(wake_word) &&
+ 0 == wakeup_language_storage[loop].compare(language)) {
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';
+ if (0 == wakeup_word_storage[loop].length()) {
+ wakeup_word_storage[loop] = wake_word;
+ wakeup_language_storage[loop] = language;
found = true;
}
}
}
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])
+ std::vector<std::string> &wakeup_word_storage,
+ std::vector<std::string> &wakeup_language_storage)
{
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_language_storage[shift][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
+
+ size_t max_size = get_custom_wake_word_num(wakeup_word_storage, wakeup_language_storage);
+
+ for (int loop = 0;loop < max_size;loop++) {
+ if (0 == wakeup_word_storage[loop].compare(wake_word) &&
+ 0 == wakeup_language_storage[loop].compare(language)) {
+ for (int shift = loop;shift < max_size - 1;shift++) {
+ wakeup_word_storage[shift] = wakeup_word_storage[shift + 1];
+ wakeup_language_storage[shift] = wakeup_language_storage[shift + 1];
}
- 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);
+ wakeup_word_storage[max_size - 1].clear();
+ wakeup_language_storage[max_size - 1].clear();
loop--; /* Just in case there are duplicated items */
found = true;
}
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])
+ std::vector<std::string> &wakeup_word_storage,
+ std::vector<std::string> &wakeup_language_storage)
{
const char delimeter = '|';
+ wakeup_word_storage.clear();
+ wakeup_language_storage.clear();
+
/* 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)];
*word_end = '\0';
*language_end = '\0';
if (0 == strlen(word_start)) break;
- strncpy(wakeup_word_storage[index], word_start, MAX_WAKEUP_WORD_LEN - 1);
- strncpy(wakeup_language_storage[index], language_start, MAX_SUPPORTED_LANGUAGE_LEN - 1);
+ std::string word{word_start,
+ (strlen(word_start) < MAX_WAKEUP_WORD_LEN) ? strlen(word_start) : MAX_WAKEUP_WORD_LEN};
+ std::string language{word_start,
+ (strlen(language_start) < MAX_WAKEUP_WORD_LEN) ? strlen(language_start) : MAX_SUPPORTED_LANGUAGE_LEN};
+ wakeup_word_storage.push_back(word);
+ wakeup_language_storage.push_back(language);
word_start = word_end + 1;
language_start = language_end + 1;
LOGD("Added custom wakeup word : (%s) (%s)",
}
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])
+ std::vector<std::string> &wakeup_word_storage,
+ std::vector<std::string> &wakeup_language_storage)
{
const char* delimeter = "|";
/* Add 1 for additional pipe character */
char wakeup_words[MAX_WAKEUP_WORDS_NUM * (MAX_WAKEUP_WORD_LEN + 1)];
char wakeup_languages[MAX_WAKEUP_WORDS_NUM * (MAX_SUPPORTED_LANGUAGE_LEN + 1)];
+
memset(wakeup_words, 0x00, sizeof(wakeup_words));
memset(wakeup_languages, 0x00, sizeof(wakeup_languages));
- for (int loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) {
- if (strlen(wakeup_word_storage[loop]) > 0) {
+
+ size_t max_size = get_custom_wake_word_num(wakeup_word_storage, wakeup_language_storage);
+
+ for (int loop = 0;loop < max_size;loop++) {
+ if (wakeup_word_storage[loop].length() > 0) {
int wakeup_words_len = strlen(wakeup_words);
- strncat(wakeup_words, wakeup_word_storage[loop],
+ strncat(wakeup_words, wakeup_word_storage[loop].c_str(),
sizeof(wakeup_words) - wakeup_words_len - 1);
strncat(wakeup_words, delimeter, strlen(delimeter));
int wakeup_languages_len = strlen(wakeup_languages);
- strncat(wakeup_languages, wakeup_language_storage[loop],
+ strncat(wakeup_languages, wakeup_language_storage[loop].c_str(),
sizeof(wakeup_languages) - wakeup_languages_len - 1);
strncat(wakeup_languages, delimeter, strlen(delimeter));
}
}
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])
+ std::vector<std::string> &wakeup_word_storage,
+ std::vector<std::string> &wakeup_language_storage)
{
- int num = 0;
- for (int loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) {
- if (0 < strlen(wakeup_word_storage[loop])) {
- num++;
- }
- }
- return num;
+ size_t max_size = MAX_WAKEUP_WORDS_NUM;
+ if (max_size > wakeup_word_storage.size()) max_size = wakeup_word_storage.size();
+ if (max_size > wakeup_language_storage.size()) max_size = wakeup_language_storage.size();
+
+ return max_size;
}
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])
+ std::vector<std::string> &wakeup_word_storage,
+ std::vector<std::string> &wakeup_language_storage)
{
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)) {
+ size_t max_size = get_custom_wake_word_num(wakeup_word_storage, wakeup_language_storage);
+
+ for (int loop = 0;loop < max_size;loop++) {
+ if (0 == wakeup_word_storage[loop].compare(wake_word) &&
+ 0 == wakeup_language_storage[loop].compare(language)) {
return true;
}
}
boost::optional<std::string> preprocessing_appid =
mPreferenceManager.get_string(WAKEUP_SETTINGS_KEY_PREPROCESSING_ASSISTANT_APPID);
if (preprocessing_appid) {
- ClientInfoItems *items = mClientInfo.getItems();
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ for (int loop = 0; loop < std::min(MAX_MACLIENT_INFO_NUM, items.size()); loop++) {
if (items[loop].used &&
- strncmp((*preprocessing_appid).c_str(), items[loop].appid, MAX_APPID_LEN) == 0) {
+ (*preprocessing_appid).compare(items[loop].appid) == 0) {
if (mClientManager.check_client_validity_by_appid(*preprocessing_appid)) {
ret = true;
}
bool CServiceMain::is_current_assistant(pid_t pid)
{
bool ret = false;
- const char *current_maclient_appid = NULL;
- if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) {
- ClientInfoItems *items = mClientInfo.getItems();
- current_maclient_appid = items[mCurrentClientInfo].appid;
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ if (mCurrentClientInfo >= 0 && mCurrentClientInfo < std::min(MAX_MACLIENT_INFO_NUM, items.size())) {
pid_t pid_by_appid = mClientManager.find_client_pid_by_appid(
- std::string{current_maclient_appid});
+ items[mCurrentClientInfo].appid);
if (pid == pid_by_appid) {
ret = true;
} else {
MAS_LOGE("[ERROR] Current client: [%d], active client : [%d %s]",
- pid, pid_by_appid, current_maclient_appid);
+ pid, pid_by_appid, items[mCurrentClientInfo].appid.c_str());
}
}
return ret;
}
-bool CServiceMain::is_current_preprocessing_assistant(const char* appid)
+bool CServiceMain::is_current_preprocessing_assistant(boost::optional<std::string> appid)
{
- if (NULL == appid) return false;
+ if (boost::none == appid) return false;
bool ret = false;
int CServiceMain::client_set_preprocessing_allow_mode(pid_t pid, ma_preprocessing_allow_mode_e mode, const char* appid)
{
+ if (appid == nullptr) {
+ MAS_LOGE("appid is NULL");
+ return -1;
+ }
+
std::string pid_appid;
boost::optional<std::string> 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++) {
- ClientInfoItems *items = mClientInfo.getItems();
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ for (int loop = 0; loop < std::min(MAX_MACLIENT_INFO_NUM, items.size()); loop++) {
if (items[loop].used) {
if (0 == pid_appid.compare(items[loop].appid)) {
items[loop].preprocessing_allow_mode = mode;
if (appid) {
- strncpy(items[loop].preprocessing_allow_appid, appid, MAX_APPID_LEN);
- items[loop].preprocessing_allow_appid[MAX_APPID_LEN - 1] = '\0';
+ items[loop].preprocessing_allow_appid = std::string(appid);
} else {
- items[loop].preprocessing_allow_appid[0] = '\0';
+ items[loop].preprocessing_allow_appid = boost::none;
}
}
}
int CServiceMain::client_send_preprocessing_result(pid_t pid, bool result)
{
- std::string pid_appid;
boost::optional<std::string> 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.c_str())) return -1;
+ if (!is_current_preprocessing_assistant(appid_by_pid)) return -1;
- const char *current_maclient_appid = NULL;
- if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) {
- ClientInfoItems *items = mClientInfo.getItems();
+ boost::optional<std::string> current_maclient_appid;
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ if (mCurrentClientInfo >= 0 && mCurrentClientInfo < std::min(MAX_MACLIENT_INFO_NUM, items.size())) {
current_maclient_appid = items[mCurrentClientInfo].appid;
}
if (result) {
- MAS_LOGD("Preprocessing succeeded, bring (%s) to foreground", pid_appid.c_str());
+ MAS_LOGD("Preprocessing succeeded, bring (%s) to foreground",
+ appid_by_pid.value_or(std::string()).c_str());
process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_SUCCEEDED);
} else {
- MAS_LOGD("Preprocessing failed, bring (%s) to foreground", current_maclient_appid);
+ MAS_LOGD("Preprocessing failed, bring (%s) to foreground",
+ current_maclient_appid.value_or(std::string()).c_str());
process_preprocessing_state_event(PREPROCESSING_STATE_EVENT_PREPROCESSING_FAILED);
}
if (current_maclient_appid) {
- pid_t pid_by_appid = mClientManager.find_client_pid_by_appid(
- std::string{current_maclient_appid});
+ pid_t pid_by_appid = mClientManager.find_client_pid_by_appid(current_maclient_appid.value());
mServiceIpc.send_preprocessing_result(pid_by_appid, result);
}
pid_appid = *appid_by_pid;
}
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- ClientInfoItems *items = mClientInfo.getItems();
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ for (int loop = 0; loop < std::min(MAX_MACLIENT_INFO_NUM, items.size()); loop++) {
if (items[loop].used &&
0 == pid_appid.compare(items[loop].appid)) {
int ret = mServiceConfig.add_custom_wake_word(wake_word, language,
pid_appid = *appid_by_pid;
}
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- ClientInfoItems *items = mClientInfo.getItems();
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ for (int loop = 0; loop < std::min(MAX_MACLIENT_INFO_NUM, items.size()); loop++) {
if (items[loop].used &&
0 == pid_appid.compare(items[loop].appid)) {
int ret = mServiceConfig.remove_custom_wake_word(wake_word, language,
}
set_current_client_by_appid(appid);
- pid_t pid = get_client_pid_by_appid(appid);
+ pid_t pid = get_client_pid_by_appid(appid ? boost::optional<std::string>(appid) : boost::none);
if (pid != -1) {
- bring_client_to_foreground(appid);
+ bring_client_to_foreground(appid ? boost::optional<std::string>(appid) : boost::none);
client_send_preprocessing_information(pid);
if (MA_VOICE_KEY_STATUS_PRESSED == mLastVoiceKeyStatus) {
client_send_voice_key_status_change(pid, mLastVoiceKeyStatus);
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 mClientInfo */
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- ClientInfoItems *items = mClientInfo.getItems();
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ for (int loop = 0; loop < std::min(MAX_MACLIENT_INFO_NUM, items.size()); loop++) {
if (items[loop].used &&
- 0 < strlen(items[loop].appid) &&
- 0 < strlen(items[loop].wakeup_word[0])) {
- if (strncmp(appid, items[loop].appid, MAX_APPID_LEN) == 0) {
- launch_client_by_appid(items[loop].appid, nullptr,
+ 0 < items[loop].appid.length() &&
+ 0 < items[loop].wakeup_word.size()) {
+ if (items[loop].appid.compare(appid) == 0) {
+ launch_client_by_appid(items[loop].appid.c_str(), nullptr,
nullptr, 0, nullptr, CLIENT_LAUNCH_MODE_ACTIVATION);
}
}
int index = -1;
int loop = 0;
- ClientInfoItems *items = mClientInfo.getItems();
- while(-1 == index && loop < MAX_MACLIENT_INFO_NUM) {
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ while(-1 == index && loop < std::min(MAX_MACLIENT_INFO_NUM, items.size())) {
if (false == items[loop].used) {
index = loop;
}
loop++;
}
+ if (-1 == index) {
+ if (items.size() < MAX_MACLIENT_INFO_NUM) {
+ index = items.size();
+ items.push_back(ClientInfoItems());
+ }
+ }
if (-1 != index) {
items[index].used = true;
items[index].preprocessing_allow_mode = MA_PREPROCESSING_ALLOW_NONE;
- items[index].preprocessing_allow_appid[0] = '\0';
+ items[index].preprocessing_allow_appid = boost::none;
MAS_LOGD("app_id(%s)", info->app_id);
- strncpy(items[index].appid, info->app_id, MAX_APPID_LEN);
- items[index].appid[MAX_APPID_LEN - 1] = '\0';
+ items[index].appid = info->app_id;
if (is_current_preprocessing_assistant(items[index].appid)) {
mCurrentPreprocessingClientInfo = index;
}
+ items[index].wakeup_word.clear();
+ items[index].wakeup_language.clear();
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(items[index].wakeup_word[loop], info->wakeup_list[loop], MAX_WAKEUP_WORD_LEN);
- items[index].wakeup_word[loop][MAX_WAKEUP_WORD_LEN - 1] = '\0';
+ items[index].wakeup_word.push_back(info->wakeup_list[loop]);
if (info->wakeup_language[loop]) {
- strncpy(items[index].wakeup_language[loop], info->wakeup_language[loop], MAX_SUPPORTED_LANGUAGE_LEN);
- items[index].wakeup_language[loop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
+ items[index].wakeup_language.push_back(info->wakeup_language[loop]);
} else {
- strncpy(items[index].wakeup_language[loop], "", MAX_SUPPORTED_LANGUAGE_LEN);
+ items[index].wakeup_language.push_back(std::string());
}
- } else {
- strncpy(items[index].wakeup_word[loop], "", MAX_WAKEUP_WORD_LEN);
}
}
+ items[index].supported_language.clear();
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(items[index].supported_language[loop], info->supported_lang[loop], MAX_SUPPORTED_LANGUAGE_LEN);
- items[index].supported_language[loop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
- } else {
- strncpy(items[index].supported_language[loop], "", MAX_SUPPORTED_LANGUAGE_LEN);
+ items[index].supported_language.push_back(info->supported_lang[loop]);
}
}
+ items[index].wakeup_engine.clear();
for (loop = 0;loop < MAX_WAKEUP_ENGINES_NUM;loop++) {
if (loop < info->cnt_wakeup_engine && info->wakeup_engine[loop]) {
MAS_LOGD("wakeup_engine(%s)", info->wakeup_engine[loop]);
- strncpy(items[index].wakeup_engine[loop], info->wakeup_engine[loop], MAX_APPID_LEN);
- items[index].wakeup_engine[loop][MAX_APPID_LEN - 1] = '\0';
- } else {
- items[index].wakeup_engine[loop][0] = '\0';
- MAS_LOGW("Wakeup engine information not provided for : %s", info->app_id);
+ items[index].wakeup_engine.push_back(info->wakeup_engine[loop]);
}
}
items[index].custom_ui_option = info->custom_ui_option;
mLastWakeupInfo.extraDataDesc.clear();
if (0 == mServiceConfig.get_assistant_info(assistant_info_cb, this)) {
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ for (int loop = 0; loop < std::min(MAX_MACLIENT_INFO_NUM, items.size()); loop++) {
int inner_loop;
- ClientInfoItems *items = mClientInfo.getItems();
- if (0 < strlen(items[loop].appid)) {
- mServiceConfig.load_custom_wake_words(items[loop].appid,
+ if (0 < items[loop].appid.length()) {
+ mServiceConfig.load_custom_wake_words(items[loop].appid.c_str(),
items[loop].wakeup_word, items[loop].wakeup_language);
- for (inner_loop = 0; inner_loop < MAX_WAKEUP_ENGINES_NUM; inner_loop++) {
- if (0 < strlen(items[loop].wakeup_engine[inner_loop])) {
+ for (inner_loop = 0;
+ inner_loop < std::min(MAX_WAKEUP_ENGINES_NUM, items[loop].wakeup_engine.size()); inner_loop++) {
+ if (0 < items[loop].wakeup_engine[inner_loop].length()) {
mServicePlugin.add_assistant_wakeup_engine(
- items[loop].appid,
- items[loop].wakeup_engine[inner_loop]);
+ items[loop].appid.c_str(),
+ items[loop].wakeup_engine[inner_loop].c_str());
}
}
- for (inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
- if (0 < strlen(items[loop].wakeup_word[inner_loop])) {
+ for (inner_loop = 0;
+ inner_loop < std::min(MAX_WAKEUP_WORDS_NUM, items[loop].wakeup_word.size()); inner_loop++) {
+ if (0 < items[loop].wakeup_word[inner_loop].length()) {
MAS_LOGD("Registering wakeup word %s for app %s",
- items[loop].wakeup_word[inner_loop], items[loop].appid);
+ items[loop].wakeup_word[inner_loop].c_str(), items[loop].appid.c_str());
if (0 != mServicePlugin.add_assistant_wakeup_word(
- items[loop].appid,
- items[loop].wakeup_word[inner_loop],
- items[loop].wakeup_language[inner_loop])) {
+ items[loop].appid.c_str(),
+ items[loop].wakeup_word[inner_loop].c_str(),
+ items[loop].wakeup_language[inner_loop].c_str())) {
MAS_LOGE("Fail to add assistant's wakeup word");
}
}
}
- for (inner_loop = 0; inner_loop < MAX_SUPPORTED_LANGUAGES_NUM; inner_loop++) {
- if (0 < strlen(items[loop].supported_language[inner_loop])) {
+ for (inner_loop = 0;
+ inner_loop < std::min(MAX_SUPPORTED_LANGUAGES_NUM, items[loop].supported_language.size()); inner_loop++) {
+ if (0 < items[loop].supported_language[inner_loop].length()) {
MAS_LOGD("Adding language %s for app %s",
- items[loop].supported_language[inner_loop], items[loop].appid);
+ items[loop].supported_language[inner_loop].c_str(), items[loop].appid.c_str());
if (0 != mServicePlugin.add_assistant_language(
- items[loop].appid,
- items[loop].supported_language[inner_loop])) {
+ items[loop].appid.c_str(),
+ items[loop].supported_language[inner_loop].c_str())) {
MAS_LOGE("Fail to add assistant's language");
}
}
const char *default_assistant = NULL;
if (0 == mServicePlugin.get_default_assistant(&default_assistant)) {
if (NULL == default_assistant) {
- ClientInfoItems *items = mClientInfo.getItems();
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
if (items[0].used) {
- default_assistant = items[0].appid;
+ default_assistant = items[0].appid.c_str();
MAS_LOGW("No default assistant, setting %s as default", default_assistant);
mServicePlugin.set_default_assistant(default_assistant);
} else {
boost::optional<std::string> CServiceMain::get_current_client_appid()
{
boost::optional<std::string> ret;
- if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) {
- ClientInfoItems *items = mClientInfo.getItems();
- const char *appid = items[mCurrentClientInfo].appid;
- if (appid) {
- ret = std::string{appid};
- }
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ if (mCurrentClientInfo >= 0 && mCurrentClientInfo < std::min(MAX_MACLIENT_INFO_NUM, items.size())) {
+ ret = items[mCurrentClientInfo].appid;
}
return ret;
}
boost::optional<std::string> CServiceMain::get_current_preprocessing_client_appid()
{
boost::optional<std::string> ret;
- if (mCurrentPreprocessingClientInfo >= 0 && mCurrentPreprocessingClientInfo < MAX_MACLIENT_INFO_NUM) {
- ClientInfoItems *items = mClientInfo.getItems();
- const char *appid = items[mCurrentPreprocessingClientInfo].appid;
- if (appid) {
- ret = std::string{appid};
- }
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ if (mCurrentPreprocessingClientInfo >= 0 && mCurrentPreprocessingClientInfo < std::min(MAX_MACLIENT_INFO_NUM, items.size())) {
+ ret = items[mCurrentPreprocessingClientInfo].appid;
}
return ret;
}
boost::optional<std::string> CServiceMain::get_current_audio_processing_appid()
{
boost::optional<std::string> ret;
- if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) {
- ClientInfoItems *items = mClientInfo.getItems();
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ if (mCurrentClientInfo >= 0 && mCurrentClientInfo < std::min(MAX_MACLIENT_INFO_NUM, items.size())) {
ret = items[mCurrentClientInfo].audio_processing_appid;
}
return ret;
}
-pid_t CServiceMain::get_client_pid_by_appid(const char *appid)
+pid_t CServiceMain::get_client_pid_by_appid(boost::optional<std::string> appid)
{
- MAS_LOGI("Checking PID of appid : %s", appid);
+ MAS_LOGI("Checking PID of appid : %s", appid.value_or(std::string()).c_str());
pid_t ret = -1;
if (appid) {
- ret = mClientManager.find_client_pid_by_appid(std::string{appid});
+ ret = mClientManager.find_client_pid_by_appid(appid.value());
}
- if (-1 != ret && !mApplicationManager.is_application_running(appid)) {
- MAS_LOGE("The PID for %s was %d, but it seems to be terminated", appid, ret);
+ if (-1 != ret && !mApplicationManager.is_application_running(appid.value())) {
+ MAS_LOGE("The PID for %s was %d, but it seems to be terminated", appid.value_or(std::string()).c_str(), ret);
on_deinitialize(ret, mClientManager.find_sender_info_by_pid(ret));
ret = -1;
}
bool CServiceMain::get_client_custom_ui_option_by_appid(const char *appid)
{
bool ret = false;
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- ClientInfoItems *items = mClientInfo.getItems();
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ for (int loop = 0; loop < std::min(MAX_MACLIENT_INFO_NUM, items.size()); loop++) {
if (items[loop].used &&
- 0 < strlen(items[loop].appid) &&
- 0 < strlen(items[loop].wakeup_word[0])) {
- if (strncmp(appid, items[loop].appid, MAX_APPID_LEN) == 0) {
+ 0 < items[loop].appid.length() &&
+ 0 < items[loop].wakeup_word.size()) {
+ if (0 == items[loop].appid.compare(appid)) {
ret = items[loop].custom_ui_option;
}
}
int CServiceMain::get_client_pid_by_wakeup_word(const char *wakeup_word)
{
- const char *appid = get_client_appid_by_wakeup_word(wakeup_word);
- return get_client_pid_by_appid(appid);
+ boost::optional<std::string> appid = get_client_appid_by_wakeup_word(wakeup_word);
+ return get_client_pid_by_appid(appid.value_or(std::string()));
}
-const char* CServiceMain::get_client_appid_by_wakeup_word(const char *wakeup_word)
+boost::optional<std::string> CServiceMain::get_client_appid_by_wakeup_word(const char *wakeup_word)
{
int loop;
- const char *appid = NULL;
+ boost::optional<std::string> appid;
- if (NULL == wakeup_word) return NULL;
+ if (NULL == wakeup_word) return boost::none;
- ClientInfoItems *items = mClientInfo.getItems();
- for (loop = 0; loop < MAX_MACLIENT_INFO_NUM && NULL == appid; loop++) {
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ for (loop = 0; loop < std::min(MAX_MACLIENT_INFO_NUM , items.size()) && boost::none == appid; loop++) {
if (items[loop].used &&
- 0 < strlen(items[loop].appid)) {
+ 0 < items[loop].appid.length()) {
for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
- if (0 < strlen(items[loop].wakeup_word[inner_loop])) {
- if (0 == strncmp(wakeup_word, items[loop].wakeup_word[inner_loop], MAX_WAKEUP_WORD_LEN)) {
+ if (0 < items[loop].wakeup_word[inner_loop].length()) {
+ if (0 == items[loop].wakeup_word[inner_loop].compare(wakeup_word)) {
appid = items[loop].appid;
}
}
}
/* Perform extended search, by eliminating blank characters */
- if (NULL == appid) {
- for (loop = 0; loop < MAX_MACLIENT_INFO_NUM && NULL == appid; loop++) {
+ if (boost::none == appid) {
+ for (loop = 0; loop < std::min(MAX_MACLIENT_INFO_NUM , items.size()) && boost::none == appid; loop++) {
if (items[loop].used &&
- 0 < strlen(items[loop].appid)) {
+ 0 < items[loop].appid.length()) {
for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
- if (0 < strlen(items[loop].wakeup_word[inner_loop])) {
+ if (0 < items[loop].wakeup_word[inner_loop].length()) {
char comparand[MAX_WAKEUP_WORD_LEN] = {0, };
int comparand_index = 0;
for (int index = 0; index < MAX_WAKEUP_WORD_LEN; index++) {
- if (' ' != items[loop].wakeup_word[inner_loop][index]) {
- comparand[comparand_index++] = items[loop].wakeup_word[inner_loop][index];
+ for (auto &c : items[loop].wakeup_word[inner_loop]) {
+ if (' ' != c) {
+ comparand[comparand_index++] = c;
+ }
}
}
if (0 == strncmp(wakeup_word, comparand, MAX_WAKEUP_WORD_LEN)) {
int ret = -1;
int prev_selection = mCurrentClientInfo;
- ClientInfoItems *items = mClientInfo.getItems();
- for (loop = 0; loop < MAX_MACLIENT_INFO_NUM && -1 == ret; loop++) {
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ for (loop = 0; loop < std::min(MAX_MACLIENT_INFO_NUM , items.size()) && -1 == ret; loop++) {
if (items[loop].used &&
- 0 < strlen(items[loop].appid)) {
+ 0 < items[loop].appid.length()) {
for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
- if (0 < strlen(items[loop].wakeup_word[inner_loop])) {
- if (0 == strncmp(wakeup_word, items[loop].wakeup_word[inner_loop], MAX_WAKEUP_WORD_LEN)) {
+ if (0 < items[loop].wakeup_word[inner_loop].length()) {
+ if (items[loop].wakeup_word[inner_loop].compare(wakeup_word) == 0) {
mCurrentClientInfo = loop;
MAS_LOGE("mCurrentClientInfo : %d %s", mCurrentClientInfo, wakeup_word);
ret = 0;
}
/* Perform extended search, by eliminating blank characters */
if (ret == -1) {
- for (loop = 0; loop < MAX_MACLIENT_INFO_NUM && -1 == ret; loop++) {
+ for (loop = 0; loop < std::min(MAX_MACLIENT_INFO_NUM , items.size()) && -1 == ret; loop++) {
if (items[loop].used &&
- 0 < strlen(items[loop].appid)) {
+ 0 < items[loop].appid.length()) {
for (int inner_loop = 0; inner_loop < MAX_WAKEUP_WORDS_NUM; inner_loop++) {
- if (0 < strlen(items[loop].wakeup_word[inner_loop])) {
+ if (0 < items[loop].wakeup_word[inner_loop].length()) {
char comparand[MAX_WAKEUP_WORD_LEN] = {0, };
int comparand_index = 0;
for (int index = 0; index < MAX_WAKEUP_WORD_LEN; index++) {
}
if (mCurrentClientInfo != prev_selection) {
- if (prev_selection >= 0 && prev_selection < MAX_MACLIENT_INFO_NUM) {
+ if (prev_selection >= 0 && prev_selection < std::min(MAX_MACLIENT_INFO_NUM, items.size())) {
pid_t pid = get_client_pid_by_appid(items[prev_selection].appid);
mServiceIpc.change_active_state(pid, MA_ACTIVE_STATE_INACTIVE, nullptr, nullptr, 0, nullptr);
if (mLastDuckingRequester == pid) {
MAS_LOGE("Last ducking requester is deactivated, resetting background volume");
- mServicePlugin.set_background_volume(items[prev_selection].appid, 1.0f);
+ mServicePlugin.set_background_volume(items[prev_selection].appid.c_str(), 1.0f);
mLastDuckingRequester = -1;
}
}
int ret = -1;
int prev_selection = mCurrentClientInfo;
- ClientInfoItems *items = mClientInfo.getItems();
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ for (int loop = 0; loop < std::min(MAX_MACLIENT_INFO_NUM, items.size()); loop++) {
if (items[loop].used &&
- 0 < strlen(items[loop].appid) &&
- 0 < strlen(items[loop].wakeup_word[0])) {
- if (strncmp(appid, items[loop].appid, MAX_APPID_LEN) == 0) {
+ 0 < items[loop].appid.length() &&
+ 0 < items[loop].wakeup_word[0].size()) {
+ if (0 == items[loop].appid.compare(appid)) {
MAS_LOGE("mCurrentClientInfo : %d %s", mCurrentClientInfo, appid);
mCurrentClientInfo = loop;
ret = 0;
}
if (mCurrentClientInfo != prev_selection) {
- if (prev_selection >= 0 && prev_selection < MAX_MACLIENT_INFO_NUM) {
+ if (prev_selection >= 0 && prev_selection < std::min(MAX_MACLIENT_INFO_NUM, items.size())) {
pid_t pid = get_client_pid_by_appid(items[prev_selection].appid);
mServiceIpc.change_active_state(pid, MA_ACTIVE_STATE_INACTIVE, nullptr, nullptr, 0, nullptr);
if (mLastDuckingRequester == pid) {
MAS_LOGE("Last ducking requester is deactivated, resetting background volume");
- mServicePlugin.set_background_volume(items[prev_selection].appid, 1.0f);
+ mServicePlugin.set_background_volume(items[prev_selection].appid.c_str(), 1.0f);
mLastDuckingRequester = -1;
}
}
if (CLIENT_LAUNCH_MODE_ACTIVATION == launch_mode) {
bool found = false;
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- ClientInfoItems *items = mClientInfo.getItems();
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ for (int loop = 0; loop < std::min(MAX_MACLIENT_INFO_NUM, items.size()); loop++) {
if (items[loop].used &&
- 0 < strlen(items[loop].appid)) {
- if (strncmp(appid, items[loop].appid, MAX_APPID_LEN) == 0) {
+ 0 < items[loop].appid.length()) {
+ if (items[loop].appid.compare(appid) == 0) {
mLastWakeupInfo.wakeupAppId = items[loop].appid;
mLastWakeupInfo.wakeupWord = (word ? word : "");
if (extra_data && extra_data_length > 0) {
return result;
}
-int CServiceMain::bring_client_to_foreground(const char* appid)
+int CServiceMain::bring_client_to_foreground(boost::optional<std::string> appid)
{
LOGI("[ENTER]");
int ret = 0;
- if (NULL == appid || 0 == strlen(appid)) {
+ if (!appid || 0 == appid.value().length()) {
MAS_LOGE("appid invalid, failed launching MA Client");
return -1;
}
- if (!mApplicationManager.bring_app_to_foreground(appid)) {
+ if (!mApplicationManager.bring_app_to_foreground(appid.value())) {
ret = -1;
}
int CServiceMain::launch_client_by_wakeup_word(const char *wakeup_word,
const unsigned char* extra_data, size_t extra_data_length, const char *extra_data_desc)
{
- const char *appid = get_client_appid_by_wakeup_word(wakeup_word);
- return launch_client_by_appid(appid, wakeup_word,
+ boost::optional<std::string> appid = get_client_appid_by_wakeup_word(wakeup_word);
+ return launch_client_by_appid(appid.value_or(std::string()).c_str(), wakeup_word,
extra_data, extra_data_length, extra_data_desc, CLIENT_LAUNCH_MODE_ACTIVATION);
}
bool successful = false;
const char *default_assistant = NULL;
if (0 == mServicePlugin.get_default_assistant(&default_assistant)) {
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- ClientInfoItems *items = mClientInfo.getItems();
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ for (int loop = 0; loop < std::min(MAX_MACLIENT_INFO_NUM, items.size()); loop++) {
if (items[loop].used) {
LOGI("APPID : %s", items[loop].appid);
if (default_assistant &&
- strncmp(default_assistant, items[loop].appid, MAX_APPID_LEN) == 0) {
+ items[loop].appid.compare(default_assistant) == 0) {
float duration = items[loop].voice_key_tap_duration;
if (0.0f < duration) {
mServicePlugin.set_voice_key_tap_duration(duration);
return 0;
}
-ma_preprocessing_allow_mode_e CServiceMain::get_preprocessing_allow_mode(const char* appid)
+ma_preprocessing_allow_mode_e CServiceMain::get_preprocessing_allow_mode(boost::optional<std::string> appid)
{
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
- ClientInfoItems *items = mClientInfo.getItems();
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ for (int loop = 0; loop < std::min(MAX_MACLIENT_INFO_NUM, items.size()); loop++) {
if (appid && items[loop].used) {
- if (strncmp(appid, items[loop].appid, MAX_APPID_LEN) == 0) {
+ if (items[loop].appid.compare(appid.value()) == 0) {
return items[loop].preprocessing_allow_mode;
}
}
int CServiceMain::process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event)
{
- const char* current_maclient_appid = NULL;
- const char* preprocessing_allow_appid = NULL;
- if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) {
- ClientInfoItems *items = mClientInfo.getItems();
+ boost::optional<std::string> current_maclient_appid;
+ boost::optional<std::string> preprocessing_allow_appid;
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ if (mCurrentClientInfo >= 0 && mCurrentClientInfo < std::min(MAX_MACLIENT_INFO_NUM, items.size())) {
current_maclient_appid = items[mCurrentClientInfo].appid;
preprocessing_allow_appid = items[mCurrentClientInfo].preprocessing_allow_appid;
}
bool CServiceMain::is_valid_wakeup_engine(const char* appid)
{
- for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM;loop++) {
- ClientInfoItems *items = mClientInfo.getItems();
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ for (int loop = 0; loop < std::min(MAX_MACLIENT_INFO_NUM, items.size());loop++) {
if (items[loop].used) {
for (int inner_loop = 0;inner_loop < MAX_WAKEUP_ENGINES_NUM;inner_loop++) {
LOGD("comparing appid : %s %s", items[loop].wakeup_engine[inner_loop], appid);
- if (0 == strncmp(items[loop].wakeup_engine[inner_loop], appid, MAX_APPID_LEN)) {
+ if (0 == items[loop].wakeup_engine[inner_loop].compare(appid)) {
return true;
}
}
mClientManager.create_client(pid, pid_appid, sender_info);
- const char *current_maclient_appid = NULL;
- if (mCurrentClientInfo >= 0 && mCurrentClientInfo < MAX_MACLIENT_INFO_NUM) {
- ClientInfoItems *items = mClientInfo.getItems();
+ boost::optional<std::string> current_maclient_appid;
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ if (mCurrentClientInfo >= 0 && mCurrentClientInfo < std::min(MAX_MACLIENT_INFO_NUM, items.size())) {
current_maclient_appid = items[mCurrentClientInfo].appid;
}
if (MA_VOICE_KEY_STATUS_PRESSED == mLastVoiceKeyStatus) {
client_send_voice_key_status_change(pid, mLastVoiceKeyStatus);
}
- if (current_maclient_appid && 0 == pid_appid.compare(current_maclient_appid)) {
+ if (current_maclient_appid && 0 == pid_appid.compare(current_maclient_appid.value())) {
MAS_LOGD("MA client with current maclient appid connected!");
if (0 == mLastWakeupInfo.wakeupAppId.compare(pid_appid)) {
LOGE("AP requested to start streaming audio data : %s %d",
ap_appid.c_str(), type);
- if (mCurrentClientInfo < 0 || mCurrentClientInfo >= MAX_MACLIENT_INFO_NUM) {
+ std::vector<ClientInfoItems> &items = mClientInfo.getItems();
+ if (mCurrentClientInfo < 0 || mCurrentClientInfo >= std::min(MAX_MACLIENT_INFO_NUM, items.size())) {
MAS_LOGE("Invalid client info index");
return -1;
}
- ClientInfoItems *items = mClientInfo.getItems();
if (items[mCurrentClientInfo].audio_processing_appid) {
if (ap_appid.compare(*(items[mCurrentClientInfo].audio_processing_appid)) == 0) {
std::string appid = items[mCurrentClientInfo].appid;