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