253
|
1 |
// Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// @file usbclientstatewatcher.cpp
|
|
15 |
// @internalComponent
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include "UsbClientStateWatcher.h"
|
253
|
20 |
#include "OstTraceDefinitions.h"
|
|
21 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
22 |
#include "UsbClientStateWatcherTraces.h"
|
|
23 |
#endif
|
0
|
24 |
#include <d32usbc.h>
|
|
25 |
#include <e32test.h>
|
|
26 |
#include <e32debug.h>
|
|
27 |
|
|
28 |
extern RTest gtest;
|
|
29 |
|
|
30 |
namespace NUnitTesting_USBDI
|
|
31 |
{
|
|
32 |
|
|
33 |
CUsbClientStateWatcher* CUsbClientStateWatcher::NewL(RDevUsbcClient& aClientDriver,MUsbClientStateObserver& aStateObserver)
|
|
34 |
{
|
253
|
35 |
OstTraceFunctionEntryExt( CUSBCLIENTSTATEWATCHER_NEWL_ENTRY, 0 );
|
0
|
36 |
CUsbClientStateWatcher* self = new (ELeave) CUsbClientStateWatcher(aClientDriver,aStateObserver);
|
|
37 |
CleanupStack::PushL(self);
|
|
38 |
self->ConstructL();
|
|
39 |
CleanupStack::Pop(self);
|
253
|
40 |
OstTraceFunctionExit1( CUSBCLIENTSTATEWATCHER_NEWL_EXIT, ( TUint )( self ) );
|
0
|
41 |
return self;
|
|
42 |
}
|
|
43 |
|
|
44 |
|
|
45 |
CUsbClientStateWatcher::CUsbClientStateWatcher(RDevUsbcClient& aClientDriver,MUsbClientStateObserver& aStateObserver)
|
|
46 |
: CActive(EPriorityUserInput),
|
|
47 |
iClientDriver(aClientDriver),
|
|
48 |
iStateObserver(aStateObserver)
|
|
49 |
{
|
253
|
50 |
OstTraceFunctionEntryExt( CUSBCLIENTSTATEWATCHER_CUSBCLIENTSTATEWATCHER_ENTRY, this );
|
0
|
51 |
CActiveScheduler::Add(this);
|
253
|
52 |
OstTraceFunctionExit1( CUSBCLIENTSTATEWATCHER_CUSBCLIENTSTATEWATCHER_EXIT, this );
|
0
|
53 |
}
|
|
54 |
|
|
55 |
|
|
56 |
CUsbClientStateWatcher::~CUsbClientStateWatcher()
|
|
57 |
{
|
253
|
58 |
OstTraceFunctionEntry1( CUSBCLIENTSTATEWATCHER_CUSBCLIENTSTATEWATCHER_ENTRY_DUP01, this );
|
0
|
59 |
Cancel();
|
253
|
60 |
OstTraceFunctionExit1( CUSBCLIENTSTATEWATCHER_CUSBCLIENTSTATEWATCHER_EXIT_DUP01, this );
|
0
|
61 |
}
|
|
62 |
|
|
63 |
|
|
64 |
void CUsbClientStateWatcher::ConstructL()
|
|
65 |
{
|
253
|
66 |
OstTraceFunctionEntry1( CUSBCLIENTSTATEWATCHER_CONSTRUCTL_ENTRY, this );
|
|
67 |
OstTrace0(TRACE_NORMAL, CUSBCLIENTSTATEWATCHER_CONSTRUCTL, "<Client State Watcher> Watching state of device");
|
0
|
68 |
iClientDriver.AlternateDeviceStatusNotify(iStatus,iState);
|
|
69 |
SetActive();
|
253
|
70 |
OstTraceFunctionExit1( CUSBCLIENTSTATEWATCHER_CONSTRUCTL_EXIT, this );
|
0
|
71 |
}
|
|
72 |
|
|
73 |
|
|
74 |
void CUsbClientStateWatcher::DoCancel()
|
|
75 |
{
|
253
|
76 |
OstTraceFunctionEntry1( CUSBCLIENTSTATEWATCHER_DOCANCEL_ENTRY, this );
|
0
|
77 |
// Cancel device status notification
|
|
78 |
iClientDriver.AlternateDeviceStatusNotifyCancel();
|
253
|
79 |
OstTraceFunctionExit1( CUSBCLIENTSTATEWATCHER_DOCANCEL_EXIT, this );
|
0
|
80 |
}
|
|
81 |
|
|
82 |
void CUsbClientStateWatcher::RunL()
|
|
83 |
{
|
253
|
84 |
OstTraceFunctionEntry1( CUSBCLIENTSTATEWATCHER_RUNL_ENTRY, this );
|
0
|
85 |
// Retrieve the asynchronous completion code
|
|
86 |
TInt completionCode(iStatus.Int());
|
|
87 |
|
|
88 |
if(iState & KUsbAlternateSetting)
|
|
89 |
{
|
|
90 |
// This is notification for alternate interface setting selected by the host
|
|
91 |
// so do nothing (Do not watch for these)
|
|
92 |
}
|
|
93 |
else
|
|
94 |
{
|
|
95 |
if(completionCode == KErrNone)
|
|
96 |
{
|
|
97 |
switch(iState)
|
|
98 |
{
|
|
99 |
case EUsbcDeviceStateUndefined:
|
253
|
100 |
OstTrace0(TRACE_NORMAL, CUSBCLIENTSTATEWATCHER_RUNL, "<Client State> Not attached");
|
0
|
101 |
break;
|
|
102 |
|
|
103 |
case EUsbcDeviceStateAttached:
|
253
|
104 |
OstTrace0(TRACE_NORMAL, CUSBCLIENTSTATEWATCHER_RUNL_DUP01, "<Client State> Attached to host but not powered");
|
0
|
105 |
break;
|
|
106 |
|
|
107 |
case EUsbcDeviceStatePowered:
|
253
|
108 |
OstTrace0(TRACE_NORMAL, CUSBCLIENTSTATEWATCHER_RUNL_DUP02, "<Client State> Attached and powered but no reset");
|
0
|
109 |
break;
|
|
110 |
|
|
111 |
case EUsbcDeviceStateDefault:
|
253
|
112 |
OstTrace0(TRACE_NORMAL, CUSBCLIENTSTATEWATCHER_RUNL_DUP03, "<Client State> Reset but not addressed");
|
0
|
113 |
break;
|
|
114 |
|
|
115 |
case EUsbcDeviceStateAddress:
|
253
|
116 |
OstTrace0(TRACE_NORMAL, CUSBCLIENTSTATEWATCHER_RUNL_DUP04, "<Client State> Addressed but not configured");
|
0
|
117 |
break;
|
|
118 |
|
|
119 |
case EUsbcDeviceStateConfigured:
|
253
|
120 |
OstTrace0(TRACE_NORMAL, CUSBCLIENTSTATEWATCHER_RUNL_DUP05, "<Client State> Fully configured");
|
0
|
121 |
break;
|
|
122 |
|
|
123 |
case EUsbcDeviceStateSuspended:
|
253
|
124 |
OstTrace0(TRACE_NORMAL, CUSBCLIENTSTATEWATCHER_RUNL_DUP06, "<Client State> Suspended");
|
0
|
125 |
break;
|
|
126 |
|
|
127 |
case EUsbcNoState: //follow through
|
|
128 |
default:
|
253
|
129 |
OstTrace0(TRACE_NORMAL, CUSBCLIENTSTATEWATCHER_RUNL_DUP07, "<Client State> Not specified");
|
0
|
130 |
break;
|
|
131 |
}
|
|
132 |
}
|
|
133 |
else
|
|
134 |
{
|
253
|
135 |
OstTrace1(TRACE_NORMAL, CUSBCLIENTSTATEWATCHER_RUNL_DUP08, "<Client State> Notification error %d",completionCode);
|
0
|
136 |
}
|
|
137 |
|
|
138 |
// Device state change
|
|
139 |
iStateObserver.StateChangeL(static_cast<TUsbcDeviceState>(iState),completionCode);
|
|
140 |
}
|
|
141 |
|
|
142 |
// Keep asking to be informed for status notifications
|
|
143 |
iClientDriver.AlternateDeviceStatusNotify(iStatus,iState);
|
|
144 |
SetActive();
|
253
|
145 |
OstTraceFunctionExit1( CUSBCLIENTSTATEWATCHER_RUNL_EXIT, this );
|
0
|
146 |
}
|
|
147 |
|
|
148 |
|
|
149 |
TInt CUsbClientStateWatcher::RunError(TInt aError)
|
|
150 |
{
|
253
|
151 |
OstTraceFunctionEntryExt( CUSBCLIENTSTATEWATCHER_RUNERROR_ENTRY, this );
|
0
|
152 |
aError = KErrNone;
|
253
|
153 |
OstTraceFunctionExitExt( CUSBCLIENTSTATEWATCHER_RUNERROR_EXIT, this, aError );
|
0
|
154 |
return aError;
|
|
155 |
}
|
|
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
CAlternateInterfaceSelectionWatcher* CAlternateInterfaceSelectionWatcher::NewL(
|
|
163 |
RDevUsbcClient& aClientDriver,MAlternateSettingObserver& aObserver)
|
|
164 |
{
|
253
|
165 |
OstTraceFunctionEntryExt( CALTERNATEINTERFACESELECTIONWATCHER_NEWL_ENTRY, 0 );
|
0
|
166 |
CAlternateInterfaceSelectionWatcher* self = new (ELeave) CAlternateInterfaceSelectionWatcher(aClientDriver,aObserver);
|
|
167 |
CleanupStack::PushL(self);
|
|
168 |
self->ConstructL();
|
|
169 |
CleanupStack::Pop(self);
|
253
|
170 |
OstTraceFunctionExit1( CALTERNATEINTERFACESELECTIONWATCHER_NEWL_EXIT, ( TUint )( self ) );
|
0
|
171 |
return self;
|
|
172 |
}
|
|
173 |
|
|
174 |
|
|
175 |
CAlternateInterfaceSelectionWatcher::CAlternateInterfaceSelectionWatcher(
|
|
176 |
RDevUsbcClient& aClientDriver,MAlternateSettingObserver& aObserver)
|
|
177 |
: CActive(EPriorityUserInput),
|
|
178 |
iClientDriver(aClientDriver),
|
|
179 |
iObserver(aObserver)
|
|
180 |
{
|
253
|
181 |
OstTraceFunctionEntryExt( CALTERNATEINTERFACESELECTIONWATCHER_CALTERNATEINTERFACESELECTIONWATCHER_ENTRY, this );
|
0
|
182 |
CActiveScheduler::Add(this);
|
253
|
183 |
OstTraceFunctionExit1( CALTERNATEINTERFACESELECTIONWATCHER_CALTERNATEINTERFACESELECTIONWATCHER_EXIT, this );
|
0
|
184 |
}
|
|
185 |
|
|
186 |
|
|
187 |
CAlternateInterfaceSelectionWatcher::~CAlternateInterfaceSelectionWatcher()
|
|
188 |
{
|
253
|
189 |
OstTraceFunctionEntry1( CALTERNATEINTERFACESELECTIONWATCHER_CALTERNATEINTERFACESELECTIONWATCHER_ENTRY_DUP01, this );
|
0
|
190 |
|
|
191 |
Cancel();
|
253
|
192 |
OstTraceFunctionExit1( CALTERNATEINTERFACESELECTIONWATCHER_CALTERNATEINTERFACESELECTIONWATCHER_EXIT_DUP01, this );
|
0
|
193 |
}
|
|
194 |
|
|
195 |
|
|
196 |
void CAlternateInterfaceSelectionWatcher::ConstructL()
|
|
197 |
{
|
253
|
198 |
OstTraceFunctionEntry1( CALTERNATEINTERFACESELECTIONWATCHER_CONSTRUCTL_ENTRY, this );
|
0
|
199 |
|
|
200 |
iClientDriver.AlternateDeviceStatusNotify(iStatus,iState);
|
|
201 |
SetActive();
|
253
|
202 |
OstTraceFunctionExit1( CALTERNATEINTERFACESELECTIONWATCHER_CONSTRUCTL_EXIT, this );
|
0
|
203 |
}
|
|
204 |
|
|
205 |
|
|
206 |
void CAlternateInterfaceSelectionWatcher::DoCancel()
|
|
207 |
{
|
253
|
208 |
OstTraceFunctionEntry1( CALTERNATEINTERFACESELECTIONWATCHER_DOCANCEL_ENTRY, this );
|
0
|
209 |
|
|
210 |
iClientDriver.AlternateDeviceStatusNotifyCancel();
|
253
|
211 |
OstTraceFunctionExit1( CALTERNATEINTERFACESELECTIONWATCHER_DOCANCEL_EXIT, this );
|
0
|
212 |
}
|
|
213 |
|
|
214 |
|
|
215 |
void CAlternateInterfaceSelectionWatcher::RunL()
|
|
216 |
{
|
253
|
217 |
OstTraceFunctionEntry1( CALTERNATEINTERFACESELECTIONWATCHER_RUNL_ENTRY, this );
|
0
|
218 |
|
|
219 |
TInt completionCode(iStatus.Int());
|
|
220 |
|
|
221 |
if(iState & KUsbAlternateSetting)
|
|
222 |
{
|
|
223 |
iObserver.AlternateInterfaceSelectedL(iState & (~KUsbAlternateSetting));
|
|
224 |
}
|
|
225 |
// Keep asking to be informed for status notifications
|
|
226 |
iClientDriver.AlternateDeviceStatusNotify(iStatus,iState);
|
|
227 |
SetActive();
|
253
|
228 |
OstTraceFunctionExit1( CALTERNATEINTERFACESELECTIONWATCHER_RUNL_EXIT, this );
|
0
|
229 |
}
|
|
230 |
|
|
231 |
|
|
232 |
TInt CAlternateInterfaceSelectionWatcher::RunError(TInt aError)
|
|
233 |
{
|
253
|
234 |
OstTraceFunctionEntryExt( CALTERNATEINTERFACESELECTIONWATCHER_RUNERROR_ENTRY, this );
|
0
|
235 |
|
253
|
236 |
OstTraceFunctionExitExt( CALTERNATEINTERFACESELECTIONWATCHER_RUNERROR_EXIT, this, KErrNone );
|
0
|
237 |
return KErrNone;
|
|
238 |
}
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
|
253 |
}
|