|
1 /* |
|
2 * Copyright (c) 2007-2008 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: Implements VoIP server object. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <e32svr.h> |
|
19 #include <e32uid.h> |
|
20 #include <e32capability.h> |
|
21 #include "debugtracemacros.h" |
|
22 #include "VoIPECallEventHandler.h" |
|
23 #include "VoIPServerShutdown.h" |
|
24 #include "VoIPServerSession.h" |
|
25 #include "VoIPServer.h" |
|
26 |
|
27 // CONSTANTS |
|
28 const TInt KShutDownDelayTime = 2000000; // 2 sec delay time |
|
29 const TInt KNumOfSessions = 3; |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CVoIPAudioServer::NewL |
|
33 // |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CVoIPAudioServer* CVoIPAudioServer::NewL() |
|
37 { |
|
38 CVoIPAudioServer* self = new (ELeave) CVoIPAudioServer; |
|
39 CleanupStack::PushL(self); |
|
40 self->ConstructL(); |
|
41 CleanupStack::Pop(self); |
|
42 return self; |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CVoIPAudioServer::CVoIPAudioServer |
|
47 // |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CVoIPAudioServer::CVoIPAudioServer() : |
|
51 CServer2(CActive::EPriorityHigh, ESharableSessions), |
|
52 iSession(0) |
|
53 { |
|
54 iECallInProgress = EFalse; |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CVoIPAudioServer::~CVoIPAudioServer |
|
59 // |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CVoIPAudioServer::~CVoIPAudioServer() |
|
63 { |
|
64 TRACE_PRN_FN_ENT; |
|
65 CancelECallEventNotifier(); |
|
66 delete iShutdownTimer; |
|
67 TRACE_PRN_FN_EXT; |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CVoIPAudioServer::NewSessionL |
|
72 // |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 CSession2* CVoIPAudioServer::NewSessionL(const TVersion& aVersion, |
|
76 const RMessage2& aMessage) const |
|
77 { |
|
78 TRACE_PRN_FN_ENT; |
|
79 |
|
80 // Block session creation during active emergency call |
|
81 if (iECallInProgress) |
|
82 { |
|
83 User::Leave(KErrPermissionDenied); |
|
84 } |
|
85 |
|
86 // Block access to audio device when MultimediaDD capability missing |
|
87 if (!aMessage.HasCapability(ECapabilityMultimediaDD)) |
|
88 { |
|
89 User::Leave(KErrPermissionDenied); |
|
90 } |
|
91 |
|
92 // Limit number of sessions created by the server. |
|
93 if (iSession >= KNumOfSessions) |
|
94 { |
|
95 User::Leave(KErrPermissionDenied); |
|
96 } |
|
97 |
|
98 const TVersion version(KVoIPServMajorVersionNumber, |
|
99 KVoIPServMinorVersionNumber, KVoIPServBuildVersionNumber); |
|
100 |
|
101 if (!User::QueryVersionSupported(version, aVersion)) |
|
102 { |
|
103 User::Leave(KErrNotSupported); |
|
104 } |
|
105 |
|
106 CVoIPAudioServerSession* session = CVoIPAudioServerSession::NewL( |
|
107 *((CVoIPAudioServer*) this)); |
|
108 |
|
109 TRACE_PRN_FN_EXT; |
|
110 return session; |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CVoIPAudioServer::ConstructL |
|
115 // |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CVoIPAudioServer::ConstructL() |
|
119 { |
|
120 TRACE_PRN_FN_ENT; |
|
121 |
|
122 iShutdownTimer = CDelayVoIPServerShutDown::NewL(); |
|
123 StartL(KVoIPServerName); |
|
124 RThread().SetPriority(EPriorityRealTime); |
|
125 StartECallEventNotifierL(); |
|
126 |
|
127 TRACE_PRN_FN_EXT; |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CVoIPAudioServer::AddSession |
|
132 // |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 void CVoIPAudioServer::AddSession() |
|
136 { |
|
137 iSession++; |
|
138 // If shutdown timer is active, cancel it here. |
|
139 iShutdownTimer->Cancel(); |
|
140 |
|
141 TRACE_PRN_N1(_L("VoIP->SRV: AddSession->Active Sessions: [%d]"), iSession); |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CVoIPAudioServer::DropSession |
|
146 // |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 void CVoIPAudioServer::DropSession() |
|
150 { |
|
151 iSession--; |
|
152 |
|
153 // If session count is zero, launch shutdown timer here |
|
154 if (iSession == 0) |
|
155 { |
|
156 iShutdownTimer->SetDelay(TTimeIntervalMicroSeconds32( |
|
157 KShutDownDelayTime)); |
|
158 } |
|
159 |
|
160 TRACE_PRN_N1(_L("VoIP->DNL: DropSession->Active Sessions: [%d]"), iSession); |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CVoIPAudioServer::SessionCount |
|
165 // |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 TInt CVoIPAudioServer::SessionCount() |
|
169 { |
|
170 return iSession; |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CVoIPAudioServer::SetDnLinkSession |
|
175 // |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 void CVoIPAudioServer::SetDnLinkSession(CVoIPAudioServerSession* aSession, |
|
179 TBool aStatus) |
|
180 { |
|
181 if (aStatus) |
|
182 { |
|
183 iDnlinkSession = aSession; |
|
184 } |
|
185 else |
|
186 { |
|
187 iDnlinkSession = NULL; |
|
188 } |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CVoIPAudioServer::SetUpLinkSession |
|
193 // |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 void CVoIPAudioServer::SetUpLinkSession(CVoIPAudioServerSession* aSession, |
|
197 TBool aStatus) |
|
198 { |
|
199 if (aStatus) |
|
200 { |
|
201 iUplinkSession = aSession; |
|
202 } |
|
203 else |
|
204 { |
|
205 iUplinkSession = NULL; |
|
206 } |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CVoIPAudioServer::HasDnLinkSession |
|
211 // |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 TBool CVoIPAudioServer::HasDnLinkSession() |
|
215 { |
|
216 TBool status = EFalse; |
|
217 if (iDnlinkSession) |
|
218 { |
|
219 status = ETrue; |
|
220 } |
|
221 return status; |
|
222 } |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // CVoIPAudioServer::HasUpLinkSession |
|
226 // |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 TBool CVoIPAudioServer::HasUpLinkSession() |
|
230 { |
|
231 TBool status = EFalse; |
|
232 if (iUplinkSession) |
|
233 { |
|
234 status = ETrue; |
|
235 } |
|
236 return status; |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // CVoIPAudioServer::StartECallEventNotifierL |
|
241 // |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 void CVoIPAudioServer::StartECallEventNotifierL() |
|
245 { |
|
246 if (!iECallHandler) |
|
247 { |
|
248 iECallHandler = CVoIPECallEventHandler::NewL( |
|
249 (const_cast<CVoIPAudioServer*> (this))); |
|
250 } |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CVoIPAudioServer::CancelECallEventNotifier |
|
255 // |
|
256 // ----------------------------------------------------------------------------- |
|
257 // |
|
258 void CVoIPAudioServer::CancelECallEventNotifier() |
|
259 { |
|
260 delete iECallHandler; |
|
261 iECallHandler = NULL; |
|
262 } |
|
263 |
|
264 // ----------------------------------------------------------------------------- |
|
265 // CVoIPAudioServer::NotifyECallEvent |
|
266 // |
|
267 // ----------------------------------------------------------------------------- |
|
268 // |
|
269 void CVoIPAudioServer::NotifyECallEvent(TInt aECall) |
|
270 { |
|
271 iECallInProgress = aECall; |
|
272 |
|
273 if (iECallInProgress) |
|
274 { |
|
275 if (HasDnLinkSession()) |
|
276 { |
|
277 iDnlinkSession->CloseDownlink(); |
|
278 } |
|
279 if (HasUpLinkSession()) |
|
280 { |
|
281 iUplinkSession->CloseUplink(); |
|
282 } |
|
283 } |
|
284 } |
|
285 |
|
286 // ----------------------------------------------------------------------------- |
|
287 // CVoIPAudioServer::RunServerL |
|
288 // |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 static void RunServerL() |
|
292 { |
|
293 TRACE_PRN_N(_L("VoIP->RunServerL")); |
|
294 |
|
295 // Create and install the active scheduler we need |
|
296 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
297 CleanupStack::PushL(scheduler); |
|
298 CActiveScheduler::Install(scheduler); |
|
299 |
|
300 // Create the server (leave it on the cleanup stack) |
|
301 CVoIPAudioServer* server = CVoIPAudioServer::NewL(); |
|
302 |
|
303 // Initialisation complete, now signal the client |
|
304 RProcess::Rendezvous(KErrNone); |
|
305 |
|
306 // Start the scheduler and wait for client requests |
|
307 CActiveScheduler::Start(); |
|
308 |
|
309 // Ready to exit. |
|
310 // Cleanup scheduler and delete the server |
|
311 CleanupStack::PopAndDestroy(scheduler); |
|
312 delete server; |
|
313 |
|
314 TRACE_PRN_N(_L("VoIP->RunServerL - VoIP server closed")); |
|
315 } |
|
316 |
|
317 // ----------------------------------------------------------------------------- |
|
318 // E32Main |
|
319 // Entry point for the server |
|
320 // ----------------------------------------------------------------------------- |
|
321 // |
|
322 TInt E32Main() |
|
323 { |
|
324 __UHEAP_MARK; |
|
325 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
326 TInt r = KErrNoMemory; |
|
327 if (cleanup) |
|
328 { |
|
329 TRAP(r, RunServerL()); |
|
330 delete cleanup; |
|
331 } |
|
332 __UHEAP_MARKEND; |
|
333 return r; |
|
334 } |
|
335 |
|
336 // End of file |