locationrequestmgmt/locationserver/src/EPos_CPosLocMonitorReqHandlerHub.cpp
changeset 0 9cfd9a3ee49c
child 52 29dbbeac905d
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 /*
       
     2 * Copyright (c) 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:  	Receives the Last Known Position, Last Known Position Area requests and Empty
       
    15 * 				Position Store requests from Subsessions and Sessions in the Location Server and 
       
    16 *				forwards them to the respective active objects*
       
    17 */
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <e32def.h>
       
    21 #include "EPos_CPosLocMonitorReqHandlerHub.h"
       
    22 #include <lbs/epos_lastknownlocationpskeys.h>
       
    23 
       
    24 
       
    25 // ============================ CONSTANTS ===========================================================
       
    26 
       
    27 // CONSTANTS
       
    28 #ifdef _DEBUG
       
    29 _LIT(KTraceFileName, "EPos_CPosLocMonitorReqHandlerHub.cpp");
       
    30 #endif
       
    31 
       
    32 
       
    33 // ============================== MEMBER FUNCTIONS ===================================================
       
    34 /**
       
    35  * NewL of the Two-phased constructor.
       
    36  *
       
    37  */
       
    38 CPosLocMonitorReqHandlerHub* CPosLocMonitorReqHandlerHub::NewL()
       
    39 	{
       
    40 
       
    41 	CPosLocMonitorReqHandlerHub* self = new( ELeave ) CPosLocMonitorReqHandlerHub();
       
    42 	CleanupStack::PushL( self );
       
    43 	self->ConstructL();
       
    44 	CleanupStack::Pop( self );
       
    45 	return self;
       
    46 	}
       
    47 
       
    48 /**
       
    49  * C++ default constructor
       
    50  * 
       
    51  * @param aDumpInterval 
       
    52  */
       
    53 CPosLocMonitorReqHandlerHub::CPosLocMonitorReqHandlerHub() 
       
    54     {
       
    55 
       
    56     }
       
    57 
       
    58 /**
       
    59  * Symbian 2nd phase constructor
       
    60  */
       
    61 void CPosLocMonitorReqHandlerHub::ConstructL()
       
    62 	{
       
    63 	
       
    64 	// Establish a session with the Location Monitor - The subsessions are
       
    65 	// established in the "active objects" owned by the CPosLocMonitorReqHandlerHub
       
    66 	User::LeaveIfError(iLocMonSession.Connect()); 
       
    67 	
       
    68 	// Establish the subsession with the location monitor - As SetPositionInfoL()
       
    69 	// is likely to be called whenever we have an update from the PSYs, the subsession
       
    70 	// with the location monitor is created as a member variable instead of a local variable.
       
    71 	iLocMonSubSession.OpenL(iLocMonSession);	
       
    72 	}
       
    73 
       
    74 
       
    75 /**
       
    76  * Destructor
       
    77  */
       
    78 CPosLocMonitorReqHandlerHub::~CPosLocMonitorReqHandlerHub()
       
    79 	{
       
    80 	
       
    81     delete iLastKnownPosHandler;	
       
    82     delete iLastKnownPosAreaHandler;
       
    83     delete iEmptyLastKnownPosStoreHandler;
       
    84 	
       
    85 	// Close the session with the Location Monitor
       
    86 	if ( iLocMonSubSession.SubSessionHandle() )
       
    87 		{
       
    88 		iLocMonSubSession.Close();
       
    89 		}
       
    90 	
       
    91 	// Close the session with the Location Monitor
       
    92 	if ( iLocMonSession.Handle() )
       
    93 		{
       
    94 		iLocMonSession.Close();
       
    95 		}
       
    96 		
       
    97 	}
       
    98 
       
    99 /** 
       
   100  * Set Position Information (SetPositionInfo)
       
   101  * 		>> Whenever there is a position update from any of the PSYs update the 
       
   102  * 		   location monitor of this latest position.
       
   103  *
       
   104  * @param aPositionInfo The last known position.
       
   105  */
       
   106 void CPosLocMonitorReqHandlerHub::SetPositionInfo( const TPositionInfo& aPositionInfo )
       
   107 	{
       
   108 	DEBUG_TRACE("CPosLocMonitorReqHandlerHub::SetPositionInfoL", __LINE__)
       
   109 	
       
   110 	TInt errSetPos = iLocMonSubSession.SetLastKnownPosition(aPositionInfo);
       
   111 	}
       
   112 
       
   113 /** 
       
   114  * Get Last Known Position Request
       
   115  * 		>> Called by the subsession to request the last known position.
       
   116  *
       
   117  * @param aMessage The message containing info about the request from subsession
       
   118  */
       
   119 void CPosLocMonitorReqHandlerHub::GetLastKnownPosReqL(const RMessage2& aMessage)
       
   120 	{
       
   121 	DEBUG_TRACE("CPosLocMonitorReqHandlerHub::GetLastKnownPosReqL", __LINE__)
       
   122 	
       
   123 	if (!iLastKnownPosHandler)
       
   124 		{
       
   125 		// The very first request with the location monitor
       
   126 		iLastKnownPosHandler = CPosLastKnownPosHandler::NewL();
       
   127 		}
       
   128 	
       
   129 	// The timeout value for this request is hardcoded in the constant 
       
   130 	// KLastKnownPosTimeOut [in CPosLastKnownPosHandler]
       
   131 	iLastKnownPosHandler->GetLastKnownPosL(iLocMonSession, aMessage);
       
   132 	}
       
   133 
       
   134 
       
   135 /** Cancel Get Last Known Position Request 
       
   136  * 		>> Called by the subsession to cancel a last knwon position request
       
   137  * @param aMessage The message containing info about the request from subsession
       
   138  */
       
   139 void CPosLocMonitorReqHandlerHub::CancelGetLastKnownPosReqL(const RMessage2& aMessage)
       
   140 	{
       
   141 	DEBUG_TRACE("CPosLocMonitorReqHandlerHub::CancelGetLastKnownPosReqL", __LINE__)
       
   142 
       
   143 	if (!iLastKnownPosHandler)
       
   144 		{
       
   145 		// The client never sent any get last known position request earlier
       
   146 		if (!aMessage.IsNull())
       
   147 			{
       
   148 			aMessage.Complete(KErrNotFound);
       
   149 			}
       
   150 		}
       
   151 	else
       
   152 		{
       
   153 		iLastKnownPosHandler->CancelGetLastKnownPosL(aMessage);
       
   154 		}
       
   155 	}
       
   156 
       
   157 
       
   158 /** 
       
   159  * Get Last Known Position Area Request
       
   160  * 		>> Called by the subsession to request the last known position area.
       
   161  *
       
   162  * @param aMessage The message containing info about the request from subsession
       
   163  */
       
   164 void CPosLocMonitorReqHandlerHub::GetLastKnownPosAreaReqL(const RMessage2& aMessage)
       
   165 	{
       
   166 	DEBUG_TRACE("CPosLocMonitorReqHandlerHub::GetLastKnownPosAreaReqL", __LINE__)
       
   167 
       
   168 	if (!iLastKnownPosAreaHandler)
       
   169 		{
       
   170 		// The very first request with the location monitor
       
   171 		iLastKnownPosAreaHandler = CPosLastKnownPosAreaHandler::NewL();
       
   172 		}
       
   173 	iLastKnownPosAreaHandler->GetLastKnownPosAreaL(iLocMonSession, aMessage);
       
   174 
       
   175 	}
       
   176 
       
   177 
       
   178 /** Cancel Get Last Known Position Area Request 
       
   179  * 		>> Called by the subsession to cancel a LKPosArea request
       
   180  * @param aMessage The message containing info about the request from subsession
       
   181  */
       
   182 void CPosLocMonitorReqHandlerHub::CancelGetLastKnownPosAreaReqL(const RMessage2& aMessage)
       
   183 	{
       
   184 	DEBUG_TRACE("CPosLocMonitorReqHandlerHub::CancelGetLastKnownPosAreaReqL", __LINE__)
       
   185 
       
   186 	if (!iLastKnownPosAreaHandler)
       
   187 		{
       
   188 		// The client never sent any get last known position area request earlier
       
   189 		if (!aMessage.IsNull())
       
   190 			{
       
   191 			aMessage.Complete(KErrNotFound);
       
   192 			}
       
   193 		}
       
   194 	else
       
   195 		{
       
   196 		iLastKnownPosAreaHandler->CancelGetLastKnownPosAreaL(aMessage);
       
   197 		}
       
   198 	}
       
   199 
       
   200 /** 
       
   201  * Empty Last Known Position Store Request (EmptyPositionStoreReq)
       
   202  *		>> Called by the subsession to Empty the last known position store
       
   203  *
       
   204  *  @param aMessage The message containing info about the request from subsession
       
   205  */
       
   206 void CPosLocMonitorReqHandlerHub::EmptyLastKnownPosStoreReqL(const RMessage2& aMessage)
       
   207 	{
       
   208 	DEBUG_TRACE("CPosLocMonitorReqHandlerHub::EmptyLastKnownPosStoreL", __LINE__)
       
   209 	
       
   210 	if (!iEmptyLastKnownPosStoreHandler)
       
   211 		{
       
   212 		// The very first request with the location monitor
       
   213 		iEmptyLastKnownPosStoreHandler = CPosEmptyLastKnownPosStoreHandler::NewL();
       
   214 		}
       
   215 	
       
   216 	iEmptyLastKnownPosStoreHandler->EmptyLastKnownPosStoreL(iLocMonSession, aMessage);
       
   217 
       
   218 	// Cancel outstanding last known position or last known position area requests
       
   219 	if (iLastKnownPosAreaHandler)
       
   220 		{
       
   221 		iLastKnownPosAreaHandler->NotifyOnEmptyLastKnownPosStoreReq();
       
   222 		}
       
   223 	
       
   224 	if (iLastKnownPosHandler)
       
   225 		{
       
   226 		iLastKnownPosHandler->NotifyOnEmptyLastKnownPosStoreReq();
       
   227 		}
       
   228 	
       
   229 	}
       
   230 
       
   231 
       
   232 /** Cancel Empty Last Known Position Store Request 
       
   233  * 		>> Called by the subsession to cancel an earlier EmptyLastKnownPosStoreReq
       
   234  * @param aMessage The message containing info about the request from subsession
       
   235  */
       
   236 void CPosLocMonitorReqHandlerHub::CancelEmptyLastKnownPosStoreReqL(const RMessage2& aMessage)
       
   237 	{
       
   238 	DEBUG_TRACE("CPosLocMonitorReqHandlerHub::CancelGetLastKnownPosAreaReqL", __LINE__)
       
   239 	
       
   240 	iEmptyLastKnownPosStoreHandler->CancelEmptyLastKnownPosStoreL(aMessage);
       
   241 	}
       
   242 
       
   243 
       
   244 /** 
       
   245  * NotifyServerShutDown
       
   246  * 		>> Notification from the Session that the server is going to shutdown
       
   247  * 
       
   248  */
       
   249 void CPosLocMonitorReqHandlerHub::NotifyServerShutDown()
       
   250 	{
       
   251 	DEBUG_TRACE("CPosLocMonitorReqHandlerHub::NotifyServerShutDown", __LINE__)
       
   252 	
       
   253 	if (iLastKnownPosAreaHandler)
       
   254 		{
       
   255 		iLastKnownPosAreaHandler->NotifyServerShutDown();
       
   256 		}
       
   257 	
       
   258 	if (iLastKnownPosHandler)
       
   259 		{
       
   260 		iLastKnownPosHandler->NotifyServerShutDown();
       
   261 		}
       
   262 	
       
   263 	if (iEmptyLastKnownPosStoreHandler)
       
   264 		{
       
   265 		iEmptyLastKnownPosStoreHandler->NotifyServerShutDown();
       
   266 		}
       
   267 	}
       
   268 
       
   269 /** 
       
   270  * NotifySubSessionClosed
       
   271  * 		>> Notification from the Session that the subsessions are to be closed
       
   272  * 
       
   273  */
       
   274 void CPosLocMonitorReqHandlerHub::NotifySubSessionClosed(const RMessage2& aMessage)
       
   275 	{
       
   276 
       
   277 	if (iLastKnownPosHandler)
       
   278 		{
       
   279 		iLastKnownPosHandler->NotifySubSessionClosed(aMessage);
       
   280 		}
       
   281 	
       
   282 	if (iLastKnownPosAreaHandler)
       
   283 		{
       
   284 		iLastKnownPosAreaHandler->NotifySubSessionClosed(aMessage);
       
   285 		}
       
   286 	// No need to notify the emptylastknownpositionstore request as it is issued on a 
       
   287 	// session and not a subsession
       
   288 	}
       
   289 
       
   290 /** 
       
   291  * NotifySessionClosed
       
   292  * 		>> Notification from the Session that it is going to be closed 
       
   293  *		NOTE : Not guaranteed that the requests would be completed with EPositoinRequestsNotCancelled
       
   294  * 			   - This method is used to ensure that the request queue is cleaned up
       
   295  * @param aSessionPtr The Session pointer
       
   296  */
       
   297 void CPosLocMonitorReqHandlerHub::NotifySessionClosed(const CSession2* aSessionPtr)
       
   298 	{
       
   299 	DEBUG_TRACE("CPosLocMonitorReqHandlerHub::NotifySessionClosed", __LINE__)
       
   300 	
       
   301 	if (iLastKnownPosAreaHandler)
       
   302 		{
       
   303 		iLastKnownPosAreaHandler->NotifySessionClosed(aSessionPtr);
       
   304 		}
       
   305 	
       
   306 	if (iLastKnownPosHandler)
       
   307 		{
       
   308 		iLastKnownPosHandler->NotifySessionClosed(aSessionPtr);
       
   309 		}
       
   310 	
       
   311 	if (iEmptyLastKnownPosStoreHandler)
       
   312 		{
       
   313 		iEmptyLastKnownPosStoreHandler->NotifySessionClosed(aSessionPtr);
       
   314 		}
       
   315 	
       
   316 	}
       
   317 
       
   318 
       
   319