|
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: Accessory Control Interface class for HDMI Cable Status FSM. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "accessorycontrolif.h" |
|
20 #include "multifinitestatemachine.h" |
|
21 #include "pdeconstants.h" |
|
22 #include "trace.h" |
|
23 #include "hdmicablestatusfsm.h" |
|
24 #include <AccessoryServer.h> |
|
25 #include <AccessoryControl.h> |
|
26 #include <AsyCmdTypes.h> |
|
27 #include <AccConfigFileParser.h> |
|
28 #include <e32cmn.h> |
|
29 |
|
30 // ======== LOCAL FUNCTIONS ======== |
|
31 |
|
32 |
|
33 // ======== MEMBER FUNCTIONS ======== |
|
34 |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // Symbian two-phased constructor |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 CAccessoryControlIf* CAccessoryControlIf::NewL( |
|
41 MFSMForBody& aFSM, |
|
42 RAccessoryServer& aAccessoryServer ) |
|
43 { |
|
44 FUNC_LOG; |
|
45 CAccessoryControlIf* self = new ( ELeave ) CAccessoryControlIf( aFSM ); |
|
46 CleanupStack::PushL( self ); |
|
47 self->ConstructL( aAccessoryServer ); |
|
48 CleanupStack::Pop( self ); |
|
49 return self; |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // Destructor |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CAccessoryControlIf::~CAccessoryControlIf() |
|
57 { |
|
58 FUNC_LOG; |
|
59 Cancel(); |
|
60 if ( iAccessoryConnected ) |
|
61 { |
|
62 TRequestStatus status; |
|
63 iAccessoryControl.DisconnectAccessory( status, iGenericIDPtr->GenericID() ); |
|
64 User::WaitForRequest( status ); |
|
65 TInt retval = status.Int(); |
|
66 INFO_1( "iAccessoryControl.DisconnectAccessory() return value %i", retval ); |
|
67 } |
|
68 delete iGenericIDPtr; |
|
69 iAccessoryControl.CloseSubSession(); |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // ConnectAccessoryL |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 void CAccessoryControlIf::ConnectAccessoryL( TBool aCopyProtectionStatus ) |
|
77 { |
|
78 FUNC_LOG; |
|
79 if ( !IsActive() ) |
|
80 { |
|
81 CAccConfigFileParser* accConfigFileParser = |
|
82 CAccConfigFileParser::NewL( _L("Configuration file") ); |
|
83 CleanupStack::PushL( accConfigFileParser ); |
|
84 if ( !iGenericIDPtr ) |
|
85 { |
|
86 delete iGenericIDPtr; |
|
87 iGenericIDPtr = NULL; |
|
88 } |
|
89 iGenericIDPtr = CAccConGenericID::NewL(); |
|
90 |
|
91 RArray<TAccPolNameValueRecord> nameValueArray; |
|
92 CleanupClosePushL( nameValueArray ); |
|
93 TBuf<KHWModelIDMaxLength> hwModelID( _L("hdmi")); |
|
94 TAccPolNameRecord nameRecord; |
|
95 TAccPolValueRecord valueRecord; |
|
96 |
|
97 TBuf<KHWModelIDMaxLength> HWModelID( _L("hdmi")); |
|
98 |
|
99 //Set GenericID header |
|
100 TAccPolGIDHeader GIDHeader; |
|
101 GIDHeader.iAccessoryDeviceType = KDTAVDevice; |
|
102 GIDHeader.iPhysicalConnection = KPCHDMI; |
|
103 GIDHeader.iApplicationProtocol = 0x0; |
|
104 GIDHeader.iCapabilitiesSubblocks = KSBAudioSubblock | KSBVideoSubblock; |
|
105 GIDHeader.iHWModelID = hwModelID; |
|
106 GIDHeader.iHWDeviceID = 0x0; |
|
107 GIDHeader.iDeviceAddress = 0x0; |
|
108 TAccPolGenericID genericID; |
|
109 GIDHeader.iDBID = genericID.UniqueID(); |
|
110 |
|
111 //Set "Audio Output Type" capability |
|
112 TAccPolNameValueRecord nameValueRecordAudioOutputType( KAccAudioOutputType, |
|
113 EAccAudioOutPutTypePublic, |
|
114 EAPVInt, |
|
115 EAPVPolicy ); |
|
116 nameValueArray.AppendL( nameValueRecordAudioOutputType ); |
|
117 |
|
118 //Set "Video Output Type" capability |
|
119 TAccPolNameValueRecord nameValueRecordVideoOut( KAccVideoOut, |
|
120 EAccVideoOutEHDMI, |
|
121 EAPVInt, |
|
122 EAPVAccessory ); |
|
123 nameValueArray.AppendL( nameValueRecordVideoOut ); |
|
124 |
|
125 // Set "HDMI attributes" capability |
|
126 TAccPolNameValueRecord nameValueRecordHdmiAttributes( KAccVideoHdmiAttributes, |
|
127 EAPVAccessory ); |
|
128 nameValueArray.AppendL( nameValueRecordHdmiAttributes ); |
|
129 |
|
130 // Set "HDCP" capability |
|
131 TAccPolNameValueRecord nameValueRecordHdcpSupport( KAccVideoHdcpSupport, |
|
132 aCopyProtectionStatus, |
|
133 EAPVBool, |
|
134 EAPVAccessory ); |
|
135 nameValueArray.AppendL( nameValueRecordHdcpSupport ); |
|
136 |
|
137 // Set "HDCP status" capability |
|
138 TAccPolNameValueRecord nameValueRecordHdcpSupportStatus( KAccVideoHdcpSupportStatus, |
|
139 aCopyProtectionStatus, |
|
140 EAPVBool, |
|
141 EAPVAccessory ); |
|
142 nameValueArray.AppendL( nameValueRecordHdcpSupportStatus ); |
|
143 |
|
144 // Set "Video active format" capability |
|
145 TAccPolNameValueRecord nameValueRecordVideoFormat( KAccVideoFormat, |
|
146 EAPVAccessory ); |
|
147 nameValueArray.AppendL( nameValueRecordVideoFormat ); |
|
148 |
|
149 accConfigFileParser->ParseGenericIDL( iGenericIDPtr, |
|
150 GIDHeader, |
|
151 nameValueArray ); |
|
152 nameValueArray.Close(); |
|
153 |
|
154 |
|
155 CleanupStack::PopAndDestroy( &nameValueArray ); |
|
156 CleanupStack::PopAndDestroy( accConfigFileParser ); |
|
157 |
|
158 iActiveRequestId = EAccessoryControlIfConnectRequested; |
|
159 iAccessoryControl.ConnectAccessory( iStatus, iGenericIDPtr, EFalse ); |
|
160 SetActive(); |
|
161 } |
|
162 else |
|
163 { |
|
164 if ( EAccessoryControlIfConnectRequested == iActiveRequestId ) |
|
165 { |
|
166 INFO("Could not connect, because connect request already pending") |
|
167 } |
|
168 else if ( EAccessoryControlIfDisconnectRequested == iActiveRequestId ) |
|
169 { |
|
170 INFO("Could not connect, because disconnect is pending") |
|
171 } |
|
172 User::Leave(KErrCouldNotConnect); |
|
173 } |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 // DisconnectAccessory |
|
178 // --------------------------------------------------------------------------- |
|
179 // |
|
180 void CAccessoryControlIf::DisconnectAccessory() |
|
181 { |
|
182 FUNC_LOG; |
|
183 if ( IsActive() ) |
|
184 { |
|
185 Cancel(); |
|
186 } |
|
187 iActiveRequestId = EAccessoryControlIfDisconnectRequested; |
|
188 iAccessoryControl.DisconnectAccessory( iStatus, iGenericIDPtr->GenericID() ); |
|
189 SetActive(); |
|
190 } |
|
191 |
|
192 // --------------------------------------------------------------------------- |
|
193 // GetUniqueID |
|
194 // --------------------------------------------------------------------------- |
|
195 // |
|
196 TInt CAccessoryControlIf::GetUniqueID() |
|
197 { |
|
198 FUNC_LOG; |
|
199 TInt uniqueID( 0 ); |
|
200 if ( iGenericIDPtr ) |
|
201 { |
|
202 uniqueID = iGenericIDPtr->GenericID().UniqueID(); |
|
203 } |
|
204 return uniqueID; |
|
205 } |
|
206 |
|
207 // --------------------------------------------------------------------------- |
|
208 // GetAccPolGenericID |
|
209 // --------------------------------------------------------------------------- |
|
210 // |
|
211 TInt CAccessoryControlIf::GetAccPolGenericID( TAccPolGenericID& aAccPolGenericID ) |
|
212 { |
|
213 FUNC_LOG; |
|
214 TInt retVal( KErrNone ); |
|
215 if ( iGenericIDPtr ) |
|
216 { |
|
217 aAccPolGenericID = iGenericIDPtr->GenericID(); |
|
218 } |
|
219 else |
|
220 { |
|
221 retVal = KErrNotFound; |
|
222 } |
|
223 return retVal; |
|
224 } |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // NotifyValueChange |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 TInt CAccessoryControlIf::NotifyValueChange( |
|
231 const TUint32& aName, |
|
232 const TAccValueTypeTBool aValue ) const |
|
233 { |
|
234 FUNC_LOG; |
|
235 TInt retVal( KErrNone ); |
|
236 if ( iGenericIDPtr ) |
|
237 { |
|
238 TAccPolNameRecord aNameRecord; |
|
239 aNameRecord.SetName( aName ); |
|
240 TRAP( retVal, iAccessoryControl.AccessoryValueChangedNotifyL( iGenericIDPtr->GenericID(), aNameRecord, aValue ) ); |
|
241 if ( KErrNone != retVal ) |
|
242 { |
|
243 INFO_1( "RAccessoryControl::AccessoryValueChangedNotifyL() failed, return code: %d", retVal ); |
|
244 } |
|
245 } |
|
246 else |
|
247 { |
|
248 INFO( "No Generic ID found, cannot notify"); |
|
249 retVal = KErrNotFound; |
|
250 } |
|
251 return retVal; |
|
252 } |
|
253 |
|
254 // --------------------------------------------------------------------------- |
|
255 // NotifyValueChange |
|
256 // --------------------------------------------------------------------------- |
|
257 // |
|
258 TInt CAccessoryControlIf::NotifyValueChange( |
|
259 const TUint32& aName, |
|
260 const CAccPolObjectCon& aValue ) const |
|
261 { |
|
262 FUNC_LOG; |
|
263 TInt retVal( KErrNone ); |
|
264 if ( iGenericIDPtr ) |
|
265 { |
|
266 TAccPolNameRecord aNameRecord; |
|
267 aNameRecord.SetName( aName ); |
|
268 TRAP( retVal, iAccessoryControl.AccessoryValueChangedNotifyL( iGenericIDPtr->GenericID(), aNameRecord, aValue ) ); |
|
269 if ( KErrNone != retVal ) |
|
270 { |
|
271 INFO_1( "RAccessoryControl::AccessoryValueChangedNotifyL() failed, return code: %d", retVal ); |
|
272 } |
|
273 } |
|
274 else |
|
275 { |
|
276 INFO( "No Generic ID found, cannot notify"); |
|
277 retVal = KErrNotFound; |
|
278 } |
|
279 return retVal; |
|
280 } |
|
281 |
|
282 |
|
283 // ---------------------------------------------------------------------------- |
|
284 // RunL |
|
285 // |
|
286 // ---------------------------------------------------------------------------- |
|
287 // |
|
288 void CAccessoryControlIf::RunL() |
|
289 { |
|
290 |
|
291 FUNC_LOG; |
|
292 TInt retVal( iStatus.Int() ); |
|
293 if ( KErrNone == retVal ) |
|
294 { |
|
295 if ( EAccessoryControlIfConnectRequested == iActiveRequestId ) |
|
296 { |
|
297 iAccessoryConnected = ETrue; |
|
298 |
|
299 ((CHDMICableStatusFSM*)&iFSM)->GetPDEngine()->Input( |
|
300 EPDEFSMIdHDMICableStatus, |
|
301 EPDEIfAccessoryControl, |
|
302 EPDEIfAccessoryControlEventConnected ); |
|
303 } |
|
304 else if ( EAccessoryControlIfDisconnectRequested == iActiveRequestId ) |
|
305 { |
|
306 iAccessoryConnected = EFalse; |
|
307 |
|
308 ((CHDMICableStatusFSM*)&iFSM)->GetPDEngine()->Input( |
|
309 EPDEFSMIdHDMICableStatus, |
|
310 EPDEIfAccessoryControl, |
|
311 EPDEIfAccessoryControlEventDisconnected ); |
|
312 delete iGenericIDPtr; |
|
313 iGenericIDPtr = NULL; |
|
314 } |
|
315 } |
|
316 else |
|
317 { |
|
318 if ( EAccessoryControlIfConnectRequested == iActiveRequestId ) |
|
319 { |
|
320 INFO_1( "RAccessoryControl::ConnectAccessory failed, error code: %d", retVal ); |
|
321 |
|
322 ((CHDMICableStatusFSM*)&iFSM)->GetPDEngine()->Input( |
|
323 EPDEFSMIdHDMICableStatus, |
|
324 EPDEIfAccessoryControl, |
|
325 EPDEIfAccessoryControlEventConnectFailed ); |
|
326 } |
|
327 else if ( EAccessoryControlIfDisconnectRequested == iActiveRequestId ) |
|
328 { |
|
329 INFO_1( "RAccessoryControl::DisconnectAccessory failed, error code: %d", retVal ); |
|
330 |
|
331 ((CHDMICableStatusFSM*)&iFSM)->GetPDEngine()->Input( |
|
332 EPDEFSMIdHDMICableStatus, |
|
333 EPDEIfAccessoryControl, |
|
334 EPDEIfAccessoryControlEventDisconnectFailed ); |
|
335 delete iGenericIDPtr; |
|
336 iGenericIDPtr = NULL; |
|
337 } |
|
338 } |
|
339 iActiveRequestId = EAccessoryControlIfNoRequestActive; |
|
340 } |
|
341 |
|
342 // ---------------------------------------------------------------------------- |
|
343 // DoCancel |
|
344 // |
|
345 // ---------------------------------------------------------------------------- |
|
346 // |
|
347 void CAccessoryControlIf::DoCancel() |
|
348 { |
|
349 FUNC_LOG; |
|
350 if ( EAccessoryControlIfConnectRequested == iActiveRequestId ) |
|
351 { |
|
352 iAccessoryControl.CancelConnectAccessory(); |
|
353 } |
|
354 else if ( EAccessoryControlIfDisconnectRequested == iActiveRequestId ) |
|
355 { |
|
356 iAccessoryControl.CancelDisconnectAccessory(); |
|
357 } |
|
358 iActiveRequestId = EAccessoryControlIfNoRequestActive; |
|
359 } |
|
360 |
|
361 // --------------------------------------------------------- |
|
362 // C++ constructor |
|
363 // --------------------------------------------------------- |
|
364 // |
|
365 CAccessoryControlIf::CAccessoryControlIf( |
|
366 MFSMForBody& aFSM |
|
367 ) |
|
368 : CActive( CActive::EPriorityLow ), |
|
369 iFSM( aFSM ) |
|
370 { |
|
371 FUNC_LOG; |
|
372 } |
|
373 |
|
374 // --------------------------------------------------------- |
|
375 // ConstructL |
|
376 // --------------------------------------------------------- |
|
377 // |
|
378 void CAccessoryControlIf::ConstructL( RAccessoryServer& aAccessoryServer ) |
|
379 { |
|
380 FUNC_LOG; |
|
381 |
|
382 User::LeaveIfError( iAccessoryControl.CreateSubSession( aAccessoryServer ) ); |
|
383 CActiveScheduler::Add( this ); |
|
384 } |
|
385 |
|
386 // ======== GLOBAL FUNCTIONS ======== |
|
387 |