|
1 // Copyright (c) 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 @internalTechnology |
|
19 */ |
|
20 |
|
21 #include <f32file.h> |
|
22 #include <mtp/tmtptyperequest.h> |
|
23 #include <mtp/mmtpdataproviderframework.h> |
|
24 #include <mtp/mtpprotocolconstants.h> |
|
25 #include <mtp/cmtptypestring.h> |
|
26 #include <mtp/mmtpobjectmgr.h> |
|
27 #include <mtp/cmtpobjectmetadata.h> |
|
28 |
|
29 #include "mtpimagedpconst.h" |
|
30 #include "mtpimagedppanic.h" |
|
31 #include "mtpimagedputilits.h" |
|
32 #include "cmtpimagedp.h" |
|
33 #include "cmtpimagedpobjectpropertymgr.h" |
|
34 #include "cmtpimagedpsetobjectpropvalue.h" |
|
35 |
|
36 __FLOG_STMT(_LIT8(KComponent,"CMTPImageDpSetObjectPropValue");) |
|
37 /** |
|
38 Two-phase construction method |
|
39 @param aPlugin The data provider plugin |
|
40 @param aFramework The data provider framework |
|
41 @param aConnection The connection from which the request comes |
|
42 @return a pointer to the created request processor object |
|
43 */ |
|
44 MMTPRequestProcessor* CMTPImageDpSetObjectPropValue::NewL( |
|
45 MMTPDataProviderFramework& aFramework, |
|
46 MMTPConnection& aConnection,CMTPImageDataProvider& aDataProvider) |
|
47 { |
|
48 CMTPImageDpSetObjectPropValue* self = new (ELeave) CMTPImageDpSetObjectPropValue(aFramework, aConnection,aDataProvider); |
|
49 CleanupStack::PushL(self); |
|
50 self->ConstructL(); |
|
51 CleanupStack::Pop(self); |
|
52 return self; |
|
53 } |
|
54 |
|
55 /** |
|
56 Destructor |
|
57 */ |
|
58 CMTPImageDpSetObjectPropValue::~CMTPImageDpSetObjectPropValue() |
|
59 { |
|
60 __FLOG(_L8(">> ~CMTPImageDpSetObjectPropValue")); |
|
61 delete iMTPTypeString; |
|
62 delete iObjectMeta; |
|
63 __FLOG(_L8("<< ~CMTPImageDpSetObjectPropValue")); |
|
64 __FLOG_CLOSE; |
|
65 } |
|
66 |
|
67 /** |
|
68 Standard c++ constructor |
|
69 */ |
|
70 CMTPImageDpSetObjectPropValue::CMTPImageDpSetObjectPropValue( |
|
71 MMTPDataProviderFramework& aFramework, |
|
72 MMTPConnection& aConnection,CMTPImageDataProvider& aDataProvider) |
|
73 :CMTPRequestProcessor(aFramework, aConnection, 0, NULL), |
|
74 iDataProvider(aDataProvider), |
|
75 iObjectPropertyMgr(aDataProvider.PropertyMgr()) |
|
76 { |
|
77 } |
|
78 |
|
79 |
|
80 /** |
|
81 A helper function of CheckRequestL. To check whether the object property code is readonly. |
|
82 @param aObjectPropCode the object property code passed in. |
|
83 @return ETrue if the object property code is readonly. Otherwise EFalse. |
|
84 */ |
|
85 TBool CMTPImageDpSetObjectPropValue::IsPropCodeReadonly(TUint32 aObjectPropCode) |
|
86 { |
|
87 __FLOG(_L8(">> CMTPImageDpSetObjectPropValue::IsPropCodeReadonly")); |
|
88 TBool returnCode = EFalse; |
|
89 if(aObjectPropCode == EMTPObjectPropCodeStorageID |
|
90 || aObjectPropCode == EMTPObjectPropCodeObjectFormat |
|
91 || aObjectPropCode == EMTPObjectPropCodeProtectionStatus |
|
92 || aObjectPropCode == EMTPObjectPropCodeObjectSize |
|
93 || aObjectPropCode == EMTPObjectPropCodeParentObject |
|
94 || aObjectPropCode == EMTPObjectPropCodeDateCreated |
|
95 || aObjectPropCode == EMTPObjectPropCodePersistentUniqueObjectIdentifier |
|
96 || aObjectPropCode == EMTPObjectPropCodeWidth |
|
97 || aObjectPropCode == EMTPObjectPropCodeHeight |
|
98 || aObjectPropCode == EMTPObjectPropCodeImageBitDepth |
|
99 || aObjectPropCode == EMTPObjectPropCodeRepresentativeSampleFormat |
|
100 || aObjectPropCode == EMTPObjectPropCodeRepresentativeSampleSize |
|
101 || aObjectPropCode == EMTPObjectPropCodeRepresentativeSampleHeight |
|
102 || aObjectPropCode == EMTPObjectPropCodeRepresentativeSampleWidth) |
|
103 { |
|
104 returnCode = ETrue; |
|
105 } |
|
106 __FLOG(_L8("<< CMTPImageDpSetObjectPropValue::IsPropCodeReadonly")); |
|
107 return returnCode; |
|
108 } |
|
109 |
|
110 /** |
|
111 Verify object handle, prop code |
|
112 */ |
|
113 TMTPResponseCode CMTPImageDpSetObjectPropValue::CheckRequestL() |
|
114 { |
|
115 __FLOG(_L8(">> CMTPImageDpSetObjectPropValue::CheckRequestL")); |
|
116 TMTPResponseCode responseCode = CMTPRequestProcessor::CheckRequestL(); |
|
117 if(responseCode == EMTPRespCodeOK) |
|
118 { |
|
119 responseCode = MTPImageDpUtilits::VerifyObjectHandleL(iFramework, Request().Uint32(TMTPTypeRequest::ERequestParameter1), *iObjectMeta); |
|
120 } |
|
121 |
|
122 TUint32 propCode = Request().Uint32(TMTPTypeRequest::ERequestParameter2); |
|
123 if(responseCode == EMTPRespCodeOK) |
|
124 { |
|
125 const TInt count = sizeof(KMTPImageDpSupportedProperties) / sizeof(TUint16); |
|
126 TInt i = 0; |
|
127 for(i = 0; i < count; i++) |
|
128 { |
|
129 if(KMTPImageDpSupportedProperties[i] == propCode |
|
130 && IsPropCodeReadonly(propCode)) |
|
131 // Object property code supported, but cann't be set. |
|
132 { |
|
133 responseCode = EMTPRespCodeAccessDenied; |
|
134 break; |
|
135 } |
|
136 else if(KMTPImageDpSupportedProperties[i] == propCode) |
|
137 // Object property code supported and can be set. |
|
138 { |
|
139 break; |
|
140 } |
|
141 } |
|
142 if(i == count) |
|
143 { |
|
144 responseCode = EMTPRespCodeInvalidObjectPropCode; |
|
145 } |
|
146 } |
|
147 __FLOG(_L8("<< CMTPImageDpSetObjectPropValue::CheckRequestL")); |
|
148 return responseCode; |
|
149 } |
|
150 |
|
151 /** |
|
152 SetObjectPropValue request handler |
|
153 */ |
|
154 void CMTPImageDpSetObjectPropValue::ServiceL() |
|
155 { |
|
156 __FLOG(_L8(">> CMTPImageDpSetObjectPropValue::ServiceL")); |
|
157 TUint32 propCode = Request().Uint32(TMTPTypeRequest::ERequestParameter2); |
|
158 delete iMTPTypeString; |
|
159 iMTPTypeString = NULL; |
|
160 iMTPTypeString = CMTPTypeString::NewL(); |
|
161 switch(propCode) |
|
162 { |
|
163 case EMTPObjectPropCodeDateModified: |
|
164 case EMTPObjectPropCodeObjectFileName: |
|
165 case EMTPObjectPropCodeName: |
|
166 ReceiveDataL(*iMTPTypeString); |
|
167 break; |
|
168 case EMTPObjectPropCodeNonConsumable: |
|
169 ReceiveDataL(iMTPTypeUint8); |
|
170 break; |
|
171 default: |
|
172 User::Leave(KErrGeneral); |
|
173 } |
|
174 __FLOG(_L8("<< CMTPImageDpSetObjectPropValue::ServiceL")); |
|
175 } |
|
176 |
|
177 /** |
|
178 Apply the references to the specified object |
|
179 @return EFalse |
|
180 */ |
|
181 TBool CMTPImageDpSetObjectPropValue::DoHandleResponsePhaseL() |
|
182 { |
|
183 __FLOG(_L8(">> CMTPImageDpSetObjectPropValue::DoHandleResponsePhaseL")); |
|
184 |
|
185 iObjectPropertyMgr.SetCurrentObjectL(*iObjectMeta, ETrue); |
|
186 /* |
|
187 [Winlog]If file is readonly, all property of this file shoule not be changed. |
|
188 */ |
|
189 TUint16 protection; |
|
190 iObjectPropertyMgr.GetPropertyL(EMTPObjectPropCodeProtectionStatus, protection); |
|
191 if(EMTPProtectionReadOnly == protection) |
|
192 { |
|
193 SendResponseL(EMTPRespCodeAccessDenied); |
|
194 return EFalse; |
|
195 } |
|
196 TInt32 handle(Request().Uint32(TMTPTypeRequest::ERequestParameter1)); |
|
197 TMTPResponseCode responseCode = EMTPRespCodeOK; |
|
198 TUint32 propCode = Request().Uint32(TMTPTypeRequest::ERequestParameter2); |
|
199 |
|
200 switch(propCode) |
|
201 { |
|
202 case EMTPObjectPropCodeDateModified: |
|
203 { |
|
204 if (iMTPTypeString->NumChars() == (iMTPTypeString->StringChars().Length() + 1)) |
|
205 { |
|
206 iObjectPropertyMgr.SetPropertyL(TMTPObjectPropertyCode(propCode), iMTPTypeString->StringChars()); |
|
207 } |
|
208 else if ( iMTPTypeString->NumChars() == 0 ) |
|
209 { |
|
210 responseCode = EMTPRespCodeOK; |
|
211 } |
|
212 } |
|
213 break; |
|
214 |
|
215 case EMTPObjectPropCodeObjectFileName: |
|
216 case EMTPObjectPropCodeName: |
|
217 { |
|
218 if (iMTPTypeString->NumChars() == (iMTPTypeString->StringChars().Length() + 1)) |
|
219 { |
|
220 iObjectPropertyMgr.SetPropertyL(TMTPObjectPropertyCode(propCode), iMTPTypeString->StringChars()); |
|
221 iFramework.ObjectMgr().ModifyObjectL(*iObjectMeta); |
|
222 } |
|
223 else if ( iMTPTypeString->NumChars() == 0 ) |
|
224 { |
|
225 responseCode = EMTPRespCodeOK; |
|
226 } |
|
227 } |
|
228 break; |
|
229 case EMTPObjectPropCodeNonConsumable: |
|
230 { |
|
231 iObjectPropertyMgr.SetPropertyL(TMTPObjectPropertyCode(propCode), iMTPTypeUint8.Value()); |
|
232 iFramework.ObjectMgr().ModifyObjectL(*iObjectMeta); |
|
233 responseCode = EMTPRespCodeOK; |
|
234 } |
|
235 break; |
|
236 default: |
|
237 responseCode = EMTPRespCodeInvalidObjectPropFormat; |
|
238 //Panic(EMTPImageDpUnsupportedProperty); |
|
239 } |
|
240 |
|
241 SendResponseL(responseCode); |
|
242 |
|
243 __FLOG(_L8("<< CMTPImageDpSetObjectPropValue::DoHandleResponsePhaseL")); |
|
244 return EFalse; |
|
245 } |
|
246 |
|
247 TBool CMTPImageDpSetObjectPropValue::HasDataphase() const |
|
248 { |
|
249 return ETrue; |
|
250 } |
|
251 |
|
252 /** |
|
253 Second-phase construction |
|
254 */ |
|
255 void CMTPImageDpSetObjectPropValue::ConstructL() |
|
256 { |
|
257 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
258 __FLOG(_L8(">> CMTPImageDpSetObjectPropList::ConstructL")); |
|
259 |
|
260 iObjectMeta = CMTPObjectMetaData::NewL(); |
|
261 |
|
262 __FLOG(_L8("<< CMTPImageDpSetObjectPropList::ConstructL")); |
|
263 } |
|
264 |
|
265 |