locationmanager/locationtrail/inc/clocationrecord.h
changeset 0 c53acadfccc6
child 3 b73a2e62868f
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2006-2009 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:  A class for recording and storing locations.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef C_CLOCATIONRECORD_H
       
    19 #define C_CLOCATIONRECORD_H
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <e32property.h>
       
    23 #include <Lbs.h>
       
    24 
       
    25 #include "rlocationtrail.h"
       
    26 #include "locationdatatype.h"
       
    27 #include "cnetworkinfo.h"
       
    28 #include "cpositioninfo.h"
       
    29 #include "rlocationobjectmanipulator.h"
       
    30 
       
    31 #include "mdccommon.h"
       
    32 #include "mdesession.h"
       
    33 #include "mdenamespacedef.h"
       
    34 #include "mdeobjectdef.h"
       
    35 #include "mdepropertydef.h"
       
    36 #include "mderelation.h"
       
    37 #include "mdequery.h"
       
    38 #include "locationremappingao.h"
       
    39 
       
    40 typedef RLocationTrail::TTrailState TLocTrailState;
       
    41 
       
    42 class CTelephony;
       
    43 class TPositionSatelliteInfo;
       
    44 
       
    45 /**
       
    46 *  An observer interface, which is used for getting notification when the 
       
    47 *  location trail's state changes.    
       
    48 *
       
    49 *  @since S60 3.1
       
    50 */
       
    51 class MLocationTrailObserver
       
    52     {
       
    53 public:    
       
    54     /**
       
    55      * This method is used to notify about location trail state changes.
       
    56      */
       
    57     virtual void LocationTrailStateChange() = 0;
       
    58     
       
    59     virtual void CurrentLocation( const TPositionSatelliteInfo& aSatelliteInfo, 
       
    60     							  const CTelephony::TNetworkInfoV1& aNetworkInfo,
       
    61                                   const TInt aError ) = 0;
       
    62     
       
    63     virtual void GPSSignalQualityChanged( const TPositionSatelliteInfo& aSatelliteInfo ) = 0;
       
    64     };
       
    65 
       
    66 /**
       
    67 * Location trail item class.
       
    68 */
       
    69 class TLocationTrailItem
       
    70     {
       
    71     public:
       
    72     	TLocationData	iLocationData; // Location info & network info
       
    73         TTime           iTimeStamp;  // Time stamp.
       
    74         TLocTrailState  iTrailState; // Trail state for this item.
       
    75     };
       
    76     
       
    77 class MLocationAddObserver
       
    78 	{
       
    79 public:
       
    80 	/**
       
    81 	 * This method is used to notify about new locations added to location trail
       
    82 	 */
       
    83 	virtual void LocationAdded( const TLocationTrailItem& aTrailItem, 
       
    84 								const TPositionSatelliteInfo& aSatellites ) = 0;
       
    85 	};    
       
    86 
       
    87 /**
       
    88  *  Location trail collects location information periodically and stores them
       
    89  *  to an array. Stored locations may be searched by time stamp to get 
       
    90  *  a location, which corresponds to certain time.  
       
    91  *
       
    92  *  @since S60 3.1
       
    93  */
       
    94 class CLocationRecord : public CBase,
       
    95                         public MNetworkInfoObserver,
       
    96                         public MPositionInfoObserver,
       
    97                         public MMdEQueryObserver
       
    98     {
       
    99 public:  
       
   100     /**
       
   101      * 2-phased constructor.
       
   102      * @since S60 3.1
       
   103      */
       
   104     IMPORT_C static CLocationRecord* NewL();
       
   105 
       
   106     /**
       
   107      * C++ destructor.
       
   108      * @since S60 3.1
       
   109      */    
       
   110     IMPORT_C virtual ~CLocationRecord();
       
   111 
       
   112     
       
   113 public:
       
   114     /**
       
   115      * Returns the current state of the location trail.
       
   116      * @since S60 3.1
       
   117      * @param aState, The current state is written to this variable.
       
   118      * @return None.
       
   119      */    
       
   120     IMPORT_C void LocationTrailState( TLocTrailState& aState );
       
   121     
       
   122     /**
       
   123      * Starts collecting locations from Location Acquisition API.
       
   124      * @since S60 3.1
       
   125      * @param None.
       
   126      * @return None.
       
   127      */    
       
   128     IMPORT_C void StartL( RLocationTrail::TTrailCaptureSetting aCaptureSetting );
       
   129     
       
   130     /**
       
   131      * Stops collecting locations.
       
   132      * @since S60 3.1
       
   133      * @param None.
       
   134      * @return None.
       
   135      */    
       
   136     IMPORT_C void Stop();    
       
   137 
       
   138     /**
       
   139      * Returns the location info, which is nearest to the given time.
       
   140      * @since S60 3.1
       
   141      * @param aTime, A time stamp to get corresponding location.
       
   142      * @param aPosition, Location info is written to this param.
       
   143      * @param 
       
   144      * @return None.
       
   145      */
       
   146     IMPORT_C void GetLocationByTimeL( const TTime aTime,
       
   147     								  TLocationData& aLocationData,
       
   148                                       /*TLocality& aPosition,
       
   149                                       CTelephony::TNetworkInfoV1& aNetworkInfo,*/
       
   150                                       TLocTrailState& aState );
       
   151 
       
   152     /**
       
   153      * Request location info. The result is returned by calllback method.
       
   154      * @since S60 3.1
       
   155      * @param None.
       
   156      * @return None.
       
   157      */
       
   158     IMPORT_C void RequestLocationL();
       
   159 
       
   160     /**
       
   161      * Cancel request for location info. 
       
   162      * @since S60 3.1
       
   163      * @param None.
       
   164      * @return None.
       
   165      */    
       
   166     IMPORT_C void CancelLocationRequest();
       
   167         
       
   168     /**
       
   169      * Get network cell id.
       
   170      * @since S60 3.1
       
   171      * @param aCellId, Network cell is written into this param.
       
   172      * @return None.
       
   173      */
       
   174     IMPORT_C void GetNetworkInfo( CTelephony::TNetworkInfoV1& aNetworkInfo );
       
   175     
       
   176     /**
       
   177      * Set observer for notifying state changes.
       
   178      * @since S60 3.1
       
   179      * @param aObserver, An interface to notify about state changes.
       
   180      * @return None.
       
   181      */
       
   182     IMPORT_C void SetObserver( MLocationTrailObserver* aObserver );
       
   183     
       
   184     /**
       
   185      * Set observer (TrackLog) for notifying new locations in location trail
       
   186      */
       
   187     IMPORT_C void SetAddObserver( MLocationAddObserver* aObserver );    
       
   188     
       
   189     static TInt UpdateNetworkInfo( TAny* aAny );
       
   190     
       
   191     IMPORT_C void CreateLocationObjectL( const TLocationData& aLocationData,
       
   192     		const TUint& aObjectId );
       
   193     
       
   194     IMPORT_C void LocationSnapshotL( const TUint& aObjectId );
       
   195     
       
   196     TItemId DoCreateLocationL( const TLocationData& aLocationData );
       
   197     
       
   198     TItemId CreateRelationL( const TUint& aObjectId, const TUint& aLocationId );
       
   199     
       
   200     IMPORT_C void SetMdeSession( CMdESession* aSession );
       
   201     
       
   202     IMPORT_C void SetStateToStopping();
       
   203     
       
   204     TTime GetMdeObjectTimeL( TItemId aObjectId );
       
   205     
       
   206     IMPORT_C TBool RemappingNeeded();
       
   207 
       
   208 public: // from MNetworkInfoObserver.
       
   209     /**
       
   210      * 
       
   211      * @since S60 3.1
       
   212      * @param 
       
   213      * @return 
       
   214      */
       
   215     void NetworkInfo( const CTelephony::TNetworkInfoV1 &aNetworkInfo, TInt aError );
       
   216     
       
   217 public: // from MPositionInfoObserver    
       
   218     /**
       
   219      * 
       
   220      * @since S60 3.1
       
   221      * @param 
       
   222      * @return  
       
   223      */
       
   224     void Position( const TPositionInfo& aPositionInfo, const TInt aError );
       
   225     
       
   226     
       
   227 public: // From MMdEQueryObserver
       
   228 
       
   229 	void HandleQueryNewResults(CMdEQuery& aQuery, TInt aFirstNewItemIndex, 
       
   230 			TInt aNewItemCount);
       
   231 	
       
   232 	void HandleQueryCompleted(CMdEQuery& aQuery, TInt aError);
       
   233 	
       
   234 private:    
       
   235     /**
       
   236      * Stores the location info into the array.
       
   237      */
       
   238     void StoreLocation( /*const TPosition& aPosition, const TCourse& aCourse,*/ 
       
   239     		const TPositionSatelliteInfo& aSatelliteInfo );
       
   240     
       
   241     /**
       
   242      * Changes the current state. New state is published in P&S and
       
   243      * possible observer is notified.
       
   244      */    
       
   245     void SetCurrentState( TLocTrailState aState );
       
   246     
       
   247     /**
       
   248      * Returns the requested location via callback method, if the location
       
   249      * is valid. Otherwise new location value is requested until the value
       
   250      * is succesful, or the time out limit has been reached.
       
   251      * 
       
   252      */
       
   253     void HandleLocationRequest( const TPositionSatelliteInfo& aSatelliteInfo /*TLocality& aPosition*/, 
       
   254                                 const TInt aError );
       
   255     /**
       
   256      * C++ constructor.
       
   257      */  
       
   258     CLocationRecord();
       
   259     
       
   260     /**
       
   261      * 2nd phase constructor.
       
   262      */
       
   263     void ConstructL();
       
   264     
       
   265     /**
       
   266      * Read interval value from Central repository
       
   267      * @param aKey, Key to item
       
   268      * @param aValue, Read value
       
   269      */ 
       
   270     void ReadCenRepValueL(TInt aKey, TInt& aValue);
       
   271     
       
   272     TBool CheckGPSFix( const TPositionSatelliteInfo& aSatelliteInfo );
       
   273     
       
   274     void StartTimerL();
       
   275 
       
   276 private:
       
   277 	/**
       
   278 	 * A session to Metadata Engine for creating and manipulating location objects.
       
   279 	 */
       
   280 	CMdESession* iMdeSession;
       
   281 	
       
   282     /**
       
   283      * An observer interface to notify about state changes.
       
   284      * Not own.
       
   285      */
       
   286     MLocationTrailObserver* iObserver;
       
   287     
       
   288     /**
       
   289      * An observer interface to notify about new locations.
       
   290      * Not own.
       
   291      */
       
   292     MLocationAddObserver* iAddObserver;    
       
   293 
       
   294     /**
       
   295      * An array to collect location values.
       
   296      * Own.
       
   297      */
       
   298     RArray<TLocationTrailItem> iTrail;
       
   299 
       
   300     /**
       
   301      * P&S key property.
       
   302      * Own.
       
   303      */
       
   304     RProperty iProperty;
       
   305 
       
   306     /**
       
   307      * Active class to get network information.
       
   308      * Own.
       
   309      */
       
   310     CNetworkInfo* iNetworkInfo;
       
   311     
       
   312     /**
       
   313      * Active class to get position information.
       
   314      * Own.
       
   315      */
       
   316     CPositionInfo* iPositionInfo;
       
   317     
       
   318 	/**
       
   319 	 * Class which handles database remapping operations
       
   320 	 */ 
       
   321 	CLocationRemappingAO* iRemapper;
       
   322     
       
   323     CActiveSchedulerWait   iWait;
       
   324     
       
   325     /**
       
   326      * Timer for capturing network info only
       
   327      */
       
   328     CPeriodic*			   iNetworkInfoTimer;
       
   329 
       
   330     TLocTrailState         iState;    
       
   331     TLocationTrailItem     iNewItem;
       
   332     RLocationTrail::TTrailCaptureSetting   iTrailCaptureSetting;
       
   333     CTelephony::TNetworkInfoV1		   iNetwork;
       
   334 
       
   335     TInt                   iMaxTrailSize;
       
   336     TInt                   iLocationCounter;
       
   337     
       
   338     /*
       
   339      * Interval value for location trail
       
   340      */
       
   341     TInt iInterval;
       
   342     
       
   343     /**
       
   344      * Buffer size for tracklog
       
   345      */ 
       
   346     TInt iBufferSize;
       
   347     
       
   348     TBool                  iRequestCurrentLoc;
       
   349     TBool                  iTrailStarted;
       
   350     
       
   351     TUint				   iLastNumberOfSatellitesUsed;
       
   352     TReal32				   iLastHDOP;
       
   353     TReal32				   iLastVDOP;
       
   354     TBool				   iLastGPSFixState;
       
   355     
       
   356     TInt                   iLocationDelta;
       
   357     TLocationData          iLastLocation;
       
   358     TItemId                iLastLocationId;
       
   359     
       
   360     TItemId iObjectId;               
       
   361     TLocationData iLocationData;
       
   362     
       
   363     /**
       
   364      * This query object is used to find existing locations
       
   365      */
       
   366     CMdEObjectQuery* iLocationQuery;
       
   367     };
       
   368 
       
   369 #endif // C_CLOCATIONRECORD_H 
       
   370 
       
   371 // End of file.