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"
24 #include <Commons/Exception.h>
25 #include <CommonsJavaScript/JSCallbackManager.h>
26 #include <dpl/shared_ptr.h>
30 #include <IFilterVisitor.h>
31 #include "CallHistoryDefine.h"
33 #include "CallHistoryFilter.h"
35 using namespace DeviceAPI::Tizen;
36 using namespace WrtDeviceApis;
37 using namespace WrtDeviceApis::Commons;
38 using namespace WrtDeviceApis::CommonsJavaScript;
42 namespace CallHistory {
44 std::vector<CallHistory::WatcherPtr> CallHistory::m_watchers;
46 CallHistory::CallHistory()
49 if (contacts_connect2() == CONTACTS_ERROR_NONE) {
50 LoggerD("Successful to connect Call history DB ");
52 LoggerD("Failed to connect Call history DB ");
55 EventCallHistoryPtr event(new EventCallHistory());
56 event->setCmdType(EventCallHistory::CONNECT);
57 event->setForSynchronousCall();
58 EventRequestReceiver<EventCallHistory>::PostRequest(event);
61 CallHistory::~CallHistory()
65 if (contacts_disconnect2() == CONTACTS_ERROR_NONE) {
66 LoggerD("Successful to disconnect Call history DB ");
68 LoggerD("Failed to disconnect Call history DB ");
71 int ret = CONTACTS_ERROR_NONE;
72 std::vector<CallHistory::WatcherPtr>::iterator it = CallHistory::m_watchers.begin();
74 if (m_watchers.size() > 0) {
75 for (;it < CallHistory::m_watchers.end();) {
76 ret = contacts_db_remove_changed_cb_with_info(_contacts_phone_log._uri, callhistoryListenerCB, it->Get());
78 if (ret != CONTACTS_ERROR_NONE) {
79 LoggerD("Failed removing listener");
82 it = CallHistory::m_watchers.erase(it);
86 EventCallHistoryPtr event(new EventCallHistory());
87 event->setCmdType(EventCallHistory::DISCONNECT);
88 event->setForSynchronousCall();
89 EventRequestReceiver<EventCallHistory>::PostRequest(event);
92 void CallHistory::callhistoryListenerCB(const char* view_uri, char *changes, void* user_data)
95 if (user_data != NULL) {
96 ((CallHistory::Watcher*)user_data)->ListenerCB(changes);
100 void CallHistory::removeBatchCB(int error, void *user_data)
103 if (user_data != NULL) {
104 CallHistory* chManager = (CallHistory *)((EventCallHistoryPtrs<EventRemoveBatch> *)user_data)->getThisPtr();
107 EventRemoveBatchPtr event = ((EventCallHistoryPtrs<EventRemoveBatch> *)user_data)->getEventPtrs();
108 chManager->callRemoveBatchEvent(error, event);
114 void CallHistory::removeAllCB(int error, void *user_data)
117 if (user_data != NULL) {
118 CallHistory* chManager = (CallHistory *)((EventCallHistoryPtrs<EventRemoveAll> *)user_data)->getThisPtr();
121 EventRemoveAllPtr event = ((EventCallHistoryPtrs<EventRemoveAll> *)user_data)->getEventPtrs();
122 chManager->callRemoveAllEvent(error, event);
128 bool CallHistory::convertCallHistory(callhistory_query_s *query_log, CallHistoryEntryListPtr &callEntries)
130 if (query_log == NULL || callEntries == NULL)
133 CallHistoryEntryPropertiesPtr callHistoryItem(new CallHistoryEntryProperties());
134 StringArrayPtr stringArray(new StringArray());
135 RemotePartyPtr remoteParty(new RemoteParty());
136 RemotePartyListPtr remotePartyList(new RemotePartyList());
138 std::string callType("");
139 std::string tags("");
140 std::string direction("");
141 std::string number("");
143 if (query_log->phone_number != NULL) {
144 number.append(query_log->phone_number);
147 switch(query_log->calllog_type) {
148 case CONTACTS_PLOG_TYPE_VOICE_INCOMMING:
149 callType.append(STR_TIZEN_TEL);
150 tags.append(STR_CALL_VOICE);
151 direction.append(STR_RECEIVED);
153 case CONTACTS_PLOG_TYPE_VOICE_OUTGOING:
154 callType.append(STR_TIZEN_TEL);
155 tags.append(STR_CALL_VOICE);
156 direction.append(STR_DIALED);
158 case CONTACTS_PLOG_TYPE_VOICE_INCOMMING_SEEN:
159 callType.append(STR_TIZEN_TEL);
160 tags.append(STR_CALL_VOICE);
161 direction.append(STR_MISSED);
163 case CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN:
164 callType.append(STR_TIZEN_TEL);
165 tags.append(STR_CALL_VOICE);
166 direction.append(STR_MISSED_NEW);
168 case CONTACTS_PLOG_TYPE_VOICE_REJECT:
169 callType.append(STR_TIZEN_TEL);
170 tags.append(STR_CALL_VOICE);
171 direction.append(STR_REJECTED);
173 case CONTACTS_PLOG_TYPE_VOICE_BLOCKED:
174 callType.append(STR_TIZEN_TEL);
175 tags.append(STR_CALL_VOICE);
176 direction.append(STR_BLOCKED);
178 case CONTACTS_PLOG_TYPE_VIDEO_INCOMMING:
179 callType.append(STR_TIZEN_TEL);
180 tags.append(STR_CALL_VIDEO);
181 direction.append(STR_RECEIVED);
183 case CONTACTS_PLOG_TYPE_VIDEO_OUTGOING:
184 callType.append(STR_TIZEN_TEL);
185 tags.append(STR_CALL_VIDEO);
186 direction.append(STR_DIALED);
188 case CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN:
189 callType.append(STR_TIZEN_TEL);
190 tags.append(STR_CALL_VIDEO);
191 direction.append(STR_MISSED);
193 case CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN:
194 callType.append(STR_TIZEN_TEL);
195 tags.append(STR_CALL_VIDEO);
196 direction.append(STR_MISSED_NEW);
198 case CONTACTS_PLOG_TYPE_VIDEO_REJECT:
199 callType.append(STR_TIZEN_TEL);
200 tags.append(STR_CALL_VIDEO);
201 direction.append(STR_REJECTED);
203 case CONTACTS_PLOG_TYPE_VIDEO_BLOCKED:
204 callType.append(STR_TIZEN_TEL);
205 tags.append(STR_CALL_VIDEO);
206 direction.append(STR_BLOCKED);
212 callHistoryItem->setEntryId(query_log->calllog_db_id);
213 callHistoryItem->setCallType(callType);
214 stringArray->push_back(tags);
215 callHistoryItem->setTags(stringArray);
217 remoteParty->setRemoteParty(number);
218 std::stringstream personIdStream;
219 personIdStream << query_log->person_db_id;
220 remoteParty->setPersonId(personIdStream.str());
222 remotePartyList->push_back(remoteParty);
223 callHistoryItem->setRemoteParties(remotePartyList);
225 callHistoryItem->setStartTime(query_log->timestamp);
226 callHistoryItem->setDuration((unsigned long)(query_log->duration_sec));
227 callHistoryItem->setDirection(direction);
229 callEntries->insert(callEntries->end(), callHistoryItem);
234 void CallHistory::find(const EventFindCallHistoryPtr& event)
236 EventRequestReceiver<EventFindCallHistory>::PostRequest(event);
239 bool CallHistory::remove(const unsigned long entryId)
242 int ret = contacts_db_delete_record(_contacts_phone_log._uri, (int)entryId);
244 if (ret == CONTACTS_ERROR_NONE) {
249 } catch (const Commons::PlatformException& ex) {
250 ThrowMsg(Commons::PlatformException, ex.GetMessage());
254 void CallHistory::removeBatch(const EventRemoveBatchPtr& event)
256 EventRequestReceiver<EventRemoveBatch>::PostRequest(event);
259 void CallHistory::removeAll(const EventRemoveAllPtr& event)
261 EventRequestReceiver<EventRemoveAll>::PostRequest(event);
264 long CallHistory::addListener(const EventCallHistoryListenerEmitterPtr& emitter)
268 if (CallHistory::m_watchers.size() == 0) {
269 WatcherPtr watcher(new Watcher(0, emitter));
270 ret = contacts_db_add_changed_cb_with_info(_contacts_phone_log._uri, callhistoryListenerCB, watcher.Get());
272 watcher->setHandle(static_cast<long>(emitter->getId()));
273 CallHistory::m_watchers.push_back(watcher);
274 return watcher->getHandle();
280 void CallHistory::removeListener(const long id)
282 std::vector<CallHistory::WatcherPtr>::iterator it = CallHistory::m_watchers.begin();
284 int ret = CONTACTS_ERROR_NONE;
286 for (;it < CallHistory::m_watchers.end();) {
288 if (id == (*it)->getHandle()) {
290 ret = contacts_db_remove_changed_cb_with_info(_contacts_phone_log._uri, callhistoryListenerCB, it->Get());
292 if (ret != CONTACTS_ERROR_NONE) {
293 LoggerD("Failed removing listener");
296 it = CallHistory::m_watchers.erase(it);
303 ThrowMsg(Commons::InvalidArgumentException, "Invalid values");
307 bool CallHistory::parseRecord(contacts_list_h *recordList, CallHistoryEntryListPtr &callEntries)
309 int ret = CONTACTS_ERROR_NONE;
310 unsigned int total = 0;
311 contacts_record_h record = NULL;
312 callhistory_query_s query_data;
317 contacts_list_get_count(*recordList, &total);
319 for (i = 0; i < total; i++) {
320 ret = contacts_list_get_current_record_p(*recordList, &record);
322 if (record == NULL) {
323 ret = contacts_list_next(*recordList);
324 if (ret != CONTACTS_ERROR_NONE && ret != CONTACTS_ERROR_NO_DATA) {
325 LoggerD("Failed callhistory parser");
332 memset(&query_data, 0x00, sizeof(callhistory_query_s));
333 int validPersonId = 0;
335 if (ret == CONTACTS_ERROR_NONE) {
336 contacts_record_get_int(record, _contacts_phone_log.id, &(query_data.calllog_db_id));
337 contacts_record_get_int(record, _contacts_phone_log.log_type , &logType);
338 contacts_record_get_int(record, _contacts_phone_log.person_id, &(query_data.person_db_id));
339 contacts_record_get_str_p(record, _contacts_phone_log.address, &(query_data.phone_number));
342 validPersonId = updateValidPersonId(query_data.phone_number);
343 query_data.person_db_id = validPersonId;
345 contacts_record_get_int(record, _contacts_phone_log.log_time, &time);
346 contacts_record_get_int(record, _contacts_phone_log.extra_data1, &(query_data.duration_sec));
347 query_data.calllog_type = static_cast<contacts_phone_log_type_e>(logType);
348 query_data.timestamp = static_cast<time_t>(time);
349 convertCallHistory(&query_data, callEntries);
352 ret = contacts_list_next(*recordList);
353 if (ret != CONTACTS_ERROR_NONE && ret != CONTACTS_ERROR_NO_DATA) {
354 LoggerD("Failed callhistory parser");
363 int CallHistory::updateValidPersonId(char* phoneNum)
365 contacts_query_h query = NULL;
366 contacts_filter_h filter = NULL;
367 contacts_list_h recordList = NULL;
368 int ret = CONTACTS_ERROR_NONE;
370 contacts_query_create(_contacts_person_phone_log._uri, &query);
371 contacts_filter_create(_contacts_person_phone_log._uri, &filter);
372 contacts_filter_add_str(filter, _contacts_person_phone_log.address, CONTACTS_MATCH_EXACTLY, phoneNum);
374 contacts_query_set_filter(query, filter);
376 ret = contacts_db_get_records_with_query(query, 0, 1, &recordList);
377 if (ret != CONTACTS_ERROR_NONE) {
378 contacts_list_destroy(recordList, true);
379 contacts_query_destroy(query);
380 contacts_filter_destroy(filter);
381 LoggerD("Invalid callhistory query [" << ret << "]");
385 contacts_record_h record = NULL;
386 int validPersonId = 0;
388 ret = contacts_list_get_current_record_p(recordList, &record);
389 if (ret == CONTACTS_ERROR_NONE) {
390 contacts_record_get_int(record, _contacts_person_phone_log.person_id, &validPersonId);
393 contacts_list_destroy(recordList, true);
394 contacts_query_destroy(query);
395 contacts_filter_destroy(filter);
397 return validPersonId;
402 unsigned int CallHistory::convertAttrName(std::string &name)
404 std::string attrName("");
405 if (name.compare(STR_RP_REMOTEPARTY) == 0) {
406 return _contacts_phone_log.address;
407 } else if (name.compare(STR_START_TIME) == 0) {
408 return _contacts_phone_log.log_time;
409 } else if (name.compare(STR_DURATION) == 0) {
410 return _contacts_phone_log.extra_data1;
411 } else if (name.compare(STR_DIRECTION) == 0) {
412 return _contacts_phone_log.log_type;
413 } else if (name.compare(STR_ENTRY_ID) == 0) {
414 return _contacts_phone_log.id;
420 void CallHistory::OnRequestReceived(const EventCallHistoryPtr& event)
423 if (event->getCmdType() == EventCallHistory::CONNECT) {
424 if (contacts_connect2() == CONTACTS_ERROR_NONE) {
425 LoggerD("Successful to connect Call history DB by sub thread");
427 LoggerD("Failed to connect Call history DB by sub thread");
429 } else if (event->getCmdType() == EventCallHistory::DISCONNECT) {
430 if (contacts_disconnect2() == CONTACTS_ERROR_NONE) {
431 LoggerD("Successful to disconnect Call history DB by sub thread");
433 LoggerD("Failed to disconnect Call history DB by sub thread");
436 } catch (const Commons::PlatformException& ex) {
437 LoggerE("Exception: " << ex.GetMessage());
438 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
442 void CallHistory::OnRequestReceived(const EventFindCallHistoryPtr& event)
446 CallHistoryEntryListPtr callHistoryListPtr(new CallHistoryEntryList());
447 int ret = CONTACTS_ERROR_NONE;
449 contacts_query_h query = NULL;
450 contacts_filter_h filter = NULL;
451 contacts_list_h recordList = NULL;
452 bool isAscending = false;
456 contacts_query_create(_contacts_phone_log._uri, &query);
457 contacts_filter_create(_contacts_phone_log._uri, &filter);
459 CallHistoryFilterPtr filtering(new CallHistoryFilter(filter));
460 IFilterVisitorPtr filterTraversal = DPL::StaticPointerCast<IFilterVisitor>(filtering);
462 if (event->getFilterIsSet()) {
463 FilterPtr filterPtr = event->getFilter();
464 filterPtr->travel(filterTraversal, 0);
466 contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND);
467 contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_LESS_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
469 contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_LESS_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED);
471 contacts_query_set_filter(query, filter);
473 if (event->getSortModesIsSet()) {
474 if (event->getSortMode()->getOrder() == DeviceAPI::Tizen::ASCENDING_SORT_ORDER) {
479 std::string attriName(event->getSortMode()->getAttributeName());
480 ret = contacts_query_set_sort(query, convertAttrName(attriName), isAscending);
483 ret = contacts_query_set_sort(query, _contacts_phone_log.id, isAscending);
486 if (ret != CONTACTS_ERROR_NONE) {
487 LoggerD("callhistory invalid query statement");
491 if (event->getLimitIsSet()) {
492 limit = static_cast<int>(event->getLimit());
495 if (event->getOffsetIsSet()) {
496 offset = static_cast<int>(event->getOffset());
499 ret = contacts_db_get_records_with_query(query, offset, limit, &recordList);
501 if (ret != CONTACTS_ERROR_NONE) {
502 LoggerD("Invalid query statement");
505 if (parseRecord(&recordList, callHistoryListPtr)) {
506 event->setResult(callHistoryListPtr);
509 contacts_list_destroy(recordList, true);
510 contacts_query_destroy(query);
511 contacts_filter_destroy(filter);
512 } catch (const Commons::PlatformException& ex) {
513 LoggerE("Exception: " << ex.GetMessage());
514 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
518 void CallHistory::OnRequestReceived(const EventRemoveBatchPtr& event)
523 std::vector<unsigned long> entryIds = event->getEntryIds();
524 unsigned int cnt = 0;
525 int ret = CONTACTS_ERROR_NONE;
526 list = new int[entryIds.size()];
528 for (cnt = 0; cnt < entryIds.size(); cnt++) {
529 list[cnt] = static_cast<int>(entryIds[cnt]);
532 if (entryIds.size() > 0) {
533 EventRemoveBatchDataPtr eventData( new EventCallHistoryPtrs<EventRemoveBatch>(event, this));
535 JSCallbackManagerPtr data = DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
537 if (data->getOnSuccess() != NULL) {
538 ret = contacts_db_delete_records_async(_contacts_phone_log._uri, list, entryIds.size(), removeBatchCB, eventData.Get());
539 if (ret == CONTACTS_ERROR_NONE) {
540 m_removeBatchEvent.push_back(eventData);
541 event->switchToManualAnswer();
543 LoggerD("Failed callhistory remove Batch [" << ret << "]");
544 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
547 ret = contacts_db_delete_records(_contacts_phone_log._uri, list, entryIds.size());
548 if (ret != CONTACTS_ERROR_NONE) {
549 LoggerD("Failed callhistory remove Batch [" << ret << "]");
550 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
554 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
558 } catch (const Commons::PlatformException& ex) {
559 LoggerE("Exception: " << ex.GetMessage());
560 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
569 void CallHistory::OnRequestReceived(const EventRemoveAllPtr& event)
574 int ret = CONTACTS_ERROR_NONE;
575 contacts_list_h record_list = NULL;
576 contacts_record_h record = NULL;
577 unsigned int total = 0;
578 unsigned int cnt = 0;
581 ret = contacts_db_get_all_records(_contacts_phone_log._uri, 0, 0, &record_list);
583 if (record_list == NULL) {
584 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
588 contacts_list_get_count(record_list, &total);
590 list = new int[total];
591 for (unsigned int i = 0; i < total; i++) {
592 ret = contacts_list_get_current_record_p(record_list, &record);
594 if (record == NULL) {
595 ret = contacts_list_next(record_list);
596 if ( !(ret==CONTACTS_ERROR_NONE || ret==CONTACTS_ERROR_NO_DATA) ){
597 LoggerD("Failed callhistory remove all [" << ret << "]");
598 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
603 if (ret == CONTACTS_ERROR_NONE) {
604 ret = contacts_record_get_int(record, _contacts_phone_log.id , &value);
605 if (ret == CONTACTS_ERROR_NONE) {
611 ret = contacts_list_next(record_list);
612 if ( !(ret==CONTACTS_ERROR_NONE || ret==CONTACTS_ERROR_NO_DATA) ){
613 LoggerD("Failed callhistory remove all [" << ret << "]");
614 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
619 EventRemoveAllDataPtr eventData( new EventCallHistoryPtrs<EventRemoveAll>(event, this));
621 JSCallbackManagerPtr data = DPL::DynamicPointerCast<JSCallbackManager>(event->getPrivateData());
623 if (data->getOnSuccess() != NULL) {
624 ret = contacts_db_delete_records_async(_contacts_phone_log._uri, list, cnt, removeAllCB, eventData.Get());
625 if (ret == CONTACTS_ERROR_NONE) {
626 m_removeAllEvent.push_back(eventData);
627 event->switchToManualAnswer();
629 LoggerD("Failed callhistory remove all [" << ret << "]");
630 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
633 ret = contacts_db_delete_records(_contacts_phone_log._uri, list, cnt);
634 if (ret != CONTACTS_ERROR_NONE) {
635 LoggerD("Failed callhistory remove all [" << ret << "]");
636 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
642 contacts_list_destroy(record_list, true);
643 } catch (const Commons::PlatformException& ex) {
644 LoggerE("Exception: " << ex.GetMessage());
645 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
654 void CallHistory::callRemoveBatchEvent(int error, const EventRemoveBatchPtr &event)
656 if (error != CONTACTS_ERROR_NONE) {
657 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
660 EventRequestReceiver<EventRemoveBatch>::ManualAnswer(event);
662 std::vector<EventRemoveBatchDataPtr>::iterator it;
663 for (it = m_removeBatchEvent.begin(); it != m_removeBatchEvent.end(); ++it) {
664 if ((*it)->getEventPtrs() == event) {
665 m_removeBatchEvent.erase(it);
671 void CallHistory::callRemoveAllEvent(int error, const EventRemoveAllPtr &event)
673 if (error != CONTACTS_ERROR_NONE) {
674 event->setExceptionCode(Commons::ExceptionCodes::PlatformException);
677 EventRequestReceiver<EventRemoveAll>::ManualAnswer(event);
679 std::vector<EventRemoveAllDataPtr>::iterator it;
680 for (it = m_removeAllEvent.begin(); it != m_removeAllEvent.end(); ++it) {
681 if ((*it)->getEventPtrs() == event) {
682 m_removeAllEvent.erase(it);
688 CallHistory::Watcher::Watcher(long handle, const EventCallHistoryListenerEmitterPtr& emitter) :
693 m_missedCallList = MissedCallListPtr(new MissedCallList());
694 if (contacts_connect2() == CONTACTS_ERROR_NONE) {
695 LoggerD("Successful to connect Call history DB ");
697 LoggerD("Failed to connect Call history DB ");
701 CallHistory::Watcher::~Watcher()
703 if (contacts_disconnect2() == CONTACTS_ERROR_NONE) {
704 LoggerD("Successful to disconnect Call history DB ");
706 LoggerD("Failed to disconnect Call history DB ");
710 void CallHistory::Watcher::stateHasChanged(CallHistoryEntryListPtr &entryList, EventCallHistoryListener::ResultStates state)
712 if (entryList == NULL)
717 EventCallHistoryListenerPtr event(new EventCallHistoryListener());
718 event->setResultState(state);
719 event->setResult(entryList);
720 m_emitter->emit(event);
723 void CallHistory::Watcher::stateHasRemoved(StringArrayPtr &entryList, EventCallHistoryListener::ResultStates state)
725 if (entryList == NULL)
730 EventCallHistoryListenerPtr event(new EventCallHistoryListener());
731 event->setResultState(state);
732 event->setRemoveResult(entryList);
733 m_emitter->emit(event);
737 bool CallHistory::Watcher::parseRecord(contacts_list_h *recordList, CallHistoryEntryListPtr &entryList)
739 CallHistory* callHistory = (CallHistory *) this;
740 if (callHistory != NULL) {
741 return callHistory->parseRecord(recordList, entryList);
746 bool CallHistory::Watcher::parseRemoveRecord(char* record, StringArrayPtr &removeRecords)
748 std::string recordStr(record);
749 removeRecords->push_back(recordStr);
754 void CallHistory::Watcher::ListenerCB(char* changes)
759 char* tokenType = NULL;
760 char* tokenId = NULL;
764 CallHistoryEntryListPtr callHistoryListPtr(new CallHistoryEntryList());
765 StringArrayPtr RemoveListPtr(new StringArray());
767 tokenType = strtok( changes, seps );
768 while( tokenType != NULL )
770 tokenId = strtok( NULL, seps );
773 changeType = atoi((const char*)tokenType);
775 changeId = atoi((const char*)tokenId);
778 contacts_query_h query = NULL;
779 contacts_filter_h filter = NULL;
780 contacts_list_h recordList = NULL;
781 int ret = CONTACTS_ERROR_NONE;
783 contacts_query_create(_contacts_phone_log._uri, &query);
784 contacts_filter_create(_contacts_phone_log._uri, &filter);
785 contacts_filter_add_int(filter, _contacts_phone_log.id, CONTACTS_MATCH_EQUAL, changeId );
787 contacts_query_set_filter(query, filter);
789 ret = contacts_query_set_sort(query, _contacts_phone_log.id, false);
790 if (ret != CONTACTS_ERROR_NONE) {
791 LoggerD("Invalid callhistory query [" << ret << "]");
794 ret = contacts_db_get_records_with_query(query, 0, 1, &recordList);
795 if (ret != CONTACTS_ERROR_NONE) {
796 contacts_list_destroy(recordList, true);
797 contacts_query_destroy(query);
798 contacts_filter_destroy(filter);
799 LoggerD("Invalid callhistory query [" << ret << "]");
803 if((changeType == CONTACTS_CHANGE_INSERTED)||(changeType == CONTACTS_CHANGE_UPDATED)){
804 if (parseRecord(&recordList, callHistoryListPtr)) {
805 if (callHistoryListPtr->size() > 0) {
806 setCurrentLogId((*callHistoryListPtr)[0]->getEntryId());
809 }else if(changeType == CONTACTS_CHANGE_DELETED){
810 parseRemoveRecord(tokenId, RemoveListPtr);
813 contacts_list_destroy(recordList, true);
814 contacts_query_destroy(query);
815 contacts_filter_destroy(filter);
817 tokenType = strtok( NULL, seps );
821 if((changeType == CONTACTS_CHANGE_INSERTED)||(changeType == CONTACTS_CHANGE_UPDATED)){
822 if (callHistoryListPtr->size() > 0) {
823 setCurrentLogId((*callHistoryListPtr)[0]->getEntryId());
825 if(changeType == CONTACTS_CHANGE_INSERTED){
826 stateHasChanged(callHistoryListPtr, EventCallHistoryListener::ADDED);
827 }else if(changeType == CONTACTS_CHANGE_UPDATED){
828 stateHasChanged(callHistoryListPtr, EventCallHistoryListener::CHANGED);
832 }else if(changeType == CONTACTS_CHANGE_DELETED){
833 stateHasRemoved(RemoveListPtr, EventCallHistoryListener::REMOVED);