|
1 /* |
|
2 * Copyright (c) 2006 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: Implements the cell id database |
|
15 * |
|
16 */ |
|
17 #include "lbtcelliddatabase.h" |
|
18 |
|
19 /** |
|
20 * Maximum entry that database can hold |
|
21 */ |
|
22 static const TInt KMaxEntry = 25; |
|
23 |
|
24 /** |
|
25 * Index of the entry that needs to removed. |
|
26 */ |
|
27 static const TInt EIndexToBeRemoved = 0; |
|
28 |
|
29 // ======== MEMBER FUNCTIONS ======== |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // CLbtCellIdDatabase::NewL |
|
33 // The Symbian 2 phase constructor |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 CLbtCellIdDatabase* CLbtCellIdDatabase::NewL() |
|
37 { |
|
38 CLbtCellIdDatabase* self = new(ELeave) CLbtCellIdDatabase; |
|
39 CleanupStack::PushL( self ); |
|
40 self->ConstructL(); |
|
41 CleanupStack::Pop( self ); |
|
42 return self; |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // CLbtCellIdDatabase::CLbtCellIdDatabase |
|
47 // Default constructor |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 CLbtCellIdDatabase::CLbtCellIdDatabase() |
|
51 { |
|
52 |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // CLbtCellIdDatabase::ConstructL |
|
57 // |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 void CLbtCellIdDatabase::ConstructL() |
|
61 { |
|
62 |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CLbtCellIdDatabase::~CLbtCellIdDatabase |
|
67 // Destructor |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 CLbtCellIdDatabase::~CLbtCellIdDatabase() |
|
71 { |
|
72 iCellIdDbArray.Close(); |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // CLbtCellIdDatabase::InsertCidLocationL |
|
77 // |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 void CLbtCellIdDatabase::InsertCidLocation( TInt32 aCountryCode, |
|
81 TInt32 aNetworkID, |
|
82 TInt32 aLac, |
|
83 TInt32 aCellId, |
|
84 TLocality aLocality ) |
|
85 { |
|
86 if( IsDuplicateEntry( aCountryCode,aNetworkID,aLac,aCellId,aLocality ) ) |
|
87 { |
|
88 return; |
|
89 } |
|
90 TCellIdCoordinateData cellIdCoordinateData; |
|
91 cellIdCoordinateData.iCountryCode = aCountryCode; |
|
92 cellIdCoordinateData.iNetworkID = aNetworkID; |
|
93 cellIdCoordinateData.iLac = aLac; |
|
94 cellIdCoordinateData.iCellId = aCellId; |
|
95 cellIdCoordinateData.iLocality.SetCoordinate( aLocality.Latitude(), |
|
96 aLocality.Longitude(), |
|
97 aLocality.Altitude() ); |
|
98 cellIdCoordinateData.iLocality.SetHorizontalAccuracy( aLocality.HorizontalAccuracy() ); |
|
99 |
|
100 if( iCellIdDbArray.Count() == KMaxEntry ) |
|
101 { |
|
102 iCellIdDbArray.Remove( EIndexToBeRemoved ); |
|
103 } |
|
104 TInt error = iCellIdDbArray.Append( cellIdCoordinateData ); |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // CLbtCellIdDatabase::GetLocationForCid |
|
109 // |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 TInt CLbtCellIdDatabase::GetLocationForCid( TInt32 aCountryCode, |
|
113 TInt32 aNetworkID, |
|
114 TInt32 aLac, |
|
115 TInt32 aCellId, |
|
116 TLocality& aLocality ) |
|
117 { |
|
118 for( TInt i=0;i<iCellIdDbArray.Count();i++ ) |
|
119 { |
|
120 if( iCellIdDbArray[i].iCountryCode == aCountryCode && |
|
121 iCellIdDbArray[i].iNetworkID == aNetworkID && |
|
122 iCellIdDbArray[i].iLac == aLac && |
|
123 iCellIdDbArray[i].iCellId == aCellId ) |
|
124 { |
|
125 aLocality.SetCoordinate( iCellIdDbArray[i].iLocality.Latitude(), |
|
126 iCellIdDbArray[i].iLocality.Longitude(), |
|
127 iCellIdDbArray[i].iLocality.Altitude() ); |
|
128 aLocality.SetHorizontalAccuracy( iCellIdDbArray[i].iLocality.HorizontalAccuracy() ); |
|
129 |
|
130 // This entry has been used and should be deleted last compared to |
|
131 // unused entry. This is pushed to the end because we delete |
|
132 // entry from first when max cap is reached. |
|
133 iCellIdDbArray.Append( iCellIdDbArray[i] ); |
|
134 iCellIdDbArray.Remove( i ); |
|
135 |
|
136 return KErrNone; |
|
137 } |
|
138 } |
|
139 return KErrNotFound; |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // CLbtCellIdDatabase::IsDuplicateEntry |
|
144 // |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 TBool CLbtCellIdDatabase::IsDuplicateEntry( TInt32 aCountryCode, |
|
148 TInt32 aNetworkID, |
|
149 TInt32 aLac, |
|
150 TInt32 aCellId, |
|
151 TLocality aLocality ) |
|
152 { |
|
153 for( TInt i=0;i<iCellIdDbArray.Count();i++ ) |
|
154 { |
|
155 if( iCellIdDbArray[i].iCountryCode == aCountryCode && |
|
156 iCellIdDbArray[i].iNetworkID == aNetworkID && |
|
157 iCellIdDbArray[i].iLac == aLac && |
|
158 iCellIdDbArray[i].iCellId == aCellId ) |
|
159 { |
|
160 // If the HA of the current entry is less than the existing entry, |
|
161 // replace the old entry with new one. |
|
162 if( aLocality.HorizontalAccuracy() < iCellIdDbArray[i].iLocality.HorizontalAccuracy() ) |
|
163 { |
|
164 iCellIdDbArray[i].iLocality.SetCoordinate( aLocality.Latitude(), |
|
165 aLocality.Longitude(), |
|
166 aLocality.Altitude() ); |
|
167 iCellIdDbArray[i].iLocality.SetHorizontalAccuracy( aLocality.HorizontalAccuracy() ); |
|
168 } |
|
169 return ETrue; |
|
170 } |
|
171 } |
|
172 return EFalse; |
|
173 } |