datacommsserver/esockserver/ssock/ss_connstates.cpp
changeset 0 dfb7c4ff071f
child 1 21d2ab05f085
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     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 "SS_conn.H"
       
    17 #include "ss_connstates.h"
       
    18 #include <comms-infras/ss_log.h>
       
    19 #include <comms-infras/ss_coreprstates.h>
       
    20 #include <comms-infras/ss_corepractivities.h>
       
    21 #include "ss_subconn.h"
       
    22 #include <comms-infras/ss_mcprnodemessages.h>
       
    23 #include <elements/sm_core.h>
       
    24 #include <commdbconnpref.h> //TCommDbConnPref
       
    25 #include <ss_glob.h> //TCommDbConnPref
       
    26 #include <connpref.h> //TConnPrefList
       
    27 #include <etelpckt.h>
       
    28 #include <comms-infras/metadata.h>
       
    29 #include <comms-infras/esock_params.h> //TConnAPPref
       
    30 #include <comms-infras/esock_params_internal.h> //TConnCSRPref
       
    31 
       
    32 #include <comms-infras/es_connectionservparameterbundle.h> // CConnectionServParameterBundle
       
    33 #include <comms-infras/es_accesspointstatus.h> // TAccessPointStatusFilter
       
    34 #include <comms-infras/cs_connservparams.h> // XAccessPointGenericParameterSet
       
    35 #include <comms-infras/cs_connservparams_internal.h>
       
    36 
       
    37 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    38 #include <es_enum_internal.h>
       
    39 #include <nifvar_internal.h>
       
    40 #endif
       
    41 
       
    42 #include <elements/nm_messages_child.h>
       
    43 #include <elements/nm_messages_peer.h>
       
    44 #include <comms-infras/ss_nodemessages_dataclient.h>
       
    45 #include <comms-infras/ss_nodemessages_legacy.h>
       
    46 #include <comms-infras/ss_nodemessages_tiermanager.h>
       
    47 #include <comms-infras/ss_nodemessages_serviceprovider.h>
       
    48 #include <comms-infras/ss_nodemessages_internal_esock.h>
       
    49 #include <comms-infras/ss_nodemessages_selector.h>
       
    50 #include <comms-infras/ss_nodemessages_factory.h>
       
    51 #include <comms-infras/ss_nodemessages_tiermanagerfactory.h>
       
    52 
       
    53 #define SYMBIAN_NETWORKING_UPS
       
    54 
       
    55 #ifdef SYMBIAN_NETWORKING_UPS
       
    56 #include <comms-infras/ss_upsaccesspointconfigext.h>
       
    57 #include <comms-infras/upsmessages.h>
       
    58 #endif
       
    59 
       
    60 #ifdef _DEBUG
       
    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)
       
    63 _LIT(KSpecAssert_ESockSSockscnsts, "ESockSSockscnsts");
       
    64 #endif
       
    65 
       
    66 using namespace ESock;
       
    67 using namespace SubSessActivities;
       
    68 using namespace NetStateMachine;
       
    69 using namespace ConnStates;
       
    70 using namespace ConnActivities;
       
    71 using namespace ConnectionServ;
       
    72 using namespace Elements;
       
    73 using namespace Messages;
       
    74 using namespace MeshMachine;
       
    75 
       
    76 //#ifdef LOG
       
    77 //	#define KESockActivityTag KESockCoreProviderTag
       
    78 //	_LIT8(KESockActivitySubTag, "esockactivity");
       
    79 //#endif
       
    80 
       
    81 _LIT (KCConnectionPanic,"CConnectionPanic");
       
    82 
       
    83 void ConnPanic(TInt aCode)
       
    84 	{
       
    85 	User::Panic(KCConnectionPanic, aCode);
       
    86 	}
       
    87 
       
    88 //
       
    89 //Start
       
    90 
       
    91 DEFINE_SMELEMENT(ConnStates::TErrorIfAlreadyStartedAttached, NetStateMachine::MStateTransition, ConnStates::TContext)
       
    92 void ConnStates::TErrorIfAlreadyStartedAttached::DoL()
       
    93 	{
       
    94 	__ASSERT_DEBUG((subsessmessage_cast<ECNStart>(&iContext.iMessage))
       
    95 		|| (subsessmessage_cast<ECNAttach>(&iContext.iMessage)),
       
    96 			ConnPanic(KPanicIncorrectMessage));
       
    97 	RNodeInterface* sp = iContext.Node().ServiceProvider();
       
    98 	User::LeaveIfError(sp? KErrAlreadyExists : KErrNone);
       
    99 	}
       
   100 
       
   101 DEFINE_SMELEMENT(ConnStates::TParseECNStart, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   102 void ConnStates::TParseECNStart::DoL()
       
   103 	{
       
   104 	__ASSERT_DEBUG((subsessmessage_cast<ECNStart>(&iContext.iMessage)), ConnPanic(KPanicIncorrectMessage));
       
   105 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   106 	ConnActivities::CStartAttachActivity& ac = static_cast<ConnActivities::CStartAttachActivity&>(*iContext.iNodeActivity);
       
   107 
       
   108     if (ac.Function() == ECNSetStartPrefs)
       
   109     	{
       
   110         //Extract preferences if ECNSetStartPrefs
       
   111     	TConnPref prefs;
       
   112 		ac.ReadL(0, prefs);
       
   113 
       
   114    		if(prefs.ExtensionId() != TConnPref::EConnPrefEComList)
       
   115   			{
       
   116   			ac.SelectionPrefs().SetPrefs(prefs);
       
   117   			}
       
   118   		else
       
   119   			{
       
   120   			RBuf8 buffer;
       
   121   			TInt length = ac.GetDesLengthL(0);
       
   122   			buffer.CreateL(length);
       
   123   			CleanupClosePushL(buffer);
       
   124   			ac.ReadL(0, buffer);
       
   125 
       
   126   			TConnPrefList* prefsList = TConnPrefList::NewL();
       
   127   			CleanupStack::PushL(prefsList);
       
   128   			TPtrC8 ptr(buffer);
       
   129   			TInt ret = prefsList->Load(ptr);
       
   130   			User::LeaveIfError(ret);
       
   131 
       
   132   			//This loop is used to check that there is no more than 1 instance
       
   133   			//of TConnAPPref in the list passed to the CSR. This is not allowed
       
   134   			//(as it may have adverse effects in the construction of the stack)
       
   135   			//KErrArugment is returned if there is more than 1 instance present
       
   136   			TInt instances = 0;
       
   137   			for(TInt i=0; i<prefsList->Count(); i++)
       
   138   				{
       
   139   				TConnAPPref* pref = smetadata_cast<TConnAPPref>((*prefsList)[i]);
       
   140   				if(pref)
       
   141   				    {
       
   142   					instances++;
       
   143   				    }
       
   144   				}
       
   145   			if(instances > 1)
       
   146   			    {
       
   147   				User::Leave(KErrArgument);
       
   148   			    }
       
   149 
       
   150   			TConnCSRPref* csr = TConnCSRPref::NewL();
       
   151   			CleanupStack::PushL(csr);
       
   152   			ac.SetCSRPreferences(csr);
       
   153   			csr->SetScope(TSelectionPrefs::EExplicitConnection);
       
   154   			prefsList->AppendL(csr);
       
   155 
       
   156   			ac.SelectionPrefs().SetPrefs(*prefsList);
       
   157     		ac.SetConnPrefList(prefsList);
       
   158 
       
   159     		CleanupStack::Pop(csr);
       
   160     		CleanupStack::Pop(prefsList);
       
   161     		CleanupStack::PopAndDestroy(&buffer);
       
   162     		}
       
   163 		
       
   164 		// Complete the ECNSetStartPrefs, activity will be held until the 2nd IPC of the Start with Prefs
       
   165    		// call is received. Null iSubSession so that the 2nd IPC can be aquired by the activity.
       
   166    		ac.iMessage.Complete(KErrNone);
       
   167    		ac.iSubSession = NULL;
       
   168 		}
       
   169     else
       
   170         {
       
   171         ac.SetSelectionScope(TSelectionPrefs::EExplicitConnection);
       
   172         }
       
   173 	}
       
   174 
       
   175 DEFINE_SMELEMENT(ConnStates::TSendStartingSelectionStateChange, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   176 void ConnStates::TSendStartingSelectionStateChange::DoL()
       
   177 	{
       
   178 	//Send the relevant progress (don't use ReceivedL or you will warp), also use Null Activity id.
       
   179 	RNodeInterface::OpenPostMessageClose(iContext.NodeId(), iContext.NodeId(), TCFMessage::TStateChange(TStateChange(KStartingSelection,KErrNone)).CRef());
       
   180 	}
       
   181 
       
   182 DEFINE_SMELEMENT(ConnStates::TClearProgressQueue, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   183 void ConnStates::TClearProgressQueue::DoL()
       
   184 	{
       
   185 	iContext.Node().iProgressQueue.Reset();		// clear progress notification cache
       
   186 	iContext.Node().ResetLastProgressError();	// clear last progress in error
       
   187 	// Initialise iLastProgress with an invalid progress rather than 0 (which is actually KConnectionUninitialised)
       
   188 	// otherwise we can end up unintentionally filtering out a KConnectionUninitialised progress.
       
   189 	const TInt KInvalidProgress = -1;
       
   190 	iContext.Node().iLastProgress = TStateChange(KInvalidProgress, 0);
       
   191 	iContext.Node().iLastProgressError = TStateChange();
       
   192 	}
       
   193 
       
   194 DEFINE_SMELEMENT(ConnStates::TRequestCSRCreation, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   195 void ConnStates::TRequestCSRCreation::DoL()
       
   196 	{
       
   197 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   198 	__ASSERT_DEBUG(static_cast<ConnActivities::CStartAttachActivity&>(*iContext.iNodeActivity).CSR().IsNull(), ConnPanic(KPanicExpectedNoCSR));
       
   199 	iContext.iNodeActivity->PostRequestTo(SockManGlobals::Get()->GetPlaneFC(TCFPlayerRole(TCFPlayerRole::ETierMgrPlane)), TCFInternalEsock::TCreateCSR(iContext.Node().iTierId).CRef(), EFalse);
       
   200 	}
       
   201 
       
   202 DEFINE_SMELEMENT(ConnStates::TProcessCSRCreation, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   203 void ConnStates::TProcessCSRCreation::DoL()
       
   204 	{
       
   205 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   206 	ConnActivities::CStartAttachActivity& ac = static_cast<ConnActivities::CStartAttachActivity&>(*iContext.iNodeActivity);
       
   207 	__ASSERT_DEBUG(ac.CSR().IsNull(), User::Panic(KSpecAssert_ESockSSockscnsts, 1));
       
   208 	ac.SetCSR(message_cast<TCFInternalEsock::TCSRCreated>(iContext.iMessage).iNodeId);
       
   209 
       
   210 	
       
   211 	RNodeInterface::OpenPostMessageClose(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), ac.CSR(),
       
   212 		TCFMessage::TProvisionConnectionInfo(iContext.Node().ConnectionInfo()).CRef());
       
   213 	}
       
   214 
       
   215 DEFINE_SMELEMENT(ConnStates::TSelectMetaPlane, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   216 void ConnStates::TSelectMetaPlane::DoL()
       
   217 	{
       
   218 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   219 	ConnActivities::CStartAttachActivity& ac = static_cast<ConnActivities::CStartAttachActivity&>(*iContext.iNodeActivity);
       
   220 
       
   221     //Diagnostic only. If attach then it must be ESelectFromExisting
       
   222     __ASSERT_DEBUG(!iContext.Node().IsMonitor()
       
   223     	|| ac.SelectionPrefs().Scope() & TSelectionPrefs::ESelectFromExisting, User::Panic(KSpecAssert_ESockSSockscnsts, 2));
       
   224 
       
   225 	if(ac.SelectionPrefs().Prefs().ExtensionId() != TConnPref::EConnPrefEComList)
       
   226 		{
       
   227 		ac.SelectionPrefs().SetSubSessionUniqueId(iContext.Node().UniqueId());
       
   228 		iContext.iNodeActivity->PostRequestTo(
       
   229 			ac.CSR(),
       
   230 			TCFSelector::TSimpleSelect(ac.SelectionPrefs()).CRef()
       
   231 			);
       
   232 		}
       
   233 	else
       
   234 		{
       
   235 		ac.CSRPreferences()->SetSubSessionUniqueId(iContext.Node().UniqueId());
       
   236 		RConnPrefList handle;
       
   237 		handle.Open(ac.ConnPrefList());
       
   238 
       
   239 		iContext.iNodeActivity->PostRequestTo(
       
   240 			ac.CSR(),
       
   241 			TCFSelector::TSelect(handle).CRef()
       
   242 			);
       
   243 		}
       
   244 	}
       
   245 
       
   246 DEFINE_SMELEMENT(ConnStates::TSendFinishedSelectionStateChange, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   247 void ConnStates::TSendFinishedSelectionStateChange::DoL()
       
   248 	{
       
   249 	//Send the relevant progress (don't use ReceivedL or you will warp), also use Null Activity id.
       
   250 	RNodeInterface::OpenPostMessageClose(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), iContext.NodeId(),
       
   251 		TCFMessage::TStateChange(TStateChange(KFinishedSelection,KErrNone)).CRef());
       
   252 	}
       
   253 
       
   254 DEFINE_SMELEMENT(ConnStates::TJoinReceivedCpr, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   255 void ConnStates::TJoinReceivedCpr::DoL()
       
   256 	{
       
   257 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   258 	__ASSERT_DEBUG(iContext.Node().ServiceProvider()==NULL, ConnPanic(KPanicExpectedNoServiceProvider));
       
   259 
       
   260 	TCFDataClient::TBindTo& bt = message_cast<TCFDataClient::TBindTo>(iContext.iMessage);
       
   261     iContext.Node().AddClientL(bt.iNodeId, TClientType(TCFClientType::EServProvider, TCFClientType::EActive));
       
   262 
       
   263     //If this is attach, we need to see if we are a monitor or not
       
   264     TClientType clientType(TCFClientType::ECtrl);
       
   265 
       
   266     TUint selPrefs = static_cast<ConnActivities::CStartAttachActivity&>(*iContext.iNodeActivity).SelectionPrefs().Flags();
       
   267     if (selPrefs & TSelectionPrefs::EMonitor)
       
   268     	{
       
   269 		clientType.SetFlags(TCFClientType::EMonitor);
       
   270     	iContext.Node().iIsMonitor = ETrue;
       
   271     	}
       
   272 
       
   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
       
   274 	if (selPrefs & TSelectionPrefs::EAttach)
       
   275     	{
       
   276 		clientType.SetFlags(TCFClientType::EAttach);
       
   277     	}
       
   278     iContext.iNodeActivity->PostRequestTo(bt.iNodeId,
       
   279     	TCFServiceProvider::TJoinRequest(iContext.NodeId(), clientType).CRef());
       
   280 	}
       
   281 
       
   282 DEFINE_SMELEMENT(ConnStates::TJoinReceivedSCpr, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   283 void ConnStates::TJoinReceivedSCpr::DoL()
       
   284 	{
       
   285 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   286 	__ASSERT_DEBUG(iContext.iPeer == iContext.Node().ServiceProvider(), ConnPanic(KPanicExpectedNoServiceProvider));
       
   287 
       
   288 	TCFServiceProvider::TCommsBinderResponse& br = message_cast<TCFServiceProvider::TCommsBinderResponse>(iContext.iMessage);
       
   289     iContext.Node().AddClientL(br.iNodeId, TClientType(TCFClientType::EServProvider, TCFClientType::EDefault));
       
   290 
       
   291     //If this is attach, we need to see if we are a monitor or not
       
   292     TCFClientType clientType(TCFClientType::ECtrl);
       
   293 
       
   294     TUint selPrefs = static_cast<ConnActivities::CStartAttachActivity&>(*iContext.iNodeActivity).SelectionPrefs().Flags();
       
   295     if (selPrefs & TSelectionPrefs::EMonitor)
       
   296     	{
       
   297 		clientType.SetFlags(TCFClientType::EMonitor);
       
   298     	}
       
   299 
       
   300 	// If it is an attach set the flag cause it is used by NetUPS to check if a JoinRequest comes from an RConnection::Attach
       
   301 	if (selPrefs & TSelectionPrefs::EAttach)
       
   302     	{
       
   303 		clientType.SetFlags(TCFClientType::EAttach);
       
   304     	}
       
   305 
       
   306     iContext.iNodeActivity->PostRequestTo(br.iNodeId,
       
   307     	TCFServiceProvider::TJoinRequest(iContext.NodeId(), clientType).CRef());
       
   308 	}
       
   309 
       
   310 DEFINE_SMELEMENT(ConnStates::TJoinReceivedMcpr, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   311 void ConnStates::TJoinReceivedMcpr::DoL()
       
   312 	{
       
   313 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   314 	__ASSERT_DEBUG(iContext.Node().ServiceProvider()==NULL, ConnPanic(KPanicExpectedNoServiceProvider));
       
   315 
       
   316 	TCFSelector::TSelectComplete& sc = message_cast<TCFSelector::TSelectComplete>(iContext.iMessage);
       
   317 	iContext.Node().AddClientL(sc.iNodeId,TClientType(TCFClientType::EServProvider, TCFClientType::EAvailabilityProvider));
       
   318 
       
   319 
       
   320 	iContext.iNodeActivity->PostRequestTo(sc.iNodeId,
       
   321 		TCFServiceProvider::TJoinRequest(iContext.NodeId(), TCFClientType(TCFClientType::ECtrl)).CRef());
       
   322 	}
       
   323 
       
   324 DEFINE_SMELEMENT(ConnStates::TRequestCommsBinder, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   325 void ConnStates::TRequestCommsBinder::DoL()
       
   326 	{
       
   327     __ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   328     RNodeInterface* sp = iContext.Node().ServiceProvider();
       
   329     __ASSERT_DEBUG(sp, ConnPanic(KPanicNoServiceProvider));
       
   330     iContext.iNodeActivity->PostRequestTo(*sp,
       
   331     	TCFServiceProvider::TCommsBinderRequest(TSubConnOpen::EAttachToDefault).CRef());
       
   332 	}
       
   333 
       
   334 DEFINE_SMELEMENT(ConnStates::TRequestCommsBinderFromMcpr, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   335 void ConnStates::TRequestCommsBinderFromMcpr::DoL()
       
   336 	{
       
   337 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   338 	TClientIter<TDefaultClientMatchPolicy> iter = iContext.Node().GetClientIter<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EServProvider, TCFClientType::EAvailabilityProvider));
       
   339 	RNodeInterface* mcpr = iter[0];
       
   340 	__ASSERT_DEBUG(mcpr, ConnPanic(KPanicNoAvailabilityProvider));
       
   341 	iContext.iNodeActivity->PostRequestTo(*mcpr,
       
   342 		TCFServiceProvider::TCommsBinderRequest().CRef());
       
   343 	}
       
   344 
       
   345 DEFINE_SMELEMENT(ConnStates::TProcessBinderResponseForCpr, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   346 void ConnStates::TProcessBinderResponseForCpr::DoL()
       
   347 	{
       
   348 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   349 	__ASSERT_DEBUG(iContext.Node().ServiceProvider()==NULL, ConnPanic(KPanicExpectedNoServiceProvider));
       
   350 
       
   351 	TCFServiceProvider::TCommsBinderResponse& br = message_cast<TCFServiceProvider::TCommsBinderResponse>(iContext.iMessage);
       
   352 
       
   353 	iContext.Node().AddClientL(br.iNodeId, TClientType(TCFClientType::EServProvider, TCFClientType::EActive));
       
   354 
       
   355 	//If this is attach, we need to see if we are a monitor or not
       
   356 	TCFClientType clientType;
       
   357 
       
   358 	TUint selPrefs = static_cast<ConnActivities::CStartAttachActivity&>(*iContext.iNodeActivity).SelectionPrefs().Flags();
       
   359 	if (selPrefs & TSelectionPrefs::EMonitor)
       
   360 		{
       
   361 		clientType.SetFlags(TCFClientType::EMonitor);
       
   362 		iContext.Node().iIsMonitor = ETrue;
       
   363 		}
       
   364 
       
   365 	if (selPrefs & TSelectionPrefs::EAttach)
       
   366 		{
       
   367 		clientType.SetFlags(TCFClientType::EAttach);
       
   368 		}
       
   369 	
       
   370 	iContext.iNodeActivity->PostRequestTo(br.iNodeId,
       
   371 		TCFServiceProvider::TJoinRequest(iContext.NodeId(), clientType).CRef());
       
   372 	}
       
   373 
       
   374 DEFINE_SMELEMENT(ConnStates::TStartConnection, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   375 void ConnStates::TStartConnection::DoL()
       
   376 	{
       
   377 	RNodeInterface* cpr = iContext.Node().ServiceProvider();
       
   378 	__ASSERT_DEBUG(cpr, ConnPanic(KPanicNoServiceProvider));
       
   379 
       
   380 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   381     iContext.iNodeActivity->PostRequestTo(*cpr, TCFServiceProvider::TStart().CRef());
       
   382 	}
       
   383 
       
   384 DEFINE_SMELEMENT(ConnStates::TErrorOrCancel, NetStateMachine::MStateFork, ConnStates::TContext)
       
   385 /**
       
   386 If the activity has been cancelled, return KCancelTag else return KErrorTag
       
   387  */
       
   388 TInt ConnStates::TErrorOrCancel::TransitionTag()
       
   389 	{
       
   390 	if (iContext.Activity()->Error() == KErrCancel)
       
   391 		{
       
   392 		return ConnActivities::CStartAttachActivity::KCancelTag;
       
   393 		}
       
   394 	else
       
   395 		{
       
   396 		__ASSERT_DEBUG(iContext.Activity()->Error() != KErrNone, User::Panic(KSpecAssert_ESockSSockscnsts, 3));		// meant to be called in error conditions only
       
   397 		return KErrorTag;
       
   398 		}
       
   399 	}
       
   400 
       
   401 //
       
   402 //Attach
       
   403 DEFINE_SMELEMENT(ConnStates::TParseECNAttach, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   404 void ConnStates::TParseECNAttach::DoL()
       
   405 	{
       
   406 	__ASSERT_DEBUG((subsessmessage_cast<ECNAttach>(&iContext.iMessage)), ConnPanic(KPanicIncorrectMessage));
       
   407 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   408 	ConnActivities::CStartAttachActivity& ac = static_cast<ConnActivities::CStartAttachActivity&>(*iContext.iNodeActivity);
       
   409 
       
   410 	//Read preferences
       
   411 	const TUint KMaxConnectionInfoLength = 32;
       
   412 	TBuf8<KMaxConnectionInfoLength> info;
       
   413 	ac.ReadL(1,info);
       
   414 	if (info.Length() < KConnInfoPart)
       
   415 		{
       
   416 		User::Leave(KErrArgument);
       
   417 		}
       
   418 
       
   419 	TUint monitorMode = (RConnection::TConnAttachType)ac.Int0() == RConnection::EAttachTypeMonitor?
       
   420 		TSelectionPrefs::EMonitor : 0;
       
   421 	// The attach flag should always be set since it is used by NetUPS to check if a JoinRequest comes from an RConnection::Attach
       
   422 	ac.SetSelectionFlags(monitorMode | TSelectionPrefs::EAttach);
       
   423 
       
   424 	TConnArgBase& connInfo = *((TConnArgBase*)&info[0]);
       
   425 	if (connInfo.Version() < KConnArgVersion3)
       
   426 		{
       
   427         TConnectionInfo& connI = static_cast<TConnectionInfo&>(connInfo);
       
   428         TCommDbConnPref pref;
       
   429 		pref.SetIapId(connI.iIapId);
       
   430     	ac.SelectionPrefs().SetPrefs(pref);
       
   431     	ac.SetSelectionScope(TSelectionPrefs::ESelectFromExisting | TSelectionPrefs::EExplicitConnection);
       
   432 		}
       
   433 	else
       
   434 		{
       
   435 		__ASSERT_DEBUG(connInfo.Version() == KConnArgVersion3, User::Panic(KSpecAssert_ESockSSockscnsts, 4)); //Currently no support for > KConnArgVersion3;
       
   436 		TConnProviderInfo& provinfo = static_cast<TConnProviderInfo&>(connInfo);
       
   437 		__ASSERT_DEBUG(iContext.Node().iTierId.iUid == provinfo.iInfo[0], User::Panic(KSpecAssert_ESockSSockscnsts, 5));
       
   438     	ac.SelectionPrefs().SetPrefs(TConnProviderInfoPref(provinfo));
       
   439     	ac.SetSelectionScope(TSelectionPrefs::ESelectFromExisting);
       
   440 		}
       
   441 	}
       
   442 
       
   443 DEFINE_SMELEMENT(ConnStates::TCompleteLegacyAttach, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   444 void ConnStates::TCompleteLegacyAttach::DoL()
       
   445 	{
       
   446 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   447 	iContext.Node().iLegacyConnection.CompleteAttachL(static_cast<ConnActivities::CStartAttachActivity&>(*iContext.iNodeActivity).SelectionPrefs());
       
   448 	}
       
   449 
       
   450 
       
   451 //
       
   452 //WaitForIncoming
       
   453 DEFINE_SMELEMENT(ConnStates::TRequestIncomingConnection, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   454 void ConnStates::TRequestIncomingConnection::DoL()
       
   455 	{
       
   456 	__ASSERT_DEBUG((subsessmessage_cast<ECNWaitForIncoming>(&iContext.iMessage)), ConnPanic(KPanicIncorrectMessage));
       
   457 	RNodeInterface* sp = iContext.Node().ServiceProvider();
       
   458 	User::LeaveIfError(sp ? KErrNone : KErrNotReady);
       
   459 
       
   460     iContext.iNodeActivity->PostRequestTo(*sp,
       
   461     	TCFServiceProvider::TCommsBinderRequest(TSubConnOpen::EWaitForIncoming).CRef());
       
   462 	}
       
   463 
       
   464 DEFINE_SMELEMENT(ConnStates::TProcessIncomingConnection, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   465 void ConnStates::TProcessIncomingConnection::DoL()
       
   466 	{
       
   467 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   468     CSubConnection* waitingSubConn = iContext.Node().Session()->CSubConnectionFromHandle(static_cast<CESockClientActivityBase&>(*iContext.iNodeActivity).Int0());
       
   469 	User::LeaveIfError(waitingSubConn != NULL ? KErrNone : KErrCancel);
       
   470 
       
   471     TCFServiceProvider::TCommsBinderResponse& binderResp = message_cast<TCFServiceProvider::TCommsBinderResponse>(iContext.iMessage);
       
   472     iContext.iNodeActivity->PostRequestTo(waitingSubConn->Id(),
       
   473         TCFDataClient::TBindTo(binderResp.iNodeId).CRef());
       
   474 	}
       
   475 
       
   476 
       
   477 //
       
   478 //Stop
       
   479 DEFINE_SMELEMENT(ConnStates::TSendStopConnection, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   480 void ConnStates::TSendStopConnection::DoL()
       
   481 	{
       
   482 	__ASSERT_DEBUG((subsessmessage_cast<ECNStop>(&iContext.iMessage)), ConnPanic(KPanicIncorrectMessage));
       
   483 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   484 	CESockClientActivityBase& ac = static_cast<CESockClientActivityBase&>(*iContext.iNodeActivity);
       
   485 
       
   486 	//Convert the received enum (the stop type) into an error code that will be passed to the interface clients
       
   487 	TInt stopCode = KErrCancel;
       
   488 	switch (ac.Int0())
       
   489 		{
       
   490 		case RConnection::EStopNormal:
       
   491 			stopCode = KErrCancel;
       
   492 			break;
       
   493 		case RConnection::EStopAuthoritative:
       
   494 			stopCode = KErrConnectionTerminated;
       
   495 			break;
       
   496 		default:
       
   497 			__ASSERT_DEBUG(EFalse, User::Panic(KSpecAssert_ESockSSockscnsts, 6));
       
   498 		}
       
   499 
       
   500 	RNodeInterface* sp = iContext.Node().ServiceProvider();
       
   501 	if(sp)
       
   502 		{ // We can only post the 'stop' if we've got a service provider and its not already leaving (e.g., gone down).
       
   503 		if (!(sp->Flags() & TClientType::ELeaving))
       
   504 		    {
       
   505 			sp->PostMessage(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), TCFServiceProvider::TStop(stopCode).CRef());
       
   506 		    }
       
   507 		else
       
   508 			{
       
   509 			MESH_LOG((KESockConnectionTag, _L8("ConnStates::TSendStopConnection:\tDoL - IGNORING POST!")));
       
   510 			}
       
   511 		}
       
   512 	else
       
   513 		{ // Otherwise just set the activity idle and bail out.
       
   514 		iContext.Activity()->SetIdle();
       
   515 		}
       
   516 	}
       
   517 
       
   518 DEFINE_SMELEMENT(ConnStates::TConnectionSendStopSCPR, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   519 void ConnStates::TConnectionSendStopSCPR::DoL()
       
   520 	{
       
   521 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   522 
       
   523 	TInt stopCode = 0;
       
   524 
       
   525 	switch (static_cast<CESockClientActivityBase*>(iContext.iNodeActivity)->Int1())
       
   526 		{
       
   527 	case RConnection::EStopNormal:
       
   528 		stopCode = KErrCancel;
       
   529 		break;
       
   530 
       
   531 	case RConnection::EStopAuthoritative:
       
   532 		stopCode = KErrConnectionTerminated;
       
   533 		break;
       
   534 
       
   535 	default:
       
   536 		__ASSERT_DEBUG( false , User::Panic(KSpecAssert_ESockSSockscnsts, 7)); // CConnection should have verified the parameters before stopping the subconnection
       
   537 		}
       
   538 
       
   539 	// Send the stop message to the subconnection.
       
   540 	RNodeInterface* scpr = static_cast<CConnection&>(iContext.Node()).DefaultSubConnectionServiceProvider();
       
   541 	__ASSERT_DEBUG( scpr , User::Panic(KSpecAssert_ESockSSockscnsts, 8)); // subconnection must exist or the stop operation should not have been initiated
       
   542 	scpr->PostMessage(
       
   543 		TNodeCtxId(iContext.ActivityId(), iContext.NodeId()),
       
   544 		TCFServiceProvider::TStop(stopCode).CRef()
       
   545 		);
       
   546 	}
       
   547 
       
   548 DEFINE_SMELEMENT(ConnStates::TCancelStartOrAttachConnection, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   549 void ConnStates::TCancelStartOrAttachConnection::DoL()
       
   550 	{
       
   551 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   552 
       
   553 	if (iContext.Node().FindActivityById(ECFActivityStart))
       
   554 		{
       
   555 		RClientInterface::OpenPostMessageClose(
       
   556 			TNodeCtxId(ECNStart, iContext.NodeId()),
       
   557 			TNodeCtxId(ECNStart, iContext.NodeId()),
       
   558 			TEBase::TCancel().CRef());
       
   559 		}
       
   560 	else if (iContext.Node().FindActivityById(ECFActivityConnectionAttach))
       
   561 		{
       
   562 		RClientInterface::OpenPostMessageClose(
       
   563 			TNodeCtxId(ECNAttach, iContext.NodeId()),
       
   564 			TNodeCtxId(ECNAttach, iContext.NodeId()),
       
   565 			TEBase::TCancel().CRef());
       
   566 		}
       
   567 	}
       
   568 
       
   569 //
       
   570 //Close
       
   571 DEFINE_SMELEMENT(ConnStates::TDetachDataClients, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   572 void ConnStates::TDetachDataClients::DoL()
       
   573 	{
       
   574 	while (ETrue)
       
   575     	{
       
   576     	TClientIter<TDefaultClientMatchPolicy> iter = iContext.Node().GetClientIter<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EData));
       
   577     	RNodeInterface* client = iter[0];
       
   578     	if (client)
       
   579         	{
       
   580 #if defined(__GCCXML__)
       
   581         	CSubConnection& subconn = *reinterpret_cast<CSubConnection*>(&client->RecipientId().Node());
       
   582 #else
       
   583         	CSubConnection& subconn = *mcfnode_cast<CSubConnection>(&client->RecipientId().Node());
       
   584 #endif
       
   585         	iContext.Node().RemoveClient(subconn.Id());
       
   586         	subconn.RemoveClient(iContext.NodeId());
       
   587         	}
       
   588     	else
       
   589         	{
       
   590         	break;
       
   591         	}
       
   592     	}
       
   593 	}
       
   594 
       
   595 DEFINE_SMELEMENT(ConnStates::TStartOrAttachActive, NetStateMachine::MStateFork, ConnStates::TContext)
       
   596 TInt ConnStates::TStartOrAttachActive::TransitionTag()
       
   597 	{
       
   598 	if (iContext.Node().FindActivityById(ECFActivityStart) || iContext.Node().FindActivityById(ECFActivityConnectionAttach))
       
   599 		{
       
   600 		return MeshMachine::KActiveTag;
       
   601 		}
       
   602 	return KNoTag;
       
   603 	}
       
   604 
       
   605 DEFINE_SMELEMENT(ConnStates::TAwaitingGoneDown, NetStateMachine::MState, ConnStates::TContext)
       
   606 TBool ConnStates::TAwaitingGoneDown::Accept()
       
   607 	{
       
   608 	if (!iContext.iMessage.IsMessage<TCFControlClient::TGoneDown>())
       
   609     	{
       
   610     	return EFalse;
       
   611     	}
       
   612 
       
   613     //TODO - fix this defect:
       
   614     //1) TGoneDown should not be sent when stopping or closing
       
   615     //2) FindActivityById(ECFActivityStop) is not safe
       
   616     //3) why the condition iContext.Node().ServiceProvider()? Who can be sending TGoneDown if not the service provider?
       
   617     bool stoppingOrClosing = iContext.Node().FindActivityById(ECFActivityStop) || iContext.Node().FindActivityById(ECFActivityDestroy);
       
   618     if (!stoppingOrClosing && iContext.Node().ServiceProvider() &&
       
   619         *iContext.Node().ServiceProvider() == iContext.iSender)
       
   620         {
       
   621         return ETrue;
       
   622         }
       
   623     iContext.iMessage.ClearMessageId();
       
   624     return EFalse;
       
   625 	}
       
   626 
       
   627 DEFINE_SMELEMENT(ConnStates::TGenerateConnectionUpProgress, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   628 void ConnStates::TGenerateConnectionUpProgress::DoL()
       
   629 	{
       
   630 	TCFMessage::TStateChange msg(TStateChange(KConnectionUp, KErrNone));
       
   631 	RNodeInterface::OpenPostMessageClose(iContext.Node().Id(), iContext.Node().Id(), msg);
       
   632 	}
       
   633 
       
   634 DEFINE_SMELEMENT(ConnStates::TGenerateConnectionDownProgress, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   635 void ConnStates::TGenerateConnectionDownProgress::DoL()
       
   636 	{
       
   637 	// Do not self-post a message if there is a pending ConnectionClose activity.  When the ConnectionGoingDown
       
   638 	// activity (calling this method) terminates, the ConnectionClose activity unparks (being synchronised
       
   639 	// against ConnectionGoingDown), the CConnection is destroyed, and the subsequent self-dispatch
       
   640 	// will panic.
       
   641     __ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   642 	TInt error = iContext.iNodeActivity->Error();
       
   643 
       
   644 	if (error == KErrNone && iContext.iMessage.IsMessage<TCFServiceProvider::TStopped>())
       
   645 		{
       
   646 		error = message_cast<TCFServiceProvider::TStopped>(iContext.iMessage).iValue;
       
   647 		}
       
   648 
       
   649     __ASSERT_DEBUG(error != KErrNone, ConnPanic(KPanicIncorrectState));
       
   650 	
       
   651 	if (iContext.Node().CountActivities(ECFActivityDestroy) == 0)
       
   652 		{
       
   653 		TCFMessage::TStateChange msg(TStateChange(KConnectionDown, error));
       
   654 		CConnection& cc = iContext.Node();
       
   655 		RNodeInterface::OpenPostMessageClose(cc.Id(), cc.Id(), msg);
       
   656 		}
       
   657 	}
       
   658 
       
   659 //
       
   660 //Progress & Progress Request
       
   661 DEFINE_SMELEMENT(ConnStates::TProcessStateChange, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   662 void ConnStates::TProcessStateChange::DoL()
       
   663 	{
       
   664 	TStateChange& progress = message_cast<TCFMessage::TStateChange>(iContext.iMessage).iStateChange;
       
   665 
       
   666 	//Check whether KDataTransferUnblocked is received and if yes, then traslate it to KConnectionUp (== KLinkLayerOpen)
       
   667 	// the log only sees the translated version, this goes into the queue, so it alright I suppose.
       
   668 	if (progress.iStage == KDataTransferUnblocked )
       
   669 		{
       
   670 		progress.iStage = KConnectionUp;	// KLinkLayerOpen
       
   671 		}
       
   672 
       
   673 	LOG( ESockLog::Printf(KESockConnectionTag, _L("CConnection %08x:\tProgressNotification(TInt aStage %d, TInt aError %d)"),
       
   674 		&(iContext.Node()), progress.iStage, progress.iError) );
       
   675 
       
   676 	//Diagnostic assertion.
       
   677 	//If ECFActivityConnectionStateChangeRequest is running, it has not been
       
   678 	//presented with the TStateChange message (channel activity id != 0?) which is a serious mistake.
       
   679 	__ASSERT_DEBUG(iContext.Node().CountActivities(ECFActivityConnectionStateChangeRequest)==0, User::Panic(KSpecAssert_ESockSSockscnsts, 9));
       
   680 
       
   681 	CConnection& cc = iContext.Node();
       
   682 	if (cc.iLastProgress == progress)
       
   683 		{
       
   684 		return; //ignore this duplicate
       
   685 		}
       
   686 	cc.iLastProgress = progress;
       
   687 
       
   688 	if (progress.iError != KErrNone)
       
   689 		{
       
   690         cc.iLastProgressError = progress; //Save last progress in error for use by LastProgressErrorL()
       
   691     	}
       
   692 
       
   693 	#ifdef ESOCK_LOGGING_ACTIVE
       
   694 		// Check to see if the progress queue is full causing older progress to be discarded.
       
   695 		// This has the potential to cause problems if a critical progress item is lost.
       
   696 		// Normally the queue is large enough such that this doesn't happen but this log entry
       
   697 		// serves as a warning if it ever does.
       
   698 		if( cc.iProgressQueue.IsFull() )
       
   699 			{
       
   700 			LOG( ESockLog::Printf(KESockConnectionTag, _L("CConnection %08x:\tThe maximum progress queue size of %d has been exceeded - discarding old progress to make space for new item"), this, KMaxProgressQueueLength); )
       
   701 			}
       
   702 	#endif
       
   703 
       
   704 	//Add the progress to queue
       
   705 	cc.iProgressQueue.Enque(progress);
       
   706 	}
       
   707 
       
   708 DEFINE_SMELEMENT(ConnStates::TProcessProgressRequest, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   709 void ConnStates::TProcessProgressRequest::DoL()
       
   710 	{
       
   711 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   712 	CESockClientActivityBase& ac = static_cast<CESockClientActivityBase&>(*iContext.iNodeActivity);
       
   713 	TUint selectedProgressStage = ac.Int1();
       
   714 
       
   715 	TStateChange progress;
       
   716 	TBool found = EFalse;
       
   717 
       
   718 	//Are we here as a result of receiving TStateChange (rather than ECNProgressNotification)?
       
   719 	TCFMessage::TStateChange* msg = message_cast<TCFMessage::TStateChange>(&iContext.iMessage);
       
   720 	if (msg)
       
   721 		{ //Yes, we have been triggered by a TStateChange message
       
   722 		//Check if this is the progress we are waiting for, otherwise dump the progress
       
   723 		//Check whether KDataTransferUnblocked is received and if yes, then traslate it to KConnectionUp (== KLinkLayerOpen)
       
   724 		if (msg->iStateChange.iStage == KDataTransferUnblocked )
       
   725 			{
       
   726 			msg->iStateChange.iStage = KConnectionUp;	// KLinkLayerOpen
       
   727 			}
       
   728 		if (selectedProgressStage == KConnProgressDefault
       
   729 			|| selectedProgressStage == msg->iStateChange.iStage
       
   730 				|| KErrNone != msg->iStateChange.iError)
       
   731 			{
       
   732 			progress = msg->iStateChange;
       
   733 			found = ETrue;
       
   734 			}
       
   735 		}
       
   736 	else
       
   737 		{ //No, we must have been triggered by a ECNProgressNotification message
       
   738 		__ASSERT_DEBUG((subsessmessage_cast<ECNProgressNotification>(&iContext.iMessage)), ConnPanic(KPanicIncorrectMessage));
       
   739 
       
   740 		//Process the queue looking for the progress of interest
       
   741 		found = iContext.Node().iProgressQueue.Deque(progress);
       
   742 		if (found && selectedProgressStage != KConnProgressDefault)
       
   743 			{
       
   744 			// For a selected progress request, dequeue entries until we find one which
       
   745 			// matches the criteria.  If we dequeue all entries, fall through without
       
   746 			// completing the message.  It it not considered useful to retain un-matching
       
   747 			// entries on the queue if a selected progress request is pending.
       
   748 			while (found)
       
   749 				{
       
   750 				if (progress.iStage == selectedProgressStage || progress.iError != KErrNone)
       
   751 					{
       
   752 					break;
       
   753 					}
       
   754 				found = iContext.Node().iProgressQueue.Deque(progress);
       
   755 				}
       
   756 			}
       
   757 		}
       
   758 
       
   759 	if (found)
       
   760 		{
       
   761 		//We have found a progress of interest, finish
       
   762 		TPckg<TStateChange> progressPkg(progress);
       
   763 		ac.WriteL(0,progressPkg);
       
   764 		ac.SetIdle(); //We are done
       
   765 		}
       
   766 	}
       
   767 
       
   768 
       
   769 //
       
   770 //Legacy enumeration
       
   771 DEFINE_SMELEMENT(ConnStates::TAwaitingEnumResponse, NetStateMachine::MState, ConnStates::TContext)
       
   772 TBool ConnStates::TAwaitingEnumResponse::Accept()
       
   773 	{
       
   774 	return iContext.iMessage.IsMessage<TCFInternalEsock::TLegacyConnectionEnumResponse>();
       
   775 	}
       
   776 
       
   777 DEFINE_SMELEMENT(ConnStates::TProcessEnumResponse, NetStateMachine::MStateTransition, ConnStates::TContext)
       
   778 void ConnStates::TProcessEnumResponse::DoL()
       
   779 	{
       
   780 	TCFInternalEsock::TLegacyConnectionEnumResponse& msg = message_cast<TCFInternalEsock::TLegacyConnectionEnumResponse>(iContext.iMessage);
       
   781 	iContext.Node().iLegacyConnection.CompleteDataPlaneEnumeration(address_cast<TNodeId>(iContext.iSender), msg.iValue1, reinterpret_cast<HBufC8*>(msg.iValue2), msg.iValue3);
       
   782 	}
       
   783 
       
   784 
       
   785 //
       
   786 //CStartAttachActivity
       
   787 MeshMachine::CNodeActivityBase* ConnActivities::CStartAttachActivity::NewWaitForIncomingConnectionActivityL(const MeshMachine::TNodeActivity& aActivitySig, MeshMachine::AMMNodeBase& aNode)
       
   788 	{
       
   789 	//Leave from here will complete the client message
       
   790 	User::LeaveIfError(aNode.CountActivities(ECFActivityStart)? KErrInUse : KErrNone);
       
   791 	User::LeaveIfError(aNode.CountActivities(ECFActivityConnectionAttach)? KErrInUse : KErrNone);
       
   792 
       
   793 	// When waiting for an incoming connection we will additionally check that the connection is already started
       
   794 	User::LeaveIfError(aNode.CountClients<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EServProvider)) > 0 ? KErrNone : KErrNotReady );
       
   795 
       
   796 	return new (ELeave) ConnActivities::CStartAttachActivity(aActivitySig,aNode);
       
   797 	}
       
   798 
       
   799 MeshMachine::CNodeActivityBase* ConnActivities::CStartAttachActivity::NewStartConnectionActivityL(const MeshMachine::TNodeActivity& aActivitySig, MeshMachine::AMMNodeBase& aNode)
       
   800 	{
       
   801 	//Leave from here will complete the client message
       
   802 	User::LeaveIfError(aNode.CountActivities(ECFActivityStart)? KErrInUse : KErrNone);
       
   803 	User::LeaveIfError(aNode.CountActivities(ECFActivityConnectionAttach)? KErrInUse : KErrNone);
       
   804 
       
   805 	// When starting a connection we will additionally check that the connection is not already started
       
   806 	User::LeaveIfError(aNode.CountClients<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EServProvider)) > 0 ? KErrInUse : KErrNone);
       
   807 
       
   808 	return new (ELeave) ConnActivities::CStartAttachActivity(aActivitySig,aNode);
       
   809 	}
       
   810 
       
   811 ConnActivities::CStartAttachActivity::~CStartAttachActivity()
       
   812 	{
       
   813 	// Call ABindingActivity base class to send TBindToComplete (before TDestroy)
       
   814 	FinalReplyToOriginator(KErrAbort);
       
   815 
       
   816 	if (!iCSR.IsNull())
       
   817 		{
       
   818 #ifndef __GCCXML__
       
   819 		RNodeInterface::OpenPostMessageClose(TNodeCtxId(ActivityId(), iNode.Id()), iCSR, TEChild::TDestroy().CRef());
       
   820 #endif
       
   821 		iCSR.SetNull(); // = TNodeId::NullCommsId();
       
   822 		}
       
   823 
       
   824 	if(iConnPrefList)
       
   825 		{
       
   826 		while(iConnPrefList->Count() != 0)
       
   827 			{
       
   828 			SMetaData* pref = (*iConnPrefList)[0];
       
   829 			if(pref != NULL)
       
   830 				delete pref;
       
   831 			iConnPrefList->Remove(0);
       
   832 			}
       
   833 
       
   834 		delete iConnPrefList;
       
   835 		iConnPrefList = NULL;
       
   836 		}
       
   837 	}
       
   838 
       
   839 
       
   840 TBool ConnActivities::CStartAttachActivity::Next(MeshMachine::TNodeContextBase& aContext)
       
   841     {
       
   842     // If the connection start preferences were set the activity will have completed the initial IPC and will
       
   843     // now be waiting upon the async ECNStart IPC to arrive before proceeding. The TCFInternalEsock::TSubSess
       
   844     // message will use the IPC number in the activity id part of aContext. MatchSender() will expect the
       
   845     // activity Id and so will never give a match. Here we ensure that our second IPC is matched and accepted.
       
   846     
       
   847     TCFInternalEsock::TSubSess* msg = message_cast<TCFInternalEsock::TSubSess>(&aContext.iMessage);
       
   848     if (!msg || msg->iMessage.Function() != ECNStart)
       
   849         {
       
   850         return CNodeActivityBase::Next(aContext);
       
   851         }
       
   852     
       
   853     MESH_LOG((KESockConnectionTag, _L8("CStartAttachActivity::Next:\tAccepted ECNStart IPC after ECNSetStartPrefs")));
       
   854     TBool nextRet = ACore::Next(&aContext);
       
   855     if(nextRet)
       
   856         {
       
   857         MESH_LOG_ACTIVITY_EXT(KESockConnectionTag, this, &aContext, (_L8("CStartAttachActivity::Next:\tNext->transition")));
       
   858         }
       
   859     return nextRet;
       
   860     }
       
   861 
       
   862 
       
   863 DEFINE_SMELEMENT(CStartAttachActivity::TNoTagOrStartPrefsSetTag, NetStateMachine::MStateFork, ConnStates::TContext)
       
   864 TInt CStartAttachActivity::TNoTagOrStartPrefsSetTag::TransitionTag()
       
   865     {
       
   866     CStartAttachActivity& ac = static_cast<CStartAttachActivity&>(*iContext.iNodeActivity);
       
   867 
       
   868     if (ac.Function() == ECNSetStartPrefs)
       
   869         {
       
   870         return CStartAttachActivity::KStartPrefsSetTag | NetStateMachine::EForward;
       
   871         }
       
   872     return MeshMachine::KNoTag | NetStateMachine::EForward;
       
   873     }
       
   874 
       
   875 DEFINE_SMELEMENT(CStartAttachActivity::TNoTagOrLegacyAttach, NetStateMachine::MStateFork, ConnStates::TContext)
       
   876 TInt CStartAttachActivity::TNoTagOrLegacyAttach::TransitionTag()
       
   877 	{
       
   878 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   879 	const TConnPref& cp = static_cast<ConnActivities::CStartAttachActivity&>(*iContext.iNodeActivity).SelectionPrefs().Prefs();
       
   880 	if (cp.ExtensionId()==TConnPref::EConnPrefCommDb)
       
   881 		{//this is legacy attach
       
   882 		return CStartAttachActivity::KExecuteLegacyAttach;
       
   883 		}
       
   884 	return KNoTag;
       
   885 	}
       
   886 
       
   887 DEFINE_SMELEMENT(CStartAttachActivity::TNoTagOrWaitAvailable, NetStateMachine::MStateFork, ConnStates::TContext)
       
   888 TInt CStartAttachActivity::TNoTagOrWaitAvailable::TransitionTag()
       
   889 	{
       
   890 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   891 	ConnActivities::CStartAttachActivity& activity = static_cast<ConnActivities::CStartAttachActivity&>(*iContext.iNodeActivity);
       
   892 
       
   893 	TConnPrefList* prefsList = activity.ConnPrefList();
       
   894 	if (prefsList)
       
   895 		{
       
   896 		TBool startAuto = EFalse;
       
   897 		for (TInt i = 0; i < prefsList->Count(); i++)
       
   898 				{
       
   899 				TConnAutoStartPref* pref = smetadata_cast<TConnAutoStartPref>((*prefsList)[i]);
       
   900 				if(pref)
       
   901 					{
       
   902 					startAuto = ETrue;
       
   903 					break;
       
   904 					}
       
   905 				}
       
   906 		if (startAuto)
       
   907 			{
       
   908 			TBool &autoStart = activity.AutoStartPresent();
       
   909 			autoStart = ETrue;
       
   910 			iContext.iNodeActivity->ClearPostedTo();
       
   911 			return KWaitAvailable;
       
   912 			}
       
   913 
       
   914 		}
       
   915 	return KNoTag;
       
   916 	}
       
   917 
       
   918 DEFINE_SMELEMENT(CStartAttachActivity::TErrorTagOrWaitAvailableBackward, NetStateMachine::MStateFork, ConnStates::TContext)
       
   919 TInt CStartAttachActivity::TErrorTagOrWaitAvailableBackward::TransitionTag()
       
   920 	{
       
   921 	__ASSERT_DEBUG((message_cast<TEBase::TError>(&iContext.iMessage)), ConnPanic(KPanicIncorrectMessage));
       
   922 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   923 	ConnActivities::CStartAttachActivity& activity = static_cast<ConnActivities::CStartAttachActivity&>(*iContext.iNodeActivity);
       
   924 
       
   925 	if (!activity.AutoStartPresent())
       
   926 		{
       
   927 		return KErrorTag;
       
   928 		}
       
   929 
       
   930 	TEBase::TError& msg = message_cast<TEBase::TError>(iContext.iMessage);
       
   931 	if (msg.iValue == KErrUmtsMaxNumOfContextExceededByNetwork ||
       
   932 		msg.iValue == KErrUmtsMaxNumOfContextExceededByPhone)
       
   933 		{
       
   934 		return KWaitAvailable | NetStateMachine::EBackward;
       
   935 		}
       
   936 	else
       
   937 		{
       
   938 		return KErrorTag;
       
   939 		}
       
   940 	}
       
   941 
       
   942 DEFINE_SMELEMENT(CStartAttachActivity::TAwaitingAvailableOrError, NetStateMachine::MState, TContext)
       
   943 TInt CStartAttachActivity::TAwaitingAvailableOrError::Accept()
       
   944 	{
       
   945 	if (iContext.iMessage.IsMessage<TCFAvailabilityControlClient::TAvailabilityNotification>())
       
   946 		{
       
   947 		TCFAvailabilityControlClient::TAvailabilityNotification& msg = message_cast<TCFAvailabilityControlClient::TAvailabilityNotification>(iContext.iMessage);
       
   948 		if (msg.iAvailabilityStatus.Score() > TAvailabilityStatus::EMinAvailabilityScore)
       
   949 			{
       
   950 			RNodeInterface::OpenPostMessageClose(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), iContext.iSender,
       
   951 					TEBase::TCancel().CRef());
       
   952 			return ETrue;
       
   953 			}
       
   954 		return EFalse;
       
   955 		}
       
   956 	else if (iContext.iMessage.IsMessage<TEBase::TError>())
       
   957 		{
       
   958 		TEBase::TError* msg = message_cast<TEBase::TError>(&iContext.iMessage);
       
   959 		iContext.iNodeActivity->SetError(msg->iValue);
       
   960 		return ETrue;
       
   961 		}
       
   962 	return EFalse;
       
   963 	}
       
   964 
       
   965 
       
   966 DEFINE_SMELEMENT(CStartAttachActivity::TSubscribeForAvailability, NetStateMachine::MStateTransition, TContext)
       
   967 void CStartAttachActivity::TSubscribeForAvailability::DoL()
       
   968 	{
       
   969 	__ASSERT_DEBUG(iContext.iNodeActivity, ConnPanic(KPanicNoActivity));
       
   970 	ConnActivities::CStartAttachActivity& activity = static_cast<ConnActivities::CStartAttachActivity&>(*iContext.iNodeActivity);
       
   971 
       
   972 	TConnPrefList* connPrefList = activity.ConnPrefList();
       
   973 	if (connPrefList && connPrefList->Count()>0)
       
   974 		{
       
   975 		TBool startAuto = EFalse;
       
   976 		for (TInt i = 0; i < connPrefList->Count(); i++)
       
   977 				{
       
   978 				TConnAutoStartPref* pref = smetadata_cast<TConnAutoStartPref>((*connPrefList)[i]);
       
   979 				if(pref)
       
   980 					{
       
   981 					startAuto = ETrue;
       
   982 					break;
       
   983 					}
       
   984 				}
       
   985 		if (startAuto)
       
   986 			{
       
   987 			TAvailabilitySubscriptionOptions subscriptionOptions;
       
   988 			TClientIter<TDefaultClientMatchPolicy> iter = iContext.Node().GetClientIter<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EServProvider, TCFClientType::EAvailabilityProvider));
       
   989 			RNodeInterface* mcpr = iter[0];
       
   990 			__ASSERT_DEBUG(mcpr, ConnPanic(KPanicNoAvailabilityProvider));
       
   991 			RNodeInterface::OpenPostMessageClose(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), mcpr->RecipientId(),
       
   992 				TCFAvailabilityProvider::TAvailabilityNotificationRegistration(subscriptionOptions).CRef());
       
   993 			}
       
   994 		}
       
   995 	}
       
   996 
       
   997 DEFINE_SMELEMENT(CStartAttachActivity::TAwaitingSelectCompleteOrError, NetStateMachine::MState, TContext)
       
   998 TInt CStartAttachActivity::TAwaitingSelectCompleteOrError::Accept()
       
   999 	{
       
  1000 	if (iContext.iMessage.IsMessage<TCFSelector::TSelectComplete>())
       
  1001 		{
       
  1002 		return ETrue;
       
  1003 		}
       
  1004 	else if(iContext.iMessage.IsMessage<TEBase::TError>())
       
  1005 		{
       
  1006 		TEBase::TError& errorMsg = message_cast<TEBase::TError>(iContext.iMessage);
       
  1007 		iContext.Activity()->SetError(errorMsg.iValue);
       
  1008 		return ETrue;
       
  1009 		}
       
  1010 
       
  1011 	return EFalse;
       
  1012 	}
       
  1013 
       
  1014 
       
  1015 #ifdef SYMBIAN_NETWORKING_UPS
       
  1016 
       
  1017 DEFINE_SMELEMENT(CStartAttachActivity::TSendPolicyCheckRequestToServiceProvider, NetStateMachine::MStateTransition, ConnStates::TContext)
       
  1018 void CStartAttachActivity::TSendPolicyCheckRequestToServiceProvider::DoL()
       
  1019 	{
       
  1020 	MPlatsecApiExt* platsec = NULL;
       
  1021 	iContext.Node().ReturnInterfacePtrL(platsec);		// from CConnection
       
  1022 	// TODO: what to do on an error (see TODO below)
       
  1023     __ASSERT_DEBUG(platsec, User::Panic(KSpecAssert_ESockSSockscnsts, 18));
       
  1024 
       
  1025 	TProcessId processId;
       
  1026 	TThreadId threadId;
       
  1027 	TInt err = platsec->GetProcessAndThreadId(processId, threadId);
       
  1028 	if (err != KErrNone)
       
  1029 		{
       
  1030 		const TNodeId& self = iContext.Node().Id();
       
  1031 		iContext.Node().SelfInterface().PostMessage(self, TEBase::TError(err).CRef());
       
  1032 		iContext.Activity()->ClearPostedTo();
       
  1033 		}
       
  1034 	else
       
  1035 		{
       
  1036 		// KErrCorrupt is a default value for the platsec result.  The platsec result must be filled-in by the provider
       
  1037 		// and not ESock because only the provider knows the (technology specific) policy to check against.
       
  1038 		// Destination address is not valid in this context, so it is just a null descriptor.
       
  1039 
       
  1040 		const TPolicyCheckRequestParams params(processId, threadId, KErrCorrupt, KNullDesC8(), TUpsDestinationAddrType(ETNone), iContext.NodeId());
       
  1041 
       
  1042 		const UpsMessage::TPolicyCheckRequest checkMsg(params);
       
  1043 
       
  1044 		RNodeInterface* serviceProvider = iContext.Node().ServiceProvider();
       
  1045 
       
  1046         __ASSERT_DEBUG(serviceProvider, User::Panic(KSpecAssert_ESockSSockscnsts, 19));
       
  1047 		iContext.Activity()->PostRequestTo(*serviceProvider, checkMsg);
       
  1048 		}
       
  1049 	}
       
  1050 
       
  1051 DEFINE_SMELEMENT(CStartAttachActivity::TNoTagOrUpsErrorTag, NetStateMachine::MStateFork, ConnStates::TContext)
       
  1052 TInt CStartAttachActivity::TNoTagOrUpsErrorTag::TransitionTag()
       
  1053 	{
       
  1054 	UpsMessage::TPolicyCheckResponse* policyCheckResponseMsg = message_cast<UpsMessage::TPolicyCheckResponse>(&iContext.iMessage);
       
  1055 	if (policyCheckResponseMsg && policyCheckResponseMsg->iValue != KErrNone)
       
  1056 		{
       
  1057 		iContext.Activity()->SetError(policyCheckResponseMsg->iValue);
       
  1058 		return KUpsErrorTag;
       
  1059 		}
       
  1060 	else
       
  1061 		{
       
  1062 		TEBase::TError* errorMsg = message_cast<TEBase::TError>(&iContext.iMessage);
       
  1063 		// TODO: there is already code for this isn't there?  A template that checks for TError and
       
  1064 		// sets the activity in error?
       
  1065 		if (errorMsg)
       
  1066 			{
       
  1067 			iContext.Activity()->SetError(errorMsg->iValue);
       
  1068 			return KUpsErrorTag;
       
  1069 			}
       
  1070 		}
       
  1071 	return KNoTag;
       
  1072 	}
       
  1073 #endif
       
  1074 
       
  1075 //
       
  1076 // CTierManagerActivity
       
  1077 
       
  1078 MeshMachine::CNodeActivityBase* ConnActivities::CTierManagerActivity::NewL(const MeshMachine::TNodeActivity& aActivitySig, MeshMachine::AMMNodeBase& aNode)
       
  1079 	{
       
  1080 	return new(ELeave) ConnActivities::CTierManagerActivity(aActivitySig, aNode);
       
  1081 	}
       
  1082 
       
  1083 // States
       
  1084 
       
  1085 DEFINE_SMELEMENT(CTierManagerActivity::TAwaitingTierManager, NetStateMachine::MState, TContext)
       
  1086 TInt CTierManagerActivity::TAwaitingTierManager::Accept()
       
  1087 	{
       
  1088 	if(iContext.iMessage.IsMessage<TCFFactory::TPeerFoundOrCreated>())
       
  1089 		{
       
  1090 		TCFFactory::TPeerFoundOrCreated& msg = message_cast<TCFFactory::TPeerFoundOrCreated>(iContext.iMessage);
       
  1091 		iContext.Activity()->iTierManager = msg.iNodeId;
       
  1092 		iContext.Activity()->ClearPostedTo();
       
  1093 
       
  1094 		return ETrue;
       
  1095 		}
       
  1096 	else if(iContext.iMessage.IsMessage<TEBase::TCancel>())
       
  1097 		{
       
  1098 		iContext.Activity()->SetError(KErrCancel);
       
  1099 
       
  1100 		return ETrue;
       
  1101 		}
       
  1102 	else if(iContext.iMessage.IsMessage<TEBase::TError>())
       
  1103 		{
       
  1104 		// Register the error
       
  1105 		TEBase::TError& errorMsg = message_cast<TEBase::TError>(iContext.iMessage);
       
  1106 		iContext.Activity()->SetError(errorMsg.iValue);
       
  1107 
       
  1108 		return ETrue;
       
  1109 		}
       
  1110 
       
  1111 	return EFalse;
       
  1112 	}
       
  1113 
       
  1114 DEFINE_SMELEMENT(CTierManagerActivity::TAwaitingJoinComplete, NetStateMachine::MState, TContext)
       
  1115 TInt CTierManagerActivity::TAwaitingJoinComplete::Accept()
       
  1116 	{
       
  1117 	if(iContext.iMessage.IsMessage<TCFPeer::TJoinComplete>())
       
  1118 		{
       
  1119 		return ETrue;
       
  1120 		}
       
  1121 	else if(iContext.iMessage.IsMessage<TEBase::TCancel>())
       
  1122 		{
       
  1123 		iContext.Activity()->SetError(KErrCancel);
       
  1124 
       
  1125 		return ETrue;
       
  1126 		}
       
  1127 	else if(iContext.iMessage.IsMessage<TEBase::TError>())
       
  1128 		{
       
  1129 		// Register the error
       
  1130 		TEBase::TError& errorMsg = message_cast<TEBase::TError>(iContext.iMessage);
       
  1131 		iContext.Activity()->SetError(errorMsg.iValue);
       
  1132 
       
  1133 		return ETrue;
       
  1134 		}
       
  1135 
       
  1136 	return EFalse;
       
  1137 	}
       
  1138 
       
  1139 // Transitions
       
  1140 
       
  1141 DEFINE_SMELEMENT(CTierManagerActivity::TFindTierManager, NetStateMachine::MStateTransition, TContext)
       
  1142 void CTierManagerActivity::TFindTierManager::DoL()
       
  1143 	{
       
  1144 	__ASSERT_DEBUG(iContext.Activity(), ConnPanic(KPanicNoActivity));
       
  1145 
       
  1146 	// Find out if the tier UID has been set.
       
  1147 	TBool tierUidIsNull = (iContext.Activity()->iTierUid == TUid::Null());
       
  1148 
       
  1149 	// Panic in UDEB, Leave in UREL. The tier UID should be set in the derived
       
  1150 	// class's constructor
       
  1151 	__ASSERT_DEBUG(!tierUidIsNull, User::Panic(KSpecAssert_ESockSSockscnsts, 10));
       
  1152 	User::LeaveIfError(tierUidIsNull ? KErrNotReady : KErrNone);
       
  1153 	TAlwaysFindFactoryQuery query;
       
  1154 	RNodeInterface::OpenPostMessageClose(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), SockManGlobals::Get()->GetPlaneFC(TCFPlayerRole(TCFPlayerRole::ETierMgrPlane)),
       
  1155 		 TCFFactory::TFindOrCreatePeer(TCFPlayerRole::ETierMgrPlane, iContext.Activity()->iTierUid, &query).CRef());
       
  1156 	}
       
  1157 
       
  1158 DEFINE_SMELEMENT(CTierManagerActivity::TJoinTierManager, NetStateMachine::MStateTransition, TContext)
       
  1159 void CTierManagerActivity::TJoinTierManager::DoL()
       
  1160 	{
       
  1161 	__ASSERT_DEBUG(iContext.Activity(), ConnPanic(KPanicNoActivity));
       
  1162 
       
  1163 	RNodeInterface::OpenPostMessageClose(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), iContext.Activity()->iTierManager,
       
  1164 		TCFServiceProvider::TJoinRequest(iContext.NodeId(), TClientType(TCFClientType::EAdministrative)).CRef());
       
  1165 
       
  1166 	iContext.Node().AddClientL(iContext.Activity()->iTierManager, TClientType(TCFClientType::EServProvider));
       
  1167 	}
       
  1168 
       
  1169 // This solely exists separately from the other identical-looking version
       
  1170 //    in this file
       
  1171 //    ("AllInterfaceNotificationActivity::TLeaveTierManager::DoL()") because
       
  1172 //    the activities referenced by its TContext have iTierManager
       
  1173 //    at different offsets. This is because they have different parent
       
  1174 //    classes and, as such, have different member variable.
       
  1175 //
       
  1176 // The terrible thing is, this is usable in the other place,
       
  1177 //    and builds without complaint... then explodes when it tries
       
  1178 //    to send messages to a garbage iTierManager.
       
  1179 //
       
  1180 //    TAKE CARE OF IT!!!
       
  1181 DEFINE_SMELEMENT(CTierManagerActivity::TLeaveTierManager, NetStateMachine::MStateTransition, TContext)
       
  1182 void CTierManagerActivity::TLeaveTierManager::DoL()
       
  1183 	{
       
  1184 	__ASSERT_DEBUG(iContext.Activity(), ConnPanic(KPanicNoActivity));
       
  1185 
       
  1186 	RNodeInterface::OpenPostMessageClose(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), iContext.Activity()->iTierManager,
       
  1187 		TEChild::TLeft().CRef());
       
  1188 
       
  1189 	iContext.Node().RemoveClient(iContext.Activity()->iTierManager);
       
  1190 	}
       
  1191 
       
  1192 //
       
  1193 // CAllInterfaceNotificationActivity
       
  1194 
       
  1195 CNodeActivityBase* ConnActivities::CAllInterfaceNotificationActivity::NewL(const MeshMachine::TNodeActivity& aActivitySig, MeshMachine::AMMNodeBase& aNode)
       
  1196 	{
       
  1197 	return new (ELeave) ConnActivities::CAllInterfaceNotificationActivity(aActivitySig, aNode);
       
  1198 	}
       
  1199 
       
  1200 ConnActivities::CAllInterfaceNotificationActivity::~CAllInterfaceNotificationActivity()
       
  1201 	{
       
  1202 	//Remove the only client here
       
  1203 	RNodeInterface* aux = iNode.GetFirstClient<TDefaultClientMatchPolicy>(TClientType(TCFClientType::EAux));
       
  1204 	if (aux)
       
  1205 		{
       
  1206 		iNode.RemoveClient(aux->RecipientId());
       
  1207 		}
       
  1208 	delete iAllInterfaceNotificationWorker; //delete this node (why via iAllInterfaceNotificationWorker??)
       
  1209 	}
       
  1210 
       
  1211 // States
       
  1212 
       
  1213 DEFINE_SMELEMENT(AllInterfaceNotificationActivity::TAwaitingStart, NetStateMachine::MState, TContext)
       
  1214 TInt AllInterfaceNotificationActivity::TAwaitingStart::Accept()
       
  1215 	{
       
  1216 	return iContext.iMessage.IsMessage<TCFServiceProvider::TStart>();
       
  1217 	}
       
  1218 
       
  1219 DEFINE_SMELEMENT(AllInterfaceNotificationActivity::TAwaitingTierManager, NetStateMachine::MState, TContext)
       
  1220 TInt AllInterfaceNotificationActivity::TAwaitingTierManager::Accept()
       
  1221 	{
       
  1222 	if(iContext.iMessage.IsMessage<TCFFactory::TPeerFoundOrCreated>())
       
  1223 		{
       
  1224 		TCFFactory::TPeerFoundOrCreated& msg = message_cast<TCFFactory::TPeerFoundOrCreated>(iContext.iMessage);
       
  1225 		iContext.Activity()->iTierManager = msg.iNodeId;
       
  1226 		iContext.Activity()->ClearPostedTo();
       
  1227 
       
  1228 		return ETrue;
       
  1229 		}
       
  1230 	return EFalse;
       
  1231 	}
       
  1232 
       
  1233 DEFINE_SMELEMENT(AllInterfaceNotificationActivity::TAwaitingJoinComplete, NetStateMachine::MState, TContext)
       
  1234 TInt AllInterfaceNotificationActivity::TAwaitingJoinComplete::Accept()
       
  1235 	{
       
  1236 	return iContext.iMessage.IsMessage<TCFPeer::TJoinComplete>();
       
  1237 	}
       
  1238 
       
  1239 DEFINE_SMELEMENT(AllInterfaceNotificationActivity::TAwaitingLinkNotification, NetStateMachine::MState, TContext)
       
  1240 TInt AllInterfaceNotificationActivity::TAwaitingLinkNotification::Accept()
       
  1241 	{
       
  1242 	return (iContext.iMessage.IsMessage<TCFTierStatusProvider::TTierNotification>() ||
       
  1243 			iContext.iMessage.IsMessage<TEBase::TCancel>() ||
       
  1244 			iContext.iMessage.IsMessage<TEBase::TError>() );
       
  1245 	}
       
  1246 
       
  1247 void AllInterfaceNotificationActivity::TAwaitingLinkNotification::Cancel()
       
  1248 	{
       
  1249 	__ASSERT_DEBUG(0, User::Panic(KSpecAssert_ESockSSockscnsts, 11));
       
  1250 	}
       
  1251 
       
  1252 
       
  1253 // for shutdown
       
  1254 DEFINE_SMELEMENT(AllInterfaceNotificationActivity::TAwaitingLinkNotificationError, NetStateMachine::MState, TContext)
       
  1255 TInt AllInterfaceNotificationActivity::TAwaitingLinkNotificationError::Accept()
       
  1256 	{
       
  1257 	if(iContext.iMessage.IsMessage<TCFTierStatusProvider::TTierNotification>())
       
  1258 		{
       
  1259 		// we're already shutting down. so have detached from CConnection.
       
  1260 		//  so we have to delete the enclosed object instead.
       
  1261 		LOG( ESockLog::Printf(KESockConnectionTag, _L("AllInterfaceNotification received bundle when already shutting down so deleting it")));
       
  1262 		TCFTierStatusProvider::TTierNotification& msg = message_cast<TCFTierStatusProvider::TTierNotification>(iContext.iMessage);
       
  1263 		msg.iBundle->Close();
       
  1264        	iContext.iMessage.ClearMessageId();
       
  1265 		}
       
  1266 	else if(iContext.iMessage.IsMessage<TEBase::TCancel>())
       
  1267 		{
       
  1268 		LOG( ESockLog::Printf(KESockConnectionTag, _L("AllInterfaceNotification received TCancel when already shutting down so discarding it")));
       
  1269        	iContext.iMessage.ClearMessageId();
       
  1270 		}
       
  1271 
       
  1272 	return iContext.iMessage.IsMessage<TEBase::TError>();
       
  1273 	}
       
  1274 
       
  1275 
       
  1276 // Transitions
       
  1277 
       
  1278 DEFINE_SMELEMENT(ConnectionGoingDownActivity::TStoreGoneDownError, NetStateMachine::MStateTransition, TContext)
       
  1279 void ConnectionGoingDownActivity::TStoreGoneDownError::DoL()
       
  1280 	{
       
  1281 	__ASSERT_DEBUG(iContext.Activity(), ConnPanic(KPanicNoActivity));
       
  1282     TCFControlClient::TGoneDown& goneDownMessage = message_cast<TCFControlClient::TGoneDown>(iContext.iMessage);
       
  1283 	LOG( ESockLog::Printf(KESockConnectionTag, _L("TStoreGoneDownError. error:%d"), goneDownMessage.iValue1));
       
  1284 	iContext.Activity()->SetError(goneDownMessage.iValue1);
       
  1285 	}
       
  1286 
       
  1287 DEFINE_SMELEMENT(AllInterfaceNotificationActivity::TAddClient, NetStateMachine::MStateTransition, TContext)
       
  1288 void AllInterfaceNotificationActivity::TAddClient::DoL()
       
  1289 	{
       
  1290 	__ASSERT_DEBUG(iContext.Activity() == NULL, ConnPanic(KPanicNoActivity));
       
  1291 	__ASSERT_DEBUG(iContext.iPeer == NULL, User::Panic(KSpecAssert_ESockSSockscnsts, 12));
       
  1292 	iContext.iPeer = iContext.Node().AddClientL(address_cast<TNodeId>(iContext.iSender), TClientType(TCFClientType::EAux));
       
  1293 	}
       
  1294 
       
  1295 DEFINE_SMELEMENT(AllInterfaceNotificationActivity::TFindTierManager, NetStateMachine::MStateTransition, TContext)
       
  1296 void AllInterfaceNotificationActivity::TFindTierManager::DoL()
       
  1297 	{
       
  1298 	__ASSERT_DEBUG(iContext.Activity(), ConnPanic(KPanicNoActivity));
       
  1299 
       
  1300 	// Find out if the tier UID has been set.
       
  1301 	TBool tierUidIsNull = (iContext.Activity()->iTierUid == TUid::Null());
       
  1302 
       
  1303 	// Panic in UDEB, Leave in UREL. The tier UID should be set in the derived
       
  1304 	// class's constructor
       
  1305 	__ASSERT_DEBUG(!tierUidIsNull, User::Panic(KSpecAssert_ESockSSockscnsts, 13));
       
  1306 	User::LeaveIfError(tierUidIsNull ? KErrNotReady : KErrNone);
       
  1307 
       
  1308 	TAlwaysFindFactoryQuery query;
       
  1309 	RNodeInterface::OpenPostMessageClose(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), SockManGlobals::Get()->GetPlaneFC(TCFPlayerRole(TCFPlayerRole::ETierMgrPlane)),
       
  1310 		TCFFactory::TFindOrCreatePeer(TCFPlayerRole::ETierMgrPlane, iContext.Activity()->iTierUid, &query).CRef());
       
  1311 	}
       
  1312 
       
  1313 DEFINE_SMELEMENT(AllInterfaceNotificationActivity::TJoinTierManager, NetStateMachine::MStateTransition, TContext)
       
  1314 void AllInterfaceNotificationActivity::TJoinTierManager::DoL()
       
  1315 	{
       
  1316 	__ASSERT_DEBUG(iContext.Activity(), ConnPanic(KPanicNoActivity));
       
  1317 
       
  1318 
       
  1319 	RNodeInterface::OpenPostMessageClose(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), iContext.Activity()->iTierManager,
       
  1320 		TCFServiceProvider::TJoinRequest(iContext.NodeId(), TClientType(TCFClientType::EAdministrative)).CRef());
       
  1321 
       
  1322 	iContext.Node().AddClientL(iContext.Activity()->iTierManager, TClientType(TCFClientType::EServProvider));
       
  1323 	}
       
  1324 
       
  1325 DEFINE_SMELEMENT(AllInterfaceNotificationActivity::TStartLinkNotification, NetStateMachine::MStateTransition, TContext)
       
  1326 void AllInterfaceNotificationActivity::TStartLinkNotification::DoL()
       
  1327 	{
       
  1328 	__ASSERT_DEBUG(iContext.Activity(), ConnPanic(KPanicNoActivity));
       
  1329 
       
  1330 	CConnectionServParameterBundle* queryBundle = CConnectionServParameterBundle::NewL();
       
  1331    	CleanupStack::PushL(queryBundle);
       
  1332    	CRefCountOwnedParameterBundle* bundleOwner = new(ELeave)CRefCountOwnedParameterBundle(queryBundle);
       
  1333    	CleanupStack::Pop();
       
  1334    	bundleOwner->Open();
       
  1335    	CleanupClosePushL(*bundleOwner);
       
  1336 
       
  1337 	CParameterSetContainer* psc = CParameterSetContainer::NewL(*queryBundle);
       
  1338 
       
  1339 	// Set up a status filter for connected access points only
       
  1340 	TAccessPointStatusFilter availFilter;
       
  1341 	availFilter.Configured(EAccessPointFlagIgnore);
       
  1342 	availFilter.Restricted(EAccessPointFlagIgnore);
       
  1343 	availFilter.Available(EAccessPointFlagIgnore);
       
  1344 	availFilter.Started(EAccessPointFlagIgnore);
       
  1345 	availFilter.Active(EAccessPointFlagMatchAny);
       
  1346 	queryBundle->AddMatchConditionL(availFilter);
       
  1347 	queryBundle->AddParameterSetToReturnL(XAccessPointGenericParameterSet::Type());
       
  1348 	queryBundle->AddParameterSetToReturnL(XIpProtoAccessPointParameterSet::Type());
       
  1349 
       
  1350    	const CAllInterfaceNotificationWorker* worker = iContext.Activity()->iAllInterfaceNotificationWorker;
       
  1351    	const RMessage2* rm2 = &(iContext.Activity()->iAllInterfaceNotificationWorker->iConnection.Message());
       
  1352 
       
  1353    	RClientInterface::OpenPostMessageClose(worker->Id(), iContext.Activity()->iTierManager,
       
  1354    		TCFTierStatusProvider::TTierNotificationRegistration(bundleOwner, rm2).CRef());
       
  1355    	CleanupStack::Pop(); // bundleOwner
       
  1356 	}
       
  1357 
       
  1358 DEFINE_SMELEMENT(AllInterfaceNotificationActivity::TEnqueueNotification, NetStateMachine::MStateTransition, TContext)
       
  1359 void AllInterfaceNotificationActivity::TEnqueueNotification::DoL()
       
  1360 	{
       
  1361 	__ASSERT_DEBUG(iContext.Activity(), ConnPanic(KPanicNoActivity));
       
  1362 
       
  1363 	TCFTierStatusProvider::TTierNotification& msg = message_cast<TCFTierStatusProvider::TTierNotification>(iContext.iMessage);
       
  1364 
       
  1365 	__ASSERT_DEBUG(msg.iBundle, User::Panic(KSpecAssert_ESockSSockscnsts, 14));
       
  1366 	if(msg.iBundle->PtrL()->CountParamSetContainers() > 0)
       
  1367 		{
       
  1368 		TInt i = 0;
       
  1369 		TBool found = EFalse;
       
  1370 		while(const CConnectionServParameterSetContainer* container = static_cast<const CConnectionServParameterSetContainer*>(msg.iBundle->Ptr()->GetParamSetContainer(i++)))
       
  1371 			{
       
  1372 			const XAccessPointGenericParameterSet* status = XAccessPointGenericParameterSet::FindInParamSetContainer(*container);
       
  1373 			
       
  1374 			TConnInterfaceState interfaceState;
       
  1375 			if (status->AccessPointStatus().Active() == ConnectionServ::EAccessPointFlagTrue)
       
  1376 				{
       
  1377 				interfaceState = EInterfaceUp;
       
  1378 				}
       
  1379 			else
       
  1380 				{			
       
  1381 				interfaceState = EInterfaceDown;
       
  1382 				}
       
  1383 
       
  1384 			const XIpProtoAccessPointParameterSet* ipApParams = XIpProtoAccessPointParameterSet::FindInParamSetContainer(*container);
       
  1385 //			ASSERT(ipApParams);
       
  1386 			if (ipApParams) // commsdat might be broken so XIpProtoAccessPointParameterSet not available
       
  1387 				{
       
  1388 				TConnectionInfo connectionInfo(ipApParams->IapId(), ipApParams->NetworkId());
       
  1389 
       
  1390 				TInterfaceNotification notification = { connectionInfo,  interfaceState };
       
  1391 
       
  1392 				iContext.Node().iConnection.iLegacyConnection.iNotificationQueue.Enque(notification);
       
  1393 
       
  1394 				found = ETrue;
       
  1395 				}
       
  1396 			}
       
  1397 		if (found)
       
  1398 			iContext.Node().iConnection.iLegacyConnection.CompleteAllInterfaceNotificationL(KErrNone);
       
  1399 
       
  1400 		}
       
  1401 
       
  1402 	msg.iBundle->Close();
       
  1403 	}
       
  1404 
       
  1405 DEFINE_SMELEMENT(AllInterfaceNotificationActivity::TCancelLinkNotification, NetStateMachine::MStateTransition, TContext)
       
  1406 void AllInterfaceNotificationActivity::TCancelLinkNotification::DoL()
       
  1407 	{
       
  1408 	__ASSERT_DEBUG(iContext.Activity(), ConnPanic(KPanicNoActivity));
       
  1409 
       
  1410    	TNodeId goo = iContext.Activity()->iTierManager;
       
  1411 
       
  1412    	const CAllInterfaceNotificationWorker* worker = iContext.Activity()->iAllInterfaceNotificationWorker;
       
  1413 
       
  1414 	RNodeInterface::OpenPostMessageClose(worker->Id(), iContext.Activity()->iTierManager,
       
  1415 		TEBase::TCancel().CRef());
       
  1416 	}
       
  1417 
       
  1418 // This solely exists separately from the other identical-looking version
       
  1419 //    in this file ("CTierManagerActivity::TLeaveTierManager::DoL()") because
       
  1420 //    the activities referenced by its TContext have iTierManager
       
  1421 //    at different offsets. This is because they have different parent
       
  1422 //    classes and, as such, have different member variable.
       
  1423 //
       
  1424 // The terrible thing is, this is usable in the other place,
       
  1425 //    and builds without complaint... then explodes when it tries
       
  1426 //    to send messages to a garbage iTierManager.
       
  1427 //
       
  1428 //    TAKE CARE OF IT!!!
       
  1429 DEFINE_SMELEMENT(AllInterfaceNotificationActivity::TLeaveTierManager, NetStateMachine::MStateTransition, TContext)
       
  1430 void AllInterfaceNotificationActivity::TLeaveTierManager::DoL()
       
  1431 	{
       
  1432 	__ASSERT_DEBUG(iContext.Activity(), ConnPanic(KPanicNoActivity));
       
  1433 
       
  1434 	RNodeInterface::OpenPostMessageClose(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), iContext.Activity()->iTierManager,
       
  1435 		TEChild::TLeft().CRef());
       
  1436 
       
  1437 	iContext.Node().RemoveClient(iContext.Activity()->iTierManager);
       
  1438 	}
       
  1439 
       
  1440 DEFINE_SMELEMENT(AllInterfaceNotificationActivity::TSendErrorToConnection, NetStateMachine::MStateTransition, TContext)
       
  1441 void AllInterfaceNotificationActivity::TSendErrorToConnection::DoL()
       
  1442 	{
       
  1443 	// Send a TError to the CConnection to complete the shutdown handshake.
       
  1444 	RNodeInterface::OpenPostMessageClose(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), iContext.Node().iConnection.Id(), TEBase::TError(iContext.Activity()->KickOffMessageId(), KErrCancel).CRef());
       
  1445 	}
       
  1446 
       
  1447 DEFINE_SMELEMENT(TNoTagOrCancelAllInterfaceWorker, NetStateMachine::MStateFork, TContext)
       
  1448 TInt TNoTagOrCancelAllInterfaceWorker::TransitionTag()
       
  1449 	{
       
  1450 	// If this CConnection has an AllInterfaceNotificationWorker, return KCancelAllInterfaceWorker else return KNoTag.
       
  1451 	AConnectionLegacy& cl = iContext.Node().iLegacyConnection;
       
  1452 	return cl.iAllInterfaceNotificationWorker.IsNull() ? KNoTag : KCancelAllInterfaceWorker;
       
  1453 	}
       
  1454 
       
  1455 DEFINE_SMELEMENT(TCancelAllInterfaceNotificationWorker, NetStateMachine::MStateTransition, TContext)
       
  1456 void TCancelAllInterfaceNotificationWorker::DoL()
       
  1457 	{
       
  1458 	CConnection& cc = iContext.Node();
       
  1459 	AConnectionLegacy& cl = cc.iLegacyConnection;
       
  1460 	// If this CConnection has an AllInterfaceNotificationWorker, send a TCancel to it to begin
       
  1461 	// the shutdown handshake.
       
  1462 	if(!cl.iAllInterfaceNotificationWorker.IsNull())
       
  1463 		{
       
  1464 		TNodeCtxId dest(ECFActivityConnectionAllInterfaceNotification, cl.iAllInterfaceNotificationWorker);
       
  1465 		RNodeInterface::OpenPostMessageClose(cc.Id(), dest, TEBase::TCancel().CRef());
       
  1466 		cl.iAllInterfaceNotificationWorker.SetNull();
       
  1467 		}
       
  1468 	}
       
  1469 
       
  1470 //
       
  1471 // CEnumerateConnectionsActivity
       
  1472 
       
  1473 MeshMachine::CNodeActivityBase* ConnActivities::CEnumerateConnectionsActivity::NewL(const MeshMachine::TNodeActivity& aActivitySig, MeshMachine::AMMNodeBase& aNode)
       
  1474 	{
       
  1475 	return new(ELeave) ConnActivities::CEnumerateConnectionsActivity(aActivitySig, aNode);
       
  1476 	}
       
  1477 
       
  1478 // States
       
  1479 
       
  1480 DEFINE_SMELEMENT(EnumerateConnectionsActivity::TAwaitingTierStatus, NetStateMachine::MState, TContext)
       
  1481 TInt EnumerateConnectionsActivity::TAwaitingTierStatus::Accept()
       
  1482 	{
       
  1483 	TBool isTierStatus = iContext.iMessage.IsMessage<TCFTierStatusProvider::TTierStatus>();
       
  1484 	TBool isError = iContext.iMessage.IsMessage<TEBase::TError>();
       
  1485 
       
  1486 	if(isTierStatus || isError)
       
  1487 		{
       
  1488 		// Leave the tier manager
       
  1489 		RNodeInterface::OpenPostMessageClose(TNodeCtxId(iContext.ActivityId(), iContext.NodeId()), iContext.Activity()->iTierManager,
       
  1490 			TEChild::TLeft().CRef());
       
  1491 
       
  1492 		iContext.Node().RemoveClient(iContext.Activity()->iTierManager);
       
  1493 		}
       
  1494 
       
  1495 	return isTierStatus;
       
  1496 	}
       
  1497 
       
  1498 // Transitions
       
  1499 
       
  1500 DEFINE_SMELEMENT(EnumerateConnectionsActivity::TQueryTierStatus, NetStateMachine::MStateTransition, TContext)
       
  1501 void EnumerateConnectionsActivity::TQueryTierStatus::DoL()
       
  1502 	{
       
  1503 	__ASSERT_DEBUG(iContext.Activity(), ConnPanic(KPanicNoActivity));
       
  1504 
       
  1505 	// Clear the connection info cache
       
  1506 	iContext.Node().iLegacyConnection.iConnectionInfoPtrArray.ResetAndDestroy();
       
  1507 
       
  1508 	CConnectionServParameterBundle* queryBundle = CConnectionServParameterBundle::NewL();
       
  1509    	CleanupStack::PushL(queryBundle);
       
  1510    	CRefCountOwnedParameterBundle* bundleOwner = new (ELeave)CRefCountOwnedParameterBundle(queryBundle);
       
  1511    	CleanupStack::Pop(queryBundle);
       
  1512    	bundleOwner->Open();
       
  1513    	CleanupClosePushL(*bundleOwner);
       
  1514 
       
  1515 	// Set up a status filter for connected access points only
       
  1516 	TAccessPointStatusFilter availFilter;
       
  1517 	availFilter.Configured(EAccessPointFlagIgnore);
       
  1518 	availFilter.Restricted(EAccessPointFlagIgnore);
       
  1519 	availFilter.Available(EAccessPointFlagIgnore);
       
  1520 	availFilter.Started(EAccessPointFlagIgnore);
       
  1521 	availFilter.Active(EAccessPointFlagMatchTrue);
       
  1522 
       
  1523 	queryBundle->AddMatchConditionL(availFilter);
       
  1524 	queryBundle->AddParameterSetToReturnL(XIpProtoAccessPointParameterSet::Type());
       
  1525 
       
  1526    	RClientInterface::OpenPostMessageClose(iContext.NodeId(), iContext.Activity()->iTierManager,
       
  1527    		TCFTierStatusProvider::TTierStatusQuery(bundleOwner, &iContext.Activity()->iMessage).CRef());
       
  1528    	CleanupStack::Pop(); // bundleOwner
       
  1529 	}
       
  1530 
       
  1531 DEFINE_SMELEMENT(EnumerateConnectionsActivity::TCompleteClient, NetStateMachine::MStateTransition, TContext)
       
  1532 void EnumerateConnectionsActivity::TCompleteClient::DoL()
       
  1533 	{
       
  1534 	__ASSERT_DEBUG(iContext.Activity(), ConnPanic(KPanicNoActivity));
       
  1535 
       
  1536 	TPckg<TUint> pckg(iContext.Node().iLegacyConnection.iConnectionInfoPtrArray.Count());
       
  1537 	iContext.Activity()->WriteL(0, pckg);
       
  1538 	}
       
  1539 
       
  1540 DEFINE_SMELEMENT(EnumerateConnectionsActivity::TCacheConnectionInfo, NetStateMachine::MStateTransition, TContext)
       
  1541 void EnumerateConnectionsActivity::TCacheConnectionInfo::DoL()
       
  1542 	{
       
  1543 	__ASSERT_DEBUG(iContext.Activity(), ConnPanic(KPanicNoActivity));
       
  1544 
       
  1545 	TCFTierStatusProvider::TTierStatus& msg = message_cast<TCFTierStatusProvider::TTierStatus>(iContext.iMessage);
       
  1546 
       
  1547 	const CConnectionServParameterSetContainer* container;
       
  1548 	const XIpProtoAccessPointParameterSet* ipApParams;
       
  1549 
       
  1550 	for (TInt i=0; i<msg.iBundle->PtrL()->CountParamSetContainers(); i++)
       
  1551 		{
       
  1552 		container = static_cast<const CConnectionServParameterSetContainer*>(msg.iBundle->Ptr()->GetParamSetContainer(i));
       
  1553 
       
  1554 		ipApParams = XIpProtoAccessPointParameterSet::FindInParamSetContainer(*container);
       
  1555 		__ASSERT_DEBUG(ipApParams, User::Panic(KSpecAssert_ESockSSockscnsts, 16));
       
  1556 
       
  1557 		TSourcedConnectionInfo* connInfo = new(ELeave) TSourcedConnectionInfo(ipApParams->IapId(), ipApParams->NetworkId(), ipApParams->ConnectionType(), ipApParams->ControlClientId());
       
  1558 		iContext.Node().iLegacyConnection.iConnectionInfoPtrArray.AppendL(connInfo);
       
  1559 		}
       
  1560 
       
  1561 	msg.iBundle->Close();
       
  1562 	}
       
  1563 
       
  1564 DEFINE_SMELEMENT(ConnectionCleanupActivities::TNoTagOrNoTagBackwards, NetStateMachine::MStateFork, TContext)
       
  1565 TInt ConnectionCleanupActivities::TNoTagOrNoTagBackwards::TransitionTag()
       
  1566     {
       
  1567 	if ( iContext.iMessage.IsMessage<TEPeer::TLeaveComplete>() )
       
  1568 		{
       
  1569 //		__ASSERT_DEBUG(iContext.Node().GetClientIter(RNodeInterface::ECtrl|RNodeInterface::EData)[0] == NULL,
       
  1570 //		User::Panic(KCorePRPanic, KPanicClientsStillPresent));
       
  1571 		if (iContext.Node().GetFirstClient<TDefaultClientMatchPolicy>(TCFClientType(TCFClientType::EServProvider)) == NULL)
       
  1572 			{ // This was the last service provider
       
  1573 			return NetStateMachine::EForward | MeshMachine::KNoTag;
       
  1574 			}
       
  1575 		// There are more service providers to expect 'leave complete' from so
       
  1576 		// loop round and wait for the next one.
       
  1577 		return NetStateMachine::EBackward | MeshMachine::KNoTag;
       
  1578 		}
       
  1579     __ASSERT_DEBUG(EFalse, User::Panic(KSpecAssert_ESockSSockscnsts, 17));
       
  1580     return KNoTag;
       
  1581     }
       
  1582 
       
  1583 DEFINE_SMELEMENT(ConnSubConnEventsActivity::TAwaitingSubConnEvent, NetStateMachine::MState, TContext)
       
  1584 TInt ConnSubConnEventsActivity::TAwaitingSubConnEvent::Accept()
       
  1585 	{
       
  1586 	if(iContext.iMessage.IsMessage<TCFInternalEsock::TSubConnectionOpenedEvent>() ||
       
  1587 	   iContext.iMessage.IsMessage<TCFInternalEsock::TSubConnectionClosedEvent>())
       
  1588 		{
       
  1589 		return ETrue;
       
  1590 		}
       
  1591 	return EFalse;
       
  1592 	}
       
  1593 
       
  1594 DEFINE_SMELEMENT(ConnSubConnEventsActivity::TProcessSubConnEvent, NetStateMachine::MStateTransition, TContext)
       
  1595 void ConnSubConnEventsActivity::TProcessSubConnEvent::DoL()
       
  1596 	{
       
  1597 	CConnection& conn = static_cast<CConnection&>(iContext.Node());
       
  1598 
       
  1599 	if(iContext.iMessage.IsMessage<TCFInternalEsock::TSubConnectionOpenedEvent>())
       
  1600 		{
       
  1601 		const TCFInternalEsock::TSubConnectionOpenedEvent& msg = message_cast<TCFInternalEsock::TSubConnectionOpenedEvent>(iContext.iMessage);
       
  1602 		conn.iLegacyConnection.SubConnectionEvent(msg.iSubConnectionOpenedEvent);
       
  1603 		}
       
  1604 	else
       
  1605 		{
       
  1606 		const TCFInternalEsock::TSubConnectionClosedEvent& msg = message_cast<TCFInternalEsock::TSubConnectionClosedEvent>(iContext.iMessage);
       
  1607 		conn.iLegacyConnection.SubConnectionEvent(msg.iSubConnectionClosedEvent);
       
  1608 		}
       
  1609 	}
       
  1610 
       
  1611 CNodeActivityBase* CConnLegacyRMessage2Activity::NewL( const TNodeActivity& aActivitySig, AMMNodeBase& aNode )
       
  1612 	{
       
  1613 	TUint c = GetNextActivityCountL(aActivitySig,aNode);
       
  1614 	return new (ELeave) CConnLegacyRMessage2Activity( aActivitySig, aNode, c);
       
  1615 	}
       
  1616 	
       
  1617 CConnLegacyRMessage2Activity::CConnLegacyRMessage2Activity( const TNodeActivity& aActivitySig, AMMNodeBase& aNode, TUint aNextActivityCount)
       
  1618 	: MeshMachine::CNodeParallelMessageStoreActivityBase(aActivitySig, aNode, aNextActivityCount)
       
  1619 	{
       
  1620 	}
       
  1621 
       
  1622 CConnLegacyRMessage2Activity::~CConnLegacyRMessage2Activity()
       
  1623 	{
       
  1624 	if (Error() != KErrNone)
       
  1625 		{
       
  1626 		Complete(Error());
       
  1627 		}
       
  1628 	if (!iCancelMessage.IsNull())
       
  1629 		{
       
  1630 		iCancelMessage.Complete(KErrNone);
       
  1631 		}
       
  1632 	SetError(KErrNone);
       
  1633 	}
       
  1634 
       
  1635 void CConnLegacyRMessage2Activity::PanicClient(const TDesC& aCatagory, TInt aCode)
       
  1636 	{
       
  1637 	if (!iSafeMessage.IsNull())
       
  1638 		{
       
  1639 		iSafeMessage.PanicClient(aCatagory, aCode);
       
  1640 		}
       
  1641 	}
       
  1642 
       
  1643 void CConnLegacyRMessage2Activity::Complete(TInt aCode)
       
  1644 	{
       
  1645 	if (!iSafeMessage.IsNull())
       
  1646 		{
       
  1647 		iSafeMessage.Complete(aCode);
       
  1648 		}
       
  1649 	}
       
  1650 
       
  1651 void CConnLegacyRMessage2Activity::SetCancelRequest(const Den::RSafeMessage& aMessage)
       
  1652 	{
       
  1653 	iCancelMessage.Duplicate(aMessage);
       
  1654 	}
       
  1655 
       
  1656 
       
  1657 DEFINE_SMELEMENT(TProcessLegacyRMessage2, NetStateMachine::MStateTransition, TContext)
       
  1658 void TProcessLegacyRMessage2::DoL()
       
  1659 	{
       
  1660 	ASSERT(iContext.iMessage.IsTypeOf(Meta::STypeId::CreateSTypeId(TCFSigLegacyRMessage2Ext::EUid, TCFSigLegacyRMessage2Ext::ETypeId)));
       
  1661 	// static_cast as it will be a derivative and message_cast won't work
       
  1662 	CConnLegacyRMessage2Activity* act = static_cast<CConnLegacyRMessage2Activity*>(iContext.Activity());
       
  1663 	TCFSigLegacyRMessage2Ext& msg = static_cast<TCFSigLegacyRMessage2Ext&>(iContext.iMessage);
       
  1664 	act->iSafeMessage.Duplicate(msg.iMessage);
       
  1665 	
       
  1666 	if (msg.CanProcess(iContext))
       
  1667 		{
       
  1668 		msg.ProcessL(iContext);
       
  1669 		}
       
  1670 	else
       
  1671 		{
       
  1672 		msg.ForwardL(iContext);
       
  1673 		}
       
  1674 	}
       
  1675 
       
  1676 DEFINE_SMELEMENT(TCompleteRMessage2, NetStateMachine::MStateTransition, TContext)
       
  1677 void TCompleteRMessage2::DoL()
       
  1678 	{
       
  1679 	TCFLegacyMessage::TLegacyRMessage2Processed& msg = message_cast<TCFLegacyMessage::TLegacyRMessage2Processed>(iContext.iMessage);
       
  1680 	CConnLegacyRMessage2Activity* act = static_cast<CConnLegacyRMessage2Activity*>(iContext.Activity());
       
  1681 
       
  1682     if (msg.iResponse.iType == TLegacyRMessage2Response::EPanic)
       
  1683 		{
       
  1684 		act->PanicClient(msg.iResponse.iCatagory, msg.iResponse.iCode);
       
  1685 		}
       
  1686     else
       
  1687 		{
       
  1688 		ASSERT(act->Message().IsTypeOf(Meta::STypeId::CreateSTypeId(TCFSigLegacyRMessage2Ext::EUid, TCFSigLegacyRMessage2Ext::ETypeId)));
       
  1689 		TInt error = static_cast<TCFSigLegacyRMessage2Ext&>(act->Message()).CheckError(iContext, msg.iResponse.iCode);
       
  1690 		act->Complete(error);
       
  1691 		}
       
  1692 	}
       
  1693 
       
  1694 DEFINE_SMELEMENT(THandleRMessage2Error, NetStateMachine::MStateTransition, ConnStates::TContext)
       
  1695 void THandleRMessage2Error::DoL()
       
  1696     {
       
  1697     CConnLegacyRMessage2Activity* act = static_cast<CConnLegacyRMessage2Activity*>(iContext.Activity());
       
  1698 	
       
  1699 	ASSERT(act->Message().IsTypeOf(Meta::STypeId::CreateSTypeId(TCFSigLegacyRMessage2Ext::EUid, TCFSigLegacyRMessage2Ext::ETypeId)));
       
  1700 	TInt error = static_cast<TCFSigLegacyRMessage2Ext&>(act->Message()).CheckError(iContext, act->Error());
       
  1701 	act->SetError(error);
       
  1702 	act->Complete(error);
       
  1703     }
       
  1704 
       
  1705 
       
  1706 DEFINE_SMELEMENT(TCancelAllLegacyRMessage2Activities, NetStateMachine::MStateTransition, TContext)
       
  1707 void TCancelAllLegacyRMessage2Activities::DoL()
       
  1708 	{
       
  1709 	const RPointerArray<CNodeActivityBase>& activities = iContext.Node().Activities();
       
  1710 
       
  1711 	for (TInt i = 0; i < activities.Count(); i++)
       
  1712 		{
       
  1713 		if (activities[i]->ActivitySigId() == ESock::ECFActivityConnectionLegacyRMessage2Handler)
       
  1714 			{
       
  1715 			activities[i]->Cancel(iContext);
       
  1716 			}
       
  1717 		}
       
  1718 	}
       
  1719 
       
  1720