1 /* |
|
2 * Copyright (c) 2009 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: mpxplaybackutility stub for testing MpNowPlayingBackEnd |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <Qt> |
|
19 #include <mpxplaybackobserver.h> |
|
20 #include <mpxmessagegeneraldefs.h> |
|
21 #include <mpxmediageneraldefs.h> |
|
22 #include <mpxmediamusicdefs.h> |
|
23 |
|
24 #include "stub/inc/mpxplaybackutility.h" |
|
25 |
|
26 bool gLeaveMediaL = false; |
|
27 int gMediaCounter = 0; |
|
28 |
|
29 bool gLeaveUtilityL = false; |
|
30 bool gLeaveAddObserverL = false; |
|
31 bool gLeaveRemoveObserverL = false; |
|
32 bool gLeaveCommandL = false; |
|
33 bool gLeaveStateL = false; |
|
34 int gUtilCloseCounter = 0; |
|
35 int gRemoveObserverCounter = 0; |
|
36 bool gSourceExists = true; |
|
37 TMPXPlaybackState gPlaybackState = EPbStateStopped; |
|
38 |
|
39 // Constants |
|
40 _LIT( KTitle, "Title" ); |
|
41 _LIT( KUri, "Uri" ); |
|
42 _LIT( KArtist, "Artist" ); |
|
43 |
|
44 /*! |
|
45 Stub constructor. |
|
46 */ |
|
47 MMPXSource::MMPXSource() |
|
48 { |
|
49 } |
|
50 |
|
51 /*! |
|
52 Stub destructor. |
|
53 */ |
|
54 MMPXSource::~MMPXSource() |
|
55 { |
|
56 } |
|
57 |
|
58 /*! |
|
59 Sets gLeaveMediaL. |
|
60 If true MMPXSource::MediaL leaves. |
|
61 */ |
|
62 void MMPXSource::setMediaLeave(bool leave) |
|
63 { |
|
64 gLeaveMediaL = leave; |
|
65 } |
|
66 |
|
67 /*! |
|
68 Returns gMediaCounter. |
|
69 gMediaCounter counts the number of MMPXSource::MediaL calls. |
|
70 */ |
|
71 int MMPXSource::getMediaCounter() |
|
72 { |
|
73 return gMediaCounter; |
|
74 } |
|
75 |
|
76 /*! |
|
77 Resets gMediaCounter to zero. |
|
78 */ |
|
79 void MMPXSource::resetMediaCounter() |
|
80 { |
|
81 gMediaCounter = 0; |
|
82 } |
|
83 |
|
84 /*! |
|
85 Causes callback to observer. |
|
86 \sa MMPXSource::MediaL |
|
87 */ |
|
88 void MMPXSource::sendHandleMediaL(bool title, bool uri, bool artist) |
|
89 { |
|
90 CMPXMedia* media = CMPXMedia::NewL(); |
|
91 CleanupStack::PushL(media); |
|
92 if ( title ) { |
|
93 media->SetTextValueL(KMPXMediaGeneralTitle, KTitle); |
|
94 } |
|
95 if ( uri ) { |
|
96 media->SetTextValueL(KMPXMediaGeneralUri, KUri); |
|
97 } |
|
98 if ( artist ) { |
|
99 media->SetTextValueL(KMPXMediaMusicArtist, KArtist); |
|
100 } |
|
101 iObserver->HandleMediaL(*media, KErrNone); |
|
102 CleanupStack::PopAndDestroy( media ); |
|
103 } |
|
104 |
|
105 /*! |
|
106 Sets the observer |
|
107 \sa MMPXSource::sendHandleMediaL. |
|
108 */ |
|
109 void MMPXSource::setObserver(MMPXPlaybackCallback* obs) |
|
110 { |
|
111 iObserver = obs; |
|
112 } |
|
113 |
|
114 /*! |
|
115 Stub function. |
|
116 */ |
|
117 void MMPXSource::MediaL(const TArray<TMPXAttribute>& aAttrs, MMPXPlaybackCallback& aCallback) |
|
118 { |
|
119 Q_UNUSED(aAttrs); |
|
120 if (gLeaveMediaL) { |
|
121 User::Leave(KErrGeneral); |
|
122 } |
|
123 iObserver = &aCallback; |
|
124 gMediaCounter++; |
|
125 } |
|
126 |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // ----------------------------------------------------------------------------- |
|
130 |
|
131 |
|
132 /*! |
|
133 Stub constructor. |
|
134 */ |
|
135 MMPXPlaybackUtility::MMPXPlaybackUtility() |
|
136 { |
|
137 } |
|
138 |
|
139 /*! |
|
140 Stub destructor. |
|
141 */ |
|
142 MMPXPlaybackUtility::~MMPXPlaybackUtility() |
|
143 { |
|
144 } |
|
145 |
|
146 /*! |
|
147 Sets gLeaveUtilityL. |
|
148 If true MMPXPlaybackUtility::UtilityL leaves. |
|
149 */ |
|
150 void MMPXPlaybackUtility::setUtilityLeave(bool leave) |
|
151 { |
|
152 gLeaveUtilityL = leave; |
|
153 } |
|
154 |
|
155 /*! |
|
156 Sets gLeaveAddObserverL. |
|
157 If true MMPXPlaybackUtility::AddObserverL leaves. |
|
158 */ |
|
159 void MMPXPlaybackUtility::setAddObserverLeave(bool leave) |
|
160 { |
|
161 gLeaveAddObserverL = leave; |
|
162 } |
|
163 |
|
164 /*! |
|
165 Sets gLeaveRemoveObserverL. |
|
166 If true MMPXPlaybackUtility::RemoveObserverL leaves. |
|
167 */ |
|
168 void MMPXPlaybackUtility::setRemoveObserverLeave(bool leave) |
|
169 { |
|
170 gLeaveRemoveObserverL = leave; |
|
171 } |
|
172 |
|
173 /*! |
|
174 Sets gLeaveCommandL. |
|
175 If true MMPXPlaybackUtility::CommandL leaves. |
|
176 */ |
|
177 void MMPXPlaybackUtility::setCommandLeave(bool leave) |
|
178 { |
|
179 gLeaveCommandL = leave; |
|
180 } |
|
181 |
|
182 /*! |
|
183 Sets gLeaveStateL. |
|
184 If true MMPXPlaybackUtility::StateL leaves. |
|
185 */ |
|
186 void MMPXPlaybackUtility::setStateLeave(bool leave) |
|
187 { |
|
188 gLeaveStateL = leave; |
|
189 } |
|
190 |
|
191 /*! |
|
192 Returns gUtilCloseCounter. |
|
193 gUtilCloseCounter counts the number of MMPXPlaybackUtility::Close calls. |
|
194 */ |
|
195 int MMPXPlaybackUtility::getCloseCounter() |
|
196 { |
|
197 return gUtilCloseCounter; |
|
198 } |
|
199 |
|
200 /*! |
|
201 Resets gUtilCloseCounter to zero. |
|
202 */ |
|
203 void MMPXPlaybackUtility::resetCloseCounter() |
|
204 { |
|
205 gUtilCloseCounter = 0; |
|
206 } |
|
207 |
|
208 /*! |
|
209 Returns gRemoveObserverCounter. |
|
210 gRemoveObserverCounter counts the number of MMPXPlaybackUtility::RemoveObserverL calls. |
|
211 */ |
|
212 int MMPXPlaybackUtility::getRemoveObserverCounter() |
|
213 { |
|
214 return gRemoveObserverCounter; |
|
215 } |
|
216 |
|
217 /*! |
|
218 Resets gRemoveObserverCounter to zero. |
|
219 */ |
|
220 void MMPXPlaybackUtility::resetRemoveObserverCounter() |
|
221 { |
|
222 gRemoveObserverCounter = 0; |
|
223 } |
|
224 |
|
225 /*! |
|
226 Sets gSourceExists. |
|
227 If true MMPXPlaybackUtility::Source returns valid pointer. |
|
228 */ |
|
229 void MMPXPlaybackUtility::setSource(bool exist) |
|
230 { |
|
231 gSourceExists = exist; |
|
232 } |
|
233 |
|
234 /*! |
|
235 Sets gPlaybackState. |
|
236 \sa MMPXPlaybackUtility::getState() |
|
237 \sa MMPXPlaybackUtility::StateL() |
|
238 */ |
|
239 void MMPXPlaybackUtility::setState(TMPXPlaybackState state) |
|
240 { |
|
241 gPlaybackState = state; |
|
242 } |
|
243 |
|
244 /*! |
|
245 Gets gPlaybackState. |
|
246 \sa MMPXPlaybackUtility::setState() |
|
247 */ |
|
248 TMPXPlaybackState MMPXPlaybackUtility::getState() |
|
249 { |
|
250 return gPlaybackState; |
|
251 } |
|
252 |
|
253 /*! |
|
254 Causes callback to observer. |
|
255 */ |
|
256 void MMPXPlaybackUtility::sendHandlePlaybackMessage(TMPXPlaybackMessage::TEvent event) |
|
257 { |
|
258 CMPXMessage* msg = CMPXMessage::NewL(); |
|
259 CleanupStack::PushL(msg); |
|
260 TMPXMessageId id=static_cast<TMPXMessageId>(KMPXMessageGeneral); |
|
261 msg->SetTObjectValueL<TMPXMessageId>(KMPXMessageGeneralId, id); |
|
262 msg->SetTObjectValueL<TInt>(KMPXMessageGeneralEvent, event); |
|
263 iObserver->HandlePlaybackMessage(msg, KErrNone); |
|
264 CleanupStack::PopAndDestroy( msg ); |
|
265 } |
|
266 |
|
267 /*! |
|
268 Stub function. |
|
269 */ |
|
270 MMPXPlaybackUtility* MMPXPlaybackUtility::UtilityL(const TUid& aModeId) |
|
271 { |
|
272 Q_UNUSED(aModeId); |
|
273 if (gLeaveUtilityL) { |
|
274 User::Leave(KErrGeneral); |
|
275 } |
|
276 static MMPXPlaybackUtility playbackUtilility; |
|
277 return &playbackUtilility; |
|
278 } |
|
279 |
|
280 /*! |
|
281 Stub function. |
|
282 */ |
|
283 void MMPXPlaybackUtility::AddObserverL(MMPXPlaybackObserver& aObs) |
|
284 { |
|
285 if (gLeaveAddObserverL) { |
|
286 User::Leave(KErrGeneral); |
|
287 } |
|
288 iObserver = &aObs; |
|
289 } |
|
290 |
|
291 /*! |
|
292 Stub function. |
|
293 */ |
|
294 void MMPXPlaybackUtility::RemoveObserverL(MMPXPlaybackObserver& aObs) |
|
295 { |
|
296 Q_UNUSED(aObs); |
|
297 if (gLeaveRemoveObserverL) { |
|
298 User::Leave(KErrGeneral); |
|
299 } |
|
300 gRemoveObserverCounter++; |
|
301 } |
|
302 |
|
303 /*! |
|
304 Stub function. |
|
305 */ |
|
306 void MMPXPlaybackUtility::Close() |
|
307 { |
|
308 gUtilCloseCounter++; |
|
309 } |
|
310 |
|
311 /*! |
|
312 Stub function. |
|
313 */ |
|
314 void MMPXPlaybackUtility::CommandL(TMPXPlaybackCommand aCmd, TInt aData) |
|
315 { |
|
316 Q_UNUSED(aCmd); |
|
317 Q_UNUSED(aData); |
|
318 if (gLeaveCommandL) { |
|
319 User::Leave(KErrGeneral); |
|
320 } |
|
321 if ( gPlaybackState == EPbStatePlaying ) { |
|
322 gPlaybackState = EPbStatePaused; |
|
323 } |
|
324 else { |
|
325 gPlaybackState = EPbStatePlaying; |
|
326 } |
|
327 } |
|
328 |
|
329 /*! |
|
330 Stub function. |
|
331 */ |
|
332 TMPXPlaybackState MMPXPlaybackUtility::StateL() const |
|
333 { |
|
334 if (gLeaveStateL) { |
|
335 User::Leave(KErrGeneral); |
|
336 } |
|
337 return gPlaybackState; |
|
338 } |
|
339 |
|
340 /*! |
|
341 Stub function. |
|
342 */ |
|
343 MMPXSource* MMPXPlaybackUtility::Source() |
|
344 { |
|
345 if ( gSourceExists ) { |
|
346 return &iSource; |
|
347 } |
|
348 else { |
|
349 return 0; |
|
350 } |
|
351 } |
|
352 |
|