S60 3rd Edition SDK for Symbian OS
Example Applications Guide

LandmarksEngine.h

00001 /*
00002 * ==============================================================================
00003 *  Name        : LandmarksEngine.h
00004 *  Part of     : Landmark Reference Application
00005 *  Interface   : -
00006 *  Description : See class description below
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 #ifndef __LANDMARKS_ENGINE_H__
00017 #define __LANDMARKS_ENGINE_H__
00018 
00019 // INCLUDES
00020 #include "LandmarksEngineBase.h"
00021 #include "LandmarksOperationObserver.h"
00022 #include <EPos_TPosLmSortPref.h>
00023 
00024 // FORWARD DECLARATIONS
00025 class CPosLandmark;
00026 
00027 // CLASS DECLARATION
00028 
00029 /**
00030 *  Implements all functions of the engine related to landmarks. This engine
00031 *  servs the landmarks view.
00032 */
00033 class CLandmarksEngine : public CLandmarksEngineBase
00034     {
00035     public: // Constructors and destructor
00036 
00037         /**
00038         * Two-phased constructor.
00039         *
00040         * @param aDb an instance of the defaukt landmark database
00041         */
00042         static CLandmarksEngine* NewL(
00043             CPosLandmarkDatabase& aDb);
00044 
00045         /**
00046         * Destructor.
00047         */
00048         ~CLandmarksEngine();
00049 
00050     public: // New functions
00051 
00052         /**
00053         * StartInitializeDbIfNecessaryL indicates if the default database needs
00054         * to be initialised before it can be used. If it needs to be
00055         * initialized the initialization is started immediately and the
00056         * supplied observer is notified when initialization is ready.
00057         *
00058         * @param aObserver the observer to be notified when initialization is
00059         * ready
00060         * @return ETrue if initializing is necessary, EFalse otherwise
00061         */
00062         TBool StartInitializeDbIfNecessaryL(MLandmarksOperationObserver* aObserver);
00063 
00064         /**
00065         * AddLandmarkL adds a landmark to the database.
00066         *
00067         * @param aLandmark the landmark to add
00068         */
00069         void AddLandmarkL(CPosLandmark& aLandmark);
00070 
00071         /**
00072         * CommitLandmarkL commits a modified landmark.
00073         *
00074         * @param aLandmark the landmark to commit
00075         */
00076         void CommitLandmarkL(const CPosLandmark& aLandmark);
00077 
00078         /**
00079         * DeleteLandmarkL deletes a landmark.
00080         *
00081         * @param aItemId the itemId identifying the landmark to be deleted
00082         */
00083         void DeleteLandmarkL(TPosLmItemId aItemId);
00084 
00085         /**
00086         * LandmarkLC reads all fields of a landmark in the default
00087         * landmark database. Ownership of the returned landmark is transferred
00088         * to the caller.
00089         *
00090         * @param aItemId the ItemId identifying the landmark
00091         * @return a landmark
00092         */
00093         CPosLandmark* LandmarkLC(TPosLmItemId aItemId);
00094 
00095         /**
00096         * StartSearchingLandmarksL starts an asynchronous search operation for
00097         * landmarks. When the search completes the supplied observer is
00098         * notified and it is supposed to fetch the matches by calling
00099         * @ref FetchLandmarkSearchResult. All landmarks in the database are
00100         * returned.
00101         *
00102         * @param aObserver the observer that is notified when the search
00103         * operation completes
00104         */
00105         void StartSearchingLandmarksL(
00106             MLandmarksOperationObserver* aObserver);
00107 
00108         /**
00109         * StartSearchingLandmarksL starts an asynchronous search operation for
00110         * landmarks. The names of the landmarks are uses as criterion for a
00111         * match. When the search completes the supplied observer is notified
00112         * and it is supposed to fetch the matches by calling
00113         * @ref FetchLandmarkSearchResult.
00114         *
00115         * @param aSearchPattern search pattern to compare landmarks against
00116         * @param aSearchOnlyInPreviousMatches boolean indicating that only
00117         * previous matches should be searched
00118         * @param aObserver the observer that is notified when the search
00119         * operation completes
00120         */
00121         void StartSearchingLandmarksL(
00122             const TDesC& aSearchPattern,
00123             TBool aSearchOnlyInPreviousMatches,
00124             MLandmarksOperationObserver* aObserver);
00125 
00126         /**
00127         * FetchSearchResultL should be called after a successful
00128         * landmark search operation. It returns the matches from the
00129         * previous landmark search operation. Ownership of the returned array
00130         * is kept by this class.
00131         *
00132         * @return an array containing matches from a previous landmark search
00133         * operation
00134         */
00135         RArray<TPosLmItemId>* FetchSearchResult();
00136 
00137         /**
00138         * StartReadingLandmarksL should be called after a successful
00139         * landmark search operation. It continously reads a number of landmarks
00140         * partially, i.e. only the name and the icon of the landmarks are read,
00141         * until all landmarks found in a previous search operation are read.
00142         * The method is asynchronous and every time a number of landmarks are
00143         * read the supplied observer is notified, @ref FetchLandmarksLC should
00144         * be called to fetch the read landmarks.
00145         *
00146         * @param aNrOfItemsToReadPerBundle the number of items to read before
00147         * notifying the supplied observer
00148         * @param aObserver the observer that is notified every time a bundle of
00149         * landmarks are read
00150         */
00151         void StartReadingLandmarksL(
00152             TInt aNrOfItemsToReadPerBundle,
00153             MLandmarksOperationObserver* aObserver);
00154 
00155         /**
00156         * FetchLandmarksLC should be called after a successful landmark read
00157         * operation. It returns the landmarks that were partially read during a
00158         * preceding landmark read operation. Ownership of the returned array
00159         * is transferred to the caller.
00160         *
00161         * @return an array containing partially read landmarks from a previous
00162         * read operation
00163         */
00164         CArrayPtr<CPosLandmark>* FetchLandmarksLC();
00165 
00166 
00167     protected: // From CActive
00168 
00169         /**
00170         * Handles an active object’s request completion event.
00171         */
00172         void RunL();
00173 
00174         /**
00175         * Implements cancellation of an outstanding request.
00176         */
00177         void DoCancel();
00178 
00179         /**
00180         * Handles a leave occurring in the request completion event
00181         * handler RunL().
00182         *
00183         * @return KErrNone
00184         */
00185         TInt RunError(TInt aError);
00186 
00187     private: // New functions
00188 
00189         /**
00190         * C++ constructor.
00191         *
00192         * @param aDb an instance of the default landmark database
00193         */
00194         CLandmarksEngine(CPosLandmarkDatabase& aDb);
00195 
00196         /**
00197         * By default Symbian 2nd phase constructor is private.
00198         */
00199         void ConstructL();
00200 
00201         /**
00202         * ReadSomeLandmarksL reads a number of landmarks. The number of
00203         * landmarks is specified when initiating an asynchronous landmark read
00204         * operation.
00205         */
00206         void ReadSomeLandmarksL();
00207 
00208         /**
00209         * NotifyOperationReadyL notifies the observer of an asynchronous
00210         * operation that the operation has completed.
00211         *
00212         * @param aOperation the kind of operation that is finished
00213         * @param aErrorCode the complete code the operation returned
00214         */
00215         void NotifyOperationReadyL(TOperation aOperation, TInt aErrorCode);
00216 
00217         /**
00218         * Fetches the matches after a search operation and populates the data
00219         * member @ref iItemIds
00220         */
00221         void PopulateItemIdArrayL();
00222 
00223     private: // Data
00224 
00225         //! an array containing the item Ids of the last search
00226         RArray<TPosLmItemId> iItemIds;
00227 
00228         //! the observer to notify the progress asynchronous operations
00229         MLandmarksOperationObserver* iObserver;
00230 
00231         //! keeps track of which type of operation is executed
00232         TOperation iActiveOperation;
00233 
00234         //! keeps track of which item to read
00235         TInt iCurrentItemId;
00236 
00237         //! keeps track of how many items to read per bundle
00238         TInt iNrOfItemsToRead;
00239 
00240         //! indicates if there is any previous result to search
00241         TBool iSearchResultExists;
00242 
00243         /** indicates if the current search operation has been carried
00244         out with or without search pattern */
00245         TBool iFilterSearch;
00246 
00247         //! defines the sort preferences for this engine
00248         TPosLmSortPref iSortPref;
00249 
00250     };
00251 
00252 #endif // __LANDMARKS_ENGINE_H__
00253 
00254 // End of File
00255 

© Nokia 2006

Back to top