locationmanager/server/inc/clocationmanagerserver.h
changeset 0 c53acadfccc6
child 1 acef663c1218
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:  Header file for Location Manager Server.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef C_CLOCATIONMANAGERSERVER_H
       
    19 #define C_CLOCATIONMANAGERSERVER_H
       
    20 
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <etel3rdparty.h>
       
    24 #include <centralrepository.h>
       
    25 #include <locationdatatype.h>
       
    26 #include <locationeventdef.h>
       
    27 
       
    28 #include "rlocationtrail.h"
       
    29 #include "rlocationobjectmanipulator.h"
       
    30 #include "clocationrecord.h"
       
    31 #include "ctracklog.h"
       
    32 #include "mdeconstants.h"
       
    33 #include "mdsutils.h"
       
    34 #include "mdesession.h"
       
    35 #include "mdequery.h"
       
    36 #include "mderelationquery.h"
       
    37 #include "locationmanagerdefs.h"
       
    38 
       
    39 
       
    40 class CMdESession;
       
    41 
       
    42 // Total number of ranges
       
    43 const TUint KLocationManagerRangeCount = 1;
       
    44 
       
    45 // Definition of the ranges of IPC numbers
       
    46 const TInt KLocationManagerRanges[KLocationManagerRangeCount] = 
       
    47     {
       
    48     0,
       
    49     }; 
       
    50 
       
    51 // Policy to implement for each of the above ranges        
       
    52 const TUint8 KLocationManagerElementsIndex[KLocationManagerRangeCount] = 
       
    53     {
       
    54     0,
       
    55     };
       
    56 
       
    57 const CPolicyServer::TPolicyElement KLocationManagerPolicyElements[] = 
       
    58     {
       
    59     { _INIT_SECURITY_POLICY_C3(ECapabilityReadUserData,
       
    60                                ECapabilityWriteUserData,
       
    61                                ECapabilityLocation),
       
    62                                CPolicyServer::EFailClient }
       
    63     };
       
    64 
       
    65 // Package all the above together into a policy
       
    66 const CPolicyServer::TPolicy KLocationManagerPolicy =
       
    67     {
       
    68     CPolicyServer::EAlwaysPass,     // all attempts should pass
       
    69     KLocationManagerRangeCount,     // number of ranges
       
    70     KLocationManagerRanges,         // ranges array
       
    71     KLocationManagerElementsIndex,  // elements<->ranges index
       
    72     KLocationManagerPolicyElements, // array of elements
       
    73     };
       
    74     
       
    75 class CLocationRecord;
       
    76 //class CLocationWrite;
       
    77 
       
    78 /**
       
    79 *  A server class to initialize server. 
       
    80 *
       
    81 *  @since S60 3.1
       
    82 */
       
    83 class CLocationManagerServer : public CPolicyServer,
       
    84                                public MLocationTrailObserver,
       
    85                                public MMdESessionObserver,
       
    86                                public MMdEQueryObserver,
       
    87                                public MMdEObjectObserver,
       
    88                                public MGpxConversionObserver
       
    89     {
       
    90 private:
       
    91 	struct TMessageQuery
       
    92 		{
       
    93 		CMdERelationQuery* iQuery;
       
    94 		const RMessage2& iMessage;
       
    95 		
       
    96 		TMessageQuery( CMdERelationQuery* aQuery, const RMessage2& aMessage ) 
       
    97 			:  iQuery ( aQuery ), iMessage( aMessage ) { }
       
    98 		};
       
    99     
       
   100 public:
       
   101     /**
       
   102     * 2-phased constructor.
       
   103     */
       
   104     static CLocationManagerServer* NewLC();
       
   105     
       
   106     /**
       
   107     * C++ destructor.
       
   108     */ 
       
   109     virtual ~CLocationManagerServer();
       
   110   
       
   111 public:
       
   112     /**
       
   113     * From CServer2, creates a new session.
       
   114     */
       
   115     CSession2* NewSessionL( const TVersion& aVersion, 
       
   116                             const RMessage2& aMessage ) const;
       
   117 
       
   118 public: // From MMdESessionObserver
       
   119 	void HandleSessionOpened(CMdESession& aSession, TInt aError);
       
   120     void HandleSessionError(CMdESession& aSession, TInt aError);
       
   121     
       
   122 public: // From MMdEQueryObserver
       
   123 	void HandleQueryNewResults(CMdEQuery& aQuery, TInt aFirstNewItemIndex, TInt aNewItemCount);
       
   124 	void HandleQueryCompleted(CMdEQuery& aQuery, TInt aError);
       
   125 
       
   126 public:
       
   127     /**
       
   128      * Increase session count.
       
   129      * @since S60 3.1
       
   130      * @param None.
       
   131      * @return None.
       
   132      */
       
   133     void AddSession();
       
   134     
       
   135     /**
       
   136      * Decrease session count, close server if count is zero.
       
   137      * @since S60 3.1
       
   138      * @param None.
       
   139      * @return None.
       
   140      */
       
   141     void RemoveSession();
       
   142 
       
   143 public:
       
   144     /**
       
   145      * Starts to record locations to the trail.
       
   146      * @since S60 3.1
       
   147      * @param None.
       
   148      * @return None.
       
   149      */     
       
   150     void StartGPSPositioningL( RLocationTrail::TTrailCaptureSetting aCaptureSetting );
       
   151     
       
   152     /**
       
   153      * Stops trail recording.
       
   154      * @since S60 3.1
       
   155      * @param None.
       
   156      * @return None.
       
   157      */     
       
   158     void StopGPSPositioningL();
       
   159     
       
   160     /**
       
   161      * Gets the current state of the location trail.
       
   162      * @since S60 3.1
       
   163      * @param aState, The state of the trail is written to this param.
       
   164      * @return None.
       
   165      */     
       
   166     void GetLocationTrailState( RLocationTrail::TTrailState& aState );
       
   167     
       
   168     /**
       
   169      * Adds client's notification request to the request array.
       
   170      * @since S60 3.1
       
   171      * @param aNotifReq, asynchonous RMessage is stored to be completed
       
   172      *                   when the state of the trail changes.
       
   173      * @return None.
       
   174      */     
       
   175     void AddNotificationRequestL( const RMessage2& aNotifReq );
       
   176     
       
   177     /**
       
   178      * Add client's track log notification request to the request array.
       
   179      * @param aNotifReq, asynchonous RMessage is stored to be completed
       
   180      *                   when the state of the track log changes.
       
   181      * @return None.
       
   182      */
       
   183     void AddTrackLogNotificationRequestL( const RMessage2& aNotifReq );
       
   184     
       
   185     /**
       
   186      * Cancel notification request from client.
       
   187      * @since S60 3.1
       
   188      * @param aHandle, A handle of the request to be cancelled.
       
   189      * @return None.
       
   190      */     
       
   191     void CancelNotificationRequest( const TInt aHandle );
       
   192     
       
   193     /**
       
   194      * Get a location by time stamp.
       
   195      * @since S60 3.1
       
   196      * @param aTimeStamp, A time stamp to get corresponding location.
       
   197      * @param aPosition, Location info is written to this param.
       
   198      * @return None.
       
   199      */     
       
   200     void GetLocationByTimeL( const TTime& aTimeStamp, 
       
   201     						 TLocationData& aLocationData,
       
   202                              /*TLocality& aPosition, 
       
   203                              CTelephony::TNetworkInfoV1& aNetworkInfo,*/
       
   204                              TLocTrailState& aState );
       
   205 
       
   206     /**
       
   207      * Get current location.
       
   208      * @since S60 3.1
       
   209      * @param aCurrLocReq 
       
   210      * @return None.
       
   211      */     
       
   212     void RequestCurrentLocationL( const RMessage2& aCurrLocReq ); 
       
   213 
       
   214     /**
       
   215      * Cancel location request.
       
   216      * @since S60 3.1
       
   217      * @param aCurrLocReq 
       
   218      * @return None.
       
   219      */     
       
   220     void CancelLocationRequest( const TInt aHandle ); 
       
   221     
       
   222     /**
       
   223      * Cancel tracklog notification request.
       
   224      * @param aHandle
       
   225      * @return None.
       
   226      */
       
   227     void CLocationManagerServer::CancelTrackLogNotificationRequest( const TInt aHandle );
       
   228 
       
   229     /**
       
   230      * Get current network cell id.
       
   231      * @since S60 3.1
       
   232      * @param aCurrLocReq 
       
   233      * @return None.
       
   234      */     
       
   235     void GetCurrentNetworkInfo( CTelephony::TNetworkInfoV1& aNetworkInfo );
       
   236     
       
   237     /**
       
   238      * Create a location context object in DB and create relationships to objects
       
   239      * whose id is given in the array.
       
   240      * @param aLocationData
       
   241      * @param aObjectId
       
   242      */
       
   243 	void CreateLocationObjectL( const TLocationData& aLocationData, 
       
   244     						   	   const TUint& aObjectId );
       
   245 	
       
   246     /**
       
   247      * Create a location context object in DB and create relationships to objects
       
   248      * whose id is given in the array.
       
   249      * Location information is taken from location trail
       
   250      * @param aObjectId
       
   251      */
       
   252 	void LocationSnapshotL( const TUint& aObjectId );
       
   253 	
       
   254 	/**
       
   255 	 * Deletes the relationship between an object and 
       
   256 	 * the location context object associated with it.
       
   257 	 * @since S60 3.2
       
   258 	 * @param aObjectId
       
   259 	 * @return None.
       
   260 	 */ 
       
   261 	void RemoveLocationObjectL(TUint& aObjectId);
       
   262 	void CopyLocationObjectL( TItemId aSource, const RArray<TItemId>& aTargets, TMessageQuery& aQuery );
       
   263 	void CopyLocationObjectL( const TDesC& aSource, const RArray<TPtrC>& aTargets, TMessageQuery& aQuery );
       
   264 	
       
   265 	TBool IsSessionReady();
       
   266 	
       
   267 	TItemId StartTrackLogL();
       
   268 	
       
   269 	void StopTrackLogL();
       
   270 	
       
   271 	void IsTrackLogRecording( TBool &aRec );
       
   272 	
       
   273 	TInt GetTrackLogStatus( TBool& aRecording, TPositionSatelliteInfo& aFixQuality);
       
   274 	
       
   275 	TInt DeleteTrackLogL(const TDesC& aUri);
       
   276 	
       
   277 	TInt TrackLogName(TFileName& aFileName);
       
   278 	
       
   279 	void GetCaptureSetting( RLocationTrail::TTrailCaptureSetting& aCaptureSetting );
       
   280 	
       
   281 	void AddGpxObserver( MGpxConversionObserver* aObserver );
       
   282 	
       
   283 	void InitCopyLocationByIdL( const RMessage2& aMessage );
       
   284 	void InitCopyLocationByURIL( const RMessage2& aMessage );
       
   285 
       
   286 public: // from MLocationTrailObserver.
       
   287     /**
       
   288      * Callback method to get notification about trail state change.
       
   289      * @since S60 3.1
       
   290      * @param None.
       
   291      * @return None.
       
   292      */
       
   293     void LocationTrailStateChange();
       
   294     
       
   295     /**
       
   296      * Callback method to return current location.
       
   297      * @since S60 3.1
       
   298      * @param aSatelliteInfo, includes position and satellite info.
       
   299      * @param aNetworkInfo, network and cell info.
       
   300      * @param aError.
       
   301      * @return None.
       
   302      */
       
   303     void CurrentLocation( const TPositionSatelliteInfo& aSatelliteInfo,
       
   304     		const CTelephony::TNetworkInfoV1& aNetworkInfo, const TInt aError );
       
   305     
       
   306     /**
       
   307      * Callback method to notify observer of changes in GPS signal quality.
       
   308      * @param aSatelliteInfo, includes position and satellite info
       
   309      * @return None.
       
   310      */
       
   311     void GPSSignalQualityChanged( const TPositionSatelliteInfo& aSatelliteInfo );
       
   312     
       
   313 public: // from MMdeObjectObserver
       
   314 	/**
       
   315 	 * Called to notify the observer that new objects has been
       
   316 	 * added/modified/removed in the metadata engine database.
       
   317 	 *
       
   318 	 * @param aSession session
       
   319 	 * @param aType defines if object was added/modified/remove
       
   320 	 * @param aObjectIdArray IDs of added object
       
   321 	 */
       
   322 	void HandleObjectNotification( CMdESession& aSession, 
       
   323 						TObserverNotificationType aType,
       
   324 						const RArray<TItemId>& aObjectIdArray );
       
   325 	
       
   326 public: // from MGpxConversionObserver
       
   327 
       
   328 	void GpxFileCreated( const TDesC& aFileName, TItemId aTagId, TReal32 aLength,
       
   329 			TTime aStart, TTime aEnd );
       
   330 
       
   331 private:    
       
   332     /**
       
   333     * C++ constructor.
       
   334     */
       
   335     CLocationManagerServer();
       
   336     
       
   337     /**
       
   338     * 2nd phase constructor.
       
   339     */
       
   340     void ConstructL();
       
   341     
       
   342     void CopyLocationL( CMdEQuery& aQuery );
       
   343 
       
   344     /**
       
   345      * Go through all messages in lists, complete request
       
   346      * with KErrCancel status and remove items from list.
       
   347      */ 
       
   348     void CancelRequests(RArray<RMessage2>& aMessagesList);
       
   349     
       
   350     
       
   351     void CancelCopyRequests(RArray<TMessageQuery>& aMessageList);
       
   352     
       
   353     /**
       
   354      * Create a new tracklog tag object in the database.
       
   355      * @return TItemId tag ID in the database
       
   356      */ 
       
   357     TItemId CreateTrackLogTagL();
       
   358     
       
   359     /**
       
   360      * Create a new tracklog object in the database and link tracklog tag to it.
       
   361      * @param aTagId, tracklog tag id
       
   362      */ 
       
   363     void CreateTrackLogL( TItemId aTagId, const TDesC& aUri, TReal32 aLength,
       
   364     		TTime aStart, TTime aEnd );
       
   365     
       
   366     /**
       
   367      * Start listening for tracklog tag removals.
       
   368      */
       
   369     void StartListeningTagRemovalsL();
       
   370     
       
   371     /**
       
   372      * Start listening for media object creations.
       
   373      */
       
   374     void StartListeningObjectCreationsL();
       
   375     
       
   376     /**
       
   377      * Create a relationship between mediaobject(s) and a tracklog tag.
       
   378      * @param aObjectIdArray, array of media object ids
       
   379      */
       
   380     void LinkObjectToTrackLogTagL( const RArray<TItemId>& aObjectIdArray );
       
   381     
       
   382     /**
       
   383      * Callback function for positioning stop timer.
       
   384      * @param aAny, a pointer to CLocationRecord object
       
   385      * @return Error code
       
   386      */
       
   387     static TInt PositioningStopTimeout( TAny* aAny );
       
   388     
       
   389     /**
       
   390      * Stops location trail and deletes the positioning stop timer.
       
   391      */
       
   392     void StopRecording();
       
   393     
       
   394     void CompleteNotifyRequest( TEventTypes aEventType, TInt aError );
       
   395 
       
   396 private:
       
   397     /**
       
   398      * A class for recording and storing locations.
       
   399      * Own.
       
   400      */
       
   401     CLocationRecord* iLocationRecord;
       
   402     
       
   403     /**
       
   404      * Pointer to TrackLog
       
   405      * Own.
       
   406      */
       
   407     CTrackLog* iTrackLog;
       
   408     
       
   409     /**
       
   410      * An active scheduler wait loop for waiting a session to MdE to open.
       
   411      */
       
   412     CActiveSchedulerWait* iASW;
       
   413     
       
   414     /**
       
   415      * An array for asynchronous notification requests.
       
   416      * Own.
       
   417      */
       
   418     RArray<RMessage2> iNotifReqs;
       
   419     
       
   420     /**
       
   421      * An array for asynchronous location requests.
       
   422      * Own.
       
   423      */
       
   424     RArray<RMessage2> iLocationReqs;
       
   425     
       
   426     /**
       
   427      * An array for track log notification requests.
       
   428      * Own.
       
   429      */
       
   430     RArray<RMessage2> iTrackLogNotifyReqs;
       
   431     
       
   432     /**
       
   433      * An array for location copy requests.
       
   434      * Own.
       
   435      */
       
   436     RArray<TMessageQuery> iCopyReqs;
       
   437     
       
   438     /**
       
   439      * A session to Metadata Engine for creating and manipulating location objects.
       
   440      */
       
   441     CMdESession* iMdeSession;
       
   442     
       
   443     /** A relation query used to seach for related location objects */
       
   444     CMdERelationQuery* iRelationQuery;
       
   445     
       
   446     /**
       
   447      * A timer to stop location trail.
       
   448      * Own.
       
   449      */
       
   450     CPeriodic* iTimer;
       
   451     
       
   452     TBool iClientSwitch;    
       
   453     TInt iSessionCount;
       
   454     TBool iSessionReady;  
       
   455     
       
   456     RArray<TItemId> iTargetObjectIds;
       
   457     TItemId iTagId;
       
   458     TInt iLocManStopDelay;
       
   459     
       
   460     RLocationTrail::TTrailCaptureSetting iCaptureSetting;
       
   461     TBool iRemoveLocation;    
       
   462     };
       
   463 
       
   464 
       
   465 #endif // C_CLOCATIONMANAGERSERVER_H
       
   466 
       
   467 // End of file.