|
1 /* |
|
2 * Copyright (c) 2004 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 the License "Symbian Foundation License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * ?description_line |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 |
|
22 #include "FT_CPosTp57.h" |
|
23 #include <EPos_CPosLandmarkDatabase.h> |
|
24 #include <EPos_CPosLmTextCriteria.h> |
|
25 #include <EPos_CPosLmAreaCriteria.h> |
|
26 |
|
27 // CONSTANTS |
|
28 |
|
29 // ================= MEMBER FUNCTIONS ======================= |
|
30 |
|
31 // --------------------------------------------------------- |
|
32 // CPosTp57::GetName |
|
33 // |
|
34 // (other items were commented in a header). |
|
35 // --------------------------------------------------------- |
|
36 // |
|
37 void CPosTp57::GetName(TDes& aName) const |
|
38 { |
|
39 _LIT(KTestName, "TP57 - Multiple db search"); |
|
40 aName = KTestName; |
|
41 } |
|
42 |
|
43 // --------------------------------------------------------- |
|
44 // CPosTp57::CloseTest |
|
45 // |
|
46 // (other items were commented in a header). |
|
47 // --------------------------------------------------------- |
|
48 // |
|
49 void CPosTp57::CloseTest() |
|
50 { |
|
51 iSearchResults.ResetAndDestroy(); |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------- |
|
55 // CPosTp57::StartL |
|
56 // |
|
57 // (other items were commented in a header). |
|
58 // --------------------------------------------------------- |
|
59 // |
|
60 void CPosTp57::StartL() |
|
61 { |
|
62 |
|
63 iDatabase = UseGeneratedDbFileL(); |
|
64 |
|
65 CPosLandmark* lm = NULL; |
|
66 TRAPD(err, |
|
67 { |
|
68 lm = iDatabase->ReadLandmarkLC(1); |
|
69 CleanupStack::PopAndDestroy(lm); |
|
70 } |
|
71 ); |
|
72 |
|
73 /* if (!err) |
|
74 { |
|
75 delete lm; |
|
76 } |
|
77 */ |
|
78 |
|
79 |
|
80 /* |
|
81 CreateDatabasesL(); |
|
82 |
|
83 SearchWithTextCriteriaL(); |
|
84 |
|
85 SearchWithAreaCriteriaL(); |
|
86 */ |
|
87 } |
|
88 |
|
89 |
|
90 |
|
91 // --------------------------------------------------------- |
|
92 // CPosTp57::SearchWithTextCriteria |
|
93 // |
|
94 // (other items were commented in a header). |
|
95 // --------------------------------------------------------- |
|
96 // |
|
97 void CPosTp57::SearchWithTextCriteriaL() |
|
98 { |
|
99 AppendSearchResultsL(); |
|
100 |
|
101 for(TInt i=0; i<iSearchResults.Count(); i++) |
|
102 { |
|
103 CPosLmTextCriteria* textCriteria = CPosLmTextCriteria::NewLC(); |
|
104 |
|
105 textCriteria->SetTextL(iSearchResults[i]->TextCriteria()); |
|
106 textCriteria->SetAttributesToSearch(iSearchResults[i]->Attributes()); |
|
107 |
|
108 textCriteria->SetPositionFieldsToSearchL(iSearchResults[i]->PositionFields()); |
|
109 |
|
110 |
|
111 |
|
112 } |
|
113 |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------- |
|
117 // CPosTp57::SearchWithAreaCriteriaL |
|
118 // |
|
119 // (other items were commented in a header). |
|
120 // --------------------------------------------------------- |
|
121 // |
|
122 void CPosTp57::SearchWithAreaCriteriaL() |
|
123 { |
|
124 AppendAreaSearchResultsL(); |
|
125 |
|
126 |
|
127 TBuf<255> info; |
|
128 for (TInt i=0; i<iAreaSearchResults.Count(); i++) |
|
129 { |
|
130 CPosLmAreaCriteria* areaCriteria=NULL; |
|
131 TRAPD(err, areaCriteria = CPosTp57::NewLmAreaCriteriaL(iAreaSearchResults[i]->SouthLat(), |
|
132 iAreaSearchResults[i]->NorthLat(), |
|
133 iAreaSearchResults[i]->WestLong(), |
|
134 iAreaSearchResults[i]->EastLong() |
|
135 )); |
|
136 CleanupStack::PushL(areaCriteria); |
|
137 |
|
138 if (err != iAreaSearchResults[i]->ErrorCode()) |
|
139 { |
|
140 iLog->Put(_L("Unexpected error code returned")); |
|
141 iLog->Put(_L("Area Search result read from file:")); |
|
142 |
|
143 iAreaSearchResults[i]->Print(info); |
|
144 iLog->Put(info); |
|
145 |
|
146 _LIT(KReturned, "NewLmAreaCriteriaL error = %d"); |
|
147 info.Format(KReturned, err); |
|
148 iLog->Put(info); |
|
149 User::Leave(KErrGeneral); |
|
150 } |
|
151 |
|
152 if (!err) |
|
153 { |
|
154 |
|
155 |
|
156 |
|
157 } |
|
158 } |
|
159 |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------- |
|
163 // CPosTp57::NewLmAreaCriteriaL |
|
164 // |
|
165 // (other items were commented in a header). |
|
166 // --------------------------------------------------------- |
|
167 // |
|
168 CPosLmAreaCriteria* CPosTp57::NewLmAreaCriteriaL(const TReal64 &aSouthLat, |
|
169 const TReal64 &aNorthLat, |
|
170 const TReal64 &aWestLong, |
|
171 const TReal64 &aEastLong) |
|
172 { |
|
173 CPosLmAreaCriteria* areaCriteria = CPosLmAreaCriteria::NewLC(aSouthLat, |
|
174 aNorthLat, |
|
175 aWestLong, |
|
176 aEastLong |
|
177 ); |
|
178 CleanupStack::Pop(); |
|
179 |
|
180 return areaCriteria; |
|
181 } |
|
182 // --------------------------------------------------------- |
|
183 // CPosTp57::CreateDatabasesL |
|
184 // |
|
185 // (other items were commented in a header). |
|
186 // --------------------------------------------------------- |
|
187 // |
|
188 void CPosTp57::CreateDatabasesL() |
|
189 { |
|
190 /* |
|
191 Very inefficient and time consuming method, maybe better to execute once and store the |
|
192 created databases as testdata |
|
193 |
|
194 Db name: Landmarks id: |
|
195 eposlm1.ldb 1-10 |
|
196 eposlm2.ldb 11-20 |
|
197 eposlm3.ldb 21-30 |
|
198 eposlm4.ldb 31-40 |
|
199 eposlm5.ldb 41-50 |
|
200 eposlm6.ldb 51-60 |
|
201 eposlm7.ldb 61-70 |
|
202 eposlm8.ldb 71-80 |
|
203 eposlm9.ldb 81-90 |
|
204 eposlm10.ldb 91-100 |
|
205 eposlm11.ldb 101-105 |
|
206 */ |
|
207 |
|
208 // Paths will need to be changed to the secure dbms path when security is implemented |
|
209 _LIT(KDefaultDbPath, "c:\\system\\data\\eposlm.ldb"); // Contains now no landmarks but the global categories |
|
210 _LIT(KDbNamePath, "c:\\system\\data\\eposlm%d.ldb"); |
|
211 |
|
212 const TInt KLastId=105; |
|
213 const TInt KNoDatabases=11; |
|
214 |
|
215 RemoveDefaultDbL(); |
|
216 |
|
217 CPosLandmarkDatabase* lmd = CPosLandmarkDatabase::OpenL(); |
|
218 CleanupStack::PushL(lmd); |
|
219 |
|
220 if (lmd->IsInitializingNeeded()) |
|
221 { |
|
222 ExecuteAndDeleteLD(lmd->InitializeL()); |
|
223 } |
|
224 CleanupStack::PopAndDestroy(lmd); |
|
225 |
|
226 RFs fs; |
|
227 User::LeaveIfError(fs.Connect()); |
|
228 CleanupClosePushL(fs); |
|
229 |
|
230 CFileMan* fileMan = CFileMan::NewL(fs); |
|
231 CleanupStack::PushL(fileMan); |
|
232 |
|
233 // Create 11 databases |
|
234 TInt i=0; |
|
235 for (i=1; i <= KNoDatabases; i++) |
|
236 { |
|
237 TBuf<100> db; |
|
238 db.Format(KDbNamePath, i); |
|
239 |
|
240 fs.Delete(db); |
|
241 User::LeaveIfError(fileMan->Copy(KDefaultDbPath, db, CFileMan::EOverWrite)); |
|
242 } |
|
243 CleanupStack::PopAndDestroy(2, &fs); |
|
244 |
|
245 iDatabase = UseGeneratedDbFileL(); |
|
246 |
|
247 if (iDatabase->IsInitializingNeeded()) |
|
248 { |
|
249 ExecuteAndDeleteLD(iDatabase->InitializeL()); |
|
250 } |
|
251 |
|
252 _LIT(KDbName, "eposlm%d.ldb"); |
|
253 |
|
254 TInt databaseNumber=1; |
|
255 for (i=1; i <= KLastId; i++) |
|
256 { |
|
257 CPosLandmark* lm = iDatabase->ReadLandmarkLC(i); |
|
258 |
|
259 TBuf<100> name; |
|
260 name.Format(KDbName, databaseNumber); |
|
261 |
|
262 iLog->Put(name); |
|
263 CPosLandmarkDatabase* lmd = CPosLandmarkDatabase::OpenL(name); |
|
264 CleanupStack::PushL(lmd); |
|
265 |
|
266 lmd->AddLandmarkL(*lm); |
|
267 CleanupStack::PopAndDestroy(2, lm); |
|
268 |
|
269 if (i % 10 == 0) |
|
270 { |
|
271 ++databaseNumber; |
|
272 } |
|
273 } |
|
274 |
|
275 // DEBUG |
|
276 for (i=1; i <= KNoDatabases; i++) |
|
277 { |
|
278 TBuf<100> dbNo; |
|
279 dbNo.Format(_L(" -------- Printing Db %d --------------"), i); |
|
280 iLog->Put(dbNo); |
|
281 |
|
282 TBuf<100> db; |
|
283 db.Format(KDbName, i); |
|
284 iLog->Put(db); |
|
285 |
|
286 CPosLandmarkDatabase* lmd = CPosLandmarkDatabase::OpenL(db); |
|
287 CleanupStack::PushL(lmd); |
|
288 |
|
289 CPosLmItemIterator* iter = lmd->LandmarkIteratorL(); |
|
290 CleanupStack::PushL(iter); |
|
291 |
|
292 TPosLmItemId id = iter->NextL(); |
|
293 |
|
294 while (id != KPosLmNullItemId) |
|
295 { |
|
296 CPosLandmark* lm = lmd->ReadLandmarkLC(id); |
|
297 |
|
298 TBuf<255> info; |
|
299 PrintLandmark(*lm, info); |
|
300 iLog->Put(info); |
|
301 CleanupStack::PopAndDestroy(lm); |
|
302 |
|
303 id = iter->NextL(); |
|
304 } |
|
305 |
|
306 CleanupStack::PopAndDestroy(2, lmd); |
|
307 } |
|
308 } |
|
309 |
|
310 // End of File |