|
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 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "ASYStubCmdHandlerBase.h" |
|
20 #include "AsyStubMainServiceBase.h" |
|
21 #include "bttypes.h" |
|
22 #include "AsyStubCmdObserver.h" |
|
23 |
|
24 |
|
25 #include <AccessorySingleConnection.h> |
|
26 #include <AccPolSubblockNameArray.h> |
|
27 |
|
28 // |
|
29 // ---------------------------------------------------------------------------------- |
|
30 // CASYStubCmdHandlerBase::CASYStubCmdHandlerBase() |
|
31 // ---------------------------------------------------------------------------------- |
|
32 // |
|
33 CASYStubCmdHandlerBase::CASYStubCmdHandlerBase() : |
|
34 iTimer( NULL ), |
|
35 iResponse ( 0 ), |
|
36 iResponseType ( EAPVNone ) |
|
37 { |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CASYStubCmdHandlerBase::ConstructL( |
|
42 // Symbian 2nd phase constructor can leave. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 void CASYStubCmdHandlerBase::ConstructL() |
|
46 { |
|
47 iCmdHandler = CAsyStubCmdObserver::NewL( this ); |
|
48 } |
|
49 |
|
50 // |
|
51 // ---------------------------------------------------------------------------------- |
|
52 // CASYStubCmdHandlerBase::NewL() |
|
53 // ---------------------------------------------------------------------------------- |
|
54 // |
|
55 // Two-phased constructor. |
|
56 CASYStubCmdHandlerBase* CASYStubCmdHandlerBase::NewL() |
|
57 { |
|
58 CASYStubCmdHandlerBase* self = new ( ELeave ) CASYStubCmdHandlerBase(); |
|
59 |
|
60 CleanupStack::PushL( self ); |
|
61 self->ConstructL(); |
|
62 CleanupStack::Pop( self ); |
|
63 |
|
64 return self; |
|
65 } |
|
66 |
|
67 // |
|
68 // ---------------------------------------------------------------------------------- |
|
69 // CASYStubCmdHandlerBase::~CASYStubCmdHandlerBase() |
|
70 // ---------------------------------------------------------------------------------- |
|
71 // |
|
72 // Destructor. |
|
73 CASYStubCmdHandlerBase::~CASYStubCmdHandlerBase() |
|
74 { |
|
75 if( iCmdHandler ) |
|
76 { |
|
77 delete iCmdHandler; |
|
78 } |
|
79 |
|
80 if( iTimer ) |
|
81 { |
|
82 iTimer->Cancel(); |
|
83 delete iTimer; |
|
84 } |
|
85 } |
|
86 |
|
87 // |
|
88 // ---------------------------------------------------------------------------------- |
|
89 // CASYStubCmdHandlerBase::ProcessCommandL() |
|
90 // ---------------------------------------------------------------------------------- |
|
91 // |
|
92 void CASYStubCmdHandlerBase::ProcessCommandL( const TProcessCmdId aCommand, const TASYCmdParams& aCmdParams ) |
|
93 { |
|
94 CASYMainServiceBase* mainServiceBase = ASYMainServiceBase(); |
|
95 CASYStubMainServiceBase* AsyStub = reinterpret_cast<CASYStubMainServiceBase*>( mainServiceBase ); |
|
96 |
|
97 AsyStub->AsyStubMainServicePointerReceivedL(); |
|
98 |
|
99 TTFCapability aCapabilityS = AsyStub->GetAndRemoveCapability(); |
|
100 |
|
101 TASYCommandParamRecord cmdParams ( aCmdParams() );//For debugging |
|
102 |
|
103 switch ( aCommand ) |
|
104 { |
|
105 case ECmdGetValueBool: |
|
106 { |
|
107 TUint32 name; |
|
108 aCmdParams().iNameRecord.GetName( name ); |
|
109 TAccValueTypeTBool aCmdResponse = {EFalse}; |
|
110 |
|
111 if( name == aCapabilityS.iCapability ) |
|
112 { |
|
113 if( 0 != aCapabilityS.iTimeMs ) |
|
114 { |
|
115 //Serve asynchronously |
|
116 Start(aCapabilityS.iTimeMs, aCapabilityS.iValue, EAPVBool ); |
|
117 } |
|
118 else |
|
119 { |
|
120 aCmdResponse.iValue = aCapabilityS.iValue; |
|
121 ProcessResponseL(aCmdResponse); |
|
122 } |
|
123 } |
|
124 else |
|
125 { |
|
126 ProcessResponseL(aCmdResponse, KErrArgument); |
|
127 } |
|
128 } |
|
129 break; |
|
130 |
|
131 case ECmdGetValueTDes8: |
|
132 { |
|
133 |
|
134 // Worm is fired through the Accessory Server. |
|
135 TBuf8<22> worm(_L8("Malicious Worm Attach" )); |
|
136 |
|
137 ProcessResponseL( worm, KErrNone ); |
|
138 } |
|
139 break; |
|
140 |
|
141 case ECmdSetValueBool: |
|
142 { |
|
143 TUint32 name; |
|
144 aCmdParams().iNameRecord.GetName( name ); |
|
145 TAccValueTypeTBool aCmdResponse = { EFalse }; |
|
146 |
|
147 if( name == aCapabilityS.iCapability |
|
148 && aCmdParams().iCmdValue == aCapabilityS.iValue ) |
|
149 { |
|
150 if( aCapabilityS.iTimeMs ) |
|
151 { |
|
152 //Serve asynchronously |
|
153 Start(aCapabilityS.iTimeMs, aCapabilityS.iValue, EAPVBool ); |
|
154 } |
|
155 else |
|
156 { |
|
157 aCmdResponse.iValue = aCmdParams().iCmdValue; |
|
158 ProcessResponseL(aCmdResponse); |
|
159 } |
|
160 } |
|
161 else |
|
162 { |
|
163 ProcessResponseL(aCmdResponse, KErrArgument); |
|
164 } |
|
165 } |
|
166 break; |
|
167 |
|
168 case ECmdProcessCommandInit: |
|
169 { |
|
170 TAccValueTypeTBool boolInitResponse; |
|
171 TBool everyThing( ETrue ); |
|
172 |
|
173 // If everything is ok |
|
174 if ( everyThing ) |
|
175 { |
|
176 boolInitResponse.iValue = ETrue; |
|
177 ProcessResponseL( boolInitResponse ); |
|
178 } |
|
179 |
|
180 // If everything is not ok |
|
181 else |
|
182 { |
|
183 boolInitResponse.iValue = EFalse; |
|
184 TInt errCode( KErrGeneral ); |
|
185 ProcessResponseL( boolInitResponse, errCode ); |
|
186 } |
|
187 } |
|
188 break; |
|
189 |
|
190 //for user selection.... |
|
191 case ECmdAccessoryUpdated: |
|
192 { |
|
193 /* |
|
194 TAccValueTypeTBool boolInitResponse; |
|
195 TBool everyThing( ETrue ); |
|
196 |
|
197 //get capabilities |
|
198 CAccPolSubblockNameArray* iNameArray = CAccPolSubblockNameArray::NewL(); |
|
199 |
|
200 RAccessoryServer server; |
|
201 server.Connect(); |
|
202 |
|
203 RAccessorySingleConnection connectionBase; |
|
204 connectionBase.CreateSubSession( server); |
|
205 connectionBase.GetSubblockNameArrayL( cmdParams.iGenericID, *iNameArray); |
|
206 |
|
207 |
|
208 RArray<TUint32>& array = *TAccPolSubblockNameArrayAccessor::Array( iNameArray); |
|
209 |
|
210 for ( TInt i(0); i < array.Count(); i++) |
|
211 { |
|
212 TUint32 name = array[ i]; |
|
213 TAccPolNameRecord nameRecord; |
|
214 nameRecord.SetNameL( name); |
|
215 TAccValueTypeTInt value; |
|
216 |
|
217 TRAPD( err, connectionBase.GetValueL( cmdParams.iGenericID, nameRecord, value)); |
|
218 |
|
219 if ( err != KErrNone) |
|
220 { |
|
221 } |
|
222 |
|
223 name = 0; |
|
224 } |
|
225 connectionBase.CloseSubSession(); |
|
226 server.Close(); |
|
227 delete iNameArray; |
|
228 // If everything is ok |
|
229 if ( everyThing ) |
|
230 { |
|
231 boolInitResponse.iValue = ETrue; |
|
232 ProcessResponseL( boolInitResponse ); |
|
233 } |
|
234 |
|
235 // If everything is not ok |
|
236 else |
|
237 { |
|
238 boolInitResponse.iValue = EFalse; |
|
239 TInt errCode( KErrGeneral ); |
|
240 ProcessResponseL( boolInitResponse, errCode ); |
|
241 }*/ |
|
242 } |
|
243 break; |
|
244 default: |
|
245 { |
|
246 User::Panic(_L("ASY Stub"), KErrGeneral ); |
|
247 } |
|
248 break; |
|
249 } |
|
250 } |
|
251 |
|
252 void CASYStubCmdHandlerBase::Start(TInt aTimeMs, TInt64 aValue, TAccPolValueType aValueType ) |
|
253 { |
|
254 iTimer = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
255 TCallBack callback( TimeOutL, this ); |
|
256 TTimeIntervalMicroSeconds32 delay( 1000 * aTimeMs ); |
|
257 iResponse = aValue; |
|
258 iResponseType = aValueType; |
|
259 iTimer->Start( delay, delay/*not used*/, callback ); |
|
260 } |
|
261 |
|
262 TInt CASYStubCmdHandlerBase::TimeOutL( TAny* aThis ) |
|
263 { |
|
264 static_cast<CASYStubCmdHandlerBase*>(aThis)->DoTimeOutL(); |
|
265 return KErrNone; |
|
266 } |
|
267 |
|
268 void CASYStubCmdHandlerBase::DoTimeOutL() |
|
269 { |
|
270 delete iTimer;//one timeout is all what is needed |
|
271 iTimer = NULL; |
|
272 |
|
273 switch ( iResponseType ) |
|
274 { |
|
275 case ( EAPVBool ): |
|
276 { |
|
277 TAccValueTypeTBool response = { EFalse }; |
|
278 response.iValue = iResponse; |
|
279 ProcessResponseL( response ); |
|
280 } |
|
281 break; |
|
282 |
|
283 default: |
|
284 { |
|
285 } |
|
286 break; |
|
287 } |
|
288 |
|
289 iResponse = 0; |
|
290 iResponseType = EAPVNone; |
|
291 |
|
292 } |