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 ERR("invalid parameter (property:0x%x)", property_id);
144 return CALENDAR_ERROR_INVALID_PARAMETER;
147 return CALENDAR_ERROR_NONE;
150 static int _cal_record_alarm_get_str_p(calendar_record_h record, unsigned int property_id, char** out_str)
152 cal_alarm_s *rec = (cal_alarm_s*)(record);
153 switch (property_id) {
154 case CAL_PROPERTY_ALARM_DESCRIPTION:
155 *out_str = (rec->alarm_description);
157 case CAL_PROPERTY_ALARM_SUMMARY:
158 *out_str = (rec->alarm_summary);
160 case CAL_PROPERTY_ALARM_ATTACH:
161 *out_str = (rec->alarm_attach);
164 ERR("invalid parameter (property:0x%x)", property_id);
165 return CALENDAR_ERROR_INVALID_PARAMETER;
168 return CALENDAR_ERROR_NONE;
171 static int _cal_record_alarm_get_int(calendar_record_h record, unsigned int property_id, int* out_value)
173 cal_alarm_s *rec = (cal_alarm_s*)(record);
174 switch (property_id) {
175 case CAL_PROPERTY_ALARM_TICK:
176 *out_value = (rec->remind_tick);
178 case CAL_PROPERTY_ALARM_TICK_UNIT:
179 *out_value = (rec->remind_tick_unit);
181 case CAL_PROPERTY_ALARM_PARENT_ID:
182 *out_value = (rec->parent_id);
184 case CAL_PROPERTY_ALARM_ACTION:
185 *out_value = (rec->alarm_action);
188 ERR("invalid parameter (property:0x%x)", property_id);
189 return CALENDAR_ERROR_INVALID_PARAMETER;
192 return CALENDAR_ERROR_NONE;
195 static int _cal_record_alarm_get_caltime(calendar_record_h record, unsigned int property_id, calendar_time_s* out_value)
197 cal_alarm_s *rec = (cal_alarm_s*)(record);
198 switch (property_id) {
199 case CAL_PROPERTY_ALARM_ALARM:
200 *out_value = rec->alarm;
203 ERR("invalid parameter (property:0x%x)", property_id);
204 return CALENDAR_ERROR_INVALID_PARAMETER;
206 return CALENDAR_ERROR_NONE;
209 static int _cal_record_alarm_set_str(calendar_record_h record, unsigned int property_id, const char* value)
211 cal_alarm_s *rec = (cal_alarm_s*)(record);
212 switch (property_id) {
213 case CAL_PROPERTY_ALARM_DESCRIPTION:
214 CAL_FREE(rec->alarm_description);
215 rec->alarm_description = cal_strdup(value);
217 case CAL_PROPERTY_ALARM_SUMMARY:
218 CAL_FREE(rec->alarm_summary);
219 rec->alarm_summary = cal_strdup(value);
221 case CAL_PROPERTY_ALARM_ATTACH:
222 CAL_FREE(rec->alarm_attach);
223 rec->alarm_attach = cal_strdup(value);
226 ERR("invalid parameter (property:0x%x)", property_id);
227 return CALENDAR_ERROR_INVALID_PARAMETER;
230 return CALENDAR_ERROR_NONE;
233 static int _cal_record_alarm_set_int(calendar_record_h record, unsigned int property_id, int value)
235 cal_alarm_s *rec = (cal_alarm_s*)(record);
236 switch (property_id) {
237 case CAL_PROPERTY_ALARM_TICK:
238 rec->remind_tick = value;
240 case CAL_PROPERTY_ALARM_TICK_UNIT:
242 case CALENDAR_ALARM_NONE:
243 case CALENDAR_ALARM_TIME_UNIT_SPECIFIC:
244 case CALENDAR_ALARM_TIME_UNIT_MINUTE:
245 case CALENDAR_ALARM_TIME_UNIT_HOUR:
246 case CALENDAR_ALARM_TIME_UNIT_DAY:
247 case CALENDAR_ALARM_TIME_UNIT_WEEK:
248 rec->remind_tick_unit = value;
251 ERR("invalid parameter (value:%d)", value);
252 return CALENDAR_ERROR_INVALID_PARAMETER;
255 case CAL_PROPERTY_ALARM_PARENT_ID:
256 rec->parent_id = value;
258 case CAL_PROPERTY_ALARM_ACTION:
260 case CALENDAR_ALARM_ACTION_AUDIO:
261 case CALENDAR_ALARM_ACTION_DISPLAY:
262 case CALENDAR_ALARM_ACTION_EMAIL:
263 rec->alarm_action = value;
266 ERR("invalid parameter (value:%d)", value);
267 return CALENDAR_ERROR_INVALID_PARAMETER;
271 ERR("invalid parameter (property:0x%x)", property_id);
272 return CALENDAR_ERROR_INVALID_PARAMETER;
275 return CALENDAR_ERROR_NONE;
278 static int _cal_record_alarm_set_caltime(calendar_record_h record, unsigned int property_id, calendar_time_s value)
280 cal_alarm_s *rec = (cal_alarm_s*)(record);
281 switch (property_id) {
282 case CAL_PROPERTY_ALARM_ALARM:
286 ERR("invalid parameter (property:0x%x)", property_id);
287 return CALENDAR_ERROR_INVALID_PARAMETER;
289 return CALENDAR_ERROR_NONE;