key = xmlNodeGetContent(child_node);
if (key) {
temp.supported_lang[temp.cnt_lang++] = strdup((const char*)key);
- MAS_LOGD("Language : %s", key);
+ MAS_LOGI("Language : %s", key);
xmlFree(key);
}
}
key = xmlNodeGetContent(child_node);
if (key) {
temp.wakeup_list[temp.cnt_wakeup] = strdup((const char*)key);
- MAS_LOGD("Wakeup Word : %s", key);
+ MAS_LOGI("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);
+ MAS_LOGI("Wakeup Language for %s : %s", temp.wakeup_list[temp.cnt_wakeup], prop);
xmlFree(prop);
}
temp.cnt_wakeup++;
key = xmlNodeGetContent(cur);
if (key) {
temp.name = strdup((const char*)key);
- MAS_LOGD("Name : %s", key);
+ MAS_LOGI("Name : %s", key);
xmlFree(key);
}
} else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_APPID)) {
key = xmlNodeGetContent(cur);
if (key) {
temp.app_id = strdup((const char*)key);
- MAS_LOGD("ID : %s", key);
+ MAS_LOGI("ID : %s", key);
xmlFree(key);
}
} else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_ICON_PATH)) {
key = xmlNodeGetContent(cur);
if (key) {
temp.icon_path = strdup((const char*)key);
- MAS_LOGD("Icon Path : %s", key);
+ MAS_LOGI("Icon Path : %s", key);
xmlFree(key);
}
+ /* For supporting previous version of schema - START */
} 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);
+ if (temp.cnt_wakeup_engine == 0) {
+ key = xmlNodeGetContent(cur);
+ if (key) {
+ temp.wakeup_engine[0] = strdup((const char*)key);
+ MAS_LOGI("Wakeup Engine : %s", key);
+ xmlFree(key);
+ }
+ temp.cnt_wakeup_engine = 1;
+ } else {
+ MAS_LOGE("wakeup engine appid with cnt_wakeup_engine (%d) found", temp.cnt_wakeup_engine);
+ }
+ /* For supporting previous version of schema - END */
+ } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar *)MA_TAG_ASSISTANT_WAKEUP_ENGINE_SET)) {
+ xmlNodePtr child_node = cur->xmlChildrenNode;
+ while (child_node != NULL) {
+ if (child_node->name && 0 == xmlStrcmp(child_node->name, (const xmlChar*)MA_TAG_ASSISTANT_WAKEUP_ENGINE_APPID)) {
+ key = xmlNodeGetContent(child_node);
+ if (key) {
+ temp.wakeup_engine[temp.cnt_wakeup_engine] = strdup((const char*)key);
+ MAS_LOGI("Wakeup Engine : %s", key);
+ xmlFree(key);
+ }
+ temp.cnt_wakeup_engine++;
+ if (temp.cnt_wakeup_engine >= MAX_WAKEUP_ENGINES_NUM) {
+ MAS_LOGE("cnt_wakeup_engine exceeds : %zu", MAX_WAKEUP_ENGINES_NUM);
+ temp.cnt_wakeup_engine = MAX_WAKEUP_ENGINES_NUM - 1;
+ }
+ }
+
+ child_node = child_node->next;
}
} else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_CUSTOM_UI)) {
key = xmlNodeGetContent(cur);
if (0 == xmlStrcasecmp(key, reinterpret_cast<const xmlChar*>("true"))) {
temp.custom_ui_option = true;
}
- MAS_LOGD("Use custom UI : %d", temp.custom_ui_option);
+ MAS_LOGI("Use custom UI : %d", temp.custom_ui_option);
xmlFree(key);
}
} else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_VOICE_KEY_SUPPORT_MODE)) {
} else {
temp.voice_key_support_mode = VOICE_KEY_SUPPORT_MODE_NONE;
}
- MAS_LOGD("Voice key support mode : %s", cur->name);
+ MAS_LOGI("Voice key support mode : %s", cur->name);
xmlFree(key);
}
} else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_VOICE_KEY_TAP_DURATION)) {
key = xmlNodeGetContent(cur);
if (key) {
temp.voice_key_tap_duration = atof((const char*)key);
- MAS_LOGD("Voice key tap duration : %s", key);
+ MAS_LOGI("Voice key tap duration : %s", key);
xmlFree(key);
}
} else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_AUDIO_DATA_PROCESSOR)) {
free((void*)(temp.supported_lang[loop]));
}
}
- if (temp.wakeup_engine) {
- free((void*)temp.wakeup_engine);
+ for (loop = 0; loop < temp.cnt_wakeup_engine; loop++) {
+ if (temp.wakeup_engine[loop]) {
+ free((void*)(temp.wakeup_engine[loop]));
+ }
}
xmlFreeDoc(doc);
int CServiceConfig::get_assistant_info(service_config_assistant_info_cb callback, void* user_data)
{
+ MAS_LOGI("[ENTER] %s", MA_ASSISTANT_INFO);
const char *suffix = ".xml";
DIR *d;
while (NULL != (dir = readdir(d))) {
if (suffix && strlen(suffix) <= strlen(dir->d_name)) {
if (0 == strcmp(dir->d_name + strlen(dir->d_name) - strlen(suffix), suffix)) {
- char fullpath[_POSIX_PATH_MAX];
- snprintf(fullpath, _POSIX_PATH_MAX - 1, "%s/%s", MA_ASSISTANT_INFO, dir->d_name);
- MAS_LOGD("Parsing file : %s\n", fullpath);
+ const size_t path_max = _POSIX_PATH_MAX * 2;
+ char fullpath[path_max];
+ snprintf(fullpath, path_max - 1, "%s/%s", MA_ASSISTANT_INFO, dir->d_name);
+ MAS_LOGI("Parsing file : %s\n", fullpath);
parse_assistant_info(callback, fullpath, user_data);
}
}
closedir(d);
}
+ MAS_LOGI("[EXIT]");
return 0;
}
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)) {
+ 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)) {
LOGE("The wakeup word already exists!");
return -1; /* Already exists */
}
- if (0 == strlen(wakeup_word_storage[loop])) {
- strncpy(wakeup_word_storage[loop], wake_word, MAX_WAKEUP_WORD_LEN);
- wakeup_word_storage[loop][MAX_WAKEUP_WORD_LEN - 1] = '\0';
- strncpy(wakeup_language_storage[loop], language, MAX_SUPPORTED_LANGUAGE_LEN);
- wakeup_language_storage[loop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
- found = true;
- }
}
- if (!found) {
+ if (max_size < MAX_WAKEUP_WORDS_NUM) {
+ wakeup_word_storage.push_back(wake_word);
+ wakeup_language_storage.push_back(language);
+ } else {
LOGE("No empty slot found while trying to add new wake word!");
return -1;
}
}
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';
+ int found = 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;
+ found++;
}
}
- if (!found) return -1;
+ if (found == 0) return -1;
+
+ wakeup_word_storage.resize((max_size > found) ? max_size - found : 0);
+ wakeup_language_storage.resize((max_size > found) ? max_size - found : 0);
+
return 0;
}
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 = '|';
preference_is_existing("custom_wakeup_languages", &existing);
if (!existing) return -1;
- char* value = NULL;
- preference_get_string("custom_wakeup_words", &value);
- if (NULL == value) return -1;
- strncpy(wakeup_words, value, sizeof(wakeup_words) - 1);
+ char* custom_wakeup_words = NULL;
+ preference_get_string("custom_wakeup_words", &custom_wakeup_words);
+ if (NULL == custom_wakeup_words) return -1;
+ strncpy(wakeup_words, custom_wakeup_words, sizeof(wakeup_words) - 1);
wakeup_words[sizeof(wakeup_words) - 1] = '\0';
LOGD("Custom wakeup words loaded : %s", wakeup_words);
- free(value);
+ free(custom_wakeup_words);
+ custom_wakeup_words = NULL;
- preference_get_string("custom_wakeup_languages", &value);
- if (NULL == value) return -1;
- strncpy(wakeup_languages, value, sizeof(wakeup_languages) - 1);
+ char* custom_wakeup_languages = NULL;
+ preference_get_string("custom_wakeup_languages", &custom_wakeup_languages);
+ if (NULL == custom_wakeup_languages) return -1;
+ strncpy(wakeup_languages, custom_wakeup_languages, sizeof(wakeup_languages) - 1);
wakeup_languages[sizeof(wakeup_languages) - 1] = '\0';
LOGD("Custom wakeup languages loaded : %s", wakeup_languages);
- free(value);
+ free(custom_wakeup_languages);
+ custom_wakeup_languages = NULL;
char *word_start = wakeup_words;
char *language_start = wakeup_languages;
*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 words_num = MAX_WAKEUP_WORDS_NUM;
+ if (words_num > wakeup_word_storage.size()) words_num = wakeup_word_storage.size();
+ if (words_num > wakeup_language_storage.size()) words_num = wakeup_language_storage.size();
+
+ return words_num;
}
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;
}
}