locationrequestmgmt/networkrequesthandler/LbsX3P/LbsX3PApi/src/LbsX3PImpl.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 // Copyright (c) 2006-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 // Client side implementation for the LbsX3P Api.
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32base.h>
       
    19 #include <e32debug.h>
       
    20 #include <lbspositioninfo.h>
       
    21 #include "lbsnrhserverdata.h"
       
    22 #include "LbsX3PImpl.h"
       
    23 #include "lbsprocessuiddefs.h"
       
    24 #include "messageutils.h"
       
    25 #include "lbsx3pdata.h"
       
    26 #include "lbsnrhmessageenums.h"
       
    27 #include "lbssystemcontroller.h"
       
    28 
       
    29 
       
    30 //
       
    31 // RNrhServer
       
    32 //
       
    33 
       
    34 /* The X3P Implementation hides the details of the 
       
    35  * Privacy Controller from the class CLbsPrivacyController, which uses only the
       
    36  * published API.
       
    37  *
       
    38  * The privacy comntroller is implemented here as a client of the Network
       
    39  * Request Handler, which includes a server to handle requests from this 
       
    40  * component.
       
    41  *
       
    42  * Generic operation on thet client side is implemented by the
       
    43  * code in lbsloccommon\serverframework.
       
    44   */
       
    45 RNrhServer::RNrhServer()
       
    46 	{
       
    47 	// nothing to do
       
    48 	}
       
    49  	
       
    50 RNrhServer::~RNrhServer()
       
    51 	{
       
    52 	// nothing to do
       
    53 	}
       
    54 
       
    55 TVersion RNrhServer::Version()
       
    56 	{
       
    57 	return TVersion(KNrhServerMajorVersionNumber,
       
    58 					KNrhServerMinorVersionNumber,
       
    59 					KNrhServerBuildVersionNumber);
       
    60 	}
       
    61 
       
    62 TInt RNrhServer::StartServer(TServerStartParams& /*aParams*/)
       
    63 	{
       
    64 	// Start LBS from LbsRoot    
       
    65     TRAPD(err, StartLbsL());
       
    66     return (err);
       
    67 	}
       
    68 
       
    69 void RNrhServer::StartLbsL()
       
    70 	{
       
    71     RLbsSystemController systemController;
       
    72     RProcess process;
       
    73     CleanupClosePushL(process);
       
    74 	systemController.OpenL(process.SecureId());
       
    75 	CleanupClosePushL(systemController);
       
    76 	
       
    77 	TInt startErr = systemController.RequestSystemStartup();
       
    78 	if (startErr != ELbsStartupSuccess)
       
    79 		{
       
    80 		User::Leave(KErrCouldNotConnect);
       
    81 		}
       
    82 	
       
    83 	CleanupStack::PopAndDestroy(2, &process);
       
    84 	}
       
    85 
       
    86 //
       
    87 // RNrhSession
       
    88 //
       
    89 
       
    90 RNrhSession::RNrhSession() :
       
    91 	iTransmittedPosInfoPtr(NULL, 0),
       
    92 	iTransmitPositionParamsPtr(NULL, 0),
       
    93 	iReferencePosInfoPtr(NULL, 0),
       
    94 	iReferencePositionParamsPtr(NULL, 0)
       
    95 	{
       
    96 	// nothing to do
       
    97 	}
       
    98 	
       
    99 RNrhSession::~RNrhSession()
       
   100 	{
       
   101 	// nothing to do
       
   102 	}
       
   103 
       
   104 void RNrhSession::TransmitPosition(const TDesC& aDestinationId,
       
   105 								   TUint aTransmitPriority,
       
   106 								   TRequestStatus& aStatus, 
       
   107 								   TPositionInfo& aTransmittedPosInfo)
       
   108 	{	
       
   109 	// iDestinationId is too big to fit in the buffer;
       
   110 	// complete the request early with an error code	
       
   111 	if (aDestinationId.Length() > iTransmitPositionParams.iDestinationId.MaxLength())
       
   112 		{
       
   113 		TRequestStatus* status = &aStatus;
       
   114 		User::RequestComplete(status, KErrTooBig);
       
   115 		}
       
   116 	
       
   117 	iTransmitPositionParams.iDestinationId = aDestinationId;
       
   118 	iTransmitPositionParams.iPriority = aTransmitPriority;
       
   119 	iTransmitPositionParams.iPositionInfoClassType = aTransmittedPosInfo.PositionClassType();
       
   120 	iTransmitPositionParams.iPositionInfoClassSize = aTransmittedPosInfo.PositionClassSize();
       
   121 	
       
   122 	iTransmitPositionParamsPtr.Set(reinterpret_cast<TUint8*>(&iTransmitPositionParams),
       
   123 								   sizeof(iTransmitPositionParams),
       
   124 								   sizeof(iTransmitPositionParams));
       
   125 	iTransmittedPosInfoPtr.Set(reinterpret_cast<TUint8*>(&aTransmittedPosInfo), 
       
   126 							   aTransmittedPosInfo.PositionClassSize(),
       
   127 							   aTransmittedPosInfo.PositionClassSize());
       
   128 	TIpcArgs args(&iTransmitPositionParamsPtr, &iTransmittedPosInfoPtr);
       
   129 	SendReceive(EX3pTransmitPosition, args, aStatus);
       
   130 	}
       
   131 
       
   132 void RNrhSession::TransmitPosition(const TDesC& aDestinationId,TUint aTransmitPriority,
       
   133 						                 TRequestStatus& aRefPosStatus, TPositionInfo& aRefPosInfo,
       
   134 						  TRequestStatus& aTransmittedPosStatus, TPositionInfo& aTransmittedPosInfo)
       
   135 	{
       
   136 	// iDestinationId is too big to fit in the buffer;
       
   137 	// complete the request early with an error code	
       
   138 	if (aDestinationId.Length() > iTransmitPositionParams.iDestinationId.MaxLength())
       
   139 		{
       
   140 		TRequestStatus* refStatus = &aRefPosStatus;
       
   141 		TRequestStatus* transmittedStatus = &aTransmittedPosStatus;
       
   142 		User::RequestComplete(refStatus, KErrTooBig);
       
   143 		User::RequestComplete(transmittedStatus, KErrTooBig);
       
   144 		}
       
   145 		
       
   146 	ReportReferenceLocation(aRefPosStatus, aRefPosInfo);
       
   147 	TransmitPosition(aDestinationId, aTransmitPriority,
       
   148 					 aTransmittedPosStatus, aTransmittedPosInfo);
       
   149 	}
       
   150 
       
   151 void RNrhSession::ReportReferenceLocation(TRequestStatus& aRefPosStatus, TPositionInfo& aReferencePosInfo)
       
   152 	{
       
   153 
       
   154 	iReferencePositionParams.iPositionInfoClassType = aReferencePosInfo.PositionClassType();
       
   155 	iReferencePositionParams.iPositionInfoClassSize = aReferencePosInfo.PositionClassSize();
       
   156 	
       
   157 	iReferencePositionParamsPtr.Set(reinterpret_cast<TUint8*>(&iReferencePositionParams),
       
   158 								   sizeof(iReferencePositionParams),
       
   159 								   sizeof(iReferencePositionParams));
       
   160 								   
       
   161 	iReferencePosInfoPtr.Set(reinterpret_cast<TUint8*>(&aReferencePosInfo), 
       
   162 							   aReferencePosInfo.PositionClassSize(),
       
   163 							   aReferencePosInfo.PositionClassSize());
       
   164 	TIpcArgs args(&iReferencePositionParamsPtr, &iReferencePosInfoPtr);
       
   165 	SendReceive(EX3pReportReferenceLocation , args, aRefPosStatus);
       
   166 	}
       
   167 
       
   168 void RNrhSession::CancelTransmitPosition()
       
   169 	{
       
   170 	TIpcArgs args;
       
   171 	SendReceive(EX3pCancelTransmitPosition, args);
       
   172 	}
       
   173 
       
   174 TInt RNrhSession::SetTransmitOptions(const TLbsTransmitPositionOptions& aTransmitOptions)
       
   175 	{
       
   176 	TPckgC<TLbsTransmitPositionOptions> optionsPckg(aTransmitOptions);
       
   177 	TIpcArgs args(&optionsPckg);
       
   178 	return (SendReceive(EX3pSetTransmitOptions, args));
       
   179 	}
       
   180 	
       
   181 TInt RNrhSession::GetTransmitOptions(TLbsTransmitPositionOptions& aTransmitOptions) const
       
   182 	{
       
   183 	TPckg<TLbsTransmitPositionOptions> optionsPckg(aTransmitOptions);
       
   184 	TIpcArgs args(&optionsPckg);
       
   185 	return (SendReceive(EX3pGetTransmitOptions, args));
       
   186 	}
       
   187 
       
   188 //
       
   189 // CLbsTransmitPositionServerImpl
       
   190 //
       
   191 
       
   192 CLbsTransmitPositionServerImpl::CLbsTransmitPositionServerImpl()
       
   193 	{
       
   194 	}
       
   195 		
       
   196 CLbsTransmitPositionServerImpl::~CLbsTransmitPositionServerImpl()
       
   197 	{
       
   198 	iServer.Close();
       
   199 	}
       
   200 	
       
   201 CLbsTransmitPositionServerImpl* CLbsTransmitPositionServerImpl::NewL()
       
   202 	{
       
   203 	CLbsTransmitPositionServerImpl* self = new (ELeave) CLbsTransmitPositionServerImpl;
       
   204 	CleanupStack::PushL(self);
       
   205 	self->ConstructL();
       
   206 	CleanupStack::Pop(self);
       
   207 	return self;
       
   208 	}
       
   209 
       
   210 void CLbsTransmitPositionServerImpl::ConstructL()
       
   211 	{
       
   212 	/**
       
   213 	 * See the ServerFramework code for the meaning of this code
       
   214 	 */
       
   215 	iParams.SetServerFileName(KNrhServerFileName);
       
   216 	iParams.SetServerName(KNrhServerName);
       
   217 	iParams.SetNumberOfServerSlots(-1); // Use messages from the global pool
       
   218 	iParams.SetServerUids(KNullUid, KNullUid, KLbsNetRequestHandlerUid);
       
   219 	
       
   220 	User::LeaveIfError(iServer.Connect(iParams));
       
   221 	}
       
   222 
       
   223 RNrhServer& CLbsTransmitPositionServerImpl::Server()
       
   224 	{
       
   225 	return iServer;
       
   226 	}
       
   227 
       
   228 //
       
   229 // CLbsTransmitPositionImpl
       
   230 //
       
   231 
       
   232 CLbsTransmitPositionImpl::CLbsTransmitPositionImpl()
       
   233 	{
       
   234 	
       
   235 	}
       
   236 	
       
   237 CLbsTransmitPositionImpl::~CLbsTransmitPositionImpl()
       
   238 	{
       
   239 	iSession.Close();
       
   240 	}
       
   241 
       
   242 CLbsTransmitPositionImpl* CLbsTransmitPositionImpl::NewL(RLbsTransmitPositionServer& aServer)
       
   243 	{
       
   244 	CLbsTransmitPositionImpl* self = new (ELeave) CLbsTransmitPositionImpl;
       
   245 	CleanupStack::PushL(self);
       
   246 	self->ConstructL(aServer);
       
   247 	CleanupStack::Pop(self);
       
   248 	return self;	
       
   249 	}
       
   250 
       
   251 void CLbsTransmitPositionImpl::ConstructL(RLbsTransmitPositionServer& aServer)
       
   252 	{
       
   253 	TNrhX3PData data;
       
   254 	TNrhSubSessionType type(ENrhSubSessionX3P);
       
   255 	User::LeaveIfError(iSession.Open<TNrhSubSessionType, TNrhX3PData>(
       
   256 						aServer.Impl().Server(), 
       
   257 						type,
       
   258 						data));
       
   259 	}
       
   260 
       
   261 void CLbsTransmitPositionImpl::TransmitPosition(const TDesC& aDestinationID,
       
   262 												TUint aTransmitPriority, 
       
   263 												TRequestStatus& aTransmittedPosStatus, 
       
   264 												TPositionInfo& aTransmittedPosInfo)
       
   265 	{
       
   266 	iSession.TransmitPosition(aDestinationID, aTransmitPriority,
       
   267 							  aTransmittedPosStatus, aTransmittedPosInfo);
       
   268 	}
       
   269 
       
   270 void CLbsTransmitPositionImpl::TransmitPosition(const TDesC& aDestinationID,TUint aTransmitPriority,
       
   271 						                 TRequestStatus& aRefPosStatus, TPositionInfo& aRefPosInfo,
       
   272 						  TRequestStatus& aTransmittedPosStatus, TPositionInfo& aTransmittedPosInfo)
       
   273 	{
       
   274 	iSession.TransmitPosition(aDestinationID, aTransmitPriority, aRefPosStatus,aRefPosInfo,
       
   275 						      aTransmittedPosStatus, aTransmittedPosInfo);
       
   276 	}
       
   277 
       
   278 void CLbsTransmitPositionImpl::CancelTransmitPosition()
       
   279 	{
       
   280 	iSession.CancelTransmitPosition();
       
   281 	}
       
   282 
       
   283 TInt CLbsTransmitPositionImpl::SetTransmitOptions(const TLbsTransmitPositionOptions& aTransmitOptions)
       
   284 	{
       
   285 	return (iSession.SetTransmitOptions(aTransmitOptions));
       
   286 	}
       
   287 	
       
   288 TInt CLbsTransmitPositionImpl::GetTransmitOptions(TLbsTransmitPositionOptions& aTransmitOptions) const
       
   289 	{
       
   290 	return (iSession.GetTransmitOptions(aTransmitOptions));
       
   291 	}
       
   292 
       
   293