1 /* |
|
2 * Copyright (c) 2010 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 "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 |
|
19 |
|
20 #ifndef __OVER_DUMMYUSBSCLDD__ |
|
21 #include <e32base.h> |
|
22 #include <d32usbc.h>//EEndPoint2 |
|
23 #else |
|
24 #include <dummyusbsclddapi.h> |
|
25 #endif |
|
26 |
|
27 #include "ncmdatareceiver.h" |
|
28 #include "ncmdatainterface.h" |
|
29 |
|
30 #include "OstTraceDefinitions.h" |
|
31 #ifdef OST_TRACE_COMPILER_IN_USE |
|
32 #include "ncmdatareceiverTraces.h" |
|
33 #endif |
|
34 |
|
35 |
|
36 |
|
37 #ifdef _DEBUG |
|
38 _LIT(KDataReceiverPanic, "DataRcvrPanic"); |
|
39 #endif |
|
40 |
|
41 /** |
|
42 @file |
|
43 @internalComponent |
|
44 */ |
|
45 |
|
46 /** |
|
47 * Constructor |
|
48 */ |
|
49 CNcmDataReceiver::CNcmDataReceiver(RDevUsbcScClient& aPort, CNcmDataInterface& aParent) : |
|
50 CActive(CActive::EPriorityStandard), |
|
51 iPort(aPort), |
|
52 iParent(aParent) |
|
53 { |
|
54 CActiveScheduler::Add(this); |
|
55 } |
|
56 |
|
57 /** |
|
58 * NewL to create object. |
|
59 */ |
|
60 CNcmDataReceiver* CNcmDataReceiver::NewL(RDevUsbcScClient& aPort, CNcmDataInterface& aParent) |
|
61 { |
|
62 OstTraceFunctionEntry0(CNCMDATARECEIVER_NEWL); |
|
63 |
|
64 CNcmDataReceiver* self = new(ELeave) CNcmDataReceiver(aPort, aParent); |
|
65 CleanupStack::PushL(self); |
|
66 self->ConstructL(); |
|
67 CleanupStack::Pop(self); |
|
68 |
|
69 OstTraceFunctionExit1(CNCMDATARECEIVER_NEWL_DUP01, self); |
|
70 return self; |
|
71 } |
|
72 |
|
73 void CNcmDataReceiver::ConstructL() |
|
74 { |
|
75 iNtbParser = CNcmNtb16Parser::NewL(*this); |
|
76 } |
|
77 |
|
78 /** |
|
79 * Destructor |
|
80 */ |
|
81 CNcmDataReceiver::~CNcmDataReceiver() |
|
82 { |
|
83 OstTraceFunctionEntry0(CNCMDATARECEIVER_CNCMDATARECEIVER_DUP01); |
|
84 |
|
85 Cancel(); |
|
86 delete iNtbParser; |
|
87 } |
|
88 |
|
89 /** |
|
90 * Start to receive and parse the USB data. |
|
91 */ |
|
92 void CNcmDataReceiver::Start() |
|
93 { |
|
94 OstTraceFunctionEntry0(CNCMDATARECEIVER_START); |
|
95 |
|
96 TInt ret = iPort.OpenEndpoint(iEpIn, EEndpoint2); |
|
97 if (KErrNone != ret) |
|
98 { |
|
99 OstTrace1(TRACE_ERROR, CNCMDATARECEIVER_START_DUP01, "OpenEndpoint error=%d", ret); |
|
100 iParent.DataError(ret); |
|
101 OstTraceFunctionExit0(CNCMDATARECEIVER_START_DUP02); |
|
102 return; |
|
103 } |
|
104 ReadData(); |
|
105 OstTraceFunctionExit0(CNCMDATARECEIVER_START_DUP03); |
|
106 } |
|
107 |
|
108 /** |
|
109 * Read the data packet from NCM host |
|
110 */ |
|
111 void CNcmDataReceiver::ReadData() |
|
112 { |
|
113 OstTraceFunctionEntry0(CNCMDATARECEIVER_READDATA); |
|
114 |
|
115 const TInt KRetryCount = 3; |
|
116 TInt ret = KErrNone; |
|
117 TInt errCnt = KRetryCount; |
|
118 |
|
119 while(errCnt) |
|
120 { |
|
121 ret = iEpIn.TakeBuffer(reinterpret_cast<TAny*&>(iBuf), iBufLen, iZlp, iStatus); |
|
122 if (KErrCompletion == ret) |
|
123 { |
|
124 errCnt = KRetryCount; |
|
125 if (iBufLen > 0) |
|
126 { |
|
127 OstTraceExt3(TRACE_NORMAL, CNCMDATARECEIVER_READDATA_DUP02, "iBuf=%x, iBufLen=%d, iZlp=%d", (TInt)iBuf, iBufLen, iZlp); |
|
128 ret = iNtbParser->Parse(iBuf, iBufLen, iZlp); |
|
129 } |
|
130 } |
|
131 else if (KErrNone == ret || KErrEof == ret) |
|
132 { |
|
133 break; |
|
134 } |
|
135 else |
|
136 { |
|
137 OstTrace1(TRACE_ERROR, CNCMDATARECEIVER_READDATA_DUP03, "TakeBuffer error=%d", ret); |
|
138 errCnt --; |
|
139 } |
|
140 } |
|
141 |
|
142 if (KErrNone == ret) |
|
143 { |
|
144 SetActive(); |
|
145 } |
|
146 else if (KErrEof != ret) |
|
147 { |
|
148 iParent.DataError(ret); |
|
149 } |
|
150 |
|
151 OstTraceFunctionExit0(CNCMDATARECEIVER_READDATA_DUP01); |
|
152 } |
|
153 |
|
154 /** |
|
155 * Expire the Share Chunk LDD's buffer (see above TakeBuffer) |
|
156 */ |
|
157 void CNcmDataReceiver::ExpireBuffer(TAny* aBuf) |
|
158 { |
|
159 TInt ret = iEpIn.Expire(aBuf); |
|
160 __ASSERT_DEBUG(KErrNone==ret, User::Panic(KDataReceiverPanic, __LINE__)); |
|
161 } |
|
162 |
|
163 /** |
|
164 * Deliver the received packet data to upper link |
|
165 */ |
|
166 void CNcmDataReceiver::ProcessEtherFrame(RMBufPacket& aPacket) |
|
167 { |
|
168 iParent.ProcessDatagram(aPacket); |
|
169 } |
|
170 |
|
171 /** |
|
172 * RunL, a state machine to read the NCM packet data from NCM host |
|
173 */ |
|
174 void CNcmDataReceiver::RunL() |
|
175 { |
|
176 if(KErrNone == iStatus.Int()) |
|
177 { |
|
178 ReadData(); |
|
179 } |
|
180 else |
|
181 { |
|
182 OstTrace1(TRACE_ERROR, CNCMDATARECEIVER_RUNL, "iStatus.Int()=%d", iStatus.Int()); |
|
183 iParent.DataError(iStatus.Int()); |
|
184 } |
|
185 } |
|
186 |
|
187 /** |
|
188 * Cancel the outgoing read request |
|
189 */ |
|
190 void CNcmDataReceiver::DoCancel() |
|
191 { |
|
192 OstTraceFunctionEntry0(CNCMDATARECEIVER_DOCANCEL); |
|
193 iPort.ReadCancel(iEpIn.BufferNumber()); |
|
194 } |
|
195 |
|
196 void CNcmDataReceiver::Stop() |
|
197 { |
|
198 OstTraceFunctionEntry0(CNCMDATARECEIVER_STOP); |
|
199 Cancel(); |
|
200 iNtbParser->Reset(); |
|
201 TInt ret = iEpIn.Close(); |
|
202 |
|
203 OstTraceFunctionExit0(CNCMDATARECEIVER_STOP_DUP01); |
|
204 } |
|