|
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 // TestDummy implementation file for a Connection Provider |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 */ |
|
22 |
|
23 #include <comms-infras/mobilitycpractivities.h> |
|
24 #include <comms-infras/ss_nodemessages_factory.h> |
|
25 #include <es_sock.h> |
|
26 |
|
27 #include "dummypr_metaconnprov.h" |
|
28 #include "dummypr_connprov.h" |
|
29 #include "dummypr_subconnprov.h" |
|
30 |
|
31 #include <elements/sd_mintercept.h> |
|
32 |
|
33 |
|
34 #ifdef _DEBUG |
|
35 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module |
|
36 // (if it could happen through user error then you should give it an explicit, documented, category + code) |
|
37 _LIT(KSpecAssert_ESockTestdmyprcn, "ESockTestdmyprcn"); |
|
38 #endif |
|
39 |
|
40 #ifdef _DEBUG |
|
41 #define KDummyCprTag KESockConnectionTag |
|
42 #endif |
|
43 |
|
44 using namespace Messages; |
|
45 using namespace ESock; |
|
46 using namespace MeshMachine; |
|
47 using namespace PRActivities; |
|
48 |
|
49 //We reserve space for two preallocated activities that may start concurrently on the CPR |
|
50 //node: destroy and data client stop. |
|
51 static const TUint KDefaultMaxPreallocatedActivityCount = 2; |
|
52 static const TUint KMaxPreallocatedActivitySize = sizeof(MeshMachine::CNodeRetryParallelActivity) + sizeof(MeshMachine::APreallocatedOriginators<4>); |
|
53 static const TUint KDummyCPRPreallocatedActivityBufferSize = KDefaultMaxPreallocatedActivityCount * KMaxPreallocatedActivitySize; |
|
54 |
|
55 //-================================================ |
|
56 // |
|
57 // States and Transitions |
|
58 // |
|
59 //-================================================ |
|
60 namespace DummyCPRStates |
|
61 { |
|
62 DEFINE_SMELEMENT(TSetClientAsIncoming, NetStateMachine::MStateTransition, DummyCPRStates::TContext) |
|
63 void TSetClientAsIncoming::DoL() |
|
64 { |
|
65 if (iContext.Node().iConnStatus == CDummyConnectionProvider::EConnIncoming) |
|
66 { |
|
67 TCFFactory::TPeerFoundOrCreated& dcJoined = message_cast<TCFFactory::TPeerFoundOrCreated>(iContext.iMessage); |
|
68 Messages::ANode& incomingDCMCFNode = dcJoined.iNodeId.Node(); |
|
69 CDummySubConnectionProvider& incomingDC = mcfnode_cast<CDummySubConnectionProvider>(incomingDCMCFNode); |
|
70 incomingDC.SetToIncomingL(); |
|
71 } |
|
72 } |
|
73 |
|
74 DEFINE_SMELEMENT(TCreateIncomingSCPR, NetStateMachine::MStateTransition, DummyCPRStates::TContext) |
|
75 void TCreateIncomingSCPR::DoL() |
|
76 { |
|
77 if (iContext.Node().iConnStatus != CDummyConnectionProvider::EConnIncoming) |
|
78 { |
|
79 //wait forever. |
|
80 return; |
|
81 } |
|
82 TCFServiceProvider::TCommsBinderRequest& commsBinderReq = message_cast<TCFServiceProvider::TCommsBinderRequest>(iContext.iMessage); |
|
83 __ASSERT_DEBUG(commsBinderReq.iValue == TSubConnOpen::EWaitForIncoming, User::Panic(KSpecAssert_ESockTestdmyprcn, 1)); |
|
84 commsBinderReq.iValue = TSubConnOpen::ECreateNew; |
|
85 PRStates::TCreateDataClient createSCPR(iContext); |
|
86 createSCPR.DoL(); |
|
87 } |
|
88 |
|
89 DEFINE_SMELEMENT(TAwaitingStart, NetStateMachine::MState, DummyCPRStates::TContext) |
|
90 TBool TAwaitingStart::Accept() |
|
91 { |
|
92 const TLayerSelectionInfo* selectionInfo = static_cast<const TLayerSelectionInfo*>( |
|
93 iContext.Node().AccessPointConfig().FindExtension(TLayerSelectionInfo::TypeId())); |
|
94 ASSERT(selectionInfo); // should always be there |
|
95 |
|
96 if (iContext.iMessage.IsMessage<TCFServiceProvider::TStart>() && |
|
97 TCprConfigModifier::Is(selectionInfo->CprConfig(), TCprConfigModifier::EDontStart)) |
|
98 { |
|
99 return ETrue; |
|
100 } |
|
101 return EFalse; |
|
102 } |
|
103 } |
|
104 |
|
105 //-================================================ |
|
106 // |
|
107 // Activities |
|
108 // |
|
109 //-================================================ |
|
110 namespace DummyCprBinderRequestActivity |
|
111 { |
|
112 DECLARE_DEFINE_CUSTOM_NODEACTIVITY(ECFActivityBinderRequest, DummyCprBinderRequest, TCFServiceProvider::TCommsBinderRequest, CCommsBinderActivity::NewL) |
|
113 FIRST_NODEACTIVITY_ENTRY(CoreNetStates::TAwaitingBinderRequest, CCommsBinderActivity::TNoTagOrWaitForIncomingOrUseExistingDefaultBlockedByBinderRequest) |
|
114 NODEACTIVITY_ENTRY(KNoTag, PRStates::TCreateDataClient, CoreNetStates::TAwaitingDataClientJoin, MeshMachine::TNoTag) |
|
115 NODEACTIVITY_ENTRY(CoreNetStates::KWaitForIncoming, DummyCPRStates::TCreateIncomingSCPR, MeshMachine::TAwaitingMessageState<TCFFactory::TPeerFoundOrCreated>, MeshMachine::TNoTag) |
|
116 |
|
117 // Below this point we need to modify the error handling approach. If we're getting a TError on TBinderResponse, |
|
118 // this means the client requesting the binder couldn't bind to it. As far as the client is concerned, this |
|
119 // activity is finished (it has flagged an error). The standard error handling will result in erroring |
|
120 // the originator. In this case we shouoldn't error the originator, instead, wrap up quietly. |
|
121 THROUGH_NODEACTIVITY_ENTRY(KNoTag, CCommsBinderActivity::TProcessDataClientCreation, MeshMachine::TNoTag) |
|
122 THROUGH_NODEACTIVITY_ENTRY(KNoTag, DummyCPRStates::TSetClientAsIncoming, MeshMachine::TTag<CoreStates::KUseExisting>) |
|
123 |
|
124 NODEACTIVITY_ENTRY(CoreStates::KUseExisting, CCommsBinderActivity::TSendBinderResponse, CCommsBinderActivity::TAwaitingBindToComplete, MeshMachine::TNoTagOrErrorTag) |
|
125 LAST_NODEACTIVITY_ENTRY(KNoTag, MeshMachine::TDoNothing) |
|
126 LAST_NODEACTIVITY_ENTRY(KErrorTag, MeshMachine::TClearError) |
|
127 LAST_NODEACTIVITY_ENTRY(CoreNetStates::KWaitForIncoming, MeshMachine::TRaiseError<KErrNotSupported>) |
|
128 NODEACTIVITY_END() |
|
129 } |
|
130 |
|
131 namespace DummyCprStartActivity |
|
132 { |
|
133 DECLARE_DEFINE_CUSTOM_NODEACTIVITY(ECFActivityStart, DummyCPrStart, TCFServiceProvider::TStart, PRActivities::CStartActivity::NewL) |
|
134 FIRST_NODEACTIVITY_ENTRY(DummyCPRStates::TAwaitingStart, MeshMachine::TNoTag) |
|
135 LAST_NODEACTIVITY_ENTRY(KNoTag, MeshMachine::TRaiseError<KErrAbort>) |
|
136 NODEACTIVITY_END() |
|
137 } |
|
138 |
|
139 // Activity Map |
|
140 namespace DummyCPRStates |
|
141 { |
|
142 DECLARE_DEFINE_ACTIVITY_MAP(stateMap) |
|
143 ACTIVITY_MAP_ENTRY(DummyCprBinderRequestActivity, DummyCprBinderRequest) |
|
144 ACTIVITY_MAP_ENTRY(DummyCprStartActivity, DummyCPrStart) |
|
145 ACTIVITY_MAP_END_BASE(MobilityCprActivities, mobilityCprActivities) |
|
146 } |
|
147 |
|
148 CDummyConnectionProvider* CDummyConnectionProvider::NewL(ESock::CConnectionProviderFactoryBase& aFactory, TConnType aConnStatus) |
|
149 { |
|
150 CDummyConnectionProvider* self = new (ELeave) CDummyConnectionProvider(aFactory, aConnStatus); |
|
151 CleanupStack::PushL(self); |
|
152 self->ConstructL(KDummyCPRPreallocatedActivityBufferSize); |
|
153 CleanupStack::Pop(self); |
|
154 return self; |
|
155 } |
|
156 |
|
157 |
|
158 CDummyConnectionProvider::CDummyConnectionProvider(CConnectionProviderFactoryBase& aFactory, TConnType aConnStatus) |
|
159 : CMobilityConnectionProvider(aFactory, DummyCPRStates::stateMap::Self()), |
|
160 TIfStaticFetcherNearestInHierarchy(this), |
|
161 iConnStatus(aConnStatus) |
|
162 { |
|
163 LOG_NODE_CREATE(KDummyCprTag, CDummyConnectionProvider); |
|
164 } |
|
165 |
|
166 CDummyConnectionProvider::~CDummyConnectionProvider() |
|
167 { |
|
168 LOG_NODE_DESTROY(KDummyCprTag, CDummyConnectionProvider); |
|
169 } |
|
170 |
|
171 |
|
172 TInt CDummyConnectionProvider::ControlL(TUint aOptionLevel, TUint /*aOptionName*/, TDes8& /*aOption*/, ESock::MPlatsecApiExt* /*aPlatsecIfc*/) |
|
173 { |
|
174 if (aOptionLevel == EConnIncoming) |
|
175 { |
|
176 iConnStatus = EConnIncoming; |
|
177 } |
|
178 else if (aOptionLevel == EConnNoIncoming) |
|
179 { |
|
180 iConnStatus = EConnNoIncoming; |
|
181 } |
|
182 return KErrNone; |
|
183 } |
|
184 |
|
185 void CDummyConnectionProvider::ReturnInterfacePtrL(ESock::MLegacyControlApiExt*& aInterface) |
|
186 { |
|
187 aInterface = this; |
|
188 } |
|
189 |
|
190 |
|
191 |