diff options
Diffstat (limited to 'src/agent/service-adapter/sa_command.c')
-rwxr-xr-x | src/agent/service-adapter/sa_command.c | 1016 |
1 files changed, 1016 insertions, 0 deletions
diff --git a/src/agent/service-adapter/sa_command.c b/src/agent/service-adapter/sa_command.c new file mode 100755 index 0000000..7a65503 --- /dev/null +++ b/src/agent/service-adapter/sa_command.c @@ -0,0 +1,1016 @@ +/* + * oma-ds-agent + * Copyright (c) 2012 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @SA_Command.c + * @version 0.1 + * @brief This file is the source file of implementation of functions for command structure which is used in Service Adapter + */ + +#include <stdlib.h> + +#include <sync_agent.h> + +#include "service-adapter/sa_command.h" +#include "service-adapter/sa_command_internal.h" +#include "service-adapter/sa_elements.h" +#include "service-adapter/sa_elements_internal.h" +#include "service-adapter/sa_session.h" +#include "service-adapter/sa_session_internal.h" + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "OMA_DS_SA" +#endif + +static command_s *_create_command(session_s * session, command_type_e type); + +static command_s *_create_command(session_s * session, command_type_e type) +{ + _INNER_FUNC_ENTER; + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (session == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (!type) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + command_s *cmd = (command_s *) calloc(1, sizeof(command_s)); + if (cmd == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + cmd->type = type; + cmd->msg_id = session->msg_id; + cmd->cmd_id = session->cmd_id; + cmd->ref_count = 1; + + session->cmd_id++; + + _INNER_FUNC_EXIT; + return cmd; + + error: + _INNER_FUNC_EXIT; + return NULL; +} + +void free_commands(GList * commands) +{ + _EXTERN_FUNC_ENTER; + + retm_if(commands == NULL, "List is NULL"); + + _DEBUG_INFO("start list length is %d", g_list_length(commands)); + + GList *iter = NULL; + command_s *pCommand = NULL; + for (iter = commands; iter != NULL;) { + pCommand = iter->data; + _DEBUG_INFO("command list length is %d command type is %d\n", g_list_length(commands), pCommand->type); + + iter = g_list_next(iter); + if (pCommand->type != COMMAND_TYPE_UNKNOWN) { + commands = g_list_remove(commands, pCommand); + free_command(pCommand); + } + } + + g_list_free(commands); + + _EXTERN_FUNC_EXIT; + return; +} + +sa_error_type_e create_alert_command(session_s * session, alert_type_e sync_type, location_s * source, location_s * target, char *last_anchor, char *next_anchor, cred_s * cred, command_s ** command) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start with syncType =%d", sync_type); + + sa_error_type_e errorType = SA_INTERNAL_OK; + anchor_s *pAnchor = NULL; + + if (source == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (target == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *command = _create_command(session, COMMAND_TYPE_ALERT); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->target = target; + (*command)->source = source; + + /*TODO check that sync Type is ALERT_NEXT_MESSAGE(does not need last and next anchor) */ + /*TODO check that sync Type is ALERT_SLOW_SYNC(does not need last anchor) */ + + if (next_anchor != NULL) { + errorType = create_anchor(last_anchor, next_anchor, &pAnchor); + if (errorType != SA_INTERNAL_OK) + goto error; + + (*command)->private.alert.anchor = pAnchor; + pAnchor = NULL; + } + + if (cred != NULL) + (*command)->cred = dup_cred(cred); + + (*command)->private.alert.type = sync_type; + + _EXTERN_FUNC_EXIT; + return errorType; + + error: + + if (pAnchor != NULL) + free_anchor(pAnchor); + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e create_get_command(session_s * session, location_s * target, const char *content_type, command_s ** command) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start with content type = %s", content_type); + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (target == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *command = _create_command(session, COMMAND_TYPE_GET); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->private.access.item = create_item(); + if ((*command)->private.access.item == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + set_item_target((*command)->private.access.item, target); + + if (content_type != NULL) + (*command)->private.access.item->content_type = strdup(content_type); + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e create_put_command(session_s * session, location_s * source, const char *content_type, devinf_s * devinf, command_s ** command) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start with content type = %s", content_type); + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (source == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *command = _create_command(session, COMMAND_TYPE_PUT); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->private.access.item = create_item_for_devinf(devinf); + + if ((*command)->private.access.item == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + set_item_source((*command)->private.access.item, source); + + if (content_type != NULL) + (*command)->private.access.item->content_type = strdup(content_type); + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e create_results_command(session_s * session, location_s * source, const char *content_type, devinf_s * devinf, command_s ** command) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start with content type = %s", content_type); + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (source == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *command = _create_command(session, COMMAND_TYPE_RESULTS); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->private.results.item = create_item_for_devinf(devinf); + + if ((*command)->private.results.item == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + set_item_source((*command)->private.results.item, source); + + if (content_type != NULL) + (*command)->private.results.item->content_type = strdup(content_type); + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e create_sync_start_command(session_s * session, location_s * source, location_s * target, command_s ** command) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (source == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (target == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *command = _create_command(session, COMMAND_TYPE_SYNC_START); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->source = source; + (*command)->target = target; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e set_sync_start_command_number_of_changes(command_s * command, unsigned int number_of_changes) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (command == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + command->private.sync.has_num_changed = 1; + command->private.sync.num_changed = number_of_changes; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e set_sync_start_command_mem(command_s * command, mem_s * mem) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (command == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + command->private.sync.mem = mem; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; + +} + +sa_error_type_e create_sync_end_command(command_s ** command) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + *command = (command_s *) calloc(1, sizeof(command_s)); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->type = COMMAND_TYPE_SYNC_END; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e create_add_command(session_s * session, change_type_e type, char *luid, const char *content_type, char *data, unsigned int size, int more_data, command_s ** command) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start with ChangeType = %d content type = %s", type, content_type); + + sa_error_type_e errorType = SA_INTERNAL_OK; + item_s *temp = NULL; + location_s *pLocation = NULL; + + *command = _create_command(session, COMMAND_TYPE_ADD); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + temp = create_item_for_data(data, size); + if (!temp) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->private.change.type = type; + if (content_type != NULL) + temp->content_type = strdup(content_type); + temp->more_data = more_data; + + errorType = create_location(luid, NULL, &pLocation); + if (errorType != SA_INTERNAL_OK) + goto error; + + set_item_source(temp, pLocation); + (*command)->private.change.items = g_list_append((*command)->private.change.items, temp); + temp = NULL; + + error: + + if (temp != NULL) + free(temp); + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e create_replace_command(session_s * session, change_type_e type, char *luid, const char *content_type, const char *data, unsigned int size, int more_data, command_s ** command) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start with ChangeType = %d content type = %s", type, content_type); + + sa_error_type_e errorType = SA_INTERNAL_OK; + item_s *temp = NULL; + location_s *pLocation = NULL; + + *command = _create_command(session, COMMAND_TYPE_REPLACE); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + temp = create_item_for_data(data, size); + if (!temp) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->private.change.type = type; + if (content_type != NULL) + temp->content_type = strdup(content_type); + temp->more_data = more_data; + + errorType = create_location(luid, NULL, &pLocation); + if (errorType != SA_INTERNAL_OK) + goto error; + + set_item_source(temp, pLocation); + (*command)->private.change.items = g_list_append((*command)->private.change.items, temp); + temp = NULL; + + error: + + if (temp != NULL) + free(temp); + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e create_delete_command(session_s * session, change_type_e type, char *luid, const char *content_type, command_s ** command) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start with ChangeType = %d content type = %s", type, content_type); + + sa_error_type_e errorType = SA_INTERNAL_OK; + item_s *temp = NULL; + location_s *pLocation = NULL; + + *command = _create_command(session, COMMAND_TYPE_DELETE); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + temp = create_item(); + if (temp == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->private.change.type = type; + + errorType = create_location(luid, NULL, &pLocation); + if (errorType != SA_INTERNAL_OK) + goto error; + + set_item_source(temp, pLocation); + if (content_type != NULL) + temp->content_type = strdup(content_type); + (*command)->private.change.items = g_list_append((*command)->private.change.items, temp); + temp = NULL; + + error: + + if (temp != NULL) + free(temp); + + _EXTERN_FUNC_EXIT; + return errorType; + +} + +sa_error_type_e create_map_command(session_s * session, location_s * source, location_s * target, command_s ** command) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (source == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + if (target == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + *command = _create_command(session, COMMAND_TYPE_MAP); + if (*command == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*command)->source = source; + (*command)->target = target; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e set_map_command_item(command_s * map_command, item_s * temp) +{ + _EXTERN_FUNC_ENTER; + + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (map_command == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + map_command->private.map.items = g_list_append(map_command->private.map.items, temp); + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e increase_command_ref_count(command_s * command) +{ + _EXTERN_FUNC_ENTER; + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (command == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + command->ref_count++; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e decrease_command_ref_count(command_s * command) +{ + _EXTERN_FUNC_ENTER; + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (command == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + command->ref_count--; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e set_results_command_msg_ref(command_s * command, unsigned int msg_ref) +{ + _EXTERN_FUNC_ENTER; + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (command == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + command->private.results.msg_ref = msg_ref; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e set_results_command_cmd_ref(command_s * command, unsigned int cmd_ref) +{ + _EXTERN_FUNC_ENTER; + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (command == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + command->private.results.cmd_ref = cmd_ref; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e set_results_command_target_ref(command_s * command, location_s * location) +{ + _EXTERN_FUNC_ENTER; + sa_error_type_e errorType = SA_INTERNAL_OK; + + if (command == NULL) { + errorType = SA_INTERNAL_NOT_DEFINED; + goto error; + } + + _DEBUG_INFO("start with Command Type =%d\n", command->type); + + command->private.results.target_ref = dup_location(location); + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +void free_command(command_s * command) +{ + _EXTERN_FUNC_ENTER; + + retm_if(command == NULL, "pCommand is NULL"); + + _DEBUG_INFO("start with Command type is %d", command->type); + + GList *iter = NULL; + + if (command->ref_count > 1) { + _DEBUG_INFO("Command's refCount is %d", command->ref_count); + decrease_command_ref_count(command); + return; + } + + switch (command->type) { + case COMMAND_TYPE_ALERT: + if (command->private.alert.anchor != NULL) { + free_anchor(command->private.alert.anchor); + command->private.alert.anchor = NULL; + } + + if (command->private.alert.content_type != NULL) { + free(command->private.alert.content_type); + command->private.alert.content_type = NULL; + } + break; + case COMMAND_TYPE_SYNC_START: + /*nothing to free */ + break; + case COMMAND_TYPE_SYNC_END: + /*nothing to free */ + break; + case COMMAND_TYPE_PUT: + if (command->private.access.type != NULL) { + free(command->private.access.type); + command->private.access.type = NULL; + } + + if (command->private.access.item != NULL) { + free_item(command->private.access.item); + command->private.access.item = NULL; + } + break; + case COMMAND_TYPE_HEADER: + /*COMMAND_TYPE_HEADER doesnot come here */ + break; + case COMMAND_TYPE_ADD: + case COMMAND_TYPE_REPLACE: + case COMMAND_TYPE_DELETE: + for (iter = command->private.change.items; iter != NULL; iter = g_list_next(iter)) + free_item(iter->data); + break; + case COMMAND_TYPE_MAP: + for (iter = command->private.map.items; iter != NULL; iter = g_list_next(iter)) + free_item(iter->data); + break; + case COMMAND_TYPE_GET: + if (command->private.access.type != NULL) { + free(command->private.access.type); + command->private.access.type = NULL; + } + + if (command->private.access.item != NULL) { + free_item(command->private.access.item); + command->private.access.item = NULL; + } + break; + case COMMAND_TYPE_RESULTS: + if (command->private.results.type != NULL) { + free(command->private.results.type); + command->private.results.type = NULL; + } + + if (command->private.results.item != NULL) { + free_item(command->private.results.item); + command->private.results.item = NULL; + } + + if (command->private.results.target_ref != NULL) { + free_location(command->private.results.target_ref); + command->private.results.target_ref = NULL; + } + + break; + case COMMAND_TYPE_UNKNOWN: + break; + } + + if (command->source != NULL) { + free_location(command->source); + command->source = NULL; + } + + if (command->target != NULL) { + free_location(command->target); + command->target = NULL; + } + + if (command->cred != NULL) { + free_cred(command->cred); + command->cred = NULL; + } + + free(command); + + _EXTERN_FUNC_EXIT; +} + +sa_error_type_e create_new_status_location(session_s * session, oma_status_type_e data, command_s * command, location_s * source_ref, location_s * target_ref, command_type_e type, status_s ** status) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start Errortype %d", data); + + sa_error_type_e errorType = SA_INTERNAL_OK; + + errorType = create_status(data, session->cmd_id, session->last_recieved_msg_id, command->cmd_id, source_ref, target_ref, type, status); + if (errorType != SA_INTERNAL_OK) + goto error; + + session->cmd_id++; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e create_new_status(session_s * session, oma_status_type_e data, command_s * command, command_type_e type, status_s ** status) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start Errortype %d", data); + + sa_error_type_e errorType = SA_INTERNAL_OK; + + errorType = create_status(data, session->cmd_id, session->last_recieved_msg_id, command->cmd_id, command->source, command->target, type, status); + if (errorType != SA_INTERNAL_OK) + goto error; + + session->cmd_id++; + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +sa_error_type_e create_status(oma_status_type_e data, unsigned int cmd_id, unsigned int msg_ref, unsigned int cmd_ref, location_s * source_ref, location_s * target_ref, command_type_e type, status_s ** status) +{ + _EXTERN_FUNC_ENTER; + _DEBUG_INFO("start Errortype %d", data); + + sa_error_type_e errorType = SA_INTERNAL_OK; + + *status = (status_s *) calloc(1, sizeof(status_s)); + if (*status == NULL) { + errorType = SA_INTERNAL_NO_MEMORY; + goto error; + } + + (*status)->cmd_id = cmd_id; + (*status)->msg_ref = msg_ref; + (*status)->cmd_ref = cmd_ref; + (*status)->type = type; + (*status)->data = g_strdup_printf("%d", data); + + if (source_ref != NULL) + (*status)->source_ref = dup_location(source_ref); + + if (target_ref != NULL) + (*status)->target_ref = dup_location(target_ref); + + error: + + _EXTERN_FUNC_EXIT; + return errorType; +} + +void free_statuses(GList * statuses) +{ + _EXTERN_FUNC_ENTER; + + retm_if(statuses == NULL, "List is NULL"); + + GList *iter = NULL; + status_s *status = NULL; + _DEBUG_INFO("count : %d", g_list_length(statuses)); + for (iter = statuses; iter != NULL; iter = g_list_next(iter)) { + status = (status_s *) iter->data; + free_status(status); + } + + g_list_free(statuses); + + _EXTERN_FUNC_EXIT; +} + +void free_status(status_s * status) +{ + _EXTERN_FUNC_ENTER; + + retm_if(status == NULL, "pStatus is NULL"); + + if (status->data != NULL) + free(status->data); + + if (status->source_ref != NULL) + free_location(status->source_ref); + + if (status->target_ref != NULL) + free_location(status->target_ref); + + if (status->cred != NULL) + free_cred(status->cred); + + if (status->chal != NULL) + free_chal(status->chal); + + free_item(status->item); + + free(status); + status = NULL; + + _EXTERN_FUNC_EXIT; +} + +oma_status_type_e get_status_code(status_s * status) +{ + _EXTERN_FUNC_ENTER; + + _EXTERN_FUNC_EXIT; + + return atoi(status->data); +} + +command_type_e convert_command_type(char *type) +{ + _EXTERN_FUNC_ENTER; + + command_type_e commandType = COMMAND_TYPE_UNKNOWN; + + retvm_if(type == NULL, commandType, "type is NULL"); + + if (!strcmp(type, "Alert")) { + commandType = COMMAND_TYPE_ALERT; + } else if (!strcmp(type, "Sync")) { + commandType = COMMAND_TYPE_SYNC_START; + } else if (!strcmp(type, "Put")) { + commandType = COMMAND_TYPE_PUT; + } else if (!strcmp(type, "SyncHdr")) { + commandType = COMMAND_TYPE_HEADER; + } else if (!strcmp(type, "Add")) { + commandType = COMMAND_TYPE_ADD; + } else if (!strcmp(type, "Replace")) { + commandType = COMMAND_TYPE_REPLACE; + } else if (!strcmp(type, "Map")) { + commandType = COMMAND_TYPE_MAP; + } else if (!strcmp(type, "Delete")) { + commandType = COMMAND_TYPE_DELETE; + } else if (!strcmp(type, "Results")) { + commandType = COMMAND_TYPE_RESULTS; + } else if (!strcmp(type, "Get")) { + commandType = COMMAND_TYPE_GET; + } + + _EXTERN_FUNC_EXIT; + return commandType; +} + +change_type_e convert_change_type_command_type(command_type_e type) +{ + _EXTERN_FUNC_ENTER; + + change_type_e changeType = CHANGE_UNKNOWN; + switch (type) { + case COMMAND_TYPE_UNKNOWN: + case COMMAND_TYPE_ALERT: + case COMMAND_TYPE_SYNC_START: + case COMMAND_TYPE_SYNC_END: + case COMMAND_TYPE_PUT: + case COMMAND_TYPE_HEADER: + case COMMAND_TYPE_MAP: + case COMMAND_TYPE_GET: + case COMMAND_TYPE_RESULTS: + /*never comes these commands */ + break; + case COMMAND_TYPE_ADD: + changeType = CHANGE_ADD; + break; + case COMMAND_TYPE_REPLACE: + changeType = CHANGE_REPLACE; + break; + case COMMAND_TYPE_DELETE: + changeType = CHANGE_DELETE; + break; + } + + _EXTERN_FUNC_EXIT; + return changeType; +} + +command_type_e convert_command_type_change_type(change_type_e type) +{ + _EXTERN_FUNC_ENTER; + + command_type_e commandType = COMMAND_TYPE_UNKNOWN; + + switch (type) { + case CHANGE_UNKNOWN: + commandType = COMMAND_TYPE_UNKNOWN; + break; + case CHANGE_ADD: + commandType = COMMAND_TYPE_ADD; + break; + case CHANGE_REPLACE: + commandType = COMMAND_TYPE_REPLACE; + break; + case CHANGE_DELETE: + commandType = COMMAND_TYPE_DELETE; + break; + } + + _EXTERN_FUNC_EXIT; + return commandType; +} + +/* +ChangeType convertToChangeType(unsigned int type) { + + ChangeType changeType=CHANGE_UNKNOWN; + switch (type) { + case 1: + changeType = CHANGE_ADD; + break; + case 2: + changeType = CHANGE_REPLACE; + break; + case 3: + changeType = CHANGE_DELETE; + break; + } + + return changeType; +} + +char *convertFromCommandType(CommandType type) { + char *commandType=NULL; + + switch (type) { + case COMMAND_TYPE_ALERT: + commandType = "Alert"; + break; + case COMMAND_TYPE_SYNC_START: + case COMMAND_TYPE_SYNC_END: + commandType = "Sync"; + break; + case COMMAND_TYPE_PUT: + commandType = "Put"; + break; + case COMMAND_TYPE_HEADER: + commandType = "SyncHdr"; + break; + case COMMAND_TYPE_ADD: + commandType = "Add"; + break; + case COMMAND_TYPE_REPLACE: + commandType = "Replace"; + break; + case COMMAND_TYPE_MAP: + commandType = "Map"; + break; + case COMMAND_TYPE_DELETE: + commandType = "Delete"; + break; + case COMMAND_TYPE_RESULTS: + commandType = "Results"; + break; + case COMMAND_TYPE_GET: + commandType = "Get"; + break; + default: + commandType="UNKNOWN"; + } + return commandType; +} +*/ |