|
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: mpxplaybackutility stub for testing MpNowPlayingBackEnd |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <mpxplaybackcommanddefs.h> |
|
20 #include <e32debug.h> |
|
21 |
|
22 #include "stub/inc/mpxplaybackutility.h" |
|
23 #include "mpmediakeyhandler_p.h" |
|
24 |
|
25 |
|
26 int gMMPXPlaybackUtilityCount = 0; |
|
27 bool gMMPXPlaybackUtilityNewLLeave = false; |
|
28 bool gMMPXPlaybackUtilityAddObserverLLeave = false; |
|
29 bool gMMPXPlaybackUtilityRemoveObserverLLeave = false; |
|
30 bool gMMPXPlaybackUtilityCommandLLeave = false; |
|
31 bool gMMPXPlaybackUtilityStateLLeave = false; |
|
32 TMPXPlaybackState gMMPXPlaybackUtilityState = EPbStateNotInitialised; |
|
33 |
|
34 |
|
35 //static functions start |
|
36 |
|
37 int MMPXPlaybackUtility::getCount() |
|
38 { |
|
39 return gMMPXPlaybackUtilityCount; |
|
40 } |
|
41 |
|
42 void MMPXPlaybackUtility::setNewLLeave() |
|
43 { |
|
44 gMMPXPlaybackUtilityNewLLeave = true; |
|
45 } |
|
46 |
|
47 void MMPXPlaybackUtility::NewLLeaveIfDesiredL() |
|
48 { |
|
49 if (gMMPXPlaybackUtilityNewLLeave) |
|
50 { |
|
51 RDebug::Print(_L("MMPXPlaybackUtility::NewLLeaveIfDesiredL Leave")); |
|
52 gMMPXPlaybackUtilityNewLLeave = false; |
|
53 User::Leave(KErrGeneral); |
|
54 } |
|
55 } |
|
56 |
|
57 void MMPXPlaybackUtility::setAddObserverLLeave() |
|
58 { |
|
59 gMMPXPlaybackUtilityAddObserverLLeave = true; |
|
60 } |
|
61 |
|
62 void MMPXPlaybackUtility::AddObserverLLeaveIfDesiredL() |
|
63 { |
|
64 if (gMMPXPlaybackUtilityAddObserverLLeave) |
|
65 { |
|
66 RDebug::Print(_L("MMPXPlaybackUtility::AddObserverLLeaveIfDesiredL Leave")); |
|
67 gMMPXPlaybackUtilityAddObserverLLeave = false; |
|
68 User::Leave(KErrGeneral); |
|
69 } |
|
70 } |
|
71 |
|
72 void MMPXPlaybackUtility::setRemoveObserverLLeave() |
|
73 { |
|
74 gMMPXPlaybackUtilityRemoveObserverLLeave = true; |
|
75 } |
|
76 |
|
77 void MMPXPlaybackUtility::RemoveObserverLLeaveIfDesiredL() |
|
78 { |
|
79 if (gMMPXPlaybackUtilityRemoveObserverLLeave) |
|
80 { |
|
81 RDebug::Print(_L("MMPXPlaybackUtility::RemoveObserverLLeaveIfDesiredL Leave")); |
|
82 gMMPXPlaybackUtilityRemoveObserverLLeave = false; |
|
83 User::Leave(KErrGeneral); |
|
84 } |
|
85 } |
|
86 |
|
87 void MMPXPlaybackUtility::setCommandLLeave() |
|
88 { |
|
89 gMMPXPlaybackUtilityCommandLLeave = true; |
|
90 } |
|
91 |
|
92 void MMPXPlaybackUtility::CommandLLeaveIfDesiredL() |
|
93 { |
|
94 if (gMMPXPlaybackUtilityCommandLLeave) |
|
95 { |
|
96 RDebug::Print(_L("MMPXPlaybackUtility::CommandLLeaveIfDesiredL Leave")); |
|
97 gMMPXPlaybackUtilityCommandLLeave = false; |
|
98 User::Leave(KErrGeneral); |
|
99 } |
|
100 } |
|
101 |
|
102 void MMPXPlaybackUtility::setStateLLeave() |
|
103 { |
|
104 gMMPXPlaybackUtilityStateLLeave = true; |
|
105 } |
|
106 |
|
107 void MMPXPlaybackUtility::StateLLeaveIfDesiredL() |
|
108 { |
|
109 if (gMMPXPlaybackUtilityStateLLeave) |
|
110 { |
|
111 RDebug::Print(_L("MMPXPlaybackUtility::StateLLeaveIfDesiredL Leave")); |
|
112 gMMPXPlaybackUtilityStateLLeave = false; |
|
113 User::Leave(KErrGeneral); |
|
114 } |
|
115 } |
|
116 |
|
117 void MMPXPlaybackUtility::setPlaying() |
|
118 { |
|
119 gMMPXPlaybackUtilityState = EPbStatePlaying; |
|
120 } |
|
121 |
|
122 //static functions end |
|
123 |
|
124 MMPXPlaybackUtility::MMPXPlaybackUtility() |
|
125 : CActive(EPriorityStandard), |
|
126 iObserver(NULL), |
|
127 iVolume(5), |
|
128 iVolumeUp(ETrue) |
|
129 { |
|
130 gMMPXPlaybackUtilityState = EPbStateNotInitialised; |
|
131 } |
|
132 |
|
133 MMPXPlaybackUtility::~MMPXPlaybackUtility() |
|
134 { |
|
135 } |
|
136 |
|
137 MMPXPlaybackUtility* MMPXPlaybackUtility::UtilityL(const TUid& /*aModeId*/) |
|
138 { |
|
139 RDebug::Print(_L("stub MMPXPlaybackUtility::UtilityL")); |
|
140 MMPXPlaybackUtility::NewLLeaveIfDesiredL(); |
|
141 gMMPXPlaybackUtilityCount++; |
|
142 static MMPXPlaybackUtility playbackUtilility; |
|
143 return &playbackUtilility; |
|
144 } |
|
145 |
|
146 void MMPXPlaybackUtility::Close() |
|
147 { |
|
148 iObserver = NULL; |
|
149 gMMPXPlaybackUtilityCount--; |
|
150 } |
|
151 |
|
152 void MMPXPlaybackUtility::AddObserverL(MpMediaKeyHandlerPrivate& aObs) |
|
153 { |
|
154 MMPXPlaybackUtility::AddObserverLLeaveIfDesiredL(); |
|
155 iObserver = &aObs; |
|
156 } |
|
157 |
|
158 void MMPXPlaybackUtility::RemoveObserverL(MpMediaKeyHandlerPrivate& /*aObs*/) |
|
159 { |
|
160 MMPXPlaybackUtility::RemoveObserverLLeaveIfDesiredL(); |
|
161 iObserver = NULL; |
|
162 } |
|
163 |
|
164 void MMPXPlaybackUtility::CommandL(TMPXPlaybackCommand aCmd, TInt /*aData*/) |
|
165 { |
|
166 RDebug::Print(_L(">>MMPXPlaybackUtility::CommandL")); |
|
167 |
|
168 MMPXPlaybackUtility::CommandLLeaveIfDesiredL(); |
|
169 |
|
170 if (IsActive()) |
|
171 User::Leave(KErrNotReady); |
|
172 else |
|
173 { |
|
174 if ((aCmd == EPbCmdIncreaseVolume) || (aCmd == EPbCmdDecreaseVolume)) |
|
175 { |
|
176 if (aCmd == EPbCmdIncreaseVolume) |
|
177 iVolumeUp = ETrue; |
|
178 else |
|
179 iVolumeUp = EFalse; |
|
180 |
|
181 // stub should not be async |
|
182 /*TRequestStatus* status = &iStatus; |
|
183 User::RequestComplete(status, KErrNone); |
|
184 SetActive();*/ |
|
185 |
|
186 RunL(); |
|
187 } |
|
188 } |
|
189 |
|
190 RDebug::Print(_L("<<MMPXPlaybackUtility::CommandL")); |
|
191 } |
|
192 |
|
193 TMPXPlaybackState MMPXPlaybackUtility::StateL() const |
|
194 { |
|
195 MMPXPlaybackUtility::StateLLeaveIfDesiredL(); |
|
196 return gMMPXPlaybackUtilityState; |
|
197 } |
|
198 |
|
199 void MMPXPlaybackUtility::DoCancel() |
|
200 { |
|
201 } |
|
202 |
|
203 void MMPXPlaybackUtility::RunL() |
|
204 { |
|
205 RDebug::Print(_L(">>MMPXPlaybackUtility::RunL")); |
|
206 |
|
207 TInt err = KErrNone; |
|
208 |
|
209 if (iVolumeUp) |
|
210 { |
|
211 if (iVolume < 10) |
|
212 iVolume++; |
|
213 else |
|
214 err = KErrArgument; |
|
215 } |
|
216 else |
|
217 { |
|
218 if (iVolume > 0) |
|
219 iVolume--; |
|
220 else |
|
221 err = KErrArgument; |
|
222 } |
|
223 |
|
224 if (iObserver) |
|
225 iObserver->HandlePropertyL(EPbPropertyVolume, iVolume, err); |
|
226 |
|
227 RDebug::Print(_L("<<MMPXPlaybackUtility::RunL")); |
|
228 } |
|
229 |
|
230 //end of file |