|
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 #include <mtp/tmtptyperequest.h> |
|
17 #include <mtp/mmtpdataproviderframework.h> |
|
18 #include <mtp/mtpprotocolconstants.h> |
|
19 #include <mtp/cmtptypeobjectinfo.h> |
|
20 #include <mtp/cmtptypeobjectproplist.h> |
|
21 #include <mtp/cmtpdataproviderplugin.h> |
|
22 #include <mtp/cmtptypearray.h> |
|
23 |
|
24 #include "rmtpframework.h" |
|
25 #include "cmtpdataprovidercontroller.h" |
|
26 #include "cmtpparserrouter.h" |
|
27 #include "cmtpdataprovider.h" |
|
28 #include "cmtpgetobjectproplist.h" |
|
29 #include "mtpproxydppanic.h" |
|
30 #include "cmtpobjectbrowser.h" |
|
31 #include "mtpdppanic.h" |
|
32 #include "cmtpobjectmgr.h" |
|
33 |
|
34 __FLOG_STMT( _LIT8( KComponent,"PrxyGetObjPrpLst" ); ) |
|
35 const TUint KInvalidDpId = 0xFF; |
|
36 /** |
|
37 Factory method. |
|
38 @param aFramework The data provider framework |
|
39 @param aConnection The connection from which the request comes |
|
40 @return a pointer to the created request processor object. |
|
41 */ |
|
42 MMTPRequestProcessor* CMTPGetObjectPropList::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) |
|
43 { |
|
44 CMTPGetObjectPropList* self = new (ELeave) CMTPGetObjectPropList(aFramework, aConnection); |
|
45 CleanupStack::PushL(self); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop(self); |
|
48 return self; |
|
49 } |
|
50 |
|
51 /** |
|
52 Destructor. |
|
53 */ |
|
54 CMTPGetObjectPropList::~CMTPGetObjectPropList() |
|
55 { |
|
56 delete iObjectPropList; |
|
57 iSingletons.Close(); |
|
58 iTargetDps.Close(); |
|
59 iHandles.Close(); |
|
60 delete iObjBrowser; |
|
61 __FLOG( _L8("+/-Dtor") ); |
|
62 __FLOG_CLOSE; |
|
63 } |
|
64 |
|
65 /** |
|
66 GetObjectPropList request handler. Builds a list of all the data providers |
|
67 that support the request, then starts an active object to send it to them all. |
|
68 */ |
|
69 void CMTPGetObjectPropList::ServiceL() |
|
70 { |
|
71 iTargetDps.Reset(); |
|
72 CMTPParserRouter& router(iSingletons.Router()); |
|
73 CMTPParserRouter::TRoutingParameters params(Request(), iConnection); |
|
74 router.ParseOperationRequestL(params); |
|
75 router.RouteOperationRequestL(params, iTargetDps); |
|
76 |
|
77 GetObjectHandlesL(); |
|
78 } |
|
79 |
|
80 void CMTPGetObjectPropList::ProxyReceiveDataL(MMTPType& /*aData*/, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& /*aStatus*/) |
|
81 { |
|
82 Panic(EMTPWrongRequestPhase); |
|
83 } |
|
84 |
|
85 #ifdef _DEBUG |
|
86 void CMTPGetObjectPropList::ProxySendDataL(const MMTPType& aData, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection, TRequestStatus& aStatus) |
|
87 #else |
|
88 void CMTPGetObjectPropList::ProxySendDataL(const MMTPType& aData, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& aStatus) |
|
89 #endif |
|
90 { |
|
91 __ASSERT_DEBUG((( (iRequest == &aRequest) || ( &iCurrentRequest == &aRequest ) ) && (&iConnection == &aConnection)), Panic(EMTPNotSameRequestProxy)); |
|
92 __ASSERT_DEBUG(aData.Type() == EMTPTypeObjectPropListDataset, Panic(EMTPInvalidDataType)); |
|
93 |
|
94 const CMTPTypeObjectPropList& sourceObjectPropList(static_cast<const CMTPTypeObjectPropList&>(aData)); |
|
95 |
|
96 iObjectPropList->AppendObjectPropListL(sourceObjectPropList); |
|
97 |
|
98 TRequestStatus* status(&aStatus); |
|
99 User::RequestComplete(status, KErrNone); |
|
100 } |
|
101 |
|
102 #ifdef _DEBUG |
|
103 void CMTPGetObjectPropList::ProxySendResponseL(const TMTPTypeResponse& aResponse, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection, TRequestStatus& aStatus) |
|
104 #else |
|
105 void CMTPGetObjectPropList::ProxySendResponseL(const TMTPTypeResponse& aResponse, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& aStatus) |
|
106 #endif |
|
107 { |
|
108 __FLOG( _L8("+ProxySendResponseL") ); |
|
109 |
|
110 __ASSERT_DEBUG((( (iRequest == &aRequest) || ( &iCurrentRequest == &aRequest ) ) && (&iConnection == &aConnection)), Panic(EMTPNotSameRequestProxy)); |
|
111 MMTPType::CopyL(aResponse, iResponse); |
|
112 TRequestStatus* status(&aStatus); |
|
113 User::RequestComplete(status, KErrNone); |
|
114 |
|
115 __FLOG( _L8("-ProxySendResponseL") ); |
|
116 } |
|
117 |
|
118 #ifdef _DEBUG |
|
119 void CMTPGetObjectPropList::ProxyTransactionCompleteL(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection) |
|
120 #else |
|
121 void CMTPGetObjectPropList::ProxyTransactionCompleteL(const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/) |
|
122 #endif |
|
123 { |
|
124 __FLOG( _L8("+ProxyTransactionCompleteL") ); |
|
125 __FLOG_1( _L8("Response code is 0x%08X,"), iResponse.Uint16(TMTPTypeResponse::EResponseCode) ); |
|
126 |
|
127 __ASSERT_DEBUG((( (iRequest == &aRequest) || ( &iCurrentRequest == &aRequest ) ) && (&iConnection == &aConnection)), Panic(EMTPNotSameRequestProxy)); |
|
128 TUint16 response = iResponse.Uint16(TMTPTypeResponse::EResponseCode); |
|
129 if(( EMTPRespCodeGroupNotSupported == response) || (EMTPRespCodeSpecificationByGroupUnsupported == response)) |
|
130 { |
|
131 response = EMTPRespCodeOK; |
|
132 iResponse.SetUint16(TMTPTypeResponse::EResponseCode, response); |
|
133 } |
|
134 |
|
135 TInt err((EMTPRespCodeOK == response) ? KErrNone : KErrGeneral); |
|
136 if (err == KErrNone) |
|
137 { |
|
138 ++iCurrentHandle; |
|
139 Schedule(err); |
|
140 } |
|
141 else |
|
142 { |
|
143 SendResponseL( response ); |
|
144 } |
|
145 |
|
146 |
|
147 __FLOG( _L8("-ProxyTransactionCompleteL") ); |
|
148 } |
|
149 |
|
150 /** |
|
151 Sends the request to all the data providers that expressed an interest, |
|
152 one each iteration of the active object. |
|
153 */ |
|
154 void CMTPGetObjectPropList::RunL() |
|
155 { |
|
156 __FLOG( _L8("+RunL") ); |
|
157 |
|
158 // We cannot use assertion here, because it might be completed with KErrGeneral. See ProxyTransactionCompleteL() |
|
159 |
|
160 if ( iStatus == KErrNone ) |
|
161 { |
|
162 GetNextObjectPropL(); |
|
163 if ( iOwnerDp != KInvalidDpId ) |
|
164 { |
|
165 CMTPDataProvider& dp = iSingletons.DpController().DataProviderL( iOwnerDp ); |
|
166 dp.ExecuteProxyRequestL( iCurrentRequest, Connection(), *this ); |
|
167 } |
|
168 } |
|
169 else |
|
170 { |
|
171 SendResponseL( iResponse.Uint16( TMTPTypeResponse::EResponseCode ) ); |
|
172 } |
|
173 |
|
174 __FLOG( _L8("-RunL") ); |
|
175 } |
|
176 |
|
177 /** |
|
178 Constructor. |
|
179 */ |
|
180 CMTPGetObjectPropList::CMTPGetObjectPropList(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) : |
|
181 CMTPRequestProcessor(aFramework, aConnection, 0, NULL) |
|
182 { |
|
183 __FLOG_OPEN( KMTPSubsystem, KComponent ); |
|
184 __FLOG( _L8("+/-Ctor") ); |
|
185 } |
|
186 |
|
187 /** |
|
188 Second phase constructor. |
|
189 */ |
|
190 void CMTPGetObjectPropList::ConstructL() |
|
191 { |
|
192 __FLOG( _L8("+ConstructL") ); |
|
193 iSingletons.OpenL(); |
|
194 iOwnerDp = KInvalidDpId; |
|
195 __FLOG( _L8("-ConstructL") ); |
|
196 } |
|
197 |
|
198 /** |
|
199 Completes the current asynchronous request with the specified |
|
200 completion code. |
|
201 @param aError The asynchronous request completion request. |
|
202 */ |
|
203 void CMTPGetObjectPropList::Schedule(TInt aError) |
|
204 { |
|
205 TRequestStatus* status(&iStatus); |
|
206 User::RequestComplete(status, aError); |
|
207 SetActive(); |
|
208 } |
|
209 |
|
210 /** |
|
211 Sends a response to the initiator. |
|
212 @param aCode MTP response code |
|
213 */ |
|
214 void CMTPGetObjectPropList::SendResponseL(TUint16 aCode) |
|
215 { |
|
216 const TMTPTypeRequest& req(Request()); |
|
217 iResponse.SetUint16(TMTPTypeResponse::EResponseCode, aCode); |
|
218 iResponse.SetUint32(TMTPTypeResponse::EResponseSessionID, req.Uint32(TMTPTypeRequest::ERequestSessionID)); |
|
219 iResponse.SetUint32(TMTPTypeResponse::EResponseTransactionID, req.Uint32(TMTPTypeRequest::ERequestTransactionID)); |
|
220 iFramework.SendResponseL(iResponse, req, Connection()); |
|
221 } |
|
222 |
|
223 void CMTPGetObjectPropList::GetObjectHandlesL() |
|
224 { |
|
225 __FLOG( _L8("+GetObjectHandlesL") ); |
|
226 |
|
227 delete iObjBrowser; |
|
228 iObjBrowser = NULL; |
|
229 iObjBrowser = CMTPObjectBrowser::NewL( iFramework ); |
|
230 |
|
231 iHandles.Reset(); |
|
232 |
|
233 delete iObjectPropList; |
|
234 iObjectPropList = NULL; |
|
235 iObjectPropList = CMTPTypeObjectPropList::NewL(); |
|
236 |
|
237 iCurrentHandle = 0; |
|
238 MMTPType::CopyL( Request(), iCurrentRequest ); |
|
239 // Set depth to be zero to avoid the other DPs enumerating objects repeatedly. |
|
240 iCurrentRequest.SetUint32( TMTPTypeRequest::ERequestParameter5, 0 ); |
|
241 |
|
242 CMTPObjectBrowser::TBrowseCallback callback = { CMTPGetObjectPropList::OnBrowseObjectL, this }; |
|
243 TUint32 handle = Request().Uint32( TMTPTypeRequest::ERequestParameter1 ); |
|
244 TUint32 fmtCode = Request().Uint32( TMTPTypeRequest::ERequestParameter2 ); |
|
245 TUint32 depth = Request().Uint32( TMTPTypeRequest::ERequestParameter5 ); |
|
246 iObjBrowser->GoL( fmtCode, handle, depth, callback ); |
|
247 __FLOG_1( _L8("The total of object handles is %d"), iHandles.Count() ); |
|
248 |
|
249 if ( 0 == iHandles.Count() ) |
|
250 { |
|
251 if ( handle==KMTPHandleNone && depth==0 ) |
|
252 { |
|
253 SendDataL( *iObjectPropList ); |
|
254 } |
|
255 else if ( fmtCode != KMTPFormatsAll ) |
|
256 { |
|
257 SendResponseL(EMTPRespCodeSpecificationByFormatUnsupported); |
|
258 } |
|
259 else if ( handle != KMTPHandleAll ) |
|
260 { |
|
261 SendResponseL(EMTPRespCodeInvalidObjectHandle); |
|
262 } |
|
263 } |
|
264 else |
|
265 { |
|
266 Schedule( KErrNone ); |
|
267 } |
|
268 |
|
269 __FLOG( _L8("-GetObjectHandlesL") ); |
|
270 } |
|
271 |
|
272 void CMTPGetObjectPropList::GetNextObjectPropL() |
|
273 { |
|
274 __FLOG( _L8("+GetNextObjectPropL") ); |
|
275 |
|
276 iOwnerDp = KInvalidDpId; |
|
277 if ( iCurrentHandle < iHandles.Count() ) |
|
278 { |
|
279 TUint32 handle = iHandles[iCurrentHandle]; |
|
280 iOwnerDp = iSingletons.ObjectMgr().ObjectOwnerId( handle ); |
|
281 if ( iOwnerDp == KInvalidDpId ) |
|
282 { |
|
283 SendResponseL(EMTPRespCodeInvalidObjectHandle); |
|
284 } |
|
285 else |
|
286 { |
|
287 iCurrentRequest.SetUint32( TMTPTypeRequest::ERequestParameter1, handle ); |
|
288 } |
|
289 } |
|
290 else |
|
291 { |
|
292 SendDataL( *iObjectPropList ); |
|
293 } |
|
294 |
|
295 __FLOG( _L8("-GetNextObjectPropL") ); |
|
296 } |
|
297 |
|
298 void CMTPGetObjectPropList::OnBrowseObjectL( TAny* aSelf, TUint aHandle, TUint32 /*aCurDepth*/ ) |
|
299 { |
|
300 CMTPGetObjectPropList* self = reinterpret_cast< CMTPGetObjectPropList* >( aSelf ); |
|
301 if ( self->iTargetDps.Find(self->iSingletons.ObjectMgr().ObjectOwnerId(aHandle)) != KErrNotFound ) |
|
302 { |
|
303 self->iHandles.AppendL( aHandle ); |
|
304 } |
|
305 } |