2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file AddressBook.cpp
19 * @author Kisub Song (kisubs.song@samsung.com)
30 #include <dpl/log/log.h>
31 #include <dpl/exception.h>
32 #include <Commons/Exception.h>
33 #include <Commons/Regex.h>
34 #include <API/Contact/IAddressBook.h>
35 #include <API/Contact/IContact.h>
36 #include "AddressBook.h"
38 #include "ContactObjectA2PConverter.h"
39 #include "ContactObjectP2AConverter.h"
40 #include "ContactSearchEngine.h"
41 #include "ContactFilterValidator.h"
42 #include "ContactDownloadManager.h"
43 #include "ContactUtility.h"
49 using namespace TizenApis::Api::Contact;
50 using namespace TizenApis::Api::Tizen;
51 using namespace WrtDeviceApis::Commons;
54 AddressBook::AddressBook() :
56 m_name("TEST_ADDRESS_BOOK")
61 AddressBook::~AddressBook()
63 if(m_addressBookEmitters.size() != 0)
65 ContactListenerManagerSingleton::Instance().unregisterAppListChangedCallbacks(this);
69 std::string AddressBook::getId() const
71 std::stringstream oss;
76 void AddressBook::setId(const std::string &value)
78 std::stringstream oss(value);
82 std::string AddressBook::getAccountId() const
84 std::stringstream oss;
89 void AddressBook::setAccountId(const std::string &value)
91 std::stringstream oss(value);
95 void AddressBook::OnRequestReceived(const EventAddressBookGetPtr &event)
99 CTSstruct *ctsStruct = NULL;
101 if(!event->getIdIsSet())
102 ThrowMsg(InvalidArgumentException, "Invalid contact id");
104 string contactId = event->getId();
106 int contactIdInt = ContactUtility::strToInt(contactId);
108 int errorCode = contacts_svc_get_contact(contactIdInt, &ctsStruct);
109 if(errorCode != CTS_SUCCESS)
111 ThrowMsg(NotFoundException, "No contact (id:" << contactIdInt << ")");
113 ContactObjectP2AConverterPtr contactObjConverter(
114 new ContactObjectP2AConverter(ctsStruct, false));
115 ContactPtr contact = contactObjConverter->getAbstractContact();
117 event->setContact(contact);
118 event->setResult(true);
120 } Catch (NotFoundException) {
121 LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
122 event->setExceptionCode(ExceptionCodes::NotFoundException);
123 event->setResult(false);
125 } Catch (PlatformException) {
126 LogError("Error during getting contact : " << _rethrown_exception.GetMessage());
127 event->setExceptionCode(ExceptionCodes::PlatformException);
128 event->setResult(false);
130 } Catch (InvalidArgumentException) {
131 LogError("Invalid Arguments : " << _rethrown_exception.GetMessage());
132 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
133 event->setResult(false);
136 LogError("Error on platform : " << _rethrown_exception.GetMessage());
137 event->setExceptionCode(ExceptionCodes::UnknownException);
138 event->setResult(false);
141 if(ctsStruct != NULL)
142 contacts_svc_struct_free(ctsStruct);
145 void AddressBook::OnRequestReceived(const EventAddressBookAddPtr &event)
149 ContactPtr contact(NULL);
152 if(!event->getContactIsSet())
153 ThrowMsg(InvalidArgumentException, "Contacts were not set.");
155 contact = event->getContact();
157 ThrowMsg(InvalidArgumentException, "No contacts.");
159 } Catch(InvalidArgumentException) {
160 LogError("Invalid arguments for adding contacts : " << _rethrown_exception.GetMessage());
161 event->setResult(false);
162 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
166 CTSstruct *ctsStruct = NULL;
170 internalAddContact(contact);
172 string id = contact->getId();
175 int idInt = ContactUtility::strToInt(id);
176 int errorCode = contacts_svc_get_contact(idInt, &ctsStruct);
177 if(errorCode != CTS_SUCCESS)
179 ThrowMsg(PlatformException, "No contact just inserted (id:" << id << ")");
181 ContactObjectP2AConverterPtr contactObjConverter(
182 new ContactObjectP2AConverter(ctsStruct, false));
183 ContactPtr insertedContact = contactObjConverter->getAbstractContact();
184 contact->copy(insertedContact);
187 event->setResult(true);
188 event->setExceptionCode(ExceptionCodes::None);
190 Catch (PlatformException) {
191 LogError("Error during adding contact : " << _rethrown_exception.GetMessage());
192 event->setResult(false);
193 event->setExceptionCode(ExceptionCodes::PlatformException);
196 LogError("Error during adding contact : " << _rethrown_exception.GetMessage());
197 event->setResult(false);
198 event->setExceptionCode(ExceptionCodes::UnknownException);
201 if(ctsStruct != NULL)
202 contacts_svc_struct_free(ctsStruct);
205 void AddressBook::OnRequestReceived(const EventAddressBookAddBatchPtr &event)
208 ContactArrayPtr contacts(NULL);
211 if(!event->getContactsIsSet())
212 ThrowMsg(InvalidArgumentException, "Contacts were not set.");
214 contacts = event->getContacts();
216 ThrowMsg(InvalidArgumentException, "No contacts.");
218 } Catch(InvalidArgumentException) {
219 LogError("Invalid arguments for adding contacts : " << _rethrown_exception.GetMessage());
220 event->setResult(false);
221 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
225 CTSstruct *ctsStruct = NULL;
229 int ret = contacts_svc_begin_trans();
231 LogError("error code " << ret);
232 ThrowMsg(PlatformException, "Error during executing contacts_svc_begin_trans()");
235 for(ContactArray::iterator i = contacts->begin(); i != contacts->end(); i++)
237 ContactPtr contact = *i;
239 internalAddContact(contact);
241 ret = contacts_svc_end_trans(true);
243 LogError("error code " << ret);
244 ThrowMsg(PlatformException, "Error during executing contacts_svc_end_trans()");
247 for(ContactArray::iterator i = contacts->begin(); i != contacts->end(); i++)
249 ContactPtr contact = *i;
251 string id = contact->getId();
254 int idInt = ContactUtility::strToInt(id);
255 int errorCode = contacts_svc_get_contact(idInt, &ctsStruct);
256 if(errorCode != CTS_SUCCESS)
258 ThrowMsg(PlatformException, "No contact just inserted (id:" << id << ")");
260 ContactObjectP2AConverterPtr contactObjConverter(
261 new ContactObjectP2AConverter(ctsStruct, false));
262 ContactPtr insertedContact = contactObjConverter->getAbstractContact();
263 contact->copy(insertedContact);
267 event->setResult(true);
268 event->setExceptionCode(ExceptionCodes::None);
270 Catch (NotFoundException)
272 contacts_svc_end_trans(false);
273 LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
274 event->setResult(false);
275 event->setExceptionCode(ExceptionCodes::NotFoundException);
277 Catch (PlatformException) {
278 contacts_svc_end_trans(false);
279 LogError("Error during adding contact : " << _rethrown_exception.GetMessage());
280 event->setResult(false);
281 event->setExceptionCode(ExceptionCodes::PlatformException);
284 contacts_svc_end_trans(false);
285 LogError("Error during adding contact : " << _rethrown_exception.GetMessage());
286 event->setResult(false);
287 event->setExceptionCode(ExceptionCodes::PlatformException);
290 if(ctsStruct != NULL)
291 contacts_svc_struct_free(ctsStruct);
294 void AddressBook::OnRequestReceived(const EventAddressBookUpdatePtr &event)
296 ContactPtr contact(NULL);
299 if(!event->getContactIsSet())
300 ThrowMsg(InvalidArgumentException, "Contacts were not set.");
302 contact = event->getContact();
304 ThrowMsg(InvalidArgumentException, "No contacts.");
306 } Catch(InvalidArgumentException) {
307 LogError("Invalid arguments for adding contacts : " << _rethrown_exception.GetMessage());
308 event->setResult(false);
309 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
315 internalAddContact(contact);
317 Catch (NotFoundException)
319 LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
320 event->setResult(false);
321 event->setExceptionCode(ExceptionCodes::NotFoundException);
324 Catch (PlatformException) {
325 LogError("Error during adding contact : " << _rethrown_exception.GetMessage());
326 event->setResult(false);
327 event->setExceptionCode(ExceptionCodes::PlatformException);
331 LogError("Error during adding contact : " << _rethrown_exception.GetMessage());
332 event->setResult(false);
333 event->setExceptionCode(ExceptionCodes::PlatformException);
336 //m_latestVersion = get_contact_version();
338 event->setResult(true);
339 event->setExceptionCode(ExceptionCodes::None);
342 void AddressBook::OnRequestReceived(const EventAddressBookUpdateBatchPtr &event)
345 ContactArrayPtr contacts(NULL);
348 if(!event->getContactsIsSet())
349 ThrowMsg(InvalidArgumentException, "Contacts were not set.");
351 contacts = event->getContacts();
353 ThrowMsg(InvalidArgumentException, "No contacts.");
355 } Catch(InvalidArgumentException) {
356 LogError("Invalid arguments for updating contacts : " << _rethrown_exception.GetMessage());
357 event->setResult(false);
358 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
364 int ret = contacts_svc_begin_trans();
366 LogError("error code " << ret);
367 ThrowMsg(PlatformException, "Error during executing contacts_svc_begin_trans()");
370 for(ContactArray::iterator i = contacts->begin(); i != contacts->end(); i++)
372 ContactPtr contact = *i;
374 internalAddContact(contact);
376 contacts_svc_end_trans(true);
378 LogError("error code " << ret);
379 ThrowMsg(PlatformException, "Error during executing contacts_svc_end_trans()");
382 Catch (NotFoundException)
384 contacts_svc_end_trans(false);
385 LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
386 event->setResult(false);
387 event->setExceptionCode(ExceptionCodes::NotFoundException);
390 Catch (PlatformException) {
391 contacts_svc_end_trans(false);
392 LogError("Error during updating contact : " << _rethrown_exception.GetMessage());
393 event->setResult(false);
394 event->setExceptionCode(ExceptionCodes::PlatformException);
398 LogError("Error during updating contact : " << _rethrown_exception.GetMessage());
399 event->setResult(false);
400 event->setExceptionCode(ExceptionCodes::PlatformException);
403 //m_latestVersion = get_contact_version();
405 event->setResult(true);
406 event->setExceptionCode(ExceptionCodes::None);
409 void AddressBook::OnRequestReceived(const EventAddressBookRemovePtr &event)
416 if(!event->getContactIdIsSet())
417 ThrowMsg(InvalidArgumentException, "Contacts were not set.");
419 string contactIdStr = event->getContactId();
421 if(!validate("^[0-9]+$", contactIdStr, VALIDATE_MATCH_CASELESS))
422 ThrowMsg(InvalidArgumentException, "Id is wrong (" << contactIdStr << ")" );
425 istringstream iss(contactIdStr);
428 ThrowMsg(InvalidArgumentException, "Id is wrong (" << contactIdStr << ")" );
431 internalDeleteContactById(contactId);
433 Catch (InvalidArgumentException)
435 LogError("Invalid contact id : " << _rethrown_exception.GetMessage());
436 event->setResult(false);
437 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
440 Catch (NotFoundException)
442 LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
443 event->setResult(false);
444 event->setExceptionCode(ExceptionCodes::NotFoundException);
447 Catch (PlatformException) {
448 LogError("Error during updating contact : " << _rethrown_exception.GetMessage());
449 event->setResult(false);
450 event->setExceptionCode(ExceptionCodes::PlatformException);
454 LogError("Error during updating contact : " << _rethrown_exception.GetMessage());
455 event->setResult(false);
456 event->setExceptionCode(ExceptionCodes::PlatformException);
459 //m_latestVersion = get_contact_version();
461 event->setResult(true);
462 event->setExceptionCode(ExceptionCodes::None);
465 void AddressBook::OnRequestReceived(const EventAddressBookRemoveBatchPtr &event)
468 StringArrayPtr contactIds(NULL);
471 if(!event->getContactIdsIsSet())
472 ThrowMsg(InvalidArgumentException, "Contacts were not set.");
474 contactIds = event->getContactIds();
476 ThrowMsg(InvalidArgumentException, "No contacts.");
478 } Catch(InvalidArgumentException) {
479 LogError("Invalid arguments for updating contacts : " << _rethrown_exception.GetMessage());
480 event->setResult(false);
481 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
487 int ret = contacts_svc_begin_trans();
489 LogError("error code " << ret);
490 ThrowMsg(PlatformException, "Error during executing contacts_svc_begin_trans()");
492 for(StringArray::iterator i = contactIds->begin(); i != contactIds->end(); i++)
494 string contactIdStr = *i;
498 if(!validate("^[0-9]+$", contactIdStr, VALIDATE_MATCH_CASELESS))
499 ThrowMsg(InvalidArgumentException, "Id is wrong (" << contactIdStr << ")" );
502 istringstream iss(contactIdStr);
505 ThrowMsg(InvalidArgumentException, "Id is wrong (" << contactIdStr << ")" );
508 internalDeleteContactById(contactId);
510 contacts_svc_end_trans(true);
512 LogError("error code " << ret);
513 ThrowMsg(PlatformException, "Error during executing contacts_svc_end_trans()");
516 Catch (InvalidArgumentException)
518 contacts_svc_end_trans(false);
519 LogError("Invalid contact id : " << _rethrown_exception.GetMessage());
520 event->setResult(false);
521 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
524 Catch (NotFoundException)
526 contacts_svc_end_trans(false);
527 LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
528 event->setResult(false);
529 event->setExceptionCode(ExceptionCodes::NotFoundException);
532 Catch (PlatformException) {
533 contacts_svc_end_trans(false);
534 LogError("Error during updating contact : " << _rethrown_exception.GetMessage());
535 event->setResult(false);
536 event->setExceptionCode(ExceptionCodes::PlatformException);
540 contacts_svc_end_trans(false);
541 LogError("Error during updating contact : " << _rethrown_exception.GetMessage());
542 event->setResult(false);
543 event->setExceptionCode(ExceptionCodes::PlatformException);
546 //m_latestVersion = get_contact_version();
548 event->setResult(true);
549 event->setExceptionCode(ExceptionCodes::None);
552 void AddressBook::OnRequestReceived(const EventAddressBookFindPtr &event)
556 ContactSearchEnginePtr searchEngine(new ContactSearchEngine(ContactSearchEngine::CONTACT_QUERY));
558 if(event->getFilterIsSet())
560 FilterPtr filter = event->getFilter();
562 FilterValidatorPtr validator = ContactFilterValidatorFactory::getContactFilterValidator();
563 bool success = filter->validate(validator);
566 ThrowMsg(InvalidArgumentException, "Invalid filter arguments.");
568 searchEngine->setCondition(filter);
571 // Currently not support attributeOfInterests
572 //if (event->getAttributesOfInterestIsSet())
573 // searchEngine->setAttributeOfInterest(event->getAttributesOfInterest());
575 // searchEngine->setAttributeOfInterest();
577 searchEngine->setAttributeOfInterest();
579 if (event->getSortModeIsSet())
581 searchEngine->setSortMode(event->getSortMode());
584 searchEngine->setSortMode();
586 event->setContacts(searchEngine->getContactSearchResult());
587 event->setResult(true);
589 } Catch (NotFoundException) {
590 LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
591 event->setExceptionCode(ExceptionCodes::NotFoundException);
592 event->setResult(false);
594 } Catch (PlatformException) {
595 LogError("Error during deleting contact : " << _rethrown_exception.GetMessage());
596 event->setExceptionCode(ExceptionCodes::PlatformException);
597 event->setResult(false);
599 } Catch (InvalidArgumentException) {
600 LogError("Invalid Arguments : " << _rethrown_exception.GetMessage());
601 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
602 event->setResult(false);
604 } Catch (Exception) {
605 LogError("Error during deleting contact : " << _rethrown_exception.GetMessage());
606 event->setExceptionCode(ExceptionCodes::PlatformException);
607 event->setResult(false);
611 void AddressBook::OnRequestReceived(const EventAddressBookGetCategoriesPtr &event)
616 StringArrayPtr categories = StringArrayPtr(new StringArray());
618 CTSiter *iter = NULL;
619 if(CTS_SUCCESS != contacts_svc_get_list(CTS_LIST_ALL_GROUP, &iter))
620 ThrowMsg(PlatformException, "Fail to get categories list.");
622 while(CTS_SUCCESS == contacts_svc_iter_next(iter))
624 CTSvalue *group = contacts_svc_iter_get_info(iter);
628 const char *groupCStr = contacts_svc_value_get_str(group, CTS_LIST_GROUP_NAME_STR);
630 categories->push_back(string(groupCStr));
632 contacts_svc_value_free(group);
634 contacts_svc_iter_remove(iter);
636 event->setCategories(categories);
637 event->setResult(true);
639 } Catch (NotFoundException) {
640 LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
641 event->setExceptionCode(ExceptionCodes::NotFoundException);
642 event->setResult(false);
644 } Catch (PlatformException) {
645 LogError("Error during deleting contact : " << _rethrown_exception.GetMessage());
646 event->setExceptionCode(ExceptionCodes::PlatformException);
647 event->setResult(false);
649 } Catch (InvalidArgumentException) {
650 LogError("Invalid Arguments : " << _rethrown_exception.GetMessage());
651 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
652 event->setResult(false);
655 LogError("Error on platform : " << _rethrown_exception.GetMessage());
656 event->setExceptionCode(ExceptionCodes::UnknownException);
657 event->setResult(false);
661 void AddressBook::OnRequestReceived(const EventAddressBookAddChangeListenerPtr &event)
666 if(!event->getEmitterIsSet())
667 ThrowMsg(InvalidArgumentException, "Invalid arguments.");
669 EventAddressBookChangeListenerEmitterPtr emitter = event->getEmitter();
671 ThrowMsg(InvalidArgumentException, "Invalid arguments.");
673 //DPL::Mutex::ScopedLock lock(&m_addressBookEmittersMutex);
675 if(m_addressBookEmitters.size() == 0)
677 LogDebug("Watch registered initially");
679 ContactListenerManagerSingleton::Instance().registerAppListChangedCallbacks(this, m_id);
682 m_addressBookEmitters.attach(emitter);
684 long id = ContactListenerManagerSingleton::Instance().getWatchIdAndInc();
685 m_watchIdMap[id] = emitter->getId();
688 event->setResult(true);
690 } Catch (NotFoundException) {
691 LogError("Contact doesn't exist : " << _rethrown_exception.GetMessage());
692 event->setExceptionCode(ExceptionCodes::NotFoundException);
693 event->setResult(false);
695 } Catch (PlatformException) {
696 LogError("Error during deleting contact : " << _rethrown_exception.GetMessage());
697 event->setExceptionCode(ExceptionCodes::PlatformException);
698 event->setResult(false);
700 } Catch (InvalidArgumentException) {
701 LogError("Invalid Arguments : " << _rethrown_exception.GetMessage());
702 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
703 event->setResult(false);
705 } Catch (Exception) {
706 LogError("Error during deleting contact : " << _rethrown_exception.GetMessage());
707 event->setExceptionCode(ExceptionCodes::PlatformException);
708 event->setResult(false);
712 void AddressBook::OnRequestReceived(const EventAddressBookRemoveChangeListenerPtr &event)
717 if(!event->getIdIsSet())
718 ThrowMsg(InvalidArgumentException, "Invalid arguments.");
720 long id = event->getId();
721 if(m_watchIdMap.find(id) == m_watchIdMap.end())
722 ThrowMsg(NotFoundException, "No watchId : " << id);
724 //DPL::Mutex::ScopedLock lock(&m_addressBookEmittersMutex);
725 bool success = m_addressBookEmitters.detach(m_watchIdMap[id]);
727 ThrowMsg(NotFoundException, "No watchId : " << id);
729 m_watchIdMap.erase(id);
731 if(m_addressBookEmitters.size() == 0)
733 LogDebug("No watcher is registered. unsubscribing from contact service.");
735 ContactListenerManagerSingleton::Instance().unregisterAppListChangedCallbacks(this);
738 event->setResult(true);
740 } Catch (NotFoundException) {
741 LogError("WatchId doesn't exist : " << _rethrown_exception.GetMessage());
742 event->setExceptionCode(ExceptionCodes::NotFoundException);
743 event->setResult(false);
745 } Catch (PlatformException) {
746 LogError("Error during deleting contact : " << _rethrown_exception.GetMessage());
747 event->setExceptionCode(ExceptionCodes::PlatformException);
748 event->setResult(false);
750 } Catch (InvalidArgumentException) {
751 LogError("Invalid Arguments : " << _rethrown_exception.GetMessage());
752 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
753 event->setResult(false);
755 } Catch (Exception) {
756 LogError("Error during deleting contact : " << _rethrown_exception.GetMessage());
757 event->setExceptionCode(ExceptionCodes::PlatformException);
758 event->setResult(false);
762 void AddressBook::onContactEventAdded(TizenApis::Api::Contact::ContactArrayPtr &contacts)
764 EventInfoAddressBookChangeAddedPtr contactsAdded(new EventInfoAddressBookChangeAdded());
765 contactsAdded->setContacts(contacts);
766 EventInfoAddressBookChangePtr event = DPL::StaticPointerCast<EventInfoAddressBookChange>(contactsAdded);
767 EventAddressBookChangeListenerPtr listener(new EventAddressBookChangeListener(event));
768 m_addressBookEmitters.emit(listener);
771 void AddressBook::onContactEventUpdated(TizenApis::Api::Contact::ContactArrayPtr &contacts)
773 EventInfoAddressBookChangeUpdatedPtr contactsUpdated(new EventInfoAddressBookChangeUpdated());
774 contactsUpdated->setContacts(contacts);
775 EventInfoAddressBookChangePtr event = DPL::StaticPointerCast<EventInfoAddressBookChange>(contactsUpdated);
776 EventAddressBookChangeListenerPtr listener(new EventAddressBookChangeListener(event));
777 m_addressBookEmitters.emit(listener);
780 void AddressBook::onContactEventRemoved(TizenApis::Api::Contact::StringArrayPtr &contactIds)
782 EventInfoAddressBookChangeRemovedPtr contactsRemoved(new EventInfoAddressBookChangeRemoved());
783 contactsRemoved->setContactIds(contactIds);
784 EventInfoAddressBookChangePtr event = DPL::StaticPointerCast<EventInfoAddressBookChange>(contactsRemoved);
785 EventAddressBookChangeListenerPtr listener(new EventAddressBookChangeListener(event));
786 m_addressBookEmitters.emit(listener);
789 void AddressBook::internalAddContact(const ContactPtr &newContact)
793 DPL::Mutex::ScopedLock lock(&m_contactEditingMutex);
795 //translate provided path to real filesystem path
796 if (newContact->getPhotoURIIsSet())
798 string realPath = ContactDownloadManager::getInstance()->getRealPath(newContact->getPhotoURI());
799 if(realPath.length() <= MAXPATHLEN)
800 newContact->setPhotoURI(realPath);
803 if (newContact->getRingtoneURIIsSet())
805 string realPath = ContactDownloadManager::getInstance()->getRealPath(newContact->getRingtoneURI());
806 if(realPath.length() <= MAXPATHLEN)
807 newContact->setRingtoneURI(realPath);
810 DPL::SharedPtr<TizenApis::Platform::Contact::Contact> newContactT =
811 DPL::StaticPointerCast<TizenApis::Platform::Contact::Contact>(newContact);
813 ContactObjectA2PConverterPtr contactObjConverter(NULL);
815 CTSstruct* contact = newContactT->getCTSStruct();
818 contactObjConverter = ContactObjectA2PConverterPtr(
819 new ContactObjectA2PConverter(newContact, false) );
820 contact = contactObjConverter->getPlatformContact();
824 contactObjConverter = ContactObjectA2PConverterPtr(
825 new ContactObjectA2PConverter(newContact, false, contact) );
826 contact = contactObjConverter->getPlatformContact();
831 LogError("Error during converting contact object");
832 ThrowMsg(PlatformException, "Error during converting contact object");
835 if ( newContact->getIdIsSet() )
837 int ret = contacts_svc_update_contact(contact);
838 if (ret == CTS_ERR_DB_RECORD_NOT_FOUND)
839 ThrowMsg(NotFoundException, "Error during executing contacts_svc_update_contact()");
841 LogError("error code " << ret);
842 ThrowMsg(PlatformException, "Error during executing contacts_svc_update_contact()");
847 string addressBookIdStr = newContact->getAddressBookId();
848 int addressBookId = ContactUtility::strToInt(addressBookIdStr);
850 int id = contacts_svc_insert_contact(addressBookId, contact);
852 LogError("error code " << id);
853 ThrowMsg(PlatformException, "Error during executing contacts_svc_insert_contact()");
855 newContact->setId(id);
859 void AddressBook::internalDeleteContactById(int id)
861 LogDebug("entered with id " << id);
866 DPL::Mutex::ScopedLock lock(&m_contactEditingMutex);
868 int res = contacts_svc_delete_contact(id);
869 if (res == CTS_ERR_DB_RECORD_NOT_FOUND)
870 ThrowMsg(NotFoundException, "Error during executing contacts_svc_delete_contact()");
871 else if (res != CTS_SUCCESS)
872 ThrowMsg(PlatformException, "Error during executing contacts_svc_delete_contact()");