locationdataharvester/mylocationsengine/inc/mylocationsengine.h
changeset 17 0f22fb80ebba
child 20 cd10d5b85554
equal deleted inserted replaced
15:13ae750350c9 17:0f22fb80ebba
       
     1 /*
       
     2 * Copyright (c) 2010 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: Mylocation engine header implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __MYLOCATIONSENGINE_H__
       
    20 #define __MYLOCATIONSENGINE_H__
       
    21 
       
    22 // INCLUDES
       
    23 
       
    24 // calendar related headers
       
    25 #include <calsession.h>
       
    26 #include <calentryview.h>
       
    27 
       
    28 // Header for contact DB
       
    29 #include <CNTDB.H>
       
    30 
       
    31 // Header for landmarks db
       
    32 #include<epos_cposlandmarkdatabase.h>
       
    33 
       
    34 // mylocations database manager
       
    35 #include "maptileinterface.h"
       
    36 #include "mylocationsdatabasemanager.h"
       
    37 #include "lookupmaptiledb.h"
       
    38 #include "addresscomparision.h"
       
    39 #include "calendernotification.h"
       
    40 
       
    41 /**  
       
    42  * This class contains the required data  for maptile image  processing.
       
    43  * Each  address added/modified in contact database will be added as queue
       
    44  * using this class for maptile processing.
       
    45  */
       
    46 class CMapTileRequest: public CBase
       
    47 {
       
    48 public:
       
    49     //Consturctor
       
    50     CMapTileRequest():iLandmarkInfo(NULL),iAddressDetails(NULL){};
       
    51     //Destrucotr
       
    52     ~CMapTileRequest(){delete iLandmarkInfo;delete iAddressDetails;};
       
    53 public:
       
    54     //Landmark contains address details
       
    55     CPosLandmark* iLandmarkInfo;
       
    56     //single row address.
       
    57     HBufC* iAddressDetails;
       
    58     //Contact id
       
    59     TInt32 iUId;
       
    60     //Address type 
       
    61     TInt32 iAddressType;
       
    62     //Image path 
       
    63     TFileName iImagePath;
       
    64     //Event type    
       
    65     TInt iEventType;
       
    66 };
       
    67 
       
    68 // CLASS DECLARATION
       
    69 /**  Class used to listen on various database change events from applications like calendar, 
       
    70  * contacts, landmarks
       
    71  * 
       
    72  * This class listens on database change events from applications like contacts, calendar, landmarks
       
    73  * and triggers updating the Mylocations database accordingly. 
       
    74  * This process starts on phone bootup and always runs in the background.
       
    75  */
       
    76 class CMyLocationsEngine : public CActive, public MCalChangeCallBack2,
       
    77 				 public MContactDbObserver, public MMapTileObserver,public MNotifyChange
       
    78 			
       
    79 {
       
    80     
       
    81 public:
       
    82     
       
    83     /** 
       
    84      * Contact address types
       
    85      */
       
    86     enum TContactAddressType
       
    87         {
       
    88         /** Address Type Pref */
       
    89         EAddressPref,
       
    90         /** Address type Work */
       
    91         EAddressWork,
       
    92         /** Address type Home */
       
    93         EAddressHome,
       
    94         };
       
    95 
       
    96 public:
       
    97 
       
    98     /** 
       
    99      * CMyLocationsEngine::NewL()
       
   100      */
       
   101     static CMyLocationsEngine* CMyLocationsEngine::NewL();
       
   102     
       
   103     /**
       
   104      * ~CMyLocationsEngine.
       
   105      * Virtual Destructor.
       
   106      */
       
   107     virtual ~CMyLocationsEngine();
       
   108     
       
   109     /** Starts calender change notification method to get callbacks when entries are added/modified/deleted in calender
       
   110      *
       
   111      */      
       
   112     void StartCalenderChangeNotifierL();
       
   113 
       
   114     /** Starts contacts change notification method to get callbacks when entries are added/modified/deleted in contacts
       
   115      *
       
   116      */      
       
   117     void StartContactsChangeNotifierL();
       
   118 
       
   119     /** Starts landmarks change notification method to get callbacks when entries are added/modified/deleted in landmarks
       
   120      *
       
   121      */      
       
   122     void StartLandmarksChangeNotifier();
       
   123     
       
   124     /** Maps the source type change type to Mylocations entry change type
       
   125     * @param[in] aSrcType Source type of the change
       
   126     * @param[in] aChangeType Type of change ( added/modified/deleted ).
       
   127     * @return The mylocations entry change type value.
       
   128      */      
       
   129     TEntryChangeType MapChangeType( TUidSourceType aSrcType, TUint32 aChangeType );    
       
   130  
       
   131     /** Gets the handle to mylocations database manager
       
   132      *
       
   133      */      
       
   134     CMyLocationsDatabaseManager& MyLocationsDbManager();
       
   135 
       
   136 private:
       
   137     
       
   138     /**
       
   139      * ConstructL.
       
   140      * 2nd phase constructor.
       
   141      */
       
   142     void ConstructL();
       
   143     
       
   144     /**
       
   145      * CMyLocationsEngine.
       
   146      * C++ default constructor. 
       
   147      */
       
   148     CMyLocationsEngine();
       
   149     
       
   150     /** Creates a landmark object from contact item's location details and checks whether address available.
       
   151     * @param[in] aContactItem A contact item whose location details needs to be used to create landmark object.
       
   152     * @param[in] aAddressType Mentions the address type ( prefered/work/home ) of the contact item to be used.
       
   153     * @returns A valid landmark object if location in the contact item is validated, NULL otherwise.
       
   154      */      
       
   155     CPosLandmark* GetContactAddressDetailsLC( const CContactItem *aContactItem, 
       
   156             TContactAddressType aAddressType );
       
   157             
       
   158     /** Creates a landmark object from contact item's location details
       
   159     * @param[in] aContactItem A contact item whose location details needs to be used to create landmark object.
       
   160     * @param[in] aAddressType Mentions the address type ( prefered/work/home ) of the contact item to be used.
       
   161     * @returns A valid landmark object if location in the contact item is validated, NULL otherwise.
       
   162     */    
       
   163     CPosLandmark* GetContactLocationDetailsLC( const CContactItem *aContactItem, 
       
   164            TContactAddressType aAddressType );
       
   165 
       
   166     /** Finds the contact's field type id
       
   167     * @param[in] aContactItem A contact item whose field details needs to found.
       
   168     * @param[in] aAddressType Mentions the address type ( prefered/work/home ) of the contact item to be used.
       
   169     * @param[in] aField The field type of interest.
       
   170     * @return If found, the index of the field within the field set, or KErrNotFound if not found.
       
   171     */      
       
   172     TInt FindContactsField( const CContactItem *aContactItem, TContactAddressType aAddressType, 
       
   173             TUid aField );
       
   174 
       
   175     /**
       
   176      *  A call back function for calendar change notification
       
   177 	 *	@param aChangeItems  List of changes since the last notification.	
       
   178 	 */      
       
   179     virtual void CalChangeNotification( RArray<TCalChangeEntry>& aChangeItems );
       
   180     
       
   181     /** Tests the contact database observer event type and handles it. The ID of a 
       
   182     * contact affected by the change event, if relevant, can be retrieved via TContactDbObserverEvent::iContactId.
       
   183     * @param aEvent Provides information about the change event. 
       
   184     */
       
   185     virtual void HandleDatabaseEventL( TContactDbObserverEvent aEvent );
       
   186     
       
   187     /** 
       
   188      * Triggers the maptile processing for complete address
       
   189      * @param aEvent  Provides information about the change event.   
       
   190      */      
       
   191 	void TriggerMaptileRequestL(  TContactDbObserverEvent& aEvent  );
       
   192 			
       
   193     /** 
       
   194      * Process the contact database event and updates the landmark database
       
   195      * @param aEvent  Provides information about the change event.   
       
   196      */      
       
   197 	void HandlelandmarkDatabaseL( TContactDbObserverEvent& aEvent );
       
   198     /** 
       
   199     * Process the maptile database event and updates the maptile database
       
   200     * @param aEventType  Provides information about the type of request address.
       
   201     * @param aLookupItem Provides information about single address of contact.  
       
   202     */  
       
   203 	void HandleMaptileDatabaseL(TInt aEventType ,
       
   204 	                             TLookupItem& aLookupItem );
       
   205     /**
       
   206      *  Handles active object's request completion event. 
       
   207      */
       
   208     void RunL();
       
   209 
       
   210     /** 
       
   211      * Implements cancellation of an outstanding request. 
       
   212      */
       
   213     void DoCancel();
       
   214  
       
   215     /** 
       
   216      * Implements RunError of active object. 
       
   217      */
       
   218     TInt RunError( TInt aError );
       
   219     
       
   220     /** 
       
   221      * Requests for map tile image , structure serch.
       
   222      * @param aLandmark  Provides information about the address.
       
   223      * @param aAddressType Provides information about address type .  
       
   224      * @param aUId, uid of the event.
       
   225      */
       
   226     void RequestMapTileImageL( CPosLandmark&  aLandmark, const TUidSourceType aAddressType,
       
   227                                const TInt32 aUId  );
       
   228     
       
   229     /** 
       
   230      * Requests for map tile image , one box serch.
       
   231      * @param aAddressDetails  Provides information about the address.
       
   232      * @param aAddressType Provides information about address type .  
       
   233      * @param aUId, uid of the event.
       
   234      */
       
   235     void RequestMapTileImageL(const TDesC& aAddressDetails,
       
   236             const TUidSourceType aAddressType, const TInt32 aUId);
       
   237     
       
   238     /** 
       
   239      * Add to maptile request queue.
       
   240      * @param mapTileRequest, request queue.
       
   241      * @return If successful, retrun KErrNone, or return some systemwide error.
       
   242      */
       
   243     TInt RequestExecute( CMapTileRequest* aMapTileRequest);
       
   244 	/**
       
   245     * SetFolderPath.
       
   246     * Sets the maptile storing path.
       
   247     */
       
   248     void SetFolderPathL();
       
   249     /**
       
   250     * Calender entry added.
       
   251     */
       
   252     void CalenderEntryAddedL(TCalChangeEntry aCalChangeEntry);
       
   253 
       
   254 public:  //From MMapTileObserver
       
   255     
       
   256     /**
       
   257      *  Informs the maptile fetching completion  
       
   258      */ 
       
   259     void MapTilefetchingCompleted( TInt aErrCode,const TDesC& aMapTilePath );
       
   260     
       
   261     /** 
       
   262      * Informs the geocode completion
       
   263      */
       
   264     void RestGeoCodeCompleted( TReal latitude,TReal longitude);
       
   265     
       
   266 public://from MNotifychange
       
   267     void NotifyChangeL(TInt &aStatus);
       
   268     
       
   269 private:
       
   270 
       
   271     // Data member
       
   272     
       
   273     //handle to timer class
       
   274     //calendar session handle
       
   275     CCalSession *iCalSession;
       
   276     
       
   277     // calendar view
       
   278     CCalEntryView *iCalView;   
       
   279 
       
   280     // Handle to the contacts database
       
   281     CContactDatabase* iContactsDb;
       
   282     
       
   283     // Receives events reporting changes to a contact database.
       
   284     CContactChangeNotifier *iContactChangeNotifier;
       
   285     
       
   286     // Handle to landmarks db
       
   287     CPosLandmarkDatabase* iLandmarkDb;
       
   288     
       
   289     // landmark change event type.
       
   290     TPosLmEvent iLmEvent;
       
   291    
       
   292     //Handle to maptile interface
       
   293     CMapTileInterface* iMapTileInterface;
       
   294     
       
   295     CMyLocationsDatabaseManager*  iMyLocationsDatabaseManager;
       
   296     
       
   297     //maptiledb 
       
   298     CLookupMapTileDatabase* iMaptileDatabase;
       
   299 
       
   300     //Current event type
       
   301     TInt iEventType;
       
   302     
       
   303     //Address comparison pointer
       
   304     CAddressComparision *iAddressCompare;
       
   305     
       
   306     //Maptile image request queue
       
   307     RArray<CMapTileRequest*> iMapTileRequestQueue;
       
   308     
       
   309     //Flag to check maptilegeocoder plugin availability
       
   310     TBool iMaptileGeocoderPluginAvailable;
       
   311 	
       
   312 	//Maptile image path
       
   313     TFileName imageFilePath;
       
   314     //Object to listen calender db create notification.    
       
   315     CCalenderNotification  *iCalenderNotification;
       
   316     
       
   317 };
       
   318 
       
   319 #endif // __MYLOCATIONSENGINE_H__
       
   320 // End of File