summaryrefslogtreecommitdiff
path: root/src/plugins/ds-public/plain-text/src/plugin_interface.c
blob: 2cc32d1e6382f12e46c5848182c6b45d1ba7be55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
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;
}
*/