3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
22 #include <sync_agent.h>
24 #include "in_datastore_info_plain_text.h"
27 #define EXPORT_API __attribute__ ((visibility("default")))
30 #ifndef OMADS_AGENT_LOG
32 #define LOG_TAG "PLUGIN_PLAIN_TEXT"
35 static int _free_obj_field_info(sync_agent_plugin_field_info_s * field_list, int count);
36 static int _set_obj_field_info(sync_agent_plugin_field_info_s ** field_list, int count, plain_text_field_list_s * input_list);
38 static sync_agent_da_return_e __convert_service_error_to_common_error(int err);
41 EXPORT_API sync_agent_da_return_e sync_agent_plugin_converter(const void *agent_data, void **service_data)
45 retvm_if(agent_data == NULL, SYNC_AGENT_DA_ERRORS, "agent_data is NULL");
47 sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
48 struct memo_data *temp_service_data = 0;
49 char *temp_agent_data = (char *)agent_data;
52 temp_service_data = memo_create_data();
53 if (temp_service_data == NULL) {
54 _DEBUG_INFO("[dc_plain_text_plugIn] memo_create_data() Fail!\n");
55 ret = SYNC_AGENT_DA_ERRORS;
58 _DEBUG_INFO("[dc_plain_text_plugIn] memo_create_data() Success!\n");
59 temp_service_data->content = strdup(temp_agent_data); /* configuration item */
60 *service_data = (void *)temp_service_data;
67 EXPORT_API sync_agent_da_return_e sync_agent_plugin_replace_converter(void *old_service_data, const void *agent_data, void **new_service_data)
71 retvm_if(old_service_data == NULL, SYNC_AGENT_DA_ERRORS, "old_service_data is NULL");
72 retvm_if(agent_data == NULL, SYNC_AGENT_DA_ERRORS, "agent_data is NULL");
74 sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
75 struct memo_data *temp_service_data = (struct memo_data *)old_service_data;
76 char *temp_agent_data = (char *)agent_data;
79 if (temp_service_data->has_doodle == 0) {
80 free(temp_service_data->content);
81 temp_service_data->content = strdup(temp_agent_data);
82 } else if (temp_service_data->comment != NULL) {
83 free(temp_service_data->comment);
84 temp_service_data->comment = strdup(temp_agent_data);
86 *new_service_data = (void *)temp_service_data;
92 EXPORT_API sync_agent_da_return_e sync_agent_plugin_reverse_converter(void *service_data, void **agent_data)
96 retvm_if(service_data == NULL, SYNC_AGENT_DA_ERRORS, "service_data is NULL");
98 sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
99 char *temp_agent_data = 0;
100 struct memo_data *temp_service_data = (struct memo_data *)service_data;
103 if (temp_service_data == NULL) {
104 _DEBUG_INFO("[dc_plain_text_plugIn] Fail : no data !\n");
105 ret = SYNC_AGENT_DA_ERRORS;
107 } else if (temp_service_data->has_doodle == 0) {
108 _DEBUG_INFO("[dc_plain_text_plugIn] Success!\n");
109 temp_agent_data = strdup(temp_service_data->content);
110 *agent_data = (void *)temp_agent_data;
111 } else if (temp_service_data->comment != NULL) {
112 _DEBUG_INFO("[dc_plain_text_plugIn] Success!\n");
113 temp_agent_data = strdup(temp_service_data->comment);
114 *agent_data = (void *)temp_agent_data;
118 if (temp_service_data != NULL)
119 memo_free_data(temp_service_data);
125 EXPORT_API void *sync_agent_plugin_alloc_object()
127 _DEBUG_INFO("[da_memo_plugIn] not implement !!");
131 EXPORT_API int sync_agent_plugin_free_object(void *in_object)
133 _DEBUG_INFO("[da_memo_plugIn] not implement !!");
137 EXPORT_API void *sync_agent_plugin_set_value(void *in_object, int key, char *extension_key, void *value)
139 _DEBUG_INFO("[da_memo_plugIn] not implement !!");
143 EXPORT_API void *sync_agent_plugin_get_value(void *in_object, int key, char *extension_key)
145 _DEBUG_INFO("[da_memo_plugIn] not implement !!");
149 EXPORT_API sync_agent_plugin_object_info_s *sync_agent_plugin_get_obj_info()
153 sync_agent_plugin_object_info_s *obj_info = (sync_agent_plugin_object_info_s *) calloc(1, sizeof(sync_agent_plugin_object_info_s));
154 if (obj_info == NULL) {
155 _DEBUG_INFO("CALLOC failed !!!");
159 obj_info->type = PLAIN_TEXT_TYPE;
160 obj_info->version = PLAIN_TEXT_VERSION;
161 obj_info->field_cnt = sizeof(plain_text_field_list) / sizeof(plain_text_field_list_s);
163 if (obj_info->field_cnt > 0)
164 if (_set_obj_field_info(&(obj_info->field_list), obj_info->field_cnt, plain_text_field_list) == 0)
171 EXPORT_API int sync_agent_plugin_free_obj_info(sync_agent_plugin_object_info_s * obj_info)
176 if (obj_info->field_cnt > 0)
177 if (_free_obj_field_info(obj_info->field_list, obj_info->field_cnt) == 0)
187 static int _free_obj_field_info(sync_agent_plugin_field_info_s * field_list, int count)
192 sync_agent_plugin_field_info_s *child = NULL;
194 if (field_list != NULL) {
195 for (field_count = 0; field_count < count; field_count++) {
196 child = field_list + field_count;
197 if (child->field_child_cnt > 0)
198 if (_free_obj_field_info(child->field_child_list, child->field_child_cnt) == 0)
208 static int _set_obj_field_info(sync_agent_plugin_field_info_s ** field_list, int count, plain_text_field_list_s * input_list)
213 sync_agent_plugin_field_info_s *child = NULL;
215 *field_list = (sync_agent_plugin_field_info_s *) calloc(count, sizeof(sync_agent_plugin_field_info_s));
216 if (*field_list == NULL) {
217 _DEBUG_ERROR("CALLOC failed !!!");
221 for (field_count = 0; field_count < count; field_count++) {
222 child = (*field_list) + field_count;
223 child->field_name = input_list[field_count].field_name;
224 _DEBUG_TRACE("[%s]", child->field_name);
232 static sync_agent_da_return_e __convert_service_error_to_common_error(int err)
234 sync_agent_da_return_e ret = SYNC_AGENT_DA_SUCCESS;
235 _DEBUG_INFO("[da_memo_plugIn] Error Code : %d\n", err);
239 ret = SYNC_AGENT_DA_ERRORS;