1 /* |
|
2 * Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "DrmUdtConn.h" |
|
22 #include "DrmUdtObserver.h" |
|
23 |
|
24 #include <CommDbConnPref.h> |
|
25 #include <commdb.h> |
|
26 #include <cdblen.h> |
|
27 #include <es_enum.h> |
|
28 |
|
29 // #include <ApSelect.h> // for checking APs |
|
30 |
|
31 #ifdef _DEBUG |
|
32 #define LOGGING |
|
33 #endif |
|
34 |
|
35 #define LOGGING |
|
36 |
|
37 #ifdef LOGGING |
|
38 _LIT(KLogDir, "DRM"); |
|
39 _LIT(KLogName, "UDT.log"); |
|
40 #include "flogger.h" |
|
41 #define LOG(string) \ |
|
42 RFileLogger::Write(KLogDir, KLogName, \ |
|
43 EFileLoggingModeAppend, string); |
|
44 #define LOGHEX(buffer) \ |
|
45 RFileLogger::HexDump(KLogDir, KLogName, \ |
|
46 EFileLoggingModeAppend, _S(""), _S(""), \ |
|
47 buffer.Ptr(), buffer.Length()); |
|
48 #else |
|
49 #define LOG |
|
50 #define LOGHEX |
|
51 #endif |
|
52 |
|
53 // ================= MEMBER FUNCTIONS ======================= |
|
54 |
|
55 // --------------------------------------------------------- |
|
56 // CDrmUdtConn::NewL() |
|
57 // --------------------------------------------------------- |
|
58 // |
|
59 CDrmUdtConn* CDrmUdtConn::NewL() |
|
60 { |
|
61 LOG( _L("CDrmUdtConn::NewL") ); |
|
62 CDrmUdtConn* conn = new (ELeave) CDrmUdtConn(); |
|
63 CleanupStack::PushL( conn ); |
|
64 conn->ConstructL(); |
|
65 CleanupStack::Pop( conn ); |
|
66 return conn; |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------- |
|
70 // CDrmUdtConn::~CDrmUdtConn() |
|
71 // --------------------------------------------------------- |
|
72 // |
|
73 CDrmUdtConn::~CDrmUdtConn() |
|
74 { |
|
75 LOG( _L("CDrmUdtConn::~CDrmUdtConn") ); |
|
76 Cancel(); |
|
77 iConnection.Close(); |
|
78 iSocketServ.Close(); |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------- |
|
82 // CDrmUdtConn::ConnectL() |
|
83 // --------------------------------------------------------- |
|
84 // |
|
85 void CDrmUdtConn::ConnectL( TUint32 aIap, |
|
86 MDrmUdtObserver* aObserver, |
|
87 TRequestStatus* aStatus ) |
|
88 { |
|
89 LOG( _L("CDrmUdtConn::ConnectL") ); |
|
90 |
|
91 iObserver = aObserver; |
|
92 |
|
93 if ( iState == EInit ) |
|
94 { |
|
95 // Not connected. Attach to existing connection, or create new one if |
|
96 // allowed. |
|
97 iStatus = KErrGeneral; |
|
98 |
|
99 // Make this part atomic by pushing closes on the stack. |
|
100 User::LeaveIfError( iSocketServ.Connect() ); |
|
101 CleanupClosePushL<RSocketServ>( iSocketServ ); |
|
102 User::LeaveIfError( iConnection.Open( iSocketServ ) ); |
|
103 CleanupClosePushL<RConnection>( iConnection ); |
|
104 |
|
105 TConnectionInfoBuf connInfo; |
|
106 TUint count; |
|
107 User::LeaveIfError( iConnection.EnumerateConnections( count ) ); |
|
108 TUint i; |
|
109 if ( count ) |
|
110 { |
|
111 // Select from existing connections. Try to make AP match. |
|
112 for ( i = count; i; i-- ) |
|
113 { |
|
114 // Note: GetConnectionInfo expects 1-based index. |
|
115 User::LeaveIfError( iConnection.GetConnectionInfo( i, connInfo ) ); |
|
116 if ( aIap == 0 || connInfo().iIapId == aIap ) |
|
117 { |
|
118 // "Accept any" or AP match. Attach to this one. |
|
119 break; |
|
120 } |
|
121 } |
|
122 if ( !i ) |
|
123 { |
|
124 // No AP match, select AP with largest index. |
|
125 User::LeaveIfError |
|
126 ( iConnection.GetConnectionInfo( count, connInfo ) ); |
|
127 } |
|
128 User::LeaveIfError |
|
129 ( iConnection.Attach( connInfo, RConnection::EAttachTypeNormal ) ); |
|
130 iState = EConnected; |
|
131 iStatus = KErrNone; |
|
132 } |
|
133 else |
|
134 { |
|
135 // No existing connections, create new one. |
|
136 #ifdef __WINS__ |
|
137 // WINS connection creation does not work if preferences are given. |
|
138 // Defaults are to be used always. |
|
139 iConnection.Start( iStatus ); |
|
140 #else |
|
141 // Note: the TCommDbConnPref must NOT be stack variable. |
|
142 // It must persist until completion of RConnection::Start(). |
|
143 iConnPref.SetDirection( ECommDbConnectionDirectionOutgoing ); |
|
144 iConnPref.SetDialogPreference( ECommDbDialogPrefPrompt ); |
|
145 iConnPref.SetBearerSet( ECommDbBearerCSD | ECommDbBearerWcdma ); |
|
146 // New connection is always created with user-selected AP; |
|
147 // so 0 is used instead of aIap. |
|
148 iConnPref.SetIapId( 0 ); |
|
149 iConnection.Start( iConnPref, iStatus ); |
|
150 #endif |
|
151 if ( iObserver ) |
|
152 { |
|
153 iObserver->ConnectionStartedL(); |
|
154 } |
|
155 |
|
156 iState = EConnecting; |
|
157 SetActive(); // The only path with a real async request. |
|
158 } |
|
159 CleanupStack::Pop( 2 ); // closing iConn and iSockServ |
|
160 // End of atomic part. |
|
161 } |
|
162 else |
|
163 { |
|
164 // Not expecting this to be called in other states. |
|
165 } |
|
166 |
|
167 iParentStatus = aStatus; |
|
168 *iParentStatus = KRequestPending; |
|
169 |
|
170 if ( !IsActive() ) |
|
171 { |
|
172 // Unless we have an outstanding connect request (iConn.Start), |
|
173 // we are done. |
|
174 User::RequestComplete( iParentStatus, iStatus.Int() ); |
|
175 iParentStatus = NULL; |
|
176 } |
|
177 } |
|
178 |
|
179 // --------------------------------------------------------- |
|
180 // CDrmUdtConn::Close() |
|
181 // --------------------------------------------------------- |
|
182 // |
|
183 void CDrmUdtConn::Close() |
|
184 { |
|
185 LOG( _L("CDrmUdtConn::Close") ); |
|
186 Cancel(); |
|
187 iConnection.Close(); |
|
188 iSocketServ.Close(); |
|
189 iState = EInit; |
|
190 } |
|
191 |
|
192 // --------------------------------------------------------- |
|
193 // CDrmUdtConn::IsConnected() |
|
194 // --------------------------------------------------------- |
|
195 // |
|
196 TBool CDrmUdtConn::IsConnected( TUint32& aIap ) |
|
197 { |
|
198 LOG( _L("CDrmUdtConn::IsConnected") ); |
|
199 TBool connected( EFalse ); |
|
200 if( iState == EConnected ) |
|
201 { |
|
202 TBuf<KCommsDbSvrMaxColumnNameLength * 2 + 1> iapId; |
|
203 _LIT( KFormatIapId, "%S\\%S" ); |
|
204 TPtrC iap( IAP ); |
|
205 TPtrC id( COMMDB_ID ); |
|
206 iapId.Format( KFormatIapId, &iap, &id ); |
|
207 TInt err = iConnection.GetIntSetting( iapId, aIap ); |
|
208 connected = err ? EFalse : ETrue; |
|
209 } |
|
210 return connected; |
|
211 } |
|
212 |
|
213 // --------------------------------------------------------- |
|
214 // CDrmUdtConn::CConnection() |
|
215 // --------------------------------------------------------- |
|
216 // |
|
217 CDrmUdtConn::CDrmUdtConn() |
|
218 : CActive( CActive::EPriorityStandard ), |
|
219 iState( EInit ) |
|
220 { |
|
221 LOG( _L("CDrmUdtConn::CDrmUdtConn") ); |
|
222 CActiveScheduler::Add( this ); |
|
223 } |
|
224 |
|
225 // --------------------------------------------------------- |
|
226 // CDrmUdtConn::ConstructL() |
|
227 // --------------------------------------------------------- |
|
228 // |
|
229 void CDrmUdtConn::ConstructL() |
|
230 { |
|
231 LOG( _L("CDrmUdtConn::ConstructL") ); |
|
232 /* |
|
233 TUint32 APs( 0 ); |
|
234 CCommsDatabase* commsdb = CCommsDatabase::NewL( EDatabaseTypeIAP ); |
|
235 CleanupStack::PushL( commsdb ); |
|
236 CApSelect* apSel = CApSelect::NewLC ( |
|
237 *commsdb, |
|
238 KEApIspTypeAll, |
|
239 EApBearerTypeAll, |
|
240 KEApSortUidAscending ); |
|
241 APs = apSel->Count(); |
|
242 CleanupStack::PopAndDestroy( 2 ); |
|
243 if ( !APs ) |
|
244 { |
|
245 // No AP defined |
|
246 User::Leave( KErrRoapGeneral ); |
|
247 } |
|
248 */ |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------- |
|
252 // CDrmUdtConn::DoCancel() |
|
253 // --------------------------------------------------------- |
|
254 // |
|
255 void CDrmUdtConn::DoCancel() |
|
256 { |
|
257 LOG( _L("CDrmUdtConn::DoCancel") ); |
|
258 iConnection.Close(); |
|
259 iSocketServ.Close(); |
|
260 User::RequestComplete( iParentStatus, KErrCancel ); |
|
261 } |
|
262 |
|
263 // --------------------------------------------------------- |
|
264 // CDrmUdtConn::RunL() |
|
265 // --------------------------------------------------------- |
|
266 // |
|
267 void CDrmUdtConn::RunL() |
|
268 { |
|
269 LOG( _L("CDrmUdtConn::RunL") ); |
|
270 User::LeaveIfError( iStatus.Int() ); // Handle errors in RunError(). |
|
271 |
|
272 iState = EConnected; |
|
273 User::RequestComplete( iParentStatus, iStatus.Int() ); |
|
274 iParentStatus = NULL; |
|
275 } |
|
276 |
|
277 // --------------------------------------------------------- |
|
278 // CDrmUdtConn::RunError() |
|
279 // --------------------------------------------------------- |
|
280 // |
|
281 TInt CDrmUdtConn::RunError( TInt /*aError*/ ) |
|
282 { |
|
283 LOG( _L("CDrmUdtConn::RunError") ); |
|
284 iConnection.Close(); |
|
285 iSocketServ.Close(); |
|
286 iState = EInit; |
|
287 User::RequestComplete( iParentStatus, iStatus.Int() ); |
|
288 iParentStatus = NULL; |
|
289 return KErrNone; |
|
290 } |
|
291 |
|
292 // --------------------------------------------------------- |
|
293 // CRoapConnection::Conn() |
|
294 // --------------------------------------------------------- |
|
295 // |
|
296 RSocketServ& CDrmUdtConn::SocketServ() |
|
297 { |
|
298 LOG( _L("CDrmUdtConn::SocketServ") ); |
|
299 return iSocketServ; |
|
300 } |
|
301 |
|
302 // --------------------------------------------------------- |
|
303 // CRoapConnection::Conn() |
|
304 // --------------------------------------------------------- |
|
305 // |
|
306 RConnection& CDrmUdtConn::Conn() |
|
307 { |
|
308 LOG( _L("CDrmUdtConn::Conn") ); |
|
309 return iConnection; |
|
310 } |
|
311 |
|