author | Sebastian Brannstrom <sebastianb@symbian.org> |
Wed, 28 Jul 2010 14:18:09 +0100 | |
branch | RCL_3 |
changeset 248 | 31659d49b2e7 |
parent 163 | f94dbd678dda |
child 285 | 4d42a5e09930 |
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() |
|
58 |
{ |
|
59 |
if ( iStatus.Int() == KErrNone ) |
|
60 |
{ |
|
61 |
delete iMobility; |
|
62 |
iMobility = NULL; |
|
63 |
iMobility = CActiveCommsMobilityApiExt::NewL( iConnection, *this ); |
|
64 |
} |
|
65 |
||
66 |
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
|
67 |
ReportConnectionL( iStatus.Int() ); |
2 | 68 |
} |
69 |
||
70 |
void CConnectionEngine::DoCancel() |
|
71 |
{ |
|
72 |
} |
|
73 |
||
74 |
TInt CConnectionEngine::RunError( TInt /*aError*/ ) |
|
75 |
{ |
|
76 |
return KErrNone; |
|
77 |
} |
|
78 |
||
79 |
void CConnectionEngine::PreferredCarrierAvailable( TAccessPointInfo /*aOldAPInfo*/, |
|
80 |
TAccessPointInfo /*aNewAPInfo*/, |
|
81 |
TBool aIsUpgrade, |
|
82 |
TBool aIsSeamless ) |
|
83 |
{ |
|
84 |
if ( aIsUpgrade ) |
|
85 |
{ |
|
86 |
} |
|
87 |
else |
|
88 |
{ |
|
89 |
} |
|
90 |
||
91 |
if ( aIsSeamless ) |
|
92 |
{ |
|
93 |
// in S60 3.2, this situation cannot occur. |
|
94 |
} |
|
95 |
else |
|
96 |
{ |
|
97 |
// Sockets have to be closed at this point. |
|
98 |
||
99 |
iMobility->MigrateToPreferredCarrier(); |
|
100 |
} |
|
101 |
||
102 |
} |
|
103 |
||
104 |
void CConnectionEngine::NewCarrierActive( TAccessPointInfo /*aNewAPInfo*/, TBool aIsSeamless ) |
|
105 |
{ |
|
106 |
if ( aIsSeamless ) |
|
107 |
{ |
|
108 |
// in S60 3.2, this situation cannot occur. |
|
109 |
||
110 |
} |
|
111 |
else |
|
112 |
{ |
|
113 |
// Sockets have to be re-opened and check they can connect |
|
114 |
// to their server at this point. |
|
115 |
||
116 |
iMobility->NewCarrierAccepted(); |
|
117 |
} |
|
118 |
} |
|
119 |
||
120 |
void CConnectionEngine::Error( TInt /*aError*/ ) |
|
121 |
{ |
|
122 |
||
123 |
} |
|
124 |
||
125 |
TBool CConnectionEngine::ConnectionSettingL() |
|
126 |
{ |
|
127 |
TBool selected( EFalse ); |
|
128 |
||
129 |
CCmApplicationSettingsUi* settings = CCmApplicationSettingsUi::NewL(); |
|
130 |
CleanupStack::PushL( settings ); |
|
131 |
||
132 |
TUint listedItems = |
|
133 |
CMManager::EShowDefaultConnection | |
|
134 |
CMManager::EShowDestinations; |
|
135 |
||
136 |
TBearerFilterArray filter; |
|
13 | 137 |
ReportConnectionSelectionStart(); |
2 | 138 |
selected = settings->RunApplicationSettingsL( iUserSelection, |
139 |
listedItems, |
|
140 |
filter ); |
|
141 |
||
142 |
CleanupStack::PopAndDestroy( settings ); |
|
13 | 143 |
ReportConnectionSelectionEnd(); |
2 | 144 |
return selected; |
145 |
} |
|
146 |
||
147 |
||
148 |
void CConnectionEngine::StartL(TConnectionType aConnectionType) |
|
149 |
{ |
|
150 |
DP1("CConnectionEngine::StartL, aConnectionType=%d", aConnectionType); |
|
151 |
||
152 |
iConnection.Close(); |
|
153 |
User::LeaveIfError( iConnection.Open( iSocketServer ) ); |
|
154 |
// Connect using UI Setting |
|
155 |
if(aConnectionType == EDefaultConnection) |
|
156 |
{ |
|
157 |
iConnection.Start( iStatus ); |
|
158 |
SetActive(); |
|
159 |
} |
|
160 |
else if(aConnectionType == EUserSelectConnection) |
|
161 |
{ |
|
162 |
TBool selected = ConnectionSettingL(); |
|
163 |
||
164 |
if ( selected ) |
|
165 |
{ |
|
166 |
switch ( iUserSelection.iResult ) |
|
167 |
{ |
|
168 |
case CMManager::EDestination: |
|
169 |
{ |
|
170 |
iSnapPreference.SetSnap( iUserSelection.iId ); |
|
171 |
iConnection.Start( iSnapPreference, iStatus ); |
|
172 |
aConnectionType = ESNAPConnection; |
|
173 |
break; |
|
174 |
} |
|
175 |
default: // CMManager::EAlwaysAsk |
|
176 |
case CMManager::EDefaultConnection: |
|
177 |
{ |
|
178 |
iConnection.Start( iStatus ); |
|
179 |
break; |
|
180 |
} |
|
181 |
} |
|
182 |
} |
|
183 |
else |
|
184 |
{ |
|
185 |
TRequestStatus* status = &iStatus; |
|
186 |
User::RequestComplete(status, KErrCancel); |
|
187 |
} |
|
188 |
||
189 |
SetActive(); |
|
190 |
} |
|
191 |
else if (aConnectionType == EIAPConnection) |
|
192 |
{ |
|
193 |
iCommdbPreference.SetIapId((iPodcastModel.SettingsEngine().SpecificIAP()& KUseIAPMask)); |
|
194 |
iCommdbPreference.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); |
|
195 |
iCommdbPreference.SetDirection(ECommDbConnectionDirectionOutgoing); |
|
196 |
iConnection.Start( iCommdbPreference, iStatus ); |
|
197 |
SetActive(); |
|
198 |
} |
|
199 |
// Connect using SNAP |
|
200 |
else |
|
201 |
{ |
|
202 |
iSnapPreference.SetSnap(iPodcastModel.SettingsEngine().SpecificIAP()); |
|
203 |
iConnection.Start( iSnapPreference, iStatus ); |
|
204 |
SetActive(); |
|
205 |
} |
|
206 |
||
207 |
iConnectionType = aConnectionType; |
|
208 |
iConnectionState = CConnectionEngine::EConnecting; |
|
209 |
} |
|
210 |
||
163
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
96
diff
changeset
|
211 |
void CConnectionEngine::Stop() |
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
96
diff
changeset
|
212 |
{ |
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
96
diff
changeset
|
213 |
DP("CConnectionEngine::Stop"); |
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
96
diff
changeset
|
214 |
iConnection.Stop(); |
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
96
diff
changeset
|
215 |
iConnectionState = CConnectionEngine::ENotConnected; |
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
96
diff
changeset
|
216 |
} |
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
96
diff
changeset
|
217 |
|
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
96
diff
changeset
|
218 |
|
2 | 219 |
RConnection& CConnectionEngine::Connection() |
220 |
{ |
|
221 |
return iConnection; |
|
222 |
} |
|
223 |
||
224 |
CConnectionEngine::TConnectionState CConnectionEngine::ConnectionState() |
|
225 |
{ |
|
226 |
TInt selectedConn = (TInt) iSnapPreference.Snap(); |
|
227 |
TInt specIAPSNAP = iPodcastModel.SettingsEngine().SpecificIAP(); |
|
228 |
// If we have IAP preference then get that from our current connection and mask out the selected iap |
|
229 |
if((specIAPSNAP&KUseIAPFlag)) |
|
230 |
{ |
|
231 |
selectedConn = iCommdbPreference.IapId(); |
|
232 |
specIAPSNAP = specIAPSNAP&KUseIAPMask; |
|
233 |
} |
|
234 |
||
235 |
// IAPSNAP must be > 0 and then if the IAP/Sel conn IAP differs |
|
236 |
if(specIAPSNAP >0 && specIAPSNAP != selectedConn ) |
|
237 |
{ |
|
238 |
if(iConnection.SubSessionHandle() != 0) |
|
239 |
{ |
|
240 |
iConnection.Stop(); |
|
241 |
} |
|
242 |
||
243 |
iConnectionState = CConnectionEngine::ENotConnected; |
|
244 |
} |
|
245 |
else |
|
246 |
{ |
|
247 |
// We have a user selection or default selction, check our current connection state. |
|
248 |
TNifProgress progress; |
|
249 |
if(iConnection.Progress(progress) == KErrNone) |
|
250 |
{ |
|
251 |
if(progress.iError == KErrNone && progress.iStage != 0) |
|
252 |
{ |
|
253 |
if(progress.iStage == KLinkLayerOpen) |
|
254 |
{ |
|
255 |
iConnectionState = CConnectionEngine::EConnected; |
|
256 |
} |
|
257 |
} |
|
258 |
else if(iConnectionState != CConnectionEngine::EConnecting) |
|
259 |
{ |
|
260 |
iConnectionState = CConnectionEngine::ENotConnected; |
|
261 |
} |
|
262 |
} |
|
263 |
else |
|
264 |
{ |
|
265 |
iConnectionState = CConnectionEngine::ENotConnected; |
|
266 |
} |
|
267 |
} |
|
268 |
||
269 |
return iConnectionState; |
|
270 |
} |
|
271 |
||
59
9569ea080d5a
Export the proper functions for DLL usage
Lars Persson <lars.persson@embeddev.se>
parents:
13
diff
changeset
|
272 |
EXPORT_C void CConnectionEngine::AddObserver(MConnectionObserver* aObserver) |
2 | 273 |
{ |
274 |
iObserverArray.Append(aObserver); |
|
275 |
} |
|
276 |
||
277 |
RSocketServ& CConnectionEngine::SockServ() |
|
278 |
{ |
|
279 |
return iSocketServer; |
|
280 |
} |
|
281 |
||
282 |
||
35
66c5303f3610
A ton of CodeScanner fixes (high issues) - but not all
Brendan Donegan <brendand@symbian.org>
parents:
13
diff
changeset
|
283 |
void CConnectionEngine::ReportConnectionL(TInt aError) |
2 | 284 |
{ |
285 |
TInt noObservers = iObserverArray.Count(); |
|
286 |
while(noObservers) |
|
287 |
{ |
|
288 |
noObservers--; |
|
289 |
iObserverArray[noObservers]->ConnectCompleteL(aError); |
|
290 |
} |
|
291 |
} |
|
13 | 292 |
|
293 |
||
294 |
void CConnectionEngine::ReportConnectionSelectionStart() |
|
295 |
{ |
|
296 |
TInt noObservers = iObserverArray.Count(); |
|
297 |
while(noObservers) |
|
298 |
{ |
|
299 |
noObservers--; |
|
300 |
iObserverArray[noObservers]->ConnectionSelectionStart(); |
|
301 |
} |
|
302 |
} |
|
303 |
||
304 |
||
305 |
void CConnectionEngine::ReportConnectionSelectionEnd() |
|
306 |
{ |
|
307 |
TInt noObservers = iObserverArray.Count(); |
|
308 |
while(noObservers) |
|
309 |
{ |
|
310 |
noObservers--; |
|
311 |
iObserverArray[noObservers]->ConnectionSelectionEnd(); |
|
312 |
} |
|
313 |
} |