2 // Tizen Web Device API
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.
19 * @file ContactManager.cpp
20 * @author Kisub Song (kisubs.song@samsung.com)
25 #include "ContactManager.h"
28 #include <Commons/Regex.h>
29 #include "ContactFactory.h"
30 #include "IAddressBook.h"
31 #include "ContactsSvcWrapper.h"
32 #include "ContactsSvcObjectConverter.h"
33 #include "ContactUtility.h"
34 #include "PersonFilterValidator.h"
35 #include "PersonSearchEngine.h"
37 #include "ContactQueue.h"
44 using namespace WrtDeviceApis::Commons;
45 using namespace DeviceAPI::Tizen;
47 ContactManager::ContactManager() : m_eventMapAcc(0)
49 ContactsSvcWrapperSingleton::Instance();
52 ContactManager::~ContactManager()
54 if(m_contactManagerEmitters.size() != 0)
56 ContactsSvcChangeListenerManagerSingleton::Instance().unregisterPersonsChangeListener(this);
60 void ContactManager::OnRequestReceived(const EventContactManagerGetAddressBookPtr &event)
66 std::string addressBookId = event->getAddressBookId();
67 if(addressBookId.empty())
69 //when database is not opened then set result as failed
70 ThrowMsg(NotFoundException, "Address book id is empty");
73 AddressBookPtr addressBook =
74 ContactsSvcWrapperSingleton::Instance().getAddressBook(addressBookId);
76 event->setAddressBook(addressBook);
77 event->setResult(true);
78 event->setExceptionCode(ExceptionCodes::None);
80 Catch(PlatformException)
82 //when database is not opened then set result as failed
83 LoggerE("Contact DB not opened : " << _rethrown_exception.GetMessage());
84 event->setResult(false);
85 event->setExceptionCode(ExceptionCodes::PlatformException);
88 Catch(NotFoundException)
90 //when database is not opened then set result as failed
91 LoggerE("Not found : " << _rethrown_exception.GetMessage());
92 event->setResult(false);
93 event->setExceptionCode(ExceptionCodes::NotFoundException);
97 LoggerE("Unknown exception : " << _rethrown_exception.GetMessage());
98 event->setResult(false);
99 event->setExceptionCode(ExceptionCodes::UnknownException);
104 void ContactManager::OnRequestReceived(const EventContactManagerGetAddressBooksPtr &event)
110 AddressBookArrayPtr addressBookArray =
111 ContactsSvcWrapperSingleton::Instance().getAddressBooks();
113 event->setAddressBooks(addressBookArray);
114 event->setResult(true);
115 event->setExceptionCode(ExceptionCodes::None);
117 Catch (PlatformException)
119 //when database is not opened then set result as failed
120 LoggerE("Contact DB is not opened.");
121 event->setResult(false);
122 event->setExceptionCode(ExceptionCodes::PlatformException);
127 LoggerE("Unknown exception : " << _rethrown_exception.GetMessage());
128 event->setResult(false);
129 event->setExceptionCode(ExceptionCodes::UnknownException);
134 void ContactManager::OnRequestReceived(const EventContactManagerGetDefaultAddressBookPtr &event)
140 AddressBookPtr defaultAddressBook =
141 ContactsSvcWrapperSingleton::Instance().getDefaultAddressBook();
143 event->setDefaultAddressBook(defaultAddressBook);
144 event->setResult(true);
145 event->setExceptionCode(ExceptionCodes::None);
147 Catch (PlatformException)
149 //when database is not opened then set result as failed
150 LoggerE("Contact DB is not opened.");
151 event->setResult(false);
152 event->setExceptionCode(ExceptionCodes::PlatformException);
157 LoggerE("Unknown exception : " << _rethrown_exception.GetMessage());
158 event->setResult(false);
159 event->setExceptionCode(ExceptionCodes::UnknownException);
164 void ContactManager::OnRequestReceived(const EventContactManagerGetUnifiedAddressBookPtr &event)
170 AddressBookPtr unifiedAddressBook =
171 ContactsSvcWrapperSingleton::Instance().getUnifiedAddressBook();
173 event->setUnifiedAddressBook(unifiedAddressBook);
174 event->setResult(true);
175 event->setExceptionCode(ExceptionCodes::None);
177 Catch (PlatformException)
179 //when database is not opened then set result as failed
180 LoggerE("Contact DB is not opened.");
181 event->setResult(false);
182 event->setExceptionCode(ExceptionCodes::PlatformException);
187 LoggerE("Unknown exception : " << _rethrown_exception.GetMessage());
188 event->setResult(false);
189 event->setExceptionCode(ExceptionCodes::UnknownException);
194 void ContactManager::OnRequestReceived(const EventContactManagerGetPtr &event)
199 contacts_record_h contacts_record = NULL;
202 if(!event->getIdIsSet())
203 ThrowMsg(InvalidArgumentException, "Invalid person id");
205 string personId = event->getId();
207 int personIdInt = ContactUtility::strToInt(personId);
209 errorCode = contacts_db_get_record(_contacts_person._uri, personIdInt, &contacts_record);
210 if(errorCode != CONTACTS_ERROR_NONE)
212 ThrowMsg(NotFoundException, "No person (id:" << personIdInt << ") : " << errorCode);
214 PersonPtr person = PersonPtr(new Person());
216 ContactsSvcObjectConverter::convertToAbstract(contacts_record, person);
218 event->setPerson(person);
219 event->setResult(true);
221 } Catch (NotFoundException) {
222 LoggerE("Person doesn't exist : " << _rethrown_exception.GetMessage());
223 event->setExceptionCode(ExceptionCodes::NotFoundException);
224 event->setResult(false);
226 } Catch (PlatformException) {
227 LoggerE("Error during getting person : " << _rethrown_exception.GetMessage());
228 event->setExceptionCode(ExceptionCodes::PlatformException);
229 event->setResult(false);
231 } Catch (InvalidArgumentException) {
232 LoggerE("Invalid Arguments : " << _rethrown_exception.GetMessage());
233 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
234 event->setResult(false);
237 LoggerE("Error on platform : " << _rethrown_exception.GetMessage());
238 event->setExceptionCode(ExceptionCodes::UnknownException);
239 event->setResult(false);
242 if(contacts_record != NULL)
243 contacts_record_destroy(contacts_record, true);
246 void ContactManager::OnRequestReceived(const EventContactManagerUpdatePtr &event)
252 contacts_record_h contacts_record = NULL;
253 PersonPtr person(NULL);
256 if(!event->getPersonIsSet())
257 ThrowMsg(InvalidArgumentException, "Persons were not set.");
259 person = event->getPerson();
261 ThrowMsg(InvalidArgumentException, "No persons.");
263 if(!person->getIdIsSet())
264 ThrowMsg(InvalidArgumentException, "Person object is wrong");
266 } Catch(InvalidArgumentException) {
267 LoggerE("Invalid arguments for updating persons : " << _rethrown_exception.GetMessage());
268 event->setResult(false);
269 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
275 int id = ContactUtility::strToInt(person->getId());
276 LoggerD("Load platform object id : " << id);
277 errorCode = contacts_db_get_record(_contacts_person._uri, id, &contacts_record);
278 if (errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
279 ThrowMsg(NotFoundException, "Error during executing contacts_db_get_record()");
280 else if (errorCode != CONTACTS_ERROR_NONE) {
281 LoggerE("error code : " << errorCode);
282 ThrowMsg(PlatformException, "Error during executing contacts_db_get_record()");
285 ContactsSvcObjectConverter::convertToPlatform(person, contacts_record);
287 errorCode = contacts_db_update_record(contacts_record);
288 if (errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
289 ThrowMsg(NotFoundException, "Error during executing contacts_db_update_record()");
290 else if (errorCode != CONTACTS_ERROR_NONE) {
291 LoggerE("error code : " << errorCode);
292 ThrowMsg(PlatformException, "Error during executing contacts_db_update_record()");
295 event->setResult(true);
296 event->setExceptionCode(ExceptionCodes::None);
298 Catch (NotFoundException)
300 LoggerE("Person doesn't exist : " << _rethrown_exception.GetMessage());
301 event->setResult(false);
302 event->setExceptionCode(ExceptionCodes::NotFoundException);
304 Catch (PlatformException) {
305 LoggerE("Error during updating person : " << _rethrown_exception.GetMessage());
306 event->setResult(false);
307 event->setExceptionCode(ExceptionCodes::PlatformException);
310 LoggerE("Error during display_contact_id person : " << _rethrown_exception.GetMessage());
311 event->setResult(false);
312 event->setExceptionCode(ExceptionCodes::PlatformException);
315 if(contacts_record != NULL)
316 contacts_record_destroy(contacts_record, true);
321 void ContactManager::managerUpdateBatch(const EventContactManagerUpdateBatchPtr &event)
325 contacts_list_h contacts_list = NULL;
326 PersonArrayPtr persons(NULL);
330 if(!event->getPersonsIsSet())
331 ThrowMsg(InvalidArgumentException, "Persons were not set.");
333 persons = event->getPersons();
335 ThrowMsg(InvalidArgumentException, "No persons.");
338 Catch(InvalidArgumentException)
340 ContactQueueManagerSingleton::Instance().decreaseQueueList();
341 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
343 ContactQueueManagerSingleton::Instance().pop();
345 LoggerE("Invalid arguments for updating persons : " << _rethrown_exception.GetMessage());
346 event->setResult(false);
347 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
353 errorCode = contacts_list_create(&contacts_list);
354 if(errorCode != CONTACTS_ERROR_NONE)
356 ThrowMsg(PlatformException, "Fail to create contacts_list_h");
359 for(PersonArray::iterator i = persons->begin(); i != persons->end(); i++)
361 contacts_record_h contacts_record = NULL;
362 PersonPtr person = *i;
366 LoggerD("id : " << person->getId());
367 int personIdInt = ContactUtility::strToInt(person->getId());
368 errorCode = contacts_db_get_record(_contacts_person._uri, personIdInt, &contacts_record);
369 if(errorCode != CONTACTS_ERROR_NONE)
371 ThrowMsg(NotFoundException, "No person (id:" << personIdInt << ")");
374 ContactsSvcObjectConverter::convertToPlatform(person, contacts_record);
376 errorCode = contacts_list_add(contacts_list, contacts_record);
377 if(errorCode != CONTACTS_ERROR_NONE)
379 ThrowMsg(PlatformException, "Error during add to list");
384 ThrowMsg(NotFoundException, "Error during converting contact object");
385 // LoggerE("Error during converting person object : " << _rethrown_exception.GetMessage());
390 KeySharePtrPair *keyPair = new KeySharePtrPair();
391 keyPair->key = m_eventMapAcc;
392 keyPair->contactManager = this;
393 errorCode = contacts_db_update_records_async(contacts_list, personsUpdateBatchResultCallback, (void*)keyPair);
394 if(errorCode != CONTACTS_ERROR_NONE)
397 ThrowMsg(PlatformException, "Error during contacts_db_update_records_async");
400 errorCode = contacts_list_destroy(contacts_list, true);
401 contacts_list = NULL;
402 if(errorCode != CONTACTS_ERROR_NONE)
405 ThrowMsg(PlatformException, "Error during contacts_list_destroy");
408 pair<long, EventContactManagerUpdateBatchPtr> keyEventPair(m_eventMapAcc, event);
409 m_updateBatchEventMap.insert(keyEventPair);
413 // event->switchToManualAnswer();
415 Catch (NotFoundException)
417 ContactQueueManagerSingleton::Instance().decreaseQueueList();
418 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
420 ContactQueueManagerSingleton::Instance().pop();
422 LoggerE("Person doesn't exist : " << _rethrown_exception.GetMessage());
423 event->setResult(false);
424 event->setExceptionCode(ExceptionCodes::NotFoundException);
426 Catch (PlatformException)
428 ContactQueueManagerSingleton::Instance().decreaseQueueList();
429 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
431 ContactQueueManagerSingleton::Instance().pop();
433 LoggerE("Error during updating persons : " << _rethrown_exception.GetMessage());
434 event->setResult(false);
435 event->setExceptionCode(ExceptionCodes::PlatformException);
439 ContactQueueManagerSingleton::Instance().decreaseQueueList();
440 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
442 ContactQueueManagerSingleton::Instance().pop();
444 LoggerE("Error during updating persons : " << _rethrown_exception.GetMessage());
445 event->setResult(false);
446 event->setExceptionCode(ExceptionCodes::PlatformException);
449 if(contacts_list != NULL)
450 contacts_list_destroy(contacts_list, false);
453 void ContactManager::OnRequestReceived(const EventContactManagerUpdateBatchPtr &event)
459 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
460 LoggerD("isEmpty : " << isEmpty);
462 managerUpdateBatch(event);
464 ContactQueueManagerSingleton::Instance().push(ContactQueueManager::UPATEBATCH, this, event);
466 ContactQueueManagerSingleton::Instance().increaseQueueList();
467 event->switchToManualAnswer();
471 LoggerE("Error during updating persons : " << _rethrown_exception.GetMessage());
472 event->setResult(false);
473 event->setExceptionCode(ExceptionCodes::PlatformException);
477 void ContactManager::OnRequestReceived(const EventContactManagerRemovePtr &event)
484 if(!event->getPersonIdIsSet())
485 ThrowMsg(InvalidArgumentException, "Persons were not set.");
487 string personIdStr = event->getPersonId();
489 if(!validate("^[0-9]+$", personIdStr, VALIDATE_MATCH_CASELESS))
490 ThrowMsg(InvalidArgumentException, "Id is wrong (" << personIdStr << ")" );
493 istringstream iss(personIdStr);
496 ThrowMsg(InvalidArgumentException, "Id is wrong (" << personIdStr << ")" );
499 int errorCode = contacts_db_delete_record(_contacts_person._uri, personId);
500 if(errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
501 ThrowMsg(NotFoundException, "Error during executing contacts_db_delete_record()");
502 else if (errorCode != CONTACTS_ERROR_NONE)
503 ThrowMsg(PlatformException, "Error during executing contacts_db_delete_record()");
505 event->setResult(true);
506 event->setExceptionCode(ExceptionCodes::None);
508 Catch (InvalidArgumentException)
510 LoggerE("Invalid person id : " << _rethrown_exception.GetMessage());
511 event->setResult(false);
512 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
515 Catch (NotFoundException)
517 LoggerE("Person doesn't exist : " << _rethrown_exception.GetMessage());
518 event->setResult(false);
519 event->setExceptionCode(ExceptionCodes::NotFoundException);
522 Catch (PlatformException) {
523 LoggerE("Error during removing person : " << _rethrown_exception.GetMessage());
524 event->setResult(false);
525 event->setExceptionCode(ExceptionCodes::PlatformException);
529 LoggerE("Error during removing person : " << _rethrown_exception.GetMessage());
530 event->setResult(false);
531 event->setExceptionCode(ExceptionCodes::PlatformException);
536 void ContactManager::managerRemoveBatch(const EventContactManagerRemoveBatchPtr &event)
540 StringArrayPtr personIds(NULL);
544 if(!event->getPersonIdsIsSet())
545 ThrowMsg(InvalidArgumentException, "Person IDs were not set.");
547 personIds = event->getPersonIds();
549 ThrowMsg(InvalidArgumentException, "No person IDs.");
552 Catch(InvalidArgumentException)
554 ContactQueueManagerSingleton::Instance().decreaseQueueList();
555 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
557 ContactQueueManagerSingleton::Instance().pop();
559 LoggerE("Invalid arguments for removing persons : " << _rethrown_exception.GetMessage());
560 event->setResult(false);
561 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
567 int *ids = new int[personIds->size()];
570 if(errorCode != CONTACTS_ERROR_NONE)
572 ThrowMsg(PlatformException, "Fail to create contacts_list_h");
575 for(StringArray::iterator i = personIds->begin(); i != personIds->end(); i++)
577 string personIdStr = *i;
583 if(!validate("^[0-9]+$", personIdStr, VALIDATE_MATCH_CASELESS))
584 ThrowMsg(InvalidArgumentException, "Id is wrong (" << personIdStr << ")" );
588 istringstream iss(personIdStr);
593 ThrowMsg(InvalidArgumentException, "Id is wrong (" << personIdStr << ")" );
596 ids[count] = personId;
601 ThrowMsg(NotFoundException, "Error during converting person object");
602 // LoggerE("Error during converting person object : " << _rethrown_exception.GetMessage());
607 KeySharePtrPair *keyPair = new KeySharePtrPair();
608 keyPair->key = m_eventMapAcc;
609 keyPair->contactManager = this;
610 errorCode = contacts_db_delete_records_async(_contacts_person._uri, ids, count, personsRemoveBatchResultCallback, (void*)keyPair);
617 if(errorCode != CONTACTS_ERROR_NONE)
620 ThrowMsg(PlatformException, "Error during add to list");
623 pair<long, EventContactManagerRemoveBatchPtr> keyEventPair(m_eventMapAcc, event);
624 m_removeBatchEventMap.insert(keyEventPair);
628 // event->switchToManualAnswer();
630 Catch (InvalidArgumentException)
632 ContactQueueManagerSingleton::Instance().decreaseQueueList();
633 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
635 ContactQueueManagerSingleton::Instance().pop();
637 LoggerE("Invalid person id : " << _rethrown_exception.GetMessage());
638 event->setResult(false);
639 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
642 Catch (NotFoundException)
644 ContactQueueManagerSingleton::Instance().decreaseQueueList();
645 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
647 ContactQueueManagerSingleton::Instance().pop();
649 LoggerE("Person doesn't exist : " << _rethrown_exception.GetMessage());
650 event->setResult(false);
651 event->setExceptionCode(ExceptionCodes::NotFoundException);
654 Catch (PlatformException)
656 ContactQueueManagerSingleton::Instance().decreaseQueueList();
657 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
659 ContactQueueManagerSingleton::Instance().pop();
661 LoggerE("Error during removing persons : " << _rethrown_exception.GetMessage());
662 event->setResult(false);
663 event->setExceptionCode(ExceptionCodes::PlatformException);
668 ContactQueueManagerSingleton::Instance().decreaseQueueList();
669 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
671 ContactQueueManagerSingleton::Instance().pop();
673 LoggerE("Error during removing persons : " << _rethrown_exception.GetMessage());
674 event->setResult(false);
675 event->setExceptionCode(ExceptionCodes::PlatformException);
680 void ContactManager::OnRequestReceived(const EventContactManagerRemoveBatchPtr &event)
686 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
687 LoggerD("isEmpty : " << isEmpty);
689 managerRemoveBatch(event);
691 ContactQueueManagerSingleton::Instance().push(ContactQueueManager::DELETEBATCH, this, event);
693 ContactQueueManagerSingleton::Instance().increaseQueueList();
694 event->switchToManualAnswer();
698 LoggerE("Error during deleting contacts : " << _rethrown_exception.GetMessage());
699 event->setResult(false);
700 event->setExceptionCode(ExceptionCodes::PlatformException);
704 void ContactManager::OnRequestReceived(const EventContactManagerFindPtr &event)
709 PersonSearchEnginePtr searchEngine(new PersonSearchEngine());
711 if(event->getFilterIsSet())
713 FilterPtr filter = event->getFilter();
715 FilterValidatorPtr validator = PersonFilterValidatorFactory::getPersonFilterValidator();
716 bool success = filter->validate(validator);
719 ThrowMsg(InvalidArgumentException, "Invalid filter arguments.");
721 searchEngine->setCondition(filter);
724 if (event->getSortModeIsSet())
725 searchEngine->setSortMode(event->getSortMode());
727 searchEngine->setSortMode();
729 event->setPersons(searchEngine->getResult());
730 event->setResult(true);
732 } Catch (NotFoundException) {
733 LoggerE("Person doesn't exist : " << _rethrown_exception.GetMessage());
734 event->setExceptionCode(ExceptionCodes::NotFoundException);
735 event->setResult(false);
737 } Catch (PlatformException) {
738 LoggerE("Error during finding person : " << _rethrown_exception.GetMessage());
739 event->setExceptionCode(ExceptionCodes::PlatformException);
740 event->setResult(false);
742 } Catch (InvalidArgumentException) {
743 LoggerE("Invalid Arguments : " << _rethrown_exception.GetMessage());
744 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
745 event->setResult(false);
747 } Catch (Exception) {
748 LoggerE("Error during finding person : " << _rethrown_exception.GetMessage());
749 event->setExceptionCode(ExceptionCodes::PlatformException);
750 event->setResult(false);
754 void ContactManager::OnRequestReceived(const EventContactManagerAddChangeListenerPtr &event)
759 if(!event->getEmitterIsSet())
760 ThrowMsg(InvalidArgumentException, "Invalid arguments.");
762 EventContactManagerChangeListenerEmitterPtr emitter = event->getEmitter();
764 ThrowMsg(InvalidArgumentException, "Invalid arguments.");
766 if(m_contactManagerEmitters.size() == 0)
768 LoggerD("Watch registered initially");
770 ContactsSvcChangeListenerManagerSingleton::Instance().registerPersonsChangeListener(this);
773 m_contactManagerEmitters.attach(emitter);
775 long id = ContactsSvcChangeListenerManagerSingleton::Instance().getWatchIdAndInc();
776 m_watchIdMap[id] = emitter->getId();
779 event->setResult(true);
781 } Catch (NotFoundException) {
782 LoggerE("Person doesn't exist : " << _rethrown_exception.GetMessage());
783 event->setExceptionCode(ExceptionCodes::NotFoundException);
784 event->setResult(false);
786 } Catch (PlatformException) {
787 LoggerE("Error during addListner person : " << _rethrown_exception.GetMessage());
788 event->setExceptionCode(ExceptionCodes::PlatformException);
789 event->setResult(false);
791 } Catch (InvalidArgumentException) {
792 LoggerE("Invalid Arguments : " << _rethrown_exception.GetMessage());
793 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
794 event->setResult(false);
796 } Catch (Exception) {
797 LoggerE("Error during addListner person : " << _rethrown_exception.GetMessage());
798 event->setExceptionCode(ExceptionCodes::PlatformException);
799 event->setResult(false);
803 void ContactManager::OnRequestReceived(const EventContactManagerRemoveChangeListenerPtr &event)
808 if(!event->getIdIsSet())
809 ThrowMsg(InvalidArgumentException, "Invalid arguments.");
811 long id = event->getId();
812 if(m_watchIdMap.find(id) == m_watchIdMap.end())
813 ThrowMsg(NotFoundException, "No watchId : " << id);
815 //DPL::Mutex::ScopedLock lock(&m_addressBookEmittersMutex);
816 bool success = m_contactManagerEmitters.detach(m_watchIdMap[id]);
818 ThrowMsg(NotFoundException, "No watchId : " << id);
820 m_watchIdMap.erase(id);
822 if(m_contactManagerEmitters.size() == 0)
824 LoggerD("No watcher is registered. unsubscribing from person service.");
826 ContactsSvcChangeListenerManagerSingleton::Instance().unregisterPersonsChangeListener(this);
829 event->setResult(true);
831 } Catch (NotFoundException) {
832 LoggerE("WatchId doesn't exist : " << _rethrown_exception.GetMessage());
833 event->setExceptionCode(ExceptionCodes::NotFoundException);
834 event->setResult(false);
836 } Catch (PlatformException) {
837 LoggerE("Error during removeListner person : " << _rethrown_exception.GetMessage());
838 event->setExceptionCode(ExceptionCodes::PlatformException);
839 event->setResult(false);
841 } Catch (InvalidArgumentException) {
842 LoggerE("Invalid Arguments : " << _rethrown_exception.GetMessage());
843 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
844 event->setResult(false);
846 } Catch (Exception) {
847 LoggerE("Error during removeListner person : " << _rethrown_exception.GetMessage());
848 event->setExceptionCode(ExceptionCodes::PlatformException);
849 event->setResult(false);
853 void ContactManager::onContactsSvcPersonsAdded(PersonArrayPtr &persons)
855 EventInfoContactManagerChangeAddedPtr personsAdded(new EventInfoContactManagerChangeAdded());
856 personsAdded->setPersons(persons);
857 EventInfoContactManagerChangePtr event = DPL::StaticPointerCast<EventInfoContactManagerChange>(personsAdded);
858 EventContactManagerChangeListenerPtr listener(new EventContactManagerChangeListener(event));
859 m_contactManagerEmitters.emit(listener);
862 void ContactManager::onContactsSvcPersonsUpdated(PersonArrayPtr &persons)
864 EventInfoContactManagerChangeUpdatedPtr personsUpdated(new EventInfoContactManagerChangeUpdated());
865 personsUpdated->setPersons(persons);
866 EventInfoContactManagerChangePtr event = DPL::StaticPointerCast<EventInfoContactManagerChange>(personsUpdated);
867 EventContactManagerChangeListenerPtr listener(new EventContactManagerChangeListener(event));
868 m_contactManagerEmitters.emit(listener);
871 void ContactManager::onContactsSvcPersonsRemoved(StringArrayPtr &personIds)
873 EventInfoContactManagerChangeRemovedPtr personsRemoved(new EventInfoContactManagerChangeRemoved());
874 personsRemoved->setPersonIds(personIds);
875 EventInfoContactManagerChangePtr event = DPL::StaticPointerCast<EventInfoContactManagerChange>(personsRemoved);
876 EventContactManagerChangeListenerPtr listener(new EventContactManagerChangeListener(event));
877 m_contactManagerEmitters.emit(listener);
880 void ContactManager::personsUpdateBatchResultCallback(int error, void *user_data)
884 if(user_data == NULL)
886 LoggerE("user_data is NULL");
890 KeySharePtrPair *keyPair = (KeySharePtrPair*)user_data;
892 long key = keyPair->key;
893 ContactManager *contactManager = keyPair->contactManager;
897 contactManager->personsUpdateBatchResultCallback(error, key);
900 void ContactManager::personsUpdateBatchResultCallback(int error, long key)
902 EventContactManagerUpdateBatchPtr event;
904 EventContactManagerUpdateBatchMap::iterator iter;
905 iter = m_updateBatchEventMap.find(key);
906 if(iter == m_updateBatchEventMap.end())
908 LoggerE("No event for key : " << key);
912 event = iter->second;
913 m_updateBatchEventMap.erase(iter);
915 if(error != CONTACTS_ERROR_NONE)
917 LoggerE("persons_db_result_cb gives error : " << error);
918 event->setResult(false);
919 event->setExceptionCode(ExceptionCodes::PlatformException);
920 EventRequestReceiver<EventContactManagerUpdateBatch>::ManualAnswer(event);
924 event->setResult(true);
925 event->setExceptionCode(ExceptionCodes::None);
926 EventRequestReceiver<EventContactManagerUpdateBatch>::ManualAnswer(event);
929 void ContactManager::personsRemoveBatchResultCallback(int error, void *user_data)
933 if(user_data == NULL)
935 LoggerE("user_data is NULL");
939 KeySharePtrPair *keyPair = (KeySharePtrPair*)user_data;
941 long key = keyPair->key;
942 ContactManager *contactManager = keyPair->contactManager;
946 contactManager->personsRemoveBatchResultCallback(error, key);
949 void ContactManager::personsRemoveBatchResultCallback(int error, long key)
951 EventContactManagerRemoveBatchPtr event;
953 EventContactManagerRemoveBatchMap::iterator iter;
954 iter = m_removeBatchEventMap.find(key);
955 if(iter == m_removeBatchEventMap.end())
957 LoggerE("No event for key : " << key);
961 event = iter->second;
962 m_removeBatchEventMap.erase(iter);
964 if(error != CONTACTS_ERROR_NONE)
966 LoggerE("persons_db_result_cb gives error : " << error);
967 event->setResult(false);
968 event->setExceptionCode(ExceptionCodes::PlatformException);
969 EventRequestReceiver<EventContactManagerRemoveBatch>::ManualAnswer(event);
973 event->setResult(true);
974 event->setExceptionCode(ExceptionCodes::None);
975 EventRequestReceiver<EventContactManagerRemoveBatch>::ManualAnswer(event);