|
1 /* |
|
2 * Copyright (c) 2008 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: Handles native landmark databases |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INTERNAL INCLUDES |
|
20 #include "clapilandmarkstoremanager.h" |
|
21 #include "clapilmdatabaseeventnotifier.h" |
|
22 #include "clapicategorymanager.h" |
|
23 #include "clapilandmarkstore.h" |
|
24 #include "logger.h" |
|
25 |
|
26 // EXTERNAL INCLUDES |
|
27 #include <EPos_CPosLandmarkDatabase.h> |
|
28 #include <EPos_CPosLmDatabaseManager.h> |
|
29 #include <EPos_CPosLmCategoryManager.h> |
|
30 #include <EPos_CPosLmOperation.h> |
|
31 #include <EPos_Landmarks.h> |
|
32 #include <EPos_HPosLmDatabaseInfo.h> |
|
33 |
|
34 namespace |
|
35 { |
|
36 // The default protocol for internal stores |
|
37 _LIT(KLAPIDefaultProtocol, "file://"); |
|
38 } |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // CLAPILandmarkStoreManager::NewL |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 CLAPILandmarkStoreManager* CLAPILandmarkStoreManager::NewL() |
|
45 { |
|
46 JELOG2(EJavaLocation); |
|
47 CLAPILandmarkStoreManager* self = CLAPILandmarkStoreManager::NewLC(); |
|
48 CleanupStack::Pop(self); |
|
49 return self; |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // CLAPILandmarkStoreManager::NewLC |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CLAPILandmarkStoreManager* CLAPILandmarkStoreManager::NewLC() |
|
57 { |
|
58 JELOG2(EJavaLocation); |
|
59 CLAPILandmarkStoreManager* self = new(ELeave) CLAPILandmarkStoreManager; |
|
60 CleanupStack::PushL(self); |
|
61 self->ConstructL(); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CLAPILandmarkStoreManager::~CLAPILandmarkStoreManager |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 CLAPILandmarkStoreManager::~CLAPILandmarkStoreManager() |
|
70 { |
|
71 JELOG2(EJavaLocation); |
|
72 // The objects inside the array are not owned by this class |
|
73 iStores.Close(); |
|
74 delete iLmDbManager; |
|
75 // Release all landmark resources because Landmarks FW will not be used |
|
76 // anymore. This has basicly the same effect as REComSeesion::FinalClose() |
|
77 // All allocated memory and garbage plug-ins will be released |
|
78 ReleaseLandmarkResources(); |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // CLAPILandmarkStoreManager::LandmarkStoresL |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 CDesCArray* CLAPILandmarkStoreManager::LandmarkStoresL() |
|
86 { |
|
87 JELOG2(EJavaLocation); |
|
88 // List landmark databases but remove the default store from the array |
|
89 CDesCArray* stores = iLmDbManager->ListDatabasesLC(); |
|
90 HBufC* defaultDbName = iLmDbManager->DefaultDatabaseUriLC(); |
|
91 |
|
92 // Remove the default database from the store names array. External stores |
|
93 // are also removed because this API does not support other than stores |
|
94 // which are located in the file system of the device |
|
95 TInt count = stores->Count(); |
|
96 for (TInt i = 0; i < count; i++) |
|
97 { |
|
98 TPtrC storeUri = stores->MdcaPoint(i); |
|
99 if (defaultDbName->CompareF(storeUri) == 0 || storeUri.FindF( |
|
100 KLAPIDefaultProtocol) == KErrNotFound) |
|
101 { |
|
102 stores->Delete(i); |
|
103 break; |
|
104 } |
|
105 } |
|
106 |
|
107 CleanupStack::PopAndDestroy(defaultDbName); |
|
108 CleanupStack::Pop(stores); |
|
109 return stores; |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // CLAPILandmarkStoreManager::OpenStoreL |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 CLAPILandmarkStore* CLAPILandmarkStoreManager::OpenStoreL( |
|
117 const TDesC& aStoreUri) |
|
118 { |
|
119 JELOG2(EJavaLocation); |
|
120 CPosLandmarkDatabase* database(NULL); |
|
121 // Open default landmark database if the passed URI is a null descriptor |
|
122 database = (aStoreUri == KNullDesC() ? CPosLandmarkDatabase::OpenL() |
|
123 : CPosLandmarkDatabase::OpenL(aStoreUri)); |
|
124 |
|
125 CleanupStack::PushL(database); |
|
126 |
|
127 // Initialize the database if needed. Note that the store is not usable |
|
128 // in any way if it has not been initialized |
|
129 if (database->IsInitializingNeeded()) |
|
130 { |
|
131 ExecuteAndDeleteLD(database->InitializeL()); |
|
132 } |
|
133 |
|
134 // Create landmark store event notifier |
|
135 MLAPILmDatabaseEventNotifier* notifier = |
|
136 CLAPILmDatabaseEventNotifier::NewLC(*database); |
|
137 |
|
138 // Create category manager |
|
139 CLAPICategoryManager::TCtorParams managerParams; |
|
140 managerParams.iLandmarkDatabase = database; |
|
141 managerParams.iEventNotifier = notifier; |
|
142 MLAPICategoryManager* manager = CLAPICategoryManager::NewLC(managerParams); |
|
143 |
|
144 // Construct the landmark store. The store takes ownership of |
|
145 // the native landmark database, the notifier and the category manager. |
|
146 CLAPILandmarkStore::TCtorParams storeParams; |
|
147 storeParams.iLandmarkDatabase = database; |
|
148 storeParams.iCategoryManager = manager; |
|
149 storeParams.iEventNotifier = notifier; |
|
150 CLAPILandmarkStore* lmStore = CLAPILandmarkStore::NewLC(storeParams); |
|
151 |
|
152 // The store is not owned but is still monitored since it is possible |
|
153 // that an open store would be deleted which means that the store |
|
154 // must be closed in order for successful deletion |
|
155 iStores.AppendL(lmStore); |
|
156 |
|
157 CleanupStack::Pop(4, database); |
|
158 return lmStore; |
|
159 } |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // CLAPILandmarkStoreManager::CreateStoreL |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 void CLAPILandmarkStoreManager::CreateStoreL(const TDesC& aStoreUri) |
|
166 { |
|
167 JELOG2(EJavaLocation); |
|
168 __ASSERT_ALWAYS(aStoreUri != KNullDesC(), User::Leave(KErrBadName)); |
|
169 // Create database info which specifies the place of the new database |
|
170 HPosLmDatabaseInfo* dbInfo = HPosLmDatabaseInfo::NewLC(aStoreUri); |
|
171 // Create the database. This leaves if there is already a database in |
|
172 // the same URI location |
|
173 iLmDbManager->CreateDatabaseL(*dbInfo); |
|
174 CleanupStack::PopAndDestroy(dbInfo); |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // CLAPILandmarkStoreManager::DeleteStoreL |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 void CLAPILandmarkStoreManager::DeleteStoreL(const TDesC& aStoreUri) |
|
182 { |
|
183 JELOG2(EJavaLocation); |
|
184 __ASSERT_ALWAYS(aStoreUri != KNullDesC(), User::Leave(KErrBadName)); |
|
185 // Find if the requested store has been opened and close it before |
|
186 // deleting the database. This is done because if some client uses |
|
187 // the store it cannot be deleted |
|
188 TInt storeCount = iStores.Count(); |
|
189 for (TInt i = 0; i < storeCount; i++) |
|
190 { |
|
191 if (iStores[i]->StoreUri().CompareF(aStoreUri) == 0) |
|
192 { |
|
193 // Database has been opened so close it. Make sure that all |
|
194 // databases will be closed |
|
195 iStores[i]->Close(); |
|
196 } |
|
197 } |
|
198 // Now it is safe to delete the requested store |
|
199 iLmDbManager->DeleteDatabaseL(aStoreUri); |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 // CLAPILandmarkStoreManager::RemoveStore |
|
204 // --------------------------------------------------------------------------- |
|
205 // |
|
206 void CLAPILandmarkStoreManager::RemoveStore(CLAPILandmarkStore& aLandmarkStore) |
|
207 { |
|
208 JELOG2(EJavaLocation); |
|
209 TInt index = iStores.Find(&aLandmarkStore); |
|
210 if (index != KErrNotFound) |
|
211 { |
|
212 // Do not delete the store since this class does not own it |
|
213 iStores.Remove(index); |
|
214 } |
|
215 } |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // CLAPILandmarkStoreManager::CLAPILandmarkStoreManager |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 CLAPILandmarkStoreManager::CLAPILandmarkStoreManager() |
|
222 { |
|
223 JELOG2(EJavaLocation); |
|
224 } |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // CLAPILandmarkStoreManager::ConstructL |
|
228 // (other items were commented in a header) |
|
229 // --------------------------------------------------------------------------- |
|
230 // |
|
231 void CLAPILandmarkStoreManager::ConstructL() |
|
232 { |
|
233 JELOG2(EJavaLocation); |
|
234 iLmDbManager = CPosLmDatabaseManager::NewL(); |
|
235 } |
|
236 |
|
237 // End of file |