|
1 // Copyright (c) 2007-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 // SIP Connection Provider implementation |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent |
|
21 */ |
|
22 |
|
23 #include <comms-infras/ss_log.h> |
|
24 #include <comms-infras/corecprstates.h> |
|
25 #include <comms-infras/corecpractivities.h> |
|
26 #include <comms-infras/metatype.h> |
|
27 #include "sipcpr.h" |
|
28 #include "sipcprstates.h" |
|
29 #include "sipprovisioninfo.h" |
|
30 #include <elements/mm_states.h> |
|
31 |
|
32 |
|
33 using namespace SipCprStates; |
|
34 using namespace SipCpr; |
|
35 using namespace ESock; |
|
36 using namespace NetStateMachine; |
|
37 using namespace Messages; |
|
38 using namespace MeshMachine; |
|
39 using namespace Meta; |
|
40 using namespace CprActivities; |
|
41 |
|
42 // |
|
43 //========================================================= |
|
44 // |
|
45 // Activities |
|
46 // |
|
47 //-========================================================= |
|
48 |
|
49 |
|
50 |
|
51 // provision activity to store provision message containing TransitionEngineMgr,ProfileId,appUid |
|
52 // from MCPR |
|
53 namespace SipCprProvisionActivity |
|
54 { |
|
55 DECLARE_DEFINE_NODEACTIVITY(ECFActivityStoreProvision, SipCprProvision, TCFDataClient::TProvisionConfig) |
|
56 FIRST_NODEACTIVITY_ENTRY(CoreNetStates::TAwaitingProvision, MeshMachine::TNoTagOrErrorTag) |
|
57 LAST_NODEACTIVITY_ENTRY(KNoTag, SipCprStates::TStoreProvision) |
|
58 NODEACTIVITY_END() |
|
59 } |
|
60 |
|
61 |
|
62 namespace SipCprBinderRequestActivity |
|
63 { |
|
64 DECLARE_DEFINE_CUSTOM_NODEACTIVITY(ECFActivityBinderRequest, SipCprBinderRequest, TCFServiceProvider::TCommsBinderRequest, PRActivities::CCommsBinderActivity::NewL) |
|
65 FIRST_NODEACTIVITY_ENTRY(CoreNetStates::TAwaitingBinderRequest,PRActivities::CCommsBinderActivity::TNoTagOrWaitForIncomingOrUseExistingDefaultBlockedByBinderRequest) |
|
66 NODEACTIVITY_ENTRY(KNoTag, PRStates::TCreateDataClient, CoreNetStates::TAwaitingDataClientJoin, MeshMachine::TNoTag) |
|
67 NODEACTIVITY_ENTRY(CoreNetStates::KWaitForIncoming, SipCprStates::TProcessWaitForIncmg, CoreNetStates::TAwaitingDataClientJoin, MeshMachine::TNoTag) |
|
68 // Below this point we need to modify the error handling approach. If we're getting a TError on TBinderResponse, |
|
69 // this means the client requesting the binder couldn't bind to it. As far as the client is concerned, this |
|
70 // activity is finished (it has flagged an error). The standard error handling will result in erroring |
|
71 // the originator. In this case we shouoldn't error the originator, instead, wrap up quietly. |
|
72 |
|
73 THROUGH_NODEACTIVITY_ENTRY(KNoTag, SipCprStates::TProcessSCPRCreation, SipCprStates::TWaitForIncomingOrUseExisting) |
|
74 // Wait for the incomingconnection message from SIP SCPR |
|
75 NODEACTIVITY_ENTRY(CoreNetStates::KWaitForIncoming,SipCprStates::TSetPostedToScpr, SipCprStates::TAwaitingIncomingConnection, MeshMachine::TTag<CoreStates::KUseExisting>) |
|
76 NODEACTIVITY_ENTRY(CoreStates::KUseExisting, PRActivities::CCommsBinderActivity::TSendBinderResponse, PRActivities::CCommsBinderActivity::TAwaitingBindToComplete/*CoreNetStates::TAwaitingBindToComplete*/, MeshMachine::TNoTagOrErrorTag) |
|
77 LAST_NODEACTIVITY_ENTRY(KNoTag, MeshMachine::TDoNothing) |
|
78 LAST_NODEACTIVITY_ENTRY(KErrorTag, MeshMachine::TRaiseAndClearActivityError) |
|
79 |
|
80 NODEACTIVITY_END() |
|
81 } |
|
82 |
|
83 //start activity |
|
84 //this could have a race condition.Please check SipCprStates::RegisterCpr |
|
85 namespace SipCprStartActivity |
|
86 { |
|
87 DECLARE_DEFINE_CUSTOM_NODEACTIVITY(ECFActivityStart, SipCprStart, TCFServiceProvider::TStart, PRActivities::CStartActivity::NewL) |
|
88 FIRST_NODEACTIVITY_ENTRY(CoreNetStates::TAwaitingStart, SipCprStates::TNoTagOrRegisteredBlockedByStop) |
|
89 NODEACTIVITY_ENTRY(KNoTag, SipCprStates::TRegisterCpr, SipCprStates::TAwaitingRegistrationComplete, MeshMachine::TNoTagOrErrorTag) |
|
90 NODEACTIVITY_ENTRY(KNoTag, CoreNetStates::TStartSelf, CoreNetStates::TAwaitingDataClientStarted, MeshMachine::TNoTag) |
|
91 LAST_NODEACTIVITY_ENTRY(KNoTag, CoreNetStates::TSendStarted) |
|
92 LAST_NODEACTIVITY_ENTRY(SipCprStates::KRegistered, CoreNetStates::TSendStarted) |
|
93 LAST_NODEACTIVITY_ENTRY(KErrorTag, MeshMachine::TRaiseAndClearActivityError) |
|
94 NODEACTIVITY_END() |
|
95 } |
|
96 |
|
97 namespace SipCprStopActivity |
|
98 { |
|
99 DECLARE_DEFINE_NODEACTIVITY(ECFActivityStop, SipCprStop, TCFServiceProvider::TStop) |
|
100 FIRST_NODEACTIVITY_ENTRY(CoreNetStates::TAwaitingStop, MeshMachine::TActiveOrNoTag<ECFActivityStartDataClient>) |
|
101 THROUGH_NODEACTIVITY_ENTRY(MeshMachine::KActiveTag, CoreNetStates::TCancelDataClientStart, MeshMachine::TNoTag) |
|
102 NODEACTIVITY_ENTRY(KNoTag, CoreNetStates::TStopSelf, CoreNetStates::TAwaitingDataClientStopped, SipCprStates::TNoTagOrDeRegister) |
|
103 NODEACTIVITY_ENTRY(SipCprStates::KDeRegister, SipCprStates::TDeRegisterCpr, SipCprStates::TAwaitingDeRegistrationComplete, MeshMachine::TNoTagOrErrorTag) |
|
104 LAST_NODEACTIVITY_ENTRY(KNoTag, /*SipCprStates::TSendStopped*/PRStates::TSendStoppedAndGoneDown) |
|
105 LAST_NODEACTIVITY_ENTRY(KErrorTag, MeshMachine::TRaiseAndClearActivityError) |
|
106 NODEACTIVITY_END() |
|
107 } |
|
108 |
|
109 //Activity Map |
|
110 namespace SipCprActivities |
|
111 { |
|
112 DECLARE_DEFINE_ACTIVITY_MAP(activityMap) |
|
113 ACTIVITY_MAP_ENTRY(SipCprProvisionActivity, SipCprProvision) |
|
114 ACTIVITY_MAP_ENTRY(SipCprBinderRequestActivity, SipCprBinderRequest) |
|
115 ACTIVITY_MAP_ENTRY(SipCprStartActivity, SipCprStart) |
|
116 ACTIVITY_MAP_ENTRY(SipCprStopActivity, SipCprStop) |
|
117 |
|
118 ACTIVITY_MAP_END_BASE(CprActivities, coreCprActivities) |
|
119 } |
|
120 |
|
121 |
|
122 //-========================================================= |
|
123 // |
|
124 // CSipConnectionProvider methods |
|
125 // |
|
126 //-========================================================= |
|
127 |
|
128 /** |
|
129 Creates the SIP connection provider |
|
130 */ |
|
131 CSipConnectionProvider* CSipConnectionProvider::NewL(CConnectionProviderFactoryBase& aFactory) |
|
132 { |
|
133 __CFLOG_VAR((KSipCprTag, KSipCprSubTag, _L8("CSipConnectionProvider:\tNewL()"))); |
|
134 CSipConnectionProvider* prov = new (ELeave) CSipConnectionProvider(aFactory); |
|
135 CleanupStack::PushL(prov); |
|
136 prov->ConstructL(); |
|
137 CleanupStack::Pop(prov); |
|
138 return prov; |
|
139 } |
|
140 |
|
141 void CSipConnectionProvider::ConstructL() |
|
142 { |
|
143 CCoreConnectionProvider::ConstructL(); |
|
144 iProvisionInfo = NULL; |
|
145 iTransitionEngine = NULL; |
|
146 iIsIncoming = NULL; |
|
147 } |
|
148 |
|
149 /** |
|
150 Frees the memory for the transition engine |
|
151 */ |
|
152 CSipConnectionProvider::~CSipConnectionProvider() |
|
153 { |
|
154 __CFLOG_VAR((KSipCprTag, KSipCprSubTag, _L8("CSipConnectionProvider:\t ~CSipConnectionProvider()"))); |
|
155 LOG_NODE_DESTROY(KSipCprTag, CSipConnectionProvider); |
|
156 if(iTransitionEngine) |
|
157 iTransitionEngineMgr->Detach(iTransitionEngine); |
|
158 //delete iProvisionInfo; |
|
159 iProvisionInfo = NULL; |
|
160 } |
|
161 |
|
162 CSipConnectionProvider::CSipConnectionProvider(ESock::CConnectionProviderFactoryBase& aFactory) |
|
163 : CCoreConnectionProvider(aFactory, SipCprActivities::activityMap::Self()), |
|
164 iStage(EFresh),iConnStatus(EConnOutgoing) |
|
165 { |
|
166 LOG_NODE_CREATE(KSipCprTag, CSipConnectionProvider); |
|
167 iSelf.Open(NodeId()); |
|
168 } |
|
169 |
|
170 |
|
171 void CSipConnectionProvider::ReceivedL(const TRuntimeCtxId& aSender, const TNodeId& aRecipient, TSignatureBase& aMessage) |
|
172 { |
|
173 TNodeContext<CSipConnectionProvider> ctx(*this, aMessage, aSender, aRecipient); |
|
174 CCoreConnectionProvider::Received(ctx); |
|
175 User::LeaveIfError(ctx.iReturn); |
|
176 } |
|
177 |
|
178 /* |
|
179 Constructs SIP CPR provision and appends it to the access point config |
|
180 */ |
|
181 void CSipConnectionProvider::SetConfigL() |
|
182 { |
|
183 // This function will be called two times while creation of default SCPR |
|
184 // and non-default SCPR. |
|
185 if (iProvisionInfo != NULL) |
|
186 { |
|
187 //delete iProvisionInfo; |
|
188 iProvisionInfo = NULL; |
|
189 } |
|
190 |
|
191 iProvisionInfo = new (ELeave) TSipCprProvisionInfo(); |
|
192 |
|
193 iProvisionInfo->iTransitionEngine = GetTE(); |
|
194 |
|
195 //its safe to get the iFromField only after Registration. |
|
196 //We assume that the since SetConfig is invoked by the Send Provision activity |
|
197 //registration would have already been done |
|
198 |
|
199 if(iFromField == NULL && iTransitionEngine != NULL) |
|
200 { |
|
201 iFromField = const_cast<TDesC8* >(iTransitionEngine->GetFromField(iProfileId)); |
|
202 iProvisionInfo->iFromField = iFromField; |
|
203 } |
|
204 |
|
205 // A local object for RMetaExtensionContainer is created which has it's own base container class |
|
206 // and the extension is appended into the array of this base container class. |
|
207 // At the second time for non- default scpr when this function is called again a new local copy of |
|
208 // RMetaExtensionContainer is created and the previous extension added is not present in the array of this object. |
|
209 // The extension is added in new container class without panicing the code. |
|
210 |
|
211 RMetaExtensionContainer mec; |
|
212 mec.Open(AccessPointConfig()); |
|
213 CleanupClosePushL(mec); |
|
214 mec.AppendExtensionL(iProvisionInfo); |
|
215 AccessPointConfig().Close(); |
|
216 AccessPointConfig().Open(mec); |
|
217 CleanupStack::PopAndDestroy(&mec); |
|
218 |
|
219 } |
|
220 |
|
221 //-========================================================= |
|
222 // MSIPRegistrationClient methods |
|
223 //-========================================================= |
|
224 // Will be called when the registration is successful |
|
225 void CSipConnectionProvider::RegistrationComplete(TInt aError) |
|
226 { |
|
227 __CFLOG_VAR((KSipCprTag, KSipCprSubTag, _L8("CSipConnectionProvider::RegistrationComplete() errorcode=%d"), aError)); |
|
228 ASSERT(iStage == SipCpr::EStarting); |
|
229 |
|
230 // Send the RegistrationComplete message for waiting start activity |
|
231 iSelf.PostMessage(TNodeCtxId(iActivityAwaitingResponse, Id()),TSipCprMessages::TRegistrationComplete(aError).CRef()); |
|
232 iActivityAwaitingResponse = MeshMachine::KActivityNull; |
|
233 } |
|
234 |
|
235 |
|
236 // Will be called when the De-Registration is successful |
|
237 void CSipConnectionProvider::DeRegistrationComplete(TInt aError) |
|
238 { |
|
239 __CFLOG_VAR((KSipCprTag, KSipCprSubTag, _L8("CSipConnectionProvider::DeRegistrationComplete() errorcode=%d"), aError)); |
|
240 ASSERT(iStage == SipCpr::EStopping); |
|
241 iStage = SipCpr::EStopped; |
|
242 |
|
243 // Send the De-RegistrationComplete message for waiting stop activity |
|
244 iSelf.PostMessage(TNodeCtxId(iActivityAwaitingResponse, Id()),TSipCprMessages::TDeRegistrationComplete(aError).CRef()); |
|
245 iActivityAwaitingResponse = MeshMachine::KActivityNull; |
|
246 } |
|
247 |
|
248 |
|
249 // will be called when error occured. The error can occur either in registration or de-registration |
|
250 void CSipConnectionProvider::ErrorOccurred(TInt aError) |
|
251 { |
|
252 __CFLOG_VAR((KSipCprTag, KSipCprSubTag, _L8("CSipConnectionProvider::ErrorOccurred() errorcode=%d"), aError)); |
|
253 |
|
254 if (iActivityAwaitingResponse == ESock::ECFActivityStop) |
|
255 { |
|
256 //Error occured during DeRegistration |
|
257 iSelf.PostMessage(TNodeCtxId(iActivityAwaitingResponse, Id()),TSipCprMessages::TDeRegistrationComplete(aError).CRef()); |
|
258 } |
|
259 else /*if (iActivityAwaitingResponse == ESock::ECFActivityStart)*/ |
|
260 { |
|
261 //Error should have occured during Registration |
|
262 iSelf.PostMessage(TNodeCtxId(iActivityAwaitingResponse, Id()),TSipCprMessages::TRegistrationComplete(aError).CRef()); |
|
263 } |
|
264 } |
|
265 |
|
266 TUint32 CSipConnectionProvider::GetProfileId() |
|
267 { |
|
268 return iProfileId; |
|
269 } |
|
270 TUid CSipConnectionProvider::GetAppUid() |
|
271 { |
|
272 return iAppUid; |
|
273 } |
|
274 CSIPTransitionEngine* CSipConnectionProvider::GetTE() |
|
275 { |
|
276 return iTransitionEngine; |
|
277 } |