|
1 /* |
|
2 * Copyright (c) 2005 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "mcesrvendpoint.h" |
|
22 #include "mcecommediastream.h" |
|
23 #include "mcecomsession.h" |
|
24 #include "mcecomendpointproxy.h" |
|
25 #include "mcesrvstreamiterator.h" |
|
26 |
|
27 #include "mcemediaobserver.h" |
|
28 #include "mceevents.h" |
|
29 #include "mcemmlogs.h" |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CMceSrvEndpoint::CMceSrvEndpoint |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CMceSrvEndpoint::CMceSrvEndpoint( CMceMediaManager& aManager, |
|
40 CMceComEndpoint& aData ) |
|
41 : iID( KMceNotAssigned ), |
|
42 iState( CMceSrvStream::ECreated ), |
|
43 iManager( &aManager ), |
|
44 iData( &aData ) |
|
45 { |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CMceSrvEndpoint::Merge |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 void CMceSrvEndpoint::Merge( CMceSrvEndpoint& aMergeWith ) |
|
53 { |
|
54 iID = aMergeWith.iID; |
|
55 iState = aMergeWith.iState; |
|
56 } |
|
57 |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CMceSrvEndpoint::~CMceSrvEndpoint |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 CMceSrvEndpoint::~CMceSrvEndpoint() |
|
64 { |
|
65 //NOP |
|
66 } |
|
67 |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CMceSrvEndpoint::Id |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 TUint32& CMceSrvEndpoint::Id() |
|
74 { |
|
75 return iID; |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CMceSrvEndpoint::SetState |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 void CMceSrvEndpoint::SetState( CMceSrvStream::TState aState ) |
|
83 { |
|
84 iState = aState; |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CMceSrvEndpoint::State |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 CMceSrvStream::TState CMceSrvEndpoint::State() const |
|
92 { |
|
93 return iState; |
|
94 } |
|
95 |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CMceSrvEndpoint::Data |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 CMceComEndpoint& CMceSrvEndpoint::Data() const |
|
102 { |
|
103 return *iData; |
|
104 } |
|
105 |
|
106 |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CMceSrvEndpoint::MccPrepareCalledL |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 void CMceSrvEndpoint::MccPrepareCalledL( CMceSrvStream& /*aStream*/ ) |
|
113 { |
|
114 //NOP |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CMceSrvEndpoint::EnableL |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 |
|
122 TBool CMceSrvEndpoint::EnableL( CMceSrvStream& aStream, TBool aSync ) |
|
123 { |
|
124 if ( aStream.IsMccPrepared() && !Data().EndpointProxy() ) |
|
125 { |
|
126 return KMceSrvStreamDefaultSequence; |
|
127 } |
|
128 |
|
129 MCEMM_DEBUG("CMceSrvEndpoint::EnableL(): alternative enable"); |
|
130 |
|
131 TBool sequenceType = aStream.IsMccPrepared() ? |
|
132 KMceSrvStreamDefaultSequence : |
|
133 KMceSrvStreamAlternativeSequence; |
|
134 |
|
135 if ( State() >= CMceSrvStream::EStarted && |
|
136 ( aSync || !Data().IsEnabled() ) ) |
|
137 { |
|
138 MCEMM_DEBUG("CMceSrvEndpoint::EnableL(): enabling"); |
|
139 |
|
140 if ( Data().EndpointProxy() ) |
|
141 { |
|
142 sequenceType = |
|
143 Data().EndpointProxy()->ClientEnableL( Data(), aStream.Codec() ); |
|
144 } |
|
145 |
|
146 if ( !aStream.IsMccPrepared() ) |
|
147 { |
|
148 Data().EnableL( aStream.Codec() ); |
|
149 sequenceType = KMceSrvStreamAlternativeSequence; |
|
150 } |
|
151 } |
|
152 |
|
153 if ( sequenceType ) |
|
154 { |
|
155 Data().Enabled( ETrue ); |
|
156 if ( State() >= CMceSrvStream::EStarted ) |
|
157 { |
|
158 SetState( CMceSrvStream::EStarted ); |
|
159 } |
|
160 |
|
161 MCEMM_DEBUG_STREAM( "CMceSrvEndpoint::EnableL(): stream of endpoint after enable", |
|
162 aStream ); |
|
163 } |
|
164 |
|
165 return sequenceType; |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CMceSrvEndpoint::DisableL |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 |
|
173 TBool CMceSrvEndpoint::DisableL( CMceSrvStream& aStream, TBool aSync, TBool aForce ) |
|
174 { |
|
175 if ( aStream.IsMccPrepared() && !Data().EndpointProxy() ) |
|
176 { |
|
177 return KMceSrvStreamDefaultSequence; |
|
178 } |
|
179 |
|
180 MCEMM_DEBUG("CMceSrvEndpoint::DisableL(): alternative disable"); |
|
181 |
|
182 TBool sequenceType = aStream.IsMccPrepared() ? |
|
183 KMceSrvStreamDefaultSequence : |
|
184 KMceSrvStreamAlternativeSequence; |
|
185 |
|
186 if ( ( State() >= CMceSrvStream::EStarted || aForce ) && |
|
187 ( aSync || Data().IsEnabled() ) ) |
|
188 { |
|
189 MCEMM_DEBUG("CMceSrvEndpoint::DisableL(): disabling"); |
|
190 |
|
191 if ( Data().EndpointProxy() ) |
|
192 { |
|
193 sequenceType = Data().EndpointProxy()->ClientDisableL( Data() ); |
|
194 } |
|
195 |
|
196 if ( !aStream.IsMccPrepared() ) |
|
197 { |
|
198 TRAPD( err, Data().DisableL() ) |
|
199 if ( !aForce ) |
|
200 { |
|
201 // When forcing disable, error is ignored |
|
202 User::LeaveIfError( err ); |
|
203 } |
|
204 |
|
205 sequenceType = KMceSrvStreamAlternativeSequence; |
|
206 } |
|
207 } |
|
208 |
|
209 if ( sequenceType ) |
|
210 { |
|
211 Data().Enabled( EFalse ); |
|
212 if ( State() >= CMceSrvStream::EStarted ) |
|
213 { |
|
214 SetState( CMceSrvStream::EPaused ); |
|
215 } |
|
216 MCEMM_DEBUG_STREAM( "CMceSrvEndpoint::DisableL(): stream of endpoint after disable", |
|
217 aStream ); |
|
218 } |
|
219 |
|
220 return sequenceType; |
|
221 } |
|
222 |
|
223 // ----------------------------------------------------------------------------- |
|
224 // CMceSrvEndpoint::Reusable |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 TBool CMceSrvEndpoint::Reusable( const CMceSrvStream& aStream ) const |
|
228 { |
|
229 return Data().Reusable( aStream.Data() ); |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CMceSrvEndpoint::EventReceived |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 void CMceSrvEndpoint::EventReceived( TMceMccComEvent& aEvent ) |
|
237 { |
|
238 switch( aEvent.iEvent ) |
|
239 { |
|
240 case KMccLinkCreated: |
|
241 { |
|
242 SetState( CMceSrvStream::ELinkCreated ); |
|
243 break; |
|
244 } |
|
245 case KMccStreamPrepared: |
|
246 { |
|
247 SetState( CMceSrvStream::EPrepared ); |
|
248 break; |
|
249 } |
|
250 case KMccStreamStarted: |
|
251 { |
|
252 SetState( CMceSrvStream::EStarted ); |
|
253 break; |
|
254 } |
|
255 case KMccStreamStopped: |
|
256 { |
|
257 SetState( CMceSrvStream::EStopped ); |
|
258 break; |
|
259 } |
|
260 case KMccStreamPaused: |
|
261 { |
|
262 SetState( CMceSrvStream::EPaused ); |
|
263 break; |
|
264 } |
|
265 case KMccStreamResumed: |
|
266 { |
|
267 SetState( CMceSrvStream::EStarted ); |
|
268 break; |
|
269 } |
|
270 case KMccMasterKeyStaled: |
|
271 { |
|
272 TRAPD ( err, HandleSecureEventReceivedL ()); |
|
273 //ignore err |
|
274 err = err != KErrNone ? KErrNone : err; |
|
275 break; |
|
276 } |
|
277 default: |
|
278 { |
|
279 //NOP |
|
280 break; |
|
281 } |
|
282 } |
|
283 } |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CMceSrvEndpoint::Type |
|
287 // ----------------------------------------------------------------------------- |
|
288 // |
|
289 const TUid CMceSrvEndpoint::Type() const |
|
290 { |
|
291 return iData->MccType(); |
|
292 } |
|
293 |
|
294 // ----------------------------------------------------------------------------- |
|
295 // CMceSrvEndpoint::StreamStateChangeEventReceived |
|
296 // ----------------------------------------------------------------------------- |
|
297 // |
|
298 TBool CMceSrvEndpoint::StreamStateChangeEventReceived( TMceMccComEvent& aEvent ) |
|
299 { |
|
300 TBool allowEvent( ETrue ); |
|
301 |
|
302 switch ( aEvent.iEvent ) |
|
303 { |
|
304 case KMccStreamStarted: |
|
305 case KMccStreamResumed: |
|
306 { |
|
307 TMceSrvStreamIterator streams( Data().MediaStream()->Session()->MccStreams(), |
|
308 Data() ); |
|
309 CMceSrvStream* stream = NULL; |
|
310 while ( streams.Next( stream ) && allowEvent ) |
|
311 { |
|
312 if ( stream->Codec().iIsEnabled && |
|
313 Endpoint( *stream ).State() > CMceSrvStream::EPrepared && |
|
314 Endpoint( *stream ).State() != CMceSrvStream::EStarted ) |
|
315 { |
|
316 allowEvent = EFalse; |
|
317 } |
|
318 } |
|
319 break; |
|
320 } |
|
321 case KMccStreamPaused: |
|
322 { |
|
323 TMceSrvStreamIterator streams( Data().MediaStream()->Session()->MccStreams(), |
|
324 Data() ); |
|
325 CMceSrvStream* stream = NULL; |
|
326 while ( streams.Next( stream ) && allowEvent ) |
|
327 { |
|
328 if ( stream->Codec().iIsEnabled && |
|
329 Endpoint( *stream ).State() > CMceSrvStream::EPrepared && |
|
330 Endpoint( *stream ).State() != CMceSrvStream::EPaused ) |
|
331 { |
|
332 allowEvent = EFalse; |
|
333 } |
|
334 } |
|
335 break; |
|
336 } |
|
337 default: |
|
338 { |
|
339 break; |
|
340 } |
|
341 } |
|
342 return allowEvent; |
|
343 } |
|
344 |
|
345 // ----------------------------------------------------------------------------- |
|
346 // CMceSrvEndpoint::EndpointMatch |
|
347 // ----------------------------------------------------------------------------- |
|
348 // |
|
349 TBool CMceSrvEndpoint::EndpointMatch( |
|
350 const CMceComEndpoint& aEndpoint, |
|
351 TBool aUseProxyMatch ) |
|
352 { |
|
353 TBool match( EFalse ); |
|
354 if ( !aUseProxyMatch ) |
|
355 { |
|
356 match = aEndpoint == *iData; |
|
357 } |
|
358 else |
|
359 { |
|
360 match = aEndpoint == *iData || |
|
361 ( aEndpoint.EndpointProxy() && |
|
362 aEndpoint.EndpointProxy()->ServesProxyClient( *iData ) ); |
|
363 |
|
364 } |
|
365 return match; |
|
366 } |
|
367 |
|
368 // End of file |
|
369 |