Add API to get the list of the enabled assistants 57/203457/13
authorXie Ligang <ligang0.xie@samsung.com>
Mon, 15 Apr 2019 03:38:31 +0000 (11:38 +0800)
committerXie Ligang <ligang0.xie@samsung.com>
Thu, 18 Apr 2019 06:45:27 +0000 (14:45 +0800)
Change-Id: Ib726c6c749cd8c05a35e4c50a847c67e13f92203
Signed-off-by: Xie Ligang <ligang0.xie@samsung.com>
client/ma.c
include/multi_assistant.h
include/multi_assistant_common.h

index c6563efd512e18073e5331f7b8cee13247903405..0f201d8ef9d625b85789e8bf1f7fdf2f56b06f6c 100644 (file)
@@ -20,6 +20,8 @@
 #include <cynara-session.h>
 #include <Ecore_Wayland.h>
 #include <system_info.h>
+#include <vconf/vconf.h>
+#include <stdlib.h>
 
 
 #include "multi_assistant.h"
 #include "ma_client.h"
 #include "ma_main.h"
 #include "ma_defs.h"
+#include "ma_config_mgr.h"
 
+#define MAX_ASSISTANT_INFO_STR_LEN 128
+#define MAX_ASSISTANT_NUM 10
+#define APPID_URL "db/multi-assistant/enabled_assistants"
 
+typedef struct{
+       char app_id[MAX_ASSISTANT_INFO_STR_LEN];
+       char name[MAX_ASSISTANT_INFO_STR_LEN];
+       int cnt_lang;
+       bool enabled;
+}assistant_info_t;
+
+static assistant_info_t __assistant_info[MAX_ASSISTANT_NUM];
+
+static int _assistant_info_index;
 
 static ma_h g_ma = NULL;
 
@@ -150,7 +166,6 @@ static int __ma_check_privilege()
        return MA_ERROR_NONE;
 }
 
-
 int ma_initialize(void)
 {
        if (0 != __ma_get_feature_enabled()) {
@@ -1332,5 +1347,68 @@ int ma_unset_wakeup_engine_command_cb(void)
 
        ma_client_set_wakeup_engine_command_cb(g_ma, NULL, NULL);
 
+       return MA_ERROR_NONE;
+}
+
+bool __get_assistant_enable_status(const char* app_id, char* assistants) {
+       char* temp = strtok(assistants, ";");
+       while(temp) {
+               if (!strncmp(app_id, temp, MAX_ASSISTANT_INFO_STR_LEN)) {
+                       return true;
+               }
+               temp = strtok(NULL, ";");
+       }
+       return false;
+}
+
+int __get_assistant_info_cb(const char* app_id, const char* name,
+       const char* icon_path, const char* wakeup_list[], int cnt_wakeup,
+       const char* supported_lang[], int cnt_lang, void* user_data) {
+       SLOG(LOG_DEBUG, TAG_MAC, "[Client DEBUG] get assistant info cb start");
+       if (NULL == app_id) {
+               SLOG(LOG_ERROR, TAG_MAC, "[ERROR]app_id NULL, returning");
+               return -1;
+       } else if (0 <= _assistant_info_index && MAX_ASSISTANT_NUM > _assistant_info_index ) {
+               strncpy(__assistant_info[_assistant_info_index].app_id, app_id, MAX_ASSISTANT_INFO_STR_LEN);
+               __assistant_info[_assistant_info_index].app_id[MAX_ASSISTANT_INFO_STR_LEN - 1] = '\0';
+               strncpy(__assistant_info[_assistant_info_index].name, name, MAX_ASSISTANT_INFO_STR_LEN);
+               __assistant_info[_assistant_info_index].name[MAX_ASSISTANT_INFO_STR_LEN - 1] = '\0';
+               __assistant_info[_assistant_info_index].cnt_lang = cnt_lang;
+               __assistant_info[_assistant_info_index].enabled = __get_assistant_enable_status(app_id, vconf_get_str(APPID_URL));;
+               _assistant_info_index++;
+       } else {
+               return -1;
+       }
+       SLOG(LOG_DEBUG, TAG_MAC, "[Client DEBUG] get assistant info cb end");
+       return 0;
+}
+
+int ma_assistant_info_foreach_assistants(ma_assistant_info_list_cb callback, void* user_data) {
+       int res;
+       SLOG(LOG_DEBUG, TAG_MAC, "[Client DEBUG] get assistant info start");
+       if (NULL != callback) {
+               _assistant_info_index = 0;
+               res = ma_config_mgr_get_assistant_info(__get_assistant_info_cb, user_data);
+               if (0 == res) {
+                       for (int i = 0; i < _assistant_info_index; i++) {
+                               callback(&__assistant_info[i], user_data);
+                       }
+               } else {
+                       res = MA_ERROR_NOT_SUPPORTED;
+               }
+       } else {
+               res = MA_ERROR_INVALID_PARAMETER;
+       }
+       SLOG(LOG_DEBUG, TAG_MAC, "[Client DEBUG] get assistant info end");
+       return res;
+}
+
+int ma_assistant_info_get_app_id(ma_assistant_info_h handle, char **app_id) {
+       if (NULL == handle)
+               return MA_ERROR_INVALID_PARAMETER;
+       assistant_info_t* info = (assistant_info_t*)handle;
+       if (NULL == info->app_id)
+               return MA_ERROR_NOT_SUPPORTED;
+       *app_id = (char*)info->app_id;
        return MA_ERROR_NONE;
 }
\ No newline at end of file
index 051406c930758d7c8af2f6c659a6f82052e7357f..309554058015c465f7e101b66a7e311acef2525f 100644 (file)
@@ -20,7 +20,6 @@
 
 #include <multi_assistant_common.h>
 
-
 /**
  * @defgroup CAPI_UIX_MULTI_ASSISTANT_CLIENT_MODULE Multi assistant client
  * @ingroup CAPI_UIX_MULTI_ASSISTANT_MODULE
@@ -482,6 +481,37 @@ int ma_set_wakeup_engine_command_cb(ma_wakeup_engine_command_cb callback, void*
  */
 int ma_unset_wakeup_engine_command_cb(void);
 
+/**
+ * @brief Retreives the list of installed assistants.
+ * @since_tizen 5.5
+ *
+ * @param[in] callback A callback for getting the information of the installed assistants.
+ * @param[in] user_data The user data passed to the callback function
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #MA_ERROR_NONE Successful
+ * @retval #MA_ERROR_NOT_SUPPORTED Not supported
+ * @retval #MA_ERROR_INVALID_STATE Invalid state
+ * @retval #MA_ERROR_INVALID_PARAMETER Invalid parameter
+ *
+ * @see ma_voice_assistant_list_cb()
+ */
+int ma_assistant_info_foreach_assistants(ma_assistant_info_list_cb callback, void* user_data);
+
+/**
+ * @brief Retreives app id of the specific handle.
+ * @since_tizen 5.5
+ *
+ * @remarks You must not release @a app_id using free().
+ * @param[in] handle The handle to the  assistant's information
+ * @param[in] app_id The application ID of the given assistant handle
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #MA_ERROR_NONE Successful
+ * @retval #MA_ERROR_NOT_SUPPORTED Not supported
+ * @retval #MA_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+int ma_assistant_info_get_app_id(ma_assistant_info_h handle, char **app_id);
 #ifdef __cplusplus
 }
 #endif
index b8059b4a37906555075e31301cca678e219cb2a6..94e378e8ebb44f81bde5c9d73ea8a6720394d86f 100644 (file)
@@ -31,8 +31,6 @@ extern "C"
 {
 #endif
 
-
-
 /**
  * @brief Enumerations for multi-assistant error codes.
  * @since_tizen 5.0
@@ -225,6 +223,20 @@ typedef void (*ma_active_state_changed_cb)(ma_active_state_e previous, ma_active
  */
 typedef void (*ma_wakeup_engine_command_cb)(const char *command, void* user_data);
 
+/**
+ * @brief A handle to get assistant information
+ */
+
+typedef void *ma_assistant_info_h;
+
+/**
+ * @brief Called to get the assistant information once for each installed assistant.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The handle of the assistant
+ * @param[in] user_data The user data passed from the callback registration function
+ */
+typedef int (*ma_assistant_info_list_cb)(ma_assistant_info_h handle, void* user_data);
 #ifdef __cplusplus
 }
 #endif