Update contrib.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // @file usbclientstatewatcher.cpp
19 #include "UsbClientStateWatcher.h"
26 namespace NUnitTesting_USBDI
29 CUsbClientStateWatcher* CUsbClientStateWatcher::NewL(RDevUsbcClient& aClientDriver,MUsbClientStateObserver& aStateObserver)
31 CUsbClientStateWatcher* self = new (ELeave) CUsbClientStateWatcher(aClientDriver,aStateObserver);
32 CleanupStack::PushL(self);
34 CleanupStack::Pop(self);
39 CUsbClientStateWatcher::CUsbClientStateWatcher(RDevUsbcClient& aClientDriver,MUsbClientStateObserver& aStateObserver)
40 : CActive(EPriorityUserInput),
41 iClientDriver(aClientDriver),
42 iStateObserver(aStateObserver)
44 CActiveScheduler::Add(this);
48 CUsbClientStateWatcher::~CUsbClientStateWatcher()
55 void CUsbClientStateWatcher::ConstructL()
57 RDebug::Printf("<Client State Watcher> Watching state of device");
58 iClientDriver.AlternateDeviceStatusNotify(iStatus,iState);
63 void CUsbClientStateWatcher::DoCancel()
65 // Cancel device status notification
66 iClientDriver.AlternateDeviceStatusNotifyCancel();
69 void CUsbClientStateWatcher::RunL()
71 // Retrieve the asynchronous completion code
72 TInt completionCode(iStatus.Int());
74 if(iState & KUsbAlternateSetting)
76 // This is notification for alternate interface setting selected by the host
77 // so do nothing (Do not watch for these)
81 if(completionCode == KErrNone)
85 case EUsbcDeviceStateUndefined:
86 RDebug::Printf("<Client State> Not attached");
89 case EUsbcDeviceStateAttached:
90 RDebug::Printf("<Client State> Attached to host but not powered");
93 case EUsbcDeviceStatePowered:
94 RDebug::Printf("<Client State> Attached and powered but no reset");
97 case EUsbcDeviceStateDefault:
98 RDebug::Printf("<Client State> Reset but not addressed");
101 case EUsbcDeviceStateAddress:
102 RDebug::Printf("<Client State> Addressed but not configured");
105 case EUsbcDeviceStateConfigured:
106 RDebug::Printf("<Client State> Fully configured");
109 case EUsbcDeviceStateSuspended:
110 RDebug::Printf("<Client State> Suspended");
113 case EUsbcNoState: //follow through
115 RDebug::Printf("<Client State> Not specified");
121 RDebug::Printf("<Client State> Notification error %d",completionCode);
124 // Device state change
125 iStateObserver.StateChangeL(static_cast<TUsbcDeviceState>(iState),completionCode);
128 // Keep asking to be informed for status notifications
129 iClientDriver.AlternateDeviceStatusNotify(iStatus,iState);
134 TInt CUsbClientStateWatcher::RunError(TInt aError)
145 CAlternateInterfaceSelectionWatcher* CAlternateInterfaceSelectionWatcher::NewL(
146 RDevUsbcClient& aClientDriver,MAlternateSettingObserver& aObserver)
148 CAlternateInterfaceSelectionWatcher* self = new (ELeave) CAlternateInterfaceSelectionWatcher(aClientDriver,aObserver);
149 CleanupStack::PushL(self);
151 CleanupStack::Pop(self);
156 CAlternateInterfaceSelectionWatcher::CAlternateInterfaceSelectionWatcher(
157 RDevUsbcClient& aClientDriver,MAlternateSettingObserver& aObserver)
158 : CActive(EPriorityUserInput),
159 iClientDriver(aClientDriver),
162 CActiveScheduler::Add(this);
166 CAlternateInterfaceSelectionWatcher::~CAlternateInterfaceSelectionWatcher()
174 void CAlternateInterfaceSelectionWatcher::ConstructL()
178 iClientDriver.AlternateDeviceStatusNotify(iStatus,iState);
183 void CAlternateInterfaceSelectionWatcher::DoCancel()
187 iClientDriver.AlternateDeviceStatusNotifyCancel();
191 void CAlternateInterfaceSelectionWatcher::RunL()
195 TInt completionCode(iStatus.Int());
197 if(iState & KUsbAlternateSetting)
199 iObserver.AlternateInterfaceSelectedL(iState & (~KUsbAlternateSetting));
201 // Keep asking to be informed for status notifications
202 iClientDriver.AlternateDeviceStatusNotify(iStatus,iState);
207 TInt CAlternateInterfaceSelectionWatcher::RunError(TInt aError)