4 * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
24 #include "cal_internal.h"
25 #include "cal_typedef.h"
27 #include "cal_record.h"
28 #include "cal_utils.h"
30 static int _cal_record_search_create(calendar_record_h* out_record);
31 static int _cal_record_search_destroy(calendar_record_h record, bool delete_child);
32 static int _cal_record_search_clone(calendar_record_h record, calendar_record_h* out_record);
33 static int _cal_record_search_get_str(calendar_record_h record, unsigned int property_id, char** out_str);
34 static int _cal_record_search_get_str_p(calendar_record_h record, unsigned int property_id, char** out_str);
35 static int _cal_record_search_get_int(calendar_record_h record, unsigned int property_id, int* out_value);
36 static int _cal_record_search_get_double(calendar_record_h record, unsigned int property_id, double* out_value);
37 static int _cal_record_search_get_lli(calendar_record_h record, unsigned int property_id, long long int* out_value);
38 static int _cal_record_search_get_caltime(calendar_record_h record, unsigned int property_id, calendar_time_s* out_value);
39 static int _cal_record_search_set_str(calendar_record_h record, unsigned int property_id, const char* value);
40 static int _cal_record_search_set_int(calendar_record_h record, unsigned int property_id, int value);
41 static int _cal_record_search_set_double(calendar_record_h record, unsigned int property_id, double value);
42 static int _cal_record_search_set_lli(calendar_record_h record, unsigned int property_id, long long int value);
43 static int _cal_record_search_set_caltime(calendar_record_h record, unsigned int property_id, calendar_time_s value);
45 cal_record_plugin_cb_s cal_record_search_plugin_cb = {
46 .create = _cal_record_search_create,
47 .destroy = _cal_record_search_destroy,
48 .clone = _cal_record_search_clone,
49 .get_str = _cal_record_search_get_str,
50 .get_str_p = _cal_record_search_get_str_p,
51 .get_int = _cal_record_search_get_int,
52 .get_double = _cal_record_search_get_double,
53 .get_lli = _cal_record_search_get_lli,
54 .get_caltime = _cal_record_search_get_caltime,
55 .set_str = _cal_record_search_set_str,
56 .set_int = _cal_record_search_set_int,
57 .set_double = _cal_record_search_set_double,
58 .set_lli = _cal_record_search_set_lli,
59 .set_caltime = _cal_record_search_set_caltime,
60 .add_child_record = NULL,
61 .remove_child_record = NULL,
62 .get_child_record_count = NULL,
63 .get_child_record_at_p = NULL,
64 .clone_child_record_list = NULL
67 static int _cal_record_search_create(calendar_record_h* out_record)
69 cal_search_s *temp = NULL;
70 int ret = CALENDAR_ERROR_NONE;
72 temp = calloc(1, sizeof(cal_search_s));
73 RETVM_IF(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
75 *out_record = (calendar_record_h)temp;
80 static int _cal_record_search_destroy(calendar_record_h record, bool delete_child)
82 int ret = CALENDAR_ERROR_NONE;
85 cal_search_s *temp = (cal_search_s*)(record);
87 for (cursor = temp->values; cursor; cursor = cursor->next) {
88 cal_search_value_s *data = cursor->data;
89 if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_STR) == true)
90 CAL_FREE(data->value.s);
95 g_slist_free(temp->values);
101 static int _cal_record_search_clone(calendar_record_h record, calendar_record_h* out_record)
103 cal_search_s *out_data = NULL;
104 cal_search_s *src_data = NULL;
107 src_data = (cal_search_s*)(record);
109 out_data = calloc(1, sizeof(cal_search_s));
110 RETVM_IF(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
112 CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
114 for (cursor = src_data->values; cursor; cursor = cursor->next) {
115 cal_search_value_s *src = cursor->data;
116 cal_search_value_s *dest = calloc(1, sizeof(cal_search_value_s));
119 return CALENDAR_ERROR_OUT_OF_MEMORY;
121 dest->property_id = src->property_id;
122 if (CAL_PROPERTY_CHECK_DATA_TYPE(src->property_id, CAL_PROPERTY_DATA_TYPE_STR) == true) {
123 dest->value.s = cal_strdup(src->value.s);
124 } else if (CAL_PROPERTY_CHECK_DATA_TYPE(src->property_id, CAL_PROPERTY_DATA_TYPE_INT) == true) {
125 dest->value.i = src->value.i;
126 } else if (CAL_PROPERTY_CHECK_DATA_TYPE(src->property_id, CAL_PROPERTY_DATA_TYPE_DOUBLE) == true) {
127 dest->value.d = src->value.d;
128 } else if (CAL_PROPERTY_CHECK_DATA_TYPE(src->property_id, CAL_PROPERTY_DATA_TYPE_LLI) == true) {
129 dest->value.lli = src->value.lli;
130 } else if (CAL_PROPERTY_CHECK_DATA_TYPE(src->property_id, CAL_PROPERTY_DATA_TYPE_CALTIME) == true) {
131 dest->value.caltime = src->value.caltime;
137 out_data->values = g_slist_append(out_data->values, dest);
140 *out_record = (calendar_record_h)out_data;
142 return CALENDAR_ERROR_NONE;
145 static int _cal_record_search_get_str(calendar_record_h record, unsigned int property_id, char** out_str)
147 cal_search_s *rec = (cal_search_s*)(record);
150 for (cursor = rec->values; cursor; cursor = cursor->next) {
151 cal_search_value_s *data = cursor->data;
152 if (data->property_id == property_id) {
153 if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_STR) == true) {
154 *out_str = cal_strdup(data->value.s);
157 /* LCOV_EXCL_START */
158 ERR("invalid parameter (property:0x%x)", data->property_id);
159 return CALENDAR_ERROR_INVALID_PARAMETER;
165 return CALENDAR_ERROR_NONE;
168 static int _cal_record_search_get_str_p(calendar_record_h record, unsigned int property_id, char** out_str)
170 cal_search_s *rec = (cal_search_s*)(record);
173 for (cursor = rec->values; cursor; cursor = cursor->next) {
174 cal_search_value_s *data = cursor->data;
175 if (data->property_id == property_id) {
176 if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_STR) == true) {
177 *out_str = (data->value.s);
180 /* LCOV_EXCL_START */
181 ERR("invalid parameter (property:0x%x)", data->property_id);
182 return CALENDAR_ERROR_INVALID_PARAMETER;
188 return CALENDAR_ERROR_NONE;
191 static int _cal_record_search_get_int(calendar_record_h record, unsigned int property_id, int* out_value)
193 cal_search_s *rec = (cal_search_s*)(record);
196 for (cursor = rec->values; cursor; cursor = cursor->next) {
197 cal_search_value_s *data = cursor->data;
198 if (data->property_id == property_id) {
199 if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_INT) == true) {
200 *out_value = (data->value.i);
203 /* LCOV_EXCL_START */
204 ERR("invalid parameter (property:0x%x)", data->property_id);
205 return CALENDAR_ERROR_INVALID_PARAMETER;
211 return CALENDAR_ERROR_NONE;
214 static int _cal_record_search_get_double(calendar_record_h record, unsigned int property_id, double* out_value)
216 cal_search_s *rec = (cal_search_s*)(record);
219 for (cursor = rec->values; cursor; cursor = cursor->next) {
220 cal_search_value_s *data = cursor->data;
221 if (data->property_id == property_id) {
222 if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_DOUBLE) == true) {
223 *out_value = (data->value.d);
226 /* LCOV_EXCL_START */
227 ERR("invalid parameter (property:0x%x)", data->property_id);
228 return CALENDAR_ERROR_INVALID_PARAMETER;
234 return CALENDAR_ERROR_NONE;
237 static int _cal_record_search_get_lli(calendar_record_h record, unsigned int property_id, long long int* out_value)
239 cal_search_s *rec = (cal_search_s*)(record);
242 for (cursor = rec->values; cursor; cursor = cursor->next) {
243 cal_search_value_s *data = cursor->data;
244 if (data->property_id == property_id) {
245 if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_LLI) == true) {
246 *out_value = (data->value.lli);
249 /* LCOV_EXCL_START */
250 ERR("invalid parameter (property:0x%x)", data->property_id);
251 return CALENDAR_ERROR_INVALID_PARAMETER;
257 return CALENDAR_ERROR_NONE;
260 static int _cal_record_search_get_caltime(calendar_record_h record, unsigned int property_id, calendar_time_s* out_value)
262 cal_search_s *rec = (cal_search_s*)(record);
265 for (cursor = rec->values; cursor; cursor = cursor->next) {
266 cal_search_value_s *data = cursor->data;
267 if (data->property_id == property_id) {
268 if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_CALTIME) == true) {
269 *out_value = (data->value.caltime);
272 /* LCOV_EXCL_START */
273 ERR("invalid parameter (property:0x%x)", data->property_id);
274 return CALENDAR_ERROR_INVALID_PARAMETER;
280 return CALENDAR_ERROR_NONE;
283 static int _cal_record_search_set_str(calendar_record_h record, unsigned int property_id, const char* value)
285 cal_search_s *rec = (cal_search_s*)(record);
287 cal_search_value_s *data = NULL;
289 for (cursor = rec->values; cursor; cursor = cursor->next) {
291 if (data->property_id == property_id) {
292 if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_STR) == true) {
293 CAL_FREE(data->value.s);
294 (data->value.s) = cal_strdup(value);
295 return CALENDAR_ERROR_NONE;
297 /* LCOV_EXCL_START */
298 ERR("invalid parameter (property:0x%x)", data->property_id);
299 return CALENDAR_ERROR_INVALID_PARAMETER;
305 data = calloc(1, sizeof(cal_search_value_s));
306 RETVM_IF(NULL == data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
307 data->property_id = property_id;
308 data->value.s = cal_strdup(value);
309 rec->values = g_slist_append(rec->values, data);
311 return CALENDAR_ERROR_NONE;
314 static int _cal_record_search_set_int(calendar_record_h record, unsigned int property_id, int value)
316 cal_search_s *rec = (cal_search_s*)(record);
318 cal_search_value_s *data = NULL;
320 for (cursor = rec->values; cursor; cursor = cursor->next) {
322 if (data->property_id == property_id) {
323 if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_INT) == true) {
324 (data->value.i) = value;
325 return CALENDAR_ERROR_NONE;
327 /* LCOV_EXCL_START */
328 ERR("invalid parameter (property:0x%x)", data->property_id);
329 return CALENDAR_ERROR_INVALID_PARAMETER;
335 data = calloc(1, sizeof(cal_search_value_s));
336 RETVM_IF(NULL == data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
337 data->property_id = property_id;
338 (data->value.i) = value;
339 rec->values = g_slist_append(rec->values, data);
341 return CALENDAR_ERROR_NONE;
344 static int _cal_record_search_set_double(calendar_record_h record, unsigned int property_id, double value)
346 cal_search_s *rec = (cal_search_s*)(record);
348 cal_search_value_s *data = NULL;
350 for (cursor = rec->values; cursor; cursor = cursor->next) {
352 if (data->property_id == property_id) {
353 if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_DOUBLE) == true) {
354 (data->value.d) = value;
355 return CALENDAR_ERROR_NONE;
357 /* LCOV_EXCL_START */
358 ERR("invalid parameter (property:0x%x)", data->property_id);
359 return CALENDAR_ERROR_INVALID_PARAMETER;
365 data = calloc(1, sizeof(cal_search_value_s));
366 RETVM_IF(NULL == data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_search_s) Fail");
367 data->property_id = property_id;
368 (data->value.d) = value;
369 rec->values = g_slist_append(rec->values, data);
371 return CALENDAR_ERROR_NONE;
374 static int _cal_record_search_set_lli(calendar_record_h record, unsigned int property_id, long long int value)
376 cal_search_s *rec = (cal_search_s*)(record);
378 cal_search_value_s *data = NULL;
380 for (cursor = rec->values; cursor; cursor = cursor->next) {
382 if (data->property_id == property_id) {
383 if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_LLI) == true) {
384 (data->value.lli) = value;
385 return CALENDAR_ERROR_NONE;
387 /* LCOV_EXCL_START */
388 ERR("invalid parameter (property:0x%x)", data->property_id);
389 return CALENDAR_ERROR_INVALID_PARAMETER;
395 data = calloc(1, sizeof(cal_search_value_s));
396 RETVM_IF(NULL == data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
397 data->property_id = property_id;
398 (data->value.lli) = value;
399 rec->values = g_slist_append(rec->values, data);
401 return CALENDAR_ERROR_NONE;
404 static int _cal_record_search_set_caltime(calendar_record_h record, unsigned int property_id, calendar_time_s value)
406 cal_search_s *rec = (cal_search_s*)(record);
408 cal_search_value_s *data = NULL;
410 for (cursor = rec->values; cursor; cursor = cursor->next) {
412 if (data->property_id == property_id) {
413 if (CAL_PROPERTY_CHECK_DATA_TYPE(data->property_id, CAL_PROPERTY_DATA_TYPE_CALTIME) == true) {
414 (data->value.caltime) = value;
415 return CALENDAR_ERROR_NONE;
417 /* LCOV_EXCL_START */
418 ERR("invalid parameter (property:0x%x)", data->property_id);
419 return CALENDAR_ERROR_INVALID_PARAMETER;
425 data = calloc(1, sizeof(cal_search_value_s));
426 RETVM_IF(NULL == data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
427 data->property_id = property_id;
428 (data->value.caltime) = value;
429 rec->values = g_slist_append(rec->values, data);
431 return CALENDAR_ERROR_NONE;