|
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 "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 #ifndef CREQUESTPROCESSOR_H |
|
20 #define CREQUESTPROCESSOR_H |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <mtp/mtpdataproviderapitypes.h> |
|
24 #include <mtp/mtpprotocolconstants.h> |
|
25 #include <mtp/tmtptyperesponse.h> |
|
26 #include <mtp/tmtptypenull.h> |
|
27 |
|
28 #include "crequestchecker.h" |
|
29 |
|
30 class MMTPConnection; |
|
31 class TMTPTypeRequest; |
|
32 class CMTPDataProviderPlugin; |
|
33 class MMTPDataProviderFramework; |
|
34 class TMTPTypeEvent; |
|
35 class CMTPObjectInfo; |
|
36 |
|
37 static const TInt KMmMtpRArrayGranularity = 2; |
|
38 |
|
39 /** |
|
40 * Defines a request processor interface |
|
41 */ |
|
42 class MMmRequestProcessor |
|
43 { |
|
44 public: |
|
45 /** |
|
46 * Process a request from the initiator |
|
47 * @param aRequest The request to be processed |
|
48 * @param aPhase The transaction phase of the request |
|
49 * @return ETrue to signal that the processor object can be deleted, EFalse to keep the processor object |
|
50 */ |
|
51 virtual TBool HandleRequestL( const TMTPTypeRequest& aRequest, |
|
52 TMTPTransactionPhase aPhase ) = 0; |
|
53 |
|
54 /** |
|
55 * Process an event from the initiator |
|
56 * @param aEvent The event to be processed |
|
57 */ |
|
58 virtual void HandleEventL( const TMTPTypeEvent& aEvent ) = 0; |
|
59 |
|
60 /** |
|
61 * delete the request processor object |
|
62 */ |
|
63 virtual void Release() = 0; |
|
64 |
|
65 /** |
|
66 * Check if the processor matches the request on the connection |
|
67 * @param aRequest The request to be checked |
|
68 * @param aConnection The connection from which the request comes |
|
69 * @return ETrue to indicate the processor can handle the request, otherwise, EFalse |
|
70 */ |
|
71 virtual TBool Match( const TMTPTypeRequest& aRequest, |
|
72 MMTPConnection& aConnection ) const = 0; |
|
73 |
|
74 /** |
|
75 * Check if the processor matches the event on the connection |
|
76 * @param aEvent The event to be checked |
|
77 * @param aConnection The connection from which the event comes |
|
78 * @return ETrue to indicate the processor can handle the event, otherwise, EFalse |
|
79 */ |
|
80 virtual TBool Match( const TMTPTypeEvent& aEvent, |
|
81 MMTPConnection& aConnection ) const = 0; |
|
82 |
|
83 /** |
|
84 * Get the request object which the processor is currently handling |
|
85 * @return the request object which the processor is currently handling |
|
86 */ |
|
87 virtual const TMTPTypeRequest& Request() const = 0; |
|
88 |
|
89 /** |
|
90 * Get the connection object associated with the current request object |
|
91 * @return the connection object associated with the current request object |
|
92 */ |
|
93 virtual MMTPConnection& Connection() const = 0; |
|
94 |
|
95 /* |
|
96 * Rollback when WMP closed and disconnect the USB cable, |
|
97 * during the transferring file |
|
98 */ |
|
99 virtual void UsbDisconnect() = 0; |
|
100 |
|
101 /* |
|
102 * Get the session id associated with current request object |
|
103 * This interface was added to avoid the case that the data member iRequest |
|
104 * was sometimes invalid in session close phase, and getting session id from |
|
105 * request would cause panic |
|
106 * @return session id |
|
107 */ |
|
108 virtual TUint32 SessionId() = 0; |
|
109 }; |
|
110 |
|
111 /** |
|
112 * Defines a processor factory function pointer |
|
113 */ |
|
114 typedef MMmRequestProcessor |
|
115 * (*TMTPRequestProcessorCreateFunc)( MMTPDataProviderFramework& aFramework, |
|
116 MMTPConnection& aConnection ); |
|
117 |
|
118 /** |
|
119 * Defines an entry which maps from operation code to the request processor |
|
120 */ |
|
121 typedef struct |
|
122 { |
|
123 TUint16 iOperationCode; |
|
124 TMTPRequestProcessorCreateFunc iCreateFunc; |
|
125 } TMTPRequestProcessorEntry; |
|
126 |
|
127 /** |
|
128 * Defines a generic request processor interface from which all processors derive |
|
129 */ |
|
130 class CRequestProcessor : public CActive, public MMmRequestProcessor |
|
131 { |
|
132 protected: |
|
133 /** |
|
134 * Standard c++ constructor |
|
135 * @param aFramework The data provider framework |
|
136 * @param aConnection The connection from which the request comes |
|
137 * @param aElementCount Number of element in the request. |
|
138 * @param aElements The element info data. |
|
139 * @return a pointer to the created request processor object |
|
140 */ |
|
141 IMPORT_C CRequestProcessor( MMTPDataProviderFramework& aFramework, |
|
142 MMTPConnection& aConnection, |
|
143 TInt aElementCount, |
|
144 const TMTPRequestElementInfo* aElements ); |
|
145 |
|
146 /** |
|
147 * Destructor |
|
148 */ |
|
149 IMPORT_C virtual ~CRequestProcessor(); |
|
150 |
|
151 protected: |
|
152 // utility methods |
|
153 /** |
|
154 * Send a response to the initiator |
|
155 * @param aResponseCode The response code to send |
|
156 * @param aParamCount The number of parameters |
|
157 * @param aParmas The pointer to array of parameters |
|
158 */ |
|
159 IMPORT_C void SendResponseL( TMTPResponseCode aResponseCode, |
|
160 TInt aParameterCount = 0, |
|
161 TUint32* aParams = NULL ); |
|
162 |
|
163 /** |
|
164 * Signal to the framework that the current request transaction has completed |
|
165 */ |
|
166 void CompleteRequestL(); |
|
167 |
|
168 /** |
|
169 * Send data to the initiator |
|
170 * @param aData The data to send |
|
171 */ |
|
172 IMPORT_C void SendDataL( const MMTPType& aData ); |
|
173 |
|
174 /** |
|
175 * Receive data from the initiator |
|
176 * @param aData The data to receive |
|
177 */ |
|
178 IMPORT_C void ReceiveDataL( MMTPType& aData ); |
|
179 |
|
180 protected: |
|
181 // from MMTPRequestProcessor |
|
182 /** |
|
183 * Handle the request |
|
184 * @param aRequest The request to be processed |
|
185 * @param aPhase The current transaction phase of the request |
|
186 * @return ETrue if the transaction has completed, otherwise, EFalse |
|
187 */ |
|
188 IMPORT_C TBool HandleRequestL( const TMTPTypeRequest& aRequest, |
|
189 TMTPTransactionPhase aPhase ); |
|
190 |
|
191 /** |
|
192 * Handle the event |
|
193 * @param aEvent The event to be processed |
|
194 */ |
|
195 IMPORT_C void HandleEventL( const TMTPTypeEvent& aEvent ); |
|
196 |
|
197 /** |
|
198 * Relese (delete) this request processor |
|
199 */ |
|
200 IMPORT_C void Release(); |
|
201 |
|
202 /** |
|
203 * Check whether the processor can process the request |
|
204 * @param aRequest The request to be processed |
|
205 * @param aConnection The connection from which the request comes |
|
206 * @return ETrue if the processor can process the request, otherwise EFalse |
|
207 */ |
|
208 IMPORT_C TBool Match( const TMTPTypeRequest& aRequest, |
|
209 MMTPConnection& aConnection ) const; |
|
210 |
|
211 /** |
|
212 * Check whether the processor can process the event |
|
213 * @param aEvent The event to be processed |
|
214 * @param aConnection The connection from which the request comes |
|
215 * @return ETrue if the processor can process the request, otherwise EFalse |
|
216 */ |
|
217 IMPORT_C TBool Match( const TMTPTypeEvent& aEvent, |
|
218 MMTPConnection& aConnection ) const; |
|
219 |
|
220 /** |
|
221 * The current active request |
|
222 * @return A reference to the current request |
|
223 */ |
|
224 IMPORT_C const TMTPTypeRequest& Request() const; |
|
225 |
|
226 /** |
|
227 * The connection from which the current request comes |
|
228 * @return A reference to the current connection |
|
229 */ |
|
230 IMPORT_C MMTPConnection& Connection() const; |
|
231 |
|
232 /* |
|
233 * Rollback when WMP closed and disconnect the USB cable, |
|
234 * during the transferring file |
|
235 */ |
|
236 IMPORT_C void UsbDisconnect(); |
|
237 |
|
238 /* |
|
239 * Get the session id associated with current request object |
|
240 * This interface was added to avoid the case that the data member iRequest |
|
241 * was sometimes invalid in session close phase, and getting session id from |
|
242 * request would cause panic |
|
243 * @return session id |
|
244 */ |
|
245 IMPORT_C TUint32 SessionId(); |
|
246 protected: |
|
247 // from CActive |
|
248 /** |
|
249 * part of active object framework, provide default implementation |
|
250 */ |
|
251 IMPORT_C void RunL(); |
|
252 |
|
253 /** |
|
254 * part of active object framework, provide default implementation |
|
255 */ |
|
256 IMPORT_C void DoCancel(); |
|
257 |
|
258 /** |
|
259 * part of active object framework, provide default implementation |
|
260 */ |
|
261 IMPORT_C TInt RunError( TInt aError ); |
|
262 |
|
263 protected: |
|
264 //new virtuals |
|
265 /** |
|
266 * Handle the request phase of the current request |
|
267 * @return EFalse |
|
268 */ |
|
269 IMPORT_C virtual TBool DoHandleRequestPhaseL(); |
|
270 |
|
271 /** |
|
272 * Handle the receiving data phase of the current request |
|
273 * @return EFalse |
|
274 */ |
|
275 IMPORT_C virtual TBool DoHandleDataIToRPhaseL(); |
|
276 |
|
277 /** |
|
278 * Handle the sending data phase of the current request |
|
279 * @return EFalse |
|
280 */ |
|
281 IMPORT_C virtual TBool DoHandleRToIPhaseL(); |
|
282 |
|
283 /** |
|
284 * Handle the response phase of the current request |
|
285 * @return EFalse |
|
286 */ |
|
287 IMPORT_C virtual TBool DoHandleResponsePhaseL(); |
|
288 |
|
289 /** |
|
290 * Handle the completing phase of the current request |
|
291 * @return ETrue |
|
292 */ |
|
293 IMPORT_C virtual TBool DoHandleCompletingPhaseL(); |
|
294 |
|
295 /** |
|
296 * Check the current request |
|
297 * @return EMTPRespCodeOK if the reqeust is good, otherwise, one of the error response codes |
|
298 */ |
|
299 IMPORT_C virtual TMTPResponseCode CheckRequestL(); |
|
300 |
|
301 IMPORT_C virtual TBool HasDataphase() const; |
|
302 |
|
303 /** |
|
304 * service a request at request phase |
|
305 */ |
|
306 virtual void ServiceL() = 0; |
|
307 |
|
308 protected: |
|
309 /** |
|
310 * Set P&S Status to avoid MPX access conflict |
|
311 */ |
|
312 void SetPSStatus(); |
|
313 |
|
314 private: |
|
315 /** |
|
316 * retrieve the session id and transaction code from the current request |
|
317 */ |
|
318 void ExtractSessionTransactionId(); |
|
319 |
|
320 protected: |
|
321 MMTPDataProviderFramework& iFramework; |
|
322 const TMTPTypeRequest* iRequest; //the pending requst object |
|
323 MMTPConnection& iConnection; //the connection from which the request comes |
|
324 TMTPTypeResponse iResponse; //the response object to send to the initiator |
|
325 TBool iCancelled; //indicates whether the data phase (send/receive) has been cancelled |
|
326 CRequestChecker* iRequestChecker; //a utility class providing generic request verification service |
|
327 TInt iElementCount; //number of verification elements used for request checker |
|
328 const TMTPRequestElementInfo* iElements; //pointer to an array of verification elements |
|
329 TUint32 iSessionId; //session id for the pending request |
|
330 TUint32 iTransactionCode; //transaction code for the pending request |
|
331 |
|
332 private: |
|
333 TMTPResponseCode iResponseCode; // contains response from CheckRequestL call |
|
334 RBuf8 iNullBuffer; // buffer to receive data from discarded data phase |
|
335 TMTPTypeNull iNull; |
|
336 |
|
337 }; |
|
338 |
|
339 #endif // CREQUESTPROCESSOR_H |