2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FSclAddressbookManager.cpp
19 * @brief This is the implementation for AddressbookManager class.
21 * This file contains definitions of @e AddressbookManager class.
24 #include <unique_ptr.h>
26 #include <FBaseResult.h>
27 #include <FBaseString.h>
28 #include <FBaseColIList.h>
29 #include <FBaseSysLog.h>
30 #include <FSclContact.h>
31 #include <FSclCategory.h>
32 #include <FSclUserProfile.h>
33 #include <FSclAddressbookManager.h>
34 #include <FSec_AccessController.h>
35 #include <FScl_AddressbookManagerImpl.h>
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Collection;
39 using namespace Tizen::Security;
41 namespace Tizen { namespace Social
44 AddressbookManager* AddressbookManager::__pInstance = null;
46 AddressbookManager::AddressbookManager(void)
47 : __pAddressbookManagerImpl(null)
52 AddressbookManager::~AddressbookManager(void)
54 delete __pAddressbookManagerImpl;
58 AddressbookManager::Construct(void)
62 SysAssertf(__pAddressbookManagerImpl == null,
63 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
65 _AddressbookManagerImpl* pAddressbookManagerImpl = new (std::nothrow) _AddressbookManagerImpl();
66 SysTryReturnResult(NID_SCL, pAddressbookManagerImpl != null, E_OUT_OF_MEMORY, "Not enough memory.");
68 r = pAddressbookManagerImpl->Construct();
69 SysTryCatch(NID_SCL, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
71 __pAddressbookManagerImpl = pAddressbookManagerImpl;
76 delete pAddressbookManagerImpl;
82 AddressbookManager::SetEventListener(IAddressbookEventListener* pListener)
84 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
85 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
86 SysAssertf(__pAddressbookManagerImpl != null,
87 "Not yet constructed. Construct() should be called before use.");
89 result r = __pAddressbookManagerImpl->SetEventListener(pListener);
90 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
96 AddressbookManager::SetAddressbookChangeEventListener(IAddressbookChangeEventListener* pListener)
98 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
99 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
100 SysAssertf(__pAddressbookManagerImpl != null,
101 "Not yet constructed. Construct() should be called before use.");
103 result r = __pAddressbookManagerImpl->SetAddressbookChangeEventListener(pListener);
104 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
110 AddressbookManager::CreateAddressbookN(AccountId accountId, const String& name)
112 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
113 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
114 SysAssertf(__pAddressbookManagerImpl != null,
115 "Not yet constructed. Construct() should be called before use.");
117 Addressbook* pAddressbook = __pAddressbookManagerImpl->CreateAddressbookN(accountId, name);
118 SysTryReturn(NID_SCL, pAddressbook != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
124 AddressbookManager::DeleteAddressbook(AddressbookId addressbookId)
126 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
127 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
128 SysAssertf(__pAddressbookManagerImpl != null,
129 "Not yet constructed. Construct() should be called before use.");
131 result r = __pAddressbookManagerImpl->DeleteAddressbook(addressbookId);
132 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
138 AddressbookManager::GetAddressbooksByAccountN(AccountId accountId) const
140 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
141 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
142 SysAssertf(__pAddressbookManagerImpl != null,
143 "Not yet constructed. Construct() should be called before use.");
145 IList* pList = __pAddressbookManagerImpl->GetAddressbooksByAccountN(accountId);
146 SysTryReturn(NID_SCL, pList !=null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
152 AddressbookManager::GetAllAddressbooksN(void) const
154 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
155 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
156 SysAssertf(__pAddressbookManagerImpl != null,
157 "Not yet constructed. Construct() should be called before use.");
159 IList* pList = __pAddressbookManagerImpl->GetAllAddressbooksN();
160 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
166 AddressbookManager::GetAddressbookN(AddressbookId addressbookId) const
168 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
169 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
170 SysAssertf(__pAddressbookManagerImpl != null,
171 "Not yet constructed. Construct() should be called before use.");
173 Addressbook* pAddressbook = __pAddressbookManagerImpl->GetAddressbookN(addressbookId);
174 SysTryReturn(NID_SCL, pAddressbook != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
180 AddressbookManager::AddContact(Contact& contact, AddressbookId addressbookId)
182 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
183 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
184 SysAssertf(__pAddressbookManagerImpl != null,
185 "Not yet constructed. Construct() should be called before use.");
187 result r = __pAddressbookManagerImpl->AddContact(contact, addressbookId);
188 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
194 AddressbookManager::AddCategory(Category& category, AddressbookId addressbookId)
196 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
197 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
198 SysAssertf(__pAddressbookManagerImpl != null,
199 "Not yet constructed. Construct() should be called before use.");
201 result r = __pAddressbookManagerImpl->AddCategory(category, addressbookId);
202 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
208 AddressbookManager::RemoveContact(RecordId contactId)
210 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
211 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
212 SysAssertf(__pAddressbookManagerImpl != null,
213 "Not yet constructed. Construct() should be called before use.");
215 result r = __pAddressbookManagerImpl->RemoveContact(contactId);
216 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
222 AddressbookManager::RemoveCategory(RecordId categoryId)
224 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
225 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
226 SysAssertf(__pAddressbookManagerImpl != null,
227 "Not yet constructed. Construct() should be called before use.");
229 result r = __pAddressbookManagerImpl->RemoveCategory(categoryId);
230 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
236 AddressbookManager::UpdateContact(const Contact& contact)
238 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
239 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
240 SysAssertf(__pAddressbookManagerImpl != null,
241 "Not yet constructed. Construct() should be called before use.");
243 result r = __pAddressbookManagerImpl->UpdateContact(contact);
244 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
250 AddressbookManager::UpdateCategory(const Category& category)
252 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
253 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
254 SysAssertf(__pAddressbookManagerImpl != null,
255 "Not yet constructed. Construct() should be called before use.");
257 result r = __pAddressbookManagerImpl->UpdateCategory(category);
258 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
264 AddressbookManager::GetAllContactsN(void) const
266 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
267 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
268 SysAssertf(__pAddressbookManagerImpl != null,
269 "Not yet constructed. Construct() should be called before use.");
271 IList* pList = __pAddressbookManagerImpl->GetAllContactsN();
272 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
278 AddressbookManager::GetContactsByCategoryN(RecordId categoryId) const
280 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
281 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
282 SysAssertf(__pAddressbookManagerImpl != null,
283 "Not yet constructed. Construct() should be called before use.");
285 IList* pList = __pAddressbookManagerImpl->GetContactsByCategoryN(categoryId);
286 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
292 AddressbookManager::GetContactsByPersonN(PersonId personId) const
294 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
295 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
296 SysAssertf(__pAddressbookManagerImpl != null,
297 "Not yet constructed. Construct() should be called before use.");
299 IList* pList = __pAddressbookManagerImpl->GetContactsByPersonN(personId);
300 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
306 AddressbookManager::AddMemberToCategory(RecordId categoryId, RecordId contactId)
308 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
309 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
310 SysAssertf(__pAddressbookManagerImpl != null,
311 "Not yet constructed. Construct() should be called before use.");
313 result r = __pAddressbookManagerImpl->AddMemberToCategory(categoryId, contactId);
314 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
320 AddressbookManager::RemoveMemberFromCategory(RecordId categoryId, RecordId contactId)
322 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
323 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
324 SysAssertf(__pAddressbookManagerImpl != null,
325 "Not yet constructed. Construct() should be called before use.");
327 result r = __pAddressbookManagerImpl->RemoveMemberFromCategory(categoryId, contactId);
328 SysTryReturn(NID_SCL, !IsFailed(r), r, r, "[%s] Propagating.", GetErrorMessage(r));
334 AddressbookManager::GetAllCategoriesN(void) const
336 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
337 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
338 SysAssertf(__pAddressbookManagerImpl != null,
339 "Not yet constructed. Construct() should be called before use.");
341 IList* pList = __pAddressbookManagerImpl->GetAllCategoriesN();
342 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
348 AddressbookManager::GetCategoriesByContactN(RecordId contactId) const
350 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
351 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
352 SysAssertf(__pAddressbookManagerImpl != null,
353 "Not yet constructed. Construct() should be called before use.");
355 IList* pList = __pAddressbookManagerImpl->GetCategoriesByContactN(contactId);
356 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
362 AddressbookManager::GetCategoriesByPersonN(PersonId personId) const
364 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
365 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
366 SysAssertf(__pAddressbookManagerImpl != null,
367 "Not yet constructed. Construct() should be called before use.");
369 IList* pList = __pAddressbookManagerImpl->GetCategoriesByPersonN(personId);
370 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
376 AddressbookManager::SearchContactsByEmailN(const String& email) const
378 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
379 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
380 SysAssertf(__pAddressbookManagerImpl != null,
381 "Not yet constructed. Construct() should be called before use.");
383 IList* pList = __pAddressbookManagerImpl->SearchContactsByEmailN(email);
384 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
390 AddressbookManager::SearchContactsByNameN(const String& name) const
392 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
393 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
394 SysAssertf(__pAddressbookManagerImpl != null,
395 "Not yet constructed. Construct() should be called before use.");
397 IList* pList = __pAddressbookManagerImpl->SearchContactsByNameN(name);
398 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
404 AddressbookManager::SearchContactsByPhoneNumberN(const String& phoneNumber) const
406 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
407 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
408 SysAssertf(__pAddressbookManagerImpl != null,
409 "Not yet constructed. Construct() should be called before use.");
411 IList* pList = __pAddressbookManagerImpl->SearchContactsByPhoneNumberN(phoneNumber);
412 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
418 AddressbookManager::GetCategoryCount(void) const
420 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, -1, E_PRIVILEGE_DENIED,
421 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
422 SysAssertf(__pAddressbookManagerImpl != null,
423 "Not yet constructed. Construct() should be called before use.");
425 int count = __pAddressbookManagerImpl->GetCategoryCount();
426 SysTryReturn(NID_SCL, count != -1, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
432 AddressbookManager::GetContactCount(void) const
434 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, -1, E_PRIVILEGE_DENIED,
435 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
436 SysAssertf(__pAddressbookManagerImpl != null,
437 "Not yet constructed. Construct() should be called before use.");
439 int count = __pAddressbookManagerImpl->GetContactCount();
440 SysTryReturn(NID_SCL, count != -1, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
446 AddressbookManager::GetContactN(RecordId contactId) const
448 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
449 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
450 SysAssertf(__pAddressbookManagerImpl != null,
451 "Not yet constructed. Construct() should be called before use.");
453 Contact* pContact = __pAddressbookManagerImpl->GetContactN(contactId);
454 SysTryReturn(NID_SCL, pContact != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
460 AddressbookManager::GetPersonN(PersonId personId) const
462 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
463 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
464 SysAssertf(__pAddressbookManagerImpl != null,
465 "Not yet constructed. Construct() should be called before use.");
467 Person* pPerson = __pAddressbookManagerImpl->GetPersonN(personId);
468 SysTryReturn(NID_SCL, pPerson != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
473 AddressbookManager::GetCategoryN(RecordId categoryId) const
475 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
476 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
477 SysAssertf(__pAddressbookManagerImpl != null,
478 "Not yet constructed. Construct() should be called before use.");
480 Category* pCategory = __pAddressbookManagerImpl->GetCategoryN(categoryId);
481 SysTryReturn(NID_SCL, pCategory != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
487 AddressbookManager::GetLatestVersion(void) const
489 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, -1, E_PRIVILEGE_DENIED,
490 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
491 SysAssertf(__pAddressbookManagerImpl != null,
492 "Not yet constructed. Construct() should be called before use.");
494 int latestVersion = __pAddressbookManagerImpl->GetLatestVersion();
495 SysTryReturn(NID_SCL, latestVersion != -1, -1, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
497 return latestVersion;
501 AddressbookManager::GetChangedContactsAfterN(int version, int& latestVersion) const
503 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
504 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
505 SysAssertf(__pAddressbookManagerImpl != null,
506 "Not yet constructed. Construct() should be called before use.");
508 IList* pList = __pAddressbookManagerImpl->GetChangedContactsAfterN(version, latestVersion);
509 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
515 AddressbookManager::GetChangedCategoriesAfterN(int version, int& latestVersion) const
517 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
518 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
519 SysAssertf(__pAddressbookManagerImpl != null,
520 "Not yet constructed. Construct() should be called before use.");
522 IList* pList = __pAddressbookManagerImpl->GetChangedCategoriesAfterN(version, latestVersion);
523 SysTryReturn(NID_SCL, pList != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
529 AddressbookManager::RemovePerson(PersonId personId)
531 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
532 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
533 SysAssertf(__pAddressbookManagerImpl != null,
534 "Not yet constructed. Construct() should be called before use.");
536 return __pAddressbookManagerImpl->RemovePerson(personId);
540 AddressbookManager::SetPersonAsFavorite(PersonId personId, bool isFavorite)
542 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
543 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
544 SysAssertf(__pAddressbookManagerImpl != null,
545 "Not yet constructed. Construct() should be called before use.");
547 return __pAddressbookManagerImpl->SetPersonAsFavorite(personId, isFavorite);
551 AddressbookManager::GetAllPersonsN(void) const
553 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
554 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
555 SysAssertf(__pAddressbookManagerImpl != null,
556 "Not yet constructed. Construct() should be called before use.");
558 return __pAddressbookManagerImpl->GetAllPersonsN();
562 AddressbookManager::GetPersonsByCategoryN(RecordId categoryId) const
564 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
565 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
566 SysAssertf(__pAddressbookManagerImpl != null,
567 "Not yet constructed. Construct() should be called before use.");
569 return __pAddressbookManagerImpl->GetPersonsByCategoryN(categoryId);
573 AddressbookManager::GetFavoritePersonsN() const
575 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
576 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
577 SysAssertf(__pAddressbookManagerImpl != null,
578 "Not yet constructed. Construct() should be called before use.");
580 return __pAddressbookManagerImpl->GetFavoritePersonsN();
584 AddressbookManager::SearchPersonsN(const Tizen::Base::String& keyword) const
586 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
587 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
588 SysAssertf(__pAddressbookManagerImpl != null,
589 "Not yet constructed. Construct() should be called before use.");
591 return __pAddressbookManagerImpl->SearchPersonsN(keyword);
595 AddressbookManager::MergePersons(PersonId sourcePersonId, PersonId targetPersonId)
597 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
598 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
599 SysAssertf(__pAddressbookManagerImpl != null,
600 "Not yet constructed. Construct() should be called before use.");
602 result r = __pAddressbookManagerImpl->MergePersons(sourcePersonId, targetPersonId);
603 SysTryReturn(NID_SCL, r == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
609 AddressbookManager::UnlinkContact(PersonId personId, RecordId contactId, PersonId& newPersonId)
611 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_WRITE) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
612 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
613 SysAssertf(__pAddressbookManagerImpl != null,
614 "Not yet constructed. Construct() should be called before use.");
616 result r = __pAddressbookManagerImpl->UnlinkContact(personId, contactId, newPersonId);
617 SysTryReturn(NID_SCL, r == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
623 AddressbookManager::SearchN(const AddressbookFilter& filter,
624 unsigned long propertyToSort, Tizen::Base::SortOrder sortOrder, int offset, int maxCount)
626 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
627 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
628 SysAssertf(__pAddressbookManagerImpl != null,
629 "Not yet constructed. Construct() should be called before use.");
631 return __pAddressbookManagerImpl->SearchN(filter, propertyToSort, sortOrder, offset, maxCount);
635 AddressbookManager::GetMatchedItemCount(const AddressbookFilter& filter)
637 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, -1, E_PRIVILEGE_DENIED,
638 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
639 SysAssertf(__pAddressbookManagerImpl != null,
640 "Not yet constructed. Construct() should be called before use.");
642 return __pAddressbookManagerImpl->GetMatchedItemCount(filter);
646 AddressbookManager::ParseContactsFromVcardN(const Tizen::Base::String& vcardPath)
648 return __pAddressbookManagerImpl->ParseContactsFromVcardN(vcardPath);
652 AddressbookManager::ExportPersonToVcard(const Person& person, const Tizen::Base::String& vcardPath)
654 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
655 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
656 SysAssertf(__pAddressbookManagerImpl != null,
657 "Not yet constructed. Construct() should be called before use.");
659 return __pAddressbookManagerImpl->ExportPersonToVcard(person, vcardPath);
663 AddressbookManager::ExportPersonsToVcard(const Tizen::Base::Collection::IList& personList, const Tizen::Base::String& vcardPath)
665 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED,
666 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
667 SysAssertf(__pAddressbookManagerImpl != null,
668 "Not yet constructed. Construct() should be called before use.");
670 return __pAddressbookManagerImpl->ExportPersonsToVcard(personList, vcardPath);
674 AddressbookManager::ExportContactToVcard(const Contact& contact, const Tizen::Base::String& vcardPath)
676 return __pAddressbookManagerImpl->ExportContactToVcard(contact, vcardPath);
680 AddressbookManager::ExportContactsToVcard(const Tizen::Base::Collection::IList& contactList, const Tizen::Base::String& vcardPath)
682 return __pAddressbookManagerImpl->ExportContactsToVcard(contactList, vcardPath);
686 AddressbookManager::ExportContactToVcardStreamN(const Contact& contact)
688 return __pAddressbookManagerImpl->ExportContactToVcardStreamN(contact);
692 AddressbookManager::ExportContactsToVcardStreamN(const Tizen::Base::Collection::IList& contactList)
694 return __pAddressbookManagerImpl->ExportContactsToVcardStreamN(contactList);
698 AddressbookManager::ExportPersonToVcardStreamN(const Person& person)
700 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
701 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
702 SysAssertf(__pAddressbookManagerImpl != null,
703 "Not yet constructed. Construct() should be called before use.");
705 return __pAddressbookManagerImpl->ExportPersonToVcardStreamN(person);
709 AddressbookManager::ExportPersonsToVcardStreamN(const Tizen::Base::Collection::IList& personList)
711 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_CONTACT_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
712 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
713 SysAssertf(__pAddressbookManagerImpl != null,
714 "Not yet constructed. Construct() should be called before use.");
716 return __pAddressbookManagerImpl->ExportPersonsToVcardStreamN(personList);
720 AddressbookManager::ParseVcardStreamN(const Tizen::Base::ByteBuffer& vcardStream)
722 return __pAddressbookManagerImpl->ParseVcardStreamN(vcardStream);
725 Tizen::Base::ByteBuffer*
726 AddressbookManager::ExportUserProfileToVcardStreamN(const UserProfile& userProfile)
728 SysAssertf(__pAddressbookManagerImpl != null,
729 "Not yet constructed. Construct() should be called before use.");
731 return __pAddressbookManagerImpl->ExportUserProfileToVcardStreamN(userProfile);
734 Tizen::Base::ByteBuffer*
735 AddressbookManager::ExportUserProfilesToVcardStreamN(const Tizen::Base::Collection::IList& userProfileList)
737 SysAssertf(__pAddressbookManagerImpl != null,
738 "Not yet constructed. Construct() should be called before use.");
740 return __pAddressbookManagerImpl->ExportUserProfilesToVcardStreamN(userProfileList);
744 AddressbookManager::ExportUserProfileToVcard(const UserProfile& userProfile, const Tizen::Base::String& vcardPath)
746 SysAssertf(__pAddressbookManagerImpl != null,
747 "Not yet constructed. Construct() should be called before use.");
749 return __pAddressbookManagerImpl->ExportUserProfileToVcard(userProfile, vcardPath);
753 AddressbookManager::ExportUserProfilesToVcard(const Tizen::Base::Collection::IList& userProfileList, const Tizen::Base::String& vcardPath)
755 SysAssertf(__pAddressbookManagerImpl != null,
756 "Not yet constructed. Construct() should be called before use.");
758 return __pAddressbookManagerImpl->ExportUserProfilesToVcard(userProfileList, vcardPath);
761 Tizen::Base::Collection::IList*
762 AddressbookManager::GetAllUserProfilesN(void) const
764 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_USERPROFILE_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
765 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
766 SysAssertf(__pAddressbookManagerImpl != null,
767 "Not yet constructed. Construct() should be called before use.");
769 return __pAddressbookManagerImpl->GetAllUserProfilesN();
773 AddressbookManager::GetUserProfileN(AddressbookId addressbookId) const
775 SysTryReturn(NID_SCL, _AccessController::CheckUserPrivilege(_PRV_USERPROFILE_READ) == E_SUCCESS, null, E_PRIVILEGE_DENIED,
776 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
777 SysAssertf(__pAddressbookManagerImpl != null,
778 "Not yet constructed. Construct() should be called before use.");
780 return __pAddressbookManagerImpl->GetUserProfileN(addressbookId);
784 AddressbookManager::GetInstance(void)
786 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
788 if (__pInstance == null)
792 pthread_once(&onceBlock, InitAddressbookManager);
794 result r = GetLastResult();
798 onceBlock = PTHREAD_ONCE_INIT;
806 AddressbookManager::InitAddressbookManager(void)
808 std::unique_ptr<AddressbookManager> pInstance(new (std::nothrow) AddressbookManager());
809 SysTryReturnVoidResult(NID_SCL, pInstance, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
811 result r = pInstance->Construct();
812 SysTryReturnVoidResult(NID_SCL, !IsFailed(r), r, "[%s] Propagating.", GetErrorMessage(r));
814 __pInstance = pInstance.release();
816 std::atexit(DestroyAddressbookManager);
820 AddressbookManager::DestroyAddressbookManager(void)