62
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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 <e32base.h>
|
|
19 |
#include <NormalHardcodedAssert.h>
|
|
20 |
|
|
21 |
#include <stubber.h>
|
|
22 |
#include <usbmandll_stub.h>
|
|
23 |
#include <usbpersonalityids.h>
|
|
24 |
|
|
25 |
#include "mockusbman.h"
|
|
26 |
#include "stifassertmacros.h"
|
|
27 |
|
|
28 |
#include "mockcusbvbusobserver.h"
|
|
29 |
#include "debug.h"
|
|
30 |
|
|
31 |
// ======== MEMBER FUNCTIONS ========
|
|
32 |
|
|
33 |
RUsb* RUsb::NewL()
|
|
34 |
{
|
|
35 |
LOG( ( " MockRUsb::NewL" ) );
|
|
36 |
RUsb* self = new ( ELeave ) RUsb();
|
|
37 |
CleanupStack::PushL(self);
|
|
38 |
self->ConstructL();
|
|
39 |
CleanupStack::Pop(); // pop self
|
|
40 |
return self;
|
|
41 |
}
|
|
42 |
|
|
43 |
void RUsb::ConstructL()
|
|
44 |
{
|
|
45 |
|
|
46 |
}
|
|
47 |
|
|
48 |
// ---------------------------------------------------------------------------
|
|
49 |
// From class MUsb
|
|
50 |
// ?implementation_description
|
|
51 |
// ---------------------------------------------------------------------------
|
|
52 |
//
|
|
53 |
RUsb::RUsb() :
|
|
54 |
iBusCleared(EFalse),
|
|
55 |
iBusRequested(EFalse),
|
|
56 |
iServiceStateNotificationRequested(EFalse),
|
|
57 |
iTryStartError(KErrNone),
|
|
58 |
iBusRequestError(KErrNone),
|
|
59 |
iCurrentPersonalityId(0),
|
|
60 |
iUsbServiceState(EUsbServiceIdle)
|
|
61 |
{
|
|
62 |
LOG1 (" MockRUsb::RUsb: %d", iUsbServiceState );
|
|
63 |
}
|
|
64 |
|
|
65 |
RUsb::~RUsb()
|
|
66 |
{
|
|
67 |
}
|
|
68 |
|
|
69 |
// ---------------------------------------------------------------------------
|
|
70 |
// From class MUsb
|
|
71 |
// ?implementation_description
|
|
72 |
// ---------------------------------------------------------------------------
|
|
73 |
//
|
|
74 |
void RUsb::TryStart(TInt aPersonalityId, TRequestStatus& aStatus)
|
|
75 |
{
|
|
76 |
LOG( (" MockRUsb::TryStart"));
|
|
77 |
|
|
78 |
// CStubber* stubber = CStubber::NewL();
|
|
79 |
// TApiBehavior beh( KUsbManStubAgentDll, ETryStartAsync, 0, 0, KNullDesC8 );
|
|
80 |
// stubber -> InvokeApi( beh );
|
|
81 |
//
|
|
82 |
// delete stubber;
|
|
83 |
// stubber = NULL;
|
|
84 |
//
|
|
85 |
// if ( beh.iOutput != KNullDesC8 )
|
|
86 |
// {
|
|
87 |
TRequestStatus* status = &aStatus;
|
|
88 |
User::RequestComplete(status, iTryStartError);
|
|
89 |
// }
|
|
90 |
}
|
|
91 |
|
|
92 |
void RUsb::StartCancel(TRequestStatus& aStatus)
|
|
93 |
{
|
|
94 |
LOG( (" MockRUsb::StartCancel"));
|
|
95 |
|
|
96 |
TRequestStatus* status = &aStatus;
|
|
97 |
User::RequestComplete(status, iTryStartError);
|
|
98 |
|
|
99 |
}
|
|
100 |
|
|
101 |
// ---------------------------------------------------------------------------
|
|
102 |
// From class MUsb
|
|
103 |
// ?implementation_description
|
|
104 |
// ---------------------------------------------------------------------------
|
|
105 |
//
|
|
106 |
void RUsb::TryStop(TRequestStatus& aStatus)
|
|
107 |
{
|
|
108 |
LOG( (" MockRUsb::TryStop"));
|
|
109 |
|
|
110 |
// CStubber* stubber = CStubber::NewL();
|
|
111 |
// TApiBehavior beh( KUsbManStubAgentDll, ETryStartAsync, 0, 0, KNullDesC8 );
|
|
112 |
// stubber -> InvokeApi( beh );
|
|
113 |
//
|
|
114 |
// delete stubber;
|
|
115 |
// stubber = NULL;
|
|
116 |
//
|
|
117 |
// if ( beh.iOutput != KNullDesC8 )
|
|
118 |
// {
|
|
119 |
TRequestStatus* status = &aStatus;
|
|
120 |
User::RequestComplete(status, KErrNone);
|
|
121 |
// }
|
|
122 |
}
|
|
123 |
|
|
124 |
// ---------------------------------------------------------------------------
|
|
125 |
// From class MUsb
|
|
126 |
// ?implementation_description
|
|
127 |
// ---------------------------------------------------------------------------
|
|
128 |
//
|
|
129 |
void RUsb::MessageNotification(TRequestStatus& aStatus, TInt& aMessage)
|
|
130 |
{
|
|
131 |
LOG( (" MockRUsb::MessageNotification"));
|
|
132 |
|
|
133 |
}
|
|
134 |
|
|
135 |
// ---------------------------------------------------------------------------
|
|
136 |
// From class MUsb
|
|
137 |
// ?implementation_description
|
|
138 |
// ---------------------------------------------------------------------------
|
|
139 |
//
|
|
140 |
void RUsb::MessageNotificationCancel()
|
|
141 |
{
|
|
142 |
LOG( (" MockRUsb::MessageNotificationCancel"));
|
|
143 |
|
|
144 |
}
|
|
145 |
|
|
146 |
// ---------------------------------------------------------------------------
|
|
147 |
// From class MUsb
|
|
148 |
// ?implementation_description
|
|
149 |
// ---------------------------------------------------------------------------
|
|
150 |
//
|
|
151 |
void RUsb::HostEventNotification(TRequestStatus& aStatus,
|
|
152 |
TDeviceEventInformation& aDeviceInformation)
|
|
153 |
{
|
|
154 |
LOG( (" MockRUsb::HostEventNotification"));
|
|
155 |
|
|
156 |
}
|
|
157 |
|
|
158 |
// ---------------------------------------------------------------------------
|
|
159 |
// From class MUsb
|
|
160 |
// ?implementation_description
|
|
161 |
// ---------------------------------------------------------------------------
|
|
162 |
//
|
|
163 |
void RUsb::HostEventNotificationCancel()
|
|
164 |
{
|
|
165 |
LOG( (" MockRUsb::HostEventNotificationCancel"));
|
|
166 |
|
|
167 |
}
|
|
168 |
|
|
169 |
// ---------------------------------------------------------------------------
|
|
170 |
// From class MUsb
|
|
171 |
// ?implementation_description
|
|
172 |
// ---------------------------------------------------------------------------
|
|
173 |
//
|
|
174 |
TInt RUsb::EnableFunctionDriverLoading()
|
|
175 |
{
|
|
176 |
LOG( (" MockRUsb::EnableFunctionDriverLoading"));
|
|
177 |
|
|
178 |
return KErrNone;
|
|
179 |
}
|
|
180 |
|
|
181 |
// ---------------------------------------------------------------------------
|
|
182 |
// From class MUsb
|
|
183 |
// ?implementation_description
|
|
184 |
// ---------------------------------------------------------------------------
|
|
185 |
//
|
|
186 |
void RUsb::DisableFunctionDriverLoading()
|
|
187 |
{
|
|
188 |
LOG( (" MockRUsb::DisableFunctionDriverLoading"));
|
|
189 |
|
|
190 |
}
|
|
191 |
|
|
192 |
// ---------------------------------------------------------------------------
|
|
193 |
// From class MUsb
|
|
194 |
// ?implementation_description
|
|
195 |
// ---------------------------------------------------------------------------
|
|
196 |
//
|
|
197 |
TInt RUsb::BusRequest()
|
|
198 |
{
|
|
199 |
LOG1 (" MockRUsb::BusRequest, ret=%d", iBusRequestError );
|
|
200 |
|
|
201 |
iBusRequested = ETrue;
|
|
202 |
|
|
203 |
return iBusRequestError;
|
|
204 |
}
|
|
205 |
|
|
206 |
// ---------------------------------------------------------------------------
|
|
207 |
// From class MUsb
|
|
208 |
// ?implementation_description
|
|
209 |
// ---------------------------------------------------------------------------
|
|
210 |
//
|
|
211 |
TInt RUsb::BusRespondSrp()
|
|
212 |
{
|
|
213 |
LOG( (" MockRUsb::BusRespondSrp"));
|
|
214 |
|
|
215 |
return KErrNone;
|
|
216 |
}
|
|
217 |
|
|
218 |
// ---------------------------------------------------------------------------
|
|
219 |
// From class MUsb
|
|
220 |
// ?implementation_description
|
|
221 |
// ---------------------------------------------------------------------------
|
|
222 |
//
|
|
223 |
TInt RUsb::BusClearError()
|
|
224 |
{
|
|
225 |
LOG( (" MockRUsb::BusClearError"));
|
|
226 |
iBusCleared = ETrue;
|
|
227 |
|
|
228 |
return KErrNone;
|
|
229 |
}
|
|
230 |
|
|
231 |
// ---------------------------------------------------------------------------
|
|
232 |
// From class MUsb
|
|
233 |
// ?implementation_description
|
|
234 |
// ---------------------------------------------------------------------------
|
|
235 |
//
|
|
236 |
TInt RUsb::BusDrop()
|
|
237 |
{
|
|
238 |
LOG( (" MockRUsb::BusDrop"));
|
|
239 |
|
|
240 |
iBusRequested = EFalse;
|
|
241 |
|
|
242 |
return KErrNone;
|
|
243 |
}
|
|
244 |
|
|
245 |
// ---------------------------------------------------------------------------
|
|
246 |
// From class RSessionBase
|
|
247 |
// ?implementation_description
|
|
248 |
// ---------------------------------------------------------------------------
|
|
249 |
//
|
|
250 |
void RUsb::Close()
|
|
251 |
{
|
|
252 |
LOG( (" MockRUsb::Close"));
|
|
253 |
|
|
254 |
}
|
|
255 |
|
|
256 |
void RUsb::SetTryStartError(TInt aError)
|
|
257 |
{
|
|
258 |
iTryStartError = aError;
|
|
259 |
}
|
|
260 |
|
|
261 |
void RUsb::SetBusRequestError(TInt aError)
|
|
262 |
{
|
|
263 |
iBusRequestError = aError;
|
|
264 |
}
|
|
265 |
|
|
266 |
void RUsb::SetUsbServiceState(TUsbServiceState aUsbServiceState)
|
|
267 |
{
|
|
268 |
LOG2 (" MockRUsb::SetUsbServiceState: %d, %d", iUsbServiceState, aUsbServiceState );
|
|
269 |
iUsbServiceState = aUsbServiceState;
|
|
270 |
}
|
|
271 |
|
|
272 |
TBool RUsb::GetVBusUp()
|
|
273 |
{
|
|
274 |
LOG2 (" MockRUsb::GetVBusUp, iBusRequested=%d, iBusRequestError=%d", iBusRequested , iBusRequestError);
|
|
275 |
|
|
276 |
return iBusRequested && !iBusRequestError;
|
|
277 |
}
|
|
278 |
|
|
279 |
TInt RUsb::GetServiceState(TUsbServiceState& aState)
|
|
280 |
{
|
|
281 |
LOG( (" MockRUsb::GetServiceState"));
|
|
282 |
aState = iUsbServiceState;
|
|
283 |
|
|
284 |
CStubber* stubber = CStubber::NewL();
|
|
285 |
TApiBehavior beh( KUsbManStubAgentDll, EServiceState, 0, 0, KNullDesC8 );
|
|
286 |
stubber -> InvokeApi( beh );
|
|
287 |
|
|
288 |
delete stubber;
|
|
289 |
stubber = NULL;
|
|
290 |
|
|
291 |
if ( beh.iOutput != KNullDesC8 )
|
|
292 |
{
|
|
293 |
if ( !beh.iOutput.Compare( _L8( "EUsbServiceIdle" ) ) )
|
|
294 |
aState = EUsbServiceIdle;
|
|
295 |
else if ( !beh.iOutput.Compare( _L8( "EUsbServiceStarting" ) ) )
|
|
296 |
aState = EUsbServiceStarting;
|
|
297 |
else if ( !beh.iOutput.Compare( _L8( "EUsbServiceStarted" ) ) )
|
|
298 |
aState = EUsbServiceStarted;
|
|
299 |
else if ( !beh.iOutput.Compare( _L8( "EUsbServiceStopping" ) ) )
|
|
300 |
aState = EUsbServiceStopping;
|
|
301 |
else if ( !beh.iOutput.Compare( _L8( "EUsbServiceFatalError" ) ) )
|
|
302 |
aState = EUsbServiceFatalError;
|
|
303 |
}
|
|
304 |
|
|
305 |
LOG1 (" iUsbServiceState: %d", aState);
|
|
306 |
|
|
307 |
return KErrNone;
|
|
308 |
}
|
|
309 |
|
|
310 |
void RUsb::ServiceStateNotification(TUsbServiceState &aState, TRequestStatus &aStatus)
|
|
311 |
{
|
|
312 |
LOG( (" MockRUsb::ServiceStateNotification"));
|
|
313 |
if(iServiceStateNotificationRequested)
|
|
314 |
{
|
|
315 |
TRequestStatus* status = &aStatus;
|
|
316 |
User::RequestComplete(status, KErrGeneral); // already requested
|
|
317 |
return;
|
|
318 |
}
|
|
319 |
|
|
320 |
iServiceStateNotificationRequested = ETrue;
|
|
321 |
TRequestStatus* status = &aStatus;
|
|
322 |
User::RequestComplete(status, KErrNone);
|
|
323 |
}
|
|
324 |
|
|
325 |
TInt RUsb::GetCurrentPersonalityId(TInt &aPersonalityId)
|
|
326 |
{
|
|
327 |
LOG( (" MockRUsb::GetCurrentPersonalityId"));
|
|
328 |
|
|
329 |
CStubber* stubber = CStubber::NewL();
|
|
330 |
TApiBehavior beh( KUsbManStubAgentDll, EGetCurrentPersonalityId, 0, 0, KNullDesC8 );
|
|
331 |
stubber -> InvokeApi( beh );
|
|
332 |
|
|
333 |
delete stubber;
|
|
334 |
stubber = NULL;
|
|
335 |
|
|
336 |
if ( beh.iOutput != KNullDesC8 )
|
|
337 |
{
|
|
338 |
if ( !beh.iOutput.Compare( _L8( "UsbPersonalityIdPCSuite" ) ) )
|
|
339 |
aPersonalityId = KUsbPersonalityIdPCSuite;
|
|
340 |
else if ( !beh.iOutput.Compare( _L8( "UsbPersonalityIdMS" ) ) )
|
|
341 |
aPersonalityId = KUsbPersonalityIdMS;
|
|
342 |
else if ( !beh.iOutput.Compare( _L8( "UsbPersonalityIdPTP" ) ) )
|
|
343 |
aPersonalityId = KUsbPersonalityIdPTP;
|
|
344 |
else if ( !beh.iOutput.Compare( _L8( "UsbPersonalityIdMTP" ) ) )
|
|
345 |
aPersonalityId = KUsbPersonalityIdMTP;
|
|
346 |
else if ( !beh.iOutput.Compare( _L8( "UsbPersonalityIdPCSuiteMTP" ) ) )
|
|
347 |
aPersonalityId = KUsbPersonalityIdPCSuiteMTP;
|
|
348 |
|
|
349 |
LOG1( " MockRUsb::GetCurrentPersonalityId iStubbedPersonalityId: %d", aPersonalityId);
|
|
350 |
}
|
|
351 |
else
|
|
352 |
aPersonalityId = iCurrentPersonalityId;
|
|
353 |
|
|
354 |
LOG1( " MockRUsb::GetCurrentPersonalityId iCurrentPersonalityId: %d", iCurrentPersonalityId);
|
|
355 |
|
|
356 |
return KErrNone;
|
|
357 |
}
|
|
358 |
|
|
359 |
TInt RUsb::CancelInterest(TUsbReqType aMessageId) // to pending op. of usb service state
|
|
360 |
{
|
|
361 |
LOG( (" MockRUsb::CancelInterest"));
|
|
362 |
iServiceStateNotificationRequested = EFalse;
|
|
363 |
return KErrNone;
|
|
364 |
}
|
|
365 |
|
|
366 |
void RUsb::ServiceStateNotificationCancel()
|
|
367 |
{
|
|
368 |
LOG( (" MockRUsb::ServiceStateNotificationCancel"));
|
|
369 |
iServiceStateNotificationRequested = EFalse;
|
|
370 |
}
|
|
371 |
|
|
372 |
void RUsb::SetCurrentPersonality(TInt aPersonalityId)
|
|
373 |
{
|
|
374 |
LOG( (" MockRUsb::SetCurrentPersonality"));
|
|
375 |
iCurrentPersonalityId = aPersonalityId;
|
|
376 |
}
|
|
377 |
|
|
378 |
TInt RUsb::GetOtgDescriptor(TUint aDeviceId, TOtgDescriptor& aDescriptor)
|
|
379 |
{
|
|
380 |
LOG( (" MockRUsb::GetOtgDescriptor"));
|
|
381 |
|
|
382 |
aDescriptor.iAttributes = 1;
|
|
383 |
aDescriptor.iDeviceId = 2;
|
|
384 |
|
|
385 |
return KErrNone;
|
|
386 |
}
|
|
387 |
|
|
388 |
// End of File
|