[Release] wrt-plugins-common_0.3.74
[platform/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     {
60         return false;
61     }
62     if (filter->getDurationIsSet() &&
63         (filter->getDurationMinFilter() > m_logEntry->getDuration() ||
64          filter->getDurationMaxFilter() < m_logEntry->getDuration()))
65     {
66         return false;
67     }
68     if (filter->getPhoneNumberIsSet() &&
69         !pcrecpp::RE(filter->getPhoneNumberFilter()).FullMatch(m_logEntry->
70                                                                    getPhoneNumber()))
71     {
72         return false;
73     }
74     if (filter->getDescriptionIsSet() &&
75         !pcrecpp::RE(filter->getDescriptionFilter()).FullMatch(m_logEntry->
76                                                                    getDescription()))
77     {
78         return false;
79     }
80     if (filter->getFolderIsSet() &&
81         !filter->checkIfFolderIsSet(m_logEntry->getFolder()))
82     {
83         return false;
84     } else if (m_logEntry->getFolder() == LogEntry::INVALID_FOLDER) {
85         return false;
86     }
87     return true;
88 }
89
90 bool LogEntryWrapper::convertPlatformStructToAbstractStruct(CTSvalue *log)
91 {
92     LogDebug("entered");
93     if (!m_logEntry) {
94         return false;
95     }
96     if (!log) {
97         return true;
98     }
99     const char *charVal =
100         contacts_svc_value_get_str(log, CTS_LIST_PLOG_NUMBER_STR);
101     if (charVal) {
102         LogDebug("phone number " << charVal);
103         m_logEntry->setPhoneNumber(charVal);
104     }
105     charVal = contacts_svc_value_get_str(log, CTS_LIST_PLOG_SHORTMSG_STR);
106     if (charVal) {
107         m_logEntry->setDescription(charVal);
108     }
109     m_logEntry->setDuration(
110         contacts_svc_value_get_int(log, CTS_LIST_PLOG_DURATION_INT));
111     LogDebug("id " <<
112              contacts_svc_value_get_int(log, CTS_LIST_PLOG_DURATION_INT));
113     m_logEntry->setStartTime(
114         contacts_svc_value_get_int(log, CTS_LIST_PLOG_LOG_TIME_INT));
115     m_logEntry->setId(
116         contacts_svc_value_get_int(log, CTS_LIST_PLOG_ID_INT));
117     LogDebug("id " << contacts_svc_value_get_int(log, CTS_LIST_PLOG_ID_INT));
118     switch (contacts_svc_value_get_int(log, CTS_LIST_PLOG_LOG_TYPE_INT)) {
119     case CTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN:
120     case CTS_PLOG_TYPE_VOICE_INCOMMING_SEEN:
121     case CTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN:
122     case CTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN:
123         m_logEntry->setFolder(LogEntry::MISSED_CALLS_FOLDER);
124         break;
125     case CTS_PLOG_TYPE_VIDEO_INCOMMING:
126     case CTS_PLOG_TYPE_VOICE_INCOMMING:
127         m_logEntry->setFolder(LogEntry::RECEIVED_CALLS_FOLDER);
128         break;
129     case CTS_PLOG_TYPE_VIDEO_OUTGOING:
130     case CTS_PLOG_TYPE_VOICE_OUTGOING:
131         m_logEntry->setFolder(LogEntry::INITIATED_CALLS_FOLDER);
132         break;
133     default:
134         LogDebug("Invalid folder");
135         m_logEntry->setFolder(LogEntry::INVALID_FOLDER);
136         break;
137     }
138     return true;
139 }
140
141 Api::LogEntryPtr LogEntryWrapper::getAbstractCall() const
142 {
143     return m_logEntry;
144 }
145 }
146 }