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.
17 #include "Ep0Reader.h"
18 #include "testdebug.h"
20 namespace NUnitTesting_USBDI
23 CDeviceEndpoint0* CDeviceEndpoint0::NewL(MRequestHandler& aRequestHandler)
25 CDeviceEndpoint0* self = new (ELeave) CDeviceEndpoint0();
26 CleanupStack::PushL(self);
27 self->ConstructL(aRequestHandler);
28 CleanupStack::Pop(self);
33 CDeviceEndpoint0::CDeviceEndpoint0()
38 CDeviceEndpoint0::~CDeviceEndpoint0()
42 // Destroy the reader/writer
43 delete iEndpoint0Writer;
44 delete iEndpoint0Reader;
46 // Close channel to the driver
47 iClientDriver.Close();
51 void CDeviceEndpoint0::ConstructL(MRequestHandler& aRequestHandler)
54 TInt err(iClientDriver.Open(0));
57 RDebug::Printf("<Error %d> Unable to open a channel to USB client driver",err);
61 // Create the reader of data on device endpoint 0
62 iEndpoint0Reader = new (ELeave) CControlEndpointReader(iClientDriver,aRequestHandler);
64 // Create the writer of data on device endpoint 0
65 iEndpoint0Writer = new (ELeave) CEndpointWriter(iClientDriver,EEndpoint0);
69 TInt CDeviceEndpoint0::Start()
73 // Make this channel to the driver able to get device directed ep0 requests
74 TInt err(iClientDriver.SetDeviceControl());
76 // Check operation success
79 RDebug::Printf("<Error %d> Unable to obtain device control",err);
83 // Start reading for requests from host
84 TRAP(err,iEndpoint0Reader->ReadRequestsL());
90 TInt CDeviceEndpoint0::Stop()
93 // Cancel the data reader and writer
94 iEndpoint0Writer->Cancel();
95 iEndpoint0Reader->Cancel();
97 // Give device control back
98 TInt err(iClientDriver.ReleaseDeviceControl());
101 RDebug::Printf("<Error %d> Unable to release device control",err);
107 void CDeviceEndpoint0::SendData(const TDesC8& aData)
110 iEndpoint0Writer->Write(aData, ETrue);
113 TInt CDeviceEndpoint0::SendDataSynchronous(const TDesC8& aData)
116 return iEndpoint0Writer->WriteSynchronous(aData, ETrue);
119 CControlEndpointReader& CDeviceEndpoint0::Reader()
121 return *iEndpoint0Reader;