locationrequestmgmt/networkrequesthandler/LbsX3P/LbsX3PApi/src/LbsX3PPositioner.cpp
changeset 36 b47902b73a93
parent 0 9cfd9a3ee49c
equal deleted inserted replaced
35:a2efdd544abf 36:b47902b73a93
       
     1 // Copyright (c) 2005-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 #include <s32mem.h>
       
    17 #include <lbs/lbsx3p.h>
       
    18 #include <lbs.h>
       
    19 #include <lbs/lbsloccommon.h>
       
    20 #include <lbs/lbslocerrors.h>
       
    21 #include <lbs/lbslocclasstypes.h>
       
    22 #include "LbsX3PImpl.h"
       
    23 #include "lbsdevloggermacros.h"
       
    24 
       
    25 // Version of Lbs Transfer Position To Third Party
       
    26 const TInt8 KPosX3PMajorVersionNumber 	= 1;
       
    27 const TInt8 KPosX3PMinorVersionNumber 	= 0;
       
    28 const TInt16 KPosX3PBuildVersionNumber	= 0;
       
    29 
       
    30 //-----------------------------------------------------------------------------
       
    31 // RLbsTransmitPositionServer
       
    32 //-----------------------------------------------------------------------------
       
    33 EXPORT_C RLbsTransmitPositionServer::RLbsTransmitPositionServer()
       
    34 /**
       
    35 Constructor for RLbsTransmitPositionServer
       
    36 
       
    37  */ 
       
    38  	: iImpl(NULL)
       
    39  	{
       
    40  	LBSLOG(ELogP9, "->S RLbsTransmitPositionServer::() lbsnetworkrequesthandler.exe\n");
       
    41 	}
       
    42 
       
    43 EXPORT_C void RLbsTransmitPositionServer::ConstructL()
       
    44 /**
       
    45 Leaving constructor for RLbsTransmitPositionServer. Just creates the ptr-holder.
       
    46 @internalComponent
       
    47  */
       
    48 	{
       
    49 	__ASSERT_ALWAYS(iImpl == NULL, User::Panic(KLbsLocFrameworkClientFault, EPositionServerHandleNotClosed));
       
    50 	
       
    51 	iImpl = CLbsTransmitPositionServerImpl::NewL();
       
    52 	}
       
    53 
       
    54 EXPORT_C void RLbsTransmitPositionServer::Destruct()
       
    55 /**
       
    56 Destruction method for RLbsTransmitPositionServer. Just deletes the ptr-holder.
       
    57 @internalComponent 
       
    58 @capability None
       
    59  */
       
    60 	{
       
    61 	delete iImpl;
       
    62 	iImpl = NULL;
       
    63 	}
       
    64 
       
    65 EXPORT_C TInt RLbsTransmitPositionServer::Connect()
       
    66 /**
       
    67 Creates a session with the positioning server. If there are no other
       
    68 sessions when this is called, the method will start the server.
       
    69 
       
    70 @capability Location NetworkServices
       
    71 @return a Symbian OS error code.
       
    72  */
       
    73 	{
       
    74 	LBSLOG(ELogP9, "->S RLbsTransmitPositionServer::Connect() lbsnetworkrequesthandler.exe\n");
       
    75 	TInt err;
       
    76 	TRAP(err, ConstructL());
       
    77 	LBSLOG2(ELogP9, "  Return  = %d\n", err);
       
    78 	return err;
       
    79 	}
       
    80 
       
    81 EXPORT_C void RLbsTransmitPositionServer::Close()
       
    82 /**
       
    83 Closes a session with the positioning server.
       
    84 
       
    85 @capability None
       
    86  */
       
    87 	{
       
    88 	LBSLOG(ELogP9, "->S RLbsTransmitPositionServer::Close() lbsnetworkrequesthandler.exe\n");
       
    89 	Destruct();
       
    90 	}
       
    91 
       
    92 
       
    93 EXPORT_C TVersion RLbsTransmitPositionServer::Version() const
       
    94 /**
       
    95 Obtains the current version number of the location server.
       
    96 
       
    97 @capability None
       
    98 @return the version of the client API.
       
    99  */
       
   100 	{
       
   101 	LBSLOG(ELogP9, "->S RLbsTransmitPositionServer::Version() lbsnetworkrequesthandler.exe\n");
       
   102 	LBSLOG4(ELogP9, "  Return TVersion  = (%d, %d, %d)\n", KPosX3PMajorVersionNumber, KPosX3PMinorVersionNumber, 
       
   103 																KPosX3PBuildVersionNumber);
       
   104 	return TVersion(
       
   105 		KPosX3PMajorVersionNumber,
       
   106 		KPosX3PMinorVersionNumber,
       
   107 		KPosX3PBuildVersionNumber);
       
   108 	}
       
   109 
       
   110 /**
       
   111 Returns reference to implementation. Impl() is for internal use only.
       
   112 @internalComponent
       
   113 @released
       
   114 @return Returns reference to implementation. Impl() is for internal use only.
       
   115  */
       
   116 CLbsTransmitPositionServerImpl& RLbsTransmitPositionServer::Impl()
       
   117 	{
       
   118 	__ASSERT_ALWAYS(iImpl != NULL, User::Panic(KLbsLocFrameworkClientFault, EPositionServerBadHandle));
       
   119 	return *iImpl;
       
   120 	}
       
   121 
       
   122 /**
       
   123 Reserved for future expansion - derived classes should see documentation
       
   124 @param aFunctionNumber contains the Id of the function to be invoked.
       
   125 @param aPtr1 a pointer to any data 
       
   126 @param aPtr2 a pointer to any data.
       
   127 @return TAny* pointer to any function
       
   128  */
       
   129 EXPORT_C TAny* RLbsTransmitPositionServer::ExtendedInterface(TInt /*aFunctionNumber*/, TAny* /*aPtr1*/, TAny* /*aPtr2*/)
       
   130 	{
       
   131 	return NULL;
       
   132 	}
       
   133 
       
   134 //-----------------------------------------------------------------------------
       
   135 // RLbsTransmitPosition
       
   136 //-----------------------------------------------------------------------------
       
   137 EXPORT_C RLbsTransmitPosition::RLbsTransmitPosition()
       
   138 /**
       
   139 Constructor for RLbsTransmitPosition
       
   140 
       
   141 
       
   142  */
       
   143  	: iImpl(NULL)
       
   144 	{
       
   145 	LBSLOG(ELogP9, "->S RLbsTransmitPosition::RLbsTransmitPosition() lbsnetworkrequesthandler.exe\n");
       
   146 	}
       
   147 
       
   148 EXPORT_C void RLbsTransmitPosition::ConstructL(RLbsTransmitPositionServer& aServer)
       
   149 /**
       
   150 Leaving constructor for RLbsTransmitPosition. Just creates the ptr-holder.
       
   151 @internalComponent
       
   152 @param aServer Position Server
       
   153 @released  
       
   154  */
       
   155 	{
       
   156 	__ASSERT_ALWAYS(iImpl == NULL, User::Panic(KLbsLocFrameworkClientFault, EPositionServerHandleNotClosed));
       
   157 	
       
   158 	iImpl = CLbsTransmitPositionImpl::NewL(aServer);
       
   159 	}
       
   160 
       
   161 EXPORT_C void RLbsTransmitPosition::Destruct()
       
   162 /**
       
   163 Destruction method for RLbsTransmitPosition.
       
   164 @internalComponent
       
   165 @released 
       
   166  */
       
   167 	{
       
   168 	delete iImpl;
       
   169 	iImpl = NULL;
       
   170 	}
       
   171 
       
   172 EXPORT_C TInt RLbsTransmitPosition::Open(RLbsTransmitPositionServer& aServer)
       
   173 /**
       
   174 Creates a sub-session with the positioning server.
       
   175 
       
   176 @capability Location NetworkServices
       
   177 @param aServer is a connected session with the positioning server.
       
   178 @return a Symbian OS error code.
       
   179  */
       
   180 	{
       
   181 	LBSLOG(ELogP9, "->S RLbsTransmitPosition::Open() lbsnetworkrequesthandler.exe\n");
       
   182 	LBSLOG2(ELogP9, "  > RLbsTransmitPositionServer aServer  = 0x%08X\n", &aServer);
       
   183 	TInt err;
       
   184 	TRAP(err, ConstructL(aServer));
       
   185 	LBSLOG2(ELogP9, "  Return  = %d\n", err);
       
   186 	return err;
       
   187 	}
       
   188 
       
   189 
       
   190 EXPORT_C void RLbsTransmitPosition::Close()
       
   191 /**
       
   192 Closes a sub-session with the positioning server.
       
   193 
       
   194  */
       
   195 	{
       
   196 	LBSLOG(ELogP9, "->S RLbsTransmitPosition::Close() lbsnetworkrequesthandler.exe\n");
       
   197 	Destruct();
       
   198 	}
       
   199 
       
   200 /**
       
   201 This is method is used to set the options that will be used when
       
   202 requesting that the current position be sent to a third party.
       
   203 
       
   204 @capability Location NetworkServices
       
   205 @param aTransmitOptions is the options to be used.
       
   206 @return a Symbian OS error code.
       
   207  */
       
   208 EXPORT_C TInt RLbsTransmitPosition::SetTransmitOptions(const TLbsTransmitPositionOptions& aTransmitOptions)
       
   209 	{
       
   210 	LBSLOG(ELogP9, "->S RLbsTransmitPosition::SetTransmitOptions() lbsnetworkrequesthandler.exe\n");
       
   211 	LBSLOG2(ELogP9, "  > TLbsTransmitPositionOptions aTransmitOptions  = %ld\n", aTransmitOptions.TimeOut().Int64());
       
   212 	__ASSERT_ALWAYS(iImpl != NULL, User::Panic(KLbsLocFrameworkClientFault, 
       
   213 										EPositionServerBadHandle));
       
   214 	
       
   215 	TInt err = iImpl->SetTransmitOptions(aTransmitOptions);
       
   216 	LBSLOG2(ELogP9, "  Return  = %d\n", err);
       
   217 	return err;
       
   218 	}
       
   219 
       
   220 /**
       
   221 This is method is used to get the current setting for the options that will be used when
       
   222 requesting that the current position be sent to a third party.
       
   223 
       
   224 @capability Location NetworkServices
       
   225 @param aTransmitOptions is the options currently set.
       
   226 @return a Symbian OS error code.
       
   227  */
       
   228 EXPORT_C TInt RLbsTransmitPosition::GetTransmitOptions(TLbsTransmitPositionOptions& aTransmitOptions) const
       
   229 	{
       
   230 	LBSLOG(ELogP9, "->S RLbsTransmitPosition::GetTransmitOptions() lbsnetworkrequesthandler.exe\n");
       
   231 	__ASSERT_ALWAYS(iImpl != NULL, User::Panic(KLbsLocFrameworkClientFault, 
       
   232 										EPositionServerBadHandle));
       
   233 	
       
   234 	TInt err = iImpl->GetTransmitOptions(aTransmitOptions);
       
   235 	LBSLOG2(ELogP9, "  < TLbsTransmitPositionOptions aTransmitOptions  = %ld\n", aTransmitOptions.TimeOut().Int64());
       
   236 	LBSLOG2(ELogP9, "  Return  = %d\n", err);
       
   237 	return err;
       
   238 	}
       
   239 
       
   240 
       
   241  /**
       
   242 This is an asynchronous method for requesting that the current position be sent to a third 
       
   243 party. Upon successful completion, the position sent will be returned to the caller in aTransmittedPosInfo.
       
   244 
       
   245 
       
   246 @capability Location NetworkServices
       
   247 @param aDestinationID      identifies the third party. For example, it may be 
       
   248 the phone number or email address of the recipient of the position.
       
   249 @param aTransmitPriority   Priority that this request must be given. The priority
       
   250 determines the order in which transfer requests are processed.
       
   251 A priority of zero is the highest priority.
       
   252 @param aTransmittedStatus  TRequestStatus of the Active Object whose RunL will be called
       
   253 when this asynchronous request completes (the value should be checked by the caller to ensure
       
   254 that the operation was successful).
       
   255 @param aTransmittedPosInfo When the request completes succesfully, this variable will store 
       
   256 the position of the handset that was made available to the remote third party . This position
       
   257 might have been calculated by an on-board GPS receiver (terminal based and autonomous GPS modes)
       
   258 or may have been calculated by the network (terminal assisted mode).
       
   259  */
       
   260 EXPORT_C void RLbsTransmitPosition::TransmitPosition(const TDesC& aDestinationID, 
       
   261 													 TUint aTransmitPriority, 
       
   262 													 TRequestStatus& aTransmittedPosStatus, 
       
   263 													 TPositionInfo& aTransmittedPosInfo)
       
   264 	{
       
   265 	LBSLOG(ELogP9, "->A RLbsTransmitPosition::TransmitPosition(4) lbsnetworkrequesthandler.exe\n");
       
   266 	LBSLOG2(ELogP9, "  > TDesC aDestinationID  = %S\n", &aDestinationID);
       
   267 	LBSLOG2(ELogP9, "  > TRequestStatus aTransmittedPosStatus  = %d\n", aTransmittedPosStatus.Int());
       
   268 	LBSLOG2(ELogP9, "  > TUint aTransmitPriority  = %u\n", aTransmitPriority);
       
   269 
       
   270 	__ASSERT_ALWAYS(iImpl != NULL, User::Panic(KLbsLocFrameworkClientFault, 
       
   271 										EPositionServerBadHandle));
       
   272 	
       
   273 	iImpl->TransmitPosition(aDestinationID, aTransmitPriority,
       
   274 							aTransmittedPosStatus, aTransmittedPosInfo);
       
   275 	}
       
   276 
       
   277 /**
       
   278 This asynchronous method is used to request that the current handset position be transmitted
       
   279 to a third party.
       
   280 
       
   281 If there are no errors or cancellations, invoking this method will result in the user
       
   282 being called back twice and given two sequencial location upates.
       
   283 
       
   284 The first location update will take place when aRefPosStatus is signalled and will consist of
       
   285 a Reference Location which is provided by the network to the handset in the early stages
       
   286 of the transmition procedure. This position is made available to the caller in aRefPosInfo.
       
   287 
       
   288 The second location update will take place when aTransmittedPosStatus is signalled. When that
       
   289 happens aTransmitedPosInfo will contain the final position sent to the third party. This is a
       
   290 more accurate position than the Reference Location and is calculated (either in the handset 
       
   291 or in the network) with GPS data collected by the handset.
       
   292 
       
   293 
       
   294 @capability Location NetworkServices
       
   295 @param aDestinationID      identifies the third party. For example, it may be
       
   296 the phone number or email address of the recipient of the position.
       
   297 @param aTransmitPriority   Priority that this request must be given. The priority
       
   298 determines the order in which transfer requests are processed. A priority of zero is the highest priority.
       
   299 @param aRefPosStatus  TRequestStatus of the Active Object whose RunL will be called
       
   300 as soon as the Reference Location is available in aRefPosInfo. The status value should be checked by the 
       
   301 caller to ensure that the operation was successful.
       
   302 @param aRefPosInfo When aRefPosStatus is signalled, this variable will contain the Reference 
       
   303 Location provided by the network.
       
   304 @param aTransmittedPosStatus TRequestStatus of the Active Object whose RunL will be called
       
   305 when the transmition has completed. The status value should be checked by the caller to ensure
       
   306 that the operation was successful, in which case the transmitted position is available in aTransmittedPosInfo.
       
   307 @param aTransmittedPosInfo When the request completes succesfully, this variable will store 
       
   308 the position of the handset that was made available to the remote third party . This position
       
   309 might have been calculated by an on-board GPS receiver (terminal based and autonomous GPS modes)
       
   310 or may have been calculated by the network (terminal assisted mode).
       
   311  */
       
   312 EXPORT_C void RLbsTransmitPosition::TransmitPosition(const TDesC& aDestinationID,
       
   313 													 TUint aTransmitPriority, 
       
   314 													 TRequestStatus& aRefPosStatus,
       
   315 													 TPositionInfo& aRefPosInfo,
       
   316 													 TRequestStatus& aTransmittedPosStatus,
       
   317 													 TPositionInfo& aTransmittedPosInfo)
       
   318 	{
       
   319 	LBSLOG(ELogP9, "->A RLbsTransmitPosition::TransmitPosition(6) lbsnetworkrequesthandler.exe\n");
       
   320 	LBSLOG2(ELogP9, "  > TDesC aDestinationID  = %S\n", &aDestinationID);
       
   321 	LBSLOG2(ELogP9, "  > TUint aTransmitPriority  = %d\n", aTransmitPriority);
       
   322 	LBSLOG2(ELogP9, "  > TRequestStatus aRefPosStatus  = %d\n", aRefPosStatus.Int());
       
   323 	LBSLOG2(ELogP9, "  > TRequestStatus aTransmittedPosStatus  = %d\n", aTransmittedPosStatus.Int());
       
   324 
       
   325 	__ASSERT_ALWAYS(iImpl != NULL, User::Panic(KLbsLocFrameworkClientFault, 
       
   326 										EPositionServerBadHandle));
       
   327 	
       
   328 	iImpl->TransmitPosition(aDestinationID, aTransmitPriority,
       
   329 							aRefPosStatus, aRefPosInfo,
       
   330 							aTransmittedPosStatus, aTransmittedPosInfo);
       
   331 	}
       
   332 
       
   333 
       
   334 EXPORT_C void RLbsTransmitPosition::CancelTransmitPosition()
       
   335 /**
       
   336 Cancels a previously issued asynchronous request. The TRequestStatus of the
       
   337 original request will be set to KErrCancel if the cancellation request was
       
   338 successful, or any other Symbian OS error code if CancelTransmitPosition was
       
   339 called too late.
       
   340  
       
   341 @capability Location NetworkServices
       
   342  */
       
   343 	{
       
   344 	LBSLOG(ELogP9, "->S RLbsTransmitPosition::CancelTransmitPosition() lbsnetworkrequesthandler.exe\n");
       
   345 	__ASSERT_ALWAYS(iImpl != NULL, User::Panic(KLbsLocFrameworkClientFault, 
       
   346 										EPositionServerBadHandle));
       
   347 	
       
   348 	iImpl->CancelTransmitPosition();
       
   349 	}
       
   350 
       
   351 /**
       
   352 Reserved for future expansion - derived classes should see documentation
       
   353 @param aFunctionNumber contains the Id of the function to be invoked.
       
   354 @param aPtr1 a pointer to any data 
       
   355 @param aPtr2 a pointer to any data
       
   356 @return TAny* pointer to any function
       
   357  */
       
   358 EXPORT_C TAny* RLbsTransmitPosition::ExtendedInterface(TInt /*aFunctionNumber*/, TAny* /*aPtr1*/, TAny* /*aPtr2*/)
       
   359 	{
       
   360 	LBSLOG(ELogP9, "->S RLbsTransmitPosition::ExtendedInterface() lbsnetworkrequesthandler.exe\n");
       
   361 	return NULL;
       
   362 	}
       
   363 
       
   364 //-----------------------------------------------------------------------------
       
   365 // TLbsTransmitPositionOptions
       
   366 //-----------------------------------------------------------------------------	
       
   367 /**
       
   368 This is the constructor for TTransmitPositionOptions. The time out period 
       
   369 for the TransmitPosition requests is set to the default value thus 
       
   370 timeouts are disabled.
       
   371 
       
   372  */
       
   373 EXPORT_C TLbsTransmitPositionOptions::TLbsTransmitPositionOptions()
       
   374 : TLbsLocClassTypeBase()
       
   375 	{
       
   376 	iClassType |= ETransmitPositionOptionsClass;
       
   377 	iClassSize = sizeof(TLbsTransmitPositionOptions);	
       
   378 	iTimeOut = 0;
       
   379 	}
       
   380 
       
   381 
       
   382 /**
       
   383 This  constructor for TTransmitPositionOptions which allows the client 
       
   384 to define the time out period for the TransmitPosition requests. The value
       
   385 zero may be used to disable timeouts. 
       
   386 
       
   387 @param aTimeOut identifies the time out period
       
   388   */
       
   389 EXPORT_C TLbsTransmitPositionOptions::TLbsTransmitPositionOptions(const TTimeIntervalMicroSeconds& aTimeOut)
       
   390 : TLbsLocClassTypeBase()
       
   391 	{
       
   392 	iClassType |= ETransmitPositionOptionsClass;
       
   393 	iClassSize = sizeof(TLbsTransmitPositionOptions);
       
   394 	SetTimeOut(aTimeOut); // call function so it will panic on -ve timeout
       
   395 	}
       
   396 
       
   397 /**
       
   398 SetTimeOut allows the client to define the time out period for the 
       
   399 TransmitPosition requests. The value  zero may be used to disable timeouts.
       
   400 
       
   401 @param aTimeOut identifies the time out period
       
   402  */
       
   403 EXPORT_C void TLbsTransmitPositionOptions::SetTimeOut(const TTimeIntervalMicroSeconds& aTimeOut)
       
   404 	{
       
   405 	__ASSERT_ALWAYS(aTimeOut >= TTimeIntervalMicroSeconds(0),
       
   406 			User::Panic(KPosClientFault, EPositionBadTime));
       
   407 	iTimeOut = aTimeOut;
       
   408 	}
       
   409 
       
   410 /**
       
   411 TimeOut returns the current timeout period for the TransmitPosition requests.
       
   412 
       
   413 @return the time out period in micro seconds
       
   414  */
       
   415 
       
   416 EXPORT_C TTimeIntervalMicroSeconds TLbsTransmitPositionOptions::TimeOut() const
       
   417 	{
       
   418 	return iTimeOut;
       
   419 	}
       
   420