typedef int (*mas_config_assistant_info_cb)(ma_assistant_info_s* info, void* user_data);
-int mas_config_get_assistant_info(mas_config_assistant_info_cb callback, void* user_data);
-int mas_config_load_custom_wake_words(const char* app_id,
- char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
- char wakeup_language[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]);
-int mas_config_save_custom_wake_words(const char* app_id,
- char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
- char wakeup_language[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN]);
+class CConfig {
+public:
+ CConfig() {};
+ virtual ~CConfig() {};
+
+ int mas_config_get_assistant_info(mas_config_assistant_info_cb callback, void* user_data);
+
+ int mas_config_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]);
+ int mas_config_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]);
+ int mas_config_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]);
+ int mas_config_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]);
+ int mas_config_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]);
+private:
+ int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback,
+ const char *path, void* user_data);
+};
#ifdef __cplusplus
}
int multi_assistant_service_plugin_set_assistant_language(const char* appid, const char* language);
+int multi_assistant_service_plugin_set_voice_key_support_mode(int mode);
+
int multi_assistant_service_plugin_set_voice_key_tap_duration(float duration);
int multi_assistant_service_plugin_unset_voice_key_tap_duration(void);
#include "multi_assistant_config.h"
#include "multi_assistant_main.h"
-int mas_config_parse_assistant_info(mas_config_assistant_info_cb callback, const char *path, void* user_data)
+int CConfig::mas_config_parse_assistant_info(mas_config_assistant_info_cb callback,
+ const char *path, void* user_data)
{
xmlDocPtr doc = NULL;
xmlNodePtr cur = NULL;
return 0;
}
-int mas_config_get_assistant_info(mas_config_assistant_info_cb callback, void* user_data)
+int CConfig::mas_config_get_assistant_info(mas_config_assistant_info_cb callback, void* user_data)
{
const char *suffix = ".xml";
return 0;
}
-int mas_config_load_custom_wake_words(const char* app_id,
- char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
- char wakeup_language[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN])
+int CConfig::mas_config_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])
+{
+ 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)) {
+ 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) {
+ LOGE("No empty slot found while trying to add new wake word!");
+ return -1;
+ }
+ return 0;
+}
+
+int CConfig::mas_config_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])
+{
+ 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_word_storage[shift][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
+ }
+ 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);
+
+ loop--; /* Just in case there are duplicated items */
+ found = true;
+ }
+ }
+ if (!found) return -1;
+ return 0;
+}
+
+int CConfig::mas_config_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])
{
/* Add 1 for additional pipe character */
char wakeup_words[MAX_WAKEUP_WORDS_NUM * (MAX_WAKEUP_WORD_LEN + 1)];
*word_end = '\0';
*language_end = '\0';
if (0 == strlen(word_start)) break;
- strncpy(wakeup_word[index], word_start, MAX_WAKEUP_WORD_LEN - 1);
- strncpy(wakeup_language[index], language_start, MAX_WAKEUP_WORD_LEN - 1);
+ strncpy(wakeup_word_storage[index], word_start, MAX_WAKEUP_WORD_LEN - 1);
+ strncpy(wakeup_language_storage[index], language_start, MAX_WAKEUP_WORD_LEN - 1);
word_start = word_end + 1;
language_start = language_end + 1;
- LOGD("Added custom wakeup word : (%s) (%s)", wakeup_word[index], wakeup_language[index]);
+ LOGD("Added custom wakeup word : (%s) (%s)",
+ wakeup_word_storage[index], wakeup_language_storage[index]);
index++;
}
return 0;
}
-int mas_config_save_custom_wake_words(const char* app_id,
- char wakeup_word[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN],
- char wakeup_language[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN])
+int CConfig::mas_config_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])
{
/* Add 1 for additional pipe character */
char wakeup_words[MAX_WAKEUP_WORDS_NUM * (MAX_WAKEUP_WORD_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[loop]) > 0) {
+ if (strlen(wakeup_word_storage[loop]) > 0) {
int wakeup_words_len = strlen(wakeup_words);
- strncat(wakeup_words, wakeup_word[loop], sizeof(wakeup_words) - wakeup_words_len - 1);
+ strncat(wakeup_words, wakeup_word_storage[loop],
+ sizeof(wakeup_words) - wakeup_words_len - 1);
strcat(wakeup_words, "|");
int wakeup_languages_len = strlen(wakeup_languages);
- strncat(wakeup_languages, wakeup_language[loop], sizeof(wakeup_languages) - wakeup_languages_len - 1);
+ strncat(wakeup_languages, wakeup_language_storage[loop],
+ sizeof(wakeup_languages) - wakeup_languages_len - 1);
strcat(wakeup_languages, "|");
}
}
preference_set_string("custom_wakeup_words", wakeup_words);
preference_set_string("custom_wakeup_languages", wakeup_languages);
return 0;
-}
\ No newline at end of file
+}
+
+int CConfig::mas_config_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])
+{
+ int num = 0;
+ for (int loop = 0;loop < MAX_WAKEUP_WORDS_NUM;loop++) {
+ if (strlen(wakeup_word_storage[loop]) > 0) {
+ num++;
+ }
+ }
+ return num;
+}
/* client list */
static GSList* g_client_list = NULL;
+static CConfig g_config;
int ma_client_create(ma_client_s *info)
{
for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
if (g_maclient_info[loop].used &&
0 == strncmp(buf, g_maclient_info[loop].appid, MAX_APPID_LEN)) {
- bool found = false;
- bool duplicated = false;
- for (int innerLoop = 0;false == found && false == duplicated &&
- innerLoop < MAX_WAKEUP_WORDS_NUM;innerLoop++) {
- if (0 == strncmp(g_maclient_info[loop].wakeup_word[innerLoop], wake_word, MAX_WAKEUP_WORD_LEN) &&
- 0 == strncmp(g_maclient_info[loop].wakeup_language[innerLoop], language, MAX_SUPPORTED_LANGUAGE_LEN)) {
- duplicated = true;
- }
- if (0 == strlen(g_maclient_info[loop].wakeup_word[innerLoop])) {
- strncpy(g_maclient_info[loop].wakeup_word[innerLoop], wake_word, MAX_WAKEUP_WORD_LEN);
- g_maclient_info[loop].wakeup_word[innerLoop][MAX_WAKEUP_WORD_LEN - 1] = '\0';
- strncpy(g_maclient_info[loop].wakeup_language[innerLoop], language, MAX_SUPPORTED_LANGUAGE_LEN);
- g_maclient_info[loop].wakeup_word[innerLoop][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
- found = true;
- }
- }
- if (found && !duplicated) {
- mas_config_save_custom_wake_words(pid_appid,
+ ret = g_config.mas_config_add_custom_wake_word(wake_word, language,
+ g_maclient_info[loop].wakeup_word,
+ g_maclient_info[loop].wakeup_language);
+ if (0 == ret) {
+ g_config.mas_config_save_custom_wake_words(pid_appid,
g_maclient_info[loop].wakeup_word,
g_maclient_info[loop].wakeup_language);
} else {
- if (duplicated) {
- LOGE("The wakeup word already exists!");
- } else {
- LOGE("No empty slot found while trying to add new wake word!");
- }
+ LOGE("add new wake word failed!");
return -1;
}
}
for (int loop = 0; loop < MAX_MACLIENT_INFO_NUM; loop++) {
if (g_maclient_info[loop].used &&
0 == strncmp(buf, g_maclient_info[loop].appid, MAX_APPID_LEN)) {
- for (int innerLoop = 0;innerLoop < MAX_WAKEUP_WORDS_NUM;innerLoop++) {
- if (0 == strncmp(g_maclient_info[loop].wakeup_word[innerLoop], wake_word, MAX_WAKEUP_WORD_LEN) &&
- 0 == strncmp(g_maclient_info[loop].wakeup_language[innerLoop], language, MAX_SUPPORTED_LANGUAGE_LEN)) {
- for (int shift = innerLoop;shift < MAX_WAKEUP_WORDS_NUM - 1;shift++) {
- strncpy(g_maclient_info[loop].wakeup_word[shift],
- g_maclient_info[loop].wakeup_word[shift + 1], MAX_WAKEUP_WORD_LEN);
- g_maclient_info[loop].wakeup_word[shift][MAX_WAKEUP_WORD_LEN - 1] = '\0';
- strncpy(g_maclient_info[loop].wakeup_language[shift],
- g_maclient_info[loop].wakeup_language[shift + 1], MAX_SUPPORTED_LANGUAGE_LEN);
- g_maclient_info[loop].wakeup_word[shift][MAX_SUPPORTED_LANGUAGE_LEN - 1] = '\0';
- }
- memset(g_maclient_info[loop].wakeup_word[MAX_WAKEUP_WORDS_NUM - 1],
- 0x00, sizeof(g_maclient_info[loop].wakeup_word));
- memset(g_maclient_info[loop].wakeup_language[MAX_WAKEUP_WORDS_NUM - 1],
- 0x00, sizeof(g_maclient_info[loop].wakeup_language));
-
- innerLoop--; /* Just in case there are duplicated items */
- }
- }
- mas_config_save_custom_wake_words(pid_appid,
+ ret = g_config.mas_config_remove_custom_wake_word(wake_word, language,
+ g_maclient_info[loop].wakeup_word,
+ g_maclient_info[loop].wakeup_language);
+ if (0 == ret) {
+ g_config.mas_config_save_custom_wake_words(pid_appid,
g_maclient_info[loop].wakeup_word,
g_maclient_info[loop].wakeup_language);
+ }
}
}
return -1;
}
- if (0 == mas_config_get_assistant_info(__mas_assistant_info_cb, NULL)) {
+ if (0 == g_config.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)) {
- mas_config_load_custom_wake_words(g_maclient_info[loop].appid,
+ g_config.mas_config_load_custom_wake_words(g_maclient_info[loop].appid,
g_maclient_info[loop].wakeup_word, g_maclient_info[loop].wakeup_language);
if (0 < strlen(g_maclient_info[loop].wakeup_engine)) {
multi_assistant_service_plugin_set_assistant_wakeup_engine(
#include <gtest/gtest.h>
+#include "multi_assistant_config.h"
+
+#include <string>
+
class ServiceWithEmptyWakeWord : public testing::Test {
public:
ServiceWithEmptyWakeWord() {
}
virtual ~ServiceWithEmptyWakeWord() {
}
+ void SetUp() override {
+ memset(wakeup_word_storage, 0x0, sizeof(wakeup_word_storage));
+ memset(wakeup_language_storage, 0x0, sizeof(wakeup_language_storage));
+ }
+ void TearDown() override {
+ }
+ CConfig config;
+ char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN];
+ char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN];
};
class ServiceWithAnArbitraryWakeWord : public testing::Test {
}
virtual ~ServiceWithAnArbitraryWakeWord() {
}
+ void SetUp() override {
+ memset(wakeup_word_storage, 0x0, sizeof(wakeup_word_storage));
+ memset(wakeup_language_storage, 0x0, sizeof(wakeup_language_storage));
+
+ strncpy(wakeup_word_storage[0], preloaded_wake_word.c_str(), sizeof(wakeup_word_storage[0]));
+ wakeup_word_storage[0][sizeof(wakeup_word_storage[0]) - 1] = '\0';
+ }
+ void TearDown() override {
+ }
+ const std::string preloaded_wake_word{"Hi Preloaded"};
+ const std::string preloaded_language{"pr_LD"};
+ CConfig config;
+ char wakeup_word_storage[MAX_WAKEUP_WORDS_NUM][MAX_WAKEUP_WORD_LEN];
+ char wakeup_language_storage[MAX_WAKEUP_WORDS_NUM][MAX_SUPPORTED_LANGUAGE_LEN];
};
TEST_F(ServiceWithEmptyWakeWord, HasOneWakeWordAfterAdd) {
+ const std::string arbitrary_wake_word{"Hi Tizen"};
+ const std::string arbitrary_language{"ar_LA"};
+
+ config.mas_config_add_custom_wake_word(
+ arbitrary_wake_word.c_str(), arbitrary_language.c_str(),
+ wakeup_word_storage,
+ wakeup_language_storage);
+
+ int wake_word_num = config.mas_config_get_custom_wake_word_num(
+ wakeup_word_storage, wakeup_language_storage);
+ ASSERT_EQ(wake_word_num, 1);
}
TEST_F(ServiceWithAnArbitraryWakeWord, HasTwoWakeWordsAfterAdd) {
+ const std::string arbitrary_wake_word{"Hi Tizen"};
+ const std::string arbitrary_language{"ar_LA"};
+
+ config.mas_config_add_custom_wake_word(
+ arbitrary_wake_word.c_str(), arbitrary_language.c_str(),
+ wakeup_word_storage,
+ wakeup_language_storage);
+
+ int wake_word_num = config.mas_config_get_custom_wake_word_num(
+ wakeup_word_storage, wakeup_language_storage);
+ ASSERT_EQ(wake_word_num, 2);
}
int main(int argc, char** argv) {