253
|
1 |
// Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
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"
|
253
|
19 |
#include "OstTraceDefinitions.h"
|
|
20 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
21 |
#include "Ep0ReaderTraces.h"
|
|
22 |
#endif
|
0
|
23 |
|
|
24 |
namespace NUnitTesting_USBDI
|
|
25 |
{
|
|
26 |
|
|
27 |
CDeviceEndpoint0* CDeviceEndpoint0::NewL(MRequestHandler& aRequestHandler)
|
|
28 |
{
|
253
|
29 |
OstTraceFunctionEntry1( CDEVICEENDPOINT0_NEWL_ENTRY, ( TUint )&( aRequestHandler ) );
|
0
|
30 |
CDeviceEndpoint0* self = new (ELeave) CDeviceEndpoint0();
|
|
31 |
CleanupStack::PushL(self);
|
|
32 |
self->ConstructL(aRequestHandler);
|
|
33 |
CleanupStack::Pop(self);
|
253
|
34 |
OstTraceFunctionExit1( CDEVICEENDPOINT0_NEWL_EXIT, ( TUint )( self ) );
|
0
|
35 |
return self;
|
|
36 |
}
|
|
37 |
|
|
38 |
|
|
39 |
CDeviceEndpoint0::CDeviceEndpoint0()
|
|
40 |
{
|
253
|
41 |
OstTraceFunctionEntry1( CDEVICEENDPOINT0_CDEVICEENDPOINT0_ENTRY, this );
|
|
42 |
OstTraceFunctionExit1( CDEVICEENDPOINT0_CDEVICEENDPOINT0_EXIT, this );
|
0
|
43 |
}
|
|
44 |
|
|
45 |
|
|
46 |
CDeviceEndpoint0::~CDeviceEndpoint0()
|
|
47 |
{
|
253
|
48 |
OstTraceFunctionEntry1( CDEVICEENDPOINT0_CDEVICEENDPOINT0_ENTRY_DUP01, this );
|
0
|
49 |
|
|
50 |
// Destroy the reader/writer
|
|
51 |
delete iEndpoint0Writer;
|
|
52 |
delete iEndpoint0Reader;
|
|
53 |
|
|
54 |
// Close channel to the driver
|
|
55 |
iClientDriver.Close();
|
253
|
56 |
OstTraceFunctionExit1( CDEVICEENDPOINT0_CDEVICEENDPOINT0_EXIT_DUP01, this );
|
0
|
57 |
}
|
|
58 |
|
|
59 |
|
|
60 |
void CDeviceEndpoint0::ConstructL(MRequestHandler& aRequestHandler)
|
|
61 |
{
|
253
|
62 |
OstTraceFunctionEntryExt( CDEVICEENDPOINT0_CONSTRUCTL_ENTRY, this );
|
0
|
63 |
TInt err(iClientDriver.Open(0));
|
|
64 |
if(err != KErrNone)
|
|
65 |
{
|
253
|
66 |
OstTrace1(TRACE_NORMAL, CDEVICEENDPOINT0_CONSTRUCTL, "<Error %d> Unable to open a channel to USB client driver",err);
|
0
|
67 |
User::Leave(err);
|
|
68 |
}
|
|
69 |
|
|
70 |
// Create the reader of data on device endpoint 0
|
|
71 |
iEndpoint0Reader = new (ELeave) CControlEndpointReader(iClientDriver,aRequestHandler);
|
|
72 |
|
|
73 |
// Create the writer of data on device endpoint 0
|
|
74 |
iEndpoint0Writer = new (ELeave) CEndpointWriter(iClientDriver,EEndpoint0);
|
253
|
75 |
OstTraceFunctionExit1( CDEVICEENDPOINT0_CONSTRUCTL_EXIT, this );
|
0
|
76 |
}
|
|
77 |
|
|
78 |
|
|
79 |
TInt CDeviceEndpoint0::Start()
|
|
80 |
{
|
253
|
81 |
OstTraceFunctionEntry1( CDEVICEENDPOINT0_START_ENTRY, this );
|
0
|
82 |
|
|
83 |
// Make this channel to the driver able to get device directed ep0 requests
|
|
84 |
TInt err(iClientDriver.SetDeviceControl());
|
|
85 |
|
|
86 |
// Check operation success
|
|
87 |
if(err != KErrNone)
|
|
88 |
{
|
253
|
89 |
OstTrace1(TRACE_NORMAL, CDEVICEENDPOINT0_START, "<Error %d> Unable to obtain device control",err);
|
|
90 |
OstTraceFunctionExitExt( CDEVICEENDPOINT0_START_EXIT, this, err );
|
0
|
91 |
return err;
|
|
92 |
}
|
|
93 |
|
|
94 |
// Start reading for requests from host
|
|
95 |
TRAP(err,iEndpoint0Reader->ReadRequestsL());
|
|
96 |
|
253
|
97 |
OstTraceFunctionExitExt( CDEVICEENDPOINT0_START_EXIT_DUP01, this, err );
|
0
|
98 |
return err;
|
|
99 |
}
|
|
100 |
|
|
101 |
|
|
102 |
TInt CDeviceEndpoint0::Stop()
|
|
103 |
{
|
253
|
104 |
OstTraceFunctionEntry1( CDEVICEENDPOINT0_STOP_ENTRY, this );
|
0
|
105 |
// Cancel the data reader and writer
|
|
106 |
iEndpoint0Writer->Cancel();
|
|
107 |
iEndpoint0Reader->Cancel();
|
|
108 |
|
|
109 |
// Give device control back
|
|
110 |
TInt err(iClientDriver.ReleaseDeviceControl());
|
|
111 |
if(err != KErrNone)
|
|
112 |
{
|
253
|
113 |
OstTrace1(TRACE_NORMAL, CDEVICEENDPOINT0_STOP, "<Error %d> Unable to release device control",err);
|
0
|
114 |
}
|
253
|
115 |
OstTraceFunctionExitExt( CDEVICEENDPOINT0_STOP_EXIT, this, err );
|
0
|
116 |
return err;
|
|
117 |
}
|
|
118 |
|
|
119 |
|
|
120 |
void CDeviceEndpoint0::SendData(const TDesC8& aData)
|
|
121 |
{
|
253
|
122 |
OstTraceFunctionEntryExt( CDEVICEENDPOINT0_SENDDATA_ENTRY, this );
|
0
|
123 |
iEndpoint0Writer->Write(aData, ETrue);
|
253
|
124 |
OstTraceFunctionExit1( CDEVICEENDPOINT0_SENDDATA_EXIT, this );
|
0
|
125 |
}
|
|
126 |
|
|
127 |
TInt CDeviceEndpoint0::SendDataSynchronous(const TDesC8& aData)
|
|
128 |
{
|
253
|
129 |
OstTraceFunctionEntryExt( CDEVICEENDPOINT0_SENDDATASYNCHRONOUS_ENTRY, this );
|
|
130 |
TInt ret = iEndpoint0Writer->WriteSynchronous(aData, ETrue);
|
|
131 |
OstTraceFunctionExit1( CDEVICEENDPOINT0_SENDDATASYNCHRONOUS_EXIT, this );
|
|
132 |
return ret;
|
0
|
133 |
}
|
|
134 |
|
|
135 |
CControlEndpointReader& CDeviceEndpoint0::Reader()
|
|
136 |
{
|
253
|
137 |
OstTraceFunctionEntry1( CDEVICEENDPOINT0_READER_ENTRY, this );
|
|
138 |
OstTraceFunctionExit1( CDEVICEENDPOINT0_READER_EXIT, this );
|
0
|
139 |
return *iEndpoint0Reader;
|
|
140 |
}
|
|
141 |
|
|
142 |
}
|
|
143 |
|