datacommsserver/esockserver/ssock/ss_connstates.cpp
changeset 79 cf589eb1e31e
parent 65 41cc8e7ff496
equal deleted inserted replaced
75:a365cb779476 79:cf589eb1e31e
    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 
    59 #include <comms-infras/ss_roles.h>
    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)
   255 DEFINE_SMELEMENT(ConnStates::TJoinReceivedSCpr, NetStateMachine::MStateTransition, ConnStates::TContext)
   256 void ConnStates::TJoinReceivedCpr::DoL()
   256 void ConnStates::TJoinReceivedSCpr::DoL()
   257 	{
   257 	{
   258 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
   258 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
   259 	__ASSERT_DEBUG(iContext.Node().ServiceProvider()==NULL, ConnPanic(KPanicExpectedNoServiceProvider));
   259 	__ASSERT_DEBUG(iContext.iPeer == iContext.Node().ServiceProvider(), ConnPanic(KPanicExpectedNoServiceProvider));
   260 
   260 
   261 	TCFDataClient::TBindTo& bt = message_cast<TCFDataClient::TBindTo>(iContext.iMessage);
   261 	TCFServiceProvider::TCommsBinderResponse& br = message_cast<TCFServiceProvider::TCommsBinderResponse>(iContext.iMessage);
   262     RNodeInterface* newSP = iContext.Node().AddClientL(bt.iNodeId, TClientType(TCFClientType::EServProvider, TCFClientType::EActive));
   262     RNodeInterface* scpr = iContext.Node().AddClientL(br.iNodeId, TClientType(TCFClientType::EServProvider, TCFClientType::EDefault));
   263     __ASSERT_DEBUG(iContext.Node().ServiceProvider()==newSP, ConnPanic(KPanicNoServiceProvider)); //[RZ] revise this, possibly overdefensive
       
   264 
   263 
   265     //If this is attach, we need to see if we are a monitor or not
   264     //If this is attach, we need to see if we are a monitor or not
   266     TClientType clientType(TCFClientType::ECtrl);
   265     TCFClientType clientType(TCFClientType::ECtrl);
   267 
   266 
   268     TUint selPrefs = static_cast<ConnActivities::CStartAttachActivity&>(*iContext.iNodeActivity).SelectionPrefs().Flags();
   267     TUint selPrefs = static_cast<ConnActivities::CStartAttachActivity&>(*iContext.iNodeActivity).SelectionPrefs().Flags();
   269     if (selPrefs & TSelectionPrefs::EMonitor)
   268     if (selPrefs & TSelectionPrefs::EMonitor)
   270     	{
   269     	{
   271 		clientType.SetFlags(TCFClientType::EMonitor);
   270 		clientType.SetFlags(TCFClientType::EMonitor);
   272     	iContext.Node().iIsMonitor = ETrue;
       
   273     	}
   271     	}
   274 
   272 
   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
   273 	// 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)
   274 	if (selPrefs & TSelectionPrefs::EAttach)
   277     	{
   275     	{
   278 		clientType.SetFlags(TCFClientType::EAttach);
   276 		clientType.SetFlags(TCFClientType::EAttach);
   279     	}
   277     	}
   280     iContext.iNodeActivity->PostRequestTo(*newSP,
       
   281     	TCFServiceProvider::TJoinRequest(iContext.NodeId(), clientType).CRef());
       
   282 	}
       
   283 
       
   284 DEFINE_SMELEMENT(ConnStates::TJoinReceivedSCpr, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   285 void ConnStates::TJoinReceivedSCpr::DoL()
       
   286 	{
       
   287 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   288 	__ASSERT_DEBUG(iContext.iPeer == iContext.Node().ServiceProvider(), ConnPanic(KPanicExpectedNoServiceProvider));
       
   289 
       
   290 	TCFServiceProvider::TCommsBinderResponse& br = message_cast<TCFServiceProvider::TCommsBinderResponse>(iContext.iMessage);
       
   291     RNodeInterface* scpr = iContext.Node().AddClientL(br.iNodeId, TClientType(TCFClientType::EServProvider, TCFClientType::EDefault));
       
   292 
       
   293     //If this is attach, we need to see if we are a monitor or not
       
   294     TCFClientType clientType(TCFClientType::ECtrl);
       
   295 
       
   296     TUint selPrefs = static_cast<ConnActivities::CStartAttachActivity&>(*iContext.iNodeActivity).SelectionPrefs().Flags();
       
   297     if (selPrefs & TSelectionPrefs::EMonitor)
       
   298     	{
       
   299 		clientType.SetFlags(TCFClientType::EMonitor);
       
   300     	}
       
   301 
       
   302 	// If it is an attach set the flag cause it is used by NetUPS to check if a JoinRequest comes from an RConnection::Attach
       
   303 	if (selPrefs & TSelectionPrefs::EAttach)
       
   304     	{
       
   305 		clientType.SetFlags(TCFClientType::EAttach);
       
   306     	}
       
   307 
   278 
   308     iContext.iNodeActivity->PostRequestTo(*scpr,
   279     iContext.iNodeActivity->PostRequestTo(*scpr,
   309     	TCFServiceProvider::TJoinRequest(iContext.NodeId(), clientType).CRef());
   280     	TCFServiceProvider::TJoinRequest(iContext.NodeId(), clientType).CRef());
   310 	}
   281 	}
   311 
   282 
   468 void ConnStates::TProcessIncomingConnection::DoL()
   439 void ConnStates::TProcessIncomingConnection::DoL()
   469 	{
   440 	{
   470 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
   441 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
   471     CSubConnection* waitingSubConn = iContext.Node().Session()->CSubConnectionFromHandle(static_cast<CESockClientActivityBase&>(*iContext.iNodeActivity).Int0());
   442     CSubConnection* waitingSubConn = iContext.Node().Session()->CSubConnectionFromHandle(static_cast<CESockClientActivityBase&>(*iContext.iNodeActivity).Int0());
   472 	User::LeaveIfError(waitingSubConn != NULL ? KErrNone : KErrCancel);
   443 	User::LeaveIfError(waitingSubConn != NULL ? KErrNone : KErrCancel);
   473 
   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)
       
   445     __ASSERT_DEBUG(waitingSubConnPeer, ConnPanic(KPanicNoDataClient));
       
   446     	
   474     TCFServiceProvider::TCommsBinderResponse& binderResp = message_cast<TCFServiceProvider::TCommsBinderResponse>(iContext.iMessage);
   447     TCFServiceProvider::TCommsBinderResponse& binderResp = message_cast<TCFServiceProvider::TCommsBinderResponse>(iContext.iMessage);
   475     iContext.iNodeActivity->PostRequestTo(waitingSubConn->Id(),
   448     iContext.iNodeActivity->PostRequestTo(*waitingSubConnPeer,
   476         TCFDataClient::TBindTo(binderResp.iNodeId).CRef());
   449         TCFDataClient::TBindTo(binderResp.iNodeId).CRef());
   477 	}
   450 	}
   478 
   451 
   479 
   452 
   480 //
   453 //
  1299 	RNodeInterface* aux = iNode.GetFirstClient<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EAux));
  1272 	RNodeInterface* aux = iNode.GetFirstClient<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EAux));
  1300 	if (aux)
  1273 	if (aux)
  1301 		{
  1274 		{
  1302 		iNode.RemoveClient(aux->RecipientId());
  1275 		iNode.RemoveClient(aux->RecipientId());
  1303 		}
  1276 		}
       
  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 
  1304 	delete iAllInterfaceNotificationWorker; //delete this node (why via iAllInterfaceNotificationWorker??)
  1288 	delete iAllInterfaceNotificationWorker; //delete this node (why via iAllInterfaceNotificationWorker??)
  1305 	}
  1289 	}
       
  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     };
  1306 
  1331 
  1307 // States
  1332 // States
  1308 
  1333 
  1309 DEFINE_SMELEMENT(AllInterfaceNotificationActivity::TAwaitingStart, NetStateMachine::MState, TContext)
  1334 DEFINE_SMELEMENT(AllInterfaceNotificationActivity::TAwaitingStart, NetStateMachine::MState, TContext)
  1310 TInt AllInterfaceNotificationActivity::TAwaitingStart::Accept()
  1335 TInt AllInterfaceNotificationActivity::TAwaitingStart::Accept()
  1457 	__ASSERT_DEBUG(iContext.Activity(), ConnPanic(KPanicNoActivity));
  1482 	__ASSERT_DEBUG(iContext.Activity(), ConnPanic(KPanicNoActivity));
  1458 
  1483 
  1459 	TCFTierStatusProvider::TTierNotification& msg = message_cast<TCFTierStatusProvider::TTierNotification>(iContext.iMessage);
  1484 	TCFTierStatusProvider::TTierNotification& msg = message_cast<TCFTierStatusProvider::TTierNotification>(iContext.iMessage);
  1460 
  1485 
  1461 	__ASSERT_DEBUG(msg.iBundle, User::Panic(KSpecAssert_ESockSSockscnsts, 14));
  1486 	__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 
  1462 	if(msg.iBundle->PtrL()->CountParamSetContainers() > 0)
  1504 	if(msg.iBundle->PtrL()->CountParamSetContainers() > 0)
  1463 		{
  1505 		{
  1464 		TInt i = 0;
  1506 		TInt i = 0;
  1465 		TBool found = EFalse;
  1507 		TBool found = EFalse;
  1466 		while(const CConnectionServParameterSetContainer* container = static_cast<const CConnectionServParameterSetContainer*>(msg.iBundle->Ptr()->GetParamSetContainer(i++)))
  1508 		while(const CConnectionServParameterSetContainer* container = static_cast<const CConnectionServParameterSetContainer*>(msg.iBundle->Ptr()->GetParamSetContainer(i++)))