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 "cusbpnisasender.h"
|
|
20 |
#include "cusbpnpacket.h"
|
|
21 |
#include "musbpnbufferlistener.h"
|
|
22 |
#include "usbpndefinitions.h"
|
|
23 |
#include "usbpntrace.h"
|
|
24 |
|
|
25 |
#include "osttracedefinitions.h"
|
|
26 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
27 |
#include "cusbpnisasenderTraces.h"
|
|
28 |
#endif
|
|
29 |
|
|
30 |
#include <iscapi.h> // For RIscApi
|
|
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 |
// CUsbPnIsaSender::CUsbPnIsaSender
|
|
46 |
// C++ default constructor can NOT contain any code, that
|
|
47 |
// might leave.
|
|
48 |
// -----------------------------------------------------------------------------
|
|
49 |
//
|
|
50 |
CUsbPnIsaSender::CUsbPnIsaSender( MUsbPnBufferListener& aBufferListener, RIscApi& aIscApi )
|
|
51 |
:CActive( CActive::EPriorityStandard )
|
|
52 |
,iBufferListener( aBufferListener )
|
|
53 |
,iIscApi( aIscApi )
|
|
54 |
,iPacketCount( 0 )
|
|
55 |
{
|
|
56 |
OstTraceExt2( TRACE_NORMAL, CUSBPNISASENDER_CUSBPNISASENDER_ENTRY, "CUsbPnIsaSender::CUsbPnIsaSender;aBufferListener=%x;aIscApi=%x", ( TUint )&( aBufferListener ), ( TUint )&( aIscApi ) );
|
|
57 |
C_TRACE( ( _T( "CUsbPnIsaSender::CUsbPnIsaSender( aBufferListener:0x%x, aIscApi:0x%x )" ), &aBufferListener, &aIscApi ) );
|
|
58 |
|
|
59 |
CActiveScheduler::Add(this);
|
|
60 |
|
|
61 |
OstTrace0( TRACE_NORMAL, CUSBPNISASENDER_CUSBPNISASENDER_EXIT, "CUsbPnIsaSender::CUsbPnIsaSender - return" );
|
|
62 |
C_TRACE( ( _T( "CUsbPnIsaSender::CUsbPnIsaSender() - return" ) ) );
|
|
63 |
}
|
|
64 |
|
|
65 |
// -----------------------------------------------------------------------------
|
|
66 |
// CUsbPnIsaSender::ConstructL
|
|
67 |
// Symbian 2nd phase constructor can leave.
|
|
68 |
// -----------------------------------------------------------------------------
|
|
69 |
//
|
|
70 |
void CUsbPnIsaSender::ConstructL()
|
|
71 |
{
|
|
72 |
OstTrace0( TRACE_NORMAL, CUSBPNISASENDER_CONSTRUCTL_ENTRY, "CUsbPnIsaSender::ConstructL" );
|
|
73 |
C_TRACE( ( _T( "CUsbPnIsaSender::ConstructL()" ) ) );
|
|
74 |
|
|
75 |
// Create circular buffer objects
|
|
76 |
for(TUint i = 1; i < (KPnIsaPacketCount + 1); i++)
|
|
77 |
{
|
|
78 |
AddPacketBufferL(i);
|
|
79 |
}
|
|
80 |
iCurrentPacket = iPacket;
|
|
81 |
|
|
82 |
OstTrace0( TRACE_NORMAL, CUSBPNISASENDER_CONSTRUCTL_EXIT, "CUsbPnIsaSender::ConstructL - return void" );
|
|
83 |
C_TRACE( ( _T( "CUsbPnIsaSender::ConstructL() - return void" ) ) );
|
|
84 |
}
|
|
85 |
|
|
86 |
// -----------------------------------------------------------------------------
|
|
87 |
// CUsbPnIsaSender::NewL
|
|
88 |
// Two-phased constructor.
|
|
89 |
// -----------------------------------------------------------------------------
|
|
90 |
//
|
|
91 |
CUsbPnIsaSender* CUsbPnIsaSender::NewL( MUsbPnBufferListener& aBufferListener, RIscApi& aIscApi )
|
|
92 |
{
|
|
93 |
OstTraceExt2( TRACE_NORMAL, CUSBPNISASENDER_NEWL_ENTRY, "CUsbPnIsaSender::NewL;aBufferListener=%x;aIscApi=%x", ( TUint )&( aBufferListener ), ( TUint )&( aIscApi ) );
|
|
94 |
C_TRACE( ( _T( "CUsbPnIsaSender::CUsbPnIsaSender( aBufferListener 0x%x, aIscApi:0x%x )" ), &aBufferListener, &aIscApi ) );
|
|
95 |
|
|
96 |
CUsbPnIsaSender* self = new( ELeave ) CUsbPnIsaSender( aBufferListener, aIscApi );
|
|
97 |
|
|
98 |
CleanupStack::PushL( self );
|
|
99 |
self->ConstructL();
|
|
100 |
CleanupStack::Pop( self );
|
|
101 |
|
|
102 |
OstTrace1( TRACE_NORMAL, CUSBPNISASENDER_NEWL_EXIT, "CUsbPnIsaSender::NewL - return;self=%x", self );
|
|
103 |
C_TRACE( ( _T( "CUsbPnIsaSender::CUsbPnIsaSender() - return 0x%x" ), self ) );
|
|
104 |
return self;
|
|
105 |
}
|
|
106 |
|
|
107 |
|
|
108 |
// Destructor
|
|
109 |
CUsbPnIsaSender::~CUsbPnIsaSender()
|
|
110 |
{
|
|
111 |
OstTrace0( TRACE_NORMAL, CUSBPNISASENDER_CUSBPNISASENDER_DESTRUCTOR_ENTRY, "CUsbPnIsaSender::~CUsbPnIsaSender" );
|
|
112 |
C_TRACE( ( _T( "CUsbPnIsaSender::~CUsbPnIsaSender()" ) ) );
|
|
113 |
|
|
114 |
Cancel();
|
|
115 |
|
|
116 |
// Delete circular buffer objects
|
|
117 |
CUsbPnPacket* packet;
|
|
118 |
while(iPacketCount > 0)
|
|
119 |
{
|
|
120 |
iPacketCount--;
|
|
121 |
packet = &iPacket->NextPacket();
|
|
122 |
delete iPacket;
|
|
123 |
iPacket = packet;
|
|
124 |
}
|
|
125 |
iCurrentPacket = NULL;
|
|
126 |
iPacket = NULL;
|
|
127 |
|
|
128 |
OstTrace0( TRACE_NORMAL, CUSBPNISASENDER_CUSBPNISASENDER_DESTRUCTOR_EXIT, "CUsbPnIsaSender::~CUsbPnIsaSender - return" );
|
|
129 |
C_TRACE( ( _T( "CUsbPnIsaSender::~CUsbPnIsaSender() - return" ) ) );
|
|
130 |
}
|
|
131 |
|
|
132 |
// -----------------------------------------------------------------------------
|
|
133 |
// CUsbPnIsaSender::AddPacketBuffer
|
|
134 |
// -----------------------------------------------------------------------------
|
|
135 |
void CUsbPnIsaSender::AddPacketBufferL( TInt aIndex )
|
|
136 |
{
|
|
137 |
OstTrace0( TRACE_NORMAL, CUSBPNISASENDER_ADDPACKETBUFFERL_ENTRY, "CUsbPnIsaSender::AddPacketBufferL" );
|
|
138 |
C_TRACE((_T("CUsbPnIsaSender::AddPacketBuffer()")));
|
|
139 |
|
|
140 |
iPacketCount++;
|
|
141 |
iPacket = CUsbPnPacket::NewL( iPacket, aIndex );
|
|
142 |
|
|
143 |
OstTrace0( TRACE_NORMAL, CUSBPNISASENDER_ADDPACKETBUFFERL_EXIT, "CUsbPnIsaSender::AddPacketBufferL - return void" );
|
|
144 |
C_TRACE((_T("CUsbPnIsaSender::AddPacketBuffer - return void")));
|
|
145 |
}
|
|
146 |
|
|
147 |
// -----------------------------------------------------------------------------
|
|
148 |
// CUsbPnIsaSender::DoCancel
|
|
149 |
// ?implementation_description
|
|
150 |
// (other items were commented in a header).
|
|
151 |
// -----------------------------------------------------------------------------
|
|
152 |
//
|
|
153 |
void CUsbPnIsaSender::DoCancel( )
|
|
154 |
{
|
|
155 |
OstTrace0( TRACE_NORMAL, CUSBPNISASENDER_DOCANCEL_ENTRY, "CUsbPnIsaSender::DoCancel" );
|
|
156 |
C_TRACE( ( _T( "CUsbPnIsaSender::DoCancel()" ) ) );
|
|
157 |
|
|
158 |
iIscApi.SendCancel();
|
|
159 |
|
|
160 |
OstTrace0( TRACE_NORMAL, CUSBPNISASENDER_DOCANCEL_EXIT, "CUsbPnIsaSender::DoCancel - return void" );
|
|
161 |
C_TRACE( ( _T( "CUsbPnIsaSender::DoCancel() - return void" ) ) );
|
|
162 |
}
|
|
163 |
|
|
164 |
// -----------------------------------------------------------------------------
|
|
165 |
// CUsbPnIsaSender::RunL
|
|
166 |
// ?implementation_description
|
|
167 |
// (other items were commented in a header).
|
|
168 |
// -----------------------------------------------------------------------------
|
|
169 |
//
|
|
170 |
void CUsbPnIsaSender::RunL( )
|
|
171 |
{
|
|
172 |
OstTrace1( TRACE_API, CUSBPNISASENDER_RUNL_ENTRY, "CUsbPnIsaSender::RunL;iStatus=%d", iStatus.Int() );
|
|
173 |
A_TRACE( ( _T( "CUsbPnIsaSender::RunL() iStatus:%d" ), iStatus.Int() ) );
|
|
174 |
|
|
175 |
User::LeaveIfError( iStatus.Int() );
|
|
176 |
|
|
177 |
iCurrentPacket->ReleaseL();
|
|
178 |
|
|
179 |
iBufferListener.Receive( ETrue/*dummy*/ );
|
|
180 |
|
|
181 |
iCurrentPacket = &iCurrentPacket->NextPacket();
|
|
182 |
OstTraceExt2( TRACE_DETAILED, CUSBPNISASENDER_RUNL, "CUsbPnIsaSender::RunL;tail:%d,head:%d", iCurrentPacket->PacketNumber(), iPacket->PacketNumber() );
|
|
183 |
E_TRACE( ( _T( "CUsbPnIsaSender::RunL() - tail:%d,head:%d " ), iCurrentPacket->PacketNumber(), iPacket->PacketNumber()));
|
|
184 |
|
|
185 |
if(iCurrentPacket != iPacket)
|
|
186 |
{
|
|
187 |
// Continue write
|
|
188 |
OstTrace0( TRACE_DETAILED, CUSBPNISASENDER_RUNL_DUP1, "CUsbPnIsaSender::RunL - Write next in queue." );
|
|
189 |
E_TRACE( ( _T( "CUsbPnIsaSender::RunL() - Write next in queue." )));
|
|
190 |
TryToSendPacket( iCurrentPacket->NextPacket() );
|
|
191 |
}
|
|
192 |
|
|
193 |
OstTrace0( TRACE_API, CUSBPNISASENDER_RUNL_EXIT, "CUsbPnIsaSender::RunL - return void" );
|
|
194 |
A_TRACE( ( _T( "CUsbPnIsaSender::RunL() - return void" ) ) );
|
|
195 |
}
|
|
196 |
|
|
197 |
// -----------------------------------------------------------------------------
|
|
198 |
// CUsbPnIsaSender::RunError
|
|
199 |
// ?implementation_description
|
|
200 |
// (other items were commented in a header).
|
|
201 |
// -----------------------------------------------------------------------------
|
|
202 |
//
|
|
203 |
TInt CUsbPnIsaSender::RunError( TInt aError )
|
|
204 |
{
|
|
205 |
OstTrace1( TRACE_API, CUSBPNISASENDER_RUNERROR_ENTRY, "CUsbPnIsaSender::RunError;aError=%d", aError );
|
|
206 |
A_TRACE( ( _T( "CUsbPnIsaSender::RunError( aError:%d )" ), aError ) );
|
|
207 |
|
|
208 |
switch( aError )
|
|
209 |
{
|
|
210 |
case KErrNotReady:
|
|
211 |
case KErrBadDescriptor:
|
|
212 |
case KErrUnderflow:
|
|
213 |
{
|
|
214 |
TRACE_ASSERT_ALWAYS;
|
|
215 |
CActiveScheduler::Stop();
|
|
216 |
aError = KErrNone;
|
|
217 |
break;
|
|
218 |
}
|
|
219 |
default:
|
|
220 |
{
|
|
221 |
TRACE_ASSERT_ALWAYS;
|
|
222 |
User::Panic( KUsbPnPanicCat, aError );
|
|
223 |
break;
|
|
224 |
}
|
|
225 |
}
|
|
226 |
|
|
227 |
OstTrace1( TRACE_NORMAL, CUSBPNISASENDER_RUNERROR_EXIT, "CUsbPnIsaSender::RunError - return;aError=%d", aError );
|
|
228 |
C_TRACE( ( _T( "CUsbPnIsaSender::RunError() return - aError:%d )" ), aError ) );
|
|
229 |
return aError;
|
|
230 |
}
|
|
231 |
// -----------------------------------------------------------------------------
|
|
232 |
// CUsbPnIsaSender::Packet
|
|
233 |
// ?implementation_description
|
|
234 |
// (other items were commented in a header).
|
|
235 |
// -----------------------------------------------------------------------------
|
|
236 |
//
|
|
237 |
CUsbPnPacket& CUsbPnIsaSender::PacketL()
|
|
238 |
{
|
|
239 |
OstTrace0( TRACE_NORMAL, CUSBPNISASENDER_PACKETL_ENTRY, "CUsbPnIsaSender::PacketL" );
|
|
240 |
C_TRACE( ( _T( "CUsbPnIsaSender::PacketL()" ) ) );
|
|
241 |
|
|
242 |
CUsbPnPacket& packet( iPacket->NextPacket() );
|
|
243 |
TBool err = packet.PacketInUse();
|
|
244 |
if (EFalse != err)
|
|
245 |
{
|
|
246 |
User::Leave( err );
|
|
247 |
}
|
|
248 |
|
|
249 |
OstTrace1( TRACE_NORMAL, CUSBPNISASENDER_PACKETL_EXIT, "CUsbPnIsaSender::PacketL - return;packet=%d", packet.PacketNumber() );
|
|
250 |
C_TRACE((_T("CUsbPnIsaSender::PacketL() - return packet:%d"), packet.PacketNumber()));
|
|
251 |
|
|
252 |
return packet;
|
|
253 |
}
|
|
254 |
|
|
255 |
// -----------------------------------------------------------------------------
|
|
256 |
// CUsbPnIsaSender::Send
|
|
257 |
// ?implementation_description
|
|
258 |
// (other items were commented in a header).
|
|
259 |
// -----------------------------------------------------------------------------
|
|
260 |
//
|
|
261 |
void CUsbPnIsaSender::Send( CUsbPnPacket& aPacket )
|
|
262 |
{
|
|
263 |
OstTrace1( TRACE_API, CUSBPNISASENDER_SEND_ENTRY, "CUsbPnIsaSender::Send;aPacket=%x", ( TUint )&( aPacket ) );
|
|
264 |
A_TRACE( ( _T( "CUsbPnIsaSender::Send( aPacket:0x%x)" ), &aPacket ) );
|
|
265 |
|
|
266 |
CUsbPnPacket& packet( iPacket->NextPacket() );
|
|
267 |
if( &packet == &aPacket )
|
|
268 |
{
|
|
269 |
iPacket = &packet;
|
|
270 |
OstTrace1( TRACE_DETAILED, CUSBPNISASENDER_SEND, "CUsbPnIsaSender::Send;packet number:%d", iPacket->PacketNumber() );
|
|
271 |
E_TRACE( ( _T( "CUsbPnIsaSender::Send() - packet number:%d" ), iPacket->PacketNumber() ) );
|
|
272 |
|
|
273 |
TryToSendPacket( *iPacket );
|
|
274 |
}
|
|
275 |
else
|
|
276 |
{
|
|
277 |
TRACE_ASSERT_ALWAYS;
|
|
278 |
User::Panic(_L("USBPNSERVER"), KErrTotalLossOfPrecision);
|
|
279 |
}
|
|
280 |
|
|
281 |
OstTrace0( TRACE_API, CUSBPNISASENDER_SEND_EXIT, "CUsbPnIsaSender::Send - return void" );
|
|
282 |
A_TRACE( ( _T( "CUsbPnIsaSender::Send() - return void" ) ) );
|
|
283 |
}
|
|
284 |
|
|
285 |
|
|
286 |
// -----------------------------------------------------------------------------
|
|
287 |
// CUsbPnIsaSender::TryToSendPacket
|
|
288 |
// ?implementation_description
|
|
289 |
// (other items were commented in a header).
|
|
290 |
// -----------------------------------------------------------------------------
|
|
291 |
//
|
|
292 |
void CUsbPnIsaSender::TryToSendPacket( CUsbPnPacket& aPacket )
|
|
293 |
{
|
|
294 |
OstTrace1( TRACE_API, CUSBPNISASENDER_TRYTOSENDPACKET_ENTRY, "CUsbPnIsaSender::TryToSendPacket;aPacket=%x", ( TUint )&( aPacket ) );
|
|
295 |
A_TRACE( ( _T( "CUsbPnIsaSender::TryToSendPacket( aPacket:0x%x )" ), &aPacket ) );
|
|
296 |
|
|
297 |
if(!IsActive())
|
|
298 |
{
|
|
299 |
if( &aPacket == &iCurrentPacket->NextPacket() || &aPacket == iCurrentPacket )
|
|
300 |
{
|
|
301 |
OstTrace0( TRACE_DETAILED, CUSBPNISASENDER_TRYTOSENDPACKET, "CUsbPnIsaSender::TryToSendPacket - Send to ISA" );
|
|
302 |
E_TRACE( ( _T( "CUsbPnIsaSender::TryToSendPacket() - Send to ISA")));
|
|
303 |
|
|
304 |
#ifdef EXTENDED_TRACE_FLAG
|
|
305 |
TInt i(0);
|
|
306 |
HBufC8& data(aPacket.Buffer());
|
|
307 |
while(i < data.Length() )
|
|
308 |
{
|
|
309 |
OstTraceExt2( TRACE_DETAILED, CUSBPNISASENDER_TRYTOSENDPACKET_DUP1, "CUsbPnIsaSender::Send([%d] = %x )", i, data[i] );
|
|
310 |
E_TRACE( ( _T( "CUsbPnIsaSender::Send([%d] = %x )" ), i, data[i] ) );
|
|
311 |
i++;
|
|
312 |
}
|
|
313 |
#endif
|
|
314 |
|
|
315 |
iIscApi.Send( iStatus, aPacket.Buffer() );
|
|
316 |
SetActive();
|
|
317 |
}
|
|
318 |
else
|
|
319 |
{
|
|
320 |
TRACE_ASSERT_ALWAYS;
|
|
321 |
User::Panic(_L("USBPNSERVER"), KErrTotalLossOfPrecision);
|
|
322 |
}
|
|
323 |
}
|
|
324 |
else
|
|
325 |
{
|
|
326 |
OstTrace0( TRACE_DETAILED, CUSBPNISASENDER_TRYTOSENDPACKET_DUP2, "CUsbPnIsaSender::TryToSendPacket - Already sending" );
|
|
327 |
E_TRACE( ( _T( "CUsbPnIsaSender::TryToSendPacket() - Already sending")));
|
|
328 |
}
|
|
329 |
|
|
330 |
OstTrace0( TRACE_API, CUSBPNISASENDER_TRYTOSENDPACKET_EXIT, "CUsbPnIsaSender::TryToSendPacket - return void" );
|
|
331 |
A_TRACE( ( _T( "CUsbPnIsaSender::TryToSendPacket() - return void" ) ) );
|
|
332 |
}
|
|
333 |
|
|
334 |
// ========================== OTHER EXPORTED FUNCTIONS =========================
|
|
335 |
|
|
336 |
// End of File
|