1 /* |
|
2 * Copyright (c) 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "musmanagerimpl.h" |
|
21 #include "musmanager.h" |
|
22 #include "musmanageripccommon.h" |
|
23 #include "musmanagerserverstarter.h" |
|
24 #include "muslogger.h" |
|
25 #include "musavailabilityobserver.h" |
|
26 |
|
27 // --------------------------------------------------------------------------- |
|
28 // CMusManagerImpl::CMusManagerImpl |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 CMusManagerImpl::CMusManagerImpl() |
|
32 : iConnected( EFalse ) |
|
33 { |
|
34 } |
|
35 |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // CMusManagerImpl::CMusManagerImpl |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 CMusManagerImpl::CMusManagerImpl( MMusAvailabilityObserver* aObserver ) |
|
42 : iConnected( EFalse ), iAvailabilityObserver( aObserver ) |
|
43 { |
|
44 } |
|
45 |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // CMusManagerImpl::ConstructL |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 void CMusManagerImpl::ConstructL() |
|
52 { |
|
53 if ( iAvailabilityObserver ) |
|
54 { |
|
55 iListener = CMusManagerImplListener::NewL( this ); |
|
56 } |
|
57 } |
|
58 |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // CMusManagerImpl::NewL |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 CMusManagerImpl* CMusManagerImpl::NewL() |
|
65 { |
|
66 CMusManagerImpl* self = CMusManagerImpl::NewLC(); |
|
67 CleanupStack::Pop( self ); |
|
68 return self; |
|
69 } |
|
70 |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // CMusManagerImpl::NewLC |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 CMusManagerImpl* CMusManagerImpl::NewLC() |
|
77 { |
|
78 CMusManagerImpl* self = new( ELeave ) CMusManagerImpl; |
|
79 CleanupStack::PushL( self ); |
|
80 self->ConstructL(); |
|
81 return self; |
|
82 } |
|
83 |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // CMusManagerImpl::NewL |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 CMusManagerImpl* CMusManagerImpl::NewL( MMusAvailabilityObserver* aObserver ) |
|
90 { |
|
91 CMusManagerImpl* self = CMusManagerImpl::NewLC( aObserver ); |
|
92 CleanupStack::Pop( self ); |
|
93 return self; |
|
94 } |
|
95 |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // CMusManagerImpl::NewLC |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 CMusManagerImpl* CMusManagerImpl::NewLC( MMusAvailabilityObserver* aObserver ) |
|
102 { |
|
103 CMusManagerImpl* self = new( ELeave ) CMusManagerImpl( aObserver ); |
|
104 CleanupStack::PushL( self ); |
|
105 self->ConstructL(); |
|
106 return self; |
|
107 } |
|
108 |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // CMusManagerImpl::~CMusManagerImpl |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 CMusManagerImpl::~CMusManagerImpl() |
|
115 { |
|
116 MUS_LOG( "mus: [MUSCLI] -> CMusManagerImpl::~CMusManagerImpl()" ); |
|
117 delete iListener; |
|
118 iSession.Disconnect(); |
|
119 MUS_LOG( "mus: [MUSCLI] <- CMusManagerImpl::~CMusManagerImpl()" ); |
|
120 } |
|
121 |
|
122 |
|
123 // --------------------------------------------------------------------------- |
|
124 // CMusManagerImpl::~CMusManagerImpl |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 void CMusManagerImpl::StartServer() |
|
128 { |
|
129 MUS_LOG( "mus: [MUSCLI] -> CMusManagerImpl::StartServer()" ); |
|
130 TInt error = MusManagerServerStarter::Start(); |
|
131 MUS_LOG( "mus: [MUSCLI] <- CMusManagerImpl::StartServer()" ); |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // CMusManagerImpl::~CMusManagerImpl |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 TBool CMusManagerImpl::ServerStarted() |
|
139 { |
|
140 return MusManagerServerStarter::Started(); |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // CMusManagerImpl::~CMusManagerImpl |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 void CMusManagerImpl::ExamineAvailabilityL() |
|
148 { |
|
149 MUS_LOG( "mus: [MUSCLI] -> CMusManagerImpl::ExamineAvailabilityL()" ); |
|
150 // ensure server and connection are ok |
|
151 InitSessionL(); |
|
152 |
|
153 iSession.InvestigateAvailabilityL(); |
|
154 MUS_LOG( "mus: [MUSCLI] <- CMusManagerImpl::ExamineAvailabilityL()" ); |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // Returns the current availability of MultimediaSharing. |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 MultimediaSharing::TMusAvailabilityStatus CMusManagerImpl::AvailabilityL() |
|
162 { |
|
163 MUS_LOG( "mus: [MUSCLI] -> CMusManagerImpl::AvailabilityL()" ); |
|
164 |
|
165 MultimediaSharing::TMusAvailabilityStatus status; |
|
166 |
|
167 if( !ServerStarted() ) |
|
168 { |
|
169 status = ( MultimediaSharing::TMusAvailabilityStatus ) KErrNotReady; |
|
170 } |
|
171 else |
|
172 { |
|
173 status = QueryAvailabilityL(); |
|
174 } |
|
175 MUS_LOG( "mus: [MUSCLI] <- CMusManagerImpl::AvailabilityL()" ); |
|
176 |
|
177 return status; |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // Forwards command to executed by MultimediaSharing. |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 void CMusManagerImpl::HandleCommandL( |
|
185 MultimediaSharing::TCommandType aCommandType ) |
|
186 { |
|
187 MUS_LOG( "mus: [MUSCLI] -> CMusManagerImpl::HandleCommandL()" ); |
|
188 // ensure server and connection are ok |
|
189 InitSessionL(); |
|
190 |
|
191 iSession.HandleCommandL( aCommandType ); |
|
192 MUS_LOG( "mus: [MUSCLI] <- CMusManagerImpl::HandleCommandL()" ); |
|
193 } |
|
194 // --------------------------------------------------------------------------- |
|
195 // Forwards a SIP request to be handled by MultimediaSharing. |
|
196 // --------------------------------------------------------------------------- |
|
197 // |
|
198 void CMusManagerImpl::HandleSipRequestL( TInt aChannelId ) |
|
199 { |
|
200 MUS_LOG( "mus: [MUSCLI] -> CMusManagerImpl::HandleSipRequestL()" ); |
|
201 // ensure server and connection are ok |
|
202 InitSessionL(); |
|
203 |
|
204 iSession.HandleSipRequestL( aChannelId ); |
|
205 MUS_LOG( "mus: [MUSCLI] <- CMusManagerImpl::HandleSipRequestL()" ); |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------------------------- |
|
209 // Starts the MultimediaSharing application. |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 void CMusManagerImpl::StartApplicationL( MultimediaSharing::TMusUseCase aUseCase ) |
|
213 { |
|
214 MUS_LOG( "mus: [MUSCLI] -> CMusManagerImpl::StartApplicationL()" ); |
|
215 // ensure server and connection are ok |
|
216 InitSessionL(); |
|
217 |
|
218 MultimediaSharing::TMusAvailabilityStatus status = |
|
219 iSession.QueryAvailabilityL(); |
|
220 |
|
221 if( status < KErrNone || status >= MultimediaSharing::EErrSipRegistration ) |
|
222 { |
|
223 MUS_LOG1( "mus: [MUSCLI] <- CMusManagerImpl::StartApplicationL( leave: %d )", |
|
224 status ); |
|
225 User::Leave( status ); |
|
226 } |
|
227 |
|
228 iSession.StartL( aUseCase ); |
|
229 |
|
230 MUS_LOG( "mus: [MUSCLI] <- CMusManagerImpl::StartApplicationL()" ); |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------------------------- |
|
234 // Stops the MultimediaSharing application. |
|
235 // --------------------------------------------------------------------------- |
|
236 // |
|
237 void CMusManagerImpl::StopApplicationL() |
|
238 { |
|
239 MUS_LOG( "mus: [MUSCLI] -> CMusManagerImpl::StopApplicationL()" ); |
|
240 // ensure server and connection are ok |
|
241 InitSessionL(); |
|
242 |
|
243 iSession.StopL(); |
|
244 MUS_LOG( "mus: [MUSCLI] <- CMusManagerImpl::StopApplicationL()" ); |
|
245 } |
|
246 |
|
247 // --------------------------------------------------------------------------- |
|
248 // Starts investigating the current availability of MultimediaSharing. |
|
249 // --------------------------------------------------------------------------- |
|
250 // |
|
251 MultimediaSharing::TMusAvailabilityStatus CMusManagerImpl::QueryAvailabilityL() |
|
252 { |
|
253 MUS_LOG( "mus: [MUSCLI] -> CMusManagerImpl::QueryAvailabilityL()" ); |
|
254 // ensure server and connection are ok |
|
255 InitSessionL(); |
|
256 |
|
257 MultimediaSharing::TMusAvailabilityStatus status |
|
258 = iSession.QueryAvailabilityL(); |
|
259 |
|
260 MUS_LOG( "mus: [MUSCLI] <- CMusManagerImpl::QueryAvailabilityL()" ); |
|
261 return status; |
|
262 } |
|
263 |
|
264 // --------------------------------------------------------------------------- |
|
265 // Starts to monitor availability |
|
266 // --------------------------------------------------------------------------- |
|
267 // |
|
268 void CMusManagerImpl::MonitorAvailabilityL( TRequestStatus& aRequestStatus ) |
|
269 { |
|
270 MUS_LOG( "mus: [MUSCLI] -> CMusManagerImpl::MonitorAvailabilityL()" ); |
|
271 |
|
272 iPcArgs.Set( EMusManagerIpcArgAvailabilityStatus, &iPckg ); |
|
273 iSession.MonitorAvailabilityL( aRequestStatus, iPcArgs ); |
|
274 |
|
275 MUS_LOG( "mus: [MUSCLI] <- CMusManagerImpl::MonitorAvailabilityL()" ); |
|
276 } |
|
277 |
|
278 |
|
279 // --------------------------------------------------------------------------- |
|
280 // Starts server process, if needed, and then opens a session to it. |
|
281 // --------------------------------------------------------------------------- |
|
282 // |
|
283 void CMusManagerImpl::InitSessionL() |
|
284 { |
|
285 MUS_LOG( "mus: [MUSCLI] -> CMusManagerImpl::InitSessionL()" ); |
|
286 // if server not started, start it |
|
287 if( !ServerStarted() ) |
|
288 { |
|
289 StartServer(); |
|
290 } |
|
291 |
|
292 // if no session, connect |
|
293 if( !iConnected ) |
|
294 { |
|
295 ConnectL(); |
|
296 } |
|
297 MUS_LOG( "mus: [MUSCLI] <- CMusManagerImpl::InitSessionL()" ); |
|
298 } |
|
299 |
|
300 |
|
301 // --------------------------------------------------------------------------- |
|
302 // Connects this client to the server process; opens a session. |
|
303 // --------------------------------------------------------------------------- |
|
304 // |
|
305 void CMusManagerImpl::ConnectL() |
|
306 { |
|
307 MUS_LOG( "mus: [MUSCLI] -> CMusManagerImpl::ConnectL()" ); |
|
308 iSession.ConnectL(); |
|
309 |
|
310 iConnected = ETrue; |
|
311 MUS_LOG( "mus: [MUSCLI] <- CMusManagerImpl::ConnectL()" ); |
|
312 } |
|
313 |
|
314 |
|
315 // --------------------------------------------------------------------------- |
|
316 // |
|
317 // --------------------------------------------------------------------------- |
|
318 // |
|
319 void CMusManagerImpl::CancelMonitoring() |
|
320 { |
|
321 MUS_LOG( "mus: [MUSCLI] -> CMusManagerImpl::CancelMonitoring()" ); |
|
322 TRAP_IGNORE( iSession.CancelMonitoringL() ); |
|
323 MUS_LOG( "mus: [MUSCLI] <- CMusManagerImpl::CancelMonitoring()" ); |
|
324 } |
|
325 |
|
326 |
|
327 // --------------------------------------------------------------------------- |
|
328 // Creates listener |
|
329 // --------------------------------------------------------------------------- |
|
330 // |
|
331 CMusManagerImpl::CMusManagerImplListener* |
|
332 CMusManagerImpl::CMusManagerImplListener::NewL( |
|
333 CMusManagerImpl* aMusManagerImpl ) |
|
334 { |
|
335 CMusManagerImplListener* self = |
|
336 new ( ELeave ) CMusManagerImplListener( aMusManagerImpl ); |
|
337 CleanupStack::PushL( self ); |
|
338 self->ConstructL(); |
|
339 CleanupStack::Pop( self ); |
|
340 return self; |
|
341 } |
|
342 |
|
343 // --------------------------------------------------------------------------- |
|
344 // Constructs listener |
|
345 // --------------------------------------------------------------------------- |
|
346 // |
|
347 CMusManagerImpl::CMusManagerImplListener::CMusManagerImplListener( |
|
348 CMusManagerImpl* aMusManagerImpl ) : |
|
349 CActive(0), iMusManagerImpl( aMusManagerImpl ) |
|
350 { |
|
351 CActiveScheduler::Add(this); |
|
352 } |
|
353 |
|
354 // --------------------------------------------------------------------------- |
|
355 // ConstructL |
|
356 // --------------------------------------------------------------------------- |
|
357 // |
|
358 void CMusManagerImpl::CMusManagerImplListener::ConstructL() |
|
359 { |
|
360 iMusManagerImpl->InitSessionL(); |
|
361 iMusManagerImpl->iSession.StartObservingAvailabilityL(); |
|
362 ListenL(); |
|
363 } |
|
364 |
|
365 // --------------------------------------------------------------------------- |
|
366 // Destructs listener |
|
367 // --------------------------------------------------------------------------- |
|
368 // |
|
369 CMusManagerImpl::CMusManagerImplListener::~CMusManagerImplListener() |
|
370 { |
|
371 Cancel(); |
|
372 } |
|
373 |
|
374 // --------------------------------------------------------------------------- |
|
375 // Start listening availability events |
|
376 // --------------------------------------------------------------------------- |
|
377 // |
|
378 void CMusManagerImpl::CMusManagerImplListener::ListenL() |
|
379 { |
|
380 iMusManagerImpl->MonitorAvailabilityL( iStatus ); |
|
381 SetActive(); |
|
382 } |
|
383 |
|
384 // --------------------------------------------------------------------------- |
|
385 // RunL |
|
386 // --------------------------------------------------------------------------- |
|
387 // |
|
388 void CMusManagerImpl::CMusManagerImplListener::RunL() |
|
389 { |
|
390 iMusManagerImpl->iAvailabilityObserver->MusAvailabilityChangedL( |
|
391 iMusManagerImpl->iPckg() ); |
|
392 |
|
393 // restart monitoring |
|
394 ListenL(); |
|
395 } |
|
396 |
|
397 // --------------------------------------------------------------------------- |
|
398 // RunL |
|
399 // --------------------------------------------------------------------------- |
|
400 // |
|
401 TInt CMusManagerImpl::CMusManagerImplListener::RunError( TInt aError ) |
|
402 { |
|
403 MUS_LOG1( "mus: [MUSCLI] CMusManagerImplListener::RunError: %d", \ |
|
404 aError ); |
|
405 return aError; |
|
406 } |
|
407 |
|
408 // --------------------------------------------------------------------------- |
|
409 // Cancel |
|
410 // --------------------------------------------------------------------------- |
|
411 // |
|
412 void CMusManagerImpl::CMusManagerImplListener::DoCancel() |
|
413 { |
|
414 iMusManagerImpl->CancelMonitoring(); |
|
415 } |
|