linklayercontrol/nullagt/src/NullAgent.cpp
changeset 0 af10295192d8
child 37 052078dda061
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 1997-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 NullAgent.CPP 
       
    18 */
       
    19 
       
    20 #include "NullAgent.h"
       
    21 #include <d32comm.h> // Conversion of link speed constants
       
    22 #include <cdbcols.h> // CommDB access
       
    23 
       
    24 #ifdef SYMBIAN_ADAPTIVE_TCP_RECEIVE_WINDOW
       
    25 #include <networking\cfbearers.h>
       
    26 #endif //SYMBIAN_ADAPTIVE_TCP_RECEIVE_WINDOW
       
    27 
       
    28 /**
       
    29 KNullAgentPanic indicates NullAgent
       
    30 
       
    31 @internalComponent
       
    32 */
       
    33 
       
    34 extern "C" EXPORT_C CNifAgentFactory* NewAgentFactoryL()
       
    35 /**
       
    36 Agent Factory
       
    37 First ordinal export
       
    38 
       
    39 @internalComponent
       
    40 @return an object to class CNullAgentFactory,which Perform Agent initialisation.
       
    41 */
       
    42 	{	
       
    43 	return new(ELeave) CNullAgentFactory;
       
    44 	}
       
    45 
       
    46 void CNullAgentFactory::InstallL() 
       
    47 /**
       
    48 Performs a new Agent initialisation
       
    49 */
       
    50 	{}
       
    51  
       
    52 CNifAgentBase* CNullAgentFactory::NewAgentL(const TDesC& /*aName*/)
       
    53 /**
       
    54 Creates a new NullAgent to Nifman
       
    55 
       
    56 @param aName , name of the NullAgent
       
    57 @return a new instance of class CNullAgent
       
    58 */
       
    59 	{
       
    60 	return CNullAgent::NewL();
       
    61 	}
       
    62 
       
    63 TInt CNullAgentFactory::Info(TNifAgentInfo& aInfo, TInt /*aIndex*/) const
       
    64 /**
       
    65 Retrieves information about the Agent
       
    66 
       
    67 @param aInfo,a reference of class TNifAgentInfo which contains information about NullAgent
       
    68 @return KErrNone if information retrieved successfully.
       
    69 */
       
    70 	{
       
    71 	aInfo.iName = KNullAgentName;
       
    72 	aInfo.iVersion = TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
       
    73 	return KErrNone;
       
    74 	}
       
    75 
       
    76 CNullAgent::CNullAgent() :	iServiceStartedCallback(CActive::EPriorityStandard),
       
    77 							iConnectCompleteCallback(CActive::EPriorityStandard), 
       
    78 							iDisconnectCallback(CActive::EPriorityStandard)
       
    79 /**
       
    80 Default Constructor
       
    81 */
       
    82 	{
       
    83 	TCallBack serviceStartedCallback(ServiceStartedCb, this);
       
    84 	iServiceStartedCallback.Set(serviceStartedCallback);
       
    85 	
       
    86 	TCallBack connectionCompleteCallback(ConnectCompleteCb, this);
       
    87 	iConnectCompleteCallback.Set(connectionCompleteCallback);
       
    88 
       
    89 	TCallBack disconnectionCompleteCallback(DisconnectCompleteCb, this);
       
    90 	iDisconnectCallback.Set(disconnectionCompleteCallback);
       
    91 
       
    92 	iCancelled = EFalse;
       
    93 	}
       
    94  
       
    95 CNullAgent::~CNullAgent()
       
    96 /**
       
    97 Destructor
       
    98 */
       
    99 	{
       
   100 	iServiceStartedCallback.Cancel();
       
   101 	iConnectCompleteCallback.Cancel();
       
   102 	iDisconnectCallback.Cancel();
       
   103 	}
       
   104 
       
   105 
       
   106 CNullAgent* CNullAgent::NewL()
       
   107 /**
       
   108 Static NewL function constructing an object of class CNullAgent
       
   109 
       
   110 @return self,pointer to class CNullAgent,that owns a CAsyncCallback used to 
       
   111 control the asynchronous ServiceStarted() and DisconnectComplete() call from the Agent to Nifman. 
       
   112 */
       
   113 	{
       
   114 	CNullAgent* self = new (ELeave) CNullAgent();
       
   115 	CleanupStack::PushL(self);
       
   116 	self->ConstructL();
       
   117 	CleanupStack::Pop(); // self
       
   118 	return self;
       
   119 	}
       
   120 
       
   121 void CNullAgent::ConstructL()
       
   122 /**
       
   123 2nd Phase Constructor
       
   124 Calls CAgentBase::ConstructL()
       
   125 construct the database and dialog processor
       
   126 */
       
   127 	{
       
   128 	CAgentBase::ConstructL();
       
   129 	iConnected = EFalse;
       
   130 	}
       
   131 
       
   132 void CNullAgent::Info(TNifAgentInfo& aInfo) const
       
   133 /**
       
   134 Information about this Agent
       
   135 
       
   136 @param aInfo on return contains information about the agent
       
   137 */
       
   138 	{
       
   139 	aInfo.iName = KNullAgentName;
       
   140 	aInfo.iName.AppendFormat(_L("-AgentFactory[0x%08x]"), this);
       
   141 	aInfo.iVersion = TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
       
   142 	}
       
   143 
       
   144 void CNullAgent::Connect(TAgentConnectType aType)
       
   145 /**
       
   146 Connects this NullAgent to Nifman
       
   147 
       
   148 @internalComponent  
       
   149 @param aType, a variable of enum TAgentConnectType describing connection types.
       
   150 */
       
   151 	{
       
   152 	if (EAgentReconnect == aType)
       
   153 		{
       
   154 		// skip forward to connect complete (service started would panic as we already have an interface etc)
       
   155 		iConnectCompleteCallback.CallBack();
       
   156 		}
       
   157 	else
       
   158 		{
       
   159 		iCancelled = EFalse;
       
   160 		iServiceStartedCallback.CallBack();		
       
   161 		}
       
   162 	}
       
   163 
       
   164 void CNullAgent::Connect(TAgentConnectType aType, CStoreableOverrideSettings* /*aOverrideSettings*/)
       
   165 /**
       
   166 Connects this NullAgent to Nifman with store and retrieve commDB override sets to and from both
       
   167 streams and buffers.
       
   168 
       
   169 @param aType,a variable of enum TAgentConnectType describing connection types.
       
   170 @param aOverrideSettings, a pointer to class CStoreableOverrideSettings which store CommDB overrides.
       
   171 */
       
   172 	{
       
   173 	Connect(aType);
       
   174 	}
       
   175 
       
   176 void CNullAgent::CancelConnect()
       
   177 /**
       
   178 Cancels Connection of the NullAgent to Nifman 
       
   179 */
       
   180 	{
       
   181 	iServiceStartedCallback.Cancel();
       
   182 	iConnectCompleteCallback.Cancel();
       
   183 	iConnected = EFalse;
       
   184 	iCancelled = ETrue;
       
   185 	}
       
   186 
       
   187 void CNullAgent::Disconnect(TInt /*aReason*/)
       
   188 /**
       
   189 Disconnects from the NullAgent to Nifman with reason 
       
   190 
       
   191 @param aReason, reason for disconnection to the agent.
       
   192 */
       
   193 	{
       
   194 	iDisconnectCallback.CallBack();
       
   195 	}
       
   196 
       
   197 void CNullAgent::ServiceStarted(TInt /*aError*/)
       
   198 /**
       
   199 ConnectionComplete from NullAgent to Nifman
       
   200 This function is calling CallBack() function if connect is not cancelled
       
   201 
       
   202 @param aError, error number for which service needs to be started.
       
   203 */
       
   204 	{
       
   205 	__ASSERT_DEBUG(iNotify, NullAgentPanic(NullAgent::ENullNifmanNotifyPointer));
       
   206 
       
   207 	iNotify->AgentProgress(ENullAgtConnecting, KErrNone);
       
   208 	iNotify->ServiceStarted();
       
   209 	
       
   210 	/* if the connect has been cancelled during ServiceStarted() then we need to avoid 
       
   211 	 * calling ConnectComplete() - done in this next callback - otherwise we get a panic */
       
   212 	if (!iCancelled)
       
   213 		iConnectCompleteCallback.CallBack();
       
   214 	}
       
   215 
       
   216 void CNullAgent::ConnectionComplete(TInt aError)
       
   217 /**
       
   218 Second phase of completing connection of NullAgent to Nifman
       
   219 
       
   220 @param aError,error number for which connection is complete.
       
   221 */
       
   222 {
       
   223 	__ASSERT_DEBUG(iNotify, NullAgentPanic(NullAgent::ENullNifmanNotifyPointer));
       
   224 
       
   225 	iNotify->AgentProgress(ENullAgtConnected, KErrNone);
       
   226 	iNotify->ConnectComplete(aError);
       
   227 	iConnected = ETrue;
       
   228 }
       
   229 
       
   230 void CNullAgent::DisconnectionComplete()
       
   231 /**
       
   232 Completes the disconnection of NullAgent from Nifman
       
   233 */
       
   234 	{
       
   235 	__ASSERT_DEBUG(iNotify, NullAgentPanic(NullAgent::ENullNifmanNotifyPointer));
       
   236 
       
   237 	iNotify->AgentProgress(ENullAgtDisconnected, KErrNone);
       
   238 	iConnected = EFalse;
       
   239 	iNotify->DisconnectComplete();
       
   240 }
       
   241 
       
   242 TInt CNullAgent::GetExcessData(TDes8& /*aBuffer*/)
       
   243 /**
       
   244 Gets excessData from NullAgent to Nifman
       
   245 
       
   246 @param aBuffer, variable containing the name of NullAgent
       
   247 @return KErrNotSupported,error code if it does not get excess data from NullAgent.
       
   248 */
       
   249 	{
       
   250 	return KErrNotSupported;
       
   251 	}
       
   252 
       
   253 TInt CNullAgent::Notification(TNifToAgentEventType aEvent, TAny* /*aInfo*/)
       
   254 /**
       
   255 Establishes the Notification types from Nif to Agent for the agent
       
   256 
       
   257 @param aEvent,a variable of enum TNifToAgentEventType, which contains Notification types from Nif to Agent
       
   258 @param aInfo, information about the agent
       
   259 @return KErrNotSupported,error code if the notification type does not exist.
       
   260 */
       
   261 	{
       
   262 	TUint speedFromCommDb(0);
       
   263 	switch (aEvent)
       
   264 		{
       
   265 		// Respond to Raw IP NIF events
       
   266 		// N.B. This targets RawIP NIF in a test setup exclusively.
       
   267 		case (ENifToAgentEventTsyConfig) : 
       
   268 			iNotify->Notification(EAgentToNifEventTsyConfig, reinterpret_cast<TAny*>(&iTsyConfig));
       
   269 			break;
       
   270 				
       
   271 		case (ENifToAgentEventTsyConnectionSpeed) : 
       
   272 			// Reply with a static value from CommDB.
       
   273 			speedFromCommDb = CommDbModemBearerRate();
       
   274 			iNotify->Notification(EAgentToNifEventTsyConnectionSpeed, reinterpret_cast<TAny*>(&speedFromCommDb));
       
   275 			break;				
       
   276 		default : 
       
   277 			return KErrNotSupported;			
       
   278 		}
       
   279 	return KErrNone;		
       
   280 	}
       
   281 
       
   282 void CNullAgent::GetLastError(TInt& aError)
       
   283 /**
       
   284 Gets the LastError
       
   285 */
       
   286 	{
       
   287 	aError = KErrNone;
       
   288 	}
       
   289 
       
   290 TInt CNullAgent::IncomingConnectionReceived()
       
   291 /**
       
   292 IncomingConnectionReceived
       
   293 
       
   294 @return KErrNotSupported, error code if incoming connection is not received.
       
   295 */
       
   296 	{
       
   297 	return KErrNotSupported;
       
   298 	}
       
   299 
       
   300 TInt CNullAgent::ServiceStartedCb(TAny* aThisPtr)
       
   301 /**
       
   302  * Connection Callback static function 
       
   303  *
       
   304  */
       
   305 	{
       
   306 	__ASSERT_DEBUG( aThisPtr, NullAgentPanic(NullAgent::ENullTAnyPointer));
       
   307 
       
   308 	CNullAgent* self = (CNullAgent*)aThisPtr;
       
   309 	self->ServiceStarted(KErrNone);
       
   310 	return KErrNone;
       
   311 	}
       
   312 
       
   313 TInt CNullAgent::ConnectCompleteCb(TAny* aThisPtr)
       
   314 /**
       
   315  * Second callback used during connection creation
       
   316  *
       
   317  */
       
   318 {
       
   319 	__ASSERT_DEBUG(aThisPtr, NullAgentPanic(NullAgent::ENullTAnyPointer));
       
   320 
       
   321 	CNullAgent* self = (CNullAgent*) aThisPtr;
       
   322 	self->ConnectionComplete(KErrNone);
       
   323 	return KErrNone;
       
   324 }
       
   325 
       
   326 TInt CNullAgent::DisconnectCompleteCb(TAny* aThisPtr)
       
   327 /**
       
   328  * Disconnection callback static function
       
   329  *
       
   330  */
       
   331 {
       
   332 	__ASSERT_DEBUG(aThisPtr, NullAgentPanic(NullAgent::ENullTAnyPointer));
       
   333 
       
   334 	CNullAgent* self = (CNullAgent*) aThisPtr;
       
   335 	self->DisconnectionComplete();
       
   336 	return KErrNone;
       
   337 }
       
   338 
       
   339 /**
       
   340 Returns the static link rate from CommDB Modem Bearer table
       
   341 
       
   342 @return link rate 
       
   343 */ 
       
   344 TUint CNullAgent::CommDbModemBearerRate()
       
   345 	{
       
   346 	static const TUint KDefaultSpeed(115200);// Default value to use in case of a failure.
       
   347 	TUint32 speedMetric(0);
       
   348 	
       
   349 	TBuf<KCommsDbSvrMaxColumnNameLength> rateColName = TPtrC(MODEM_BEARER);
       
   350 	rateColName.Append(TChar(KSlashChar));
       
   351 	rateColName.Append(TPtrC(MODEM_RATE));
       
   352 	
       
   353 	TInt err = ReadInt(rateColName, speedMetric);
       
   354 	if(KErrNone != err)
       
   355 		{
       
   356 		return KDefaultSpeed; 
       
   357 		}
       
   358 	
       
   359 	switch(speedMetric)
       
   360 		{
       
   361 		case EBps50:
       
   362 			return 50;
       
   363 		case EBps75:
       
   364 			return 75;
       
   365 		case EBps110:
       
   366 			return 110;
       
   367 		case EBps134:
       
   368 			return 134;
       
   369 		case EBps150:
       
   370 			return 150;
       
   371 		case EBps300:
       
   372 			return 300;
       
   373 		case EBps600:
       
   374 			return 600;
       
   375 		case EBps1200:
       
   376 			return 1200;
       
   377 		case EBps1800:
       
   378 			return 1800;
       
   379 		case EBps2000:
       
   380 			return 2000;
       
   381 		case EBps2400:
       
   382 			return 2400;
       
   383 		case EBps3600:
       
   384 			return 3600;
       
   385 		case EBps4800:
       
   386 			return 4800;
       
   387 		case EBps7200:
       
   388 			return 7200;
       
   389 		case EBps9600:
       
   390 			return 9600;
       
   391 		case EBps19200:
       
   392 			return 19200;
       
   393 		case EBps38400:
       
   394 			return 38400;
       
   395 		case EBps57600:
       
   396 			return 57600;
       
   397 		case EBps115200:
       
   398 			return 115200;
       
   399 		case EBps230400:
       
   400 			return 230400;
       
   401 		case EBps460800:
       
   402 			return 460800;
       
   403 		case EBps576000:
       
   404 			return 576000;
       
   405 		case EBps1152000:
       
   406 			return 1152000;
       
   407 		case EBps4000000:
       
   408 			return 4000000;
       
   409 		default:
       
   410 			break;
       
   411 		}
       
   412 	return KDefaultSpeed;
       
   413 	}
       
   414 		
       
   415 #ifdef SYMBIAN_ADAPTIVE_TCP_RECEIVE_WINDOW
       
   416 /*
       
   417 Returns the value of the ethernet as the bearer
       
   418 @return Ethernet bearer
       
   419 */
       
   420 TUint32 CNullAgent::GetBearerInfo() const
       
   421 	{
       
   422 	return KEthernetBearer;
       
   423 	}
       
   424 #endif //SYMBIAN_ADAPTIVE_TCP_RECEIVE_WINDOW
       
   425 				
       
   426 	
       
   427 
       
   428 
       
   429 
       
   430 
       
   431 
       
   432 
       
   433 
       
   434 //void CNullAgent::MDPOLoginComplete(TInt /*aError*/) 
       
   435 //	{}
       
   436 
       
   437 //void CNullAgent::MDPOReadPctComplete(TInt /*aError*/) 
       
   438 //	{}
       
   439 
       
   440 //void CNullAgent::MDPODestroyPctComplete(TInt /*aError*/) 
       
   441 //	{}
       
   442 
       
   443 //void CNullAgent::MDPOQoSWarningComplete(TInt /*aError*/, TBool /*aResponse*/) 
       
   444 //	{}