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 #include "CallHistory.h"
25 #include <Commons/Exception.h>
26 #include <CommonsJavaScript/JSCallbackManager.h>
27 #include <dpl/shared_ptr.h>
31 #include <IFilterVisitor.h>
32 #include "CallHistoryDefine.h"
34 #include "CallHistoryFilter.h"
36 using namespace DeviceAPI::Tizen;
37 using namespace WrtDeviceApis;
38 using namespace WrtDeviceApis::Commons;
39 using namespace WrtDeviceApis::CommonsJavaScript;
43 namespace CallHistory {
45 std::vector<CallHistory::WatcherPtr> CallHistory::m_watchers;
47 CallHistory::CallHistory()
50 if (contacts_connect2() == CONTACTS_ERROR_NONE) {
51 LoggerD("Successful to connect Call history DB ");
53 LoggerD("Failed to connect Call history DB ");
56 EventCallHistoryPtr event(new EventCallHistory());
57 event->setCmdType(EventCallHistory::CONNECT);
58 event->setForSynchronousCall();
59 EventRequestReceiver<EventCallHistory>::PostRequest(event);
62 CallHistory::~CallHistory()
66 if (contacts_disconnect2() == CONTACTS_ERROR_NONE) {
67 LoggerD("Successful to disconnect Call history DB ");
69 LoggerD("Failed to disconnect Call history DB ");
72 int ret = CONTACTS_ERROR_NONE;
73 std::vector<CallHistory::WatcherPtr>::iterator it = CallHistory::m_watchers.begin();
75 if (m_watchers.size() > 0) {
76 for (;it < CallHistory::m_watchers.end();) {
77 ret = contacts_db_remove_changed_cb_with_info(_contacts_phone_log._uri, callhistoryListenerCB, it->Get());
79 if (ret != CONTACTS_ERROR_NONE) {
80 LoggerD("Failed removing listener");
83 it = CallHistory::m_watchers.erase(it);
87 EventCallHistoryPtr event(new EventCallHistory());
88 event->setCmdType(EventCallHistory::DISCONNECT);
89 event->setForSynchronousCall();
90 EventRequestReceiver<EventCallHistory>::PostRequest(event);
93 void CallHistory::callhistoryListenerCB(const char* view_uri, char *changes, void* user_data)
96 if (user_data != NULL) {
97 ((CallHistory::Watcher*)user_data)->ListenerCB(changes);
101 void CallHistory::removeBatchCB(int error, void *user_data)
104 if (user_data != NULL) {
105 CallHistory* chManager = (CallHistory *)((EventCallHistoryPtrs<EventRemoveBatch> *)user_data)->getThisPtr();
108 EventRemoveBatchPtr event = ((EventCallHistoryPtrs<EventRemoveBatch> *)user_data)->getEventPtrs();
109 chManager->callRemoveBatchEvent(error, event);
115 void CallHistory::removeAllCB(int error, void *user_data)
118 if (user_data != NULL) {
119 CallHistory* chManager = (CallHistory *)((EventCallHistoryPtrs<EventRemoveAll> *)user_data)->getThisPtr();
122 EventRemoveAllPtr event = ((EventCallHistoryPtrs<EventRemoveAll> *)user_data)->getEventPtrs();
123 chManager->callRemoveAllEvent(error, event);
129 bool CallHistory::convertCallHistory(callhistory_query_s *query_log, CallHistoryEntryListPtr &callEntries)
131 if (query_log == NULL || callEntries == NULL)
134 CallHistoryEntryPropertiesPtr callHistoryItem(new CallHistoryEntryProperties());
135 StringArrayPtr stringArray(new StringArray());
136 RemotePartyPtr remoteParty(new RemoteParty());
137 RemotePartyListPtr remotePartyList(new RemotePartyList());
139 std::string callType("");
140 std::string tags("");
141 std::string direction("");
142 std::string number("");
144 if (query_log->phone_number != NULL) {
145 number.append(query_log->phone_number);
148 switch(query_log->calllog_type) {
149 case CONTACTS_PLOG_TYPE_VOICE_INCOMMING:
150 callType.append(STR_TIZEN_TEL);
151 tags.append(STR_CALL_VOICE);
152 direction.append(STR_RECEIVED);
154 case CONTACTS_PLOG_TYPE_VOICE_OUTGOING:
155 callType.append(STR_TIZEN_TEL);
156 tags.append(STR_CALL_VOICE);
157 direction.append(STR_DIALED);
159 case CONTACTS_PLOG_TYPE_VOICE_INCOMMING_SEEN:
160 callType.append(STR_TIZEN_TEL);
161 tags.append(STR_CALL_VOICE);
162 direction.append(STR_MISSED);
164 case CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN:
165 callType.append(STR_TIZEN_TEL);
166 tags.append(STR_CALL_VOICE);
167 direction.append(STR_MISSED_NEW);
169 case CONTACTS_PLOG_TYPE_VOICE_REJECT:
170 callType.append(STR_TIZEN_TEL);
171 tags.append(STR_CALL_VOICE);
172 direction.append(STR_REJECTED);
174 case CONTACTS_PLOG_TYPE_VOICE_BLOCKED:
175 callType.append(STR_TIZEN_TEL);
176 tags.append(STR_CALL_VOICE);
177 direction.append(STR_BLOCKED);
179 case CONTACTS_PLOG_TYPE_VIDEO_INCOMMING:
180 callType.append(STR_TIZEN_TEL);
181 tags.append(STR_CALL_VIDEO);
182 direction.append(STR_RECEIVED);
184 case CONTACTS_PLOG_TYPE_VIDEO_OUTGOING:
185 callType.append(STR_TIZEN_TEL);
186 tags.append(STR_CALL_VIDEO);
187 direction.append(STR_DIALED);
189 case CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN:
190 callType.append(STR_TIZEN_TEL);
191 tags.append(STR_CALL_VIDEO);
192 direction.append(STR_MISSED);
194 case CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN:
195 callType.append(STR_TIZEN_TEL);
196 tags.append(STR_CALL_VIDEO);
197 direction.append(STR_MISSED_NEW);
199 case CONTACTS_PLOG_TYPE_VIDEO_REJECT:
200 callType.append(STR_TIZEN_TEL);
201 tags.append(STR_CALL_VIDEO);
202 direction.append(STR_REJECTED);
204 case CONTACTS_PLOG_TYPE_VIDEO_BLOCKED:
205 callType.append(STR_TIZEN_TEL);
206 tags.append(STR_CALL_VIDEO);
207 direction.append(STR_BLOCKED);
213 callHistoryItem->setEntryId(query_log->calllog_db_id);
214 callHistoryItem->setCallType(callType);
215 stringArray->push_back(tags);
216 callHistoryItem->setTags(stringArray);
218 remoteParty->setRemoteParty(number);
219 std::stringstream personIdStream;
220 personIdStream << query_log->person_db_id;
221 remoteParty->setPersonId(personIdStream.str());
223 remotePartyList->push_back(remoteParty);
224 callHistoryItem->setRemoteParties(remotePartyList);
226 callHistoryItem->setStartTime(query_log->timestamp);
227 callHistoryItem->setDuration((unsigned long)(query_log->duration_sec));
228 callHistoryItem->setDirection(direction);
230 callEntries->insert(callEntries->end(), callHistoryItem);
235 void CallHistory::find(const EventFindCallHistoryPtr& event)
237 EventRequestReceiver<EventFindCallHistory>::PostRequest(event);
240 bool CallHistory::remove(const unsigned long entryId)
243 int ret = contacts_db_delete_record(_contacts_phone_log._uri, (int)entryId);
245 if (ret == CONTACTS_ERROR_NONE) {
250 } catch (const Commons::PlatformException& ex) {
251 ThrowMsg(Commons::PlatformException, ex.GetMessage());
255 void CallHistory::removeBatch(const EventRemoveBatchPtr& event)
257 EventRequestReceiver<EventRemoveBatch>::PostRequest(event);
260 void CallHistory::removeAll(const EventRemoveAllPtr& event)
262 EventRequestReceiver<EventRemoveAll>::PostRequest(event);
265 long CallHistory::addListener(const EventCallHistoryListenerEmitterPtr& emitter)
269 if (CallHistory::m_watchers.size() == 0) {
270 WatcherPtr watcher(new Watcher(0, emitter));
271 ret = contacts_db_add_changed_cb_with_info(_contacts_phone_log._uri, callhistoryListenerCB, watcher.Get());
273 watcher->setHandle(static_cast<long>(emitter->getId()));
274 CallHistory::m_watchers.push_back(watcher);
275 return watcher->getHandle();
281 void CallHistory::removeListener(const long id)
283 std::vector<CallHistory::WatcherPtr>::iterator it = CallHistory::m_watchers.begin();
285 int ret = CONTACTS_ERROR_NONE;
287 for (;it < CallHistory::m_watchers.end();) {
289 if (id == (*it)->getHandle()) {
291 ret = contacts_db_remove_changed_cb_with_info(_contacts_phone_log._uri, callhistoryListenerCB, it->Get());
293 if (ret != CONTACTS_ERROR_NONE) {
294 LoggerD("Failed removing listener");
297 it = CallHistory::m_watchers.erase(it);
304 ThrowMsg(Commons::InvalidArgumentException, "Invalid values");
308 bool CallHistory::parseRecord(contacts_list_h *recordList, CallHistoryEntryListPtr &callEntries)
310 int ret = CONTACTS_ERROR_NONE;
311 unsigned int total = 0;
312 contacts_record_h record = NULL;
313 callhistory_query_s query_data;
318 contacts_list_get_count(*recordList, &total);
320 for (i = 0; i < total; i++) {
321 ret = contacts_list_get_current_record_p(*recordList, &record);
323 if (record == NULL) {
324 ret = contacts_list_next(*recordList);
325 if (ret != CONTACTS_ERROR_NONE && ret != CONTACTS_ERROR_NO_DATA) {
326 LoggerD("Failed callhistory parser");
333 memset(&query_data, 0x00, sizeof(callhistory_query_s));
334 int validPersonId = 0;
336 if (ret == CONTACTS_ERROR_NONE) {
337 contacts_record_get_int(record, _contacts_phone_log.id, &(query_data.calllog_db_id));
338 contacts_record_get_int(record, _contacts_phone_log.log_type , &logType);
339 contacts_record_get_int(record, _contacts_phone_log.person_id, &(query_data.person_db_id));
340 contacts_record_get_str_p(record, _contacts_phone_log.address, &(query_data.phone_number));
343 validPersonId = updateValidPersonId(query_data.phone_number);
344 query_data.person_db_id = validPersonId;
346 contacts_record_get_int(record, _contacts_phone_log.log_time, &time);
347 contacts_record_get_int(record, _contacts_phone_log.extra_data1, &(query_data.duration_sec));
348 query_data.calllog_type = static_cast<contacts_phone_log_type_e>(logType);
349 query_data.timestamp = static_cast<time_t>(time);
350 convertCallHistory(&query_data, callEntries);
353 ret = contacts_list_next(*recordList);
354 if (ret != CONTACTS_ERROR_NONE && ret != CONTACTS_ERROR_NO_DATA) {
355 LoggerD("Failed callhistory parser");
364 int CallHistory::updateValidPersonId(char* phoneNum)
366 contacts_query_h query = NULL;
367 contacts_filter_h filter = NULL;
368 contacts_list_h recordList = NULL;
369 int ret = CONTACTS_ERROR_NONE;
371 contacts_query_create(_contacts_person_phone_log._uri, &query);
372 contacts_filter_create(_contacts_person_phone_log._uri, &filter);
373 contacts_filter_add_str(filter, _contacts_person_phone_log.address, CONTACTS_MATCH_EXACTLY, phoneNum);
375 contacts_query_set_filter(query, filter);
377 ret = contacts_db_get_records_with_query(query, 0, 1, &recordList);
378 if (ret != CONTACTS_ERROR_NONE) {
379 contacts_list_destroy(recordList, true);
380 contacts_query_destroy(query);
381 contacts_filter_destroy(filter);
382 LoggerD("Invalid callhistory query [" << ret << "]");
386 contacts_record_h record = NULL;
387 int validPersonId = 0;
389 ret = contacts_list_get_current_record_p(recordList, &record);
390 if (ret == CONTACTS_ERROR_NONE) {
391 contacts_record_get_int(record, _contacts_person_phone_log.person_id, &validPersonId);
394 contacts_list_destroy(recordList, true);
395 contacts_query_destroy(query);
396 contacts_filter_destroy(filter);
398 return validPersonId;
403 unsigned int CallHistory::convertAttrName(std::string &name)
405 std::string attrName("");
406 if (name.compare(STR_RP_REMOTEPARTY) == 0) {
407 return _contacts_phone_log.address;
408 } else if (name.compare(STR_START_TIME) == 0) {
409 return _contacts_phone_log.log_time;
410 } else if (name.compare(STR_DURATION) == 0) {
411 return _contacts_phone_log.extra_data1;
412 } else if (name.compare(STR_DIRECTION) == 0) {
413 return _contacts_phone_log.log_type;
414 } else if (name.compare(STR_ENTRY_ID) == 0) {
415 return _contacts_phone_log.id;
421 void CallHistory::OnRequestReceived(const EventCallHistoryPtr& event)
424 if (event->getCmdType() == EventCallHistory::CONNECT) {
425 if (contacts_connect2() == CONTACTS_ERROR_NONE) {
426 LoggerD("Successful to connect Call history DB by sub thread");
428 LoggerD("Failed to connect Call history DB by sub thread");
430 } else if (event->getCmdType() == EventCallHistory::DISCONNECT) {
431 if (contacts_disconnect2() == CONTACTS_ERROR_NONE) {
432 LoggerD("Successful to disconnect Call history DB by sub thread");
434 LoggerD("Failed to disconnect Call history DB by sub thread");
437 } catch (const Commons::PlatformException& ex) {
438 LoggerE("Exception: " << ex.GetMessage());
439 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
443 void CallHistory::OnRequestReceived(const EventFindCallHistoryPtr& event)
447 CallHistoryEntryListPtr callHistoryListPtr(new CallHistoryEntryList());
448 int ret = CONTACTS_ERROR_NONE;
450 contacts_query_h query = NULL;
451 contacts_filter_h filter = NULL;
452 contacts_list_h recordList = NULL;
453 bool isAscending = false;
457 contacts_query_create(_contacts_phone_log._uri, &query);
458 contacts_filter_create(_contacts_phone_log._uri, &filter);
460 CallHistoryFilterPtr filtering(new CallHistoryFilter(filter));
461 IFilterVisitorPtr filterTraversal = DPL::StaticPointerCast<IFilterVisitor>(filtering);
463 if (event->getFilterIsSet()) {
464 FilterPtr filterPtr = event->getFilter();
465 filterPtr->travel(filterTraversal, 0);
467 contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND);
468 contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_LESS_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
470 contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_LESS_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
472 contacts_query_set_filter(query, filter);
474 if (event->getSortModesIsSet()) {
475 if (event->getSortMode()->getOrder() == DeviceAPI::Tizen::ASCENDING_SORT_ORDER) {
480 std::string attriName(event->getSortMode()->getAttributeName());
481 ret = contacts_query_set_sort(query, convertAttrName(attriName), isAscending);
484 ret = contacts_query_set_sort(query, _contacts_phone_log.id, isAscending);
487 if (ret != CONTACTS_ERROR_NONE) {
488 LoggerD("callhistory invalid query statement");
492 if (event->getLimitIsSet()) {
493 limit = static_cast<int>(event->getLimit());
496 if (event->getOffsetIsSet()) {
497 offset = static_cast<int>(event->getOffset());
500 ret = contacts_db_get_records_with_query(query, offset, limit, &recordList);
502 if (ret != CONTACTS_ERROR_NONE) {
503 LoggerD("Invalid query statement");
506 if (parseRecord(&recordList, callHistoryListPtr)) {
507 event->setResult(callHistoryListPtr);
510 contacts_list_destroy(recordList, true);
511 contacts_query_destroy(query);
512 contacts_filter_destroy(filter);
513 } catch (const Commons::PlatformException& ex) {
514 LoggerE("Exception: " << ex.GetMessage());
515 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
519 void CallHistory::OnRequestReceived(const EventRemoveBatchPtr& event)
524 std::vector<unsigned long> entryIds = event->getEntryIds();
525 unsigned int cnt = 0;
526 int ret = CONTACTS_ERROR_NONE;
527 list = new int[entryIds.size()];
529 for (cnt = 0; cnt < entryIds.size(); cnt++) {
530 list[cnt] = static_cast<int>(entryIds[cnt]);
533 if (entryIds.size() > 0) {
534 EventRemoveBatchDataPtr eventData( new EventCallHistoryPtrs<EventRemoveBatch>(event, this));
536 JSCallbackManagerPtr data = DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
538 if (data->getOnSuccess() != NULL) {
539 ret = contacts_db_delete_records_async(_contacts_phone_log._uri, list, entryIds.size(), removeBatchCB, eventData.Get());
540 if (ret == CONTACTS_ERROR_NONE) {
541 m_removeBatchEvent.push_back(eventData);
542 event->switchToManualAnswer();
544 LoggerD("Failed callhistory remove Batch [" << ret << "]");
545 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
548 ret = contacts_db_delete_records(_contacts_phone_log._uri, list, entryIds.size());
549 if (ret != CONTACTS_ERROR_NONE) {
550 LoggerD("Failed callhistory remove Batch [" << ret << "]");
551 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
555 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
559 } catch (const Commons::PlatformException& ex) {
560 LoggerE("Exception: " << ex.GetMessage());
561 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
570 void CallHistory::OnRequestReceived(const EventRemoveAllPtr& event)
575 int ret = CONTACTS_ERROR_NONE;
576 contacts_list_h record_list = NULL;
577 contacts_record_h record = NULL;
578 unsigned int total = 0;
579 unsigned int cnt = 0;
582 ret = contacts_db_get_all_records(_contacts_phone_log._uri, 0, 0, &record_list);
584 if (record_list == NULL) {
585 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
589 contacts_list_get_count(record_list, &total);
591 list = new int[total];
592 for (unsigned int i = 0; i < total; i++) {
593 ret = contacts_list_get_current_record_p(record_list, &record);
595 if (record == NULL) {
596 ret = contacts_list_next(record_list);
597 if ( !(ret==CONTACTS_ERROR_NONE || ret==CONTACTS_ERROR_NO_DATA) ){
598 LoggerD("Failed callhistory remove all [" << ret << "]");
599 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
604 if (ret == CONTACTS_ERROR_NONE) {
605 ret = contacts_record_get_int(record, _contacts_phone_log.id , &value);
606 if (ret == CONTACTS_ERROR_NONE) {
612 ret = contacts_list_next(record_list);
613 if ( !(ret==CONTACTS_ERROR_NONE || ret==CONTACTS_ERROR_NO_DATA) ){
614 LoggerD("Failed callhistory remove all [" << ret << "]");
615 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
620 EventRemoveAllDataPtr eventData( new EventCallHistoryPtrs<EventRemoveAll>(event, this));
622 JSCallbackManagerPtr data = DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
624 if (data->getOnSuccess() != NULL) {
625 ret = contacts_db_delete_records_async(_contacts_phone_log._uri, list, cnt, removeAllCB, eventData.Get());
626 if (ret == CONTACTS_ERROR_NONE) {
627 m_removeAllEvent.push_back(eventData);
628 event->switchToManualAnswer();
630 LoggerD("Failed callhistory remove all [" << ret << "]");
631 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
634 ret = contacts_db_delete_records(_contacts_phone_log._uri, list, cnt);
635 if (ret != CONTACTS_ERROR_NONE) {
636 LoggerD("Failed callhistory remove all [" << ret << "]");
637 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
643 contacts_list_destroy(record_list, true);
644 } catch (const Commons::PlatformException& ex) {
645 LoggerE("Exception: " << ex.GetMessage());
646 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
655 void CallHistory::callRemoveBatchEvent(int error, const EventRemoveBatchPtr &event)
657 if (error != CONTACTS_ERROR_NONE) {
658 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
661 EventRequestReceiver<EventRemoveBatch>::ManualAnswer(event);
663 std::vector<EventRemoveBatchDataPtr>::iterator it;
664 for (it = m_removeBatchEvent.begin(); it != m_removeBatchEvent.end(); ++it) {
665 if ((*it)->getEventPtrs() == event) {
666 m_removeBatchEvent.erase(it);
672 void CallHistory::callRemoveAllEvent(int error, const EventRemoveAllPtr &event)
674 if (error != CONTACTS_ERROR_NONE) {
675 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
678 EventRequestReceiver<EventRemoveAll>::ManualAnswer(event);
680 std::vector<EventRemoveAllDataPtr>::iterator it;
681 for (it = m_removeAllEvent.begin(); it != m_removeAllEvent.end(); ++it) {
682 if ((*it)->getEventPtrs() == event) {
683 m_removeAllEvent.erase(it);
689 CallHistory::Watcher::Watcher(long handle, const EventCallHistoryListenerEmitterPtr& emitter) :
694 m_missedCallList = MissedCallListPtr(new MissedCallList());
695 if (contacts_connect2() == CONTACTS_ERROR_NONE) {
696 LoggerD("Successful to connect Call history DB ");
698 LoggerD("Failed to connect Call history DB ");
702 CallHistory::Watcher::~Watcher()
704 if (contacts_disconnect2() == CONTACTS_ERROR_NONE) {
705 LoggerD("Successful to disconnect Call history DB ");
707 LoggerD("Failed to disconnect Call history DB ");
711 void CallHistory::Watcher::stateHasChanged(CallHistoryEntryListPtr &entryList, EventCallHistoryListener::ResultStates state)
713 if (entryList == NULL)
718 EventCallHistoryListenerPtr event(new EventCallHistoryListener());
719 event->setResultState(state);
720 event->setResult(entryList);
721 m_emitter->emit(event);
724 void CallHistory::Watcher::stateHasRemoved(StringArrayPtr &entryList, EventCallHistoryListener::ResultStates state)
726 if (entryList == NULL)
731 EventCallHistoryListenerPtr event(new EventCallHistoryListener());
732 event->setResultState(state);
733 event->setRemoveResult(entryList);
734 m_emitter->emit(event);
738 bool CallHistory::Watcher::parseRecord(contacts_list_h *recordList, CallHistoryEntryListPtr &entryList)
740 CallHistory* callHistory = (CallHistory *) this;
741 if (callHistory != NULL) {
742 return callHistory->parseRecord(recordList, entryList);
747 bool CallHistory::Watcher::parseRemoveRecord(char* record, StringArrayPtr &removeRecords)
749 std::string recordStr(record);
750 removeRecords->push_back(recordStr);
755 void CallHistory::Watcher::ListenerCB(char* changes)
760 char* tokenType = NULL;
761 char* tokenId = NULL;
765 CallHistoryEntryListPtr callHistoryListPtr(new CallHistoryEntryList());
766 StringArrayPtr RemoveListPtr(new StringArray());
768 tokenType = strtok( changes, seps );
769 while( tokenType != NULL )
771 tokenId = strtok( NULL, seps );
772 changeType = atoi((const char*)tokenType);
773 changeId = atoi((const char*)tokenId);
776 contacts_query_h query = NULL;
777 contacts_filter_h filter = NULL;
778 contacts_list_h recordList = NULL;
779 int ret = CONTACTS_ERROR_NONE;
781 contacts_query_create(_contacts_phone_log._uri, &query);
782 contacts_filter_create(_contacts_phone_log._uri, &filter);
783 contacts_filter_add_int(filter, _contacts_phone_log.id, CONTACTS_MATCH_EQUAL, changeId );
785 contacts_query_set_filter(query, filter);
787 ret = contacts_query_set_sort(query, _contacts_phone_log.id, false);
788 if (ret != CONTACTS_ERROR_NONE) {
789 LoggerD("Invalid callhistory query [" << ret << "]");
792 ret = contacts_db_get_records_with_query(query, 0, 1, &recordList);
793 if (ret != CONTACTS_ERROR_NONE) {
794 contacts_list_destroy(recordList, true);
795 contacts_query_destroy(query);
796 contacts_filter_destroy(filter);
797 LoggerD("Invalid callhistory query [" << ret << "]");
801 if((changeType == CONTACTS_CHANGE_INSERTED)||(changeType == CONTACTS_CHANGE_UPDATED)){
802 if (parseRecord(&recordList, callHistoryListPtr)) {
803 if (callHistoryListPtr->size() > 0) {
804 setCurrentLogId((*callHistoryListPtr)[0]->getEntryId());
807 }else if(changeType == CONTACTS_CHANGE_DELETED){
808 parseRemoveRecord(tokenId, RemoveListPtr);
811 contacts_list_destroy(recordList, true);
812 contacts_query_destroy(query);
813 contacts_filter_destroy(filter);
815 tokenType = strtok( NULL, seps );
819 if((changeType == CONTACTS_CHANGE_INSERTED)||(changeType == CONTACTS_CHANGE_UPDATED)){
820 if (callHistoryListPtr->size() > 0) {
821 setCurrentLogId((*callHistoryListPtr)[0]->getEntryId());
823 if(changeType == CONTACTS_CHANGE_INSERTED){
824 stateHasChanged(callHistoryListPtr, EventCallHistoryListener::ADDED);
825 }else if(changeType == CONTACTS_CHANGE_UPDATED){
826 stateHasChanged(callHistoryListPtr, EventCallHistoryListener::CHANGED);
830 }else if(changeType == CONTACTS_CHANGE_DELETED){
831 stateHasRemoved(RemoveListPtr, EventCallHistoryListener::REMOVED);