From: Xie Ligang Date: Mon, 15 Apr 2019 03:38:31 +0000 (+0800) Subject: Add API to get the list of the enabled assistants X-Git-Tag: submit/tizen/20190424.111132~4^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a1ec29998fc99adbba9a7900882cf7fb38d384d7;p=platform%2Fcore%2Fuifw%2Fmulti-assistant.git Add API to get the list of the enabled assistants Change-Id: Ib726c6c749cd8c05a35e4c50a847c67e13f92203 Signed-off-by: Xie Ligang --- diff --git a/client/ma.c b/client/ma.c index c6563ef..0f201d8 100644 --- a/client/ma.c +++ b/client/ma.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include "multi_assistant.h" @@ -27,8 +29,22 @@ #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 diff --git a/include/multi_assistant.h b/include/multi_assistant.h index 051406c..3095540 100644 --- a/include/multi_assistant.h +++ b/include/multi_assistant.h @@ -20,7 +20,6 @@ #include - /** * @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 diff --git a/include/multi_assistant_common.h b/include/multi_assistant_common.h index b8059b4..94e378e 100644 --- a/include/multi_assistant_common.h +++ b/include/multi_assistant_common.h @@ -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