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_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);
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,
49 .set_str = _cal_record_timezone_set_str,
50 .set_int = _cal_record_timezone_set_int,
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
61 static void _cal_record_timezone_struct_init(cal_timezone_s *record)
63 memset(record, 0, sizeof(cal_timezone_s));
64 record->calendar_id = DEFAULT_EVENT_CALENDAR_BOOK_ID;
67 static int _cal_record_timezone_create(calendar_record_h* out_record)
69 cal_timezone_s *temp = NULL;
70 int ret = CALENDAR_ERROR_NONE;
72 temp = calloc(1, sizeof(cal_timezone_s));
73 RETVM_IF(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
75 _cal_record_timezone_struct_init(temp);
77 *out_record = (calendar_record_h)temp;
82 static void _cal_record_timezone_struct_free(cal_timezone_s *record)
84 CAL_FREE(record->standard_name);
85 CAL_FREE(record->day_light_name);
90 static int _cal_record_timezone_destroy(calendar_record_h record, bool delete_child)
92 int ret = CALENDAR_ERROR_NONE;
94 cal_timezone_s *temp = (cal_timezone_s*)(record);
96 _cal_record_timezone_struct_free(temp);
101 static int _cal_record_timezone_clone(calendar_record_h record, calendar_record_h* out_record)
103 cal_timezone_s *out_data = NULL;
104 cal_timezone_s *src_data = NULL;
106 src_data = (cal_timezone_s*)(record);
108 out_data = calloc(1, sizeof(cal_timezone_s));
109 RETVM_IF(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
111 CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
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;
129 *out_record = (calendar_record_h)out_data;
131 return CALENDAR_ERROR_NONE;
134 static int _cal_record_timezone_get_str(calendar_record_h record, unsigned int property_id, char** out_str)
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);
141 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_NAME:
142 *out_str = cal_strdup(rec->day_light_name);
145 /* LCOV_EXCL_START */
146 ERR("invalid parameter (property:0x%x)", property_id);
147 return CALENDAR_ERROR_INVALID_PARAMETER;
151 return CALENDAR_ERROR_NONE;
154 static int _cal_record_timezone_get_str_p(calendar_record_h record, unsigned int property_id, char** out_str)
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);
161 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_NAME:
162 *out_str = (rec->day_light_name);
165 /* LCOV_EXCL_START */
166 ERR("invalid parameter (property:0x%x)", property_id);
167 return CALENDAR_ERROR_INVALID_PARAMETER;
171 return CALENDAR_ERROR_NONE;
174 static int _cal_record_timezone_get_int(calendar_record_h record, unsigned int property_id, int* out_value)
176 cal_timezone_s *rec = (cal_timezone_s*)(record);
177 switch (property_id) {
178 case CAL_PROPERTY_TIMEZONE_ID:
179 *out_value = (rec->index);
181 case CAL_PROPERTY_TIMEZONE_TZ_OFFSET_FROM_GMT:
182 *out_value = (rec->tz_offset_from_gmt);
184 case CAL_PROPERTY_TIMEZONE_STD_START_MONTH:
185 *out_value = (rec->std_start_month);
187 case CAL_PROPERTY_TIMEZONE_STD_START_POSITION_OF_WEEK:
188 *out_value = (rec->std_start_position_of_week);
190 case CAL_PROPERTY_TIMEZONE_STD_START_DAY:
191 *out_value = (rec->std_start_day);
193 case CAL_PROPERTY_TIMEZONE_STD_START_HOUR:
194 *out_value = (rec->std_start_hour);
196 case CAL_PROPERTY_TIMEZONE_STANDARD_BIAS:
197 *out_value = (rec->standard_bias);
199 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_MONTH:
200 *out_value = (rec->day_light_start_month);
202 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_POSITION_OF_WEEK:
203 *out_value = (rec->day_light_start_position_of_week);
205 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_DAY:
206 *out_value = (rec->day_light_start_day);
208 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_HOUR:
209 *out_value = (rec->day_light_start_hour);
211 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_BIAS:
212 *out_value = (rec->day_light_bias);
214 case CAL_PROPERTY_TIMEZONE_CALENDAR_ID:
215 *out_value = (rec->calendar_id);
218 /* LCOV_EXCL_START */
219 ERR("invalid parameter (property:0x%x)", property_id);
220 return CALENDAR_ERROR_INVALID_PARAMETER;
224 return CALENDAR_ERROR_NONE;
227 static int _cal_record_timezone_set_str(calendar_record_h record, unsigned int property_id, const char* value)
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);
235 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_NAME:
236 CAL_FREE(rec->day_light_name);
237 rec->day_light_name = cal_strdup(value);
240 /* LCOV_EXCL_START */
241 ERR("invalid parameter (property:0x%x)", property_id);
242 return CALENDAR_ERROR_INVALID_PARAMETER;
246 return CALENDAR_ERROR_NONE;
249 static int _cal_record_timezone_set_int(calendar_record_h record, unsigned int property_id, int value)
251 cal_timezone_s *rec = (cal_timezone_s*)(record);
252 switch (property_id) {
253 case CAL_PROPERTY_TIMEZONE_ID:
254 (rec->index) = value;
256 case CAL_PROPERTY_TIMEZONE_TZ_OFFSET_FROM_GMT:
257 (rec->tz_offset_from_gmt) = value;
259 case CAL_PROPERTY_TIMEZONE_STD_START_MONTH:
260 (rec->std_start_month) = value;
262 case CAL_PROPERTY_TIMEZONE_STD_START_POSITION_OF_WEEK:
263 (rec->std_start_position_of_week) = value;
265 case CAL_PROPERTY_TIMEZONE_STD_START_DAY:
266 (rec->std_start_day) = value;
268 case CAL_PROPERTY_TIMEZONE_STD_START_HOUR:
269 (rec->std_start_hour) = value;
271 case CAL_PROPERTY_TIMEZONE_STANDARD_BIAS:
272 (rec->standard_bias) = value;
274 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_MONTH:
275 (rec->day_light_start_month) = value;
277 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_POSITION_OF_WEEK:
278 (rec->day_light_start_position_of_week) = value;
280 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_DAY:
281 (rec->day_light_start_day) = value;
283 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_HOUR:
284 (rec->day_light_start_hour) = value;
286 case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_BIAS:
287 (rec->day_light_bias) = value;
289 case CAL_PROPERTY_TIMEZONE_CALENDAR_ID:
290 (rec->calendar_id) = value;
293 /* LCOV_EXCL_START */
294 ERR("invalid parameter (property:0x%x)", property_id);
295 return CALENDAR_ERROR_INVALID_PARAMETER;
299 return CALENDAR_ERROR_NONE;