Update wrt-plugins-common_0.3.53
[framework/web/wrt-plugins-common.git] / src / modules / tizen / DEPRACATED / Telephony / LogEntryWrapper.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file        LogEntryWrapper.cpp
18  * @author      Lukasz Marek (l.marek@samsung.com)
19  * @version     0.2
20  */
21
22 #include <string>
23 #include <dpl/log/log.h>
24 #include <pcrecpp.h>
25 #include "LogEntryWrapper.h"
26 #include "commons/Exception.h"
27
28 using namespace WrtPlugins::Api;
29
30 namespace WrtPlugins {
31 namespace Platform {
32 LogEntryWrapper::LogEntryWrapper(CTSvalue *log) :
33     m_logEntry(new LogEntry())
34 {
35     LogDebug("entered");
36     convertPlatformStructToAbstractStruct(log);
37 }
38
39 LogEntryWrapper::~LogEntryWrapper()
40 {
41     LogDebug("entered");
42 }
43
44 bool LogEntryWrapper::matchFilters(const LogFilterPtr &filter)
45 {
46     LogDebug("entered");
47     if (!m_logEntry) {
48         Throw(WrtPlugins::Commons::NullPointerException);
49     }
50     if (!filter) {
51         return true;
52     }
53     if (filter->getIdIsSet() && filter->getIdFilter() != m_logEntry->getId()) {
54         return false;
55     }
56     if (filter->getStartTimeIsSet() &&
57         (filter->getStartTimeMinFilter() > m_logEntry->getStartTime() ||
58          filter->getStartTimeMaxFilter() < m_logEntry->getStartTime())) {
59         return false;
60     }
61     if (filter->getDurationIsSet() &&
62         (filter->getDurationMinFilter() > m_logEntry->getDuration() ||
63          filter->getDurationMaxFilter() < m_logEntry->getDuration())) {
64         return false;
65     }
66     if (filter->getPhoneNumberIsSet() &&
67         !pcrecpp::RE(filter->getPhoneNumberFilter()).FullMatch(m_logEntry->
68                                                                    getPhoneNumber()))
69     {
70         return false;
71     }
72     if (filter->getDescriptionIsSet() &&
73         !pcrecpp::RE(filter->getDescriptionFilter()).FullMatch(m_logEntry->
74                                                                    getDescription()))
75     {
76         return false;
77     }
78     if (filter->getFolderIsSet() &&
79         !filter->checkIfFolderIsSet(m_logEntry->getFolder())) {
80         return false;
81     } else if (m_logEntry->getFolder() == LogEntry::INVALID_FOLDER) {
82         return false;
83     }
84     return true;
85 }
86
87 bool LogEntryWrapper::convertPlatformStructToAbstractStruct(CTSvalue *log)
88 {
89     LogDebug("entered");
90     if (!m_logEntry) {
91         return false;
92     }
93     if (!log) {
94         return true;
95     }
96     const char *charVal =
97         contacts_svc_value_get_str(log, CTS_LIST_PLOG_NUMBER_STR);
98     if (charVal) {
99         LogDebug("phone number " << charVal);
100         m_logEntry->setPhoneNumber(charVal);
101     }
102     charVal = contacts_svc_value_get_str(log, CTS_LIST_PLOG_SHORTMSG_STR);
103     if (charVal) {
104         m_logEntry->setDescription(charVal);
105     }
106     m_logEntry->setDuration(
107         contacts_svc_value_get_int(log, CTS_LIST_PLOG_DURATION_INT));
108     LogDebug("id " <<
109              contacts_svc_value_get_int(log, CTS_LIST_PLOG_DURATION_INT));
110     m_logEntry->setStartTime(
111         contacts_svc_value_get_int(log, CTS_LIST_PLOG_LOG_TIME_INT));
112     m_logEntry->setId(
113         contacts_svc_value_get_int(log, CTS_LIST_PLOG_ID_INT));
114     LogDebug("id " << contacts_svc_value_get_int(log, CTS_LIST_PLOG_ID_INT));
115     switch (contacts_svc_value_get_int(log, CTS_LIST_PLOG_LOG_TYPE_INT)) {
116     case CTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN:
117     case CTS_PLOG_TYPE_VOICE_INCOMMING_SEEN:
118     case CTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN:
119     case CTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN:
120         m_logEntry->setFolder(LogEntry::MISSED_CALLS_FOLDER);
121         break;
122     case CTS_PLOG_TYPE_VIDEO_INCOMMING:
123     case CTS_PLOG_TYPE_VOICE_INCOMMING:
124         m_logEntry->setFolder(LogEntry::RECEIVED_CALLS_FOLDER);
125         break;
126     case CTS_PLOG_TYPE_VIDEO_OUTGOING:
127     case CTS_PLOG_TYPE_VOICE_OUTGOING:
128         m_logEntry->setFolder(LogEntry::INITIATED_CALLS_FOLDER);
129         break;
130     default:
131         LogDebug("Invalid folder");
132         m_logEntry->setFolder(LogEntry::INVALID_FOLDER);
133         break;
134     }
135     return true;
136 }
137
138 Api::LogEntryPtr LogEntryWrapper::getAbstractCall() const
139 {
140     return m_logEntry;
141 }
142 }
143 }