|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : LandmarksApplicationEngine.cpp 00004 * Part of : Landmark reference application 00005 * Interface : - 00006 * Description : Implementation of the application engine component interface. 00007 * Version : 1.0 00008 * 00009 * Copyright (c) 2004-2006 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 // INCLUDE FILES 00017 #include <EPos_CPosLandmarkDatabase.h> 00018 00019 #include "LmRefApp.hrh" 00020 #include "LandmarksApplicationEngine.h" 00021 #include "LandmarksCommonData.h" 00022 #include "LandmarksEngine.h" 00023 #include "LandmarksCategoriesEngine.h" 00024 #include "LandmarksDbEventHandler.h" 00025 00026 // ============================ MEMBER FUNCTIONS =============================== 00027 00028 // ----------------------------------------------------------------------------- 00029 // CLandmarksApplicationEngine::CLandmarksApplicationEngine 00030 // C++ default constructor can NOT contain any code, that 00031 // might leave. 00032 // ----------------------------------------------------------------------------- 00033 // 00034 CLandmarksApplicationEngine::CLandmarksApplicationEngine() 00035 { 00036 } 00037 00038 // ----------------------------------------------------------------------------- 00039 // CLandmarksApplicationEngine::::ConstructL 00040 // Symbian 2nd phase constructor can leave. 00041 // ----------------------------------------------------------------------------- 00042 // 00043 void CLandmarksApplicationEngine::ConstructL() 00044 { 00045 iDb = CPosLandmarkDatabase::OpenL(); 00046 iLandmarksEngine = CLandmarksEngine::NewL(*iDb); 00047 iCategoriesEngine = CLandmarksCategoriesEngine::NewL(*iDb); 00048 } 00049 00050 // ----------------------------------------------------------------------------- 00051 // CLandmarksApplicationEngine::NewL 00052 // Two-phased constructor. 00053 // ----------------------------------------------------------------------------- 00054 // 00055 CLandmarksApplicationEngine* CLandmarksApplicationEngine::NewL() 00056 { 00057 CLandmarksApplicationEngine* self = 00058 new (ELeave) CLandmarksApplicationEngine(); 00059 CleanupStack::PushL(self); 00060 self->ConstructL(); 00061 CleanupStack::Pop(self); 00062 return self; 00063 } 00064 00065 // Destructor 00066 CLandmarksApplicationEngine::~CLandmarksApplicationEngine() 00067 { 00068 delete iLandmarksEngine; 00069 delete iCategoriesEngine; 00070 delete iDbEventHandler; 00071 delete iDb; 00072 } 00073 00074 // ----------------------------------------------------------------------------- 00075 // CLandmarksApplicationEngine::NotifyViewActivated 00076 // The engine that corresponds to an active view must have higher priority than 00077 // engines corresponding to deactivated views. 00078 // (other items were commented in a header). 00079 // ----------------------------------------------------------------------------- 00080 // 00081 void CLandmarksApplicationEngine::NotifyViewActivated( 00082 TUid aViewId, 00083 TBool aIsActive) 00084 { 00085 if (aViewId.iUid == ELandmarksViewId) 00086 { 00087 if (aIsActive) 00088 { 00089 iLandmarksEngine->SetPrio(CActive::EPriorityStandard); 00090 } 00091 else 00092 { 00093 iLandmarksEngine->SetPrio(CActive::EPriorityLow); 00094 } 00095 } 00096 else if (aViewId.iUid == ELandmarksCategoriesViewId) 00097 { 00098 if (aIsActive) 00099 { 00100 iCategoriesEngine->SetPrio(CActive::EPriorityStandard); 00101 } 00102 else 00103 { 00104 iCategoriesEngine->SetPrio(CActive::EPriorityLow); 00105 } 00106 } 00107 } 00108 00109 // ----------------------------------------------------------------------------- 00110 // CLandmarksApplicationEngine::StartInitializeDbIfNecessaryL 00111 // 00112 // (other items were commented in a header). 00113 // ----------------------------------------------------------------------------- 00114 // 00115 TBool CLandmarksApplicationEngine::StartInitializeDbIfNecessaryL( 00116 MLandmarksOperationObserver* aObserver) 00117 { 00118 return iLandmarksEngine->StartInitializeDbIfNecessaryL(aObserver); 00119 } 00120 00121 // ----------------------------------------------------------------------------- 00122 // CLandmarksApplicationEngine::AddDbObserverL 00123 // 00124 // (other items were commented in a header). 00125 // ----------------------------------------------------------------------------- 00126 // 00127 void CLandmarksApplicationEngine::AddDbObserverL( 00128 MLandmarksDbObserver* aObserver) 00129 { 00130 if (!iDbEventHandler) 00131 { 00132 iDbEventHandler = new (ELeave) CLandmarksDbEventHandler(*iDb); 00133 } 00134 iDbEventHandler->AddObserverL(aObserver); 00135 } 00136 00137 // ----------------------------------------------------------------------------- 00138 // CLandmarksApplicationEngine::LandmarkLC 00139 // 00140 // (other items were commented in a header). 00141 // ----------------------------------------------------------------------------- 00142 // 00143 CPosLandmark* CLandmarksApplicationEngine::LandmarkLC(TPosLmItemId aItemId) 00144 { 00145 return iDb->ReadLandmarkLC(aItemId); 00146 } 00147 00148 // ----------------------------------------------------------------------------- 00149 // CLandmarksApplicationEngine::CommitLandmarkL 00150 // 00151 // (other items were commented in a header). 00152 // ----------------------------------------------------------------------------- 00153 // 00154 void CLandmarksApplicationEngine::CommitLandmarkL( 00155 const CPosLandmark& aLandmark) 00156 { 00157 // We need to cancel any search/read operation in any view engine. 00158 // Otherwise database will be locked. 00159 iLandmarksEngine->Cancel(); 00160 iCategoriesEngine->Cancel(); 00161 00162 iLandmarksEngine->CommitLandmarkL(aLandmark); 00163 CompactIfNeededL(); 00164 } 00165 00166 // ----------------------------------------------------------------------------- 00167 // CLandmarksApplicationEngine::DeleteLandmarkL 00168 // 00169 // (other items were commented in a header). 00170 // ----------------------------------------------------------------------------- 00171 // 00172 void CLandmarksApplicationEngine::DeleteLandmarkL(TPosLmItemId aItemId) 00173 { 00174 // We need to cancel any search/read operation in any view engine. 00175 // Otherwise database will be locked. 00176 iLandmarksEngine->Cancel(); 00177 iCategoriesEngine->Cancel(); 00178 00179 iLandmarksEngine->DeleteLandmarkL(aItemId); 00180 CompactIfNeededL(); 00181 } 00182 00183 // ----------------------------------------------------------------------------- 00184 // CLandmarksApplicationEngine::AddLandmarkL 00185 // 00186 // (other items were commented in a header). 00187 // ----------------------------------------------------------------------------- 00188 // 00189 void CLandmarksApplicationEngine::AddLandmarkL(CPosLandmark& aLandmark) 00190 { 00191 // We need to cancel any search/read operation in any view engine. 00192 // Otherwise database will be locked. 00193 iLandmarksEngine->Cancel(); 00194 iCategoriesEngine->Cancel(); 00195 00196 iLandmarksEngine->AddLandmarkL(aLandmark); 00197 CompactIfNeededL(); 00198 } 00199 00200 // ----------------------------------------------------------------------------- 00201 // CLandmarksApplicationEngine::StartSearchingLandmarksL 00202 // 00203 // (other items were commented in a header). 00204 // ----------------------------------------------------------------------------- 00205 // 00206 void CLandmarksApplicationEngine::StartSearchingLandmarksL( 00207 MLandmarksOperationObserver* aObserver) 00208 { 00209 iLandmarksEngine->StartSearchingLandmarksL(aObserver); 00210 } 00211 00212 // ----------------------------------------------------------------------------- 00213 // CLandmarksApplicationEngine::StartSearchingLandmarksL 00214 // 00215 // (other items were commented in a header). 00216 // ----------------------------------------------------------------------------- 00217 // 00218 void CLandmarksApplicationEngine::StartSearchingLandmarksL( 00219 const TDesC& aSearchPattern, 00220 TBool aSearchOnlyInPreviousMatches, 00221 MLandmarksOperationObserver* aObserver) 00222 { 00223 iLandmarksEngine->StartSearchingLandmarksL( 00224 aSearchPattern, 00225 aSearchOnlyInPreviousMatches, 00226 aObserver); 00227 } 00228 00229 // ----------------------------------------------------------------------------- 00230 // CLandmarksApplicationEngine::FetchLandmarkSearchResultL 00231 // 00232 // (other items were commented in a header). 00233 // ----------------------------------------------------------------------------- 00234 // 00235 RArray<TPosLmItemId>* CLandmarksApplicationEngine::FetchLandmarkSearchResult() 00236 { 00237 return iLandmarksEngine->FetchSearchResult(); 00238 } 00239 00240 // ----------------------------------------------------------------------------- 00241 // CLandmarksApplicationEngine::StartReadingLandmarksL 00242 // 00243 // (other items were commented in a header). 00244 // ----------------------------------------------------------------------------- 00245 // 00246 void CLandmarksApplicationEngine::StartReadingLandmarksL( 00247 TInt aNrOfItemsToReadPerBundle, 00248 MLandmarksOperationObserver* aObserver) 00249 { 00250 iLandmarksEngine->StartReadingLandmarksL( 00251 aNrOfItemsToReadPerBundle, 00252 aObserver); 00253 } 00254 00255 // ----------------------------------------------------------------------------- 00256 // CLandmarksApplicationEngine::FetchLandmarksLC 00257 // 00258 // (other items were commented in a header). 00259 // ----------------------------------------------------------------------------- 00260 // 00261 CArrayPtr<CPosLandmark>* CLandmarksApplicationEngine::FetchLandmarksLC() 00262 { 00263 return iLandmarksEngine->FetchLandmarksLC(); 00264 } 00265 00266 // ----------------------------------------------------------------------------- 00267 // CLandmarksApplicationEngine::CategoryLC 00268 // 00269 // (other items were commented in a header). 00270 // ----------------------------------------------------------------------------- 00271 // 00272 CPosLandmarkCategory* CLandmarksApplicationEngine::CategoryLC( 00273 TPosLmItemId aItemId) 00274 { 00275 return iCategoriesEngine->CategoryLC(aItemId); 00276 } 00277 00278 // ----------------------------------------------------------------------------- 00279 // CLandmarksApplicationEngine::DeleteCategoryL 00280 // 00281 // (other items were commented in a header). 00282 // ----------------------------------------------------------------------------- 00283 // 00284 void CLandmarksApplicationEngine::DeleteCategoryL(TPosLmItemId aItemId) 00285 { 00286 // We need to cancel any search/read operation in any view engine. 00287 // Otherwise database will be locked. 00288 iLandmarksEngine->Cancel(); 00289 iCategoriesEngine->Cancel(); 00290 00291 iCategoriesEngine->DeleteCategoryL(aItemId); 00292 CompactIfNeededL(); 00293 } 00294 00295 // ----------------------------------------------------------------------------- 00296 // CLandmarksApplicationEngine::UpdateCategoryL 00297 // 00298 // (other items were commented in a header). 00299 // ----------------------------------------------------------------------------- 00300 // 00301 void CLandmarksApplicationEngine::UpdateCategoryL( 00302 const CPosLandmarkCategory& aCategory) 00303 { 00304 // We need to cancel any search/read operation in any view engine. 00305 // Otherwise database will be locked. 00306 iLandmarksEngine->Cancel(); 00307 iCategoriesEngine->Cancel(); 00308 00309 iCategoriesEngine->UpdateCategoryL(aCategory); 00310 CompactIfNeededL(); 00311 } 00312 00313 // ----------------------------------------------------------------------------- 00314 // CLandmarksApplicationEngine::AddCategoryL 00315 // 00316 // (other items were commented in a header). 00317 // ----------------------------------------------------------------------------- 00318 // 00319 void CLandmarksApplicationEngine::AddCategoryL(CPosLandmarkCategory& aCategory) 00320 { 00321 // We need to cancel any search/read operation in any view engine. 00322 // Otherwise database will be locked. 00323 iLandmarksEngine->Cancel(); 00324 iCategoriesEngine->Cancel(); 00325 00326 iCategoriesEngine->AddCategoryL(aCategory); 00327 CompactIfNeededL(); 00328 } 00329 00330 // ----------------------------------------------------------------------------- 00331 // CLandmarksApplicationEngine::StartSearchingCategoriesL 00332 // 00333 // (other items were commented in a header). 00334 // ----------------------------------------------------------------------------- 00335 // 00336 void CLandmarksApplicationEngine::StartSearchingCategoriesL( 00337 const TDesC& aSearchPattern, 00338 TBool aSearchOnlyInPreviousMatches, 00339 MLandmarksOperationObserver* aObserver) 00340 { 00341 iCategoriesEngine->StartSearchingCategoriesL( 00342 aSearchPattern, 00343 aSearchOnlyInPreviousMatches, 00344 aObserver); 00345 } 00346 00347 // ----------------------------------------------------------------------------- 00348 // CLandmarksApplicationEngine::StartSearchingCategoriesL 00349 // 00350 // (other items were commented in a header). 00351 // ----------------------------------------------------------------------------- 00352 // 00353 void CLandmarksApplicationEngine::StartSearchingCategoriesL( 00354 MLandmarksOperationObserver* aObserver) 00355 { 00356 iCategoriesEngine->StartSearchingCategoriesL(aObserver); 00357 } 00358 00359 // ----------------------------------------------------------------------------- 00360 // CLandmarksApplicationEngine::FetchCategorySearchResult 00361 // 00362 // (other items were commented in a header). 00363 // ----------------------------------------------------------------------------- 00364 // 00365 RArray<TPosLmItemId>* CLandmarksApplicationEngine::FetchCategorySearchResult() 00366 { 00367 return iCategoriesEngine->FetchSearchResult(); 00368 } 00369 00370 // ----------------------------------------------------------------------------- 00371 // CLandmarksApplicationEngine::StartReadingCategoriesL 00372 // 00373 // (other items were commented in a header). 00374 // ----------------------------------------------------------------------------- 00375 // 00376 void CLandmarksApplicationEngine::StartReadingCategoriesL( 00377 TInt aNrOfItemsToReadPerBundle, 00378 MLandmarksOperationObserver* aObserver) 00379 { 00380 iCategoriesEngine->StartReadingCategoriesL( 00381 aNrOfItemsToReadPerBundle, aObserver); 00382 } 00383 00384 // ----------------------------------------------------------------------------- 00385 // CLandmarksApplicationEngine::FetchCategoriesLC 00386 // 00387 // (other items were commented in a header). 00388 // ----------------------------------------------------------------------------- 00389 // 00390 CArrayPtr<CPosLandmarkCategory>* CLandmarksApplicationEngine::FetchCategoriesLC() 00391 { 00392 return iCategoriesEngine->FetchCategoriesLC(); 00393 } 00394 00395 // ----------------------------------------------------------------------------- 00396 // CLandmarksApplicationEngine::CategoriesL 00397 // 00398 // (other items were commented in a header). 00399 // ----------------------------------------------------------------------------- 00400 // 00401 CArrayPtr<CPosLandmarkCategory>* CLandmarksApplicationEngine::CategoriesL() 00402 { 00403 return iCategoriesEngine->CategoriesL(); 00404 } 00405 00406 // ----------------------------------------------------------------------------- 00407 // CLandmarksApplicationEngine::CompactIfNeededL 00408 // 00409 // (other items were commented in a header). 00410 // ----------------------------------------------------------------------------- 00411 // 00412 void CLandmarksApplicationEngine::CompactIfNeededL() 00413 { 00414 CPosLandmarkDatabase::TSize dbSize = iDb->SizeL(); 00415 if (dbSize.iUsage < KDbUsageLimit) 00416 { 00417 ExecuteAndDeleteLD(iDb->CompactL()); 00418 } 00419 } 00420 00421 // End of File 00422
|
© Nokia 2006 |