0
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// INCLUDE FILES
|
|
19 |
#include "cusbpnusbsender.h"
|
|
20 |
#include "cusbpnpacket.h"
|
|
21 |
#include "musbpnbufferlistener.h"
|
|
22 |
#include "usbpndefinitions.h" // For constants
|
|
23 |
#include "usbpntrace.h"
|
|
24 |
|
|
25 |
#include "osttracedefinitions.h"
|
|
26 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
27 |
#include "cusbpnusbsenderTraces.h"
|
|
28 |
#endif
|
|
29 |
|
|
30 |
#include <d32usbc.h> // RDevUsbcClient
|
|
31 |
|
|
32 |
// EXTERNAL DATA STRUCTURES
|
|
33 |
// EXTERNAL FUNCTION PROTOTYPES
|
|
34 |
// CONSTANTS
|
|
35 |
// MACROS
|
|
36 |
// LOCAL CONSTANTS AND MACROS
|
|
37 |
// MODULE DATA STRUCTURES
|
|
38 |
// LOCAL FUNCTION PROTOTYPES
|
|
39 |
// FORWARD DECLARATIONS
|
|
40 |
|
|
41 |
// ============================= LOCAL FUNCTIONS ===============================
|
|
42 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
43 |
|
|
44 |
// -----------------------------------------------------------------------------
|
|
45 |
// CUsbPnUsbSender::CUsbPnUsbSender
|
|
46 |
// C++ default constructor can NOT contain any code, that
|
|
47 |
// might leave.
|
|
48 |
// -----------------------------------------------------------------------------
|
|
49 |
//
|
|
50 |
CUsbPnUsbSender::CUsbPnUsbSender( MUsbPnBufferListener& aListener, RDevUsbcClient& aLdd )
|
|
51 |
:CActive( 100 ) //ECommTransmitPriority=100 in es_prot.h
|
|
52 |
,iBufferListener( aListener )
|
|
53 |
,iLdd( aLdd )
|
|
54 |
,iPacketCount( 0 )
|
|
55 |
,iPacket( NULL )
|
|
56 |
{
|
|
57 |
OstTraceExt2( TRACE_NORMAL, CUSBPNUSBSENDER_CUSBPNUSBSENDER_ENTRY, "CUsbPnUsbSender::CUsbPnUsbSender;aListener=%x;aLdd=%x", ( TUint )&( aListener ), ( TUint )&( aLdd ) );
|
|
58 |
C_TRACE( ( _T( "CUsbPnUsbSender::CUsbPnUsbSender( aListener:0x%x, aLdd:0x%x )" ), &aListener, &aLdd ) );
|
|
59 |
|
|
60 |
CActiveScheduler::Add(this);
|
|
61 |
|
|
62 |
OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_CUSBPNUSBSENDER_EXIT, "CUsbPnUsbSender::CUsbPnUsbSender - return" );
|
|
63 |
C_TRACE( ( _T( "CUsbPnUsbSender::CUsbPnUsbSender() - return" ) ) );
|
|
64 |
}
|
|
65 |
|
|
66 |
// -----------------------------------------------------------------------------
|
|
67 |
// CUsbPnUsbSender::ConstructL
|
|
68 |
// Symbian 2nd phase constructor can leave.
|
|
69 |
// -----------------------------------------------------------------------------
|
|
70 |
//
|
|
71 |
void CUsbPnUsbSender::ConstructL()
|
|
72 |
{
|
|
73 |
OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_CONSTRUCTL_ENTRY, "CUsbPnUsbSender::ConstructL" );
|
|
74 |
C_TRACE( ( _T( "CUsbPnUsbSender::ConstructL()" ) ) );
|
|
75 |
|
|
76 |
// Create circular buffer objects
|
|
77 |
for(TUint i = 1; i < (KPnUsbPacketCount + 1); i++)
|
|
78 |
{
|
|
79 |
AddPacketBufferL(i);
|
|
80 |
}
|
|
81 |
iCurrentPacket = iPacket;
|
|
82 |
|
|
83 |
OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_CONSTRUCTL_EXIT, "CUsbPnUsbSender::ConstructL - return void" );
|
|
84 |
C_TRACE( ( _T( "CUsbPnUsbSender::ConstructL() - return void" ) ) );
|
|
85 |
}
|
|
86 |
|
|
87 |
// -----------------------------------------------------------------------------
|
|
88 |
// CUsbPnUsbSender::NewL
|
|
89 |
// Two-phased constructor.
|
|
90 |
// -----------------------------------------------------------------------------
|
|
91 |
//
|
|
92 |
CUsbPnUsbSender* CUsbPnUsbSender::NewL( MUsbPnBufferListener& aBufferListener, RDevUsbcClient& aLdd )
|
|
93 |
{
|
|
94 |
OstTraceExt2( TRACE_NORMAL, CUSBPNUSBSENDER_NEWL_ENTRY, "CUsbPnUsbSender::NewL;aBufferListener=%x;aLdd=%x", ( TUint )&( aBufferListener ), ( TUint )&( aLdd ) );
|
|
95 |
C_TRACE( ( _T( "CUsbPnUsbSender::NewL( aBufferListener:0x%x, aLdd:0x%x )" ), &aBufferListener, &aLdd ) );
|
|
96 |
|
|
97 |
CUsbPnUsbSender* self = new( ELeave ) CUsbPnUsbSender( aBufferListener, aLdd );
|
|
98 |
|
|
99 |
CleanupStack::PushL( self );
|
|
100 |
self->ConstructL();
|
|
101 |
CleanupStack::Pop();
|
|
102 |
|
|
103 |
OstTrace1( TRACE_NORMAL, CUSBPNUSBSENDER_NEWL_EXIT, "CUsbPnUsbSender::NewL - return;self=%x", self );
|
|
104 |
C_TRACE( ( _T( "CUsbPnUsbSender::NewL() - return 0x%x" ), self ) );
|
|
105 |
return self;
|
|
106 |
}
|
|
107 |
|
|
108 |
|
|
109 |
// Destructor
|
|
110 |
CUsbPnUsbSender::~CUsbPnUsbSender()
|
|
111 |
{
|
|
112 |
OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_CUSBPNUSBSENDER_DESTRUCTOR_ENTRY, "CUsbPnUsbSender::~CUsbPnUsbSender" );
|
|
113 |
C_TRACE( ( _T( "CUsbPnUsbSender::~CUsbPnUsbSender()" ) ) );
|
|
114 |
|
|
115 |
Cancel();
|
|
116 |
|
|
117 |
// Delete circular buffer objects
|
|
118 |
CUsbPnPacket* packet;
|
|
119 |
while(iPacketCount > 0)
|
|
120 |
{
|
|
121 |
iPacketCount--;
|
|
122 |
packet = &iPacket->NextPacket();
|
|
123 |
delete iPacket;
|
|
124 |
iPacket = packet;
|
|
125 |
}
|
|
126 |
iCurrentPacket = NULL;
|
|
127 |
iPacket = NULL;
|
|
128 |
|
|
129 |
OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_CUSBPNUSBSENDER_DESTRUCTOR_EXIT, "CUsbPnUsbSender::~CUsbPnUsbSender - return" );
|
|
130 |
C_TRACE( ( _T( "CUsbPnUsbSender::~CUsbPnUsbSender() - return" ) ) );
|
|
131 |
}
|
|
132 |
|
|
133 |
// -----------------------------------------------------------------------------
|
|
134 |
// CUsbPnUsbSender::AddPacketBufferL
|
|
135 |
// -----------------------------------------------------------------------------
|
|
136 |
void CUsbPnUsbSender::AddPacketBufferL( TInt aIndex )
|
|
137 |
{
|
|
138 |
OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_ADDPACKETBUFFERL_ENTRY, "CUsbPnUsbSender::AddPacketBufferL" );
|
|
139 |
C_TRACE((_T("CUsbPnUsbSender::AddPacketBuffer()")));
|
|
140 |
|
|
141 |
iPacketCount++;
|
|
142 |
iPacket = CUsbPnPacket::NewL( iPacket, aIndex );
|
|
143 |
|
|
144 |
OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_ADDPACKETBUFFERL_EXIT, "CUsbPnUsbSender::AddPacketBufferL - return void" );
|
|
145 |
C_TRACE((_T("CUsbPnUsbSender::AddPacketBuffer - return void")));
|
|
146 |
}
|
|
147 |
|
|
148 |
// -----------------------------------------------------------------------------
|
|
149 |
// CUsbPnUsbSender::PacketL
|
|
150 |
// -----------------------------------------------------------------------------
|
|
151 |
CUsbPnPacket& CUsbPnUsbSender::PacketL()
|
|
152 |
{
|
|
153 |
OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_PACKETL_ENTRY, "CUsbPnUsbSender::PacketL" );
|
|
154 |
C_TRACE((_T("CUsbPnUsbSender::PacketL()")));
|
|
155 |
|
|
156 |
CUsbPnPacket& packet( iPacket->NextPacket() );
|
|
157 |
TBool err = packet.PacketInUse();
|
|
158 |
if (EFalse != err)
|
|
159 |
{
|
|
160 |
User::Leave( err );
|
|
161 |
}
|
|
162 |
|
|
163 |
OstTrace1( TRACE_NORMAL, CUSBPNUSBSENDER_PACKETL_EXIT, "CUsbPnUsbSender::PacketL - return;packet=%d", packet.PacketNumber() );
|
|
164 |
C_TRACE((_T("CUsbPnUsbSender::PacketL() - return packet:%d"), packet.PacketNumber()));
|
|
165 |
|
|
166 |
return packet;
|
|
167 |
}
|
|
168 |
|
|
169 |
// -----------------------------------------------------------------------------
|
|
170 |
// CUsbPnUsbSender::Send
|
|
171 |
// ?implementation_description
|
|
172 |
// (other items were commented in a header).
|
|
173 |
// -----------------------------------------------------------------------------
|
|
174 |
//
|
|
175 |
void CUsbPnUsbSender::Send( CUsbPnPacket& aPacket )
|
|
176 |
{
|
|
177 |
OstTrace0( TRACE_API, CUSBPNUSBSENDER_SEND_ENTRY, "CUsbPnUsbSender::Send" );
|
|
178 |
A_TRACE( ( _T( "CUsbPnUsbSender::Send()" ) ) );
|
|
179 |
|
|
180 |
iPacket = &iPacket->NextPacket();
|
|
181 |
OstTrace1( TRACE_DETAILED, CUSBPNUSBSENDER_SEND, "CUsbPnUsbSender::Send;packet number:%d", iPacket->PacketNumber() );
|
|
182 |
E_TRACE( ( _T( "CUsbPnUsbSender::Send() - packet number:%d" ), iPacket->PacketNumber() ) );
|
|
183 |
|
|
184 |
TryToSendPacket( *iPacket );
|
|
185 |
|
|
186 |
OstTrace0( TRACE_API, CUSBPNUSBSENDER_SEND_EXIT, "CUsbPnUsbSender::Send - return void" );
|
|
187 |
A_TRACE( ( _T( "CUsbPnUsbSender::Send() - return void" ) ) );
|
|
188 |
}
|
|
189 |
|
|
190 |
// -----------------------------------------------------------------------------
|
|
191 |
// CUsbPnUsbSender::TryToSendPacket
|
|
192 |
// ?implementation_description
|
|
193 |
// (other items were commented in a header).
|
|
194 |
// -----------------------------------------------------------------------------
|
|
195 |
//
|
|
196 |
void CUsbPnUsbSender::TryToSendPacket( const CUsbPnPacket& aPacket )
|
|
197 |
{
|
|
198 |
OstTraceExt2( TRACE_API, CUSBPNUSBSENDER_TRYTOSENDPACKET_ENTRY, "CUsbPnUsbSender::TryToSendPacket;aPacket=%d;iCurrentPacket=%d", aPacket.PacketNumber(), iCurrentPacket->PacketNumber() );
|
|
199 |
A_TRACE( ( _T( "CUsbPnUsbSender::TryToSendPacket( aPacketNumber:%d, iCurrentPacket:%d )" ), aPacket.PacketNumber(), iCurrentPacket->PacketNumber( ) ));
|
|
200 |
|
|
201 |
// Write message to USB
|
|
202 |
if(!IsActive())
|
|
203 |
{
|
|
204 |
if( &aPacket == &iCurrentPacket->NextPacket() || &aPacket == iCurrentPacket )
|
|
205 |
{
|
|
206 |
OstTrace0( TRACE_DETAILED, CUSBPNUSBSENDER_TRYTOSENDPACKET, "CUsbPnUsbSender::TryToSendPacket - Write to socket" );
|
|
207 |
E_TRACE( ( _T( "CUsbPnUsbSender::TryToSendPacket() - Write to socket")));
|
|
208 |
|
|
209 |
HBufC8& data(aPacket.Buffer());
|
|
210 |
TInt length( data.Length() );
|
|
211 |
#ifdef EXTENDED_TRACE_FLAG
|
|
212 |
TInt i(0);
|
|
213 |
|
|
214 |
while(i < length )
|
|
215 |
{
|
|
216 |
OstTraceExt2( TRACE_DETAILED, CUSBPNUSBSENDER_TRYTOSENDPACKET_DUP1, "CUsbPnUsbSender::Send( [%d] = %x )", i, data[i] );
|
|
217 |
E_TRACE( ( _T( "CUsbPnUsbSender::Send([%d] = %x )" ), i, data[i] ) );
|
|
218 |
i++;
|
|
219 |
}
|
|
220 |
#endif
|
|
221 |
|
|
222 |
// ZLP flag setting is optional. Could be always true as driver checks against max packet size
|
|
223 |
TBool zlp( ( length != 0 ) && ( length % KPnPacketSize ) == 0 );
|
|
224 |
|
|
225 |
iLdd.Write( iStatus, EEndpoint1, data, length, zlp );
|
|
226 |
SetActive();
|
|
227 |
}
|
|
228 |
else
|
|
229 |
{
|
|
230 |
TRACE_ASSERT_ALWAYS;
|
|
231 |
}
|
|
232 |
}
|
|
233 |
else
|
|
234 |
{
|
|
235 |
OstTrace0( TRACE_DETAILED, CUSBPNUSBSENDER_TRYTOSENDPACKET_DUP2, "CUsbPnUsbSender::TryToSendPacket - Already sending" );
|
|
236 |
E_TRACE( ( _T( "CUsbPnUsbSender::TryToSendPacket() - Already sending")));
|
|
237 |
}
|
|
238 |
|
|
239 |
OstTrace0( TRACE_API, CUSBPNUSBSENDER_TRYTOSENDPACKET_EXIT, "CUsbPnUsbSender::TryToSendPacket - return void" );
|
|
240 |
A_TRACE( ( _T( "CUsbPnUsbSender::TryToSendPacket() - return void" ) ) );
|
|
241 |
}
|
|
242 |
|
|
243 |
// -----------------------------------------------------------------------------
|
|
244 |
// CUsbPnUsbSender::DoCancel
|
|
245 |
// ?implementation_description
|
|
246 |
// (other items were commented in a header).
|
|
247 |
// -----------------------------------------------------------------------------
|
|
248 |
//
|
|
249 |
void CUsbPnUsbSender::DoCancel( )
|
|
250 |
{
|
|
251 |
OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_DOCANCEL_ENTRY, "CUsbPnUsbSender::DoCancel" );
|
|
252 |
C_TRACE( ( _T( "CUsbPnUsbSender::DoCancel()" ) ) );
|
|
253 |
iLdd.WriteCancel( EEndpoint1 );
|
|
254 |
OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_DOCANCEL_EXIT, "CUsbPnUsbSender::DoCancel - return void" );
|
|
255 |
C_TRACE( ( _T( "CUsbPnUsbSender::DoCancel() - return void" ) ) );
|
|
256 |
}
|
|
257 |
|
|
258 |
// -----------------------------------------------------------------------------
|
|
259 |
// CUsbPnUsbSender::RunL
|
|
260 |
// ?implementation_description
|
|
261 |
// (other items were commented in a header).
|
|
262 |
// -----------------------------------------------------------------------------
|
|
263 |
//
|
|
264 |
void CUsbPnUsbSender::RunL( )
|
|
265 |
{
|
|
266 |
OstTrace1( TRACE_API, CUSBPNUSBSENDER_RUNL_ENTRY, "CUsbPnUsbSender::RunL;iStatus:%d", iStatus.Int() );
|
|
267 |
A_TRACE( ( _T( "CUsbPnUsbSender::RunL() iStatus:%d" ), iStatus.Int() ) );
|
|
268 |
|
|
269 |
User::LeaveIfError( iStatus.Int() );
|
|
270 |
|
|
271 |
iCurrentPacket->ReleaseL();
|
|
272 |
iBufferListener.Receive( ETrue );
|
|
273 |
iCurrentPacket = &iCurrentPacket->NextPacket();
|
|
274 |
|
|
275 |
if(iCurrentPacket != iPacket)
|
|
276 |
{
|
|
277 |
// Continue write
|
|
278 |
OstTraceExt2( TRACE_DETAILED, CUSBPNUSBSENDER_RUNL, "CUsbPnUsbSender::RunL - Write next in queue;tail=%d;head=%d", iCurrentPacket->PacketNumber(), iPacket->PacketNumber() );
|
|
279 |
E_TRACE( ( _T( "CUsbPnUsbSender::RunL() - Write next in queue tail:%d,head:%d " ), iCurrentPacket->PacketNumber(), iPacket->PacketNumber()));
|
|
280 |
TryToSendPacket( iCurrentPacket->NextPacket() );
|
|
281 |
}
|
|
282 |
|
|
283 |
OstTrace0( TRACE_API, CUSBPNUSBSENDER_RUNL_EXIT, "CUsbPnUsbSender::RunL - return void" );
|
|
284 |
A_TRACE( ( _T( "CUsbPnUsbSender::RunL() - return void" ) ) );
|
|
285 |
}
|
|
286 |
|
|
287 |
// -----------------------------------------------------------------------------
|
|
288 |
// CUsbPnUsbSender::RunError
|
|
289 |
// ?implementation_description
|
|
290 |
// (other items were commented in a header).
|
|
291 |
// -----------------------------------------------------------------------------
|
|
292 |
//
|
|
293 |
TInt CUsbPnUsbSender::RunError( TInt aError )
|
|
294 |
{
|
|
295 |
OstTrace1( TRACE_API, CUSBPNUSBSENDER_RUNERROR_ENTRY, "CUsbPnUsbSender::RunError;aError=%d", aError );
|
|
296 |
A_TRACE( ( _T( "CUsbPnUsbSender::RunError(aError:%d)" ), aError ) );
|
|
297 |
|
|
298 |
switch( aError )
|
|
299 |
{
|
|
300 |
case KErrUsbCableDetached:
|
|
301 |
case KErrUsbDeviceBusReset:
|
|
302 |
case KErrUsbInterfaceNotReady:
|
|
303 |
case KErrUsbEpNotInInterface:
|
|
304 |
case KErrUsbDeviceNotConfigured:
|
|
305 |
case KErrUsbBadEndpoint:
|
|
306 |
case KErrUsbDeviceClosing:
|
|
307 |
case KErrUsbInterfaceChange:
|
|
308 |
case KErrUsbEpNotReady:
|
|
309 |
{
|
|
310 |
OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_RUNERROR, "CUsbPnUsbSender::RunError - Cable detached!" );
|
|
311 |
C_TRACE( ( _T( "CUsbPnUsbSender::RunError - Cable detached!" )));
|
|
312 |
aError = KErrNone;
|
|
313 |
break;
|
|
314 |
}
|
|
315 |
default:
|
|
316 |
{
|
|
317 |
TRACE_ASSERT_ALWAYS;
|
|
318 |
}
|
|
319 |
}
|
|
320 |
|
|
321 |
OstTrace0( TRACE_NORMAL, CUSBPNUSBSENDER_RUNERROR_EXIT, "CUsbPnUsbSender::RunError - return void" );
|
|
322 |
C_TRACE( ( _T( "CUsbPnUsbSender::RunL() - return void" ) ) );
|
|
323 |
return KErrNone;
|
|
324 |
}
|
|
325 |
|
|
326 |
// ========================== OTHER EXPORTED FUNCTIONS =========================
|
|
327 |
|
|
328 |
// End of File
|