15
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// INCLUDE FILES
|
|
19 |
#include "logsduplicatelookup.h"
|
|
20 |
#include "logsevent.h"
|
|
21 |
#include "logscommondata.h"
|
|
22 |
|
|
23 |
// ----------------------------------------------------------------------------
|
|
24 |
//
|
|
25 |
// ----------------------------------------------------------------------------
|
|
26 |
//
|
|
27 |
LogsDuplicateLookup::LogsDuplicateLookup()
|
|
28 |
{
|
|
29 |
for ( int i = 0; i <= LogsEvent::DirMissed; i++ ){
|
|
30 |
LogsLookupHash* directionLookup = new LogsLookupHash;
|
|
31 |
mDirectionLookupTables.append( directionLookup );
|
|
32 |
}
|
|
33 |
}
|
|
34 |
|
|
35 |
// ----------------------------------------------------------------------------
|
|
36 |
//
|
|
37 |
// ----------------------------------------------------------------------------
|
|
38 |
//
|
|
39 |
LogsDuplicateLookup::~LogsDuplicateLookup()
|
|
40 |
{
|
|
41 |
qDeleteAll(mDirectionLookupTables);
|
|
42 |
}
|
|
43 |
|
|
44 |
// ----------------------------------------------------------------------------
|
|
45 |
//
|
|
46 |
// ----------------------------------------------------------------------------
|
|
47 |
//
|
|
48 |
void LogsDuplicateLookup::invalidate()
|
|
49 |
{
|
|
50 |
for( int k = 0; k < mDirectionLookupTables.count(); k++ ){
|
|
51 |
LogsLookupHash& table = *mDirectionLookupTables.at(k);
|
|
52 |
LogsLookupHash::iterator it;
|
|
53 |
for (it = table.begin(); it != table.end(); ++it){
|
|
54 |
it.value() = 0;
|
|
55 |
}
|
|
56 |
}
|
|
57 |
}
|
|
58 |
|
|
59 |
// ----------------------------------------------------------------------------
|
|
60 |
//
|
|
61 |
// ----------------------------------------------------------------------------
|
|
62 |
//
|
|
63 |
void LogsDuplicateLookup::cleanup()
|
|
64 |
{
|
|
65 |
for( int k = 0; k < mDirectionLookupTables.count(); k++ ){
|
|
66 |
LogsLookupHash& table = *mDirectionLookupTables.at(k);
|
|
67 |
LogsLookupHash::iterator it = table.begin();
|
|
68 |
while ( it != table.end() ){
|
|
69 |
if ( it.value() == 0 ){
|
|
70 |
it = table.erase(it);
|
|
71 |
} else {
|
|
72 |
++it;
|
|
73 |
}
|
|
74 |
}
|
|
75 |
}
|
|
76 |
}
|
|
77 |
|
|
78 |
// ----------------------------------------------------------------------------
|
|
79 |
//
|
|
80 |
// ----------------------------------------------------------------------------
|
|
81 |
//
|
|
82 |
int LogsDuplicateLookup::addLookupEntry( LogsEvent& event )
|
|
83 |
{
|
|
84 |
if ( !validLookupEvent(event) ){
|
|
85 |
return -1;
|
|
86 |
}
|
|
87 |
int dir = event.direction();
|
|
88 |
QString key = constructLookupKey(event);
|
|
89 |
LogsLookupHash::iterator it = mDirectionLookupTables.at(dir)->find(key);
|
|
90 |
if ( it != mDirectionLookupTables.at(dir)->end() ){
|
|
91 |
if ( it.value() == 0 ){
|
|
92 |
it.value() = &event;
|
|
93 |
}
|
|
94 |
} else {
|
|
95 |
mDirectionLookupTables.at(dir)->insert(key, &event);
|
|
96 |
}
|
|
97 |
return 0;
|
|
98 |
}
|
|
99 |
|
|
100 |
// ----------------------------------------------------------------------------
|
|
101 |
//
|
|
102 |
// ----------------------------------------------------------------------------
|
|
103 |
//
|
|
104 |
LogsEvent* LogsDuplicateLookup::findDuplicate( const LogsEvent& event ) const
|
|
105 |
{
|
|
106 |
if ( !validLookupEvent(event) ){
|
|
107 |
return 0;
|
|
108 |
}
|
|
109 |
int dir = event.direction();
|
|
110 |
QString key = constructLookupKey(event);
|
|
111 |
LogsLookupHash::const_iterator it =
|
|
112 |
mDirectionLookupTables.at(dir)->find(key);
|
|
113 |
if ( it != mDirectionLookupTables.at(dir)->constEnd() ){
|
|
114 |
return it.value();
|
|
115 |
}
|
|
116 |
return 0;
|
|
117 |
}
|
|
118 |
|
|
119 |
// ----------------------------------------------------------------------------
|
|
120 |
//
|
|
121 |
// ----------------------------------------------------------------------------
|
|
122 |
//
|
|
123 |
QString LogsDuplicateLookup::constructLookupKey( const LogsEvent& event ) const
|
|
124 |
{
|
|
125 |
return ( event.remoteParty() + "/t" +
|
|
126 |
event.number().right(LogsCommonData::getInstance().telNumMatchLen() ) );
|
|
127 |
}
|
|
128 |
|
|
129 |
// ----------------------------------------------------------------------------
|
|
130 |
//
|
|
131 |
// ----------------------------------------------------------------------------
|
|
132 |
//
|
|
133 |
bool LogsDuplicateLookup::validLookupEvent( const LogsEvent& event ) const
|
|
134 |
{
|
|
135 |
int dir = event.direction();
|
|
136 |
return ( !event.remoteParty().isEmpty() &&
|
|
137 |
dir >= 0 && dir < mDirectionLookupTables.count() );
|
|
138 |
}
|