author | Sebastian Brannstrom <sebastianb@symbian.org> |
Tue, 16 Nov 2010 10:26:34 +0000 | |
branch | RCL_3 |
changeset 368 | b131f7696342 |
parent 310 | 2e0299e13cbf |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB |
|
3 |
* |
|
4 |
* All rights reserved. |
|
5 |
* This component and the accompanying materials are made available |
|
6 |
* under the terms of the License "Eclipse Public License v1.0" |
|
7 |
* which accompanies this distribution, and is available |
|
8 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 |
* |
|
10 |
* Initial Contributors: |
|
11 |
* EmbedDev AB - initial contribution. |
|
12 |
* |
|
13 |
* Contributors: |
|
14 |
* |
|
15 |
* Description: |
|
16 |
* |
|
17 |
*/ |
|
18 |
||
19 |
#include "connectionengine.h" |
|
20 |
#include "settingsengine.h" |
|
21 |
#include "podcastmodel.h" |
|
22 |
||
23 |
CConnectionEngine* CConnectionEngine::NewL(CPodcastModel& aPodcastModel) |
|
24 |
{ |
|
25 |
CConnectionEngine* self = new (ELeave) CConnectionEngine(aPodcastModel); |
|
26 |
CleanupStack::PushL(self); |
|
27 |
self->ConstructL(); |
|
28 |
CleanupStack::Pop(self); |
|
29 |
return self; |
|
30 |
} |
|
31 |
||
32 |
CConnectionEngine::~CConnectionEngine() |
|
33 |
{ |
|
34 |
delete iMobility; |
|
35 |
||
36 |
Cancel(); |
|
37 |
||
38 |
iConnection.Close(); |
|
39 |
||
40 |
iSocketServer.Close(); |
|
41 |
||
42 |
iObserverArray.Close(); |
|
43 |
} |
|
44 |
||
45 |
CConnectionEngine::CConnectionEngine(CPodcastModel& aPodcastModel): |
|
46 |
CActive(CActive::EPriorityStandard),iPodcastModel(aPodcastModel) |
|
47 |
{ |
|
48 |
CActiveScheduler::Add(this); |
|
49 |
} |
|
50 |
||
51 |
void CConnectionEngine::ConstructL() |
|
52 |
{ |
|
53 |
User::LeaveIfError(iSocketServer.Connect()); |
|
54 |
User::LeaveIfError( iConnection.Open( iSocketServer ) ); |
|
55 |
} |
|
56 |
||
57 |
void CConnectionEngine::RunL() |
|
285
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
58 |
{ |
310
2e0299e13cbf
Probable fix for HTTP ESock issues
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
285
diff
changeset
|
59 |
DP2("CConnectionEngine::RunL BEGIN, iStatus.Int()=%d, iConnectionState=%d", iStatus.Int(), iConnectionState); |
2e0299e13cbf
Probable fix for HTTP ESock issues
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
285
diff
changeset
|
60 |
if ( iStatus.Int() == KErrNone && iMobility == NULL && iConnectionState == EConnected) |
285
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
61 |
{ |
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
62 |
TRAPD(err, iMobility = CActiveCommsMobilityApiExt::NewL( iConnection, *this )); |
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
63 |
|
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
64 |
if (err != KErrNone) |
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
65 |
{ |
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
66 |
DP1("Leave in CActiveCommsMobilityApiExt::NewL, err=%d", err); |
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
67 |
} |
2 | 68 |
} |
69 |
||
70 |
iConnectionState = iStatus.Int() == KErrNone?CConnectionEngine::EConnected:CConnectionEngine::ENotConnected; |
|
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
13
diff
changeset
|
71 |
ReportConnectionL( iStatus.Int() ); |
285
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
72 |
DP("CConnectionEngine::RunL END"); |
2 | 73 |
} |
74 |
||
75 |
void CConnectionEngine::DoCancel() |
|
76 |
{ |
|
77 |
} |
|
78 |
||
79 |
TInt CConnectionEngine::RunError( TInt /*aError*/ ) |
|
80 |
{ |
|
81 |
return KErrNone; |
|
82 |
} |
|
83 |
||
84 |
void CConnectionEngine::PreferredCarrierAvailable( TAccessPointInfo /*aOldAPInfo*/, |
|
85 |
TAccessPointInfo /*aNewAPInfo*/, |
|
86 |
TBool aIsUpgrade, |
|
87 |
TBool aIsSeamless ) |
|
285
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
88 |
{ |
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
89 |
DP("CConnectionEngine::PreferredCarrierAvailable"); |
2 | 90 |
if ( aIsUpgrade ) |
91 |
{ |
|
92 |
} |
|
93 |
else |
|
94 |
{ |
|
95 |
} |
|
96 |
||
97 |
if ( aIsSeamless ) |
|
98 |
{ |
|
99 |
// in S60 3.2, this situation cannot occur. |
|
100 |
} |
|
101 |
else |
|
102 |
{ |
|
103 |
// Sockets have to be closed at this point. |
|
104 |
||
105 |
iMobility->MigrateToPreferredCarrier(); |
|
106 |
} |
|
107 |
||
108 |
} |
|
109 |
||
110 |
void CConnectionEngine::NewCarrierActive( TAccessPointInfo /*aNewAPInfo*/, TBool aIsSeamless ) |
|
111 |
{ |
|
285
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
112 |
DP("CConnectionEngine::NewCarrierActive"); |
2 | 113 |
if ( aIsSeamless ) |
114 |
{ |
|
115 |
// in S60 3.2, this situation cannot occur. |
|
116 |
||
117 |
} |
|
118 |
else |
|
119 |
{ |
|
120 |
// Sockets have to be re-opened and check they can connect |
|
121 |
// to their server at this point. |
|
122 |
||
123 |
iMobility->NewCarrierAccepted(); |
|
124 |
} |
|
125 |
} |
|
126 |
||
127 |
void CConnectionEngine::Error( TInt /*aError*/ ) |
|
128 |
{ |
|
129 |
||
130 |
} |
|
131 |
||
132 |
TBool CConnectionEngine::ConnectionSettingL() |
|
133 |
{ |
|
285
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
134 |
DP("CConnectionEngine::ConnectionSettingL"); |
2 | 135 |
TBool selected( EFalse ); |
136 |
||
137 |
CCmApplicationSettingsUi* settings = CCmApplicationSettingsUi::NewL(); |
|
138 |
CleanupStack::PushL( settings ); |
|
139 |
||
140 |
TUint listedItems = |
|
141 |
CMManager::EShowDefaultConnection | |
|
142 |
CMManager::EShowDestinations; |
|
143 |
||
144 |
TBearerFilterArray filter; |
|
13 | 145 |
ReportConnectionSelectionStart(); |
2 | 146 |
selected = settings->RunApplicationSettingsL( iUserSelection, |
147 |
listedItems, |
|
148 |
filter ); |
|
149 |
||
150 |
CleanupStack::PopAndDestroy( settings ); |
|
13 | 151 |
ReportConnectionSelectionEnd(); |
2 | 152 |
return selected; |
153 |
} |
|
154 |
||
155 |
||
156 |
void CConnectionEngine::StartL(TConnectionType aConnectionType) |
|
157 |
{ |
|
285
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
158 |
DP1("CConnectionEngine::StartL BEGIN, aConnectionType=%d", aConnectionType); |
2 | 159 |
|
160 |
iConnection.Close(); |
|
161 |
User::LeaveIfError( iConnection.Open( iSocketServer ) ); |
|
162 |
// Connect using UI Setting |
|
163 |
if(aConnectionType == EDefaultConnection) |
|
164 |
{ |
|
165 |
iConnection.Start( iStatus ); |
|
166 |
SetActive(); |
|
167 |
} |
|
168 |
else if(aConnectionType == EUserSelectConnection) |
|
169 |
{ |
|
170 |
TBool selected = ConnectionSettingL(); |
|
171 |
||
172 |
if ( selected ) |
|
173 |
{ |
|
174 |
switch ( iUserSelection.iResult ) |
|
175 |
{ |
|
176 |
case CMManager::EDestination: |
|
177 |
{ |
|
178 |
iSnapPreference.SetSnap( iUserSelection.iId ); |
|
179 |
iConnection.Start( iSnapPreference, iStatus ); |
|
180 |
aConnectionType = ESNAPConnection; |
|
181 |
break; |
|
182 |
} |
|
183 |
default: // CMManager::EAlwaysAsk |
|
184 |
case CMManager::EDefaultConnection: |
|
185 |
{ |
|
186 |
iConnection.Start( iStatus ); |
|
187 |
break; |
|
188 |
} |
|
189 |
} |
|
190 |
} |
|
191 |
else |
|
192 |
{ |
|
193 |
TRequestStatus* status = &iStatus; |
|
194 |
User::RequestComplete(status, KErrCancel); |
|
195 |
} |
|
196 |
||
197 |
SetActive(); |
|
198 |
} |
|
199 |
else if (aConnectionType == EIAPConnection) |
|
200 |
{ |
|
201 |
iCommdbPreference.SetIapId((iPodcastModel.SettingsEngine().SpecificIAP()& KUseIAPMask)); |
|
202 |
iCommdbPreference.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); |
|
203 |
iCommdbPreference.SetDirection(ECommDbConnectionDirectionOutgoing); |
|
204 |
iConnection.Start( iCommdbPreference, iStatus ); |
|
205 |
SetActive(); |
|
206 |
} |
|
207 |
// Connect using SNAP |
|
208 |
else |
|
209 |
{ |
|
210 |
iSnapPreference.SetSnap(iPodcastModel.SettingsEngine().SpecificIAP()); |
|
211 |
iConnection.Start( iSnapPreference, iStatus ); |
|
212 |
SetActive(); |
|
213 |
} |
|
214 |
||
215 |
iConnectionType = aConnectionType; |
|
216 |
iConnectionState = CConnectionEngine::EConnecting; |
|
285
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
217 |
DP1("CConnectionEngine::StartL END, iConnectionState=%d", iConnectionState); |
2 | 218 |
} |
219 |
||
163
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
96
diff
changeset
|
220 |
void CConnectionEngine::Stop() |
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
96
diff
changeset
|
221 |
{ |
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
96
diff
changeset
|
222 |
DP("CConnectionEngine::Stop"); |
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
96
diff
changeset
|
223 |
iConnection.Stop(); |
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
96
diff
changeset
|
224 |
iConnectionState = CConnectionEngine::ENotConnected; |
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
96
diff
changeset
|
225 |
} |
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
96
diff
changeset
|
226 |
|
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
96
diff
changeset
|
227 |
|
2 | 228 |
RConnection& CConnectionEngine::Connection() |
229 |
{ |
|
230 |
return iConnection; |
|
231 |
} |
|
232 |
||
233 |
CConnectionEngine::TConnectionState CConnectionEngine::ConnectionState() |
|
234 |
{ |
|
285
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
235 |
DP("CConnectionEngine::ConnectionState BEGIN"); |
2 | 236 |
TInt selectedConn = (TInt) iSnapPreference.Snap(); |
237 |
TInt specIAPSNAP = iPodcastModel.SettingsEngine().SpecificIAP(); |
|
238 |
// If we have IAP preference then get that from our current connection and mask out the selected iap |
|
239 |
if((specIAPSNAP&KUseIAPFlag)) |
|
240 |
{ |
|
241 |
selectedConn = iCommdbPreference.IapId(); |
|
242 |
specIAPSNAP = specIAPSNAP&KUseIAPMask; |
|
243 |
} |
|
244 |
||
245 |
// IAPSNAP must be > 0 and then if the IAP/Sel conn IAP differs |
|
246 |
if(specIAPSNAP >0 && specIAPSNAP != selectedConn ) |
|
247 |
{ |
|
248 |
if(iConnection.SubSessionHandle() != 0) |
|
249 |
{ |
|
250 |
iConnection.Stop(); |
|
251 |
} |
|
252 |
||
253 |
iConnectionState = CConnectionEngine::ENotConnected; |
|
254 |
} |
|
255 |
else |
|
256 |
{ |
|
257 |
// We have a user selection or default selction, check our current connection state. |
|
258 |
TNifProgress progress; |
|
259 |
if(iConnection.Progress(progress) == KErrNone) |
|
260 |
{ |
|
261 |
if(progress.iError == KErrNone && progress.iStage != 0) |
|
262 |
{ |
|
263 |
if(progress.iStage == KLinkLayerOpen) |
|
264 |
{ |
|
265 |
iConnectionState = CConnectionEngine::EConnected; |
|
266 |
} |
|
267 |
} |
|
268 |
else if(iConnectionState != CConnectionEngine::EConnecting) |
|
269 |
{ |
|
270 |
iConnectionState = CConnectionEngine::ENotConnected; |
|
271 |
} |
|
272 |
} |
|
273 |
else |
|
274 |
{ |
|
275 |
iConnectionState = CConnectionEngine::ENotConnected; |
|
276 |
} |
|
277 |
} |
|
278 |
||
285
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
279 |
DP("CConnectionEngine::ConnectionState END"); |
2 | 280 |
return iConnectionState; |
281 |
} |
|
282 |
||
59
9569ea080d5a
Export the proper functions for DLL usage
Lars Persson <lars.persson@embeddev.se>
parents:
13
diff
changeset
|
283 |
EXPORT_C void CConnectionEngine::AddObserver(MConnectionObserver* aObserver) |
2 | 284 |
{ |
285
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
285 |
DP("CConnectionEngine::AddObserver"); |
2 | 286 |
iObserverArray.Append(aObserver); |
287 |
} |
|
288 |
||
285
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
289 |
EXPORT_C void CConnectionEngine::RemoveObserver(MConnectionObserver* aObserver) |
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
290 |
{ |
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
291 |
DP("CConnectionEngine::RemoveObserver"); |
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
292 |
for (int i=0;i<iObserverArray.Count();i++) |
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
293 |
{ |
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
294 |
if (iObserverArray[i] == aObserver) |
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
295 |
{ |
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
296 |
iObserverArray.Remove(i); |
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
297 |
} |
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
298 |
|
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
299 |
} |
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
300 |
} |
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
301 |
|
2 | 302 |
RSocketServ& CConnectionEngine::SockServ() |
303 |
{ |
|
304 |
return iSocketServer; |
|
305 |
} |
|
306 |
||
307 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
13
diff
changeset
|
308 |
void CConnectionEngine::ReportConnectionL(TInt aError) |
2 | 309 |
{ |
285
4d42a5e09930
Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
310 |
DP1("CConnectionEngine::ReportConnectionL, aError=%d", aError); |
2 | 311 |
TInt noObservers = iObserverArray.Count(); |
312 |
while(noObservers) |
|
313 |
{ |
|
314 |
noObservers--; |
|
315 |
iObserverArray[noObservers]->ConnectCompleteL(aError); |
|
316 |
} |
|
317 |
} |
|
13 | 318 |
|
319 |
||
320 |
void CConnectionEngine::ReportConnectionSelectionStart() |
|
321 |
{ |
|
322 |
TInt noObservers = iObserverArray.Count(); |
|
323 |
while(noObservers) |
|
324 |
{ |
|
325 |
noObservers--; |
|
326 |
iObserverArray[noObservers]->ConnectionSelectionStart(); |
|
327 |
} |
|
328 |
} |
|
329 |
||
330 |
||
331 |
void CConnectionEngine::ReportConnectionSelectionEnd() |
|
332 |
{ |
|
333 |
TInt noObservers = iObserverArray.Count(); |
|
334 |
while(noObservers) |
|
335 |
{ |
|
336 |
noObservers--; |
|
337 |
iObserverArray[noObservers]->ConnectionSelectionEnd(); |
|
338 |
} |
|
339 |
} |