Tizen 2.1 base
[framework/pim/calendar-service.git] / common / ipc / cal_ipc_marshal_calendar.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
20 #include "cal_internal.h"
21 #include "cal_ipc_marshal.h"
22 #include "cal_view.h"
23
24 static int __cal_ipc_unmarshal_calendar(pims_ipc_data_h ipc_data, calendar_record_h record);
25 static int __cal_ipc_marshal_calendar(const calendar_record_h record, pims_ipc_data_h ipc_data);
26 static int __cal_ipc_marshal_calendar_get_primary_id(const calendar_record_h record, unsigned int *property_id, int *id);
27
28 cal_ipc_marshal_record_plugin_cb_s _cal_ipc_record_calendar_plugin_cb = {
29         .unmarshal_record = __cal_ipc_unmarshal_calendar,
30         .marshal_record = __cal_ipc_marshal_calendar,
31         .get_primary_id = __cal_ipc_marshal_calendar_get_primary_id
32 };
33
34 static int __cal_ipc_unmarshal_calendar(pims_ipc_data_h ipc_data, calendar_record_h record)
35 {
36     cal_calendar_s* pcalendar = NULL;
37     bool bpropertyflag = false;
38     retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
39     retv_if(record==NULL,CALENDAR_ERROR_NO_DATA);
40
41     pcalendar = (cal_calendar_s*) record;
42
43     if (pcalendar->common.properties_max_count > 0)
44     {
45         bpropertyflag = true;
46     }
47     // read only or primary/secondary key
48     if (_cal_ipc_unmarshal_int(ipc_data,&pcalendar->index) != CALENDAR_ERROR_NONE)
49     {
50         ERR("_cal_ipc_unmarshal fail");
51         return CALENDAR_ERROR_INVALID_PARAMETER;
52     }
53     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[10]) )
54     {
55         if (_cal_ipc_unmarshal_int(ipc_data,&pcalendar->store_type) != CALENDAR_ERROR_NONE)
56         {
57             ERR("_cal_ipc_unmarshal fail");
58             return CALENDAR_ERROR_INVALID_PARAMETER;
59         }
60     }
61     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[1]) )
62     {
63         if (_cal_ipc_unmarshal_char(ipc_data,&pcalendar->uid) != CALENDAR_ERROR_NONE)
64         {
65             ERR("_cal_ipc_unmarshal fail");
66             return CALENDAR_ERROR_INVALID_PARAMETER;
67         }
68     }
69
70     if (_cal_ipc_unmarshal_long(ipc_data,&pcalendar->updated) != CALENDAR_ERROR_NONE)
71     {
72         ERR("_cal_ipc_unmarshal fail");
73         return CALENDAR_ERROR_INVALID_PARAMETER;
74     }
75
76     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[2]) )
77     {
78         if (_cal_ipc_unmarshal_char(ipc_data,&pcalendar->name) != CALENDAR_ERROR_NONE)
79         {
80             ERR("_cal_ipc_unmarshal fail");
81             return CALENDAR_ERROR_INVALID_PARAMETER;
82         }
83     }
84     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[3]) )
85     {
86         if (_cal_ipc_unmarshal_char(ipc_data,&pcalendar->description) != CALENDAR_ERROR_NONE)
87         {
88             ERR("_cal_ipc_unmarshal fail");
89             return CALENDAR_ERROR_INVALID_PARAMETER;
90         }
91     }
92     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[4]) )
93     {
94         if (_cal_ipc_unmarshal_char(ipc_data,&pcalendar->color) != CALENDAR_ERROR_NONE)
95         {
96             ERR("_cal_ipc_unmarshal fail");
97             return CALENDAR_ERROR_INVALID_PARAMETER;
98         }
99     }
100     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[5]) )
101     {
102         if (_cal_ipc_unmarshal_char(ipc_data,&pcalendar->location) != CALENDAR_ERROR_NONE)
103         {
104             ERR("_cal_ipc_unmarshal fail");
105             return CALENDAR_ERROR_INVALID_PARAMETER;
106         }
107     }
108     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[6]) )
109     {
110         if (_cal_ipc_unmarshal_int(ipc_data,&pcalendar->visibility) != CALENDAR_ERROR_NONE)
111         {
112             ERR("_cal_ipc_unmarshal fail");
113             return CALENDAR_ERROR_INVALID_PARAMETER;
114         }
115     }
116     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[7]) )
117     {
118         if (_cal_ipc_unmarshal_int(ipc_data,&pcalendar->sync_event) != CALENDAR_ERROR_NONE)
119         {
120             ERR("_cal_ipc_unmarshal fail");
121             return CALENDAR_ERROR_INVALID_PARAMETER;
122         }
123     }
124     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[8]) )
125     {
126         if (_cal_ipc_unmarshal_int(ipc_data,&pcalendar->is_deleted) != CALENDAR_ERROR_NONE)
127         {
128             ERR("_cal_ipc_unmarshal fail");
129             return CALENDAR_ERROR_INVALID_PARAMETER;
130         }
131     }
132     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[9]) )
133     {
134         if (_cal_ipc_unmarshal_int(ipc_data,&pcalendar->account_id) != CALENDAR_ERROR_NONE)
135         {
136             ERR("_cal_ipc_unmarshal fail");
137             return CALENDAR_ERROR_INVALID_PARAMETER;
138         }
139     }
140     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[11]) )
141     {
142         if (_cal_ipc_unmarshal_char(ipc_data,&pcalendar->sync_data1) != CALENDAR_ERROR_NONE)
143         {
144             ERR("_cal_ipc_unmarshal fail");
145             return CALENDAR_ERROR_INVALID_PARAMETER;
146         }
147     }
148     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[12]) )
149     {
150         if (_cal_ipc_unmarshal_char(ipc_data,&pcalendar->sync_data2) != CALENDAR_ERROR_NONE)
151         {
152             ERR("_cal_ipc_unmarshal fail");
153             return CALENDAR_ERROR_INVALID_PARAMETER;
154         }
155     }
156     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[13]) )
157     {
158         if (_cal_ipc_unmarshal_char(ipc_data,&pcalendar->sync_data3) != CALENDAR_ERROR_NONE)
159         {
160             ERR("_cal_ipc_unmarshal fail");
161             return CALENDAR_ERROR_INVALID_PARAMETER;
162         }
163     }
164     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[14]) )
165     {
166         if (_cal_ipc_unmarshal_char(ipc_data,&pcalendar->sync_data4) != CALENDAR_ERROR_NONE)
167         {
168             ERR("_cal_ipc_unmarshal fail");
169             return CALENDAR_ERROR_INVALID_PARAMETER;
170         }
171     }
172
173     return CALENDAR_ERROR_NONE;
174 }
175
176 static int __cal_ipc_marshal_calendar(const calendar_record_h record, pims_ipc_data_h ipc_data)
177 {
178     cal_calendar_s* pcalendar = (cal_calendar_s*)record;
179     bool bpropertyflag = false;
180     retv_if(ipc_data==NULL,CALENDAR_ERROR_NO_DATA);
181     retv_if(pcalendar==NULL,CALENDAR_ERROR_NO_DATA);
182
183     if (_cal_ipc_marshal_record_common(&(pcalendar->common),ipc_data) != CALENDAR_ERROR_NONE)
184     {
185         ERR("_cal_ipc_marshal fail");
186         return CALENDAR_ERROR_INVALID_PARAMETER;
187     }
188     if (pcalendar->common.properties_max_count > 0)
189     {
190         bpropertyflag = true;
191     }
192     // read only or primary/secondary key
193     if (_cal_ipc_marshal_int((pcalendar->index),ipc_data) != CALENDAR_ERROR_NONE)
194     {
195         ERR("_cal_ipc_marshal fail");
196         return CALENDAR_ERROR_INVALID_PARAMETER;
197     }
198     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[10]) )
199     {
200         if (_cal_ipc_marshal_int((pcalendar->store_type),ipc_data) != CALENDAR_ERROR_NONE)
201         {
202             ERR("_cal_ipc_marshal fail");
203             return CALENDAR_ERROR_INVALID_PARAMETER;
204         }
205     }
206     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[1]) )
207     {
208         if (_cal_ipc_marshal_char((pcalendar->uid),ipc_data) != CALENDAR_ERROR_NONE)
209         {
210             ERR("_cal_ipc_marshal fail");
211             return CALENDAR_ERROR_INVALID_PARAMETER;
212         }
213     }
214     if (_cal_ipc_marshal_long((pcalendar->updated),ipc_data) != CALENDAR_ERROR_NONE)
215     {
216         ERR("_cal_ipc_marshal fail");
217         return CALENDAR_ERROR_INVALID_PARAMETER;
218     }
219     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[2]) )
220     {
221         if (_cal_ipc_marshal_char((pcalendar->name),ipc_data) != CALENDAR_ERROR_NONE)
222         {
223             ERR("_cal_ipc_marshal fail");
224             return CALENDAR_ERROR_INVALID_PARAMETER;
225         }
226     }
227     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[3]) )
228     {
229         if (_cal_ipc_marshal_char((pcalendar->description),ipc_data) != CALENDAR_ERROR_NONE)
230         {
231             ERR("_cal_ipc_marshal fail");
232             return CALENDAR_ERROR_INVALID_PARAMETER;
233         }
234     }
235     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[4]) )
236     {
237         if (_cal_ipc_marshal_char((pcalendar->color),ipc_data) != CALENDAR_ERROR_NONE)
238         {
239             ERR("_cal_ipc_marshal fail");
240             return CALENDAR_ERROR_INVALID_PARAMETER;
241         }
242     }
243     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[5]) )
244     {
245         if (_cal_ipc_marshal_char((pcalendar->location),ipc_data) != CALENDAR_ERROR_NONE)
246         {
247             ERR("_cal_ipc_marshal fail");
248             return CALENDAR_ERROR_INVALID_PARAMETER;
249         }
250     }
251     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[6]) )
252     {
253         if (_cal_ipc_marshal_int((pcalendar->visibility),ipc_data) != CALENDAR_ERROR_NONE)
254         {
255             ERR("_cal_ipc_marshal fail");
256             return CALENDAR_ERROR_INVALID_PARAMETER;
257         }
258     }
259     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[7]) )
260     {
261         if (_cal_ipc_marshal_int((pcalendar->sync_event),ipc_data) != CALENDAR_ERROR_NONE)
262         {
263             ERR("_cal_ipc_marshal fail");
264             return CALENDAR_ERROR_INVALID_PARAMETER;
265         }
266     }
267     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[8]) )
268     {
269         if (_cal_ipc_marshal_int((pcalendar->is_deleted),ipc_data) != CALENDAR_ERROR_NONE)
270         {
271             ERR("_cal_ipc_marshal fail");
272             return CALENDAR_ERROR_INVALID_PARAMETER;
273         }
274     }
275     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[9]) )
276     {
277         if (_cal_ipc_marshal_int((pcalendar->account_id),ipc_data) != CALENDAR_ERROR_NONE)
278         {
279             ERR("_cal_ipc_marshal fail");
280             return CALENDAR_ERROR_INVALID_PARAMETER;
281         }
282     }
283     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[11]) )
284     {
285         if (_cal_ipc_marshal_char((pcalendar->sync_data1),ipc_data) != CALENDAR_ERROR_NONE)
286         {
287             ERR("_cal_ipc_marshal fail");
288             return CALENDAR_ERROR_INVALID_PARAMETER;
289         }
290     }
291     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[12]) )
292     {
293         if (_cal_ipc_marshal_char((pcalendar->sync_data2),ipc_data) != CALENDAR_ERROR_NONE)
294         {
295             ERR("_cal_ipc_marshal fail");
296             return CALENDAR_ERROR_INVALID_PARAMETER;
297         }
298     }
299     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[13]) )
300     {
301         if (_cal_ipc_marshal_char((pcalendar->sync_data3),ipc_data) != CALENDAR_ERROR_NONE)
302         {
303             ERR("_cal_ipc_marshal fail");
304             return CALENDAR_ERROR_INVALID_PARAMETER;
305         }
306     }
307     if (bpropertyflag == false || CAL_IPC_CHECK_PROPERTIES_FLAG(pcalendar->common.properties_flags[14]) )
308     {
309         if (_cal_ipc_marshal_char((pcalendar->sync_data4),ipc_data) != CALENDAR_ERROR_NONE)
310         {
311             ERR("_cal_ipc_marshal fail");
312             return CALENDAR_ERROR_INVALID_PARAMETER;
313         }
314     }
315
316     return CALENDAR_ERROR_NONE;
317 }
318
319 static int __cal_ipc_marshal_calendar_get_primary_id(const calendar_record_h record, unsigned int *property_id, int *id)
320 {
321     *property_id = CAL_PROPERTY_CALENDAR_ID;
322     return calendar_record_get_int(record, *property_id, id );
323 }