datacommsserver/esockserver/ssock/ss_connstates.cpp
branchRCL_3
changeset 25 9d7ce34704c8
parent 24 00c6709d25aa
child 26 b564fb5fd78b
equal deleted inserted replaced
24:00c6709d25aa 25:9d7ce34704c8
    54 
    54 
    55 #ifdef SYMBIAN_NETWORKING_UPS
    55 #ifdef SYMBIAN_NETWORKING_UPS
    56 #include <comms-infras/ss_upsaccesspointconfigext.h>
    56 #include <comms-infras/ss_upsaccesspointconfigext.h>
    57 #include <comms-infras/upsmessages.h>
    57 #include <comms-infras/upsmessages.h>
    58 #endif
    58 #endif
    59 #include <comms-infras/ss_roles.h>
    59 
    60 #ifdef _DEBUG
    60 #ifdef _DEBUG
    61 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
    61 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
    62 // (if it could happen through user error then you should give it an explicit, documented, category + code)
    62 // (if it could happen through user error then you should give it an explicit, documented, category + code)
    63 _LIT(KSpecAssert_ESockSSockscnsts, "ESockSSockscnsts");
    63 _LIT(KSpecAssert_ESockSSockscnsts, "ESockSSockscnsts");
    64 #endif
    64 #endif
   250 	//Send the relevant progress (don't use ReceivedL or you will warp), also use Null Activity id.
   250 	//Send the relevant progress (don't use ReceivedL or you will warp), also use Null Activity id.
   251 	RNodeInterface::OpenPostMessageClose(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), iContext.NodeId(),
   251 	RNodeInterface::OpenPostMessageClose(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), iContext.NodeId(),
   252 		TCFMessage::TStateChange(TStateChange(KFinishedSelection,KErrNone)).CRef());
   252 		TCFMessage::TStateChange(TStateChange(KFinishedSelection,KErrNone)).CRef());
   253 	}
   253 	}
   254 
   254 
       
   255 DEFINE_SMELEMENT(ConnStates::TJoinReceivedCpr, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   256 void ConnStates::TJoinReceivedCpr::DoL()
       
   257 	{
       
   258 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   259 	__ASSERT_DEBUG(iContext.Node().ServiceProvider()==NULL, ConnPanic(KPanicExpectedNoServiceProvider));
       
   260 
       
   261 	TCFDataClient::TBindTo& bt = message_cast<TCFDataClient::TBindTo>(iContext.iMessage);
       
   262     RNodeInterface* newSP = iContext.Node().AddClientL(bt.iNodeId, TClientType(TCFClientType::EServProvider, TCFClientType::EActive));
       
   263     __ASSERT_DEBUG(iContext.Node().ServiceProvider()==newSP, ConnPanic(KPanicNoServiceProvider)); //[RZ] revise this, possibly overdefensive
       
   264 
       
   265     //If this is attach, we need to see if we are a monitor or not
       
   266     TClientType clientType(TCFClientType::ECtrl);
       
   267 
       
   268     TUint selPrefs = static_cast<ConnActivities::CStartAttachActivity&>(*iContext.iNodeActivity).SelectionPrefs().Flags();
       
   269     if (selPrefs & TSelectionPrefs::EMonitor)
       
   270     	{
       
   271 		clientType.SetFlags(TCFClientType::EMonitor);
       
   272     	iContext.Node().iIsMonitor = ETrue;
       
   273     	}
       
   274 
       
   275 	// If it is an attach set the flag cause it is used by NetUPS to check if a JoinRequest comes from an RConnection::Attach
       
   276 	if (selPrefs & TSelectionPrefs::EAttach)
       
   277     	{
       
   278 		clientType.SetFlags(TCFClientType::EAttach);
       
   279     	}
       
   280     iContext.iNodeActivity->PostRequestTo(*newSP,
       
   281     	TCFServiceProvider::TJoinRequest(iContext.NodeId(), clientType).CRef());
       
   282 	}
       
   283 
   255 DEFINE_SMELEMENT(ConnStates::TJoinReceivedSCpr, NetStateMachine::MStateTransition, ConnStates::TContext)
   284 DEFINE_SMELEMENT(ConnStates::TJoinReceivedSCpr, NetStateMachine::MStateTransition, ConnStates::TContext)
   256 void ConnStates::TJoinReceivedSCpr::DoL()
   285 void ConnStates::TJoinReceivedSCpr::DoL()
   257 	{
   286 	{
   258 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
   287 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
   259 	__ASSERT_DEBUG(iContext.iPeer == iContext.Node().ServiceProvider(), ConnPanic(KPanicExpectedNoServiceProvider));
   288 	__ASSERT_DEBUG(iContext.iPeer == iContext.Node().ServiceProvider(), ConnPanic(KPanicExpectedNoServiceProvider));
   439 void ConnStates::TProcessIncomingConnection::DoL()
   468 void ConnStates::TProcessIncomingConnection::DoL()
   440 	{
   469 	{
   441 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
   470 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
   442     CSubConnection* waitingSubConn = iContext.Node().Session()->CSubConnectionFromHandle(static_cast<CESockClientActivityBase&>(*iContext.iNodeActivity).Int0());
   471     CSubConnection* waitingSubConn = iContext.Node().Session()->CSubConnectionFromHandle(static_cast<CESockClientActivityBase&>(*iContext.iNodeActivity).Int0());
   443 	User::LeaveIfError(waitingSubConn != NULL ? KErrNone : KErrCancel);
   472 	User::LeaveIfError(waitingSubConn != NULL ? KErrNone : KErrCancel);
   444     RNodeInterface* waitingSubConnPeer = iContext.Node().FindClient(waitingSubConn->Id()); //To my surprise SC is a peer of this (so must use peer handle when talking to it)
   473 
   445     __ASSERT_DEBUG(waitingSubConnPeer, ConnPanic(KPanicNoDataClient));
       
   446     	
       
   447     TCFServiceProvider::TCommsBinderResponse& binderResp = message_cast<TCFServiceProvider::TCommsBinderResponse>(iContext.iMessage);
   474     TCFServiceProvider::TCommsBinderResponse& binderResp = message_cast<TCFServiceProvider::TCommsBinderResponse>(iContext.iMessage);
   448     iContext.iNodeActivity->PostRequestTo(*waitingSubConnPeer,
   475     iContext.iNodeActivity->PostRequestTo(waitingSubConn->Id(),
   449         TCFDataClient::TBindTo(binderResp.iNodeId).CRef());
   476         TCFDataClient::TBindTo(binderResp.iNodeId).CRef());
   450 	}
   477 	}
   451 
   478 
   452 
   479 
   453 //
   480 //
  1272 	RNodeInterface* aux = iNode.GetFirstClient<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EAux));
  1299 	RNodeInterface* aux = iNode.GetFirstClient<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EAux));
  1273 	if (aux)
  1300 	if (aux)
  1274 		{
  1301 		{
  1275 		iNode.RemoveClient(aux->RecipientId());
  1302 		iNode.RemoveClient(aux->RecipientId());
  1276 		}
  1303 		}
  1277 
       
  1278     if (iRegisteredForInterfaceStateChanges)
       
  1279         {
       
  1280         CCommsFactoryBase* ipProtoCprFactory = IpProtoCprFactory();
       
  1281         if (ipProtoCprFactory)
       
  1282             {
       
  1283             Factories::IFactoryNotify itf(this, GetVTable());
       
  1284             ipProtoCprFactory->DeRegisterNotifier(itf);
       
  1285             }
       
  1286         }
       
  1287 
       
  1288 	delete iAllInterfaceNotificationWorker; //delete this node (why via iAllInterfaceNotificationWorker??)
  1304 	delete iAllInterfaceNotificationWorker; //delete this node (why via iAllInterfaceNotificationWorker??)
  1289 	}
  1305 	}
  1290 
       
  1291 /**
       
  1292 Called by the IpProtoCpr factory to propagate an interface state change from IpProtoCpr to registered
       
  1293 observers (suc as ourself).  If the interface is restarting, then we need to insert an EInterfaceDown,
       
  1294 EInterfaceUp "toggle" sequence into the AllInterfaceNotification queue.  This is because, ordinarily,
       
  1295 EInterfaceUp and EInterfaceDown are generated when the IpProtoCpr itself is created and destroyed,
       
  1296 but not if it is restarted before being destroyed. 
       
  1297 */
       
  1298 void CAllInterfaceNotificationActivity::InterfaceStateChangeNotification(const TDesC8& aInfo)
       
  1299     {
       
  1300     if (aInfo.Length() == sizeof(TInterfaceNotification))
       
  1301         {
       
  1302         const TInterfaceNotification* const info = reinterpret_cast<const TInterfaceNotification*>(aInfo.Ptr());
       
  1303         if (info && info->iState == EInterfaceRestarting)
       
  1304             {
       
  1305             LOG( ESockLog::Printf(KESockConnectionTag, _L("CAllInterfaceNotificationActivity %08x:\tInterfaceStateChangeNotification(): CConnection %08x, IapId %d, NetId %d"),
       
  1306                 this, &iAllInterfaceNotificationWorker->iConnection, info->iConnectionInfo.iIapId, info->iConnectionInfo.iNetId  ));
       
  1307 
       
  1308             AConnectionLegacy& legacy = iAllInterfaceNotificationWorker->iConnection.iLegacyConnection;
       
  1309             TInterfaceNotification notification(*info);
       
  1310             notification.iState = EInterfaceDown;
       
  1311             legacy.iNotificationQueue.Enque(notification);
       
  1312             notification.iState = EInterfaceUp;
       
  1313             legacy.iNotificationQueue.Enque(notification);
       
  1314             legacy.CompleteAllInterfaceNotificationL(KErrNone);
       
  1315             }
       
  1316         }
       
  1317     }
       
  1318 
       
  1319 CCommsFactoryBase* CAllInterfaceNotificationActivity::IpProtoCprFactory() const
       
  1320     {
       
  1321     CConnectionFactoryContainer& container = *static_cast<CPlayer&>(iAllInterfaceNotificationWorker->iConnection.Player()).SockManGlobals()->iConnectionFactories;
       
  1322     return static_cast<CCommsFactoryBase*>(container.FindFactory(TUid::Uid(AConnectionLegacy::KIPProtoConnectionProviderFactoryUid)));
       
  1323     }
       
  1324 
       
  1325 // Registration table for receiving InterfaceStateChangeNotification() events.
       
  1326 const Factories::TAnyFn CAllInterfaceNotificationActivity::iInterfaceVTableF[] =
       
  1327     {
       
  1328     (Factories::TAnyFn)1, // number of methods. the following entries must be in this order!
       
  1329     (Factories::TAnyFn)(Factories::TFactoryNotify<CAllInterfaceNotificationActivity>::Notification)
       
  1330     };
       
  1331 
  1306 
  1332 // States
  1307 // States
  1333 
  1308 
  1334 DEFINE_SMELEMENT(AllInterfaceNotificationActivity::TAwaitingStart, NetStateMachine::MState, TContext)
  1309 DEFINE_SMELEMENT(AllInterfaceNotificationActivity::TAwaitingStart, NetStateMachine::MState, TContext)
  1335 TInt AllInterfaceNotificationActivity::TAwaitingStart::Accept()
  1310 TInt AllInterfaceNotificationActivity::TAwaitingStart::Accept()
  1482 	__ASSERT_DEBUG(iContext.Activity(), ConnPanic(KPanicNoActivity));
  1457 	__ASSERT_DEBUG(iContext.Activity(), ConnPanic(KPanicNoActivity));
  1483 
  1458 
  1484 	TCFTierStatusProvider::TTierNotification& msg = message_cast<TCFTierStatusProvider::TTierNotification>(iContext.iMessage);
  1459 	TCFTierStatusProvider::TTierNotification& msg = message_cast<TCFTierStatusProvider::TTierNotification>(iContext.iMessage);
  1485 
  1460 
  1486 	__ASSERT_DEBUG(msg.iBundle, User::Panic(KSpecAssert_ESockSSockscnsts, 14));
  1461 	__ASSERT_DEBUG(msg.iBundle, User::Panic(KSpecAssert_ESockSSockscnsts, 14));
  1487 	
       
  1488     CAllInterfaceNotificationActivity& act = *iContext.Activity();
       
  1489     
       
  1490     // Register with the IpProtoCpr factory for interface state changes if we haven't already done so.
       
  1491     // We can only do this if the IpProtoCpr is active, and the assumption here is that it must be active
       
  1492     // if an interface event has been generated.
       
  1493     if (!act.iRegisteredForInterfaceStateChanges)
       
  1494         {
       
  1495         CCommsFactoryBase* ipProtoCprFactory = act.IpProtoCprFactory();
       
  1496         if (ipProtoCprFactory)
       
  1497             {
       
  1498             Factories::IFactoryNotify itf(&act, act.GetVTable());
       
  1499             ipProtoCprFactory->RegisterNotifierL(itf);
       
  1500             act.iRegisteredForInterfaceStateChanges = ETrue;
       
  1501             }
       
  1502         }
       
  1503 
       
  1504 	if(msg.iBundle->PtrL()->CountParamSetContainers() > 0)
  1462 	if(msg.iBundle->PtrL()->CountParamSetContainers() > 0)
  1505 		{
  1463 		{
  1506 		TInt i = 0;
  1464 		TInt i = 0;
  1507 		TBool found = EFalse;
  1465 		TBool found = EFalse;
  1508 		while(const CConnectionServParameterSetContainer* container = static_cast<const CConnectionServParameterSetContainer*>(msg.iBundle->Ptr()->GetParamSetContainer(i++)))
  1466 		while(const CConnectionServParameterSetContainer* container = static_cast<const CConnectionServParameterSetContainer*>(msg.iBundle->Ptr()->GetParamSetContainer(i++)))