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