diff options
Diffstat (limited to 'src/plugins/ds-public/plain-text/src/plugin_interface.c')
-rwxr-xr-x | src/plugins/ds-public/plain-text/src/plugin_interface.c | 245 |
1 files changed, 245 insertions, 0 deletions
diff --git a/src/plugins/ds-public/plain-text/src/plugin_interface.c b/src/plugins/ds-public/plain-text/src/plugin_interface.c new file mode 100755 index 0000000..2cc32d1 --- /dev/null +++ b/src/plugins/ds-public/plain-text/src/plugin_interface.c @@ -0,0 +1,245 @@ +/* + * 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. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <memo-db.h> + +#include <sync_agent.h> + +#include "in_datastore_info_plain_text.h" + +#ifndef EXPORT_API +#define EXPORT_API __attribute__ ((visibility("default"))) +#endif + +#ifndef OMADS_AGENT_LOG +#undef LOG_TAG +#define LOG_TAG "PLUGIN_PLAIN_TEXT" +#endif + +static int _free_obj_field_info(sync_agent_plugin_field_info_s * field_list, int count); +static int _set_obj_field_info(sync_agent_plugin_field_info_s ** field_list, int count, plain_text_field_list_s * input_list); +/* +static sync_agent_da_return_e __convert_service_error_to_common_error(int err); +*/ + +EXPORT_API sync_agent_da_return_e sync_agent_plugin_converter(const void *agent_data, void **service_data) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(agent_data == NULL, SYNC_AGENT_DA_ERRORS, "agent_data is NULL"); + + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + struct memo_data *temp_service_data = 0; + char *temp_agent_data = (char *)agent_data; + + /* create item */ + temp_service_data = memo_create_data(); + if (temp_service_data == NULL) { + _DEBUG_INFO("[dc_plain_text_plugIn] memo_create_data() Fail!\n"); + ret = SYNC_AGENT_DA_ERRORS; + *service_data = 0; + } else { + _DEBUG_INFO("[dc_plain_text_plugIn] memo_create_data() Success!\n"); + temp_service_data->content = strdup(temp_agent_data); /* configuration item */ + *service_data = (void *)temp_service_data; + } + + _EXTERN_FUNC_EXIT; + return ret; +} + +EXPORT_API sync_agent_da_return_e sync_agent_plugin_replace_converter(void *old_service_data, const void *agent_data, void **new_service_data) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(old_service_data == NULL, SYNC_AGENT_DA_ERRORS, "old_service_data is NULL"); + retvm_if(agent_data == NULL, SYNC_AGENT_DA_ERRORS, "agent_data is NULL"); + + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + struct memo_data *temp_service_data = (struct memo_data *)old_service_data; + char *temp_agent_data = (char *)agent_data; + + /* set item */ + if (temp_service_data->has_doodle == 0) { + free(temp_service_data->content); + temp_service_data->content = strdup(temp_agent_data); + } else if (temp_service_data->comment != NULL) { + free(temp_service_data->comment); + temp_service_data->comment = strdup(temp_agent_data); + } + *new_service_data = (void *)temp_service_data; + + _EXTERN_FUNC_EXIT; + return ret; +} + +EXPORT_API sync_agent_da_return_e sync_agent_plugin_reverse_converter(void *service_data, void **agent_data) +{ + _EXTERN_FUNC_ENTER; + + retvm_if(service_data == NULL, SYNC_AGENT_DA_ERRORS, "service_data is NULL"); + + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + char *temp_agent_data = 0; + struct memo_data *temp_service_data = (struct memo_data *)service_data; + + /* deep copy */ + if (temp_service_data == NULL) { + _DEBUG_INFO("[dc_plain_text_plugIn] Fail : no data !\n"); + ret = SYNC_AGENT_DA_ERRORS; + *agent_data = 0; + } else if (temp_service_data->has_doodle == 0) { + _DEBUG_INFO("[dc_plain_text_plugIn] Success!\n"); + temp_agent_data = strdup(temp_service_data->content); + *agent_data = (void *)temp_agent_data; + } else if (temp_service_data->comment != NULL) { + _DEBUG_INFO("[dc_plain_text_plugIn] Success!\n"); + temp_agent_data = strdup(temp_service_data->comment); + *agent_data = (void *)temp_agent_data; + } + + /* memory free */ + if (temp_service_data != NULL) + memo_free_data(temp_service_data); + + _EXTERN_FUNC_EXIT; + return ret; +} + +EXPORT_API void *sync_agent_plugin_alloc_object() +{ + _DEBUG_INFO("[da_memo_plugIn] not implement !!"); + return 0; +} + +EXPORT_API int sync_agent_plugin_free_object(void *in_object) +{ + _DEBUG_INFO("[da_memo_plugIn] not implement !!"); + return 0; +} + +EXPORT_API void *sync_agent_plugin_set_value(void *in_object, int key, char *extension_key, void *value) +{ + _DEBUG_INFO("[da_memo_plugIn] not implement !!"); + return 0; +} + +EXPORT_API void *sync_agent_plugin_get_value(void *in_object, int key, char *extension_key) +{ + _DEBUG_INFO("[da_memo_plugIn] not implement !!"); + return 0; +} + +EXPORT_API sync_agent_plugin_object_info_s *sync_agent_plugin_get_obj_info() +{ + _EXTERN_FUNC_ENTER; + + sync_agent_plugin_object_info_s *obj_info = (sync_agent_plugin_object_info_s *) calloc(1, sizeof(sync_agent_plugin_object_info_s)); + if (obj_info == NULL) { + _DEBUG_INFO("CALLOC failed !!!"); + return NULL; + } + + obj_info->type = PLAIN_TEXT_TYPE; + obj_info->version = PLAIN_TEXT_VERSION; + obj_info->field_cnt = sizeof(plain_text_field_list) / sizeof(plain_text_field_list_s); + + if (obj_info->field_cnt > 0) + if (_set_obj_field_info(&(obj_info->field_list), obj_info->field_cnt, plain_text_field_list) == 0) + return NULL; + + _EXTERN_FUNC_EXIT; + return obj_info; +} + +EXPORT_API int sync_agent_plugin_free_obj_info(sync_agent_plugin_object_info_s * obj_info) +{ + _EXTERN_FUNC_ENTER; + + if (obj_info) { + if (obj_info->field_cnt > 0) + if (_free_obj_field_info(obj_info->field_list, obj_info->field_cnt) == 0) + return 0; + + free(obj_info); + } + + _EXTERN_FUNC_EXIT; + return 1; +} + +static int _free_obj_field_info(sync_agent_plugin_field_info_s * field_list, int count) +{ + _INNER_FUNC_ENTER; + + int field_count = 0; + sync_agent_plugin_field_info_s *child = NULL; + + if (field_list != NULL) { + for (field_count = 0; field_count < count; field_count++) { + child = field_list + field_count; + if (child->field_child_cnt > 0) + if (_free_obj_field_info(child->field_child_list, child->field_child_cnt) == 0) + return 0; + } + free(field_list); + } + + _INNER_FUNC_EXIT; + return 1; +} + +static int _set_obj_field_info(sync_agent_plugin_field_info_s ** field_list, int count, plain_text_field_list_s * input_list) +{ + _INNER_FUNC_ENTER; + + int field_count = 0; + sync_agent_plugin_field_info_s *child = NULL; + + *field_list = (sync_agent_plugin_field_info_s *) calloc(count, sizeof(sync_agent_plugin_field_info_s)); + if (*field_list == NULL) { + _DEBUG_ERROR("CALLOC failed !!!"); + return 0; + } + + for (field_count = 0; field_count < count; field_count++) { + child = (*field_list) + field_count; + child->field_name = input_list[field_count].field_name; + _DEBUG_TRACE("[%s]", child->field_name); + } + + _INNER_FUNC_EXIT; + return 1; +} + +/* +static sync_agent_da_return_e __convert_service_error_to_common_error(int err) +{ + sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS; + _DEBUG_INFO("[da_memo_plugIn] Error Code : %d\n", err); + + switch (err) { + default: + ret = SYNC_AGENT_DA_ERRORS; + break; + } + + return ret; +} +*/ |