kerneltest/e32test/usbho/t_usbdi/src/Ep0Reader.cpp
changeset 259 57b9594f5772
parent 0 a41df078684a
child 257 3e88ff8f41d5
equal deleted inserted replaced
247:d8d70de2bd36 259:57b9594f5772
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    14 // 
    14 // 
    15 //
    15 //
    16 
    16 
    17 #include "Ep0Reader.h"
    17 #include "Ep0Reader.h"
    18 #include "testdebug.h"
    18 #include "testdebug.h"
       
    19 #include "OstTraceDefinitions.h"
       
    20 #ifdef OST_TRACE_COMPILER_IN_USE
       
    21 #include "Ep0ReaderTraces.h"
       
    22 #endif
    19 
    23 
    20 namespace NUnitTesting_USBDI
    24 namespace NUnitTesting_USBDI
    21 	{
    25 	{
    22 	
    26 	
    23 CDeviceEndpoint0* CDeviceEndpoint0::NewL(MRequestHandler& aRequestHandler)
    27 CDeviceEndpoint0* CDeviceEndpoint0::NewL(MRequestHandler& aRequestHandler)
    24 	{
    28 	{
       
    29 	OstTraceFunctionEntry1( CDEVICEENDPOINT0_NEWL_ENTRY, ( TUint )&( aRequestHandler ) );
    25 	CDeviceEndpoint0* self = new (ELeave) CDeviceEndpoint0();
    30 	CDeviceEndpoint0* self = new (ELeave) CDeviceEndpoint0();
    26 	CleanupStack::PushL(self);
    31 	CleanupStack::PushL(self);
    27 	self->ConstructL(aRequestHandler);
    32 	self->ConstructL(aRequestHandler);
    28 	CleanupStack::Pop(self);
    33 	CleanupStack::Pop(self);
       
    34 	OstTraceFunctionExit1( CDEVICEENDPOINT0_NEWL_EXIT, ( TUint )( self ) );
    29 	return self;
    35 	return self;
    30 	}
    36 	}
    31 	
    37 	
    32 	
    38 	
    33 CDeviceEndpoint0::CDeviceEndpoint0()
    39 CDeviceEndpoint0::CDeviceEndpoint0()
    34 	{
    40 	{
       
    41 	OstTraceFunctionEntry1( CDEVICEENDPOINT0_CDEVICEENDPOINT0_ENTRY, this );
       
    42 	OstTraceFunctionExit1( CDEVICEENDPOINT0_CDEVICEENDPOINT0_EXIT, this );
    35 	}	
    43 	}	
    36 	
    44 	
    37 	
    45 	
    38 CDeviceEndpoint0::~CDeviceEndpoint0()
    46 CDeviceEndpoint0::~CDeviceEndpoint0()
    39 	{
    47 	{
    40 	LOG_FUNC
    48     OstTraceFunctionEntry1( CDEVICEENDPOINT0_CDEVICEENDPOINT0_ENTRY_DUP01, this );
    41 
    49 
    42 	// Destroy the reader/writer
    50 	// Destroy the reader/writer
    43 	delete iEndpoint0Writer; 
    51 	delete iEndpoint0Writer; 
    44 	delete iEndpoint0Reader; 
    52 	delete iEndpoint0Reader; 
    45 	
    53 	
    46 	// Close channel to the driver
    54 	// Close channel to the driver
    47 	iClientDriver.Close();
    55 	iClientDriver.Close();
       
    56 	OstTraceFunctionExit1( CDEVICEENDPOINT0_CDEVICEENDPOINT0_EXIT_DUP01, this );
    48 	}
    57 	}
    49 	
    58 	
    50 	
    59 	
    51 void CDeviceEndpoint0::ConstructL(MRequestHandler& aRequestHandler)
    60 void CDeviceEndpoint0::ConstructL(MRequestHandler& aRequestHandler)
    52 	{
    61 	{
    53 	LOG_FUNC
    62 	OstTraceFunctionEntryExt( CDEVICEENDPOINT0_CONSTRUCTL_ENTRY, this );
    54 	TInt err(iClientDriver.Open(0));
    63 	TInt err(iClientDriver.Open(0));
    55 	if(err != KErrNone)
    64 	if(err != KErrNone)
    56 		{
    65 		{
    57 		RDebug::Printf("<Error %d> Unable to open a channel to USB client driver",err);
    66 		OstTrace1(TRACE_NORMAL, CDEVICEENDPOINT0_CONSTRUCTL, "<Error %d> Unable to open a channel to USB client driver",err);
    58 		User::Leave(err);
    67 		User::Leave(err);
    59 		}
    68 		}
    60 	
    69 	
    61 	// Create the reader of data on device endpoint 0
    70 	// Create the reader of data on device endpoint 0
    62 	iEndpoint0Reader = new (ELeave) CControlEndpointReader(iClientDriver,aRequestHandler);
    71 	iEndpoint0Reader = new (ELeave) CControlEndpointReader(iClientDriver,aRequestHandler);
    63 	
    72 	
    64 	// Create the writer of data on device endpoint 0
    73 	// Create the writer of data on device endpoint 0
    65 	iEndpoint0Writer = new (ELeave) CEndpointWriter(iClientDriver,EEndpoint0);
    74 	iEndpoint0Writer = new (ELeave) CEndpointWriter(iClientDriver,EEndpoint0);
       
    75 	OstTraceFunctionExit1( CDEVICEENDPOINT0_CONSTRUCTL_EXIT, this );
    66 	}
    76 	}
    67 
    77 
    68 	
    78 	
    69 TInt CDeviceEndpoint0::Start()
    79 TInt CDeviceEndpoint0::Start()
    70 	{
    80 	{
    71 	LOG_FUNC
    81 	OstTraceFunctionEntry1( CDEVICEENDPOINT0_START_ENTRY, this );
    72 	
    82 	
    73 	// Make this channel to the driver able to get device directed ep0 requests
    83 	// Make this channel to the driver able to get device directed ep0 requests
    74 	TInt err(iClientDriver.SetDeviceControl());
    84 	TInt err(iClientDriver.SetDeviceControl());
    75 	
    85 	
    76 	// Check operation success
    86 	// Check operation success
    77 	if(err != KErrNone)
    87 	if(err != KErrNone)
    78 		{
    88 		{
    79 		RDebug::Printf("<Error %d> Unable to obtain device control",err);
    89 		OstTrace1(TRACE_NORMAL, CDEVICEENDPOINT0_START, "<Error %d> Unable to obtain device control",err);
       
    90 		OstTraceFunctionExitExt( CDEVICEENDPOINT0_START_EXIT, this, err );
    80 		return err;
    91 		return err;
    81 		}
    92 		}
    82 		
    93 		
    83 	// Start reading for requests from host
    94 	// Start reading for requests from host
    84 	TRAP(err,iEndpoint0Reader->ReadRequestsL());
    95 	TRAP(err,iEndpoint0Reader->ReadRequestsL());
    85 	
    96 	
       
    97 	OstTraceFunctionExitExt( CDEVICEENDPOINT0_START_EXIT_DUP01, this, err );
    86 	return err;
    98 	return err;
    87 	}
    99 	}
    88 
   100 
    89 
   101 
    90 TInt CDeviceEndpoint0::Stop()
   102 TInt CDeviceEndpoint0::Stop()
    91 	{
   103 	{
    92 	LOG_FUNC
   104 	OstTraceFunctionEntry1( CDEVICEENDPOINT0_STOP_ENTRY, this );
    93 	// Cancel the data reader and writer
   105 	// Cancel the data reader and writer
    94 	iEndpoint0Writer->Cancel();
   106 	iEndpoint0Writer->Cancel();
    95 	iEndpoint0Reader->Cancel();
   107 	iEndpoint0Reader->Cancel();
    96 	
   108 	
    97 	// Give device control back
   109 	// Give device control back
    98 	TInt err(iClientDriver.ReleaseDeviceControl());
   110 	TInt err(iClientDriver.ReleaseDeviceControl());
    99 	if(err != KErrNone)
   111 	if(err != KErrNone)
   100 		{
   112 		{
   101 		RDebug::Printf("<Error %d> Unable to release device control",err);
   113 		OstTrace1(TRACE_NORMAL, CDEVICEENDPOINT0_STOP, "<Error %d> Unable to release device control",err);
   102 		}
   114 		}
       
   115 	OstTraceFunctionExitExt( CDEVICEENDPOINT0_STOP_EXIT, this, err );
   103 	return err;
   116 	return err;
   104 	}
   117 	}
   105 
   118 
   106 
   119 
   107 void CDeviceEndpoint0::SendData(const TDesC8& aData)
   120 void CDeviceEndpoint0::SendData(const TDesC8& aData)
   108 	{
   121 	{
   109 	LOG_FUNC
   122 	OstTraceFunctionEntryExt( CDEVICEENDPOINT0_SENDDATA_ENTRY, this );
   110 	iEndpoint0Writer->Write(aData, ETrue);
   123 	iEndpoint0Writer->Write(aData, ETrue);
       
   124 	OstTraceFunctionExit1( CDEVICEENDPOINT0_SENDDATA_EXIT, this );
   111 	}
   125 	}
   112 
   126 
   113 TInt CDeviceEndpoint0::SendDataSynchronous(const TDesC8& aData)
   127 TInt CDeviceEndpoint0::SendDataSynchronous(const TDesC8& aData)
   114 	{
   128 	{
   115 	LOG_FUNC
   129 	OstTraceFunctionEntryExt( CDEVICEENDPOINT0_SENDDATASYNCHRONOUS_ENTRY, this );
   116 	return iEndpoint0Writer->WriteSynchronous(aData, ETrue);
   130 	TInt ret = iEndpoint0Writer->WriteSynchronous(aData, ETrue);
       
   131 	OstTraceFunctionExit1( CDEVICEENDPOINT0_SENDDATASYNCHRONOUS_EXIT, this );
       
   132 	return ret;
   117 	}
   133 	}
   118 
   134 
   119 CControlEndpointReader& CDeviceEndpoint0::Reader()
   135 CControlEndpointReader& CDeviceEndpoint0::Reader()
   120 	{
   136 	{
       
   137 	OstTraceFunctionEntry1( CDEVICEENDPOINT0_READER_ENTRY, this );
       
   138 	OstTraceFunctionExit1( CDEVICEENDPOINT0_READER_EXIT, this );
   121 	return *iEndpoint0Reader;
   139 	return *iEndpoint0Reader;
   122 	}
   140 	}
   123 
   141 
   124 	}
   142 	}
   125 
   143