Tizen 2.1 base
[framework/pim/calendar-service.git] / common / cal_record_timezone.c
1 /*
2  * Calendar Service
3  *
4  * Copyright (c) 2012 - 2013 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 #include <stdlib.h>
20 #include <stdbool.h>
21 #include <string.h>
22
23 #include "cal_internal.h"
24 #include "cal_typedef.h"
25 #include "cal_view.h"
26
27 #include "cal_record.h"
28
29 static int __cal_record_timezone_create( calendar_record_h* out_record );
30 static int __cal_record_timezone_destroy( calendar_record_h record, bool delete_child );
31 static int __cal_record_timezone_clone( calendar_record_h record, calendar_record_h* out_record );
32 static int __cal_record_timezone_get_str( calendar_record_h record, unsigned int property_id, char** out_str );
33 static int __cal_record_timezone_get_str_p( calendar_record_h record, unsigned int property_id, char** out_str );
34 static int __cal_record_timezone_get_int( calendar_record_h record, unsigned int property_id, int* out_value );
35 static int __cal_record_timezone_set_str( calendar_record_h record, unsigned int property_id, const char* value );
36 static int __cal_record_timezone_set_int( calendar_record_h record, unsigned int property_id, int value );
37
38 cal_record_plugin_cb_s _cal_record_timezone_plugin_cb = {
39                 .create = __cal_record_timezone_create,
40                 .destroy = __cal_record_timezone_destroy,
41                 .clone = __cal_record_timezone_clone,
42                 .get_str = __cal_record_timezone_get_str,
43                 .get_str_p = __cal_record_timezone_get_str_p,
44                 .get_int = __cal_record_timezone_get_int,
45                 .get_double = NULL,
46                 .get_lli = NULL,
47                 .get_caltime = NULL,
48                 .set_str = __cal_record_timezone_set_str,
49                 .set_int = __cal_record_timezone_set_int,
50                 .set_double = NULL,
51                 .set_lli = NULL,
52                 .set_caltime = NULL,
53                 .add_child_record = NULL,
54                 .remove_child_record = NULL,
55                 .get_child_record_count = NULL,
56                 .get_child_record_at_p = NULL,
57                 .clone_child_record_list = NULL
58 };
59
60 static void __cal_record_timezone_struct_init(cal_timezone_s *record)
61 {
62         memset(record,0,sizeof(cal_timezone_s));
63     record->calendar_id = DEFAULT_EVENT_CALENDAR_BOOK_ID;
64 }
65
66 static int __cal_record_timezone_create( calendar_record_h* out_record )
67 {
68         cal_timezone_s *temp = NULL;
69         int ret= CALENDAR_ERROR_NONE, type = 0;
70
71         type = CAL_RECORD_TYPE_TIMEZONE;
72
73         temp = (cal_timezone_s*)calloc(1,sizeof(cal_timezone_s));
74         retvm_if(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "malloc(cal_timezone_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
75
76         __cal_record_timezone_struct_init(temp);
77
78     *out_record = (calendar_record_h)temp;
79
80         return ret;
81 }
82
83 static void __cal_record_timezone_struct_free(cal_timezone_s *record)
84 {
85         CAL_FREE(record->standard_name);
86         CAL_FREE(record->day_light_name);
87         CAL_FREE(record);
88
89 }
90
91 static int __cal_record_timezone_destroy( calendar_record_h record, bool delete_child )
92 {
93     int ret = CALENDAR_ERROR_NONE;
94
95         cal_timezone_s *temp = (cal_timezone_s*)(record);
96
97     __cal_record_timezone_struct_free(temp);
98
99         return ret;
100 }
101
102 static int __cal_record_timezone_clone( calendar_record_h record, calendar_record_h* out_record )
103 {
104         cal_timezone_s *out_data = NULL;
105         cal_timezone_s *src_data = NULL;
106
107         src_data = (cal_timezone_s*)(record);
108
109         out_data = calloc(1, sizeof(cal_timezone_s));
110         retvm_if(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc(cal_timezone_s) Failed(%d)", CALENDAR_ERROR_OUT_OF_MEMORY);
111
112         CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
113
114         out_data->index = src_data->index;
115         out_data->tz_offset_from_gmt = src_data->tz_offset_from_gmt;
116         out_data->standard_name = SAFE_STRDUP(src_data->standard_name);
117         out_data->std_start_month = src_data->std_start_month;
118         out_data->std_start_position_of_week = src_data->std_start_position_of_week;
119         out_data->std_start_day = src_data->std_start_day;
120         out_data->std_start_hour = src_data->std_start_hour;
121         out_data->standard_bias = src_data->standard_bias;
122         out_data->day_light_name = SAFE_STRDUP(src_data->day_light_name);
123         out_data->day_light_start_month = src_data->day_light_start_month;
124         out_data->day_light_start_position_of_week = src_data->day_light_start_position_of_week;
125         out_data->day_light_start_day = src_data->day_light_start_day;
126         out_data->day_light_start_hour = src_data->day_light_start_hour;
127         out_data->day_light_bias = src_data->day_light_bias;
128         out_data->calendar_id = src_data->calendar_id;
129
130     *out_record = (calendar_record_h)out_data;
131
132         return CALENDAR_ERROR_NONE;
133 }
134
135 static int __cal_record_timezone_get_str( calendar_record_h record, unsigned int property_id, char** out_str )
136 {
137         cal_timezone_s *rec = (cal_timezone_s*)(record);
138         switch( property_id )
139         {
140         case CAL_PROPERTY_TIMEZONE_STANDARD_NAME:
141                 *out_str = SAFE_STRDUP(rec->standard_name);
142                 break;
143         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_NAME:
144                 *out_str = SAFE_STRDUP(rec->day_light_name);
145                 break;
146         default:
147             ASSERT_NOT_REACHED("invalid parameter (property:%d)",property_id);
148                 return CALENDAR_ERROR_INVALID_PARAMETER;
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         {
159         case CAL_PROPERTY_TIMEZONE_STANDARD_NAME:
160                 *out_str = (rec->standard_name);
161                 break;
162         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_NAME:
163                 *out_str = (rec->day_light_name);
164                 break;
165         default:
166             ASSERT_NOT_REACHED("invalid parameter (property:%d)",property_id);
167                 return CALENDAR_ERROR_INVALID_PARAMETER;
168         }
169
170         return CALENDAR_ERROR_NONE;
171 }
172
173 static int __cal_record_timezone_get_int( calendar_record_h record, unsigned int property_id, int* out_value )
174 {
175         cal_timezone_s *rec = (cal_timezone_s*)(record);
176         switch( property_id )
177         {
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             ASSERT_NOT_REACHED("invalid parameter (property:%d)",property_id);
219                 return CALENDAR_ERROR_INVALID_PARAMETER;
220         }
221
222         return CALENDAR_ERROR_NONE;
223 }
224
225 static int __cal_record_timezone_set_str( calendar_record_h record, unsigned int property_id, const char* value )
226 {
227         cal_timezone_s *rec = (cal_timezone_s*)(record);
228         switch( property_id )
229         {
230         case CAL_PROPERTY_TIMEZONE_STANDARD_NAME:
231                 CAL_FREE(rec->standard_name);
232                 rec->standard_name = SAFE_STRDUP(value);
233                 break;
234         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_NAME:
235                 CAL_FREE(rec->day_light_name);
236                 rec->day_light_name = SAFE_STRDUP(value);
237                 break;
238         default:
239             ASSERT_NOT_REACHED("invalid parameter (property:%d)",property_id);
240                 return CALENDAR_ERROR_INVALID_PARAMETER;
241         }
242
243         return CALENDAR_ERROR_NONE;
244 }
245
246 static int __cal_record_timezone_set_int( calendar_record_h record, unsigned int property_id, int value )
247 {
248         cal_timezone_s *rec = (cal_timezone_s*)(record);
249         switch( property_id )
250         {
251         case CAL_PROPERTY_TIMEZONE_ID:
252                 (rec->index) = value;
253                 break;
254         case CAL_PROPERTY_TIMEZONE_TZ_OFFSET_FROM_GMT:
255                 (rec->tz_offset_from_gmt) = value;
256                 break;
257         case CAL_PROPERTY_TIMEZONE_STD_START_MONTH:
258                 (rec->std_start_month) = value;
259                 break;
260         case CAL_PROPERTY_TIMEZONE_STD_START_POSITION_OF_WEEK:
261                 (rec->std_start_position_of_week) = value;
262                 break;
263         case CAL_PROPERTY_TIMEZONE_STD_START_DAY:
264                 (rec->std_start_day) = value;
265                 break;
266         case CAL_PROPERTY_TIMEZONE_STD_START_HOUR:
267                 (rec->std_start_hour) = value;
268                 break;
269         case CAL_PROPERTY_TIMEZONE_STANDARD_BIAS:
270                 (rec->standard_bias) = value;
271                 break;
272         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_MONTH:
273                 (rec->day_light_start_month) = value;
274                 break;
275         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_POSITION_OF_WEEK:
276                 (rec->day_light_start_position_of_week) = value;
277                 break;
278         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_DAY:
279                 (rec->day_light_start_day) = value;
280                 break;
281         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_START_HOUR:
282                 (rec->day_light_start_hour) = value;
283                 break;
284         case CAL_PROPERTY_TIMEZONE_DAY_LIGHT_BIAS:
285                 (rec->day_light_bias) = value;
286                 break;
287         case CAL_PROPERTY_TIMEZONE_CALENDAR_ID:
288                 (rec->calendar_id) = value;
289                 break;
290         default:
291             ASSERT_NOT_REACHED("invalid parameter (property:%d)",property_id);
292                 return CALENDAR_ERROR_INVALID_PARAMETER;
293         }
294
295         return CALENDAR_ERROR_NONE;
296 }