networkcontrol/ipcpr/src/ipcprprovider.cpp
branchRCL_3
changeset 58 8d540f55e491
parent 57 abbed5a4b42a
child 59 e36178c55292
child 63 425d8f4f7fa5
equal deleted inserted replaced
57:abbed5a4b42a 58:8d540f55e491
     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 // This class is an example implementation of a bearer-mobile network session. It is intended as a guide only and does
       
    15 // not employ any advanced bearer selection algorithms. It is envisaged that users of these classes will want to derive their own
       
    16 // implementations from CIPNetworkSession. 
       
    17 // This is part of an ECOM plug-in
       
    18 // 
       
    19 //
       
    20 
       
    21 #include "ipcprprovider.h"	// for CIPNetworkConnectionProvider
       
    22 #include <comms-infras/ss_log.h>
       
    23 
       
    24 CIPNetworkConnectionProvider* CIPNetworkConnectionProvider::NewL(CConnectionProviderFactoryBase& aFactory)
       
    25 	{			
       
    26 	CIPNetworkConnectionProvider* p = new (ELeave) CIPNetworkConnectionProvider(aFactory);
       
    27 	CleanupStack::PushL(p);
       
    28 	p->iMDes = TMetaDes8::NewL(NULL);
       
    29 	CleanupStack::Pop(p);
       
    30 	__CFLOG_VAR((KIpcprTag, KIpcprSubTag, _L8("CIPNetworkConnectionProvider::NewL() %08x"), p));
       
    31 	return p;	
       
    32 	}
       
    33 	
       
    34 CIPNetworkConnectionProvider::~CIPNetworkConnectionProvider()
       
    35 	{
       
    36 	__CFLOG_VAR((KIpcprTag, KIpcprSubTag, _L8("CIPNetworkConnectionProvider   %08x:\t~CIPNetworkConnectionProvider"), this));
       
    37 	delete iMDes;
       
    38 	if (iShimCpr)
       
    39 		{
       
    40 		iShimCpr->Leave(*this);
       
    41 		}
       
    42 	}
       
    43 	
       
    44 #ifdef SYMBIAN_NETWORKING_UMTSR5	
       
    45 
       
    46 TUint32 CIPNetworkConnectionProvider::GetAppSecureId()
       
    47 	{
       
    48 	return iAppSecureId;
       
    49 	}
       
    50 
       
    51 void CIPNetworkConnectionProvider::SetAppSecurId(TUint32 aSecureId)
       
    52 	{
       
    53 	iAppSecureId = aSecureId;
       
    54 	}
       
    55 	
       
    56 TAny* CIPNetworkConnectionProvider::DoFetchInterfaceInstanceL( const STypeId& aTid )
       
    57 	{
       
    58 	STypeId typeId = STypeId::CreateSTypeId(KConnectionAppInfoInterfaceId,0);
       
    59 	if (typeId == aTid)
       
    60     	{
       
    61     	MConnectionAppIdInfo* ipcpr = static_cast<MConnectionAppIdInfo*>(this);
       
    62     	return ipcpr;
       
    63     	}
       
    64     return NULL;
       
    65 	}
       
    66 	
       
    67 #endif // SYMBIAN_NETWORKING_UMTSR5	
       
    68 //
       
    69 // from MConnectionControlClient
       
    70 void CIPNetworkConnectionProvider::ConnectionGoingDown(CConnectionProviderBase& aConnProvider)
       
    71 	{
       
    72 	__CFLOG_VAR((KIpcprTag, KIpcprSubTag, _L8("CIPNetworkConnectionProvider %08x:\tConnectionGoingDown(aConnProvider %08x)"), this, &aConnProvider));
       
    73 	if (&aConnProvider == iShimCpr)
       
    74 		{
       
    75 		iShimCpr = NULL;
       
    76 		DeleteMeNow();
       
    77 		}
       
    78 	}
       
    79 
       
    80 void CIPNetworkConnectionProvider::ProgressNotification(TInt aStage, TInt aError)
       
    81 	{
       
    82 	__CFLOG_VAR((KIpcprTag, KIpcprSubTag, _L8("CIPNetworkConnectionProvider %08x:\tProgressNotification(aStage %d aError %d)"), this, aStage, aError));
       
    83 	TInt max = iControlClients.Count();
       
    84 	for (TInt i = max - 1 ; i >= 0 ; i--)
       
    85    		{
       
    86 	   	iControlClients[i]->ProgressNotification(aStage, aError);
       
    87 		}
       
    88 	}
       
    89    
       
    90 void CIPNetworkConnectionProvider::ConnectionError(TInt aStage,  TInt aError)
       
    91 	{
       
    92 	__CFLOG_VAR((KIpcprTag, KIpcprSubTag, _L8("CIPNetworkConnectionProvider %08x:\tConnectionError(aStage %d aError %d)"), this, aStage, aError));
       
    93 	TInt max = iControlClients.Count();
       
    94 	for (TInt i = max - 1 ; i >= 0 ; i--)
       
    95 		{
       
    96 		iControlClients[i]->ConnectionError(aStage, aError);
       
    97 		}
       
    98 	max = iDataClients.Count();
       
    99 	for (TInt i = max - 1 ; i >= 0 ; i--)
       
   100 		{
       
   101 		iDataClients[i]->ConnectionError(aStage, aError);
       
   102 		}
       
   103   	}
       
   104    
       
   105 void CIPNetworkConnectionProvider::ServiceChangeNotification(TUint32 aId, const TDesC& aType)
       
   106 	{	
       
   107 	__CFLOG_VAR((KIpcprTag, KIpcprSubTag, _L8("CIPNetworkConnectionProvider %08x:\tServiceChangeNotification(aId %u aType %s)"), this, aId, &aType));
       
   108    	TInt max = iControlClients.Count();
       
   109 	for (TInt i = max - 1 ; i >= 0 ; i--)
       
   110    		{
       
   111 	   	iControlClients[i]->ServiceChangeNotification(aId, aType);
       
   112 		}
       
   113   	}   
       
   114  
       
   115 void CIPNetworkConnectionProvider::SubConnectionEvent(CSubConnectionProviderBase* aSubConnNextLayerProvider, const TSubConnectionEvent& aSubConnectionEvent)
       
   116 	{
       
   117 	TInt max = iControlClients.Count();
       
   118 	for (TInt i = max - 1 ; i >= 0 ; i--)
       
   119 		{
       
   120 	   	iControlClients[i]->SubConnectionEvent(aSubConnNextLayerProvider, aSubConnectionEvent);
       
   121 		}
       
   122 	}
       
   123 
       
   124 void CIPNetworkConnectionProvider::LayerUp(TInt aError)
       
   125 	{
       
   126 	TInt max = iControlClients.Count();
       
   127 	for (TInt i = max - 1 ; i >= 0 ; --i)
       
   128 		{
       
   129 		iControlClients[i]->LayerUp(aError);
       
   130 		}
       
   131 		
       
   132 	// broadcast the event to the data clients also, sideways
       
   133 	max = iDataClients.Count();	
       
   134 	for (TInt j = max - 1; j >= 0 ; --j)
       
   135 		{				
       
   136 		iDataClients[j]->Notify(MConnectionDataClient::ENotifyLayerUp, this, aError, NULL);
       
   137 		}
       
   138    }
       
   139    
       
   140 MConnectionControlClient::TCtlType CIPNetworkConnectionProvider::CtlType() const
       
   141 	{
       
   142 	return MConnectionControlClient::ENormal;
       
   143 	}
       
   144 
       
   145 //
       
   146 // from CConnectionProviderBase
       
   147 void CIPNetworkConnectionProvider::DoDataClientJoiningL(MConnectionDataClient& aDataClient)
       
   148 	{
       
   149 	(void)(aDataClient);
       
   150 	UpdateUsageProfile(NULL);
       
   151 	__CFLOG_VAR((KIpcprTag, KIpcprSubTag, _L8("CIPNetworkConnectionProvider [this=%08x]:\tDoDataClientJoiningL [iDataClients.Count=%d] [aDataClient=%08x]"), this, iDataClients.Count(), &aDataClient));
       
   152 	}
       
   153    
       
   154 void CIPNetworkConnectionProvider::DoDataClientLeaving(MConnectionDataClient& aDataClient)
       
   155 	{
       
   156 	(void)(aDataClient);
       
   157 	UpdateUsageProfile(NULL);
       
   158 	__CFLOG_VAR((KIpcprTag, KIpcprSubTag, _L8("CIPNetworkConnectionProvider [this=%08x]:\tDoDataClientLeaving [iDataClients.Count=%d] [aDataClient=%08x]"), this, iDataClients.Count(), &aDataClient));
       
   159 	}
       
   160    
       
   161 void CIPNetworkConnectionProvider::DoControlClientJoiningL(MConnectionControlClient& aControlClient)
       
   162 	{
       
   163 	(void)(aControlClient);
       
   164 	UpdateUsageProfile(NULL);
       
   165 	__CFLOG_VAR((KIpcprTag, KIpcprSubTag, _L8("CIPNetworkConnectionProvider [this=%08x]:\tDoControlClientJoiningL [iControlClients.Count=%d] [aControlClient=%08x]"), this, iControlClients.Count(), &aControlClient));
       
   166   	}
       
   167    
       
   168 void CIPNetworkConnectionProvider::DoControlClientLeaving(MConnectionControlClient& aControlClient)
       
   169 	{
       
   170 	UpdateUsageProfile(&aControlClient);
       
   171 	__CFLOG_VAR((KIpcprTag, KIpcprSubTag, _L8("CIPNetworkConnectionProvider [this=%08x]:\tDoControlClientLeaving [iControlClients.Count=%d] [aControlClient=%08x]"), this, iControlClients.Count(), &aControlClient));
       
   172   	}
       
   173 
       
   174 void CIPNetworkConnectionProvider::UpdateUsageProfile(MConnectionControlClient* aControlClient)
       
   175 /**
       
   176 Update the Usage Profile if there has been a change in the RConnection's or Sessions associated
       
   177 with this provider.
       
   178 @param aControlClient A control client that should be ignored when calculating the usage profile.
       
   179 */
       
   180 	{
       
   181 	TUint usageProfile = 0;
       
   182 	TInt ignoredClient = 0;
       
   183 	
       
   184 	TInt max = iControlClients.Count();
       
   185 	TInt nConnectionMonitorCount = 0;
       
   186 	TInt nSessionCount = 0;
       
   187 	for (TInt n = 0; n < max; n++)
       
   188 		{
       
   189 		MConnectionControlClient* client = iControlClients[n];
       
   190 		
       
   191 		// Ignore the control client passed as argument (it is the one about to leave).
       
   192 		if (!aControlClient || aControlClient != client)
       
   193 			{
       
   194 			MConnectionControlClient::TCtlType type = client->CtlType();
       
   195 			switch (type)
       
   196 				{
       
   197 				case MConnectionControlClient::EMonitor:
       
   198 					nConnectionMonitorCount++;
       
   199 					break;
       
   200 				case MConnectionControlClient::ESession:
       
   201 					nSessionCount++;
       
   202 					break;
       
   203 				}
       
   204 			}
       
   205 		else
       
   206 			{
       
   207 			ASSERT(ignoredClient == 0);
       
   208 			ignoredClient = 1;
       
   209 			}
       
   210 		}
       
   211 
       
   212 	// Assert that aControlClient, if specified, is	in iControlClients[]
       
   213 	ASSERT(aControlClient == NULL || ignoredClient == 1);
       
   214 	
       
   215 	if (max - ignoredClient > nConnectionMonitorCount)
       
   216 		usageProfile |= KConnProfileMedium;
       
   217 
       
   218 	if (nSessionCount > 0)
       
   219 		usageProfile |= KConnProfileLong;
       
   220 
       
   221 	if (iShimCpr)
       
   222 		{
       
   223 		TBuf8<sizeof(TUint)> buf;
       
   224 		buf.AppendNum(usageProfile);
       
   225 
       
   226 		//Meta derived buffer (iMDes) is only used here to pass
       
   227 		//the usageProfile down to the shimcpr
       
   228 		iMDes->iDes = &buf;
       
   229 
       
   230 		//ESetUsageProfile operation cannot leave in fact=> 
       
   231 		//=>the trap here just to make leavescan happy
       
   232 		TRAP_IGNORE(iShimCpr->ConnectionControlActivityL(ESetUsageProfile, iMDes, NULL));
       
   233 		
       
   234 		//iMDes->iDes will not be used ever again but we clean it so that it is clear
       
   235 		iMDes->iDes = NULL;
       
   236 		}
       
   237 	}
       
   238 
       
   239 void CIPNetworkConnectionProvider::DoStartL(Meta::SMetaData& aParams, const RMessagePtr2* aMessage)
       
   240 	{
       
   241 	if (iShimCpr)
       
   242 		{
       
   243 		iShimCpr->StartL(aParams, aMessage);
       
   244 		}
       
   245 	else
       
   246 		{
       
   247 		User::Leave(KErrNotReady);
       
   248 		}
       
   249   	}
       
   250    	
       
   251 TInt CIPNetworkConnectionProvider::DoStop(TInt aError, const RMessagePtr2* aMessage)
       
   252 	{
       
   253 	return 	iShimCpr ? iShimCpr->Stop(aError, aMessage) : KErrNotReady;
       
   254   	}   
       
   255 
       
   256 void CIPNetworkConnectionProvider::DoProgressL(Meta::SMetaData& aBuffer) const
       
   257 	{
       
   258 	if (iShimCpr)
       
   259 		{
       
   260 		iShimCpr->ProgressL(aBuffer);
       
   261 		}
       
   262   	}
       
   263    
       
   264 void CIPNetworkConnectionProvider::DoLastProgressError(Meta::SMetaData& aBuffer)
       
   265 	{
       
   266 	if (iShimCpr)
       
   267 		{
       
   268 		iShimCpr->LastProgressError(aBuffer);
       
   269 		}
       
   270   	}
       
   271    
       
   272 void CIPNetworkConnectionProvider::DoRequestServiceChangeNotificationL()
       
   273 	{
       
   274 	if (iShimCpr)
       
   275 		{
       
   276 		iShimCpr->RequestServiceChangeNotificationL();
       
   277 		}
       
   278   	}
       
   279    
       
   280 void CIPNetworkConnectionProvider::DoCancelServiceChangeNotification()
       
   281 	{
       
   282 	if (iShimCpr)
       
   283 		{
       
   284 		iShimCpr->CancelServiceChangeNotification();
       
   285 		}
       
   286   	}
       
   287    
       
   288 void CIPNetworkConnectionProvider::DoControlL(TUint aOptionLevel, TUint aOptionName, Meta::SMetaData& aOption, const RMessagePtr2* aMessage)
       
   289 	{
       
   290 	if (iShimCpr)
       
   291 		{
       
   292 		iShimCpr->ControlL(aOptionLevel, aOptionName, aOption, aMessage);
       
   293 		}
       
   294 	else
       
   295 		{
       
   296 		User::Leave(KErrNotReady);	
       
   297 		}
       
   298   	}
       
   299 
       
   300 TInt CIPNetworkConnectionProvider::DoEnumerateSubConnectionsL(TUint& aCount)
       
   301 	{
       
   302 	return iShimCpr ? iShimCpr->EnumerateSubConnectionsL(aCount) : KErrNotReady;
       
   303 	}
       
   304 
       
   305 TUint CIPNetworkConnectionProvider::DoEnumerateClientsL(HBufC8*& aClientInfoBuffer, TEnumClients aClientType)
       
   306 /**
       
   307 Returns information about the clients of this Interface
       
   308 
       
   309 @param aCount on return contains the number of clients using this Interface
       
   310 @param aClientInfoBuffer on return contains a TPckg<> containing information about each client
       
   311 @exception leaves with KErrNoMemory if memory allocation fails
       
   312 */
       
   313 	{	
       
   314 	const TInt KInfoBufMaxLength = 1024;  //is this large enough?
       
   315 	TBuf8<KInfoBufMaxLength> infoBuf;
       
   316 
       
   317 	TUint count = 0;
       
   318 	STypeId tid = STypeId::CreateSTypeId(KConnectionClientExtUid,EConnectionClientDesc);
       
   319 	TInt max = iControlClients.Count();
       
   320 	for ( TInt n = 0; n < max; n++ )
       
   321 		{
       
   322 		MConnectionClientDesc* intf = reinterpret_cast<MConnectionClientDesc*>(iControlClients[n]->FetchInterfaceInstanceL(*this,tid));
       
   323 		if ( intf )
       
   324 			{
       
   325 			TConnectionProcessInfo cinfo;
       
   326 			cinfo.GetInfoL(aClientType, count, *intf, infoBuf);
       
   327 			}
       
   328 		}
       
   329 	STypeId tid2 = STypeId::CreateSTypeId(KConnectionClientExtUid,EConnectionEnumerateClients);
       
   330 	max = iDataClients.Count();
       
   331 	for ( TInt n = 0; n < max; n++ )
       
   332 		{
       
   333 		MConnectionEnumerateClients* intf = reinterpret_cast<MConnectionEnumerateClients*>(iDataClients[n]->FetchInterfaceInstanceL(*this,tid2));
       
   334 		if ( intf )
       
   335 			{
       
   336 			intf->EnumerateClientsL(count, infoBuf, aClientType);
       
   337 			}
       
   338 		}
       
   339 
       
   340 	aClientInfoBuffer = infoBuf.AllocL();
       
   341 	return count;
       
   342 	}
       
   343 
       
   344 void CIPNetworkConnectionProvider::DoConnectionControlActivityL( CConnectionProviderBase::TControlActivity aControlActivity, const Meta::SMetaData* aData, const RMessagePtr2* aMessage )
       
   345 	{
       
   346 	if (iShimCpr)
       
   347 		{
       
   348 		iShimCpr->ConnectionControlActivityL(aControlActivity, aData, aMessage);
       
   349 		}
       
   350 	}
       
   351 	
       
   352 CConnectionSettings& CIPNetworkConnectionProvider::DoSettingsAccessL()
       
   353 	{
       
   354 	if (iShimCpr == NULL)
       
   355 		{
       
   356 		User::Leave(KErrNotReady);
       
   357 		}
       
   358 	return iShimCpr->SettingsAccessL();
       
   359 	}
       
   360 	
       
   361 TInt CIPNetworkConnectionProvider::DoAllSubConnectionNotificationEnable()
       
   362 	{
       
   363 	return !iShimCpr ? KErrNotReady : iShimCpr->AllSubConnectionNotificationEnable();
       
   364   	}
       
   365 
       
   366 TInt CIPNetworkConnectionProvider::DoCancelAllSubConnectionNotification()
       
   367 	{
       
   368 	return !iShimCpr ? KErrNotReady : iShimCpr->CancelAllSubConnectionNotification();
       
   369   	}
       
   370    
       
   371 void CIPNetworkConnectionProvider::DoSendIoctlMessageL(const RMessage2& aMessage)
       
   372 	{
       
   373 	if (iShimCpr)
       
   374 		{
       
   375 		iShimCpr->SendIoctlMessageL(aMessage);
       
   376 		}
       
   377 	else
       
   378 		{
       
   379 		User::Leave(KErrNotReady);	
       
   380 		}
       
   381   	}
       
   382    
       
   383 void CIPNetworkConnectionProvider::DoSendCancelIoctl()
       
   384 	{
       
   385 	if (iShimCpr)
       
   386 		{
       
   387 		iShimCpr->SendCancelIoctl();
       
   388 		}
       
   389   	}
       
   390       
       
   391 TInt CIPNetworkConnectionProvider::DoCanDoSubConnection(RSubConnection::TSubConnType /*aSubConnType*/) const
       
   392 	{
       
   393 	return ETrue;
       
   394   	}
       
   395 
       
   396 void CIPNetworkConnectionProvider::DoJoinNextLayerL(CConnectionProviderBase* aNextLayer)
       
   397 	{
       
   398 	ASSERT( !iShimCpr );
       
   399 	ASSERT( aNextLayer );
       
   400 	iShimCpr = aNextLayer;
       
   401     SetConnectionInfo(iShimCpr->ConnectionInfo());
       
   402     // join ourselves as a connection control client to the lower provider
       
   403     iShimCpr->JoinL(*this);
       
   404 	}
       
   405 
       
   406 CConnectionProviderBase* CIPNetworkConnectionProvider::DoNextLayer() const
       
   407 	{
       
   408   	return iShimCpr;
       
   409   	}
       
   410    
       
   411