1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/Ep0Reader.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,125 @@
1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +//
1.19 +
1.20 +#include "Ep0Reader.h"
1.21 +#include "testdebug.h"
1.22 +
1.23 +namespace NUnitTesting_USBDI
1.24 + {
1.25 +
1.26 +CDeviceEndpoint0* CDeviceEndpoint0::NewL(MRequestHandler& aRequestHandler)
1.27 + {
1.28 + CDeviceEndpoint0* self = new (ELeave) CDeviceEndpoint0();
1.29 + CleanupStack::PushL(self);
1.30 + self->ConstructL(aRequestHandler);
1.31 + CleanupStack::Pop(self);
1.32 + return self;
1.33 + }
1.34 +
1.35 +
1.36 +CDeviceEndpoint0::CDeviceEndpoint0()
1.37 + {
1.38 + }
1.39 +
1.40 +
1.41 +CDeviceEndpoint0::~CDeviceEndpoint0()
1.42 + {
1.43 + LOG_FUNC
1.44 +
1.45 + // Destroy the reader/writer
1.46 + delete iEndpoint0Writer;
1.47 + delete iEndpoint0Reader;
1.48 +
1.49 + // Close channel to the driver
1.50 + iClientDriver.Close();
1.51 + }
1.52 +
1.53 +
1.54 +void CDeviceEndpoint0::ConstructL(MRequestHandler& aRequestHandler)
1.55 + {
1.56 + LOG_FUNC
1.57 + TInt err(iClientDriver.Open(0));
1.58 + if(err != KErrNone)
1.59 + {
1.60 + RDebug::Printf("<Error %d> Unable to open a channel to USB client driver",err);
1.61 + User::Leave(err);
1.62 + }
1.63 +
1.64 + // Create the reader of data on device endpoint 0
1.65 + iEndpoint0Reader = new (ELeave) CControlEndpointReader(iClientDriver,aRequestHandler);
1.66 +
1.67 + // Create the writer of data on device endpoint 0
1.68 + iEndpoint0Writer = new (ELeave) CEndpointWriter(iClientDriver,EEndpoint0);
1.69 + }
1.70 +
1.71 +
1.72 +TInt CDeviceEndpoint0::Start()
1.73 + {
1.74 + LOG_FUNC
1.75 +
1.76 + // Make this channel to the driver able to get device directed ep0 requests
1.77 + TInt err(iClientDriver.SetDeviceControl());
1.78 +
1.79 + // Check operation success
1.80 + if(err != KErrNone)
1.81 + {
1.82 + RDebug::Printf("<Error %d> Unable to obtain device control",err);
1.83 + return err;
1.84 + }
1.85 +
1.86 + // Start reading for requests from host
1.87 + TRAP(err,iEndpoint0Reader->ReadRequestsL());
1.88 +
1.89 + return err;
1.90 + }
1.91 +
1.92 +
1.93 +TInt CDeviceEndpoint0::Stop()
1.94 + {
1.95 + LOG_FUNC
1.96 + // Cancel the data reader and writer
1.97 + iEndpoint0Writer->Cancel();
1.98 + iEndpoint0Reader->Cancel();
1.99 +
1.100 + // Give device control back
1.101 + TInt err(iClientDriver.ReleaseDeviceControl());
1.102 + if(err != KErrNone)
1.103 + {
1.104 + RDebug::Printf("<Error %d> Unable to release device control",err);
1.105 + }
1.106 + return err;
1.107 + }
1.108 +
1.109 +
1.110 +void CDeviceEndpoint0::SendData(const TDesC8& aData)
1.111 + {
1.112 + LOG_FUNC
1.113 + iEndpoint0Writer->Write(aData, ETrue);
1.114 + }
1.115 +
1.116 +TInt CDeviceEndpoint0::SendDataSynchronous(const TDesC8& aData)
1.117 + {
1.118 + LOG_FUNC
1.119 + return iEndpoint0Writer->WriteSynchronous(aData, ETrue);
1.120 + }
1.121 +
1.122 +CControlEndpointReader& CDeviceEndpoint0::Reader()
1.123 + {
1.124 + return *iEndpoint0Reader;
1.125 + }
1.126 +
1.127 + }
1.128 +