Use std::vector and std::string instead of arrays 37/304837/1
authorJi-hoon Lee <dalton.lee@samsung.com>
Wed, 24 Jan 2024 07:29:33 +0000 (16:29 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Wed, 24 Jan 2024 07:29:33 +0000 (16:29 +0900)
Change-Id: I5b1a194c39f3f807a039a837efb1e6fafd93f9c4

inc/client_info.h
inc/service_common.h
inc/service_config.h
inc/service_main.h
src/package_update_monitor.cpp
src/service_config.cpp
src/service_main.cpp
src/service_plugin.cpp

index fd6da21..95711b2 100644 (file)
 
 #include "service_common.h"
 
-#define MAX_MACLIENT_INFO_NUM 16
+#include <boost/optional.hpp>
+#include <string>
+#include <vector>
+
+#define MAX_MACLIENT_INFO_NUM ((size_t)16)
 
 typedef struct {
        bool used{false};
-       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_WAKEUP_ENGINES_NUM][MAX_APPID_LEN];
-       char supported_language[MAX_SUPPORTED_LANGUAGES_NUM][MAX_SUPPORTED_LANGUAGE_LEN];
+       std::string appid;
+       std::vector<std::string> wakeup_word;
+       std::vector<std::string> wakeup_language;
+       std::vector<std::string> wakeup_engine;
+       std::vector<std::string> supported_language;
        bool custom_ui_option{false};
        VOICE_KEY_SUPPORT_MODE voice_key_support_mode{VOICE_KEY_SUPPORT_MODE_PUSH_TO_TALK};
        float voice_key_tap_duration{0.0f};
 
        ma_preprocessing_allow_mode_e preprocessing_allow_mode{MA_PREPROCESSING_ALLOW_NONE};
-       char preprocessing_allow_appid[MAX_APPID_LEN];
+       boost::optional<std::string> preprocessing_allow_appid;
 
        boost::optional<std::string> audio_processing_appid;
 } ClientInfoItems;
@@ -47,11 +51,11 @@ public:
        CClientInfo() {}
        virtual ~CClientInfo() {}
 
-       ClientInfoItems* getItems() { return mItems; }
-       void resetItems() { memset(&mItems, 0x00, sizeof(mItems)); }
+       std::vector<ClientInfoItems>& getItems() { return mItems; }
+       void resetItems() { mItems.clear(); }
 
 private:
-       ClientInfoItems mItems[MAX_MACLIENT_INFO_NUM];
+       std::vector<ClientInfoItems> mItems;
 };
 
 #endif /* __CLIENT_INFO_H__ */
index 25444d6..a2011e9 100644 (file)
@@ -125,13 +125,13 @@ typedef void (*wakeup_service_voice_key_status_changed_cb)(ma_voice_key_status_e
 
 typedef void (*wakeup_service_loaded_engine_changed_cb)(void *user_data);
 
-#define MAX_WAKEUP_WORDS_NUM 255
-#define MAX_WAKEUP_WORD_LEN 32
-#define MAX_SUPPORTED_LANGUAGES_NUM 255
-#define MAX_SUPPORTED_LANGUAGE_LEN 16
-#define MAX_WAKEUP_ENGINES_NUM 4
+#define MAX_WAKEUP_WORDS_NUM ((size_t)255)
+#define MAX_WAKEUP_WORD_LEN ((size_t)32)
+#define MAX_SUPPORTED_LANGUAGES_NUM ((size_t)255)
+#define MAX_SUPPORTED_LANGUAGE_LEN ((size_t)16)
+#define MAX_WAKEUP_ENGINES_NUM ((size_t)4)
 
-#define MAX_APPID_LEN 255
+#define MAX_APPID_LEN ((size_t)255)
 
 typedef enum {
        VOICE_KEY_SUPPORT_MODE_NONE,
index ff6620c..a951c5f 100644 (file)
@@ -24,6 +24,7 @@
 #include "service_common.h"
 
 #include <string>
+#include <vector>
 #include <boost/optional.hpp>
 
 /**************************************************************************************
@@ -100,23 +101,23 @@ public:
        int get_assistant_info(service_config_assistant_info_cb callback, void* user_data);
 
        int 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);
        int 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);
        int 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);
        int 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);
        int 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);
        bool 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);
 private:
        int parse_assistant_info(service_config_assistant_info_cb callback,
                const char *path, void* user_data);
index 5d774f9..0472bf9 100644 (file)
@@ -119,9 +119,9 @@ public:
        boost::optional<std::string> get_current_audio_processing_appid();
 
        int get_client_pid_by_wakeup_word(const char *wakeup_word);
-       const char* get_client_appid_by_wakeup_word(const char *wakeup_word);
+       boost::optional<std::string> get_client_appid_by_wakeup_word(const char *wakeup_word);
 
-       int get_client_pid_by_appid(const char *appid);
+       int get_client_pid_by_appid(boost::optional<std::string> appid);
        std::string get_client_appid_by_pid(pid_t pid);
 
        bool get_client_custom_ui_option_by_appid(const char *appid);
@@ -137,7 +137,7 @@ public:
 
        int prelaunch_default_assistant();
        int set_current_service_state(ma_service_state_e state);
-       int bring_client_to_foreground(const char* appid);
+       int bring_client_to_foreground(boost::optional<std::string> appid);
        ma_service_state_e get_current_service_state();
        int process_preprocessing_state_event(PREPROCESSING_STATE_EVENT event);
        int update_voice_key_support_mode();
@@ -189,8 +189,8 @@ public:
        bool is_voice_assistant(const pkgmgrinfo_appinfo_h handle);
 private:
        bool check_preprocessing_assistant_exists();
-       ma_preprocessing_allow_mode_e get_preprocessing_allow_mode(const char* appid);
-       bool is_current_preprocessing_assistant(const char* appid);
+       ma_preprocessing_allow_mode_e get_preprocessing_allow_mode(boost::optional<std::string> appid);
+       bool is_current_preprocessing_assistant(boost::optional<std::string> appid);
        bool is_current_assistant(pid_t pid);
 
 private:
index c2c74ff..b966321 100644 (file)
@@ -75,7 +75,7 @@ static bool is_wakeup_engine(const pkgmgrinfo_appinfo_h handle, CPackageUpdateMo
                        if (clientInfo.getItems()[loop].used) {
                                for (int inner_loop = 0;inner_loop < MAX_WAKEUP_ENGINES_NUM;inner_loop++) {
                                        LOGI("comparing appid : %s %s", clientInfo.getItems()[loop].wakeup_engine[inner_loop], appid);
-                                       if (0 == strncmp(clientInfo.getItems()[loop].wakeup_engine[inner_loop], appid, MAX_APPID_LEN)) {
+                                       if (0 == clientInfo.getItems()[loop].wakeup_engine[inner_loop].compare(appid)) {
                                                is_wakeup_engine = true;
                                        }
                                }
index efd5682..98ee653 100644 (file)
@@ -266,23 +266,21 @@ int CServiceConfig::get_assistant_info(service_config_assistant_info_cb callback
 }
 
 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;
                }
        }
@@ -294,27 +292,24 @@ int CServiceConfig::add_custom_wake_word(const char* wake_word, const char* lang
 }
 
 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;
@@ -325,11 +320,14 @@ int CServiceConfig::remove_custom_wake_word(const char* wake_word, const char* l
 }
 
 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)];
@@ -372,8 +370,12 @@ int CServiceConfig::load_custom_wake_words(const char* app_id,
                *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)",
@@ -385,23 +387,27 @@ int CServiceConfig::load_custom_wake_words(const char* app_id,
 }
 
 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));
                }
@@ -414,27 +420,27 @@ int CServiceConfig::save_custom_wake_words(const char* app_id,
 }
 
 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;
                }
        }
index 8dda168..a6ccc73 100644 (file)
@@ -67,10 +67,10 @@ bool CServiceMain::check_preprocessing_assistant_exists()
        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;
                                }
@@ -87,25 +87,23 @@ bool CServiceMain::check_preprocessing_assistant_exists()
 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;
 
@@ -378,22 +376,26 @@ int CServiceMain::client_set_background_volume(pid_t pid, double ratio)
 
 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;
                                }
                        }
                }
@@ -406,30 +408,27 @@ int CServiceMain::client_set_preprocessing_allow_mode(pid_t pid, ma_preprocessin
 
 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);
        }
 
@@ -468,8 +467,8 @@ int CServiceMain::client_add_wake_word(pid_t pid, const char* wake_word, const c
                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,
@@ -498,8 +497,8 @@ int CServiceMain::client_remove_wake_word(pid_t pid, const char* wake_word, cons
                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,
@@ -547,9 +546,9 @@ int CServiceMain::ui_client_change_assistant(const char* appid)
        }
 
        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);
@@ -568,13 +567,13 @@ int CServiceMain::ui_client_change_assistant(const char* appid)
                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);
                                }
                        }
@@ -607,59 +606,57 @@ int CServiceMain::add_assistant_info(ma_assistant_info_s* info) {
 
        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;
@@ -731,38 +728,41 @@ int CServiceMain::initialize_service_plugin(void)
        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");
                                                }
                                        }
@@ -817,9 +817,9 @@ int CServiceMain::process_activated_setting()
                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 {
@@ -869,12 +869,9 @@ pid_t CServiceMain::get_current_audio_processing_pid()
 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;
 }
@@ -882,12 +879,9 @@ boost::optional<std::string> CServiceMain::get_current_client_appid()
 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;
 }
@@ -895,24 +889,24 @@ boost::optional<std::string> CServiceMain::get_current_preprocessing_client_appi
 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;
        }
@@ -923,12 +917,12 @@ pid_t CServiceMain::get_client_pid_by_appid(const char *appid)
 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;
                        }
                }
@@ -938,24 +932,24 @@ bool CServiceMain::get_client_custom_ui_option_by_appid(const char *appid)
 
 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;
                                        }
                                }
@@ -964,17 +958,19 @@ const char* CServiceMain::get_client_appid_by_wakeup_word(const char *wakeup_wor
        }
 
        /* 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)) {
@@ -997,13 +993,13 @@ int CServiceMain::set_current_client_by_wakeup_word(const char *wakeup_word)
        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;
@@ -1014,11 +1010,11 @@ int CServiceMain::set_current_client_by_wakeup_word(const char *wakeup_word)
        }
        /* 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++) {
@@ -1038,12 +1034,12 @@ int CServiceMain::set_current_client_by_wakeup_word(const char *wakeup_word)
        }
 
        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;
                        }
                }
@@ -1059,12 +1055,12 @@ int CServiceMain::set_current_client_by_appid(const char *appid)
        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;
@@ -1073,12 +1069,12 @@ int CServiceMain::set_current_client_by_appid(const char *appid)
        }
 
        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;
                        }
                }
@@ -1112,11 +1108,11 @@ int CServiceMain::launch_client_by_appid(const char *appid, const char *word,
 
        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) {
@@ -1138,17 +1134,17 @@ int CServiceMain::launch_client_by_appid(const char *appid, const char *word,
        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;
        }
 
@@ -1158,8 +1154,8 @@ int CServiceMain::bring_client_to_foreground(const char* appid)
 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);
 }
 
@@ -1189,12 +1185,12 @@ int CServiceMain::update_voice_key_support_mode()
        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);
@@ -1217,12 +1213,12 @@ int CServiceMain::update_voice_key_support_mode()
        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;
                        }
                }
@@ -1235,10 +1231,10 @@ ma_preprocessing_allow_mode_e CServiceMain::get_preprocessing_allow_mode(const c
 
 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;
        }
@@ -1368,12 +1364,12 @@ ma_service_state_e CServiceMain::get_current_service_state()
 
 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;
                                }
                        }
@@ -1503,9 +1499,9 @@ int CServiceMain::on_initialize(pid_t pid, std::string sender_info) {
 
                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;
                }
 
@@ -1513,7 +1509,7 @@ int CServiceMain::on_initialize(pid_t pid, std::string sender_info) {
                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)) {
@@ -1706,12 +1702,12 @@ int CServiceMain::on_ap_start_streaming_audio_data(std::string ap_appid, int typ
        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;
index 0f0454b..93af57b 100644 (file)
@@ -152,7 +152,9 @@ static void process_wakeup_event_by_appid_timer(void* data)
                }
 
                service_main->set_current_client_by_appid(wakeup_appid);
-               if ((pid = service_main->get_client_pid_by_appid(wakeup_appid)) != -1) {
+               boost::optional<std::string> appid;
+               if (wakeup_appid) appid = wakeup_appid;
+               if ((pid = service_main->get_client_pid_by_appid(appid)) != -1) {
                        service_main->client_send_preprocessing_information(pid);
                        service_ipc->change_active_state(pid, MA_ACTIVE_STATE_ACTIVE, wakeup_word,
                                extra_data, extra_data_length, extra_data_desc);
@@ -196,7 +198,7 @@ static void process_wakeup_event_by_word_timer(void* data)
                        memcpy(extra_data, param->extra_data, extra_data_length);
        }
        std::string extra_data_desc{param->extra_data_desc ? param->extra_data_desc : ""};
-       const char* appid = nullptr;
+       boost::optional<std::string> appid;
        int id = param->id;
        CServicePlugin* plugin = param->plugin;
        CServiceMain* service_main = nullptr;
@@ -220,7 +222,7 @@ static void process_wakeup_event_by_word_timer(void* data)
                if (param) {
                        param->id = id;
                        param->wakeup_word = strdup(wakeup_word.c_str());
-                       param->wakeup_appid = strdup(appid);
+                       param->wakeup_appid = strdup(appid.value().c_str());
                        if (extra_data && extra_data_length > 0) {
                                param->extra_data = (unsigned char*)malloc(extra_data_length);
                                if (param->extra_data)
@@ -602,7 +604,9 @@ static void __wakeup_engine_command_cb(mas_wakeup_engine_command_target_e target
        CServiceIpcDbus *service_ipc = plugin->get_service_ipc();
        CServiceMain* service_main = plugin->get_service_main();
        if (service_ipc && service_main) {
-               pid_t pid = service_main->get_client_pid_by_appid(assistant_name);
+               boost::optional<std::string> name;
+               if (assistant_name) name = assistant_name;
+               pid_t pid = service_main->get_client_pid_by_appid(name);
                if (-1 != pid) {
                        int ret = service_ipc->send_wakeup_engine_command(pid, command);
                        if (0 != ret) {