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: Base class for control groups |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <logger.h> |
|
21 #include "cammscontrolgroup.h" |
|
22 #include <cmmaplayer.h> |
|
23 #include "cammscontrol.h" |
|
24 #include "ammsutil.h" |
|
25 #include "cammsplayerstatelistener.h" |
|
26 |
|
27 #ifdef _DEBUG |
|
28 _LIT(KAMMSNoGroupNameError, "No group name"); |
|
29 #endif |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CAMMSControlGroup::~CAMMSControlGroup |
|
35 // Destructor. |
|
36 // (other items were commented in a header). |
|
37 // ----------------------------------------------------------------------------- |
|
38 CAMMSControlGroup::~CAMMSControlGroup() |
|
39 { |
|
40 if (iPlayerStateListeners) |
|
41 { |
|
42 iPlayerStateListeners->ResetAndDestroy(); |
|
43 delete iPlayerStateListeners; |
|
44 } |
|
45 |
|
46 iControls.Close(); |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CAMMSControlGroup::PlayerStateChangedL |
|
51 // This function is called when state of a player has changed. |
|
52 // (other items were commented in a header). |
|
53 // ----------------------------------------------------------------------------- |
|
54 void CAMMSControlGroup::PlayerStateChangedL( |
|
55 CMMAPlayer* aPlayer, |
|
56 TInt aNewState) |
|
57 { |
|
58 CMMAControl* findControl = AMMSUtil::FindControl( |
|
59 aPlayer, iName, iControlType); |
|
60 |
|
61 // It is safe to cast CMMAControl to the subclass CAMMSControl, as only |
|
62 // AMMS Controls are returned from FindControl method |
|
63 CAMMSControl* control = static_cast< CAMMSControl* >(findControl); |
|
64 |
|
65 // The player has a control belonging to this group if this function |
|
66 // is called. |
|
67 __ASSERT_DEBUG(control, User::Invariant()); |
|
68 |
|
69 TInt controlIndex = iControls.Find(control); |
|
70 |
|
71 // Add the control of the player to the group if the player is prefetched |
|
72 // or started. |
|
73 if (controlIndex == KErrNotFound) |
|
74 { |
|
75 if ((aNewState == CMMAPlayer::EPrefetched) || |
|
76 (aNewState == CMMAPlayer::EStarted)) |
|
77 { |
|
78 // Now it is safe to call PrepareControlL to initialize the Control |
|
79 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSControlGroup::PlayerStateChangedL calling PrepareControl for type: %d", |
|
80 control->iControlType); |
|
81 control->PrepareControlL(); |
|
82 |
|
83 // Add control to controls array |
|
84 User::LeaveIfError(iControls.Append(control)); |
|
85 |
|
86 // Notify derived classes about new player control |
|
87 NotifyPlayerAddedL(aPlayer, control); |
|
88 } |
|
89 } |
|
90 |
|
91 // Remove the control of the player from the group if the player is |
|
92 // deallocated or closed. |
|
93 else |
|
94 { |
|
95 if ((aNewState == CMMAPlayer::ERealized) || |
|
96 (aNewState == CMMAPlayer::EClosed)) |
|
97 { |
|
98 // Call DeallocateControl to delete the Control's Effect API class |
|
99 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSControlGroup::PlayerStateChangedL calling DeallocateControl for type: %d", |
|
100 control->iControlType); |
|
101 control->DeallocateControl(); |
|
102 |
|
103 NotifyPlayerRemoved(aPlayer, control); |
|
104 iControls.Remove(controlIndex); |
|
105 } |
|
106 } |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CAMMSControlGroup::ConstructL |
|
111 // 2nd phase constructor. |
|
112 // (other items were commented in a header). |
|
113 // ----------------------------------------------------------------------------- |
|
114 void CAMMSControlGroup::ConstructL() |
|
115 { |
|
116 iPlayerStateListeners = |
|
117 new(ELeave) CArrayPtrSeg< CAMMSPlayerStateListener >(1); |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CAMMSControlGroup::ControlCount |
|
122 // Returns the total count of controls in this group. |
|
123 // (other items were commented in a header). |
|
124 // ----------------------------------------------------------------------------- |
|
125 TInt CAMMSControlGroup::ControlCount() const |
|
126 { |
|
127 return iControls.Count(); |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CAMMSControlGroup::Control |
|
132 // Gets control. Ownership is not tranferred. |
|
133 // (other items were commented in a header). |
|
134 // ----------------------------------------------------------------------------- |
|
135 CMMAControl* CAMMSControlGroup::Control(TInt aIndex) const |
|
136 { |
|
137 // aIndex must not be negative and must not be greater than the number |
|
138 // of objects currently in the array, |
|
139 // otherwise the operator raises a USER-130 panic. |
|
140 return iControls[ aIndex ]; |
|
141 } |
|
142 |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CAMMSControlGroup::NotifyPlayerRemoved |
|
146 // Called by PlayerAddedL when new player is added |
|
147 // (other items were commented in a header). |
|
148 // ----------------------------------------------------------------------------- |
|
149 void CAMMSControlGroup::NotifyPlayerAddedL( |
|
150 CMMAPlayer* /*aPlayer*/, |
|
151 CMMAControl* /*aControl*/) |
|
152 { |
|
153 } |
|
154 |
|
155 // ----------------------------------------------------------------------------- |
|
156 // CAMMSControlGroup::NotifyPlayerRemoved |
|
157 // Called by PlayerRemoved when a player is removed |
|
158 // (other items were commented in a header). |
|
159 // ----------------------------------------------------------------------------- |
|
160 void CAMMSControlGroup::NotifyPlayerRemoved( |
|
161 CMMAPlayer* /*aPlayer*/, |
|
162 CMMAControl* /*aControl*/) |
|
163 { |
|
164 } |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CAMMSControlGroup::PlayerAddedL |
|
168 // Called by the owning module when a player is added |
|
169 // (other items were commented in a header). |
|
170 // ----------------------------------------------------------------------------- |
|
171 void CAMMSControlGroup::PlayerAddedL(CMMAPlayer *aPlayer) |
|
172 { |
|
173 // All derived classes must define name for the group |
|
174 __ASSERT_DEBUG(iName != KNullDesC, |
|
175 User::Panic(KAMMSNoGroupNameError, |
|
176 KErrUnknown)); |
|
177 |
|
178 // Do nothing if the player does not have a control belonging to this group. |
|
179 CMMAControl* findControl = AMMSUtil::FindControl( |
|
180 aPlayer, iName, iControlType); |
|
181 if (!findControl) |
|
182 { |
|
183 return; |
|
184 } |
|
185 |
|
186 // It is safe to cast CMMAControl to the subclass CAMMSControl, as only |
|
187 // AMMS Controls are returned from FindControl method |
|
188 CAMMSControl* control = static_cast< CAMMSControl* >(findControl); |
|
189 |
|
190 CAMMSPlayerStateListener* playerListener = |
|
191 CAMMSPlayerStateListener::NewLC(aPlayer, this); |
|
192 |
|
193 iPlayerStateListeners->AppendL(playerListener); |
|
194 |
|
195 CleanupStack::Pop(playerListener); |
|
196 |
|
197 // Add the control of the player directly to the group |
|
198 // if the player is in STARTED or PREFETCHED state. |
|
199 // If not, the control is added later when the player changes |
|
200 // its state to PREFETCHED. |
|
201 TInt playerState = aPlayer->State(); |
|
202 |
|
203 if ((playerState == CMMAPlayer::EPrefetched) || |
|
204 (playerState == CMMAPlayer::EStarted)) |
|
205 { |
|
206 // Now it is safe to call PrepareControlL to initialize the Control |
|
207 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSControlGroup::PlayerAddedL calling PrepareControl for type: %d", |
|
208 control->iControlType); |
|
209 control->PrepareControlL(); |
|
210 |
|
211 // Add control to controls array |
|
212 User::LeaveIfError(iControls.Append(control)); |
|
213 |
|
214 // Notify derived classes about new player control |
|
215 NotifyPlayerAddedL(aPlayer, control); |
|
216 } |
|
217 } |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CAMMSControlGroup::PlayerRemoved |
|
221 // Called by the owning module when a player is removed |
|
222 // (other items were commented in a header). |
|
223 // ----------------------------------------------------------------------------- |
|
224 void CAMMSControlGroup::PlayerRemoved(CMMAPlayer *aPlayer) |
|
225 { |
|
226 CMMAControl* control = AMMSUtil::FindControl( |
|
227 aPlayer, iName, iControlType); |
|
228 |
|
229 // Do nothing if the player does not have a control belonging to this group. |
|
230 if (!control) |
|
231 { |
|
232 return; |
|
233 } |
|
234 |
|
235 // Remove the control of the player if the control is in the group. |
|
236 TInt controlIndex = iControls.Find(control); |
|
237 if (controlIndex != KErrNotFound) |
|
238 { |
|
239 // It is safe to cast CMMAControl to the subclass CAMMSControl, as only |
|
240 // AMMS Controls are returned from FindControl method |
|
241 CAMMSControl* ammsControl = static_cast< CAMMSControl* >(control); |
|
242 |
|
243 // Call DeallocateControl to delete the Control's Effect API class |
|
244 LOG1( EJavaAMMS, EInfo, "AMMS::CAMMSControlGroup::PlayerRemoved calling DeallocateControl for type: %d", |
|
245 ammsControl->iControlType); |
|
246 ammsControl->DeallocateControl(); |
|
247 |
|
248 NotifyPlayerRemoved(aPlayer, ammsControl); |
|
249 iControls.Remove(controlIndex); |
|
250 } |
|
251 |
|
252 // Remove the state listener belonging to the given player. |
|
253 |
|
254 TInt listenerCount = iPlayerStateListeners->Count(); |
|
255 TInt listenerIndex = KErrNotFound; |
|
256 |
|
257 for (TInt i = 0; i < listenerCount; i++) |
|
258 { |
|
259 // Elements in the listener array are never null. |
|
260 if (iPlayerStateListeners->At(i)->Player() == aPlayer) |
|
261 { |
|
262 listenerIndex = i; |
|
263 break; |
|
264 } |
|
265 } |
|
266 |
|
267 if (listenerIndex != KErrNotFound) |
|
268 { |
|
269 delete iPlayerStateListeners->At(listenerIndex); |
|
270 iPlayerStateListeners->Delete(listenerIndex); |
|
271 } |
|
272 } |
|
273 |
|
274 // ----------------------------------------------------------------------------- |
|
275 // CAMMSControlGroup::CAMMSControlGroup |
|
276 // C++ default constructor can NOT contain any code, that might leave. |
|
277 // ----------------------------------------------------------------------------- |
|
278 CAMMSControlGroup::CAMMSControlGroup( |
|
279 const TDesC& aName, |
|
280 TAMMSControlTypes aControlType) : |
|
281 iName(aName), |
|
282 iControlType(aControlType) |
|
283 { |
|
284 } |
|
285 |
|
286 // End of File |
|