|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "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 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #ifndef CMTPUSBEPBASE_H |
|
22 #define CMTPUSBEPBASE_H |
|
23 |
|
24 #include <e32std.h> |
|
25 #include <e32base.h> |
|
26 #include <d32usbc.h> |
|
27 |
|
28 #include "mtpdebug.h" |
|
29 |
|
30 class CMTPUsbConnection; |
|
31 |
|
32 /** |
|
33 Defines the USB MTP device class endpoint data transfer controller base class. |
|
34 @internalComponent |
|
35 |
|
36 */ |
|
37 class CMTPUsbEpBase : public CActive |
|
38 { |
|
39 public: |
|
40 |
|
41 virtual ~CMTPUsbEpBase(); |
|
42 |
|
43 TEndpointNumber EndpointNumber() const; |
|
44 TUint Id() const; |
|
45 void SetMaxPacketSizeL(TUint aSize); |
|
46 void Stall(); |
|
47 void StallClear(); |
|
48 TBool Stalled() const; |
|
49 |
|
50 static TInt LinearOrder(const CMTPUsbEpBase& aL, const CMTPUsbEpBase& aR); |
|
51 |
|
52 void ResumeReceiveDataL(MMTPType& aSink); |
|
53 void CancelReceiveL(TInt aReason); |
|
54 void CancelSendL(TInt aReason); |
|
55 |
|
56 protected: |
|
57 |
|
58 CMTPUsbEpBase(TUint aId, TPriority aPriority, CMTPUsbConnection& aConnection); |
|
59 |
|
60 #ifdef __FLOG_ACTIVE |
|
61 virtual void ConstructL(const TDesC8& aComponentName); |
|
62 #else |
|
63 virtual void ConstructL(); |
|
64 #endif |
|
65 |
|
66 CMTPUsbConnection& Connection() const; |
|
67 |
|
68 void ReceiveDataL(MMTPType& aSink); |
|
69 virtual void ReceiveDataCompleteL(TInt aError, MMTPType& aSink); |
|
70 |
|
71 void SendDataL(const MMTPType& aSource); |
|
72 virtual void SendDataCompleteL(TInt aError, const MMTPType& aSource); |
|
73 |
|
74 protected: // From CActive |
|
75 |
|
76 void DoCancel(); |
|
77 |
|
78 private: // From CActive |
|
79 |
|
80 TInt RunError(TInt aError); |
|
81 void RunL(); |
|
82 |
|
83 private: |
|
84 |
|
85 TInt32 DataStreamDirection() const; |
|
86 void ResetReceiveDataStream(); |
|
87 void ResetSendDataStream(); |
|
88 void ResumeReceiveDataStreamL(); |
|
89 void ProcessSendDataStreamL(); |
|
90 |
|
91 void SetStreamState(TInt aState); |
|
92 TBool ValidateUSBHeaderL(); |
|
93 void InitiateFirstChunkReceiveL(); |
|
94 void ProcessFirstReceivedChunkL(); |
|
95 void FlushRxDataL(); |
|
96 |
|
97 protected: // Owned |
|
98 |
|
99 /** |
|
100 FLOGGER debug trace member variable. |
|
101 */ |
|
102 __FLOG_DECLARATION_MEMBER_MUTABLE; |
|
103 |
|
104 private: // Owned |
|
105 |
|
106 /** |
|
107 The data stream states. |
|
108 */ |
|
109 enum TState |
|
110 { |
|
111 /** |
|
112 Both send and receive data streams are inactive. |
|
113 */ |
|
114 EIdle = 0x00000000, |
|
115 |
|
116 /** |
|
117 Both send and receive data streams are stalled. |
|
118 */ |
|
119 EStalled = 0x0F000000, |
|
120 |
|
121 /** |
|
122 The receive data stream is active. |
|
123 */ |
|
124 EReceivingState = 0x40000000, |
|
125 EReceiveInitialising = 0x40000001, |
|
126 EReceiveInProgress = 0x40000002, |
|
127 EReceiveCompleting = 0x40000003, |
|
128 EReceiveComplete = 0x40000004, |
|
129 |
|
130 /** |
|
131 The send data stream is active. |
|
132 */ |
|
133 ESendingState = 0x80000000, |
|
134 ESendInitialising = 0x80000001, |
|
135 ESendInProgress = 0x80000002, |
|
136 ESendCompleting = 0x80000003, |
|
137 ESendComplete = 0x80000004, |
|
138 |
|
139 EStateDirection = 0xF0000000 |
|
140 }; |
|
141 |
|
142 /** |
|
143 The active data stream chunk status. |
|
144 */ |
|
145 TInt iChunkStatus; |
|
146 |
|
147 /** |
|
148 The internal endpoint identifier. |
|
149 */ |
|
150 TUint iId; |
|
151 |
|
152 /** |
|
153 The residual packet data buffer. |
|
154 */ |
|
155 RBuf8 iPacketBuffer; |
|
156 |
|
157 /** |
|
158 The maximum bulk-in endpoint size. |
|
159 */ |
|
160 TUint iPacketSizeMax; |
|
161 |
|
162 /** |
|
163 The receive data stream commit flag. |
|
164 */ |
|
165 TBool iReceiveDataCommit; |
|
166 |
|
167 /** |
|
168 The receive data stream chunk data buffer. |
|
169 */ |
|
170 TPtr8 iReceiveChunkData; |
|
171 |
|
172 /** |
|
173 The receive data stream data pointer. |
|
174 */ |
|
175 TPtr8 iReceiveData; |
|
176 |
|
177 /** |
|
178 The send data stream chunk data. |
|
179 */ |
|
180 TPtrC8 iSendChunkData; |
|
181 |
|
182 /** |
|
183 The send data stream data pointer. |
|
184 */ |
|
185 TPtrC8 iSendData; |
|
186 |
|
187 /** |
|
188 The data stream state variable. |
|
189 */ |
|
190 TInt32 iState; |
|
191 |
|
192 /** |
|
193 A flag to tell if the receive stream is the first chunk. |
|
194 */ |
|
195 TBool iIsFirstChunk; |
|
196 |
|
197 /** |
|
198 The amount of data received. |
|
199 */ |
|
200 TUint64 iDataCounter; |
|
201 |
|
202 /** |
|
203 The amount of data expected. |
|
204 */ |
|
205 TUint64 iDataLength; |
|
206 |
|
207 |
|
208 private: // Not owned |
|
209 |
|
210 /** |
|
211 The MTP USB device class transport connection which controls the endpoint. |
|
212 */ |
|
213 CMTPUsbConnection& iConnection; |
|
214 |
|
215 /** |
|
216 The receive data stream sink buffer |
|
217 */ |
|
218 MMTPType* iReceiveDataSink; |
|
219 |
|
220 /** |
|
221 The send data stream source buffer |
|
222 */ |
|
223 const MMTPType* iSendDataSource; |
|
224 }; |
|
225 |
|
226 #endif // CMTPUSBEPBASE_H |