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, "invalid Address book");
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");
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 : " << 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 errorCode = contacts_db_get_record(_contacts_person._uri, id, &contacts_record);
277 if (errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
278 ThrowMsg(NotFoundException, "Error during executing contacts_db_get_record()");
279 else if (errorCode != CONTACTS_ERROR_NONE) {
280 LoggerE("error code : " << errorCode);
281 ThrowMsg(PlatformException, "Error during executing contacts_db_get_record()");
284 ContactsSvcObjectConverter::convertToPlatform(person, contacts_record);
286 errorCode = contacts_db_update_record(contacts_record);
287 if (errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
288 ThrowMsg(NotFoundException, "Error during executing contacts_db_update_record()");
289 else if (errorCode != CONTACTS_ERROR_NONE) {
290 LoggerE("error code : " << errorCode);
291 ThrowMsg(PlatformException, "Error during executing contacts_db_update_record()");
294 event->setResult(true);
295 event->setExceptionCode(ExceptionCodes::None);
297 Catch (NotFoundException)
299 LoggerE("Person doesn't exist : " << _rethrown_exception.GetMessage());
300 event->setResult(false);
301 event->setExceptionCode(ExceptionCodes::NotFoundException);
303 Catch (PlatformException) {
304 LoggerE("Error during updating person : " << _rethrown_exception.GetMessage());
305 event->setResult(false);
306 event->setExceptionCode(ExceptionCodes::PlatformException);
309 LoggerE("Error during display_contact_id person : " << _rethrown_exception.GetMessage());
310 event->setResult(false);
311 event->setExceptionCode(ExceptionCodes::PlatformException);
314 if(contacts_record != NULL)
315 contacts_record_destroy(contacts_record, true);
320 void ContactManager::managerUpdateBatch(const EventContactManagerUpdateBatchPtr &event)
324 contacts_list_h contacts_list = NULL;
325 PersonArrayPtr persons(NULL);
329 if(!event->getPersonsIsSet())
330 ThrowMsg(InvalidArgumentException, "Persons were not set.");
332 persons = event->getPersons();
334 ThrowMsg(InvalidArgumentException, "No persons.");
337 Catch(InvalidArgumentException)
339 ContactQueueManagerSingleton::Instance().decreaseQueueList();
340 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
342 ContactQueueManagerSingleton::Instance().pop();
344 LoggerE("Invalid arguments for updating persons : " << _rethrown_exception.GetMessage());
345 event->setResult(false);
346 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
352 errorCode = contacts_list_create(&contacts_list);
353 if(errorCode != CONTACTS_ERROR_NONE)
355 ThrowMsg(PlatformException, "Fail to create contacts_list_h");
358 for(PersonArray::iterator i = persons->begin(); i != persons->end(); i++)
360 contacts_record_h contacts_record = NULL;
361 PersonPtr person = *i;
365 int personIdInt = ContactUtility::strToInt(person->getId());
366 errorCode = contacts_db_get_record(_contacts_person._uri, personIdInt, &contacts_record);
367 if(errorCode != CONTACTS_ERROR_NONE)
369 ThrowMsg(NotFoundException, "No person");
372 ContactsSvcObjectConverter::convertToPlatform(person, contacts_record);
374 errorCode = contacts_list_add(contacts_list, contacts_record);
375 if(errorCode != CONTACTS_ERROR_NONE)
377 ThrowMsg(PlatformException, "Error during add to list");
382 ThrowMsg(NotFoundException, "Error during converting contact object");
383 // LoggerE("Error during converting person object : " << _rethrown_exception.GetMessage());
388 KeySharePtrPair *keyPair = new KeySharePtrPair();
389 keyPair->key = m_eventMapAcc;
390 keyPair->contactManager = this;
391 errorCode = contacts_db_update_records_async(contacts_list, personsUpdateBatchResultCallback, (void*)keyPair);
392 if(errorCode != CONTACTS_ERROR_NONE)
395 ThrowMsg(PlatformException, "Error during contacts_db_update_records_async");
398 errorCode = contacts_list_destroy(contacts_list, true);
399 contacts_list = NULL;
400 if(errorCode != CONTACTS_ERROR_NONE)
403 ThrowMsg(PlatformException, "Error during contacts_list_destroy");
406 pair<long, EventContactManagerUpdateBatchPtr> keyEventPair(m_eventMapAcc, event);
407 m_updateBatchEventMap.insert(keyEventPair);
411 // event->switchToManualAnswer();
413 Catch (NotFoundException)
415 ContactQueueManagerSingleton::Instance().decreaseQueueList();
416 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
418 ContactQueueManagerSingleton::Instance().pop();
420 LoggerE("Person doesn't exist : " << _rethrown_exception.GetMessage());
421 event->setResult(false);
422 event->setExceptionCode(ExceptionCodes::NotFoundException);
424 Catch (PlatformException)
426 ContactQueueManagerSingleton::Instance().decreaseQueueList();
427 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
429 ContactQueueManagerSingleton::Instance().pop();
431 LoggerE("Error during updating persons : " << _rethrown_exception.GetMessage());
432 event->setResult(false);
433 event->setExceptionCode(ExceptionCodes::PlatformException);
437 ContactQueueManagerSingleton::Instance().decreaseQueueList();
438 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
440 ContactQueueManagerSingleton::Instance().pop();
442 LoggerE("Error during updating persons : " << _rethrown_exception.GetMessage());
443 event->setResult(false);
444 event->setExceptionCode(ExceptionCodes::PlatformException);
447 if(contacts_list != NULL)
448 contacts_list_destroy(contacts_list, false);
451 void ContactManager::OnRequestReceived(const EventContactManagerUpdateBatchPtr &event)
457 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
459 managerUpdateBatch(event);
461 ContactQueueManagerSingleton::Instance().push(ContactQueueManager::UPATEBATCH, this, event);
463 ContactQueueManagerSingleton::Instance().increaseQueueList();
464 event->switchToManualAnswer();
468 LoggerE("Error during updating persons : " << _rethrown_exception.GetMessage());
469 event->setResult(false);
470 event->setExceptionCode(ExceptionCodes::PlatformException);
474 void ContactManager::OnRequestReceived(const EventContactManagerRemovePtr &event)
481 if(!event->getPersonIdIsSet())
482 ThrowMsg(InvalidArgumentException, "Persons were not set.");
484 string personIdStr = event->getPersonId();
486 if(!validate("^[0-9]+$", personIdStr, VALIDATE_MATCH_CASELESS))
487 ThrowMsg(InvalidArgumentException, "invalid" );
490 istringstream iss(personIdStr);
493 ThrowMsg(InvalidArgumentException, "wrong" );
496 int errorCode = contacts_db_delete_record(_contacts_person._uri, personId);
497 if(errorCode == CONTACTS_ERROR_INVALID_PARAMETER)
498 ThrowMsg(NotFoundException, "Error during executing contacts_db_delete_record()");
499 else if (errorCode != CONTACTS_ERROR_NONE)
500 ThrowMsg(PlatformException, "Error during executing contacts_db_delete_record()");
502 event->setResult(true);
503 event->setExceptionCode(ExceptionCodes::None);
505 Catch (InvalidArgumentException)
507 LoggerE("Invalid person : " << _rethrown_exception.GetMessage());
508 event->setResult(false);
509 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
512 Catch (NotFoundException)
514 LoggerE("Person doesn't exist : " << _rethrown_exception.GetMessage());
515 event->setResult(false);
516 event->setExceptionCode(ExceptionCodes::NotFoundException);
519 Catch (PlatformException) {
520 LoggerE("Error during removing person : " << _rethrown_exception.GetMessage());
521 event->setResult(false);
522 event->setExceptionCode(ExceptionCodes::PlatformException);
526 LoggerE("Error during removing person : " << _rethrown_exception.GetMessage());
527 event->setResult(false);
528 event->setExceptionCode(ExceptionCodes::PlatformException);
533 void ContactManager::managerRemoveBatch(const EventContactManagerRemoveBatchPtr &event)
537 StringArrayPtr personIds(NULL);
541 if(!event->getPersonIdsIsSet())
542 ThrowMsg(InvalidArgumentException, "Person IDs were not set.");
544 personIds = event->getPersonIds();
546 ThrowMsg(InvalidArgumentException, "No person.");
549 Catch(InvalidArgumentException)
551 ContactQueueManagerSingleton::Instance().decreaseQueueList();
552 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
554 ContactQueueManagerSingleton::Instance().pop();
556 LoggerE("Invalid arguments for removing persons : " << _rethrown_exception.GetMessage());
557 event->setResult(false);
558 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
564 int *ids = new int[personIds->size()];
567 if(errorCode != CONTACTS_ERROR_NONE)
569 ThrowMsg(PlatformException, "Fail to create contacts_list_h");
572 for(StringArray::iterator i = personIds->begin(); i != personIds->end(); i++)
574 string personIdStr = *i;
580 if(!validate("^[0-9]+$", personIdStr, VALIDATE_MATCH_CASELESS))
581 ThrowMsg(InvalidArgumentException, "invalid" );
585 istringstream iss(personIdStr);
590 ThrowMsg(InvalidArgumentException, "wrong" );
593 ids[count] = personId;
598 ThrowMsg(NotFoundException, "Error during converting person object");
599 // LoggerE("Error during converting person object : " << _rethrown_exception.GetMessage());
604 KeySharePtrPair *keyPair = new KeySharePtrPair();
605 keyPair->key = m_eventMapAcc;
606 keyPair->contactManager = this;
607 errorCode = contacts_db_delete_records_async(_contacts_person._uri, ids, count, personsRemoveBatchResultCallback, (void*)keyPair);
614 if(errorCode != CONTACTS_ERROR_NONE)
617 ThrowMsg(PlatformException, "Error during add to list");
620 pair<long, EventContactManagerRemoveBatchPtr> keyEventPair(m_eventMapAcc, event);
621 m_removeBatchEventMap.insert(keyEventPair);
625 // event->switchToManualAnswer();
627 Catch (InvalidArgumentException)
629 ContactQueueManagerSingleton::Instance().decreaseQueueList();
630 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
632 ContactQueueManagerSingleton::Instance().pop();
634 LoggerE("Invalid person id : " << _rethrown_exception.GetMessage());
635 event->setResult(false);
636 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
639 Catch (NotFoundException)
641 ContactQueueManagerSingleton::Instance().decreaseQueueList();
642 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
644 ContactQueueManagerSingleton::Instance().pop();
646 LoggerE("Person doesn't exist : " << _rethrown_exception.GetMessage());
647 event->setResult(false);
648 event->setExceptionCode(ExceptionCodes::NotFoundException);
651 Catch (PlatformException)
653 ContactQueueManagerSingleton::Instance().decreaseQueueList();
654 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
656 ContactQueueManagerSingleton::Instance().pop();
658 LoggerE("Error during removing persons : " << _rethrown_exception.GetMessage());
659 event->setResult(false);
660 event->setExceptionCode(ExceptionCodes::PlatformException);
665 ContactQueueManagerSingleton::Instance().decreaseQueueList();
666 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
668 ContactQueueManagerSingleton::Instance().pop();
670 LoggerE("Error during removing persons : " << _rethrown_exception.GetMessage());
671 event->setResult(false);
672 event->setExceptionCode(ExceptionCodes::PlatformException);
677 void ContactManager::OnRequestReceived(const EventContactManagerRemoveBatchPtr &event)
683 bool isEmpty = ContactQueueManagerSingleton::Instance().empty();
685 managerRemoveBatch(event);
687 ContactQueueManagerSingleton::Instance().push(ContactQueueManager::DELETEBATCH, this, event);
689 ContactQueueManagerSingleton::Instance().increaseQueueList();
690 event->switchToManualAnswer();
694 LoggerE("Error during deleting contacts : " << _rethrown_exception.GetMessage());
695 event->setResult(false);
696 event->setExceptionCode(ExceptionCodes::PlatformException);
700 void ContactManager::OnRequestReceived(const EventContactManagerFindPtr &event)
705 PersonSearchEnginePtr searchEngine(new PersonSearchEngine());
707 if(event->getFilterIsSet())
709 FilterPtr filter = event->getFilter();
711 FilterValidatorPtr validator = PersonFilterValidatorFactory::getPersonFilterValidator();
712 bool success = filter->validate(validator);
715 ThrowMsg(InvalidArgumentException, "Invalid filter arguments.");
717 searchEngine->setCondition(filter);
720 if (event->getSortModeIsSet())
721 searchEngine->setSortMode(event->getSortMode());
723 searchEngine->setSortMode();
725 event->setPersons(searchEngine->getResult());
726 event->setResult(true);
728 } Catch (NotFoundException) {
729 LoggerE("Person doesn't exist : " << _rethrown_exception.GetMessage());
730 event->setExceptionCode(ExceptionCodes::NotFoundException);
731 event->setResult(false);
733 } Catch (PlatformException) {
734 LoggerE("Error during finding person : " << _rethrown_exception.GetMessage());
735 event->setExceptionCode(ExceptionCodes::PlatformException);
736 event->setResult(false);
738 } Catch (InvalidArgumentException) {
739 LoggerE("Invalid Arguments : " << _rethrown_exception.GetMessage());
740 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
741 event->setResult(false);
743 } Catch (Exception) {
744 LoggerE("Error during finding person : " << _rethrown_exception.GetMessage());
745 event->setExceptionCode(ExceptionCodes::PlatformException);
746 event->setResult(false);
750 void ContactManager::OnRequestReceived(const EventContactManagerAddChangeListenerPtr &event)
755 if(!event->getEmitterIsSet())
756 ThrowMsg(InvalidArgumentException, "Invalid arguments.");
758 EventContactManagerChangeListenerEmitterPtr emitter = event->getEmitter();
760 ThrowMsg(InvalidArgumentException, "Invalid arguments.");
762 if(m_contactManagerEmitters.size() == 0)
764 LoggerD("Watch registered initially");
766 ContactsSvcChangeListenerManagerSingleton::Instance().registerPersonsChangeListener(this);
769 m_contactManagerEmitters.attach(emitter);
771 long id = ContactsSvcChangeListenerManagerSingleton::Instance().getWatchIdAndInc();
772 m_watchIdMap[id] = emitter->getId();
775 event->setResult(true);
777 } Catch (NotFoundException) {
778 LoggerE("Person doesn't exist : " << _rethrown_exception.GetMessage());
779 event->setExceptionCode(ExceptionCodes::NotFoundException);
780 event->setResult(false);
782 } Catch (PlatformException) {
783 LoggerE("Error during addListner person : " << _rethrown_exception.GetMessage());
784 event->setExceptionCode(ExceptionCodes::PlatformException);
785 event->setResult(false);
787 } Catch (InvalidArgumentException) {
788 LoggerE("Invalid Arguments : " << _rethrown_exception.GetMessage());
789 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
790 event->setResult(false);
792 } Catch (Exception) {
793 LoggerE("Error during addListner person : " << _rethrown_exception.GetMessage());
794 event->setExceptionCode(ExceptionCodes::PlatformException);
795 event->setResult(false);
799 void ContactManager::OnRequestReceived(const EventContactManagerRemoveChangeListenerPtr &event)
804 if(!event->getIdIsSet())
805 ThrowMsg(InvalidArgumentException, "Invalid arguments.");
807 long id = event->getId();
808 if(m_watchIdMap.find(id) == m_watchIdMap.end())
809 ThrowMsg(NotFoundException, "No watchId 1 ");
811 //DPL::Mutex::ScopedLock lock(&m_addressBookEmittersMutex);
812 bool success = m_contactManagerEmitters.detach(m_watchIdMap[id]);
814 ThrowMsg(NotFoundException, "No watchId 2 ");
816 m_watchIdMap.erase(id);
818 if(m_contactManagerEmitters.size() == 0)
820 LoggerD("No watcher is registered. unsubscribing from person service.");
822 ContactsSvcChangeListenerManagerSingleton::Instance().unregisterPersonsChangeListener(this);
825 event->setResult(true);
827 } Catch (NotFoundException) {
828 LoggerE("WatchId doesn't exist : " << _rethrown_exception.GetMessage());
829 event->setExceptionCode(ExceptionCodes::NotFoundException);
830 event->setResult(false);
832 } Catch (PlatformException) {
833 LoggerE("Error during removeListner person : " << _rethrown_exception.GetMessage());
834 event->setExceptionCode(ExceptionCodes::PlatformException);
835 event->setResult(false);
837 } Catch (InvalidArgumentException) {
838 LoggerE("Invalid Arguments : " << _rethrown_exception.GetMessage());
839 event->setExceptionCode(ExceptionCodes::InvalidArgumentException);
840 event->setResult(false);
842 } Catch (Exception) {
843 LoggerE("Error during removeListner person : " << _rethrown_exception.GetMessage());
844 event->setExceptionCode(ExceptionCodes::PlatformException);
845 event->setResult(false);
849 void ContactManager::onContactsSvcPersonsAdded(PersonArrayPtr &persons)
851 EventInfoContactManagerChangeAddedPtr personsAdded(new EventInfoContactManagerChangeAdded());
852 personsAdded->setPersons(persons);
853 EventInfoContactManagerChangePtr event = DPL::StaticPointerCast<EventInfoContactManagerChange>(personsAdded);
854 EventContactManagerChangeListenerPtr listener(new EventContactManagerChangeListener(event));
855 m_contactManagerEmitters.emit(listener);
858 void ContactManager::onContactsSvcPersonsUpdated(PersonArrayPtr &persons)
860 EventInfoContactManagerChangeUpdatedPtr personsUpdated(new EventInfoContactManagerChangeUpdated());
861 personsUpdated->setPersons(persons);
862 EventInfoContactManagerChangePtr event = DPL::StaticPointerCast<EventInfoContactManagerChange>(personsUpdated);
863 EventContactManagerChangeListenerPtr listener(new EventContactManagerChangeListener(event));
864 m_contactManagerEmitters.emit(listener);
867 void ContactManager::onContactsSvcPersonsRemoved(StringArrayPtr &personIds)
869 EventInfoContactManagerChangeRemovedPtr personsRemoved(new EventInfoContactManagerChangeRemoved());
870 personsRemoved->setPersonIds(personIds);
871 EventInfoContactManagerChangePtr event = DPL::StaticPointerCast<EventInfoContactManagerChange>(personsRemoved);
872 EventContactManagerChangeListenerPtr listener(new EventContactManagerChangeListener(event));
873 m_contactManagerEmitters.emit(listener);
876 void ContactManager::personsUpdateBatchResultCallback(int error, void *user_data)
880 if(user_data == NULL)
882 LoggerE("user_data is NULL");
886 KeySharePtrPair *keyPair = (KeySharePtrPair*)user_data;
888 long key = keyPair->key;
889 ContactManager *contactManager = keyPair->contactManager;
893 contactManager->personsUpdateBatchResultCallback(error, key);
896 void ContactManager::personsUpdateBatchResultCallback(int error, long key)
898 EventContactManagerUpdateBatchPtr event;
900 EventContactManagerUpdateBatchMap::iterator iter;
901 iter = m_updateBatchEventMap.find(key);
902 if(iter == m_updateBatchEventMap.end())
904 LoggerE("No event for key : " << key);
908 event = iter->second;
909 m_updateBatchEventMap.erase(iter);
911 if(error != CONTACTS_ERROR_NONE)
913 LoggerE("persons_db_result_cb gives error : " << error);
914 event->setResult(false);
915 event->setExceptionCode(ExceptionCodes::PlatformException);
916 EventRequestReceiver<EventContactManagerUpdateBatch>::ManualAnswer(event);
920 event->setResult(true);
921 event->setExceptionCode(ExceptionCodes::None);
922 EventRequestReceiver<EventContactManagerUpdateBatch>::ManualAnswer(event);
925 void ContactManager::personsRemoveBatchResultCallback(int error, void *user_data)
929 if(user_data == NULL)
931 LoggerE("user_data is NULL");
935 KeySharePtrPair *keyPair = (KeySharePtrPair*)user_data;
937 long key = keyPair->key;
938 ContactManager *contactManager = keyPair->contactManager;
942 contactManager->personsRemoveBatchResultCallback(error, key);
945 void ContactManager::personsRemoveBatchResultCallback(int error, long key)
947 EventContactManagerRemoveBatchPtr event;
949 EventContactManagerRemoveBatchMap::iterator iter;
950 iter = m_removeBatchEventMap.find(key);
951 if(iter == m_removeBatchEventMap.end())
953 LoggerE("No event for key : " << key);
957 event = iter->second;
958 m_removeBatchEventMap.erase(iter);
960 if(error != CONTACTS_ERROR_NONE)
962 LoggerE("persons_db_result_cb gives error : " << error);
963 event->setResult(false);
964 event->setExceptionCode(ExceptionCodes::PlatformException);
965 EventRequestReceiver<EventContactManagerRemoveBatch>::ManualAnswer(event);
969 event->setResult(true);
970 event->setExceptionCode(ExceptionCodes::None);
971 EventRequestReceiver<EventContactManagerRemoveBatch>::ManualAnswer(event);