locationmanager/server/src/clocationmanagersession.cpp
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:  A session class for LocationManagerServer.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <e32debug.h>
       
    19 #include <s32mem.h>
       
    20 #include <LbsSatellite.h> 
       
    21 #include <locationdatatype.h>
       
    22 #include <locationeventdef.h>
       
    23 
       
    24 #include "clocationmanagerserver.h"
       
    25 #include "clocationmanagersession.h"
       
    26 #include "locationmanagerdefs.h"
       
    27 #include "locationmanagerdebug.h"
       
    28 #include "rlocationtrail.h"
       
    29 #include "rlocationobjectmanipulator.h"
       
    30 #include "rlocationtrail.h"
       
    31 #include "mdsutils.h"
       
    32 
       
    33 // --------------------------------------------------------------------------
       
    34 // CLocationManagerSession::CLocationManagerSession
       
    35 // C++ constructor.
       
    36 // --------------------------------------------------------------------------
       
    37 //
       
    38 CLocationManagerSession::CLocationManagerSession() 
       
    39     {
       
    40     
       
    41     }
       
    42 
       
    43 // --------------------------------------------------------------------------
       
    44 // CLocationManagerSession::~CLocationManagerSession
       
    45 // C++ destructor.
       
    46 // --------------------------------------------------------------------------
       
    47 //
       
    48 CLocationManagerSession::~CLocationManagerSession()
       
    49     {
       
    50     LOG( "CLocationManagerSession::~CLocationManagerSession(), begin" );
       
    51     Server().CancelNotificationRequest( iNotificationHandle );
       
    52     Server().CancelLocationRequest( iLocationHandle );
       
    53     Server().CancelTrackLogNotificationRequest( iTrackLogNotificationHandle );
       
    54     Server().RemoveSession();
       
    55     LOG( "CLocationManagerSession::~CLocationManagerSession(), end" );
       
    56     }
       
    57 
       
    58 // --------------------------------------------------------------------------
       
    59 // CLocationManagerSession::CreateL
       
    60 // From CSession2, used to increase server's session count.
       
    61 // --------------------------------------------------------------------------
       
    62 //
       
    63 void CLocationManagerSession::CreateL()
       
    64     {
       
    65     LOG( "CLocationManagerSession::CreateL(), begin" );
       
    66     Server().AddSession();
       
    67     LOG( "CLocationManagerSession::CreateL(), end" );
       
    68     }
       
    69 
       
    70 // --------------------------------------------------------------------------
       
    71 // CLocationManagerSession::Server
       
    72 // Reference to server.
       
    73 // --------------------------------------------------------------------------
       
    74 //
       
    75 CLocationManagerServer& CLocationManagerSession::Server()
       
    76     {   
       
    77     return *static_cast<CLocationManagerServer*>
       
    78            ( const_cast<CServer2*>( CSession2::Server() ) );
       
    79     }
       
    80     
       
    81 // --------------------------------------------------------------------------
       
    82 // CLocationManagerSession::ServiceL
       
    83 // From CSession2, passes the request forward to DispatchMessageL.
       
    84 // --------------------------------------------------------------------------
       
    85 //
       
    86 void CLocationManagerSession::ServiceL( const RMessage2& aMessage )
       
    87     {
       
    88     LOG( "CLocationManagerSession::ServiceL" );
       
    89     _LIT( KSemaphore, "LocManSynchSemaphore" );
       
    90     RSemaphore semaphore;
       
    91     TInt result = semaphore.OpenGlobal( KSemaphore );
       
    92     LOG1( "CLocationManagerSession::ServiceL - semaphore open result: %d", result );
       
    93     iMessage = RMessage2( aMessage );
       
    94     if ( result == KErrNone )
       
    95     	{
       
    96     	semaphore.Signal();
       
    97     	semaphore.Close();
       
    98     	}
       
    99     TRAPD( err, DispatchMessageL( aMessage ) );
       
   100     if ( err != KErrNone )
       
   101         {
       
   102         aMessage.Complete( err );
       
   103         }    
       
   104     }
       
   105 
       
   106 // --------------------------------------------------------------------------
       
   107 // CLocationManagerSession::DispatchMessageL
       
   108 // Handles the request from client.
       
   109 // --------------------------------------------------------------------------
       
   110 //
       
   111 void CLocationManagerSession::DispatchMessageL( const RMessage2& aMessage )
       
   112     {
       
   113     LOG( "CLocationManagerSession::DispatchMessageL" );
       
   114     switch( aMessage.Function() )
       
   115         {
       
   116         case ELocManStartTrail:
       
   117             StartLocationTrailL( aMessage );
       
   118             break;        
       
   119         case ELocManStopTrail:
       
   120             StopLocationTrailL( aMessage );
       
   121             break;        
       
   122         case ELocManTrailState:
       
   123             GetLocationTrailStateL( aMessage );
       
   124             break;        
       
   125         case ELocManNotifyTrailStateChange:
       
   126             NotifyLocationTrailStateChangeL( aMessage );
       
   127             break;        
       
   128         case ELocManCancelNotification:
       
   129             CancelNotificationRequest( aMessage );
       
   130             break;
       
   131         case ELocManRetrieveLoc:
       
   132             RetrieveLocationL( aMessage );
       
   133             break;
       
   134         case ELocManCurrentLoc:
       
   135             CurrentLocationL( aMessage );
       
   136             break;
       
   137         case ELocManCancelCurrentLoc:
       
   138             CancelLocationRequest( aMessage );
       
   139             break;
       
   140         case ELocManCreateLocationObject:
       
   141         	CreateLocationObjectL( aMessage );
       
   142         	break;
       
   143         case ELocManLocationSnapshot:
       
   144         	LocationSnapshotL( aMessage );
       
   145         	break;
       
   146         case ELocManRemoveLocationObject:
       
   147         	RemoveLocationObjectL( aMessage );
       
   148         	break;
       
   149         case ELocManCopyLocationDataById:
       
   150         	CopyLocationDataByIdL( iMessage );
       
   151         	break;
       
   152         case ELocManCopyLocationDataByUri:
       
   153 	    	CopyLocationDataByURIL( iMessage );
       
   154 	    	break;		
       
   155         case ELocManStartTrackLog:
       
   156         	StartTrackLogL( aMessage );
       
   157         	break;
       
   158         case ELocManStopTrackLog:
       
   159         	StopTrackLogL( aMessage );
       
   160         	break;
       
   161         case ELocManGetTrackLogStatus:
       
   162         	GetTrackLogStatusL( aMessage );
       
   163         	break;
       
   164         case ELocManDeleteTrackLog:
       
   165         	DeleteTrackLogL( aMessage );
       
   166         	break;
       
   167         case ELocManIsTrackLogRecording:
       
   168         	IsTrackLogRecordingL( aMessage );
       
   169         	break;
       
   170         case ELocManTrackLogName:
       
   171         	TrackLogNameL( aMessage );
       
   172         	break;
       
   173         case ELocManRegObserver:
       
   174         	RegisterTrackLogObserver( aMessage );
       
   175         	break;
       
   176         case ELocManGetCaptureSetting:
       
   177         	GetCaptureSettingL( aMessage );
       
   178         	break;
       
   179         case ELocManCancelTrackLogNotify:
       
   180         	CancelTrackLogNotificationRequest( aMessage );
       
   181         	break;
       
   182         default:
       
   183             aMessage.Complete( KErrArgument );
       
   184             break;
       
   185         }
       
   186     }
       
   187   
       
   188 // --------------------------------------------------------------------------
       
   189 // CLocationManagerSession::StartLocationTrailL
       
   190 // --------------------------------------------------------------------------
       
   191 //
       
   192 void CLocationManagerSession::StartLocationTrailL( const RMessage2& aMessage )
       
   193     {
       
   194     const TInt KParamSetting = 0;
       
   195     
       
   196     RLocationTrail::TTrailCaptureSetting setting;
       
   197     TPckg<RLocationTrail::TTrailCaptureSetting> locSetting( setting ); 
       
   198     aMessage.ReadL(KParamSetting, locSetting);    
       
   199     
       
   200     LOG1 ("CLocationManagerSession::StartLocationTrailL TTrailCaptureSetting: %d", setting);
       
   201     
       
   202     Server().StartGPSPositioningL( setting );
       
   203     aMessage.Complete( KErrNone );
       
   204     }
       
   205 
       
   206 // --------------------------------------------------------------------------
       
   207 // CLocationManagerSession::StopLocationTrailL
       
   208 // --------------------------------------------------------------------------
       
   209 //
       
   210 void CLocationManagerSession::StopLocationTrailL( const RMessage2& aMessage )
       
   211     {
       
   212     Server().StopGPSPositioningL();
       
   213     if( !aMessage.IsNull() )
       
   214         {
       
   215         aMessage.Complete( KErrNone );
       
   216         }
       
   217     }
       
   218 
       
   219 // --------------------------------------------------------------------------
       
   220 // CLocationManagerSession::GetLocationTrailStateL
       
   221 // --------------------------------------------------------------------------
       
   222 //
       
   223 void CLocationManagerSession::GetLocationTrailStateL( const RMessage2& aMessage )
       
   224     {
       
   225     RLocationTrail::TTrailState state;
       
   226     Server().GetLocationTrailState( state );
       
   227         
       
   228     TPckg<RLocationTrail::TTrailState> locState( state );    
       
   229     aMessage.WriteL( 0, locState );
       
   230     aMessage.Complete( KErrNone );    
       
   231     }
       
   232 
       
   233 // --------------------------------------------------------------------------
       
   234 // CLocationManagerSession::NotifyLocationTrailStateChangeL
       
   235 // --------------------------------------------------------------------------
       
   236 //
       
   237 void CLocationManagerSession::NotifyLocationTrailStateChangeL( const RMessage2& aMessage )
       
   238     {
       
   239     iNotificationHandle = aMessage.Handle();
       
   240     Server().AddNotificationRequestL( aMessage );
       
   241     }
       
   242 
       
   243 // --------------------------------------------------------------------------
       
   244 // CLocationManagerSession::CancelNotificationRequest
       
   245 // --------------------------------------------------------------------------
       
   246 //
       
   247 void CLocationManagerSession::CancelNotificationRequest( const RMessage2& aMessage )
       
   248     {
       
   249     Server().CancelNotificationRequest( iNotificationHandle );
       
   250     aMessage.Complete( KErrNone );
       
   251     }
       
   252 
       
   253 // --------------------------------------------------------------------------
       
   254 // CLocationManagerSession::RetrieveLocationL
       
   255 // --------------------------------------------------------------------------
       
   256 //
       
   257 void CLocationManagerSession::RetrieveLocationL( const RMessage2& aMessage )
       
   258     {
       
   259     TTime time( 0 );
       
   260     TPckg<TTime> timeBuf( time );
       
   261     aMessage.ReadL( EArgumentTime, timeBuf );
       
   262     
       
   263     TLocationData locationData;
       
   264     TLocTrailState state;
       
   265     Server().GetLocationByTimeL( time, locationData, state );
       
   266 
       
   267     TPckg<TLocationData> locDataBuf( locationData );
       
   268     aMessage.WriteL( EArgumentLocationData, locDataBuf );
       
   269     
       
   270     TPckg<TUint> stateBuf( state );
       
   271     aMessage.WriteL( EArgumentState, stateBuf );
       
   272 
       
   273     aMessage.Complete( KErrNone );
       
   274     }
       
   275 
       
   276 // --------------------------------------------------------------------------
       
   277 // CLocationManagerSession::CurrentLocationL
       
   278 // --------------------------------------------------------------------------
       
   279 //    
       
   280 void CLocationManagerSession::CurrentLocationL( const RMessage2& aMessage )
       
   281     {
       
   282     LOG ("CLocationManagerSession::StartLocationTrailL begin");
       
   283     iLocationHandle = aMessage.Handle();
       
   284     // server creates completion after it has received current location data
       
   285     Server().RequestCurrentLocationL( aMessage );
       
   286     LOG ("CLocationManagerSession::StartLocationTrailL end");
       
   287     }
       
   288 
       
   289 // --------------------------------------------------------------------------
       
   290 // CLocationManagerSession::CancelLocationRequest()
       
   291 // --------------------------------------------------------------------------
       
   292 //    
       
   293 void CLocationManagerSession::CancelLocationRequest( const RMessage2& aMessage )
       
   294     {
       
   295     Server().CancelLocationRequest( iLocationHandle );
       
   296     aMessage.Complete( KErrNone );
       
   297     }
       
   298 
       
   299 // --------------------------------------------------------------------------
       
   300 // CLocationManagerSession::CancelTrackLogNotificationRequest()
       
   301 // --------------------------------------------------------------------------
       
   302 //    
       
   303 void CLocationManagerSession::CancelTrackLogNotificationRequest( const RMessage2& aMessage )
       
   304     {
       
   305     Server().CancelTrackLogNotificationRequest( iTrackLogNotificationHandle );
       
   306     aMessage.Complete( KErrNone );
       
   307     }
       
   308 
       
   309 // --------------------------------------------------------------------------
       
   310 // CLocationManagerSession::CreateLocationObjectL
       
   311 // --------------------------------------------------------------------------
       
   312 //    
       
   313 void CLocationManagerSession::CreateLocationObjectL( const RMessage2& aMessage )
       
   314     {
       
   315     LOG( "CLocationManagerSession::CreateLocationObjectL begin" );
       
   316     const TInt KParamData = 0;
       
   317     const TInt KParamId = 1;
       
   318     
       
   319     TLocationData locationData;
       
   320     TUint objectId;
       
   321 	
       
   322     TPckg<TLocationData> locData( locationData );
       
   323     aMessage.ReadL( KParamData, locData );
       
   324     
       
   325     TPckg<TUint> objId( objectId);
       
   326     aMessage.ReadL( KParamId, objId );
       
   327     
       
   328     Server().CreateLocationObjectL( locationData, objectId );
       
   329     
       
   330     aMessage.Complete( KErrNone );
       
   331     LOG( "CLocationManagerSession::CreateLocationObjectL end" );
       
   332     }
       
   333 
       
   334 // --------------------------------------------------------------------------
       
   335 // CLocationManagerSession::LocationSnapshotL
       
   336 // --------------------------------------------------------------------------
       
   337 //    
       
   338 void CLocationManagerSession::LocationSnapshotL( const RMessage2& aMessage )
       
   339     {
       
   340     LOG( "CLocationManagerSession::LocationSnapshotL begin" );
       
   341     const TInt KParamId = 0;
       
   342     
       
   343     TUint objectId;
       
   344 	
       
   345     TPckg<TUint> objId( objectId);
       
   346     aMessage.ReadL( KParamId, objId );
       
   347     
       
   348     Server().LocationSnapshotL( objectId );
       
   349     
       
   350     aMessage.Complete( KErrNone );
       
   351     LOG( "CLocationManagerSession::LocationSnapshotL end" );
       
   352     }
       
   353 
       
   354 // --------------------------------------------------------------------------
       
   355 // CLocationManagerSession::RemoveLocationObjectL
       
   356 // --------------------------------------------------------------------------
       
   357 //    
       
   358 void CLocationManagerSession::RemoveLocationObjectL( const RMessage2& aMessage )
       
   359     {
       
   360     LOG( "CLocationManagerSession::RemoveLocationObjectL begin" );
       
   361     const TInt KParamId = 0;
       
   362     TUint objectId;
       
   363     TPckg<TUint> locObjectId( objectId );
       
   364     aMessage.ReadL(KParamId, locObjectId);
       
   365     Server().RemoveLocationObjectL(objectId);
       
   366     aMessage.Complete( KErrNone );
       
   367     LOG( "CLocationManagerSession::RemoveLocationObjectL end" );
       
   368     }
       
   369 
       
   370 // --------------------------------------------------------------------------
       
   371 // CLocationManagerSession::CopyLocationDataByIdL
       
   372 // --------------------------------------------------------------------------
       
   373 //    
       
   374 void CLocationManagerSession::CopyLocationDataByIdL( const RMessage2& aMessage )
       
   375     {
       
   376     Server().InitCopyLocationByIdL( aMessage );
       
   377     }
       
   378 
       
   379 // --------------------------------------------------------------------------
       
   380 // CLocationManagerSession::CopyLocationDataByURIL
       
   381 // --------------------------------------------------------------------------
       
   382 //    
       
   383 void CLocationManagerSession::CopyLocationDataByURIL( const RMessage2& aMessage )
       
   384     {
       
   385     Server().InitCopyLocationByURIL( aMessage );
       
   386     }
       
   387 
       
   388 // --------------------------------------------------------------------------
       
   389 // CLocationManagerSession::StartTrackLog
       
   390 // --------------------------------------------------------------------------
       
   391 //    
       
   392 void CLocationManagerSession::StartTrackLogL( const RMessage2& aMessage )
       
   393 	{
       
   394 	RLocationTrail::TTrailState state;
       
   395 	Server().GetLocationTrailState( state );
       
   396 	
       
   397 	if ( state == RLocationTrail::ETrailStopped )
       
   398 		{
       
   399 		Server().StartGPSPositioningL( RLocationTrail::ECaptureAll );
       
   400 		}
       
   401 	
       
   402 	Server().StartTrackLogL();
       
   403 
       
   404 	aMessage.Complete( KErrNone );
       
   405 	}
       
   406 
       
   407 // --------------------------------------------------------------------------
       
   408 // CLocationManagerSession::StopTrackLog
       
   409 // --------------------------------------------------------------------------
       
   410 //    
       
   411 void CLocationManagerSession::StopTrackLogL( const RMessage2& aMessage )
       
   412 	{
       
   413 	Server().StopTrackLogL();
       
   414 
       
   415 	aMessage.Complete( KErrNone );
       
   416 	}
       
   417 
       
   418 // --------------------------------------------------------------------------
       
   419 // CLocationManagerSession::GetStatus
       
   420 // --------------------------------------------------------------------------
       
   421 //    
       
   422 void CLocationManagerSession::GetTrackLogStatusL(const RMessage2& aMessage)
       
   423 	{
       
   424 	const TInt KParamRec = 0;
       
   425 	const TInt KParamQuality = 1;
       
   426 	TBool rec = EFalse;
       
   427 	TPositionSatelliteInfo fixQuality;
       
   428 	
       
   429 	Server().GetTrackLogStatus( rec, fixQuality );
       
   430 	
       
   431 	TPckg<TBool> wrapRec( rec );
       
   432 	aMessage.WriteL( KParamRec, wrapRec );
       
   433 	
       
   434 	TPckg<TPositionSatelliteInfo> wrapQuality( fixQuality );
       
   435 	aMessage.WriteL( KParamQuality, wrapQuality );
       
   436 
       
   437 	aMessage.Complete( KErrNone );
       
   438 	}
       
   439 
       
   440 // --------------------------------------------------------------------------
       
   441 // CLocationManagerSession::DeleteTrackLog
       
   442 // --------------------------------------------------------------------------
       
   443 //    
       
   444 void CLocationManagerSession::DeleteTrackLogL(const RMessage2& aMessage)
       
   445 	{
       
   446 	const TInt KParamUri = 0;
       
   447 	const TInt KParamUriLength = aMessage.GetDesLength(KParamUri);
       
   448 	
       
   449     TInt err = KErrNone;	
       
   450 	if (KParamUriLength > 0)
       
   451     	{
       
   452     	// read TDesC& aURI from request
       
   453 	    HBufC* uriBuf = HBufC::NewLC( KParamUriLength );
       
   454 	    TPtr ptrUri( uriBuf->Des() );
       
   455 	    aMessage.ReadL( KParamUri, ptrUri );  
       
   456 
       
   457 	    err = Server().DeleteTrackLogL( ptrUri );
       
   458 	    CleanupStack::PopAndDestroy( uriBuf );
       
   459     	}
       
   460 	aMessage.Complete( err );
       
   461 	}
       
   462 
       
   463 // --------------------------------------------------------------------------
       
   464 // CLocationManagerSession::IsTrackLogRecordingL
       
   465 // --------------------------------------------------------------------------
       
   466 //    
       
   467 void CLocationManagerSession::IsTrackLogRecordingL(const RMessage2& aMessage)
       
   468 	{	
       
   469 	const TInt KParamRec = 0;
       
   470 	TBool rec = EFalse;
       
   471 
       
   472 	Server().IsTrackLogRecording( rec );
       
   473 	
       
   474 	TPckg<TBool> wrapRec( rec );
       
   475 	aMessage.WriteL(KParamRec, wrapRec);
       
   476 
       
   477 	aMessage.Complete( KErrNone );
       
   478 	}
       
   479 
       
   480 // --------------------------------------------------------------------------
       
   481 // CLocationManagerSession::TrackLogName
       
   482 // --------------------------------------------------------------------------
       
   483 //    
       
   484 void CLocationManagerSession::TrackLogNameL(const RMessage2& aMessage)
       
   485 	{	
       
   486 	const TInt KParamName = 0;
       
   487 	TFileName fileName;
       
   488 	TInt err;
       
   489 	
       
   490 	err = Server().TrackLogName( fileName );
       
   491 	aMessage.WriteL(KParamName, fileName);
       
   492 	aMessage.Complete( err );
       
   493 	}
       
   494 
       
   495 // --------------------------------------------------------------------------
       
   496 // CLocationManagerSession::GpsQualityChange
       
   497 // --------------------------------------------------------------------------
       
   498 //  
       
   499 void CLocationManagerSession::RegisterTrackLogObserver( const RMessage2& aMessage )
       
   500 	{
       
   501 	iTrackLogNotificationHandle = aMessage.Handle();
       
   502 	TRAP_IGNORE( Server().AddTrackLogNotificationRequestL( aMessage ) );
       
   503 	}
       
   504 
       
   505 void CLocationManagerSession::GetCaptureSettingL( const RMessage2& aMessage )
       
   506 	{
       
   507 	TInt KParamCaptureSetting = 0;
       
   508 	RLocationTrail::TTrailCaptureSetting captureSetting = RLocationTrail::EOff;
       
   509 	
       
   510 	Server().GetCaptureSetting( captureSetting );
       
   511 	
       
   512 	TPckg<RLocationTrail::TTrailCaptureSetting> setting( captureSetting );
       
   513 	aMessage.WriteL( KParamCaptureSetting, setting );
       
   514 	aMessage.Complete( KErrNone );
       
   515 	}
       
   516     
       
   517 // End of file