Resolved Native API Reference issues for calendar-service
[platform/core/pim/calendar-service.git] / common / cal_record_timezone.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_timezone_create(calendar_record_h* out_record);
31 static int _cal_record_timezone_destroy(calendar_record_h record, bool delete_child);
32 static int _cal_record_timezone_clone(calendar_record_h record, calendar_record_h* out_record);
33 static int _cal_record_timezone_get_str(calendar_record_h record, unsigned int property_id, char** out_str);
34 static int _cal_record_timezone_get_str_p(calendar_record_h record, unsigned int property_id, char** out_str);
35 static int _cal_record_timezone_get_int(calendar_record_h record, unsigned int property_id, int* out_value);
36 static int _cal_record_timezone_set_str(calendar_record_h record, unsigned int property_id, const char* value);
37 static int _cal_record_timezone_set_int(calendar_record_h record, unsigned int property_id, int value);
38
39 cal_record_plugin_cb_s cal_record_timezone_plugin_cb = {
40         .create = _cal_record_timezone_create,
41         .destroy = _cal_record_timezone_destroy,
42         .clone = _cal_record_timezone_clone,
43         .get_str = _cal_record_timezone_get_str,
44         .get_str_p = _cal_record_timezone_get_str_p,
45         .get_int = _cal_record_timezone_get_int,
46         .get_double = NULL,
47         .get_lli = NULL,
48         .get_caltime = NULL,
49         .set_str = _cal_record_timezone_set_str,
50         .set_int = _cal_record_timezone_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_timezone_struct_init(cal_timezone_s *record)
62 {
63         memset(record, 0, sizeof(cal_timezone_s));
64         record->calendar_id = DEFAULT_EVENT_CALENDAR_BOOK_ID;
65 }
66
67 static int _cal_record_timezone_create(calendar_record_h* out_record)
68 {
69         cal_timezone_s *temp = NULL;
70         int ret = CALENDAR_ERROR_NONE;
71
72         temp = calloc(1, sizeof(cal_timezone_s));
73         RETVM_IF(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
74
75         _cal_record_timezone_struct_init(temp);
76
77         *out_record = (calendar_record_h)temp;
78
79         return ret;
80 }
81
82 static void _cal_record_timezone_struct_free(cal_timezone_s *record)
83 {
84         CAL_FREE(record->standard_name);
85         CAL_FREE(record->day_light_name);
86         CAL_FREE(record);
87
88 }
89
90 static int _cal_record_timezone_destroy(calendar_record_h record, bool delete_child)
91 {
92         int ret = CALENDAR_ERROR_NONE;
93
94         cal_timezone_s *temp = (cal_timezone_s*)(record);
95
96         _cal_record_timezone_struct_free(temp);
97
98         return ret;
99 }
100
101 static int _cal_record_timezone_clone(calendar_record_h record, calendar_record_h* out_record)
102 {
103         cal_timezone_s *out_data = NULL;
104         cal_timezone_s *src_data = NULL;
105
106         src_data = (cal_timezone_s*)(record);
107
108         out_data = calloc(1, sizeof(cal_timezone_s));
109         RETVM_IF(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
110
111         CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
112
113         out_data->index = src_data->index;
114         out_data->tz_offset_from_gmt = src_data->tz_offset_from_gmt;
115         out_data->standard_name = cal_strdup(src_data->standard_name);
116         out_data->std_start_month = src_data->std_start_month;
117         out_data->std_start_position_of_week = src_data->std_start_position_of_week;
118         out_data->std_start_day = src_data->std_start_day;
119         out_data->std_start_hour = src_data->std_start_hour;
120         out_data->standard_bias = src_data->standard_bias;
121         out_data->day_light_name = cal_strdup(src_data->day_light_name);
122         out_data->day_light_start_month = src_data->day_light_start_month;
123         out_data->day_light_start_position_of_week = src_data->day_light_start_position_of_week;
124         out_data->day_light_start_day = src_data->day_light_start_day;
125         out_data->day_light_start_hour = src_data->day_light_start_hour;
126         out_data->day_light_bias = src_data->day_light_bias;
127         out_data->calendar_id = src_data->calendar_id;
128
129         *out_record = (calendar_record_h)out_data;
130
131         return CALENDAR_ERROR_NONE;
132 }
133
134 static int _cal_record_timezone_get_str(calendar_record_h record, unsigned int property_id, char** out_str)
135 {
136         cal_timezone_s *rec = (cal_timezone_s*)(record);
137         switch (property_id) {
138         case CAL_PROPERTY_TIMEZONE_STANDARD_NAME:
139                 *out_str = cal_strdup(rec->standard_name);
140                 break;
141         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_NAME:
142                 *out_str = cal_strdup(rec->day_light_name);
143                 break;
144         default:
145                 /* LCOV_EXCL_START */
146                 ERR("invalid parameter (property:0x%x)", property_id);
147                 return CALENDAR_ERROR_INVALID_PARAMETER;
148                 /* LCOV_EXCL_STOP */
149         }
150
151         return CALENDAR_ERROR_NONE;
152 }
153
154 static int _cal_record_timezone_get_str_p(calendar_record_h record, unsigned int property_id, char** out_str)
155 {
156         cal_timezone_s *rec = (cal_timezone_s*)(record);
157         switch (property_id) {
158         case CAL_PROPERTY_TIMEZONE_STANDARD_NAME:
159                 *out_str = (rec->standard_name);
160                 break;
161         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_NAME:
162                 *out_str = (rec->day_light_name);
163                 break;
164         default:
165                 /* LCOV_EXCL_START */
166                 ERR("invalid parameter (property:0x%x)", property_id);
167                 return CALENDAR_ERROR_INVALID_PARAMETER;
168                 /* LCOV_EXCL_STOP */
169         }
170
171         return CALENDAR_ERROR_NONE;
172 }
173
174 static int _cal_record_timezone_get_int(calendar_record_h record, unsigned int property_id, int* out_value)
175 {
176         cal_timezone_s *rec = (cal_timezone_s*)(record);
177         switch (property_id) {
178         case CAL_PROPERTY_TIMEZONE_ID:
179                 *out_value = (rec->index);
180                 break;
181         case CAL_PROPERTY_TIMEZONE_TZ_OFFSET_FROM_GMT:
182                 *out_value = (rec->tz_offset_from_gmt);
183                 break;
184         case CAL_PROPERTY_TIMEZONE_STD_START_MONTH:
185                 *out_value = (rec->std_start_month);
186                 break;
187         case CAL_PROPERTY_TIMEZONE_STD_START_POSITION_OF_WEEK:
188                 *out_value = (rec->std_start_position_of_week);
189                 break;
190         case CAL_PROPERTY_TIMEZONE_STD_START_DAY:
191                 *out_value = (rec->std_start_day);
192                 break;
193         case CAL_PROPERTY_TIMEZONE_STD_START_HOUR:
194                 *out_value = (rec->std_start_hour);
195                 break;
196         case CAL_PROPERTY_TIMEZONE_STANDARD_BIAS:
197                 *out_value = (rec->standard_bias);
198                 break;
199         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_MONTH:
200                 *out_value = (rec->day_light_start_month);
201                 break;
202         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_POSITION_OF_WEEK:
203                 *out_value = (rec->day_light_start_position_of_week);
204                 break;
205         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_DAY:
206                 *out_value = (rec->day_light_start_day);
207                 break;
208         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_HOUR:
209                 *out_value = (rec->day_light_start_hour);
210                 break;
211         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_BIAS:
212                 *out_value = (rec->day_light_bias);
213                 break;
214         case CAL_PROPERTY_TIMEZONE_CALENDAR_ID:
215                 *out_value = (rec->calendar_id);
216                 break;
217         default:
218                 /* LCOV_EXCL_START */
219                 ERR("invalid parameter (property:0x%x)", property_id);
220                 return CALENDAR_ERROR_INVALID_PARAMETER;
221                 /* LCOV_EXCL_STOP */
222         }
223
224         return CALENDAR_ERROR_NONE;
225 }
226
227 static int _cal_record_timezone_set_str(calendar_record_h record, unsigned int property_id, const char* value)
228 {
229         cal_timezone_s *rec = (cal_timezone_s*)(record);
230         switch (property_id) {
231         case CAL_PROPERTY_TIMEZONE_STANDARD_NAME:
232                 CAL_FREE(rec->standard_name);
233                 rec->standard_name = cal_strdup(value);
234                 break;
235         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_NAME:
236                 CAL_FREE(rec->day_light_name);
237                 rec->day_light_name = cal_strdup(value);
238                 break;
239         default:
240                 /* LCOV_EXCL_START */
241                 ERR("invalid parameter (property:0x%x)", property_id);
242                 return CALENDAR_ERROR_INVALID_PARAMETER;
243                 /* LCOV_EXCL_STOP */
244         }
245
246         return CALENDAR_ERROR_NONE;
247 }
248
249 static int _cal_record_timezone_set_int(calendar_record_h record, unsigned int property_id, int value)
250 {
251         cal_timezone_s *rec = (cal_timezone_s*)(record);
252         switch (property_id) {
253         case CAL_PROPERTY_TIMEZONE_ID:
254                 (rec->index) = value;
255                 break;
256         case CAL_PROPERTY_TIMEZONE_TZ_OFFSET_FROM_GMT:
257                 (rec->tz_offset_from_gmt) = value;
258                 break;
259         case CAL_PROPERTY_TIMEZONE_STD_START_MONTH:
260                 (rec->std_start_month) = value;
261                 break;
262         case CAL_PROPERTY_TIMEZONE_STD_START_POSITION_OF_WEEK:
263                 (rec->std_start_position_of_week) = value;
264                 break;
265         case CAL_PROPERTY_TIMEZONE_STD_START_DAY:
266                 (rec->std_start_day) = value;
267                 break;
268         case CAL_PROPERTY_TIMEZONE_STD_START_HOUR:
269                 (rec->std_start_hour) = value;
270                 break;
271         case CAL_PROPERTY_TIMEZONE_STANDARD_BIAS:
272                 (rec->standard_bias) = value;
273                 break;
274         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_MONTH:
275                 (rec->day_light_start_month) = value;
276                 break;
277         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_POSITION_OF_WEEK:
278                 (rec->day_light_start_position_of_week) = value;
279                 break;
280         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_DAY:
281                 (rec->day_light_start_day) = value;
282                 break;
283         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_HOUR:
284                 (rec->day_light_start_hour) = value;
285                 break;
286         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_BIAS:
287                 (rec->day_light_bias) = value;
288                 break;
289         case CAL_PROPERTY_TIMEZONE_CALENDAR_ID:
290                 (rec->calendar_id) = value;
291                 break;
292         default:
293                 /* LCOV_EXCL_START */
294                 ERR("invalid parameter (property:0x%x)", property_id);
295                 return CALENDAR_ERROR_INVALID_PARAMETER;
296                 /* LCOV_EXCL_STOP */
297         }
298
299         return CALENDAR_ERROR_NONE;
300 }