add comment LCOV_EXCL
[platform/core/pim/calendar-service.git] / common / cal_record_extended.c
1 /*
2  * Calendar Service
3  *
4  * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19
20 #include <stdlib.h>
21 #include <stdbool.h>
22 #include <string.h>
23
24 #include "cal_internal.h"
25 #include "cal_typedef.h"
26 #include "cal_view.h"
27 #include "cal_record.h"
28 #include "cal_utils.h"
29
30 static int _cal_record_extended_create(calendar_record_h* out_record);
31 static int _cal_record_extended_destroy(calendar_record_h record, bool delete_child);
32 static int _cal_record_extended_clone(calendar_record_h record, calendar_record_h* out_record);
33 static int _cal_record_extended_get_str(calendar_record_h record, unsigned int property_id, char** out_str);
34 static int _cal_record_extended_get_str_p(calendar_record_h record, unsigned int property_id, char** out_str);
35 static int _cal_record_extended_get_int(calendar_record_h record, unsigned int property_id, int* out_value);
36 static int _cal_record_extended_set_str(calendar_record_h record, unsigned int property_id, const char* value);
37 static int _cal_record_extended_set_int(calendar_record_h record, unsigned int property_id, int value);
38
39 cal_record_plugin_cb_s cal_record_extended_plugin_cb = {
40         .create = _cal_record_extended_create,
41         .destroy = _cal_record_extended_destroy,
42         .clone = _cal_record_extended_clone,
43         .get_str = _cal_record_extended_get_str,
44         .get_str_p = _cal_record_extended_get_str_p,
45         .get_int = _cal_record_extended_get_int,
46         .get_double = NULL,
47         .get_lli = NULL,
48         .get_caltime = NULL,
49         .set_str = _cal_record_extended_set_str,
50         .set_int = _cal_record_extended_set_int,
51         .set_double = NULL,
52         .set_lli = NULL,
53         .set_caltime = NULL,
54         .add_child_record = NULL,
55         .remove_child_record = NULL,
56         .get_child_record_count = NULL,
57         .get_child_record_at_p = NULL,
58         .clone_child_record_list = NULL
59 };
60
61 static void _cal_record_extended_struct_init(cal_extended_s *record)
62 {
63         memset(record, 0, sizeof(cal_extended_s));
64 }
65
66 static int _cal_record_extended_create(calendar_record_h* out_record)
67 {
68         cal_extended_s *temp = NULL;
69         int ret = CALENDAR_ERROR_NONE;
70
71         temp = calloc(1, sizeof(cal_extended_s));
72         RETVM_IF(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
73
74         _cal_record_extended_struct_init(temp);
75
76         *out_record = (calendar_record_h)temp;
77
78         return ret;
79 }
80
81 static void _cal_record_extended_struct_free(cal_extended_s *record)
82 {
83         CAL_FREE(record->key);
84         CAL_FREE(record->value);
85         CAL_FREE(record);
86
87 }
88
89 static int _cal_record_extended_destroy(calendar_record_h record, bool delete_child)
90 {
91         int ret = CALENDAR_ERROR_NONE;
92
93         cal_extended_s *temp = (cal_extended_s*)(record);
94
95         _cal_record_extended_struct_free(temp);
96
97         return ret;
98 }
99
100 static int _cal_record_extended_clone(calendar_record_h record, calendar_record_h* out_record)
101 {
102         cal_extended_s *out_data = NULL;
103         cal_extended_s *src_data = NULL;
104
105         src_data = (cal_extended_s*)(record);
106
107         out_data = calloc(1, sizeof(cal_extended_s));
108         RETVM_IF(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
109
110         CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
111
112         out_data->id = src_data->id;
113         out_data->record_id = src_data->record_id;
114         out_data->record_type = src_data->record_type;
115         out_data->key = cal_strdup(src_data->key);
116         out_data->value = cal_strdup(src_data->value);
117
118         *out_record = (calendar_record_h)out_data;
119
120         return CALENDAR_ERROR_NONE;
121 }
122
123 static int _cal_record_extended_get_str(calendar_record_h record, unsigned int property_id, char** out_str)
124 {
125         cal_extended_s *rec = (cal_extended_s*)(record);
126         switch (property_id) {
127         case CAL_PROPERTY_EXTENDED_KEY:
128                 *out_str = cal_strdup(rec->key);
129                 break;
130         case CAL_PROPERTY_EXTENDED_VALUE:
131                 *out_str = cal_strdup(rec->value);
132                 break;
133         default:
134                 /* LCOV_EXCL_START */
135                 ERR("invalid parameter (property:0x%x)", property_id);
136                 return CALENDAR_ERROR_INVALID_PARAMETER;
137                 /* LCOV_EXCL_STOP */
138         }
139
140         return CALENDAR_ERROR_NONE;
141 }
142
143 static int _cal_record_extended_get_str_p(calendar_record_h record, unsigned int property_id, char** out_str)
144 {
145         cal_extended_s *rec = (cal_extended_s*)(record);
146         switch (property_id) {
147         case CAL_PROPERTY_EXTENDED_KEY:
148                 *out_str = (rec->key);
149                 break;
150         case CAL_PROPERTY_EXTENDED_VALUE:
151                 *out_str = (rec->value);
152                 break;
153         default:
154                 /* LCOV_EXCL_START */
155                 ERR("invalid parameter (property:0x%x)", property_id);
156                 return CALENDAR_ERROR_INVALID_PARAMETER;
157                 /* LCOV_EXCL_STOP */
158         }
159
160         return CALENDAR_ERROR_NONE;
161 }
162
163 static int _cal_record_extended_get_int(calendar_record_h record, unsigned int property_id, int* out_value)
164 {
165         cal_extended_s *rec = (cal_extended_s*)(record);
166         switch (property_id) {
167         case CAL_PROPERTY_EXTENDED_ID:
168                 *out_value = (rec->id);
169                 break;
170         case CAL_PROPERTY_EXTENDED_RECORD_ID:
171                 *out_value = (rec->record_id);
172                 break;
173         case CAL_PROPERTY_EXTENDED_RECORD_TYPE:
174                 *out_value = (rec->record_type);
175                 break;
176         default:
177                 /* LCOV_EXCL_START */
178                 ERR("invalid parameter (property:0x%x)", property_id);
179                 return CALENDAR_ERROR_INVALID_PARAMETER;
180                 /* LCOV_EXCL_STOP */
181         }
182
183         return CALENDAR_ERROR_NONE;
184 }
185
186 static int _cal_record_extended_set_str(calendar_record_h record, unsigned int property_id, const char* value)
187 {
188         cal_extended_s *rec = (cal_extended_s*)(record);
189         switch (property_id) {
190         case CAL_PROPERTY_EXTENDED_KEY:
191                 CAL_FREE(rec->key);
192                 rec->key = cal_strdup(value);
193                 break;
194         case CAL_PROPERTY_EXTENDED_VALUE:
195                 CAL_FREE(rec->value);
196                 rec->value = cal_strdup(value);
197                 break;
198         default:
199                 /* LCOV_EXCL_START */
200                 ERR("invalid parameter (property:0x%x)", property_id);
201                 return CALENDAR_ERROR_INVALID_PARAMETER;
202                 /* LCOV_EXCL_STOP */
203         }
204
205         return CALENDAR_ERROR_NONE;
206 }
207
208 static int _cal_record_extended_set_int(calendar_record_h record, unsigned int property_id, int value)
209 {
210         cal_extended_s *rec = (cal_extended_s*)(record);
211         switch (property_id) {
212         case CAL_PROPERTY_EXTENDED_ID:
213                 (rec->id) = value;
214                 break;
215         case CAL_PROPERTY_EXTENDED_RECORD_ID:
216                 RETVM_IF(0 < rec->id, CALENDAR_ERROR_INVALID_PARAMETER, "Invalid parameter : property_id(%d) is a write-once value (calendar)", property_id);
217                 (rec->record_id) = value;
218                 break;
219         case CAL_PROPERTY_EXTENDED_RECORD_TYPE:
220                 (rec->record_type) = value;
221                 break;
222         default:
223                 /* LCOV_EXCL_START */
224                 ERR("invalid parameter (property:0x%x)", property_id);
225                 return CALENDAR_ERROR_INVALID_PARAMETER;
226                 /* LCOV_EXCL_STOP */
227         }
228
229         return CALENDAR_ERROR_NONE;
230 }