|
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 Connection Interface class for Composite Cable Status FSM. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "accessoryconnectionif.h" |
|
20 #include "multifinitestatemachine.h" |
|
21 #include "pdeconstants.h" |
|
22 #include "trace.h" |
|
23 #include "compositecablestatusfsm.h" |
|
24 #include <AccessoryServer.h> |
|
25 #include <AccessoryConnection.h> |
|
26 #include <AsyCmdTypes.h> |
|
27 #include <AccPolCommonNameValuePairs.h> |
|
28 #include <AccPolSubblockNameArray.h> |
|
29 #include <e32cmn.h> |
|
30 |
|
31 // ======== LOCAL FUNCTIONS ======== |
|
32 |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // Symbian two-phased constructor |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 CAccessoryConnectionIf* CAccessoryConnectionIf::NewL( |
|
42 MFSMForBody& aFSM, |
|
43 RAccessoryServer& aAccessoryServer ) |
|
44 { |
|
45 FUNC_LOG; |
|
46 CAccessoryConnectionIf* self = new ( ELeave ) CAccessoryConnectionIf( aFSM ); |
|
47 CleanupStack::PushL( self ); |
|
48 self->ConstructL( aAccessoryServer ); |
|
49 CleanupStack::Pop( self ); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // Destructor |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CAccessoryConnectionIf::~CAccessoryConnectionIf() |
|
58 { |
|
59 FUNC_LOG; |
|
60 Cancel(); |
|
61 iAccessoryConnection.CloseSubSession(); |
|
62 delete iAccPolGenericIDPtr; |
|
63 } |
|
64 |
|
65 // ---------------------------------------------------------------------------- |
|
66 // RunL |
|
67 // |
|
68 // ---------------------------------------------------------------------------- |
|
69 // |
|
70 void CAccessoryConnectionIf::RunL() |
|
71 { |
|
72 FUNC_LOG; |
|
73 TInt retVal( iStatus.Int() ); |
|
74 if ( retVal == KErrNone ) |
|
75 { |
|
76 TAccPolNameRecord nameRecord; |
|
77 CAccPolSubblockNameArray* nameArray = CAccPolSubblockNameArray::NewL(); |
|
78 CleanupStack::PushL( nameArray ); |
|
79 |
|
80 const TInt count = iGenericIDarray.Count(); |
|
81 |
|
82 TBool accVideoOutCababiltyFound = EFalse; |
|
83 for ( TInt index = 0; index < count; index++ ) |
|
84 { |
|
85 //Get all supported capabilities for the connected accessory. |
|
86 iAccessoryConnection.GetSubblockNameArrayL( |
|
87 iGenericIDarray.GetGenericIDL( index ), |
|
88 *nameArray ); |
|
89 |
|
90 TAccPolGenericID genericID = iGenericIDarray.GetGenericIDL( index ); |
|
91 TBool wiredPC = genericID.PhysicalConnectionCaps( KPCWired ); |
|
92 TBool avDevice = genericID.DeviceTypeCaps( KDTAVDevice ); |
|
93 TBool videoOut = nameArray->HasName( KAccVideoOut ); |
|
94 if( ( videoOut ) && |
|
95 ( wiredPC ) && |
|
96 ( avDevice ) ) |
|
97 { |
|
98 nameRecord.SetName( KAccVideoOut ); |
|
99 TAccValueTypeTInt value; |
|
100 if( iAccessoryConnection.GetValueL( genericID, nameRecord, value ) == KErrNone ) |
|
101 { |
|
102 if( value.iValue == EAccVideoOutCVideo ) |
|
103 { |
|
104 // Video/Composite cable is connected |
|
105 accVideoOutCababiltyFound = ETrue; |
|
106 TAccPolGenericID* genId = new (ELeave) TAccPolGenericID; |
|
107 CleanupStack::PushL( genId ); |
|
108 *genId = genericID; |
|
109 iAccPolGenericIDPtr = genId; |
|
110 CleanupStack::Pop( genId ); |
|
111 } |
|
112 } |
|
113 } |
|
114 } |
|
115 |
|
116 |
|
117 // renew request for listening cable events |
|
118 iAccessoryConnection.NotifyAccessoryConnectionStatusChanged ( iStatus, |
|
119 iGenericIDarray ); |
|
120 SetActive(); |
|
121 if ( accVideoOutCababiltyFound ) |
|
122 { |
|
123 // Video/Composite cable is connected |
|
124 ((CCompositeCableStatusFSM*)&iFSM)->GetPDEngine()->Input( EPDEFSMIdCompositeCableStatus, EPDEIfAccessoryConnection, EPDEIfAccessoryConnectionEventCableConnected ); |
|
125 } |
|
126 else |
|
127 { |
|
128 delete iAccPolGenericIDPtr; |
|
129 iAccPolGenericIDPtr = NULL; |
|
130 // Video/Composite cable is disconnected |
|
131 ((CCompositeCableStatusFSM*)&iFSM)->GetPDEngine()->Input( EPDEFSMIdCompositeCableStatus, EPDEIfAccessoryConnection, EPDEIfAccessoryConnectionEventCableDisconnected ); |
|
132 } |
|
133 CleanupStack::PopAndDestroy( nameArray ); |
|
134 } |
|
135 } |
|
136 |
|
137 // ---------------------------------------------------------------------------- |
|
138 // DoCancel |
|
139 // |
|
140 // ---------------------------------------------------------------------------- |
|
141 // |
|
142 void CAccessoryConnectionIf::DoCancel() |
|
143 { |
|
144 FUNC_LOG; |
|
145 iAccessoryConnection.CancelGetAccessoryConnectionStatus(); |
|
146 iAccessoryConnection.CancelNotifyAccessoryConnectionStatusChanged(); |
|
147 } |
|
148 |
|
149 // ---------------------------------------------------------------------------- |
|
150 // DoCancel |
|
151 // |
|
152 // ---------------------------------------------------------------------------- |
|
153 // |
|
154 TInt CAccessoryConnectionIf::RunError( TInt aError ) |
|
155 { |
|
156 FUNC_LOG; |
|
157 // Make use of aError argument top get rid of compiler warning. |
|
158 TInt error( aError ); |
|
159 if ( KErrNone != error ) |
|
160 { |
|
161 INFO_1("Accessory Status request failed with error code: %d", error ); |
|
162 } |
|
163 INFO("Issuing new request for accessory status"); |
|
164 iAccessoryConnection.NotifyAccessoryConnectionStatusChanged ( iStatus, |
|
165 iGenericIDarray ); |
|
166 SetActive(); |
|
167 |
|
168 return KErrNone; |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------- |
|
172 // C++ constructor |
|
173 // --------------------------------------------------------- |
|
174 // |
|
175 CAccessoryConnectionIf::CAccessoryConnectionIf( |
|
176 MFSMForBody& aFSM ) |
|
177 : CActive( CActive::EPriorityLow ), |
|
178 iFSM( aFSM ) |
|
179 { |
|
180 FUNC_LOG; |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // GetAccPolGenericID |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 TInt CAccessoryConnectionIf::GetAccPolGenericID( TAccPolGenericID& aAccPolGenericID ) |
|
188 { |
|
189 FUNC_LOG; |
|
190 TInt retVal( KErrNone ); |
|
191 if ( iAccPolGenericIDPtr ) |
|
192 { |
|
193 aAccPolGenericID = *iAccPolGenericIDPtr; |
|
194 } |
|
195 else |
|
196 { |
|
197 retVal = KErrNotFound; |
|
198 } |
|
199 return retVal; |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------- |
|
203 // ConstructL |
|
204 // --------------------------------------------------------- |
|
205 // |
|
206 void CAccessoryConnectionIf::ConstructL( |
|
207 RAccessoryServer& aAccessoryServer ) |
|
208 { |
|
209 FUNC_LOG; |
|
210 CActiveScheduler::Add( this ); |
|
211 // Create subsession. |
|
212 User::LeaveIfError( iAccessoryConnection.CreateSubSession ( aAccessoryServer ) ); |
|
213 // Get asynchronously cable connection status |
|
214 iAccessoryConnection.GetAccessoryConnectionStatus ( |
|
215 iStatus, iGenericIDarray ); |
|
216 // Ready to run |
|
217 SetActive(); |
|
218 |
|
219 } |
|
220 |
|
221 // ======== GLOBAL FUNCTIONS ======== |
|
222 |