Resolved Native API Reference issues for calendar-service
[platform/core/pim/calendar-service.git] / common / cal_record_alarm.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_alarm_create(calendar_record_h* out_record);
31 static int _cal_record_alarm_destroy(calendar_record_h record, bool delete_child);
32 static int _cal_record_alarm_clone(calendar_record_h record, calendar_record_h* out_record);
33 static int _cal_record_alarm_get_str(calendar_record_h record, unsigned int property_id, char** out_str);
34 static int _cal_record_alarm_get_str_p(calendar_record_h record, unsigned int property_id, char** out_str);
35 static int _cal_record_alarm_get_int(calendar_record_h record, unsigned int property_id, int* out_value);
36 static int _cal_record_alarm_get_caltime(calendar_record_h record, unsigned int property_id, calendar_time_s* out_value);
37 static int _cal_record_alarm_set_str(calendar_record_h record, unsigned int property_id, const char* value);
38 static int _cal_record_alarm_set_int(calendar_record_h record, unsigned int property_id, int value);
39 static int _cal_record_alarm_set_caltime(calendar_record_h record, unsigned int property_id, calendar_time_s value);
40
41 cal_record_plugin_cb_s cal_record_alarm_plugin_cb = {
42         .create = _cal_record_alarm_create,
43         .destroy = _cal_record_alarm_destroy,
44         .clone = _cal_record_alarm_clone,
45         .get_str = _cal_record_alarm_get_str,
46         .get_str_p = _cal_record_alarm_get_str_p,
47         .get_int = _cal_record_alarm_get_int,
48         .get_double = NULL,
49         .get_lli = NULL,
50         .get_caltime = _cal_record_alarm_get_caltime,
51         .set_str = _cal_record_alarm_set_str,
52         .set_int = _cal_record_alarm_set_int,
53         .set_double = NULL,
54         .set_lli = NULL,
55         .set_caltime = _cal_record_alarm_set_caltime,
56         .add_child_record = NULL,
57         .remove_child_record = NULL,
58         .get_child_record_count = NULL,
59         .get_child_record_at_p = NULL,
60         .clone_child_record_list = NULL
61 };
62
63 static void _cal_record_alarm_struct_init(cal_alarm_s *record)
64 {
65         memset(record, 0, sizeof(cal_alarm_s));
66 }
67
68 static int _cal_record_alarm_create(calendar_record_h* out_record)
69 {
70         cal_alarm_s *temp = NULL;
71         int ret = CALENDAR_ERROR_NONE;
72
73         temp = calloc(1, sizeof(cal_alarm_s));
74         RETVM_IF(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
75
76         _cal_record_alarm_struct_init(temp);
77
78         *out_record = (calendar_record_h)temp;
79
80         return ret;
81 }
82
83 static void _cal_record_alarm_struct_free(cal_alarm_s *record)
84 {
85         CAL_FREE(record->alarm_description);
86         CAL_FREE(record->alarm_summary);
87         CAL_FREE(record->alarm_attach);
88         CAL_FREE(record);
89 }
90
91 static int _cal_record_alarm_destroy(calendar_record_h record, bool delete_child)
92 {
93         int ret = CALENDAR_ERROR_NONE;
94
95         cal_alarm_s *temp = (cal_alarm_s*)(record);
96
97         _cal_record_alarm_struct_free(temp);
98
99         return ret;
100 }
101
102 static int _cal_record_alarm_clone(calendar_record_h record, calendar_record_h* out_record)
103 {
104         cal_alarm_s *out_data = NULL;
105         cal_alarm_s *src_data = NULL;
106
107         src_data = (cal_alarm_s*)(record);
108
109         out_data = calloc(1, sizeof(cal_alarm_s));
110         RETVM_IF(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
111
112         CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
113
114         out_data->parent_id = src_data->parent_id;
115         out_data->is_deleted = src_data->is_deleted;
116         out_data->remind_tick = src_data->remind_tick;
117         out_data->remind_tick_unit = src_data->remind_tick_unit;
118         out_data->alarm_description = cal_strdup(src_data->alarm_description);
119         out_data->alarm_summary = cal_strdup(src_data->alarm_summary);
120         out_data->alarm_action = src_data->alarm_action;
121         out_data->alarm_attach = cal_strdup(src_data->alarm_attach);
122         out_data->alarm = src_data->alarm;
123
124         *out_record = (calendar_record_h)out_data;
125
126         return CALENDAR_ERROR_NONE;
127 }
128
129 static int _cal_record_alarm_get_str(calendar_record_h record, unsigned int property_id, char** out_str)
130 {
131         cal_alarm_s *rec = (cal_alarm_s*)(record);
132         switch (property_id) {
133         case CAL_PROPERTY_ALARM_DESCRIPTION:
134                 *out_str = cal_strdup(rec->alarm_description);
135                 break;
136         case CAL_PROPERTY_ALARM_SUMMARY:
137                 *out_str = cal_strdup(rec->alarm_summary);
138                 break;
139         case CAL_PROPERTY_ALARM_ATTACH:
140                 *out_str = cal_strdup(rec->alarm_attach);
141                 break;
142         default:
143                 /* LCOV_EXCL_START */
144                 ERR("invalid parameter (property:0x%x)", property_id);
145                 return CALENDAR_ERROR_INVALID_PARAMETER;
146                 /* LCOV_EXCL_STOP */
147         }
148
149         return CALENDAR_ERROR_NONE;
150 }
151
152 static int _cal_record_alarm_get_str_p(calendar_record_h record, unsigned int property_id, char** out_str)
153 {
154         cal_alarm_s *rec = (cal_alarm_s*)(record);
155         switch (property_id) {
156         case CAL_PROPERTY_ALARM_DESCRIPTION:
157                 *out_str = (rec->alarm_description);
158                 break;
159         case CAL_PROPERTY_ALARM_SUMMARY:
160                 *out_str = (rec->alarm_summary);
161                 break;
162         case CAL_PROPERTY_ALARM_ATTACH:
163                 *out_str = (rec->alarm_attach);
164                 break;
165         default:
166                 /* LCOV_EXCL_START */
167                 ERR("invalid parameter (property:0x%x)", property_id);
168                 return CALENDAR_ERROR_INVALID_PARAMETER;
169                 /* LCOV_EXCL_STOP */
170         }
171
172         return CALENDAR_ERROR_NONE;
173 }
174
175 static int _cal_record_alarm_get_int(calendar_record_h record, unsigned int property_id, int* out_value)
176 {
177         cal_alarm_s *rec = (cal_alarm_s*)(record);
178         switch (property_id) {
179         case CAL_PROPERTY_ALARM_TICK:
180                 *out_value = (rec->remind_tick);
181                 break;
182         case CAL_PROPERTY_ALARM_TICK_UNIT:
183                 *out_value = (rec->remind_tick_unit);
184                 break;
185         case CAL_PROPERTY_ALARM_PARENT_ID:
186                 *out_value = (rec->parent_id);
187                 break;
188         case CAL_PROPERTY_ALARM_ACTION:
189                 *out_value = (rec->alarm_action);
190                 break;
191         default:
192                 /* LCOV_EXCL_START */
193                 ERR("invalid parameter (property:0x%x)", property_id);
194                 return CALENDAR_ERROR_INVALID_PARAMETER;
195                 /* LCOV_EXCL_STOP */
196         }
197
198         return CALENDAR_ERROR_NONE;
199 }
200
201 static int _cal_record_alarm_get_caltime(calendar_record_h record, unsigned int property_id, calendar_time_s* out_value)
202 {
203         cal_alarm_s *rec = (cal_alarm_s*)(record);
204         switch (property_id) {
205         case CAL_PROPERTY_ALARM_ALARM:
206                 *out_value = rec->alarm;
207                 break;
208         default:
209                 /* LCOV_EXCL_START */
210                 ERR("invalid parameter (property:0x%x)", property_id);
211                 return CALENDAR_ERROR_INVALID_PARAMETER;
212                 /* LCOV_EXCL_STOP */
213         }
214         return CALENDAR_ERROR_NONE;
215 }
216
217 static int _cal_record_alarm_set_str(calendar_record_h record, unsigned int property_id, const char* value)
218 {
219         cal_alarm_s *rec = (cal_alarm_s*)(record);
220         switch (property_id) {
221         case CAL_PROPERTY_ALARM_DESCRIPTION:
222                 CAL_FREE(rec->alarm_description);
223                 rec->alarm_description = cal_strdup(value);
224                 break;
225         case CAL_PROPERTY_ALARM_SUMMARY:
226                 CAL_FREE(rec->alarm_summary);
227                 rec->alarm_summary = cal_strdup(value);
228                 break;
229         case CAL_PROPERTY_ALARM_ATTACH:
230                 CAL_FREE(rec->alarm_attach);
231                 rec->alarm_attach = cal_strdup(value);
232                 break;
233         default:
234                 /* LCOV_EXCL_START */
235                 ERR("invalid parameter (property:0x%x)", property_id);
236                 return CALENDAR_ERROR_INVALID_PARAMETER;
237                 /* LCOV_EXCL_STOP */
238         }
239
240         return CALENDAR_ERROR_NONE;
241 }
242
243 static int _cal_record_alarm_set_int(calendar_record_h record, unsigned int property_id, int value)
244 {
245         cal_alarm_s *rec = (cal_alarm_s*)(record);
246         switch (property_id) {
247         case CAL_PROPERTY_ALARM_TICK:
248                 rec->remind_tick = value;
249                 break;
250         case CAL_PROPERTY_ALARM_TICK_UNIT:
251                 switch (value) {
252                 case CALENDAR_ALARM_NONE:
253                 case CALENDAR_ALARM_TIME_UNIT_SPECIFIC:
254                 case CALENDAR_ALARM_TIME_UNIT_MINUTE:
255                 case CALENDAR_ALARM_TIME_UNIT_HOUR:
256                 case CALENDAR_ALARM_TIME_UNIT_DAY:
257                 case CALENDAR_ALARM_TIME_UNIT_WEEK:
258                         rec->remind_tick_unit = value;
259                         break;
260                 default:
261                         /* LCOV_EXCL_START */
262                         ERR("invalid parameter (value:%d)", value);
263                         return CALENDAR_ERROR_INVALID_PARAMETER;
264                         /* LCOV_EXCL_STOP */
265                 }
266                 break;
267         case CAL_PROPERTY_ALARM_PARENT_ID:
268                 rec->parent_id = value;
269                 break;
270         case CAL_PROPERTY_ALARM_ACTION:
271                 switch (value) {
272                 case CALENDAR_ALARM_ACTION_AUDIO:
273                 case CALENDAR_ALARM_ACTION_DISPLAY:
274                 case CALENDAR_ALARM_ACTION_EMAIL:
275                         rec->alarm_action = value;
276                         break;
277                 default:
278                         /* LCOV_EXCL_START */
279                         ERR("invalid parameter (value:%d)", value);
280                         return CALENDAR_ERROR_INVALID_PARAMETER;
281                         /* LCOV_EXCL_STOP */
282                 }
283                 break;
284         default:
285                 /* LCOV_EXCL_START */
286                 ERR("invalid parameter (property:0x%x)", property_id);
287                 return CALENDAR_ERROR_INVALID_PARAMETER;
288                 /* LCOV_EXCL_STOP */
289         }
290
291         return CALENDAR_ERROR_NONE;
292 }
293
294 static int _cal_record_alarm_set_caltime(calendar_record_h record, unsigned int property_id, calendar_time_s value)
295 {
296         cal_alarm_s *rec = (cal_alarm_s*)(record);
297         switch (property_id) {
298         case CAL_PROPERTY_ALARM_ALARM:
299                 rec->alarm = value;
300                 break;
301         default:
302                 /* LCOV_EXCL_START */
303                 ERR("invalid parameter (property:0x%x)", property_id);
304                 return CALENDAR_ERROR_INVALID_PARAMETER;
305                 /* LCOV_EXCL_STOP */
306         }
307         return CALENDAR_ERROR_NONE;
308
309 }