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