Fixed update instance
[framework/osp/social.git] / src / FSclAddressbook.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file                FSclAddressbook.cpp
19  * @brief               This is the implementation for Addressbook class.
20  *
21  * This file contains definitions of @e Addressbook class.
22  */
23
24 #include <new>
25 #include <FBaseColIList.h>
26 #include <FBaseResult.h>
27 #include <FBaseString.h>
28 #include <FBaseSysLog.h>
29 #include <FSclAddressbook.h>
30 #include <FSclCategory.h>
31 #include <FSclContact.h>
32 #include <FSclUserProfile.h>
33 #include <FSec_AccessController.h>
34 #include "FScl_AddressbookImpl.h"
35 #include "FScl_CategoryImpl.h"
36 #include "FScl_ContactImpl.h"
37 #include "FScl_RecordImpl.h"
38
39 using namespace Tizen::Base;
40 using namespace Tizen::Base::Collection;
41 using namespace Tizen::Security;
42
43 namespace Tizen { namespace Social
44 {
45
46 Addressbook::Addressbook(void)
47         : __pAddressbookImpl(null)
48 {
49         //empty body
50 }
51
52 Addressbook::~Addressbook(void)
53 {
54         delete __pAddressbookImpl;
55 }
56
57 result
58 Addressbook::Construct(IRecordEventListener* pListener)
59 {
60         result r = E_SUCCESS;
61
62         SysAssertf(__pAddressbookImpl == null,
63                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
64
65         __pAddressbookImpl = new (std::nothrow) _AddressbookImpl();
66         SysTryReturn(NID_SCL, __pAddressbookImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
67
68         r = __pAddressbookImpl->Construct();
69         SysTryCatch(NID_SCL, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
70
71         if (pListener != null)
72         {
73                 r = __pAddressbookImpl->SetRecordEventListener(pListener);
74                 SysTryCatch(NID_SCL, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
75         }
76
77         return E_SUCCESS;
78
79 CATCH:
80         delete __pAddressbookImpl;
81         __pAddressbookImpl = null;
82
83         return r;
84 }
85
86 result
87 Addressbook::SetEventListener(IAddressbookEventListener* pListener)
88 {
89         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
90                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
91         SysAssertf(__pAddressbookImpl != null,
92                         "Not yet constructed. Construct() should be called before use.");
93
94         result r = __pAddressbookImpl->SetAddressbookEventListener(pListener);
95         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
96
97         return E_SUCCESS;
98 }
99
100 result
101 Addressbook::SetAddressbookChangeEventListener(IAddressbookChangeEventListener* pListener)
102 {
103         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
104                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
105         SysAssertf(__pAddressbookImpl != null,
106                         "Not yet constructed. Construct() should be called before use.");
107
108         result r = __pAddressbookImpl->SetAddressbookChangeEventListener(pListener);
109         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
110
111         return E_SUCCESS;
112 }
113
114 String
115 Addressbook::GetName(void) const
116 {
117         SysAssertf(__pAddressbookImpl != null,
118                         "Not yet constructed. Construct() should be called before use.");
119
120         return __pAddressbookImpl->GetName();
121 }
122
123 AddressbookId
124 Addressbook::GetId(void) const
125 {
126         SysAssertf(__pAddressbookImpl != null,
127                         "Not yet constructed. Construct() should be called before use.");
128
129         return __pAddressbookImpl->GetId();
130 }
131
132 AccountId
133 Addressbook::GetAccountId(void) const
134 {
135         SysAssertf(__pAddressbookImpl != null,
136                         "Not yet constructed. Construct() should be called before use.");
137
138         return __pAddressbookImpl->GetAccountId();
139 }
140
141 result
142 Addressbook::AddContact(Contact& contact)
143 {
144         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
145                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
146         SysAssertf(__pAddressbookImpl != null,
147                         "Not yet constructed. Construct() should be called before use.");
148
149         result r = __pAddressbookImpl->AddContact(contact);
150         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
151
152         return E_SUCCESS;
153 }
154
155 result
156 Addressbook::AddCategory(Category& category)
157 {
158         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
159                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
160         SysAssertf(__pAddressbookImpl != null,
161                         "Not yet constructed. Construct() should be called before use.");
162
163         result r = __pAddressbookImpl->AddCategory(category);
164         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
165
166         return E_SUCCESS;
167 }
168
169 result
170 Addressbook::RemoveContact(Contact& contact)
171 {
172         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
173                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
174         SysAssertf(__pAddressbookImpl != null,
175                         "Not yet constructed. Construct() should be called before use.");
176
177         result r = __pAddressbookImpl->RemoveContact(contact);
178         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
179
180         return E_SUCCESS;
181 }
182
183 result
184 Addressbook::RemoveContact(RecordId contactId)
185 {
186         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
187                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
188         SysAssertf(__pAddressbookImpl != null,
189                         "Not yet constructed. Construct() should be called before use.");
190
191         result r = __pAddressbookImpl->RemoveContact(contactId);
192         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
193
194         return E_SUCCESS;
195 }
196
197 result
198 Addressbook::RemoveCategory(Category& category)
199 {
200         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
201                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
202         SysAssertf(__pAddressbookImpl != null,
203                         "Not yet constructed. Construct() should be called before use.");
204
205         result r = __pAddressbookImpl->RemoveCategory(category.GetRecordId());
206         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
207
208         _CategoryImpl::GetInstance(category)->Invalidate();
209         _RecordImpl::GetInstance(category)->SetRecordId(INVALID_RECORD_ID);
210
211         return E_SUCCESS;
212 }
213
214 result
215 Addressbook::RemoveCategory(RecordId categoryId)
216 {
217         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
218                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
219         SysAssertf(__pAddressbookImpl != null,
220                         "Not yet constructed. Construct() should be called before use.");
221
222         result r = __pAddressbookImpl->RemoveCategory(categoryId);
223         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
224
225         return E_SUCCESS;
226 }
227
228 result
229 Addressbook::UpdateContact(const Contact& contact)
230 {
231         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
232                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
233         SysAssertf(__pAddressbookImpl != null,
234                         "Not yet constructed. Construct() should be called before use.");
235
236         result r = __pAddressbookImpl->UpdateContact(contact);
237         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
238
239         return E_SUCCESS;
240 }
241
242 result
243 Addressbook::UpdateCategory(const Category& category)
244 {
245         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
246                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
247         SysAssertf(__pAddressbookImpl != null,
248                         "Not yet constructed. Construct() should be called before use.");
249
250         result r = __pAddressbookImpl->UpdateCategory(category);
251         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
252
253         return E_SUCCESS;
254 }
255
256 IList*
257 Addressbook::GetAllContactsN(void) const
258 {
259         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
260                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
261         SysAssertf(__pAddressbookImpl != null,
262                         "Not yet constructed. Construct() should be called before use.");
263
264         IList* pList = __pAddressbookImpl->GetAllContactsN();
265         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
266
267         return pList;
268 }
269
270 IList*
271 Addressbook::GetContactsByCategoryN(RecordId categoryId) const
272 {
273         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
274                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
275         SysAssertf(__pAddressbookImpl != null,
276                         "Not yet constructed. Construct() should be called before use.");
277
278         IList* pList = __pAddressbookImpl->GetContactsByCategoryN(categoryId);
279         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
280
281         return pList;
282 }
283
284 result
285 Addressbook::AddMemberToCategory(RecordId categoryId, RecordId contactId)
286 {
287         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
288                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
289         SysAssertf(__pAddressbookImpl != null,
290                         "Not yet constructed. Construct() should be called before use.");
291
292         result r = __pAddressbookImpl->AddMemberToCategory(categoryId, contactId);
293         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
294
295         return E_SUCCESS;
296 }
297
298 result
299 Addressbook::RemoveMemberFromCategory(RecordId categoryId, RecordId contactId)
300 {
301         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
302                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
303         SysAssertf(__pAddressbookImpl != null,
304                         "Not yet constructed. Construct() should be called before use.");
305
306         result r = __pAddressbookImpl->RemoveMemberFromCategory(categoryId, contactId);
307         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
308
309         return E_SUCCESS;
310 }
311
312 IList*
313 Addressbook::GetAllCategoriesN(void) const
314 {
315         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
316                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
317         SysAssertf(__pAddressbookImpl != null,
318                         "Not yet constructed. Construct() should be called before use.");
319
320         IList* pList = __pAddressbookImpl->GetAllCategoriesN();
321         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
322
323         return pList;
324 }
325
326 IList*
327 Addressbook::GetCategoriesByContactN(RecordId contactId) const
328 {
329         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
330                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
331         SysAssertf(__pAddressbookImpl != null,
332                         "Not yet constructed. Construct() should be called before use.");
333
334         IList* pList = __pAddressbookImpl->GetCategoriesByContactN(contactId);
335         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
336
337         return pList;
338 }
339
340 IList*
341 Addressbook::GetContactsN(int pageNo, int countPerPage) const
342 {
343         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
344                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
345         SysAssertf(__pAddressbookImpl != null,
346                         "Not yet constructed. Construct() should be called before use.");
347
348         IList* pList = __pAddressbookImpl->GetContactsN(pageNo, countPerPage);
349         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
350
351         return pList;
352 }
353
354 IList*
355 Addressbook::GetContactsInN(const Category& category, int pageNo, int countPerPage) const
356 {
357         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
358                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
359         SysAssertf(__pAddressbookImpl != null,
360                         "Not yet constructed. Construct() should be called before use.");
361
362         IList* pList = __pAddressbookImpl->GetContactsInN(category, pageNo, countPerPage);
363         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
364
365         return pList;
366 }
367
368 IList*
369 Addressbook::SearchContactsByEmailN(const String& email) const
370 {
371         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
372                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
373         SysAssertf(__pAddressbookImpl != null,
374                         "Not yet constructed. Construct() should be called before use.");
375
376         IList* pList = __pAddressbookImpl->SearchContactsByEmailN(email);
377         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
378
379         return pList;
380 }
381
382 IList*
383 Addressbook::SearchContactsByNameN(const String& name) const
384 {
385         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
386                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
387         SysAssertf(__pAddressbookImpl != null,
388                         "Not yet constructed. Construct() should be called before use.");
389
390         IList* pList = __pAddressbookImpl->SearchContactsByNameN(name);
391         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
392
393         return pList;
394 }
395
396 IList*
397 Addressbook::SearchContactsByPhoneNumberN(const String& phoneNumber) const
398 {
399         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
400                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
401         SysAssertf(__pAddressbookImpl != null,
402                         "Not yet constructed. Construct() should be called before use.");
403
404         IList* pList = __pAddressbookImpl->SearchContactsByPhoneNumberN(phoneNumber);
405         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
406
407         return pList;
408 }
409
410 int
411 Addressbook::GetCategoryCount(void) const
412 {
413         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, -1, E_PRIVILEGE_DENIED,
414                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
415         SysAssertf(__pAddressbookImpl != null,
416                         "Not yet constructed. Construct() should be called before use.");
417
418         int count = __pAddressbookImpl->GetCategoryCount();
419         SysTryReturn(NID_SCL, count != -1, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
420
421         return count;
422 }
423
424 int
425 Addressbook::GetContactCount(void) const
426 {
427         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, -1, E_PRIVILEGE_DENIED,
428                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
429         SysAssertf(__pAddressbookImpl != null,
430                         "Not yet constructed. Construct() should be called before use.");
431
432         int count = __pAddressbookImpl->GetContactCount();
433         SysTryReturn(NID_SCL, count != -1, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
434
435         return count;
436 }
437
438 Contact*
439 Addressbook::GetContactN(RecordId contactId) const
440 {
441         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
442                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
443         SysAssertf(__pAddressbookImpl != null,
444                         "Not yet constructed. Construct() should be called before use.");
445
446         Contact* pContact = __pAddressbookImpl->GetContactN(contactId);
447         SysTryReturn(NID_SCL, pContact != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
448
449         return pContact;
450 }
451
452 Category*
453 Addressbook::GetCategoryN(RecordId categoryId) const
454 {
455         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
456                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
457         SysAssertf(__pAddressbookImpl != null,
458                         "Not yet constructed. Construct() should be called before use.");
459
460         Category* pCategory = __pAddressbookImpl->GetCategoryN(categoryId);
461         SysTryReturn(NID_SCL, pCategory != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
462
463         return pCategory;
464 }
465
466 int
467 Addressbook::GetLatestVersion(void) const
468 {
469         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, -1, E_PRIVILEGE_DENIED,
470                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
471         SysAssertf(__pAddressbookImpl != null,
472                         "Not yet constructed. Construct() should be called before use.");
473
474         int latestVersion = __pAddressbookImpl->GetLatestVersion();
475         SysTryReturn(NID_SCL, latestVersion != -1, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
476
477         return latestVersion;
478 }
479
480 IList*
481 Addressbook::GetChangedContactsAfterN(int version, int& latestVersion) const
482 {
483         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
484                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
485         SysAssertf(__pAddressbookImpl != null,
486                         "Not yet constructed. Construct() should be called before use.");
487
488         IList* pList = __pAddressbookImpl->GetChangedContactsAfterN(version, latestVersion);
489         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
490
491         return pList;
492 }
493
494 IList*
495 Addressbook::GetChangedCategoriesAfterN(int version, int& latestVersion) const
496 {
497         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
498                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
499         SysAssertf(__pAddressbookImpl != null,
500                         "Not yet constructed. Construct() should be called before use.");
501
502         IList* pList = __pAddressbookImpl->GetChangedCategoriesAfterN(version, latestVersion);
503         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
504
505         return pList;
506 }
507
508 IList*
509 Addressbook::GetChangedContactInfoListN(int version, int& latestVersion) const
510 {
511         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
512                         "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
513         SysAssertf(__pAddressbookImpl != null,
514                         "Not yet constructed. Construct() should be called before use.");
515
516         IList* pList = __pAddressbookImpl->GetChangedContactInfoListN(version, latestVersion);
517         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
518
519         return pList;
520 }
521
522 IList*
523 Addressbook::GetChangedCategoryInfoListN(int version, int& latestVersion) const
524 {
525         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
526                         "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
527         SysAssertf(__pAddressbookImpl != null,
528                         "Not yet constructed. Construct() should be called before use.");
529
530         IList* pList = __pAddressbookImpl->GetChangedCategoryInfoListN(version, latestVersion);
531         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
532
533         return pList;
534 }
535
536 result
537 Addressbook::AddContacts(const IList& contactList, IListT<RecordId>* pContactIdList)
538 {
539         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
540                         "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
541         SysAssertf(__pAddressbookImpl != null,
542                         "Not yet constructed. Construct() should be called before use.");
543
544         result r = E_SUCCESS;
545
546         r = __pAddressbookImpl->AddContacts(contactList, pContactIdList);
547
548         return r;
549 }
550
551 result
552 Addressbook::UpdateContacts(const IList& contactList)
553 {
554         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
555                         "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
556         SysAssertf(__pAddressbookImpl != null,
557                         "Not yet constructed. Construct() should be called before use.");
558
559         result r = E_SUCCESS;
560
561         r = __pAddressbookImpl->UpdateContacts(contactList);
562
563         return r;
564 }
565
566 result
567 Addressbook::RemoveContacts(const IListT<RecordId>& contactIdList)
568 {
569         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
570                         "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
571         SysAssertf(__pAddressbookImpl != null,
572                         "Not yet constructed. Construct() should be called before use.");
573
574         result r = E_SUCCESS;
575
576         r = __pAddressbookImpl->RemoveContacts(contactIdList);
577
578         return r;
579 }
580
581 result
582 Addressbook::SetUserProfile(const UserProfile* pUserProfile)
583 {
584         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_USERPROFILE_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
585                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
586         SysAssertf(__pAddressbookImpl != null,
587                         "Not yet constructed. Construct() should be called before use.");
588
589         result r = __pAddressbookImpl->SetUserProfile(pUserProfile);
590         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
591
592         return E_SUCCESS;
593 }
594
595 UserProfile*
596 Addressbook::GetUserProfileN(void) const
597 {
598         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_USERPROFILE_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
599                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
600         SysAssertf(__pAddressbookImpl != null,
601                         "Not yet constructed. Construct() should be called before use.");
602
603         UserProfile* pProfile = __pAddressbookImpl->GetUserProfileN();
604         SysTryReturn(NID_SCL, pProfile != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
605
606         return pProfile;
607 }
608
609 bool
610 Addressbook::IsUserProfileChangedAfter(int version) const
611 {
612         SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_USERPROFILE_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
613                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
614         SysAssertf(__pAddressbookImpl != null,
615                         "Not yet constructed. Construct() should be called before use.");
616
617         bool isChanged = __pAddressbookImpl->IsUserProfileChangedAfter(version);
618         SysTryReturn(NID_SCL, GetLastResult() == E_SUCCESS, false, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
619
620         return isChanged;
621 }
622
623 }}  // Tizen::Social