Apply command priority 40/66940/3
authorky85.kim <ky85.kim@samsung.com>
Fri, 22 Apr 2016 06:29:58 +0000 (15:29 +0900)
committerky85.kim <ky85.kim@samsung.com>
Fri, 22 Apr 2016 07:40:18 +0000 (16:40 +0900)
Add api for filtering command by type

Change-Id: Ib21e77bf9cb681db1572f38840b438a2e34793ac

common/vc_command.c
common/vc_command.h
include/voice_control_command_expand.h
server/vcd_server.c [changed mode: 0755->0644]

index 1925731..293efdb 100644 (file)
@@ -302,6 +302,92 @@ int vc_cmd_list_foreach_commands(vc_cmd_list_h vc_cmd_list, vc_cmd_list_cb callb
        return VC_ERROR_NONE;
 }
 
+int vc_cmd_list_filter_by_type(vc_cmd_list_h original, int type, vc_cmd_list_h* filtered)
+{
+       SLOG(LOG_DEBUG, TAG_VCCMD, "===== Filter by type");
+
+       if (0 != __vc_cmd_get_feature_enabled()) {
+               return VC_ERROR_NOT_SUPPORTED;
+       }
+
+       if (NULL == original) {
+               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Input parameter is NULL");
+               return VC_ERROR_INVALID_PARAMETER;
+       }
+
+       if (VC_COMMAND_TYPE_NONE >= type || VC_COMMAND_TYPE_EXCLUSIVE < type) {
+               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Invalid type");
+               return VC_ERROR_INVALID_PARAMETER;
+       }
+
+       vc_cmd_list_s* list = NULL;
+       list = (vc_cmd_list_s*)original;
+
+       vc_cmd_list_h temp_list;
+       if (0 != vc_cmd_list_create(&temp_list)) {
+               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to list create");
+               return VC_ERROR_OPERATION_FAILED;
+       }
+
+       int count = g_slist_length(list->list);
+       int i;
+
+       GSList *iter = NULL;
+       vc_cmd_s *iter_cmd;
+
+       iter = g_slist_nth(list->list, 0);
+
+       for (i = 0; i < count; i++) {
+               if (NULL != iter->data) {
+                       iter_cmd = iter->data;
+
+                       if (NULL != iter_cmd) {
+                               int iter_type;
+                               if (0 != vc_cmd_get_type((vc_cmd_h)iter_cmd, &iter_type)) {
+                                       SLOG(LOG_ERROR,TAG_VCCMD, "[ERROR] Fail to get command type");
+                                       continue;
+                               }
+
+                               if (iter_type == type) {
+                                       vc_cmd_h temp_cmd;
+                                       if (0 != vc_cmd_create(&temp_cmd)) {
+                                               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to create cmd");
+                                               continue;
+                                       }
+
+                                       memcpy(temp_cmd, iter_cmd, sizeof(vc_cmd_s));
+                                       if (NULL != iter_cmd->command) {
+                                               ((vc_cmd_s*)temp_cmd)->command = strdup(iter_cmd->command);
+                                       }
+                                       if (NULL != iter_cmd->parameter) {
+                                               ((vc_cmd_s*)temp_cmd)->parameter = strdup(iter_cmd->parameter);
+                                       }
+
+                                       if (0 != vc_cmd_list_add(temp_list, temp_cmd)) {
+                                               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to cmd list add");
+                                               vc_cmd_destroy(temp_cmd);
+                                               continue;
+                                       }
+                               }
+                       }
+               }
+               iter = g_slist_next(iter);
+       }
+
+       count = 0;
+       if (0 != vc_cmd_list_get_count(temp_list, &count)) {
+               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Fail to get count");
+       } else {
+               SLOG(LOG_DEBUG, TAG_VCCMD, "Filtering result : (%d) command", count);
+       }
+
+       *filtered = temp_list;
+
+       SLOG(LOG_DEBUG, TAG_VCCMD, "=====");
+
+       return VC_ERROR_NONE;
+}
+
 int vc_cmd_list_first(vc_cmd_list_h vc_cmd_list)
 {
        if (0 != __vc_cmd_get_feature_enabled()) {
index 605edd6..5fc66d4 100644 (file)
@@ -67,24 +67,6 @@ int vc_cmd_get_id(vc_cmd_h vc_command, int* id);
 int vc_cmd_print_list(vc_cmd_list_h vc_cmd_list);
 
 /**
-* @brief Remove all commands from command list.
-* @since_tizen 2.4
-*
-* @param[in] vc_cmd_list The command list handle
-* @param[in] free_command The command free option @c true = release each commands in list,
-*                      @c false = remove command from list
-*
-* @return 0 on success, otherwise a negative error value
-* @retval #VC_CMD_ERROR_NONE Successful
-* @retval #VC_CMD_ERROR_INVALID_PARAMETER Invalid parameter
-* @retval #VC_CMD_ERROR_PERMISSION_DENIED Permission denied
-* @retval #VC_CMD_ERROR_NOT_SUPPORTED Not supported feature
-*
-* @see vc_cmd_list_add()
-*/
-int vc_cmd_list_remove_all(vc_cmd_list_h vc_cmd_list, bool free_command);
-
-/**
 * @brief Sets extra unfixed command.
 * @since_tizen 2.4
 *
index 8200285..03179f9 100644 (file)
@@ -129,6 +129,43 @@ int vc_cmd_set_domain(vc_cmd_h vc_command, int domain);
 */
 int vc_cmd_get_domain(vc_cmd_h vc_command, int* domain);
 
+/**
+* @brief Remove all commands from command list.
+* @since_tizen 2.4
+*
+* @param[in] vc_cmd_list The command list handle
+* @param[in] free_command The command free option @c true = release each commands in list,
+*                      @c false = remove command from list
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #VC_CMD_ERROR_NONE Successful
+* @retval #VC_CMD_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #VC_CMD_ERROR_PERMISSION_DENIED Permission denied
+* @retval #VC_CMD_ERROR_NOT_SUPPORTED Not supported feature
+*
+* @see vc_cmd_list_add()
+*/
+int vc_cmd_list_remove_all(vc_cmd_list_h vc_cmd_list, bool free_command);
+
+/**
+* @brief Retrieves all commands of command list using callback function.
+* @since_tizen 3.0
+*
+* @param[in] vc_cmd_list The command list handle
+* @param[in] callback Callback function to invoke
+* @param[in] user_data The user data to be passed to the callback function
+*
+* @return 0 on success, otherwise a negative error value
+* @retval #VC_ERROR_NONE Successful
+* @retval #VC_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #VC_ERROR_PERMISSION_DENIED Permission denied
+* @retval #VC_ERROR_NOT_SUPPORTED Not supported
+*
+* @post        This function invokes vc_cmd_list_cb() repeatedly for getting commands.
+*
+* @see vc_cmd_list_cb()
+*/
+int vc_cmd_list_filter_by_type(vc_cmd_list_h original, int type, vc_cmd_list_h* filtered);
 
 #ifdef __cplusplus
 }
old mode 100755 (executable)
new mode 100644 (file)
index 345d9f3..cb1dc7d
@@ -244,6 +244,19 @@ static Eina_Bool __vcd_send_selected_result(void *data)
        return EINA_FALSE;
 }
 
+static int __convert_type_to_priority(vc_cmd_type_e type)
+{
+       switch (type) {
+               case VC_COMMAND_TYPE_NONE:              return 0; break;
+               case VC_COMMAND_TYPE_BACKGROUND:        return 1; break;
+               case VC_COMMAND_TYPE_FOREGROUND:        return 2; break;
+               case VC_COMMAND_TYPE_WIDGET:            return 2; break;
+               case VC_COMMAND_TYPE_SYSTEM:            return 3; break;
+               case VC_COMMAND_TYPE_EXCLUSIVE:         return 3; break;
+               default:                                return 0; break;
+       }
+}
+
 static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int count, const char* all_result,
                                                                   const char* non_fixed_result, const char* msg, void *user_data)
 {
@@ -330,7 +343,7 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int
        vc_cmd_list_h vc_cmd_list = NULL;
 
        if (0 != vc_cmd_list_create(&vc_cmd_list)) {
-               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Fail to create command list");
+               SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to create command list");
                vcd_client_manager_set_exclusive(false);
                vcd_config_set_service_state(VCD_STATE_READY);
                vcdc_send_service_state(VCD_STATE_READY);
@@ -338,6 +351,7 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int
        }
 
        int i = 0;
+       int priority = 0;
        for (i = 0; i < count; i++) {
                SLOG(LOG_DEBUG, TAG_VCD, "[Server]   [%d] Result ID(%d)", i, result_id[i]);
 
@@ -348,6 +362,20 @@ static void __vcd_server_result_cb(vcp_result_event_e event, int* result_id, int
 
                ret = vcd_client_get_cmd_from_result_id(result_id[i], &temp_cmd);
                if (0 == ret && NULL != temp_cmd) {
+                       /* Add priority filter */
+                       int temp_priority = __convert_type_to_priority(temp_cmd->type);
+                       if (priority > temp_priority) {
+                               SLOG(LOG_DEBUG, TAG_VCD, "[Server] Ignore result by priority");
+                               continue;
+                       } else if (priority < temp_priority) {
+                               SLOG(LOG_DEBUG, TAG_VCD, "[Server] High priority result!!");
+                               priority = temp_priority;
+
+                               if (0 != vc_cmd_list_remove_all(vc_cmd_list, true)) {
+                                       SLOG(LOG_ERROR, TAG_VCD, "[Server] Fail to list remove all");
+                               }
+                       }
+
                        switch (temp_cmd->format) {
                        case VC_CMD_FORMAT_FIXED:
                                /* Nonfixed result is NOT valid */