Modify the spec file for secure log
[framework/osp/social.git] / src / FSclAddressbookManager.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                FSclAddressbookManager.cpp
18  * @brief               This is the implementation for AddressbookManager class.
19  *
20  * This file contains definitions of @e AddressbookManager class.
21  */
22
23 #include <unique_ptr.h>
24 #include <pthread.h>
25 #include <FBaseResult.h>
26 #include <FBaseString.h>
27 #include <FBaseColIList.h>
28 #include <FBaseSysLog.h>
29 #include <FSclContact.h>
30 #include <FSclCategory.h>
31 #include <FSclUserProfile.h>
32 #include <FSclAddressbookManager.h>
33 #include <FSec_AccessController.h>
34 #include <FScl_AddressbookManagerImpl.h>
35
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Security;
39
40 namespace Tizen { namespace Social
41 {
42
43 AddressbookManager* AddressbookManager::__pInstance = null;
44
45 AddressbookManager::AddressbookManager(void)
46         : __pAddressbookManagerImpl(null)
47 {
48         //empty body
49 }
50
51 AddressbookManager::~AddressbookManager(void)
52 {
53         delete __pAddressbookManagerImpl;
54 }
55
56 result
57 AddressbookManager::Construct(void)
58 {
59         result r = E_SUCCESS;
60
61         SysAssertf(__pAddressbookManagerImpl == null,
62                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
63
64         _AddressbookManagerImpl* pAddressbookManagerImpl = new (std::nothrow) _AddressbookManagerImpl();
65         SysTryReturnResult(NID_SCL, pAddressbookManagerImpl != null, E_OUT_OF_MEMORY, "Not enough memory.");
66
67         r = pAddressbookManagerImpl->Construct();
68         SysTryCatch(NID_SCL, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
69
70         __pAddressbookManagerImpl = pAddressbookManagerImpl;
71
72         return E_SUCCESS;
73
74 CATCH:
75         delete pAddressbookManagerImpl;
76
77         return r;
78 }
79
80 result
81 AddressbookManager::SetEventListener(IAddressbookEventListener* pListener)
82 {
83         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
84         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
85         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
86         SysAssertf(__pAddressbookManagerImpl != null,
87                         "Not yet constructed. Construct() should be called before use.");
88
89         r = __pAddressbookManagerImpl->SetEventListener(pListener);
90         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
91
92         return E_SUCCESS;
93 }
94
95 result
96 AddressbookManager::SetAddressbookChangeEventListener(IAddressbookChangeEventListener* pListener)
97 {
98         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
99         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
100         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
101         SysAssertf(__pAddressbookManagerImpl != null,
102                         "Not yet constructed. Construct() should be called before use.");
103
104         r = __pAddressbookManagerImpl->SetAddressbookChangeEventListener(pListener);
105         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
106
107         return E_SUCCESS;
108 }
109
110 Addressbook*
111 AddressbookManager::CreateAddressbookN(AccountId accountId, const String& name)
112 {
113         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
114         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
115         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
116         SysAssertf(__pAddressbookManagerImpl != null,
117                         "Not yet constructed. Construct() should be called before use.");
118
119         Addressbook* pAddressbook = __pAddressbookManagerImpl->CreateAddressbookN(accountId, name);
120         SysTryReturn(NID_SCL, pAddressbook != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
121
122         return pAddressbook;
123 }
124
125 result
126 AddressbookManager::DeleteAddressbook(AddressbookId addressbookId)
127 {
128         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
129         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
130         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
131         SysAssertf(__pAddressbookManagerImpl != null,
132                         "Not yet constructed. Construct() should be called before use.");
133
134         r = __pAddressbookManagerImpl->DeleteAddressbook(addressbookId);
135         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
136
137         return E_SUCCESS;
138 }
139
140 IList*
141 AddressbookManager::GetAddressbooksByAccountN(AccountId accountId) const
142 {
143         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
144         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
145         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
146         SysAssertf(__pAddressbookManagerImpl != null,
147                         "Not yet constructed. Construct() should be called before use.");
148
149         IList*  pList = __pAddressbookManagerImpl->GetAddressbooksByAccountN(accountId);
150         SysTryReturn(NID_SCL, pList !=null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
151
152         return pList;
153 }
154
155 IList*
156 AddressbookManager::GetAllAddressbooksN(void) const
157 {
158         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
159         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
160         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
161         SysAssertf(__pAddressbookManagerImpl != null,
162                         "Not yet constructed. Construct() should be called before use.");
163
164         IList* pList = __pAddressbookManagerImpl->GetAllAddressbooksN();
165         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
166
167         return pList;
168 }
169
170 Addressbook*
171 AddressbookManager::GetAddressbookN(AddressbookId addressbookId) const
172 {
173         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
174         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
175         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
176         SysAssertf(__pAddressbookManagerImpl != null,
177                         "Not yet constructed. Construct() should be called before use.");
178
179         Addressbook* pAddressbook = __pAddressbookManagerImpl->GetAddressbookN(addressbookId);
180         SysTryReturn(NID_SCL, pAddressbook != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
181
182         return pAddressbook;
183 }
184
185 result
186 AddressbookManager::AddContact(Contact& contact, AddressbookId addressbookId)
187 {
188         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
189         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
190         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
191         SysAssertf(__pAddressbookManagerImpl != null,
192                         "Not yet constructed. Construct() should be called before use.");
193
194         r = __pAddressbookManagerImpl->AddContact(contact, addressbookId);
195         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
196
197         return E_SUCCESS;
198 }
199
200 result
201 AddressbookManager::AddCategory(Category& category, AddressbookId addressbookId)
202 {
203         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
204         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
205         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
206         SysAssertf(__pAddressbookManagerImpl != null,
207                         "Not yet constructed. Construct() should be called before use.");
208
209         r = __pAddressbookManagerImpl->AddCategory(category, addressbookId);
210         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
211
212         return E_SUCCESS;
213 }
214
215 result
216 AddressbookManager::RemoveContact(RecordId contactId)
217 {
218         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
219         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
220         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
221         SysAssertf(__pAddressbookManagerImpl != null,
222                         "Not yet constructed. Construct() should be called before use.");
223
224         r = __pAddressbookManagerImpl->RemoveContact(contactId);
225         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
226
227         return E_SUCCESS;
228 }
229
230 result
231 AddressbookManager::RemoveCategory(RecordId categoryId)
232 {
233         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
234         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
235         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
236         SysAssertf(__pAddressbookManagerImpl != null,
237                         "Not yet constructed. Construct() should be called before use.");
238
239         r = __pAddressbookManagerImpl->RemoveCategory(categoryId);
240         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
241
242         return E_SUCCESS;
243 }
244
245 result
246 AddressbookManager::UpdateContact(const Contact& contact)
247 {
248         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
249         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
250         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
251         SysAssertf(__pAddressbookManagerImpl != null,
252                         "Not yet constructed. Construct() should be called before use.");
253
254         r = __pAddressbookManagerImpl->UpdateContact(contact);
255         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
256
257         return E_SUCCESS;
258 }
259
260 result
261 AddressbookManager::UpdateCategory(const Category& category)
262 {
263         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
264         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
265         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
266         SysAssertf(__pAddressbookManagerImpl != null,
267                         "Not yet constructed. Construct() should be called before use.");
268
269         r = __pAddressbookManagerImpl->UpdateCategory(category);
270         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
271
272         return E_SUCCESS;
273 }
274
275 IList*
276 AddressbookManager::GetAllContactsN(void) const
277 {
278         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
279         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
280         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
281         SysAssertf(__pAddressbookManagerImpl != null,
282                         "Not yet constructed. Construct() should be called before use.");
283
284         IList* pList = __pAddressbookManagerImpl->GetAllContactsN();
285         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
286
287         return pList;
288 }
289
290 IList*
291 AddressbookManager::GetContactsByCategoryN(RecordId categoryId) const
292 {
293         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
294         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
295         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
296         SysAssertf(__pAddressbookManagerImpl != null,
297                         "Not yet constructed. Construct() should be called before use.");
298
299         IList* pList = __pAddressbookManagerImpl->GetContactsByCategoryN(categoryId);
300         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
301
302         return pList;
303 }
304
305 IList*
306 AddressbookManager::GetContactsByPersonN(PersonId personId) const
307 {
308         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
309         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
310         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
311         SysAssertf(__pAddressbookManagerImpl != null,
312                         "Not yet constructed. Construct() should be called before use.");
313
314         IList* pList = __pAddressbookManagerImpl->GetContactsByPersonN(personId);
315         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
316
317         return pList;
318 }
319
320 result
321 AddressbookManager::AddMemberToCategory(RecordId categoryId, RecordId contactId)
322 {
323         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
324         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
325         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
326         SysAssertf(__pAddressbookManagerImpl != null,
327                         "Not yet constructed. Construct() should be called before use.");
328
329         r = __pAddressbookManagerImpl->AddMemberToCategory(categoryId, contactId);
330         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
331
332         return E_SUCCESS;
333 }
334
335 result
336 AddressbookManager::RemoveMemberFromCategory(RecordId categoryId, RecordId contactId)
337 {
338         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
339         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
340         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
341         SysAssertf(__pAddressbookManagerImpl != null,
342                         "Not yet constructed. Construct() should be called before use.");
343
344         r = __pAddressbookManagerImpl->RemoveMemberFromCategory(categoryId, contactId);
345         SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
346
347         return E_SUCCESS;
348 }
349
350 IList*
351 AddressbookManager::GetAllCategoriesN(void) const
352 {
353         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
354         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
355         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
356         SysAssertf(__pAddressbookManagerImpl != null,
357                         "Not yet constructed. Construct() should be called before use.");
358
359         IList* pList = __pAddressbookManagerImpl->GetAllCategoriesN();
360         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
361
362         return pList;
363 }
364
365 IList*
366 AddressbookManager::GetCategoriesByContactN(RecordId contactId) const
367 {
368         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
369         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
370         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
371         SysAssertf(__pAddressbookManagerImpl != null,
372                         "Not yet constructed. Construct() should be called before use.");
373
374         IList* pList = __pAddressbookManagerImpl->GetCategoriesByContactN(contactId);
375         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
376
377         return pList;
378 }
379
380 IList*
381 AddressbookManager::GetCategoriesByPersonN(PersonId personId) const
382 {
383         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
384         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
385         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
386         SysAssertf(__pAddressbookManagerImpl != null,
387                         "Not yet constructed. Construct() should be called before use.");
388
389         IList* pList = __pAddressbookManagerImpl->GetCategoriesByPersonN(personId);
390         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
391
392         return pList;
393 }
394
395 IList*
396 AddressbookManager::SearchContactsByEmailN(const String& email) const
397 {
398         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
399         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
400         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
401         SysAssertf(__pAddressbookManagerImpl != null,
402                         "Not yet constructed. Construct() should be called before use.");
403
404         IList* pList = __pAddressbookManagerImpl->SearchContactsByEmailN(email);
405         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
406
407         return pList;
408 }
409
410 IList*
411 AddressbookManager::SearchContactsByNameN(const String& name) const
412 {
413         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
414         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
415         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
416         SysAssertf(__pAddressbookManagerImpl != null,
417                         "Not yet constructed. Construct() should be called before use.");
418
419         IList* pList = __pAddressbookManagerImpl->SearchContactsByNameN(name);
420         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
421
422         return pList;
423 }
424
425 IList*
426 AddressbookManager::SearchContactsByPhoneNumberN(const String& phoneNumber) const
427 {
428         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
429         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
430         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
431         SysAssertf(__pAddressbookManagerImpl != null,
432                         "Not yet constructed. Construct() should be called before use.");
433
434         IList* pList = __pAddressbookManagerImpl->SearchContactsByPhoneNumberN(phoneNumber);
435         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
436
437         return pList;
438 }
439
440 int
441 AddressbookManager::GetCategoryCount(void) const
442 {
443         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
444         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
445         SysTryReturn(NID_SCL, r == E_SUCCESS, -1, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
446         SysAssertf(__pAddressbookManagerImpl != null,
447                         "Not yet constructed. Construct() should be called before use.");
448
449         int count = __pAddressbookManagerImpl->GetCategoryCount();
450         SysTryReturn(NID_SCL, count != -1, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
451
452         return count;
453 }
454
455 int
456 AddressbookManager::GetContactCount(void) const
457 {
458         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
459         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
460         SysTryReturn(NID_SCL, r == E_SUCCESS, -1, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
461         SysAssertf(__pAddressbookManagerImpl != null,
462                         "Not yet constructed. Construct() should be called before use.");
463
464         int count = __pAddressbookManagerImpl->GetContactCount();
465         SysTryReturn(NID_SCL, count != -1, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
466
467         return count;
468 }
469
470 Contact*
471 AddressbookManager::GetContactN(RecordId contactId) const
472 {
473         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
474         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
475         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
476         SysAssertf(__pAddressbookManagerImpl != null,
477                         "Not yet constructed. Construct() should be called before use.");
478
479         Contact* pContact = __pAddressbookManagerImpl->GetContactN(contactId);
480         SysTryReturn(NID_SCL, pContact != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
481
482         return pContact;
483 }
484
485 Person*
486 AddressbookManager::GetPersonN(PersonId personId) const
487 {
488         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
489         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
490         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
491         SysAssertf(__pAddressbookManagerImpl != null,
492                         "Not yet constructed. Construct() should be called before use.");
493
494         Person* pPerson = __pAddressbookManagerImpl->GetPersonN(personId);
495         SysTryReturn(NID_SCL, pPerson != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
496
497         return pPerson;
498 }
499 Category*
500 AddressbookManager::GetCategoryN(RecordId categoryId) const
501 {
502         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
503         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
504         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
505         SysAssertf(__pAddressbookManagerImpl != null,
506                         "Not yet constructed. Construct() should be called before use.");
507
508         Category* pCategory = __pAddressbookManagerImpl->GetCategoryN(categoryId);
509         SysTryReturn(NID_SCL, pCategory != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
510
511         return pCategory;
512 }
513
514 int
515 AddressbookManager::GetLatestVersion(void) const
516 {
517         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
518         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
519         SysTryReturn(NID_SCL, r == E_SUCCESS, -1, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
520         SysAssertf(__pAddressbookManagerImpl != null,
521                         "Not yet constructed. Construct() should be called before use.");
522
523         int latestVersion = __pAddressbookManagerImpl->GetLatestVersion();
524         SysTryReturn(NID_SCL, latestVersion != -1, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
525
526         return latestVersion;
527 }
528
529 IList*
530 AddressbookManager::GetChangedContactsAfterN(int version, int& latestVersion) const
531 {
532         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
533         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
534         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
535         SysAssertf(__pAddressbookManagerImpl != null,
536                         "Not yet constructed. Construct() should be called before use.");
537
538         IList* pList = __pAddressbookManagerImpl->GetChangedContactsAfterN(version, latestVersion);
539         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
540
541         return pList;
542 }
543
544 IList*
545 AddressbookManager::GetChangedCategoriesAfterN(int version, int& latestVersion) const
546 {
547         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
548         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
549         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
550         SysAssertf(__pAddressbookManagerImpl != null,
551                         "Not yet constructed. Construct() should be called before use.");
552
553         IList* pList = __pAddressbookManagerImpl->GetChangedCategoriesAfterN(version, latestVersion);
554         SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
555
556         return pList;
557 }
558
559 result
560 AddressbookManager::RemovePerson(PersonId personId)
561 {
562         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
563         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
564         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
565         SysAssertf(__pAddressbookManagerImpl != null,
566                         "Not yet constructed. Construct() should be called before use.");
567
568         return __pAddressbookManagerImpl->RemovePerson(personId);
569 }
570
571 result
572 AddressbookManager::SetPersonAsFavorite(PersonId personId, bool isFavorite)
573 {
574         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
575         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
576         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
577         SysAssertf(__pAddressbookManagerImpl != null,
578                         "Not yet constructed. Construct() should be called before use.");
579
580         return __pAddressbookManagerImpl->SetPersonAsFavorite(personId, isFavorite);
581 }
582
583 IList*
584 AddressbookManager::GetAllPersonsN(void) const
585 {       
586         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
587         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
588         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
589         SysAssertf(__pAddressbookManagerImpl != null,
590                         "Not yet constructed. Construct() should be called before use.");
591
592         return __pAddressbookManagerImpl->GetAllPersonsN();
593 }
594
595 IList*
596 AddressbookManager::GetPersonsByCategoryN(RecordId categoryId) const
597 {
598         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
599         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
600         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
601         SysAssertf(__pAddressbookManagerImpl != null,
602                         "Not yet constructed. Construct() should be called before use.");
603
604         return __pAddressbookManagerImpl->GetPersonsByCategoryN(categoryId);
605 }
606
607 IList*
608 AddressbookManager::GetFavoritePersonsN() const
609 {
610         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
611         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
612         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
613         SysAssertf(__pAddressbookManagerImpl != null,
614                         "Not yet constructed. Construct() should be called before use.");
615
616         return __pAddressbookManagerImpl->GetFavoritePersonsN();
617 }
618
619 IList*
620 AddressbookManager::SearchPersonsN(const Tizen::Base::String& keyword) const
621 {       
622         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
623         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
624         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
625         SysAssertf(__pAddressbookManagerImpl != null,
626                         "Not yet constructed. Construct() should be called before use.");
627
628         return __pAddressbookManagerImpl->SearchPersonsN(keyword);
629 }
630
631 result
632 AddressbookManager::MergePersons(PersonId sourcePersonId, PersonId targetPersonId)
633 {
634         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
635         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
636         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
637         SysAssertf(__pAddressbookManagerImpl != null,
638                         "Not yet constructed. Construct() should be called before use.");
639
640         r = __pAddressbookManagerImpl->MergePersons(sourcePersonId, targetPersonId);
641         SysTryReturn(NID_SCL, r == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
642
643         return E_SUCCESS;
644 }
645
646 result
647 AddressbookManager::UnlinkContact(PersonId personId, RecordId contactId, PersonId& newPersonId)
648 {
649         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE);
650         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
651         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
652         SysAssertf(__pAddressbookManagerImpl != null,
653                         "Not yet constructed. Construct() should be called before use.");
654
655         r = __pAddressbookManagerImpl->UnlinkContact(personId, contactId, newPersonId);
656         SysTryReturn(NID_SCL, r == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
657
658         return E_SUCCESS;
659 }
660
661 IList*
662 AddressbookManager::SearchN(const AddressbookFilter& filter, 
663                         unsigned long propertyToSort, Tizen::Base::SortOrder sortOrder, int offset, int maxCount)
664 {
665         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
666         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
667         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
668         SysAssertf(__pAddressbookManagerImpl != null,
669                         "Not yet constructed. Construct() should be called before use.");
670
671         return __pAddressbookManagerImpl->SearchN(filter, propertyToSort, sortOrder, offset, maxCount);
672 }
673
674 int
675 AddressbookManager::GetMatchedItemCount(const AddressbookFilter& filter)
676 {
677         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
678         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
679         SysTryReturn(NID_SCL, r == E_SUCCESS, -1, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
680         SysAssertf(__pAddressbookManagerImpl != null,
681                         "Not yet constructed. Construct() should be called before use.");
682
683         return __pAddressbookManagerImpl->GetMatchedItemCount(filter);
684 }
685
686 IList*
687 AddressbookManager::ParseContactsFromVcardN(const Tizen::Base::String& vcardPath)
688 {
689         return __pAddressbookManagerImpl->ParseContactsFromVcardN(vcardPath);
690 }
691
692 result
693 AddressbookManager::ExportPersonToVcard(const Person& person, const Tizen::Base::String& vcardPath)
694 {       
695         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
696         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
697         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
698         SysAssertf(__pAddressbookManagerImpl != null,
699                         "Not yet constructed. Construct() should be called before use.");
700
701         return __pAddressbookManagerImpl->ExportPersonToVcard(person, vcardPath);
702 }
703
704 result
705 AddressbookManager::ExportPersonsToVcard(const Tizen::Base::Collection::IList& personList, const Tizen::Base::String& vcardPath)
706 {
707         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
708         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
709         SysTryReturn(NID_SCL, r == E_SUCCESS, r, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
710         SysAssertf(__pAddressbookManagerImpl != null,
711                         "Not yet constructed. Construct() should be called before use.");
712
713         return __pAddressbookManagerImpl->ExportPersonsToVcard(personList, vcardPath);
714 }
715
716 result
717 AddressbookManager::ExportContactToVcard(const Contact& contact, const Tizen::Base::String& vcardPath)
718 {
719         return __pAddressbookManagerImpl->ExportContactToVcard(contact, vcardPath);
720 }
721
722 result
723 AddressbookManager::ExportContactsToVcard(const Tizen::Base::Collection::IList& contactList, const Tizen::Base::String& vcardPath)
724 {
725         return __pAddressbookManagerImpl->ExportContactsToVcard(contactList, vcardPath);
726 }
727
728 ByteBuffer*
729 AddressbookManager::ExportContactToVcardStreamN(const Contact& contact)
730 {
731         return __pAddressbookManagerImpl->ExportContactToVcardStreamN(contact);
732 }
733
734 ByteBuffer*
735 AddressbookManager::ExportContactsToVcardStreamN(const Tizen::Base::Collection::IList& contactList)
736 {
737         return __pAddressbookManagerImpl->ExportContactsToVcardStreamN(contactList);
738 }
739
740 ByteBuffer*
741 AddressbookManager::ExportPersonToVcardStreamN(const Person& person)
742 {
743         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
744         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
745         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
746         SysAssertf(__pAddressbookManagerImpl != null,
747                         "Not yet constructed. Construct() should be called before use.");
748
749         return __pAddressbookManagerImpl->ExportPersonToVcardStreamN(person);
750 }
751
752 ByteBuffer*
753 AddressbookManager::ExportPersonsToVcardStreamN(const Tizen::Base::Collection::IList& personList)
754 {
755         result r = _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ);
756         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
757         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
758         SysAssertf(__pAddressbookManagerImpl != null,
759                         "Not yet constructed. Construct() should be called before use.");
760
761         return __pAddressbookManagerImpl->ExportPersonsToVcardStreamN(personList);
762 }
763
764 IList*
765 AddressbookManager::ParseVcardStreamN(const Tizen::Base::ByteBuffer& vcardStream)
766 {
767         return __pAddressbookManagerImpl->ParseVcardStreamN(vcardStream);
768 }
769
770 Tizen::Base::ByteBuffer*
771 AddressbookManager::ExportUserProfileToVcardStreamN(const UserProfile& userProfile)
772 {
773         SysAssertf(__pAddressbookManagerImpl != null,
774                         "Not yet constructed. Construct() should be called before use.");
775
776         return __pAddressbookManagerImpl->ExportUserProfileToVcardStreamN(userProfile);
777 }
778
779 Tizen::Base::ByteBuffer*
780 AddressbookManager::ExportUserProfilesToVcardStreamN(const Tizen::Base::Collection::IList& userProfileList)
781 {
782         SysAssertf(__pAddressbookManagerImpl != null,
783                         "Not yet constructed. Construct() should be called before use.");
784
785         return __pAddressbookManagerImpl->ExportUserProfilesToVcardStreamN(userProfileList);
786 }
787
788 result
789 AddressbookManager::ExportUserProfileToVcard(const UserProfile& userProfile, const Tizen::Base::String& vcardPath)
790 {
791         SysAssertf(__pAddressbookManagerImpl != null,
792                         "Not yet constructed. Construct() should be called before use.");
793
794         return __pAddressbookManagerImpl->ExportUserProfileToVcard(userProfile, vcardPath);
795 }
796
797 result
798 AddressbookManager::ExportUserProfilesToVcard(const Tizen::Base::Collection::IList& userProfileList, const Tizen::Base::String& vcardPath)
799 {
800         SysAssertf(__pAddressbookManagerImpl != null,
801                         "Not yet constructed. Construct() should be called before use.");
802
803         return __pAddressbookManagerImpl->ExportUserProfilesToVcard(userProfileList, vcardPath);
804 }
805
806 Tizen::Base::Collection::IList*
807 AddressbookManager::GetAllUserProfilesN(void) const
808 {
809         result r = _AccessController::CheckUserPrivilege(_PRV_USERPROFILE_READ);
810         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
811         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
812         SysAssertf(__pAddressbookManagerImpl != null,
813                         "Not yet constructed. Construct() should be called before use.");
814
815         return __pAddressbookManagerImpl->GetAllUserProfilesN();
816 }
817
818 UserProfile*
819 AddressbookManager::GetUserProfileN(AddressbookId addressbookId) const
820 {
821         result r = _AccessController::CheckUserPrivilege(_PRV_USERPROFILE_READ);
822         r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
823         SysTryReturn(NID_SCL, r == E_SUCCESS, null, r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
824         SysAssertf(__pAddressbookManagerImpl != null,
825                         "Not yet constructed. Construct() should be called before use.");
826
827         return __pAddressbookManagerImpl->GetUserProfileN(addressbookId);
828 }
829
830 AddressbookManager*
831 AddressbookManager::GetInstance(void)
832 {
833         static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
834
835         if (__pInstance == null)
836         {
837                 ClearLastResult();
838
839                 pthread_once(&onceBlock, InitAddressbookManager);
840
841                 result r = GetLastResult();
842
843                 if (IsFailed(r))
844                 {
845                         onceBlock = PTHREAD_ONCE_INIT;
846                 }
847         }
848
849         return __pInstance;
850 }
851
852 void
853 AddressbookManager::InitAddressbookManager(void)
854 {
855         std::unique_ptr<AddressbookManager> pInstance(new (std::nothrow) AddressbookManager());
856         SysTryReturnVoidResult(NID_SCL, pInstance, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
857
858         result r = pInstance->Construct();
859         SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Propagating.", GetErrorMessage(r));
860
861         __pInstance = pInstance.release();
862
863         std::atexit(DestroyAddressbookManager);
864 }
865
866 void
867 AddressbookManager::DestroyAddressbookManager(void)
868 {
869         delete __pInstance;
870         __pInstance = null;
871 }
872
873 }}  // Tizen::Social