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_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);
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,
50 .get_caltime = _cal_record_alarm_get_caltime,
51 .set_str = _cal_record_alarm_set_str,
52 .set_int = _cal_record_alarm_set_int,
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
63 static void _cal_record_alarm_struct_init(cal_alarm_s *record)
65 memset(record, 0, sizeof(cal_alarm_s));
68 static int _cal_record_alarm_create(calendar_record_h* out_record)
70 cal_alarm_s *temp = NULL;
71 int ret = CALENDAR_ERROR_NONE;
73 temp = calloc(1, sizeof(cal_alarm_s));
74 RETVM_IF(NULL == temp, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
76 _cal_record_alarm_struct_init(temp);
78 *out_record = (calendar_record_h)temp;
83 static void _cal_record_alarm_struct_free(cal_alarm_s *record)
85 CAL_FREE(record->alarm_description);
86 CAL_FREE(record->alarm_summary);
87 CAL_FREE(record->alarm_attach);
91 static int _cal_record_alarm_destroy(calendar_record_h record, bool delete_child)
93 int ret = CALENDAR_ERROR_NONE;
95 cal_alarm_s *temp = (cal_alarm_s*)(record);
97 _cal_record_alarm_struct_free(temp);
102 static int _cal_record_alarm_clone(calendar_record_h record, calendar_record_h* out_record)
104 cal_alarm_s *out_data = NULL;
105 cal_alarm_s *src_data = NULL;
107 src_data = (cal_alarm_s*)(record);
109 out_data = calloc(1, sizeof(cal_alarm_s));
110 RETVM_IF(NULL == out_data, CALENDAR_ERROR_OUT_OF_MEMORY, "calloc() Fail");
112 CAL_RECORD_COPY_COMMON(&(out_data->common), &(src_data->common));
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;
124 *out_record = (calendar_record_h)out_data;
126 return CALENDAR_ERROR_NONE;
129 static int _cal_record_alarm_get_str(calendar_record_h record, unsigned int property_id, char** out_str)
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);
136 case CAL_PROPERTY_ALARM_SUMMARY:
137 *out_str = cal_strdup(rec->alarm_summary);
139 case CAL_PROPERTY_ALARM_ATTACH:
140 *out_str = cal_strdup(rec->alarm_attach);
143 /* LCOV_EXCL_START */
144 ERR("invalid parameter (property:0x%x)", property_id);
145 return CALENDAR_ERROR_INVALID_PARAMETER;
149 return CALENDAR_ERROR_NONE;
152 static int _cal_record_alarm_get_str_p(calendar_record_h record, unsigned int property_id, char** out_str)
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);
159 case CAL_PROPERTY_ALARM_SUMMARY:
160 *out_str = (rec->alarm_summary);
162 case CAL_PROPERTY_ALARM_ATTACH:
163 *out_str = (rec->alarm_attach);
166 /* LCOV_EXCL_START */
167 ERR("invalid parameter (property:0x%x)", property_id);
168 return CALENDAR_ERROR_INVALID_PARAMETER;
172 return CALENDAR_ERROR_NONE;
175 static int _cal_record_alarm_get_int(calendar_record_h record, unsigned int property_id, int* out_value)
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);
182 case CAL_PROPERTY_ALARM_TICK_UNIT:
183 *out_value = (rec->remind_tick_unit);
185 case CAL_PROPERTY_ALARM_PARENT_ID:
186 *out_value = (rec->parent_id);
188 case CAL_PROPERTY_ALARM_ACTION:
189 *out_value = (rec->alarm_action);
192 /* LCOV_EXCL_START */
193 ERR("invalid parameter (property:0x%x)", property_id);
194 return CALENDAR_ERROR_INVALID_PARAMETER;
198 return CALENDAR_ERROR_NONE;
201 static int _cal_record_alarm_get_caltime(calendar_record_h record, unsigned int property_id, calendar_time_s* out_value)
203 cal_alarm_s *rec = (cal_alarm_s*)(record);
204 switch (property_id) {
205 case CAL_PROPERTY_ALARM_ALARM:
206 *out_value = rec->alarm;
209 /* LCOV_EXCL_START */
210 ERR("invalid parameter (property:0x%x)", property_id);
211 return CALENDAR_ERROR_INVALID_PARAMETER;
214 return CALENDAR_ERROR_NONE;
217 static int _cal_record_alarm_set_str(calendar_record_h record, unsigned int property_id, const char* value)
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);
225 case CAL_PROPERTY_ALARM_SUMMARY:
226 CAL_FREE(rec->alarm_summary);
227 rec->alarm_summary = cal_strdup(value);
229 case CAL_PROPERTY_ALARM_ATTACH:
230 CAL_FREE(rec->alarm_attach);
231 rec->alarm_attach = cal_strdup(value);
234 /* LCOV_EXCL_START */
235 ERR("invalid parameter (property:0x%x)", property_id);
236 return CALENDAR_ERROR_INVALID_PARAMETER;
240 return CALENDAR_ERROR_NONE;
243 static int _cal_record_alarm_set_int(calendar_record_h record, unsigned int property_id, int value)
245 cal_alarm_s *rec = (cal_alarm_s*)(record);
246 switch (property_id) {
247 case CAL_PROPERTY_ALARM_TICK:
248 rec->remind_tick = value;
250 case CAL_PROPERTY_ALARM_TICK_UNIT:
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;
261 /* LCOV_EXCL_START */
262 ERR("invalid parameter (value:%d)", value);
263 return CALENDAR_ERROR_INVALID_PARAMETER;
267 case CAL_PROPERTY_ALARM_PARENT_ID:
268 rec->parent_id = value;
270 case CAL_PROPERTY_ALARM_ACTION:
272 case CALENDAR_ALARM_ACTION_AUDIO:
273 case CALENDAR_ALARM_ACTION_DISPLAY:
274 case CALENDAR_ALARM_ACTION_EMAIL:
275 rec->alarm_action = value;
278 /* LCOV_EXCL_START */
279 ERR("invalid parameter (value:%d)", value);
280 return CALENDAR_ERROR_INVALID_PARAMETER;
285 /* LCOV_EXCL_START */
286 ERR("invalid parameter (property:0x%x)", property_id);
287 return CALENDAR_ERROR_INVALID_PARAMETER;
291 return CALENDAR_ERROR_NONE;
294 static int _cal_record_alarm_set_caltime(calendar_record_h record, unsigned int property_id, calendar_time_s value)
296 cal_alarm_s *rec = (cal_alarm_s*)(record);
297 switch (property_id) {
298 case CAL_PROPERTY_ALARM_ALARM:
302 /* LCOV_EXCL_START */
303 ERR("invalid parameter (property:0x%x)", property_id);
304 return CALENDAR_ERROR_INVALID_PARAMETER;
307 return CALENDAR_ERROR_NONE;