os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/src/Ep0Reader.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // 
    15 //
    16 
    17 #include "Ep0Reader.h"
    18 #include "testdebug.h"
    19 
    20 namespace NUnitTesting_USBDI
    21 	{
    22 	
    23 CDeviceEndpoint0* CDeviceEndpoint0::NewL(MRequestHandler& aRequestHandler)
    24 	{
    25 	CDeviceEndpoint0* self = new (ELeave) CDeviceEndpoint0();
    26 	CleanupStack::PushL(self);
    27 	self->ConstructL(aRequestHandler);
    28 	CleanupStack::Pop(self);
    29 	return self;
    30 	}
    31 	
    32 	
    33 CDeviceEndpoint0::CDeviceEndpoint0()
    34 	{
    35 	}	
    36 	
    37 	
    38 CDeviceEndpoint0::~CDeviceEndpoint0()
    39 	{
    40 	LOG_FUNC
    41 
    42 	// Destroy the reader/writer
    43 	delete iEndpoint0Writer; 
    44 	delete iEndpoint0Reader; 
    45 	
    46 	// Close channel to the driver
    47 	iClientDriver.Close();
    48 	}
    49 	
    50 	
    51 void CDeviceEndpoint0::ConstructL(MRequestHandler& aRequestHandler)
    52 	{
    53 	LOG_FUNC
    54 	TInt err(iClientDriver.Open(0));
    55 	if(err != KErrNone)
    56 		{
    57 		RDebug::Printf("<Error %d> Unable to open a channel to USB client driver",err);
    58 		User::Leave(err);
    59 		}
    60 	
    61 	// Create the reader of data on device endpoint 0
    62 	iEndpoint0Reader = new (ELeave) CControlEndpointReader(iClientDriver,aRequestHandler);
    63 	
    64 	// Create the writer of data on device endpoint 0
    65 	iEndpoint0Writer = new (ELeave) CEndpointWriter(iClientDriver,EEndpoint0);
    66 	}
    67 
    68 	
    69 TInt CDeviceEndpoint0::Start()
    70 	{
    71 	LOG_FUNC
    72 	
    73 	// Make this channel to the driver able to get device directed ep0 requests
    74 	TInt err(iClientDriver.SetDeviceControl());
    75 	
    76 	// Check operation success
    77 	if(err != KErrNone)
    78 		{
    79 		RDebug::Printf("<Error %d> Unable to obtain device control",err);
    80 		return err;
    81 		}
    82 		
    83 	// Start reading for requests from host
    84 	TRAP(err,iEndpoint0Reader->ReadRequestsL());
    85 	
    86 	return err;
    87 	}
    88 
    89 
    90 TInt CDeviceEndpoint0::Stop()
    91 	{
    92 	LOG_FUNC
    93 	// Cancel the data reader and writer
    94 	iEndpoint0Writer->Cancel();
    95 	iEndpoint0Reader->Cancel();
    96 	
    97 	// Give device control back
    98 	TInt err(iClientDriver.ReleaseDeviceControl());
    99 	if(err != KErrNone)
   100 		{
   101 		RDebug::Printf("<Error %d> Unable to release device control",err);
   102 		}
   103 	return err;
   104 	}
   105 
   106 
   107 void CDeviceEndpoint0::SendData(const TDesC8& aData)
   108 	{
   109 	LOG_FUNC
   110 	iEndpoint0Writer->Write(aData, ETrue);
   111 	}
   112 
   113 TInt CDeviceEndpoint0::SendDataSynchronous(const TDesC8& aData)
   114 	{
   115 	LOG_FUNC
   116 	return iEndpoint0Writer->WriteSynchronous(aData, ETrue);
   117 	}
   118 
   119 CControlEndpointReader& CDeviceEndpoint0::Reader()
   120 	{
   121 	return *iEndpoint0Reader;
   122 	}
   123 
   124 	}
   125