|
1 /** @file |
|
2 * Copyright (c) 2005-2006 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: CUpnpAVCPEngine |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32svr.h> |
|
21 #include "upnpavcpengine.h" |
|
22 #include "upnpavcpenginesession.h" |
|
23 #include "upnpavcpmanager.h" |
|
24 #include "upnpavcpenginecommon.h" |
|
25 #include "upnpmdebug.h" |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CUpnpAVCPEngine::CUpnpAVCPEngine |
|
29 // constructor. |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 CUpnpAVCPEngine::CUpnpAVCPEngine( TInt aPriority ) |
|
33 : CServer2( aPriority ) |
|
34 { |
|
35 } |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CUpnpAVCPEngine::~CUpnpAVCPEngine |
|
39 // destructor. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CUpnpAVCPEngine::~CUpnpAVCPEngine() |
|
43 { |
|
44 delete iAVCPManger; |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CUpnpAVCPEngine::NewLC |
|
49 // Two-phased constructor. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CUpnpAVCPEngine* CUpnpAVCPEngine::NewLC() |
|
53 { |
|
54 CUpnpAVCPEngine* engine = new (ELeave) CUpnpAVCPEngine( EPriorityNormal ); |
|
55 CleanupStack::PushL( engine ); |
|
56 engine->ConstructL() ; |
|
57 return engine; |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CUpnpAVCPEngine::ConstructL |
|
62 // Symbian 2nd phase constructor can leave. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 void CUpnpAVCPEngine::ConstructL() |
|
66 { |
|
67 DEBUGSTRING(("CUpnpAVCPEngine::ConstructL ")); |
|
68 iAVCPManger = CUpnpAVCPManager::NewL(); |
|
69 StartL( KAVCPEngineName ); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CUpnpAVCPEngine::NewSessionL |
|
74 // Create new session. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CSession2* CUpnpAVCPEngine::NewSessionL( const TVersion& aVersion, const RMessage2& aMessage ) const |
|
78 { |
|
79 // Check it's the right version |
|
80 if ( !User::QueryVersionSupported( TVersion( |
|
81 KAVCPEngineMajorVersionNumber, |
|
82 KAVCPEngineMinorVersionNumber, |
|
83 KAVCPEngineBuildVersionNumber ), |
|
84 aVersion ) ) |
|
85 { |
|
86 User::Leave( KErrNotSupported ); |
|
87 } |
|
88 |
|
89 RThread client; |
|
90 aMessage.Client(client); |
|
91 return CUpnpAVCPEngineSession::NewL( client, *const_cast<CUpnpAVCPEngine*> ( this ), *const_cast<CUpnpAVCPManager*> (iAVCPManger) ); |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CUpnpAVCPEngine::IncrementSessions |
|
96 // Increment sessions. |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 void CUpnpAVCPEngine::IncrementSessions(CUpnpAVCPEngineSession* /*aObserver*/) |
|
100 { |
|
101 iSessionCount++; |
|
102 DEBUGSTRING(("IncrementSessions (%d)", iSessionCount)); |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CUpnpAVCPEngine::DecrementSessions |
|
107 // Decrement sessions. |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 void CUpnpAVCPEngine::DecrementSessions( CUpnpAVCPEngineSession* aObserver) |
|
111 { |
|
112 TRAP_IGNORE( iAVCPManger->CleanupSessionL(aObserver) ); |
|
113 iSessionCount--; |
|
114 DEBUGSTRING(("DecrementSessions (%d)", iSessionCount)); |
|
115 if ( iSessionCount <= 0 ) |
|
116 { |
|
117 CActiveScheduler::Stop(); |
|
118 } |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CUpnpAVCPEngine::RunError |
|
123 // RunError is called when RunL leaves. |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 TInt CUpnpAVCPEngine::RunError( TInt aError ) |
|
127 { |
|
128 DEBUGSTRING(("CUpnpAVCPEngine::RunError (%d)", aError)); |
|
129 |
|
130 if ( aError == KErrBadDescriptor ) |
|
131 { |
|
132 // A bad descriptor error implies a badly programmed client, so panic it; |
|
133 // otherwise report the error to the client |
|
134 PanicClient( Message(), /*EMessageHandlerBadDescriptor*/EAVCPEngineGenerealPanic ); |
|
135 } |
|
136 else |
|
137 { |
|
138 Message().Complete( aError ); |
|
139 } |
|
140 |
|
141 // The leave will result in an early return from CServer::RunL(), skipping |
|
142 // the call to request another message. So do that now in order to keep the |
|
143 // server running. |
|
144 ReStart(); |
|
145 |
|
146 return KErrNone; |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CUpnpAVCPEngine::PanicClient |
|
151 // Panic client. |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 void CUpnpAVCPEngine::PanicClient( const RMessage2& aMessage, |
|
155 TAVCPEnginePanic aPanic ) |
|
156 { |
|
157 aMessage.Panic( KAVCPEngine, aPanic ); |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CUpnpAVCPEngine::PanicServer |
|
162 // Panic server. |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 void CUpnpAVCPEngine::PanicServer( TAVCPEnginePanic aPanic ) |
|
166 { |
|
167 User::Panic( KAVCPEngine, aPanic ); |
|
168 } |
|
169 |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CUpnpAVCPEngine::ThreadFunctionL |
|
173 // Create and start the server. |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 void CUpnpAVCPEngine::ThreadFunctionL() |
|
177 { |
|
178 // Construct active scheduler |
|
179 CActiveScheduler* activeScheduler = new (ELeave) CActiveScheduler; |
|
180 CleanupStack::PushL( activeScheduler ); |
|
181 |
|
182 // Install active scheduler |
|
183 // We don't need to check whether an active scheduler is already installed |
|
184 // as this is a new thread, so there won't be one |
|
185 CActiveScheduler::Install( activeScheduler ); |
|
186 |
|
187 User::RenameThread( KAVCPEngineName ); |
|
188 // Construct our server |
|
189 CUpnpAVCPEngine* engine = CUpnpAVCPEngine::NewLC(); // Anonymous |
|
190 |
|
191 RProcess::Rendezvous(KErrNone); |
|
192 |
|
193 // Start handling requests |
|
194 CActiveScheduler::Start(); |
|
195 |
|
196 CleanupStack::PopAndDestroy( engine ); |
|
197 CleanupStack::PopAndDestroy( activeScheduler ); |
|
198 |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CUpnpAVCPEngine::ThreadFunctionL |
|
203 // Create and start the server. |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 TInt CUpnpAVCPEngine::ThreadFunction( TAny* /*aNone*/ ) |
|
207 { |
|
208 __UHEAP_MARK; |
|
209 |
|
210 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
211 if ( !(cleanupStack) ) |
|
212 { |
|
213 PanicServer( EAVCPEngineGenerealPanic ); |
|
214 } |
|
215 |
|
216 TRAPD( err, ThreadFunctionL() ); |
|
217 if ( err != KErrNone ) |
|
218 { |
|
219 PanicServer( EAVCPEngineGenerealPanic ); |
|
220 } |
|
221 |
|
222 delete cleanupStack; |
|
223 cleanupStack = NULL; |
|
224 |
|
225 __UHEAP_MARKEND; |
|
226 |
|
227 return KErrNone; |
|
228 } |
|
229 |
|
230 |
|
231 // ============================= LOCAL FUNCTIONS =============================== |
|
232 |
|
233 TInt E32Main() |
|
234 { |
|
235 return CUpnpAVCPEngine::ThreadFunction(NULL); |
|
236 } |
|
237 |
|
238 // End of File |