|
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: |
|
15 * CPDEngine class implementation. |
|
16 * |
|
17 */ |
|
18 |
|
19 // SYSTEM INCLUDES |
|
20 #include <AsyCmdTypes.h> |
|
21 |
|
22 // USER INCLUDES |
|
23 #include "pdengine.h" |
|
24 #include "compositecablestatusfsm.h" |
|
25 #include "hdmicablestatusfsm.h" |
|
26 #include "trace.h" |
|
27 |
|
28 // ======== MEMBER FUNCTIONS ======== |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // Symbian two phased constructor. |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 EXPORT_C CPDEngine* CPDEngine::NewL( RAccessoryServer& aAccessoryServer ) |
|
35 { |
|
36 FUNC_LOG; |
|
37 |
|
38 CPDEngine* self = CPDEngine::NewLC( aAccessoryServer ); |
|
39 CleanupStack::Pop( self ); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // Symbian two phased constructor. |
|
45 // Leaves pointer in the cleanup stack. |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 EXPORT_C CPDEngine* CPDEngine::NewLC( RAccessoryServer& aAccessoryServer ) |
|
49 { |
|
50 FUNC_LOG; |
|
51 |
|
52 CPDEngine* self = new ( ELeave ) CPDEngine(); |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL( aAccessoryServer ); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // C++ destructor. |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 CPDEngine::~CPDEngine() |
|
63 { |
|
64 FUNC_LOG; |
|
65 // Delete FSM objects |
|
66 for (TInt i = 0; i < EPDEFSMIdFirstUnused; i++ ) |
|
67 { |
|
68 delete iFSMPtr[i]; |
|
69 } |
|
70 } |
|
71 |
|
72 //------------------------------------------------------------------------------ |
|
73 // CPDEngine::ProcessCommandL |
|
74 //------------------------------------------------------------------------------ |
|
75 // |
|
76 EXPORT_C void CPDEngine::ProcessCommandL( const TProcessCmdId aCommand, |
|
77 const TASYCmdParams& aCmdParams, |
|
78 MPDAsyCmdHandler& aAsyCmdHandler ) |
|
79 { |
|
80 FUNC_LOG; |
|
81 for (TInt i = 0; i < EPDEFSMIdFirstUnused; i++ ) |
|
82 { |
|
83 TBool commandHandled = iFSMPtr[i]->ProcessCommandL( |
|
84 aCommand, |
|
85 aCmdParams, |
|
86 aAsyCmdHandler ); |
|
87 if ( commandHandled ) |
|
88 { |
|
89 break; |
|
90 } |
|
91 } |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // From MFSMBody. |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 TFSMState CPDEngine::CurrentStateID( TFSMId aFSMId ) |
|
99 { |
|
100 FUNC_LOG; |
|
101 TFSMState currentStateId( 0 ); |
|
102 if ( ( 0 <= aFSMId ) && |
|
103 ( EPDEFSMIdFirstUnused > aFSMId )) |
|
104 { |
|
105 if (iFSMPtr[ aFSMId ]) |
|
106 { |
|
107 currentStateId = iFSMPtr[ aFSMId ]->CurrentStateID(); |
|
108 } |
|
109 } |
|
110 INFO_1( "currentStateId %i", currentStateId ); |
|
111 return currentStateId; |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // From MFSMBody. |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 void CPDEngine::Input( |
|
119 TFSMId aFSMId, |
|
120 TFSMInterfaceId aInterfaceId, |
|
121 TFSMEventId aEvent ) |
|
122 { |
|
123 FUNC_LOG; |
|
124 if ( ( 0 <= aFSMId ) && |
|
125 ( EPDEFSMIdFirstUnused > aFSMId ) ) |
|
126 { |
|
127 if(EPDEFSMIdHDMICableStatus == aFSMId) |
|
128 { |
|
129 if( iFSMPtr[EPDEFSMIdCompositeCableStatus]->CurrentStateID() != ECompositeCableStateIdle ) |
|
130 { |
|
131 // Forcefully transit CompositeCable FSM to Idle state |
|
132 ((CCompositeCableStatusFSM*)iFSMPtr[EPDEFSMIdCompositeCableStatus])->Transit(ECompositeCableStateIdle); |
|
133 } |
|
134 iFSMPtr[ aFSMId ]->Input( aInterfaceId, aEvent ); |
|
135 } |
|
136 else if( ( EPDEFSMIdCompositeCableStatus == aFSMId ) |
|
137 && ( iFSMPtr[EPDEFSMIdHDMICableStatus]->CurrentStateID() != EHDMICableStateConnected ) ) |
|
138 { |
|
139 iFSMPtr[ aFSMId ]->Input( aInterfaceId, aEvent ); |
|
140 } |
|
141 } |
|
142 return; |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // From MFSMBody. |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 MFSMState* CPDEngine::CurrentState( TFSMId aFSMId ) |
|
150 { |
|
151 FUNC_LOG; |
|
152 MFSMState* currentState( NULL ); |
|
153 if ( ( 0 <= aFSMId ) && |
|
154 ( EPDEFSMIdFirstUnused > aFSMId )) |
|
155 { |
|
156 if (iFSMPtr[ aFSMId ]) |
|
157 { |
|
158 currentState = iFSMPtr[ aFSMId ]->CurrentState(); |
|
159 } |
|
160 } |
|
161 return currentState; |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // From MFSMBody. |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 MFSMForBody* CPDEngine::GetFSM( TFSMId aFSMId ) |
|
169 { |
|
170 FUNC_LOG; |
|
171 MFSMForBody* fsmPtr( NULL ); |
|
172 if ( ( 0 <= aFSMId ) && |
|
173 ( EPDEFSMIdFirstUnused > aFSMId )) |
|
174 { |
|
175 fsmPtr = iFSMPtr[ aFSMId ]; |
|
176 } |
|
177 return fsmPtr; |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // From MFSMBody. |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 TFSMMainAndSubState CPDEngine::CurrentMainAndSubstateIDs( TFSMId aFSMId ) |
|
185 { |
|
186 FUNC_LOG; |
|
187 TFSMMainAndSubState states; |
|
188 if ( ( 0 <= aFSMId ) && |
|
189 ( EPDEFSMIdFirstUnused > aFSMId )) |
|
190 { |
|
191 states = iFSMPtr[ aFSMId ]->CurrentMainAndSubstateIDs(); |
|
192 } |
|
193 return states; |
|
194 } |
|
195 |
|
196 |
|
197 // --------------------------------------------------------------------------- |
|
198 // From MFSMBody. |
|
199 // --------------------------------------------------------------------------- |
|
200 // |
|
201 TPtrC CPDEngine::CurrentStateName( TFSMId aFSMId ) |
|
202 { |
|
203 FUNC_LOG; |
|
204 TPtrC currentStateName; |
|
205 currentStateName.Set( KNullDesC ); |
|
206 if ( ( 0 <= aFSMId ) && |
|
207 ( EPDEFSMIdFirstUnused > aFSMId )) |
|
208 { |
|
209 if (iFSMPtr[ aFSMId ]) |
|
210 { |
|
211 currentStateName.Set( iFSMPtr[ aFSMId ]->CurrentStateName() ); |
|
212 } |
|
213 } |
|
214 return currentStateName; |
|
215 } |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // From MFSMBody. |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 void CPDEngine::Start() |
|
222 { |
|
223 FUNC_LOG; |
|
224 // Start FSMs |
|
225 for (TInt i = 0; i < EPDEFSMIdFirstUnused; i++ ) |
|
226 { |
|
227 if (iFSMPtr[i]) |
|
228 { |
|
229 iFSMPtr[i]->Start(); |
|
230 } |
|
231 } |
|
232 return; |
|
233 } |
|
234 |
|
235 // --------------------------------------------------------------------------- |
|
236 // CPDEngine::GetUniqueID |
|
237 // --------------------------------------------------------------------------- |
|
238 // |
|
239 TInt CPDEngine::GetAccPolGenericID( |
|
240 TFSMId aFSMId, |
|
241 TAccPolGenericID& aAccPolGenericID ) |
|
242 { |
|
243 FUNC_LOG; |
|
244 TInt retVal( KErrNotFound ); |
|
245 if ( ( 0 <= aFSMId ) && |
|
246 ( EPDEFSMIdFirstUnused > aFSMId )) |
|
247 { |
|
248 retVal = iFSMPtr[ EPDEFSMIdHDMICableStatus ]->GetAccPolGenericID( aAccPolGenericID ); |
|
249 } |
|
250 return retVal; |
|
251 } |
|
252 |
|
253 // --------------------------------------------------------------------------- |
|
254 // C++ constructor. |
|
255 // --------------------------------------------------------------------------- |
|
256 // |
|
257 CPDEngine::CPDEngine() |
|
258 { |
|
259 FUNC_LOG; |
|
260 } |
|
261 |
|
262 // --------------------------------------------------------------------------- |
|
263 // Symbian 2nd phase constructor. |
|
264 // --------------------------------------------------------------------------- |
|
265 // |
|
266 void CPDEngine::ConstructL( RAccessoryServer& aAccessoryServer ) |
|
267 { |
|
268 FUNC_LOG; |
|
269 // Create FSM objects here. |
|
270 iFSMPtr[ EPDEFSMIdHDMICableStatus ] = CHDMICableStatusFSM::NewL( aAccessoryServer, this ); |
|
271 iFSMPtr[ EPDEFSMIdCompositeCableStatus ] = CCompositeCableStatusFSM::NewL( aAccessoryServer, this ); |
|
272 Start(); |
|
273 } |
|
274 |
|
275 // End of file |