Merge "Export internal APIs needed by samsung-socil" into tizen_2.1
[framework/osp/social.git] / src / FSclCalendarbook.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 /**
17  * @file                FSclCalendarbook.cpp
18  * @brief               This is the implementation for Calendarbook class.
19  *
20  * This file contains definitions of @e Calendarbook class.
21  */
22
23 #include <new>
24 #include <FSclCalendarbook.h>
25 #include <FBaseSysLog.h>
26 #include <FSec_AccessController.h>
27 #include "FScl_CalEventImpl.h"
28 #include "FScl_CalTodoImpl.h"
29 #include "FScl_CalendarbookImpl.h"
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Security;
34
35 namespace Tizen { namespace Social
36 {
37
38 Calendarbook::Calendarbook(void)
39         : __pCalendarbookImpl(null)
40 {
41 }
42
43 Calendarbook::~Calendarbook(void)
44 {
45         delete __pCalendarbookImpl;
46 }
47
48 result
49 Calendarbook::Construct(void)
50 {
51         SysAssertf(__pCalendarbookImpl == null,
52                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
53
54         result r = E_SUCCESS;
55         _CalendarbookImpl* pCalendarbookImpl = null;
56
57         pCalendarbookImpl = new (std::nothrow) _CalendarbookImpl();
58         SysTryReturnResult(NID_SCL, pCalendarbookImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
59
60         r = pCalendarbookImpl->Construct();
61         SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
62
63         __pCalendarbookImpl = pCalendarbookImpl;
64
65         return E_SUCCESS;
66
67 CATCH:
68         delete pCalendarbookImpl;
69
70         return r;
71 }
72
73 result
74 Calendarbook::Construct(IRecordEventListener* pListener)
75 {
76         SysAssertf(__pCalendarbookImpl == null,
77                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
78
79         result r = E_SUCCESS;
80         _CalendarbookImpl* pCalendarbookImpl = null;
81
82         pCalendarbookImpl = new (std::nothrow) _CalendarbookImpl();
83         SysTryReturnResult(NID_SCL, pCalendarbookImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
84
85         r = pCalendarbookImpl->Construct(pListener);
86         SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
87
88         __pCalendarbookImpl = pCalendarbookImpl;
89
90         return E_SUCCESS;
91
92 CATCH:
93         delete pCalendarbookImpl;
94
95         return r;
96 }
97
98 result
99 Calendarbook::Construct(ICalendarbookEventListener& listener)
100 {
101         SysAssertf(__pCalendarbookImpl == null,
102                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
103
104         result r = E_SUCCESS;
105         _CalendarbookImpl* pCalendarbookImpl = null;
106
107         pCalendarbookImpl = new (std::nothrow) _CalendarbookImpl();
108         SysTryReturnResult(NID_SCL, pCalendarbookImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
109
110         r = pCalendarbookImpl->Construct(listener);
111         SysTryCatch(NID_SCL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
112
113         __pCalendarbookImpl = pCalendarbookImpl;
114
115         return E_SUCCESS;
116
117 CATCH:
118         delete pCalendarbookImpl;
119
120         return r;
121 }
122
123 result
124 Calendarbook::AddEvent(CalEvent& event)
125 {
126         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
127         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
128         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
129         SysAssertf(__pCalendarbookImpl != null,
130                         "Not yet constructed. Construct() should be called before use.");
131
132         r = __pCalendarbookImpl->AddEvent(event);
133         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
134
135         return E_SUCCESS;
136 }
137
138 result
139 Calendarbook::AddEvent(CalEvent& event, RecordId calendarId)
140 {
141         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
142         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
143         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
144         SysAssertf(__pCalendarbookImpl != null,
145                         "Not yet constructed. Construct() should be called before use.");
146
147         r = __pCalendarbookImpl->AddEvent(event, calendarId);
148         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
149
150         return E_SUCCESS;
151 }
152
153 result
154 Calendarbook::AddTodo(CalTodo& todo)
155 {
156         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
157         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
158         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
159         SysAssertf(__pCalendarbookImpl != null,
160                         "Not yet constructed. Construct() should be called before use.");
161
162         r = __pCalendarbookImpl->AddTodo(todo);
163         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
164
165         return E_SUCCESS;
166 }
167
168 result
169 Calendarbook::AddTodo(CalTodo& todo, RecordId calendarId)
170 {
171         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
172         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
173         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
174         SysAssertf(__pCalendarbookImpl != null,
175                         "Not yet constructed. Construct() should be called before use.");
176
177         r = __pCalendarbookImpl->AddTodo(todo, calendarId);
178         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
179
180         return E_SUCCESS;
181 }
182
183 result
184 Calendarbook::RemoveEvent(CalEvent& event)
185 {
186         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
187         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
188         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
189         SysAssertf(__pCalendarbookImpl != null,
190                         "Not yet constructed. Construct() should be called before use.");
191
192         r = __pCalendarbookImpl->RemoveEvent(event);
193         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
194
195         return E_SUCCESS;
196 }
197
198 result
199 Calendarbook::RemoveEvent(RecordId eventId)
200 {
201         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
202         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
203         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
204         SysAssertf(__pCalendarbookImpl != null,
205                         "Not yet constructed. Construct() should be called before use.");
206
207         r = __pCalendarbookImpl->RemoveEvent(eventId);
208         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
209
210         return E_SUCCESS;
211 }
212
213 result
214 Calendarbook::RemoveTodo(CalTodo& todo)
215 {
216         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
217         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
218         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
219         SysAssertf(__pCalendarbookImpl != null,
220                         "Not yet constructed. Construct() should be called before use.");
221
222         r = __pCalendarbookImpl->RemoveTodo(todo);
223         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
224
225         return E_SUCCESS;
226 }
227
228 result
229 Calendarbook::RemoveTodo(RecordId todoId)
230 {
231         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
232         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
233         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
234         SysAssertf(__pCalendarbookImpl != null,
235                         "Not yet constructed. Construct() should be called before use.");
236
237         r = __pCalendarbookImpl->RemoveTodo(todoId);
238         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
239
240         return E_SUCCESS;
241 }
242
243 result
244 Calendarbook::UpdateEvent(const CalEvent& event)
245 {
246         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
247         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
248         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
249         SysAssertf(__pCalendarbookImpl != null,
250                         "Not yet constructed. Construct() should be called before use.");
251
252         r = __pCalendarbookImpl->UpdateEvent(event);
253         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
254
255         return E_SUCCESS;
256 }
257
258 result
259 Calendarbook::UpdateTodo(const CalTodo& todo)
260 {
261         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
262         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
263         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
264         SysAssertf(__pCalendarbookImpl != null,
265                         "Not yet constructed. Construct() should be called before use.");
266
267         r = __pCalendarbookImpl->UpdateTodo(todo);
268         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
269
270         return E_SUCCESS;
271 }
272
273 CalEvent*
274 Calendarbook::GetEventN(RecordId eventId) const
275 {
276         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
277         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
278         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
279         SysAssertf(__pCalendarbookImpl != null,
280                         "Not yet constructed. Construct() should be called before use.");
281
282         CalEvent* pEvent = __pCalendarbookImpl->GetEventN(eventId);
283         r = GetLastResult();
284         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
285
286         return pEvent;
287 }
288
289 CalTodo*
290 Calendarbook::GetTodoN(RecordId todoId) const
291 {
292         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
293         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
294         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
295         SysAssertf(__pCalendarbookImpl != null,
296                                 "Not yet constructed. Construct() should be called before use.");
297
298         CalTodo* pTodo = __pCalendarbookImpl->GetTodoN(todoId);
299         r = GetLastResult();
300         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
301
302         return pTodo;
303 }
304
305 IList*
306 Calendarbook::GetTodosN(const DateTime& start, const DateTime& end, int pageNo, int countPerPage, unsigned long status,
307                                                 unsigned long priority) const
308 {
309         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
310         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
311         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
312         SysAssertf(__pCalendarbookImpl != null,
313                         "Not yet constructed. Construct() should be called before use.");
314
315         IList* pList = __pCalendarbookImpl->GetTodosN(start, end, pageNo, countPerPage, status, priority);
316         r = GetLastResult();
317         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
318
319         return pList;
320 }
321
322 int
323 Calendarbook::GetTodoCount(const DateTime& start, const DateTime& end, unsigned long status, unsigned long priority) const
324 {
325         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
326         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
327         SysTryReturn(NID_SCL, r == E_SUCCESS, _INVALID_COUNT, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
328         SysAssertf(__pCalendarbookImpl != null,
329                         "Not yet constructed. Construct() should be called before use.");
330
331         int count = __pCalendarbookImpl->GetTodoCount(start, end, status, priority);
332         r = GetLastResult();
333         SysTryReturn(NID_SCL, r == E_SUCCESS, _INVALID_COUNT, r, "[%s] Propagating.", GetErrorMessage(r));
334
335         return count;
336 }
337
338 IList*
339 Calendarbook::GetEventInstancesN(const DateTime& start, const DateTime& end,
340                                                                  const Tizen::Locales::TimeZone& timeZone, int pageNo, int countPerPage,
341                                                                  unsigned long category) const
342 {
343         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
344         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
345         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
346         SysAssertf(__pCalendarbookImpl != null,
347                         "Not yet constructed. Construct() should be called before use.");
348         IList* pList = __pCalendarbookImpl->GetEventInstancesN(start, end, timeZone, pageNo, countPerPage, category);
349         r = GetLastResult();
350         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
351
352         return pList;
353 }
354
355 result
356 Calendarbook::GetEventInstances(const DateTime& start, const DateTime& end,
357                                                                 const Tizen::Locales::TimeZone& timeZone, int pageNo, int countPerPage, unsigned long category,
358                                                                 RequestId& reqId,
359                                                                 const IRecordListener& listener) const
360 {
361         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
362         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
363         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
364         SysAssertf(__pCalendarbookImpl != null,
365                         "Not yet constructed. Construct() should be called before use.");
366
367         r = __pCalendarbookImpl->GetEventInstances(start, end, timeZone, pageNo, countPerPage, category, reqId, listener);
368         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
369
370         return E_SUCCESS;
371 }
372
373 IList*
374 Calendarbook::GetAllEventsN(void) const
375 {
376         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
377         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
378         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
379         SysAssertf(__pCalendarbookImpl != null,
380                         "Not yet constructed. Construct() should be called before use.");
381
382         IList* pList = __pCalendarbookImpl->GetAllEventsN();
383         r = GetLastResult();
384         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
385
386         return pList;
387 }
388
389 IList*
390 Calendarbook::GetAllTodosN(void) const
391 {
392         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
393         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
394         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
395         SysAssertf(__pCalendarbookImpl != null,
396                         "Not yet constructed. Construct() should be called before use.");
397
398         IList* pList = __pCalendarbookImpl->GetAllTodosN();
399         r = GetLastResult();
400         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
401
402         return pList;
403 }
404
405 IList*
406 Calendarbook::GetAllCalendarsN(void) const
407 {
408         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
409         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
410         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
411         SysAssertf(__pCalendarbookImpl != null,
412                         "Not yet constructed. Construct() should be called before use.");
413
414         IList* pList = __pCalendarbookImpl->GetAllCalendarsN();
415         r = GetLastResult();
416         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
417
418         return pList;
419 }
420
421 IList*
422 Calendarbook::GetChangedEventsAfterN(int version, int& latestVersion) const
423 {
424         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
425         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
426         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
427         SysAssertf(__pCalendarbookImpl != null,
428                         "Not yet constructed. Construct() should be called before use.");
429
430         IList* pList = __pCalendarbookImpl->GetChangedEventsAfterN(version, latestVersion);
431         r = GetLastResult();
432         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
433
434         return pList;
435 }
436
437 IList*
438 Calendarbook::GetChangedTodosAfterN(int version, int& latestVersion) const
439 {
440         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
441         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
442         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
443         SysAssertf(__pCalendarbookImpl != null,
444                         "Not yet constructed. Construct() should be called before use.");
445
446         IList* pList = __pCalendarbookImpl->GetChangedTodosAfterN(version, latestVersion);
447         r = GetLastResult();
448         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
449
450         return pList;
451 }
452
453 result
454 Calendarbook::AddCalendar(Calendar& calendar)
455 {
456         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
457         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
458         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
459         SysAssertf(__pCalendarbookImpl != null,
460                         "Not yet constructed. Construct() should be called before use.");
461
462         r = __pCalendarbookImpl->AddCalendar(calendar);
463         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
464
465         return E_SUCCESS;
466 }
467
468 result
469 Calendarbook::AddCalendar(Calendar& calendar, AccountId accountId)
470 {
471         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
472         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
473         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
474         SysAssertf(__pCalendarbookImpl != null,
475                         "Not yet constructed. Construct() should be called before use.");
476
477         r = __pCalendarbookImpl->AddCalendar(calendar, accountId);
478         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
479
480         return E_SUCCESS;
481 }
482
483 result
484 Calendarbook::RemoveCalendar(RecordId calendarId)
485 {
486         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
487         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
488         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
489         SysAssertf(__pCalendarbookImpl != null,
490                         "Not yet constructed. Construct() should be called before use.");
491
492         r = __pCalendarbookImpl->RemoveCalendar(calendarId);
493         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
494
495         return E_SUCCESS;
496 }
497
498 result
499 Calendarbook::UpdateCalendar(const Calendar& calendar)
500 {
501         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
502         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
503         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
504         SysAssertf(__pCalendarbookImpl != null,
505                         "Not yet constructed. Construct() should be called before use.");
506
507         r = __pCalendarbookImpl->UpdateCalendar(calendar);
508         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
509
510         return E_SUCCESS;
511 }
512
513 Calendar*
514 Calendarbook::GetCalendarN(RecordId calendarId) const
515 {
516         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
517         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
518         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
519         SysAssertf(__pCalendarbookImpl != null,
520                         "Not yet constructed. Construct() should be called before use.");
521
522         Calendar* pCalendar = __pCalendarbookImpl->GetCalendarN(calendarId);
523         r = GetLastResult();
524         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
525
526         return pCalendar;
527 }
528
529 result
530 Calendarbook::RemoveEventInstance(const CalEventInstance& eventInstance)
531 {
532         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
533         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
534         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
535         SysAssertf(__pCalendarbookImpl != null,
536                         "Not yet constructed. Construct() should be called before use.");
537
538         r = __pCalendarbookImpl->RemoveEventInstance(eventInstance);
539         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
540
541         return E_SUCCESS;
542 }
543
544 result
545 Calendarbook::UpdateEventInstance(const CalEventInstance& eventInstance, CalEvent& event)
546 {
547         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_WRITE);
548         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
549         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
550         SysAssertf(__pCalendarbookImpl != null,
551                         "Not yet constructed. Construct() should be called before use.");
552
553         r = __pCalendarbookImpl->UpdateEventInstance(eventInstance, event);
554         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
555
556         return E_SUCCESS;
557 }
558
559 int
560 Calendarbook::GetLatestVersion(void) const
561 {
562         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
563         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
564         SysTryReturn(NID_SCL, r == E_SUCCESS, _INVALID_VERSION, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
565         SysAssertf(__pCalendarbookImpl != null,
566                         "Not yet constructed. Construct() should be called before use.");
567
568         int version = __pCalendarbookImpl->GetLatestVersion();
569         r = GetLastResult();
570         SysTryReturn(NID_SCL, r == E_SUCCESS, _INVALID_VERSION, r, "[%s] Propagating.", GetErrorMessage(r));
571
572         return version;
573 }
574
575 IList*
576 Calendarbook::SearchN(const CalendarbookFilter& filter, unsigned long propertySortedBy, SortOrder sortOrder, int offset, int maxCount) const
577 {
578         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
579         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
580         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
581         SysAssertf(__pCalendarbookImpl != null,
582                         "Not yet constructed. Construct() should be called before use.");
583
584         IList* pList = __pCalendarbookImpl->SearchN(filter, propertySortedBy, sortOrder, offset, maxCount);
585         r = GetLastResult();
586         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
587
588         return pList;
589 }
590
591 int
592 Calendarbook::GetMatchedItemCount(const CalendarbookFilter& filter) const
593 {
594         result r = _AccessController::CheckUserPrivilege(_PRV_CALENDAR_READ);
595         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
596         SysTryReturn(NID_SCL, r == E_SUCCESS, _INVALID_COUNT, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
597         SysAssertf(__pCalendarbookImpl != null,
598                         "Not yet constructed. Construct() should be called before use.");
599
600         int count = __pCalendarbookImpl->GetMatchedItemCount(filter);
601         r = GetLastResult();
602         SysTryReturn(NID_SCL, r == E_SUCCESS, _INVALID_COUNT, r, "[%s] Propagating.", GetErrorMessage(r));
603
604         return count;
605 }
606
607 IList*
608 Calendarbook::ParseEventsFromVcalendarN(const String& vCalFilePath)
609 {
610         IList* pList = _CalendarbookImpl::ParseEventsFromVcalendarN(vCalFilePath);
611         result r = GetLastResult();
612         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
613
614         return pList;
615 }
616
617 IList*
618 Calendarbook::ParseTodosFromVcalendarN(const String& vCalFilePath)
619 {
620         IList* pList = _CalendarbookImpl::ParseTodosFromVcalendarN(vCalFilePath);
621         result r = GetLastResult();
622         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
623
624         return pList;
625 }
626
627 result
628 Calendarbook::ExportEventsToVcalendar(const IList& eventList, const String& vCalFilePath)
629 {
630         result r = _CalendarbookImpl::ExportEventsToVcalendar(eventList, vCalFilePath);
631         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
632
633         return E_SUCCESS;
634 }
635
636 result
637 Calendarbook::ExportTodosToVcalendar(const IList& todoList, const String& vCalFilePath)
638 {
639         result r = _CalendarbookImpl::ExportTodosToVcalendar(todoList, vCalFilePath);
640         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
641
642         return E_SUCCESS;
643 }
644
645 DateTime
646 Calendarbook::GetMaxDateTime(void)
647 {
648         return _CalendarbookImpl::GetMaxDateTime();
649 }
650 DateTime
651 Calendarbook::GetMinDateTime(void)
652 {
653         return _CalendarbookImpl::GetMinDateTime();
654 }
655
656 }}      // Tizen::Social