datasourcemodules/gpspositioningmodule/lbsagpspsy/src/responsehandler/cagpsdatabus.cpp
changeset 36 b47902b73a93
parent 0 9cfd9a3ee49c
equal deleted inserted replaced
35:a2efdd544abf 36:b47902b73a93
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @InternalComponent
       
    19 */
       
    20 
       
    21 #include "cagpsdatabus.h"
       
    22 #include "lbsdevloggermacros.h"
       
    23 #include "mdatabusobserver.h"
       
    24 #include <lbs/lbsextendedsatellite.h>
       
    25 
       
    26 #ifdef _DEBUG
       
    27 _LIT(KLocDataBus, "CAgpsDataBus");
       
    28 #endif
       
    29 
       
    30 /**
       
    31 Create a location data bus, this should be called from the location cache
       
    32 
       
    33 @return The pointer to the location data bus
       
    34 @see CLocationCache
       
    35 */
       
    36 CAgpsDataBus* CAgpsDataBus::NewL(MDataBusObserver& aObserver, const TUid& aModuleId)	
       
    37 	{
       
    38 	CAgpsDataBus* self = new (ELeave) CAgpsDataBus(aObserver, aModuleId);
       
    39 	CleanupStack::PushL(self);
       
    40 	self->ConstructL();
       
    41 	CleanupStack::Pop(self);
       
    42 	return self;
       
    43 	} 
       
    44 	
       
    45 /**
       
    46 constructor, note the location data bus is owned by location cache and used by CRequestQ, and it is a module-based CActive object.
       
    47 Set the data bus as standard priority by default.
       
    48 Add itself to Active Scheduler
       
    49 
       
    50 @param aModuleId Position module Id
       
    51 @see CRequestQ
       
    52 @see CLocationCache
       
    53 */
       
    54 CAgpsDataBus::CAgpsDataBus(MDataBusObserver& aObserver, const TUid& aModuleId) : CActive(CActive::EPriorityStandard), iModuleId(aModuleId), iObs(aObserver)
       
    55 	{
       
    56 	CActiveScheduler::Add(this);
       
    57 	}
       
    58 
       
    59 /**
       
    60 Open the RProperty object wrappered by the data bus.
       
    61 Location data bus is implemented as Publish & Subscribe mechanism.
       
    62 */
       
    63 void CAgpsDataBus::ConstructL()
       
    64 	{
       
    65 	iAGPSDataBus.OpenL(iModuleId);
       
    66 	}
       
    67 
       
    68 /**
       
    69 Cancel any outstanding request to the CActive object.
       
    70 Close the RProperty.
       
    71 */
       
    72 CAgpsDataBus::~CAgpsDataBus()
       
    73 	{
       
    74 	Cancel();
       
    75 	iAGPSDataBus.Close();
       
    76 	}
       
    77 
       
    78 /**
       
    79 Subscribe to the data bus. It will be called by objects which listen to the data bus.
       
    80 It will eventually call RProperty::Subscribe()
       
    81 Set active the data bus active object
       
    82 Panic if there are no data bus observers already set.
       
    83 */
       
    84 void CAgpsDataBus::Subscribe()
       
    85 	{
       
    86 	if(!IsActive())
       
    87 		{
       
    88 		iAGPSDataBus.NotifyPositionUpdate(iStatus);
       
    89 		SetActive();
       
    90 		}
       
    91 	}
       
    92 
       
    93 /**
       
    94 Cancel the subscribe to the data bus. Cancel any outstanding request to the CActive object.
       
    95 Panic if there are no data bus observers already set.
       
    96 */
       
    97 void CAgpsDataBus::UnSubscribe()
       
    98 	{
       
    99 	Cancel();
       
   100 	}
       
   101 
       
   102 /**
       
   103 Get the last position from the bus 
       
   104  
       
   105  */
       
   106 TInt CAgpsDataBus::GetLastPositionInfo(TPositionSatelliteInfo& aSatelliteInfo, TTime& aActualTime, TUint& aAttributes, TUint& aMode)
       
   107 	{
       
   108 	TBool conflictControl;
       
   109 	TTime targetTime;
       
   110 
       
   111 	TInt error = iAGPSDataBus.GetPositionInfo(conflictControl, &aSatelliteInfo, aSatelliteInfo.PositionClassSize(), targetTime, aActualTime, aAttributes, aMode);
       
   112 	
       
   113 	return error;
       
   114 	}
       
   115 
       
   116 
       
   117 /**
       
   118 from CActive, the main event processing loop
       
   119 Whenever there is a new event, i.e. the position info data is published to the data bus, notify the data bus observer by LocationDataAvailableL()
       
   120 */
       
   121 void CAgpsDataBus::RunL()
       
   122 	{
       
   123 	TTime actualTime;
       
   124 	TPositionExtendedSatelliteInfo satelliteInfo;
       
   125 	TUint attributes = 0;
       
   126 	TUint mode = 0;
       
   127 	
       
   128 	TInt error = GetLastPositionInfo(satelliteInfo, actualTime, attributes, mode);	
       
   129 
       
   130 	iObs.DataUpdate(satelliteInfo, iStatus.Int(), error, actualTime, attributes, mode);
       
   131 
       
   132 	}
       
   133 	
       
   134 /**
       
   135 from CActive
       
   136 Cancels the request for position update notification
       
   137 It will eventually cancel an outstanding subscription request for this property handle.
       
   138 */
       
   139 void CAgpsDataBus::DoCancel()
       
   140 	{
       
   141 	iAGPSDataBus.CancelNotifyPositionUpdate();
       
   142 	}
       
   143 	
       
   144 /**
       
   145 from CActive
       
   146 Simply fwds any errors to the observers
       
   147 */
       
   148 TInt CAgpsDataBus::RunError(TInt aError)
       
   149 	{
       
   150 	return iObs.DataError(aError, iStatus.Int());
       
   151 	}