|
1 /* |
|
2 * Copyright (c) 2006-2007 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: CUpnpContentServer class implamentation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include <e32debug.h> |
|
23 #include <w32std.h> |
|
24 |
|
25 #include "upnpcontentserver.h" |
|
26 #include "upnpcontentserversession.h" |
|
27 #include "upnpcontentserverdefs.h" |
|
28 #include "upnpcontentserverhandler.h" |
|
29 #include "upnpperiodic.h" |
|
30 |
|
31 _LIT( KComponentLogfile, "contentserver.txt"); |
|
32 #include "upnplog.h" |
|
33 |
|
34 // CONSTANTS |
|
35 _LIT( KUpnpContentServerString, "Upnp content server"); |
|
36 |
|
37 using namespace UpnpContentServer; |
|
38 |
|
39 // -------------------------------------------------------------------------- |
|
40 // Server's policy |
|
41 // -------------------------------------------------------------------------- |
|
42 |
|
43 //Total number of ranges |
|
44 static const TUint KContentServerRangeCount = 1; |
|
45 |
|
46 //Definition of the ranges of IPC numbers |
|
47 static const TInt contentServerRanges[KContentServerRangeCount] = |
|
48 { |
|
49 0 |
|
50 }; |
|
51 |
|
52 //Policy to implement for each of the above ranges |
|
53 static const TUint8 contentServerElementsIndex[KContentServerRangeCount] = |
|
54 { |
|
55 0, //applies to 0th range |
|
56 }; |
|
57 |
|
58 //Specific capability checks |
|
59 static const CPolicyServer::TPolicyElement contentServerElements[] = |
|
60 { |
|
61 {_INIT_SECURITY_POLICY_C3(ECapabilityReadUserData, |
|
62 ECapabilityWriteUserData, |
|
63 ECapabilityNetworkServices), |
|
64 CPolicyServer::EFailClient} |
|
65 //policy "0", |
|
66 //fail call if all capabilities not present |
|
67 }; |
|
68 |
|
69 //Package all the above together into a policy |
|
70 static const CPolicyServer::TPolicy KUpnpContentServerPolicy = |
|
71 { |
|
72 CPolicyServer::EAlwaysPass, //all connect attempts should pass |
|
73 KContentServerRangeCount, |
|
74 contentServerRanges, |
|
75 contentServerElementsIndex, |
|
76 contentServerElements |
|
77 }; |
|
78 |
|
79 // -------------------------------------------------------------------------- |
|
80 // E32Main |
|
81 // main function called by E32 |
|
82 // -------------------------------------------------------------------------- |
|
83 // |
|
84 GLDEF_C TInt E32Main() |
|
85 { |
|
86 TRAPD( ret, CUpnpContentServer::LaunchServerL() ); |
|
87 return ret; |
|
88 } |
|
89 |
|
90 // -------------------------------------------------------------------------- |
|
91 // CUpnpContentServer::LaunchServer |
|
92 // Initializes the process and creates an instance of CUpnpContentServer. |
|
93 // -------------------------------------------------------------------------- |
|
94 // |
|
95 TInt CUpnpContentServer::LaunchServerL() |
|
96 { |
|
97 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
98 // Check server not already started |
|
99 TFindServer findHostServer( KUpnpContentServer ); |
|
100 |
|
101 TInt err( KErrNone ); |
|
102 TFullName name; |
|
103 if ( findHostServer.Next(name) == KErrNone ) |
|
104 { // found server already |
|
105 __LOG1( "Error: %d", __LINE__ ); |
|
106 err = KErrGeneral; |
|
107 } |
|
108 if ( !err ) |
|
109 { |
|
110 User::RenameThread( KUpnpContentServer ); |
|
111 |
|
112 // Create cleanup stack. |
|
113 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
114 |
|
115 // Construct and install active scheduler. |
|
116 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
117 CActiveScheduler::Install( scheduler ); |
|
118 |
|
119 // Construct server. |
|
120 CUpnpContentServer* server = NULL; |
|
121 TRAPD( err, server = CUpnpContentServer::NewL() ); |
|
122 if ( err ) |
|
123 { |
|
124 __LOG1( "Error: %d", err ); |
|
125 } |
|
126 RProcess::Rendezvous( err ); |
|
127 |
|
128 __LOG("CUpnpContentServer::LaunchServer, Start CActiveScheduler"); |
|
129 // Start handling requests. |
|
130 CActiveScheduler::Start(); |
|
131 |
|
132 delete server; |
|
133 __LOG("CUpnpContentServer::LaunchServer, Server deleted."); |
|
134 delete scheduler; |
|
135 delete cleanup; |
|
136 } |
|
137 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
138 return err; |
|
139 } |
|
140 |
|
141 // -------------------------------------------------------------------------- |
|
142 // CUpnpContentServer::NewL |
|
143 // 2-phased constructor. |
|
144 // -------------------------------------------------------------------------- |
|
145 // |
|
146 CUpnpContentServer* CUpnpContentServer::NewL() |
|
147 { |
|
148 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
149 CUpnpContentServer* self = new (ELeave) CUpnpContentServer(); |
|
150 CleanupStack::PushL(self); |
|
151 self->ConstructL(); |
|
152 self->StartL( KUpnpContentServer ); |
|
153 CleanupStack::Pop(); // self |
|
154 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
155 return self; |
|
156 } |
|
157 |
|
158 // -------------------------------------------------------------------------- |
|
159 // CUpnpContentServer::CUpnpContentServer() |
|
160 // C++ constructor. |
|
161 // -------------------------------------------------------------------------- |
|
162 // |
|
163 CUpnpContentServer::CUpnpContentServer() |
|
164 : CPolicyServer( EPriorityStandard, KUpnpContentServerPolicy, |
|
165 ESharableSessions ) |
|
166 { |
|
167 } |
|
168 |
|
169 // -------------------------------------------------------------------------- |
|
170 // CUpnpContentServer::ConstructL |
|
171 // 2nd phase constructor. |
|
172 // -------------------------------------------------------------------------- |
|
173 // |
|
174 void CUpnpContentServer::ConstructL() |
|
175 { |
|
176 iHandler = CUpnpContentServerHandler::NewL( this ); |
|
177 } |
|
178 |
|
179 // -------------------------------------------------------------------------- |
|
180 // CUpnpContentServer::~CUpnpContentServer() |
|
181 // C++ destructor. |
|
182 // -------------------------------------------------------------------------- |
|
183 // |
|
184 CUpnpContentServer::~CUpnpContentServer() |
|
185 { |
|
186 delete iHandler; |
|
187 delete iContainerIndex; |
|
188 delete iConMon; |
|
189 delete iIdle; |
|
190 } |
|
191 |
|
192 // -------------------------------------------------------------------------- |
|
193 // CUpnpContentServer::Handler |
|
194 // Returns pointer to CUpnpContentServerHandler |
|
195 // -------------------------------------------------------------------------- |
|
196 // |
|
197 CUpnpContentServerHandler* CUpnpContentServer::Handler() const |
|
198 { |
|
199 return iHandler; |
|
200 } |
|
201 |
|
202 |
|
203 // -------------------------------------------------------------------------- |
|
204 // CUpnpContentServer::NewContainerL |
|
205 // Deletes objcet container |
|
206 // -------------------------------------------------------------------------- |
|
207 // |
|
208 void CUpnpContentServer::RemoveSession( ) |
|
209 { |
|
210 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
211 iSessionCount--; |
|
212 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
213 } |
|
214 |
|
215 // -------------------------------------------------------------------------- |
|
216 // CUpnpContentServer::NewContainerL |
|
217 // Deletes objcet container |
|
218 // -------------------------------------------------------------------------- |
|
219 // |
|
220 void CUpnpContentServer::AddSession() |
|
221 { |
|
222 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
223 iSessionCount++; |
|
224 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
225 } |
|
226 |
|
227 // -------------------------------------------------------------------------- |
|
228 // CUpnpContentServer::CanStop |
|
229 // ( other items are commented in header ) |
|
230 // -------------------------------------------------------------------------- |
|
231 // |
|
232 TBool CUpnpContentServer::CanStop() const |
|
233 { |
|
234 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
235 TBool ret( EFalse ); |
|
236 if ( iSessionCount < 1 && !iConMon ) |
|
237 { |
|
238 ret = ETrue; |
|
239 } |
|
240 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
241 return ret; |
|
242 } |
|
243 |
|
244 // -------------------------------------------------------------------------- |
|
245 // CUpnpContentServer::Stop |
|
246 // ( other items are commented in header ) |
|
247 // -------------------------------------------------------------------------- |
|
248 // |
|
249 void CUpnpContentServer::Stop() |
|
250 { |
|
251 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
252 if ( iIdle ) |
|
253 { |
|
254 iIdle->Cancel(); |
|
255 } |
|
256 else |
|
257 { |
|
258 TRAPD( err, iIdle = CUPnPPeriodic::NewL( CActive::EPriorityIdle ) ); |
|
259 __ASSERT( err == KErrNone, __FILE__, __LINE__ ); |
|
260 } |
|
261 |
|
262 iIdle->Start( KShutdownTimeout, |
|
263 KShutdownTimeout, |
|
264 TCallBack( Shutdown, this ) ); |
|
265 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
266 } |
|
267 |
|
268 // -------------------------------------------------------------------------- |
|
269 // CUpnpContentServer::Shutdown |
|
270 // ( other items are commented in header ) |
|
271 // -------------------------------------------------------------------------- |
|
272 // |
|
273 TInt CUpnpContentServer::Shutdown( TAny* aPtr ) |
|
274 { |
|
275 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
276 CUpnpContentServer* server = static_cast<CUpnpContentServer*>(aPtr); |
|
277 delete server->iIdle; |
|
278 server->iIdle = NULL; |
|
279 CActiveScheduler::Stop(); |
|
280 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
281 return KErrNone; |
|
282 } |
|
283 |
|
284 // -------------------------------------------------------------------------- |
|
285 // CUpnpContentServer::RequestConnectionLostL |
|
286 // ( other items are commented in header ) |
|
287 // -------------------------------------------------------------------------- |
|
288 // |
|
289 TInt CUpnpContentServer::RequestConnectionLostL( |
|
290 const TInt aIapId ) |
|
291 { |
|
292 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
293 if ( iHandler ) |
|
294 { |
|
295 iHandler->ValidateDefaultContainersL(); |
|
296 } |
|
297 TInt err( KErrNone ); |
|
298 if ( !iConMon ) |
|
299 { |
|
300 iConMon = CUPnPConnectionMonitor::NewL( *this, aIapId ); |
|
301 iActiveIapId = aIapId; |
|
302 } |
|
303 else if ( iActiveIapId != aIapId ) |
|
304 { |
|
305 err = KErrInUse; |
|
306 } |
|
307 |
|
308 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
309 return err; |
|
310 } |
|
311 |
|
312 // -------------------------------------------------------------------------- |
|
313 // CUpnpContentServer::CancelConnectionLostL |
|
314 // ( other items are commented in header ) |
|
315 // -------------------------------------------------------------------------- |
|
316 // |
|
317 void CUpnpContentServer::CancelConnectionLostL() |
|
318 { |
|
319 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
320 // Stop connection monitoring |
|
321 delete iConMon; |
|
322 iConMon = NULL; |
|
323 |
|
324 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
325 } |
|
326 |
|
327 // -------------------------------------------------------------------------- |
|
328 // CUpnpContentServer::ConnectionLost |
|
329 // ( other items are commented in header ) |
|
330 // -------------------------------------------------------------------------- |
|
331 // |
|
332 void CUpnpContentServer::ConnectionLost() |
|
333 { |
|
334 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
335 |
|
336 TRAP_IGNORE( iHandler->ConnectionLostL() ); |
|
337 |
|
338 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
339 } |
|
340 |
|
341 // -------------------------------------------------------------------------- |
|
342 // CUpnpContentServer::RunError |
|
343 // ( other items are commented in header ) |
|
344 // -------------------------------------------------------------------------- |
|
345 // |
|
346 TInt CUpnpContentServer::RunError( TInt aError ) |
|
347 { |
|
348 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
349 if ( aError ) |
|
350 { |
|
351 __LOG1( "Error: %d", aError ); |
|
352 } |
|
353 if ( aError == KErrBadDescriptor ) |
|
354 { |
|
355 Message().Panic( KUpnpContentServerString, aError ); |
|
356 } |
|
357 else |
|
358 { |
|
359 Message().Complete( aError ); |
|
360 } |
|
361 ReStart(); |
|
362 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
363 return KErrNone; |
|
364 } |
|
365 |
|
366 // -------------------------------------------------------------------------- |
|
367 // CUpnpContentServer::NewSessionL |
|
368 // from CServer2, creates a new session. |
|
369 // -------------------------------------------------------------------------- |
|
370 // |
|
371 CSession2* CUpnpContentServer::NewSessionL( |
|
372 const TVersion& aVersion, |
|
373 const RMessage2& /*aMessage*/ ) const |
|
374 { |
|
375 __LOG8_1( "%s begin.", __PRETTY_FUNCTION__ ); |
|
376 |
|
377 if ( iIdle ) |
|
378 { |
|
379 iIdle->Cancel(); |
|
380 } |
|
381 |
|
382 TVersion v( KUpnpContentServerVersionMajor, |
|
383 KUpnpContentServerVersionMinor, |
|
384 0 ); |
|
385 if( !User::QueryVersionSupported(v,aVersion) ) |
|
386 { |
|
387 User::Leave(KErrNotSupported); |
|
388 } |
|
389 |
|
390 __LOG8_1( "%s end.", __PRETTY_FUNCTION__ ); |
|
391 return CUpnpContentServerSession::NewL( (CUpnpContentServer*)this ); |
|
392 } |
|
393 |
|
394 // End of file |