|
1 /* |
|
2 * Copyright (c) 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 the License "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: |
|
15 * This file contains the declaration of the Download Mgr Server. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "DownloadMgrLogger.h" |
|
22 #include "DownloadMgrServer.h" |
|
23 #include "DownloadMgrDef.h" |
|
24 |
|
25 #include <HttpClientAppInstance.h> |
|
26 #include <HttpDownload.h> |
|
27 #include <e32svr.h> |
|
28 #include <basched.h> |
|
29 //#include <e32uid.h> |
|
30 |
|
31 // CONSTANTS |
|
32 |
|
33 const TUint KDMgrServerPolicyRangeCount = 3; |
|
34 const TInt KDMgrServerPolicyRanges[KDMgrServerPolicyRangeCount] = |
|
35 { |
|
36 0, // EHttpDownloadMgrInitialize, // = 0 |
|
37 1, // EHttpDownloadMgrCreateDownload, // = 1 |
|
38 /* |
|
39 EHttpDownloadMgrCheckUrl, // = 2 |
|
40 EHttpDownloadMgrAttach, // = 3 |
|
41 EHttpDownloadMgrPauseAll, // = 4 |
|
42 EHttpDownloadMgrStartAllL, // = 5 |
|
43 EHttpDownloadMgrResetAll, // = 6 |
|
44 EHttpDownloadMgrDeleteAll, // = 7 |
|
45 EHttpDownloadMgrDisconnect, // = 8 |
|
46 |
|
47 EHttpDownloadMgrGetIntAttribute, // = 9 |
|
48 EHttpDownloadMgrGetBoolAttribute, // =10 |
|
49 EHttpDownloadMgrGetStringAttribute, // =11 |
|
50 EHttpDownloadMgrGetString8Attribute, // =12 |
|
51 |
|
52 EHttpDownloadMgrSetIntAttribute, // =13 |
|
53 EHttpDownloadMgrSetBoolAttribute, // =14 |
|
54 EHttpDownloadMgrSetStringAttribute, // =15 |
|
55 EHttpDownloadMgrSetString8Attribute, // =16 |
|
56 EHttpDownloadMgrSessionEventSubscription, // =17 |
|
57 EHttpDownloadMgrSessionEventCancel, // =18 |
|
58 |
|
59 EHttpDownloadAttach, // =19 |
|
60 EHttpDownloadStart, // =20 |
|
61 EHttpDownloadPause, // =21 |
|
62 EHttpDownloadReset, // =22 |
|
63 EHttpDownloadDelete, // =23 |
|
64 EHttpDownloadMove, // =24 |
|
65 EHttpDownloadClose, // =25 |
|
66 EHttpDownloadEventSubscription, // =26 |
|
67 EHttpDownloadEventCancel, // =27 |
|
68 |
|
69 EHttpDownloadGetIntAttribute, // =28 |
|
70 EHttpDownloadGetBoolAttribute, // =29 |
|
71 EHttpDownloadGetStringAttribute, // =30 |
|
72 EHttpDownloadGetString8Attribute, // =31 |
|
73 |
|
74 EHttpDownloadSetIntAttribute, // =32 |
|
75 EHttpDownloadSetBoolAttribute, // =33 |
|
76 EHttpDownloadSetStringAttribute, // =34 |
|
77 EHttpDownloadSetString8Attribute, // =35 |
|
78 EHttpDownloadBufferAttributes, // =36 |
|
79 |
|
80 EHttpDownloadGetRFile, // =37 |
|
81 EHttpDownloadSetRFile, // =38 |
|
82 EHttpDownloadSetOnError, // =39 |
|
83 EHttpDownloadAttachToDownload // =40 |
|
84 EHttpDownloadCloseCompleted, // =41 |
|
85 EHttpDownloadDataAttribute, // =42 |
|
86 EHttpDownloadTrackAttribute, // =43 |
|
87 |
|
88 */ |
|
89 44 // EHttpDownloadMgrNotSupported // =44 |
|
90 }; |
|
91 |
|
92 enum TDownloadMgrSecurityPolicy |
|
93 { |
|
94 EDmgrSecurityNetworkServices = 0 |
|
95 }; |
|
96 |
|
97 const CPolicyServer::TPolicyElement dMgrServerPolicyElements[] = |
|
98 { |
|
99 // Check Network Services -> EDmgrSecurityNetworkServices = 0 |
|
100 {_INIT_SECURITY_POLICY_C1(ECapabilityNetworkServices), CPolicyServer::EPanicClient} |
|
101 }; |
|
102 |
|
103 const TUint8 dMgrServerPolicyElementsIndex[] = |
|
104 { |
|
105 EDmgrSecurityNetworkServices, // applies to req 0 |
|
106 CPolicyServer::EAlwaysPass, // applies to req 1 - 39 |
|
107 CPolicyServer::ENotSupported // applies to req 40 - |
|
108 }; |
|
109 |
|
110 const CPolicyServer::TPolicy dMgrServerPolicy = |
|
111 { |
|
112 CPolicyServer::EAlwaysPass, |
|
113 KDMgrServerPolicyRangeCount, |
|
114 KDMgrServerPolicyRanges, |
|
115 dMgrServerPolicyElementsIndex, |
|
116 dMgrServerPolicyElements |
|
117 }; |
|
118 |
|
119 // GLOBAL FUNCTIONS |
|
120 |
|
121 // start the server thread |
|
122 // This is called from the client. |
|
123 EXPORT_C TInt StartDownloadMgrServer( TAny* /*anArg*/ ) |
|
124 { |
|
125 CLOG_CREATE_NULL; |
|
126 CLOG_NAME_NULL( _L("Server") ); |
|
127 CLOG_WRITE_NULL( "StartDownloadMgrServer" ) |
|
128 |
|
129 TBuf<32> name( KDownloadMgrMainThreadName ); |
|
130 |
|
131 RThread().RenameMe( name ); |
|
132 |
|
133 CLOG_WRITE_NULL( "RThread().RenameMe( name );" ); |
|
134 |
|
135 TInt result = KErrNone; |
|
136 |
|
137 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
138 CLOG_WRITE_FORMAT_NULL( "%x = CTrapCleanup::New();", cleanup ); |
|
139 if ( cleanup == NULL ) |
|
140 { |
|
141 result = KErrNoMemory; |
|
142 } |
|
143 else |
|
144 { |
|
145 CActiveScheduler* scheduler = new CActiveScheduler; |
|
146 if ( scheduler == NULL ) |
|
147 { |
|
148 result = KErrNoMemory; |
|
149 } |
|
150 else |
|
151 { |
|
152 CActiveScheduler::Install( scheduler ); |
|
153 |
|
154 CDownloadMgrServer* server = NULL; |
|
155 TRAP( result, server = CDownloadMgrServer::NewL() ); |
|
156 CLOG_WRITE_FORMAT_NULL( "%x = CDownloadMgrServer::NewL();", server ); |
|
157 if ( result == KErrNone ) |
|
158 { |
|
159 CLOG_ATTACH_NULL( NULL, server ); |
|
160 |
|
161 RProcess::Rendezvous( result ); |
|
162 CLOG_WRITE_NULL( "RThread::Rendezvous( result );" ); |
|
163 // It starts an infinite loop from which we can break out |
|
164 // only if we stop the active scheduler |
|
165 CActiveScheduler::Start(); |
|
166 |
|
167 // finished |
|
168 delete server; |
|
169 } |
|
170 else |
|
171 { |
|
172 |
|
173 } |
|
174 delete scheduler; |
|
175 } |
|
176 delete cleanup; |
|
177 } |
|
178 |
|
179 CLOG_WRITE_NULL( "StartDownloadMgrServer" ) |
|
180 CLOG_CLOSE_NULL; |
|
181 |
|
182 return result; |
|
183 } |
|
184 |
|
185 // ================= MEMBER FUNCTIONS ======================= |
|
186 |
|
187 // --------------------------------------------------------- |
|
188 // CDownloadMgrServer::PanicServer |
|
189 // --------------------------------------------------------- |
|
190 // |
|
191 void CDownloadMgrServer::PanicServer( TDownloadMgrSvrPanic aPanic ) |
|
192 { |
|
193 CLOG_ENTERFN_NULL( "CDownloadMgrServer::PanicServer" ) |
|
194 _LIT( KTxtDownloadMgrServer,"CDownloadMgrServer" ); |
|
195 User::Panic( KTxtDownloadMgrServer ,aPanic ); |
|
196 } |
|
197 |
|
198 // --------------------------------------------------------- |
|
199 // CDownloadMgrServer::NewL |
|
200 // --------------------------------------------------------- |
|
201 // |
|
202 CDownloadMgrServer* CDownloadMgrServer::NewL() |
|
203 { |
|
204 CLOG_ENTERFN_NULL( "CDownloadMgrServer::NewL" ) |
|
205 CDownloadMgrServer* self = new (ELeave) CDownloadMgrServer(); |
|
206 CleanupStack::PushL( self ); |
|
207 self->StartL( KDownloadMgrServerName ); |
|
208 CLOG_WRITE_NULL( "self->StartL( KDownloadMgrServerName );" ); |
|
209 self->ConstructL(); |
|
210 CleanupStack::Pop( self ); // self |
|
211 return self; |
|
212 } |
|
213 |
|
214 |
|
215 // --------------------------------------------------------- |
|
216 // CDownloadMgrServer::NewContainerL |
|
217 // --------------------------------------------------------- |
|
218 // |
|
219 CObjectCon* CDownloadMgrServer::NewContainerL() |
|
220 { |
|
221 CLOG_WRITE( "CDownloadMgrServer::NewContainerL" ) |
|
222 return iContainerIndex->CreateL(); |
|
223 } |
|
224 |
|
225 // --------------------------------------------------------- |
|
226 // CDownloadMgrServer::NewContainerL |
|
227 // --------------------------------------------------------- |
|
228 // |
|
229 void CDownloadMgrServer::RemoveContainer( CObjectCon* aCon ) |
|
230 { |
|
231 CLOG_ENTERFN( "CDownloadMgrServer::RemoveContainer" ) |
|
232 iContainerIndex->Remove( aCon ); |
|
233 } |
|
234 |
|
235 // --------------------------------------------------------- |
|
236 // CDownloadMgrServer::CDownloadMgrServer |
|
237 // --------------------------------------------------------- |
|
238 // |
|
239 CDownloadMgrServer::CDownloadMgrServer() |
|
240 : CPolicyServer( EPriorityStandard, dMgrServerPolicy ) |
|
241 , iSessionCount( 0 ) |
|
242 { |
|
243 __DECLARE_NAME( _S( "CDownloadMgrServer" ) ); |
|
244 } |
|
245 |
|
246 |
|
247 // --------------------------------------------------------- |
|
248 // CDownloadMgrServer::ConstructL |
|
249 // --------------------------------------------------------- |
|
250 // |
|
251 void CDownloadMgrServer::ConstructL() |
|
252 { |
|
253 CLOG_ENTERFN( "CDownloadMgrServer::ConstructL" ) |
|
254 iContainerIndex = CObjectConIx::NewL(); |
|
255 iDmEngine = CHttpDownloadManagerServerEngine::NewL(); |
|
256 iShutdown = CDownloadMgrShutdown::NewL( this ); |
|
257 } |
|
258 |
|
259 |
|
260 // --------------------------------------------------------- |
|
261 // CDownloadMgrServer::~CDownloadMgrServer |
|
262 // --------------------------------------------------------- |
|
263 // |
|
264 CDownloadMgrServer::~CDownloadMgrServer() |
|
265 { |
|
266 CLOG_ENTERFN( "CDownloadMgrServer::~CDownloadMgrServer" ) |
|
267 // delete the object container index. |
|
268 delete iContainerIndex; |
|
269 if( iDmEngine ) |
|
270 { |
|
271 delete iDmEngine; |
|
272 iDmEngine = NULL; |
|
273 } |
|
274 delete iShutdown; |
|
275 } |
|
276 |
|
277 |
|
278 // --------------------------------------------------------- |
|
279 // CDownloadMgrServer::NewSessionL |
|
280 // --------------------------------------------------------- |
|
281 // |
|
282 CSession2* CDownloadMgrServer::NewSessionL( const TVersion& aVersion, const RMessage2& /*aMessage*/ ) const |
|
283 { |
|
284 CLOG_ENTERFN( "CDownloadMgrServer::NewSessionL" ) |
|
285 iShutdown->Cancel(); |
|
286 // check version is ok |
|
287 TVersion v( KDownloadMgrMajorVersionNumber, |
|
288 KDownloadMgrMinorVersionNumber, |
|
289 KDownloadMgrBuildVersionNumber ); |
|
290 |
|
291 if( !User::QueryVersionSupported( v, aVersion ) ) |
|
292 { |
|
293 User::Leave( KErrNotSupported ); |
|
294 } |
|
295 |
|
296 // make new session |
|
297 CLOG_WRITE( "__DMGRSRV_IPC_V2__" ); |
|
298 return CDownloadMgrSession::NewL( ( CDownloadMgrServer* )this ); |
|
299 } |
|
300 |
|
301 // --------------------------------------------------------- |
|
302 // CDownloadMgrServer::CreateNewClientAppInstanceL |
|
303 // --------------------------------------------------------- |
|
304 // |
|
305 CHttpClientAppInstance* CDownloadMgrServer::CreateNewClientAppInstanceL( |
|
306 TUint32 aAppUid, |
|
307 MDownloadStateObserver& aObserver, |
|
308 TBool aGetAllPendingDownloads ) |
|
309 { |
|
310 CLOG_WRITE( "CDownloadMgrServer::CreateNewClientAppInstanceL" ) |
|
311 return iDmEngine->CreateNewClientAppInstanceL( |
|
312 aAppUid, &aObserver, aGetAllPendingDownloads ); |
|
313 } |
|
314 |
|
315 // --------------------------------------------------------- |
|
316 // CDownloadMgrServer::CloseClientInstance |
|
317 // --------------------------------------------------------- |
|
318 // |
|
319 void CDownloadMgrServer::CloseClientInstance( CHttpClientAppInstance* aAppInst ) |
|
320 { |
|
321 CLOG_ENTERFN( "CDownloadMgrServer::CloseClientInstance" ) |
|
322 iDmEngine->CloseClientInstance( aAppInst ); |
|
323 } |
|
324 |
|
325 // --------------------------------------------------------- |
|
326 // CDownloadMgrServer::IcrementSessions |
|
327 // --------------------------------------------------------- |
|
328 // |
|
329 void CDownloadMgrServer::IcrementSessions() |
|
330 { |
|
331 CLOG_ENTERFN( "CDownloadMgrServer::IcrementSessions" ) |
|
332 iSessionCount++; |
|
333 iShutdown->Cancel(); |
|
334 } |
|
335 |
|
336 // --------------------------------------------------------- |
|
337 // CDownloadMgrServer::DecrementSessions |
|
338 // --------------------------------------------------------- |
|
339 // |
|
340 void CDownloadMgrServer::DecrementSessions() |
|
341 { |
|
342 CLOG_ENTERFN( "CDownloadMgrServer::DecrementSessions" ) |
|
343 iSessionCount--; |
|
344 if( iSessionCount > 0 ) |
|
345 { |
|
346 return; |
|
347 } |
|
348 iShutdown->Start(); |
|
349 } |
|
350 |
|
351 // --------------------------------------------------------- |
|
352 // CDownloadMgrServer::NextSessionId |
|
353 // --------------------------------------------------------- |
|
354 // |
|
355 TInt CDownloadMgrServer::NextSessionId() |
|
356 { |
|
357 return ++iNextSessionId; |
|
358 } |
|
359 |
|
360 // --------------------------------------------------------- |
|
361 // CDownloadMgrServer::ActiveDownloads |
|
362 // --------------------------------------------------------- |
|
363 // |
|
364 TInt CDownloadMgrServer::ActiveDownloads() const |
|
365 { |
|
366 return iDmEngine->ActiveDownloads(); |
|
367 } |
|
368 |
|
369 // --------------------------------------------------------- |
|
370 // CDownloadMgrShutdown::NewL |
|
371 // --------------------------------------------------------- |
|
372 // |
|
373 CDownloadMgrShutdown* CDownloadMgrShutdown::NewL( CDownloadMgrServer* aServer ) |
|
374 { |
|
375 CLOG_ENTERFN_NULL( "CDownloadMgrShutdown::NewL" ) |
|
376 CDownloadMgrShutdown* self = new (ELeave) CDownloadMgrShutdown( aServer ); |
|
377 CleanupStack::PushL( self ); |
|
378 self->ConstructL(); |
|
379 CleanupStack::Pop( self ); // self |
|
380 return self; |
|
381 } |
|
382 |
|
383 // --------------------------------------------------------- |
|
384 // CDownloadMgrShutdown::CDownloadMgrShutdown |
|
385 // --------------------------------------------------------- |
|
386 // |
|
387 CDownloadMgrShutdown::CDownloadMgrShutdown( CDownloadMgrServer* aServer ) |
|
388 :CActive( EPriorityStandard ) |
|
389 { |
|
390 iServer = aServer; |
|
391 } |
|
392 |
|
393 // --------------------------------------------------------- |
|
394 // CDownloadMgrShutdown::~CDownloadMgrShutdown |
|
395 // --------------------------------------------------------- |
|
396 // |
|
397 CDownloadMgrShutdown::~CDownloadMgrShutdown() |
|
398 { |
|
399 CLOG_ENTERFN( "CDownloadMgrShutdown::~CDownloadMgrShutdown" ) |
|
400 Cancel(); |
|
401 iTimer.Close(); |
|
402 } |
|
403 |
|
404 // --------------------------------------------------------- |
|
405 // CDownloadMgrShutdown::ConstructL |
|
406 // --------------------------------------------------------- |
|
407 // |
|
408 void CDownloadMgrShutdown::ConstructL() |
|
409 { |
|
410 CLOG_ENTERFN( "CDownloadMgrShutdown::ConstructL" ) |
|
411 User::LeaveIfError( iTimer.CreateLocal() ); |
|
412 CActiveScheduler::Add( this ); |
|
413 } |
|
414 |
|
415 // --------------------------------------------------------- |
|
416 // CDownloadMgrShutdown::Start |
|
417 // --------------------------------------------------------- |
|
418 // |
|
419 void CDownloadMgrShutdown::Start() |
|
420 { |
|
421 CLOG_ENTERFN( "CDownloadMgrShutdown::Start" ) |
|
422 if( !IsActive() ) |
|
423 { |
|
424 iTimer.After( iStatus, KDownloadMgrShutdownInterval ); |
|
425 SetActive(); |
|
426 } |
|
427 } |
|
428 |
|
429 // --------------------------------------------------------- |
|
430 // CDownloadMgrShutdown::DoCancel |
|
431 // --------------------------------------------------------- |
|
432 // |
|
433 void CDownloadMgrShutdown::DoCancel() |
|
434 { |
|
435 CLOG_ENTERFN( "CDownloadMgrShutdown::DoCancel" ) |
|
436 iTimer.Cancel(); |
|
437 } |
|
438 |
|
439 // --------------------------------------------------------- |
|
440 // CDownloadMgrShutdown::RunL |
|
441 // --------------------------------------------------------- |
|
442 // |
|
443 void CDownloadMgrShutdown::RunL() |
|
444 { |
|
445 CLOG_ENTERFN( "CDownloadMgrShutdown::RunL" ) |
|
446 if( !iServer->ActiveDownloads() ) |
|
447 { |
|
448 CActiveScheduler::Stop(); |
|
449 } |
|
450 else |
|
451 { |
|
452 Start(); |
|
453 } |
|
454 } |