|
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 |
|
21 #include "rmtpframework.h" |
|
22 #include "cmtpdataprovidercontroller.h" |
|
23 #include "cmtpparserrouter.h" |
|
24 #include "cmtpdataprovider.h" |
|
25 #include "cmtpsendobjectinfo.h" |
|
26 #include "mtpproxydppanic.h" |
|
27 #include "cmtpproxydpconfigmgr.h" |
|
28 #include "cmtpstoragemgr.h" |
|
29 |
|
30 __FLOG_STMT( _LIT8( KComponent,"PrxySendObjectInfo" ); ) |
|
31 |
|
32 /** |
|
33 Verification data for the SendObjectInfo request |
|
34 */ |
|
35 const TMTPRequestElementInfo KMTPSendObjectInfoPolicy[] = |
|
36 { |
|
37 {TMTPTypeRequest::ERequestParameter1, EMTPElementTypeStorageId, EMTPElementAttrWrite, 1, 0, 0}, |
|
38 {TMTPTypeRequest::ERequestParameter2, EMTPElementTypeObjectHandle, EMTPElementAttrDir | EMTPElementAttrWrite, 2, KMTPHandleAll, KMTPHandleNone} |
|
39 }; |
|
40 |
|
41 /** |
|
42 Two-phase construction method |
|
43 @param aFramework The data provider framework |
|
44 @param aConnection The connection from which the request comes |
|
45 @return a pointer to the created request processor object |
|
46 */ |
|
47 MMTPRequestProcessor* CMTPSendObjectInfo::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) |
|
48 { |
|
49 CMTPSendObjectInfo* self = new (ELeave) CMTPSendObjectInfo(aFramework, aConnection); |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL(); |
|
52 CleanupStack::Pop(self); |
|
53 return self; |
|
54 } |
|
55 |
|
56 /** |
|
57 Destructor |
|
58 */ |
|
59 CMTPSendObjectInfo::~CMTPSendObjectInfo() |
|
60 { |
|
61 __FLOG(_L8("~CMTPSendObjectInfo - Entry")); |
|
62 |
|
63 delete iObjectInfo; |
|
64 iSingletons.Close(); |
|
65 iProxyDpSingletons.Close(); |
|
66 |
|
67 __FLOG(_L8("~CMTPSendObjectInfo - Exit")); |
|
68 __FLOG_CLOSE; |
|
69 } |
|
70 |
|
71 /** |
|
72 Standard c++ constructor |
|
73 */ |
|
74 CMTPSendObjectInfo::CMTPSendObjectInfo(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) : |
|
75 CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPSendObjectInfoPolicy)/sizeof(TMTPRequestElementInfo), KMTPSendObjectInfoPolicy) |
|
76 { |
|
77 |
|
78 } |
|
79 |
|
80 /** |
|
81 Second phase constructor. |
|
82 */ |
|
83 void CMTPSendObjectInfo::ConstructL() |
|
84 { |
|
85 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
86 __FLOG(_L8("ConstructL - Entry")); |
|
87 |
|
88 iSingletons.OpenL(); |
|
89 |
|
90 __FLOG(_L8("ConstructL - Exit")); |
|
91 } |
|
92 |
|
93 /** |
|
94 SendObjectInfo/SendObject request handler |
|
95 NOTE: SendObjectInfo has to be comes before SendObject requests. To maintain the state information |
|
96 between the two requests, the two requests are combined together in one signal processor. |
|
97 */ |
|
98 void CMTPSendObjectInfo::ServiceL() |
|
99 { |
|
100 delete iObjectInfo; |
|
101 iObjectInfo = NULL; |
|
102 iObjectInfo = CMTPTypeObjectInfo::NewL(); |
|
103 ReceiveDataL(*iObjectInfo); |
|
104 } |
|
105 |
|
106 /** |
|
107 Override to handle the response phase of SendObjectInfo requests |
|
108 @return EFalse |
|
109 */ |
|
110 TBool CMTPSendObjectInfo::DoHandleResponsePhaseL() |
|
111 { |
|
112 DoHandleSendObjectInfoCompleteL(); |
|
113 return EFalse; |
|
114 } |
|
115 |
|
116 TBool CMTPSendObjectInfo::HasDataphase() const |
|
117 { |
|
118 return ETrue; |
|
119 } |
|
120 |
|
121 /** |
|
122 Handling the completing phase of SendObjectInfo request |
|
123 @return ETrue if the specified object can be saved on the specified location, otherwise, EFalse |
|
124 */ |
|
125 void CMTPSendObjectInfo::DoHandleSendObjectInfoCompleteL() |
|
126 { |
|
127 __FLOG(_L8("DoHandleSendObjectInfoCompleteL - Entry")); |
|
128 |
|
129 CMTPParserRouter::TRoutingParameters params(*iRequest, iConnection); |
|
130 iSingletons.Router().ParseOperationRequestL(params); |
|
131 TBool fileFlag=EFalse; |
|
132 RArray<TUint> targets; |
|
133 CleanupClosePushL(targets); |
|
134 params.SetParam(CMTPParserRouter::TRoutingParameters::EParamFormatCode, iObjectInfo->Uint16L(CMTPTypeObjectInfo::EObjectFormat)); |
|
135 |
|
136 iProxyDpSingletons.OpenL(iFramework); |
|
137 TInt index(KErrNotFound); |
|
138 const TUint16 formatCode=iObjectInfo->Uint16L(CMTPTypeObjectInfo::EObjectFormat); |
|
139 __FLOG_1( _L8("formatCode = %d"), formatCode ); |
|
140 switch(formatCode) |
|
141 { |
|
142 case EMTPFormatCodeAssociation: |
|
143 params.SetParam(CMTPParserRouter::TRoutingParameters::EParamFormatSubCode, iObjectInfo->Uint16L(CMTPTypeObjectInfo::EAssociationType)); |
|
144 break; |
|
145 |
|
146 case EMTPFormatCodeScript: |
|
147 { |
|
148 __FLOG_1( _L8("formatCode = %d"), EMTPFormatCodeScript ); |
|
149 const TDesC& filename = iObjectInfo->StringCharsL(CMTPTypeObjectInfo::EFilename); |
|
150 HBufC* lowFileName = HBufC::NewLC(filename.Length()); |
|
151 TPtr16 prt(lowFileName->Des()); |
|
152 prt.Append(filename); |
|
153 prt.LowerCase(); |
|
154 __FLOG_1( _L8("lowFileName = %s"), &prt ); |
|
155 if (iProxyDpSingletons.FrameworkConfig().GetFileName(prt,index) ) |
|
156 { |
|
157 fileFlag=ETrue; |
|
158 } |
|
159 CleanupStack::PopAndDestroy(lowFileName); |
|
160 |
|
161 params.SetParam(CMTPParserRouter::TRoutingParameters::EParamFormatSubCode, EMTPAssociationTypeUndefined); |
|
162 break; |
|
163 } |
|
164 default: |
|
165 params.SetParam(CMTPParserRouter::TRoutingParameters::EParamFormatSubCode, EMTPAssociationTypeUndefined); |
|
166 break; |
|
167 } |
|
168 |
|
169 __FLOG_1( _L8("fileFlag = %d"), fileFlag ); |
|
170 if(fileFlag) |
|
171 { |
|
172 TInt syncdpid = iSingletons.DpController().DpId(iProxyDpSingletons.FrameworkConfig().GetDPId(index)); |
|
173 iSingletons.DpController().DataProviderL(syncdpid).ExecuteProxyRequestL(Request(), Connection(), *this); |
|
174 } |
|
175 else |
|
176 { |
|
177 iSingletons.Router().RouteOperationRequestL(params, targets); |
|
178 CMTPStorageMgr& storages(iSingletons.StorageMgr()); |
|
179 const TUint KStorageId = Request().Uint32(TMTPTypeResponse::EResponseParameter1); |
|
180 __FLOG_1( _L8("KStorageId = %d"), KStorageId ); |
|
181 __FLOG_1( _L8("targets.Count() = %d"), targets.Count() ); |
|
182 if( KMTPNotSpecified32 == KStorageId) |
|
183 { |
|
184 iSingletons.DpController().DataProviderL(targets[0]).ExecuteProxyRequestL(Request(), Connection(), *this); |
|
185 } |
|
186 else if( storages.ValidStorageId(KStorageId) ) |
|
187 { |
|
188 if(targets.Count() == 1) |
|
189 { |
|
190 __FLOG_1( _L8("targets[0] = %d"), targets[0] ); |
|
191 iSingletons.DpController().DataProviderL(targets[0]).ExecuteProxyRequestL(Request(), Connection(), *this); |
|
192 } |
|
193 else |
|
194 { |
|
195 TInt dpID(KErrNotFound); |
|
196 if (storages.LogicalStorageId(KStorageId)) |
|
197 { |
|
198 dpID = storages.LogicalStorageOwner(KStorageId); |
|
199 } |
|
200 else |
|
201 { |
|
202 dpID = storages.PhysicalStorageOwner(KStorageId); |
|
203 } |
|
204 __FLOG_1( _L8("dpID = %d"), dpID ); |
|
205 if( targets.Find( dpID ) == KErrNotFound ) |
|
206 { |
|
207 __FLOG(_L8("No target dp is found, so send one GeneralError response.")); |
|
208 SendResponseL( EMTPRespCodeGeneralError ); |
|
209 } |
|
210 else |
|
211 { |
|
212 iSingletons.DpController().DataProviderL(dpID).ExecuteProxyRequestL(Request(), Connection(), *this); |
|
213 } |
|
214 } |
|
215 } |
|
216 else |
|
217 { |
|
218 __FLOG(_L8("StorageID is invalid.")); |
|
219 SendResponseL( EMTPRespCodeInvalidStorageID ); |
|
220 } |
|
221 } |
|
222 CleanupStack::PopAndDestroy(&targets); |
|
223 |
|
224 __FLOG(_L8("DoHandleSendObjectInfoCompleteL - Exit")); |
|
225 } |
|
226 |
|
227 #ifdef _DEBUG |
|
228 void CMTPSendObjectInfo::ProxyReceiveDataL(MMTPType& aData, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection, TRequestStatus& aStatus) |
|
229 #else |
|
230 void CMTPSendObjectInfo::ProxyReceiveDataL(MMTPType& aData, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& aStatus) |
|
231 #endif |
|
232 { |
|
233 __ASSERT_DEBUG(iRequest == &aRequest && &iConnection == &aConnection, Panic(EMTPNotSameRequestProxy)); |
|
234 MMTPType::CopyL(*iObjectInfo, aData); |
|
235 TRequestStatus* status = &aStatus; |
|
236 User::RequestComplete(status, KErrNone); |
|
237 } |
|
238 |
|
239 void CMTPSendObjectInfo::ProxySendDataL(const MMTPType& /*aData*/, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& /*aStatus*/) |
|
240 { |
|
241 Panic(EMTPWrongRequestPhase); |
|
242 } |
|
243 |
|
244 #ifdef _DEBUG |
|
245 void CMTPSendObjectInfo::ProxySendResponseL(const TMTPTypeResponse& aResponse, const TMTPTypeRequest& aRequest, MMTPConnection& aConnection, TRequestStatus& aStatus) |
|
246 #else |
|
247 void CMTPSendObjectInfo::ProxySendResponseL(const TMTPTypeResponse& aResponse, const TMTPTypeRequest& /*aRequest*/, MMTPConnection& /*aConnection*/, TRequestStatus& aStatus) |
|
248 #endif |
|
249 { |
|
250 __ASSERT_DEBUG(iRequest == &aRequest && &iConnection == &aConnection, Panic(EMTPNotSameRequestProxy)); |
|
251 MMTPType::CopyL(aResponse, iResponse); |
|
252 TRequestStatus* status = &aStatus; |
|
253 User::RequestComplete(status, KErrNone); |
|
254 } |
|
255 |
|
256 void CMTPSendObjectInfo::ProxyTransactionCompleteL(const TMTPTypeRequest& aRequest, MMTPConnection& aConnection) |
|
257 { |
|
258 __ASSERT_DEBUG(iRequest == &aRequest && &iConnection == &aConnection, Panic(EMTPNotSameRequestProxy)); |
|
259 iFramework.SendResponseL(iResponse, aRequest, aConnection); |
|
260 } |
|
261 |
|
262 |