|
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/mtpdatatypeconstants.h> |
|
18 #include <mtp/mmtpdataproviderframework.h> |
|
19 #include <mtp/mmtpobjectmgr.h> |
|
20 #include <mtp/cmtpobjectmetadata.h> |
|
21 #include <mtp/cmtptypestring.h> |
|
22 #include <mtp/cmtptypeobjectproplist.h> |
|
23 |
|
24 #include "cmtpsetobjectproplist.h" |
|
25 #include "cmtpdataprovidercontroller.h" |
|
26 |
|
27 |
|
28 EXPORT_C MMTPRequestProcessor* CMTPSetObjectPropList::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) |
|
29 { |
|
30 CMTPSetObjectPropList* self = new (ELeave) CMTPSetObjectPropList(aFramework, aConnection); |
|
31 CleanupStack::PushL(self); |
|
32 self->ConstructL(); |
|
33 CleanupStack::Pop(self); |
|
34 return self; |
|
35 } |
|
36 |
|
37 EXPORT_C CMTPSetObjectPropList::~CMTPSetObjectPropList() |
|
38 { |
|
39 iDpSingletons.Close(); |
|
40 iSingleton.Close(); |
|
41 delete iPropertyList; |
|
42 delete iObjMeta; |
|
43 } |
|
44 |
|
45 CMTPSetObjectPropList::CMTPSetObjectPropList(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) : |
|
46 CMTPRequestProcessor(aFramework, aConnection, 0, NULL) |
|
47 { |
|
48 |
|
49 } |
|
50 |
|
51 void CMTPSetObjectPropList::ConstructL() |
|
52 { |
|
53 iDpSingletons.OpenL(iFramework); |
|
54 iSingleton.OpenL(); |
|
55 iPropertyList = CMTPTypeObjectPropList::NewL(); |
|
56 iObjMeta = CMTPObjectMetaData::NewL(); |
|
57 } |
|
58 |
|
59 void CMTPSetObjectPropList::ServiceL() |
|
60 { |
|
61 ReceiveDataL(*iPropertyList); |
|
62 } |
|
63 |
|
64 TBool CMTPSetObjectPropList::DoHandleResponsePhaseL() |
|
65 { |
|
66 MMTPObjectMgr& objects(iFramework.ObjectMgr()); |
|
67 TUint32 parameter(0); |
|
68 TMTPResponseCode responseCode(EMTPRespCodeOK); |
|
69 const TUint count(iPropertyList->NumberOfElements()); |
|
70 iPropertyList->ResetCursor(); |
|
71 for (TUint i(0); ((i < count) && (responseCode == EMTPRespCodeOK)); i++) |
|
72 { |
|
73 CMTPTypeObjectPropListElement& element=iPropertyList->GetNextElementL(); |
|
74 TUint32 handle = element.Uint32L(CMTPTypeObjectPropListElement::EObjectHandle); |
|
75 TUint16 propertyCode = element.Uint16L(CMTPTypeObjectPropListElement::EPropertyCode); |
|
76 TUint16 dataType = element.Uint16L(CMTPTypeObjectPropListElement::EDatatype); |
|
77 |
|
78 if (objects.ObjectOwnerId(handle) == iFramework.DataProviderId()) |
|
79 { |
|
80 // Object is owned by the FileDp |
|
81 responseCode = CheckPropCode(propertyCode, dataType); |
|
82 if (responseCode == EMTPRespCodeOK) |
|
83 { |
|
84 responseCode = CheckObjectHandleL(handle); |
|
85 } |
|
86 |
|
87 if (responseCode == EMTPRespCodeOK) |
|
88 { |
|
89 switch(propertyCode) |
|
90 { |
|
91 case EMTPObjectPropCodeObjectFileName: |
|
92 { |
|
93 const TDesC& newName = element.StringL(CMTPTypeObjectPropListElement::EValue); |
|
94 TRAPD(err, iDpSingletons.MTPUtility().RenameObjectL(handle, newName)); |
|
95 if(KErrNotFound == err) |
|
96 { |
|
97 responseCode = EMTPRespCodeInvalidObjectHandle; |
|
98 } |
|
99 else if( KErrAlreadyExists == err) |
|
100 { |
|
101 responseCode = EMTPRespCodeInvalidObjectPropValue; |
|
102 } |
|
103 else if(KErrNone != err) |
|
104 { |
|
105 responseCode = EMTPRespCodeAccessDenied; |
|
106 } |
|
107 } |
|
108 break; |
|
109 case EMTPObjectPropCodeName: |
|
110 { |
|
111 const TDesC& newName = element.StringL(CMTPTypeObjectPropListElement::EValue); |
|
112 iObjMeta->SetDesCL( CMTPObjectMetaData::EName, newName); |
|
113 iFramework.ObjectMgr().ModifyObjectL(*iObjMeta); |
|
114 |
|
115 break; |
|
116 } |
|
117 |
|
118 case EMTPObjectPropCodeDateModified: |
|
119 { |
|
120 TTime modifiedTime; |
|
121 if( iDpSingletons.MTPUtility().MTPTimeStr2TTime(element.StringL(CMTPTypeObjectPropListElement::EValue), modifiedTime) ) |
|
122 { |
|
123 iSingleton.Fs().SetModified( iObjMeta->DesC(CMTPObjectMetaData::ESuid), modifiedTime ); |
|
124 } |
|
125 else |
|
126 { |
|
127 responseCode = EMTPRespCodeInvalidObjectPropValue; |
|
128 } |
|
129 } |
|
130 break; |
|
131 |
|
132 case EMTPObjectPropCodeNonConsumable: |
|
133 iObjMeta->SetUint( CMTPObjectMetaData::ENonConsumable, element.Uint8L(CMTPTypeObjectPropListElement::EValue)); |
|
134 iFramework.ObjectMgr().ModifyObjectL(*iObjMeta); |
|
135 break; |
|
136 |
|
137 case EMTPObjectPropCodeAssociationType: |
|
138 if (EModeMTP != iFramework.Mode()) |
|
139 { |
|
140 responseCode = EMTPRespCodeOK; |
|
141 } |
|
142 else if( element.Uint16L(CMTPTypeObjectPropListElement::EValue) == EMTPAssociationTypeGenericFolder ) |
|
143 { |
|
144 responseCode = EMTPRespCodeOK; |
|
145 } |
|
146 else |
|
147 { |
|
148 responseCode = EMTPRespCodeInvalidObjectPropValue; |
|
149 } |
|
150 break; |
|
151 |
|
152 case EMTPObjectPropCodeAssociationDesc: |
|
153 if((element.Uint32L(CMTPTypeObjectPropListElement::EValue)) == 0) |
|
154 { |
|
155 responseCode = EMTPRespCodeOK; |
|
156 } |
|
157 else |
|
158 { |
|
159 responseCode = EMTPRespCodeInvalidObjectPropValue; |
|
160 } |
|
161 break; |
|
162 default: |
|
163 responseCode = EMTPRespCodeObjectPropNotSupported; |
|
164 break; |
|
165 } |
|
166 } |
|
167 |
|
168 if (responseCode != EMTPRespCodeOK) |
|
169 { |
|
170 // Return the index of the failed property in the response. |
|
171 parameter = i; |
|
172 } |
|
173 } |
|
174 } |
|
175 |
|
176 SendResponseL(responseCode, 1, ¶meter); |
|
177 return EFalse; |
|
178 } |
|
179 |
|
180 TBool CMTPSetObjectPropList::HasDataphase() const |
|
181 { |
|
182 return ETrue; |
|
183 } |
|
184 |
|
185 TMTPResponseCode CMTPSetObjectPropList::CheckPropCode(TUint16 aPropertyCode, TUint16 aDataType) const |
|
186 { |
|
187 TMTPResponseCode responseCode = EMTPRespCodeOK; |
|
188 switch(aPropertyCode) |
|
189 { |
|
190 case EMTPObjectPropCodeStorageID: |
|
191 case EMTPObjectPropCodeObjectFormat: |
|
192 case EMTPObjectPropCodeObjectSize: |
|
193 case EMTPObjectPropCodeParentObject: |
|
194 case EMTPObjectPropCodePersistentUniqueObjectIdentifier: |
|
195 case EMTPObjectPropCodeProtectionStatus: |
|
196 responseCode = EMTPRespCodeAccessDenied; |
|
197 break; |
|
198 |
|
199 case EMTPObjectPropCodeObjectFileName: |
|
200 case EMTPObjectPropCodeName: |
|
201 case EMTPObjectPropCodeDateModified: |
|
202 if (aDataType != EMTPTypeString) |
|
203 { |
|
204 responseCode = EMTPRespCodeInvalidObjectPropFormat; |
|
205 } |
|
206 break; |
|
207 case EMTPObjectPropCodeNonConsumable: |
|
208 if (aDataType != EMTPTypeUINT8) |
|
209 { |
|
210 responseCode = EMTPRespCodeInvalidObjectPropFormat; |
|
211 } |
|
212 break; |
|
213 case EMTPObjectPropCodeAssociationType: |
|
214 if (aDataType != EMTPTypeUINT16) |
|
215 { |
|
216 responseCode = EMTPRespCodeInvalidObjectPropFormat; |
|
217 } |
|
218 break; |
|
219 case EMTPObjectPropCodeAssociationDesc: |
|
220 if (aDataType != EMTPTypeUINT32) |
|
221 { |
|
222 responseCode = EMTPRespCodeInvalidObjectPropFormat; |
|
223 } |
|
224 break; |
|
225 default: |
|
226 responseCode = EMTPRespCodeInvalidObjectPropCode; |
|
227 } |
|
228 return responseCode; |
|
229 } |
|
230 |
|
231 TMTPResponseCode CMTPSetObjectPropList::CheckObjectHandleL(TUint32 aHandle) const |
|
232 { |
|
233 TMTPResponseCode responseCode = EMTPRespCodeOK; |
|
234 |
|
235 // Obj handle doesn't exist |
|
236 if (!(iFramework.ObjectMgr().ObjectL(aHandle, *iObjMeta)) ) |
|
237 { |
|
238 responseCode = EMTPRespCodeInvalidObjectHandle; |
|
239 } |
|
240 return responseCode; |
|
241 } |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |