|
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 #include <f32file.h> |
|
18 #include <imageconversion.h> |
|
19 #include <mtp/tmtptyperequest.h> |
|
20 #include <mtp/mmtpdataproviderframework.h> |
|
21 #include <mtp/mtpprotocolconstants.h> |
|
22 #include <mtp/mmtpobjectmgr.h> |
|
23 #include <mtp/cmtptypeobjectinfo.h> |
|
24 #include <mtp/cmtpobjectmetadata.h> |
|
25 #include <mtp/cmtptypestring.h> |
|
26 #include <mtp/mmtpstoragemgr.h> |
|
27 #include "cmtppictbridgedpgetobjectinfo.h" |
|
28 #include "mtppictbridgedpconst.h" |
|
29 #include "mtppictbridgedppanic.h" |
|
30 #include "cmtprequestchecker.h" |
|
31 #include "cptpserver.h" |
|
32 |
|
33 /** |
|
34 Two-phase construction method |
|
35 */ |
|
36 MMTPRequestProcessor* CMTPPictBridgeDpGetObjectInfo::NewL( |
|
37 MMTPDataProviderFramework& aFramework, |
|
38 MMTPConnection& aConnection, |
|
39 CMTPPictBridgeDataProvider& aDataProvider) |
|
40 { |
|
41 CMTPPictBridgeDpGetObjectInfo* self = new (ELeave) CMTPPictBridgeDpGetObjectInfo(aFramework, aConnection, aDataProvider); |
|
42 CleanupStack::PushL(self); |
|
43 self->ConstructL(); |
|
44 CleanupStack::Pop(self); |
|
45 return self; |
|
46 } |
|
47 |
|
48 /** |
|
49 Destructor |
|
50 */ |
|
51 CMTPPictBridgeDpGetObjectInfo::~CMTPPictBridgeDpGetObjectInfo() |
|
52 { |
|
53 __FLOG(_L8("CMTPPictBridgeDpGetObjectInfo::~CMTPPictBridgeDpGetObjectInfo")); |
|
54 delete iObjectInfoToBuildP; |
|
55 __FLOG_CLOSE; |
|
56 } |
|
57 |
|
58 /** |
|
59 Standard c++ constructor |
|
60 */ |
|
61 CMTPPictBridgeDpGetObjectInfo::CMTPPictBridgeDpGetObjectInfo( |
|
62 MMTPDataProviderFramework& aFramework, |
|
63 MMTPConnection& aConnection, |
|
64 CMTPPictBridgeDataProvider& aDataProvider) |
|
65 :CMTPRequestProcessor(aFramework, aConnection, 0, NULL ), |
|
66 iPictBridgeDP(aDataProvider) |
|
67 { |
|
68 } |
|
69 |
|
70 /** |
|
71 GetObjectInfo request handler |
|
72 */ |
|
73 void CMTPPictBridgeDpGetObjectInfo::ServiceL() |
|
74 { |
|
75 __FLOG(_L8(">> CMTPPictBridgeDpGetObjectInfo::ServiceL")); |
|
76 BuildObjectInfoL(); |
|
77 SendDataL(*iObjectInfoToBuildP); |
|
78 __FLOG(_L8("<< CMTPPictBridgeDpGetObjectInfo::ServiceL")); |
|
79 } |
|
80 |
|
81 /** |
|
82 Second-phase construction |
|
83 */ |
|
84 void CMTPPictBridgeDpGetObjectInfo::ConstructL() |
|
85 { |
|
86 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
87 iObjectInfoToBuildP = CMTPTypeObjectInfo::NewL(); |
|
88 } |
|
89 |
|
90 /** |
|
91 Populate the object info dataset |
|
92 */ |
|
93 void CMTPPictBridgeDpGetObjectInfo::BuildObjectInfoL() |
|
94 { |
|
95 __FLOG(_L8(">> CMTPPictBridgeDpGetObjectInfo::BuildObjectInfoL")); |
|
96 __ASSERT_DEBUG(iRequestChecker, Panic(EMTPPictBridgeDpRequestCheckNull)); |
|
97 |
|
98 TUint32 objectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
|
99 |
|
100 __FLOG_VA((_L8(" object handle 0x%x"), objectHandle)); |
|
101 |
|
102 //1. storage id |
|
103 TUint32 storageId(iFramework.StorageMgr().DefaultStorageId()); // we always use default storage for DPS |
|
104 |
|
105 iObjectInfoToBuildP->SetUint32L(CMTPTypeObjectInfo::EStorageID, storageId); |
|
106 |
|
107 //2. object format |
|
108 TUint16 format(EMTPFormatCodeScript); // we only handle DPS script |
|
109 iObjectInfoToBuildP->SetUint16L(CMTPTypeObjectInfo::EObjectFormat, format); |
|
110 __FLOG_VA((_L8(" format ok 0x%x"), format)); |
|
111 |
|
112 //3. protection status, |
|
113 TUint16 protection(EMTPProtectionNoProtection); // we do not care about protection |
|
114 |
|
115 iObjectInfoToBuildP->SetUint16L(CMTPTypeObjectInfo::EProtectionStatus, protection); |
|
116 __FLOG_VA((_L8(" protection(%d) ok"), protection)); |
|
117 |
|
118 //4. object compressed size |
|
119 // see SetFileSizeDateL |
|
120 |
|
121 //5. thumb format |
|
122 iObjectInfoToBuildP->SetUint16L(CMTPTypeObjectInfo::EThumbFormat, 0); |
|
123 //6. thumb compressed size |
|
124 iObjectInfoToBuildP->SetUint32L(CMTPTypeObjectInfo::EThumbCompressedSize, 0); |
|
125 //7. thumb pix width |
|
126 iObjectInfoToBuildP->SetUint32L(CMTPTypeObjectInfo::EThumbPixWidth, 0); |
|
127 //8, thumb pix height |
|
128 iObjectInfoToBuildP->SetUint32L(CMTPTypeObjectInfo::EThumbPixHeight, 0); |
|
129 //9. image pix width |
|
130 iObjectInfoToBuildP->SetUint32L(CMTPTypeObjectInfo::EImagePixWidth, 0); |
|
131 //10. image pix height |
|
132 iObjectInfoToBuildP->SetUint32L(CMTPTypeObjectInfo::EImagePixHeight, 0); |
|
133 //11. image bit depth |
|
134 iObjectInfoToBuildP->SetUint32L(CMTPTypeObjectInfo::EImageBitDepth, 0); |
|
135 |
|
136 CMTPObjectMetaData* objectP = CMTPObjectMetaData::NewL(); |
|
137 CleanupStack::PushL(objectP); |
|
138 |
|
139 iFramework.ObjectMgr().ObjectL(objectHandle, *objectP); |
|
140 |
|
141 //12. Parent object |
|
142 TUint32 parent(objectP->Uint(CMTPObjectMetaData::EParentHandle)); |
|
143 iObjectInfoToBuildP->SetUint32L(CMTPTypeObjectInfo::EParentObject, parent); |
|
144 |
|
145 //13 and 14. Association type and description |
|
146 TUint16 associationType(EMTPAssociationTypeUndefined); |
|
147 iObjectInfoToBuildP->SetUint16L(CMTPTypeObjectInfo::EAssociationType, associationType); |
|
148 iObjectInfoToBuildP->SetUint32L(CMTPTypeObjectInfo::EAssociationDescription, 0); |
|
149 |
|
150 //15. sequence number |
|
151 iObjectInfoToBuildP->SetUint32L(CMTPTypeObjectInfo::ESequenceNumber, 0); |
|
152 |
|
153 //16. file name |
|
154 //use the name without full path specification |
|
155 TParse parse; |
|
156 User::LeaveIfError( parse.Set(objectP->DesC(CMTPObjectMetaData::ESuid), NULL, NULL) ); |
|
157 iObjectInfoToBuildP->SetStringL(CMTPTypeObjectInfo::EFilename, parse.NameAndExt()); |
|
158 |
|
159 //4, compressed size, 17 Date created, and 18 Date modified |
|
160 SetFileSizeDateL(objectP->DesC(CMTPObjectMetaData::ESuid), (objectHandle==iPictBridgeDP.PtpServer()->DeviceDiscoveryHandle())); |
|
161 |
|
162 //18. keyword |
|
163 //empty keyword |
|
164 iObjectInfoToBuildP->SetStringL(CMTPTypeObjectInfo::EKeywords, KNullDesC); |
|
165 CleanupStack::PopAndDestroy(objectP); |
|
166 __FLOG(_L8("<< CMTPPictBridgeDpGetObjectInfo::BuildObjectInfoL")); |
|
167 } |
|
168 |
|
169 |
|
170 /** |
|
171 Set file properties |
|
172 */ |
|
173 void CMTPPictBridgeDpGetObjectInfo::SetFileSizeDateL(const TDesC& aFileName, TBool aDiscoveryFile) |
|
174 { |
|
175 __FLOG_VA((_L16(">> CMTPPictBridgeDpGetObjectInfo::SetFileSizeDateL aDiscoveryFile %d %S"), aDiscoveryFile, &aFileName)); |
|
176 |
|
177 // open the file for retrieving information |
|
178 RFile file; |
|
179 TInt size(0); |
|
180 TTime modifiedTime=0; |
|
181 |
|
182 if (!aDiscoveryFile) |
|
183 { |
|
184 User::LeaveIfError(file.Open(iFramework.Fs(), aFileName, EFileShareReadersOnly)); |
|
185 CleanupClosePushL(file); |
|
186 |
|
187 //file size |
|
188 User::LeaveIfError(file.Size(size)); |
|
189 |
|
190 //file modified time |
|
191 User::LeaveIfError(file.Modified(modifiedTime)); |
|
192 } |
|
193 else |
|
194 { |
|
195 //file modified time |
|
196 modifiedTime.HomeTime(); |
|
197 } |
|
198 |
|
199 //file size |
|
200 TUint32 fileSize=size; |
|
201 iObjectInfoToBuildP->SetUint32L(CMTPTypeObjectInfo::EObjectCompressedSize, fileSize); |
|
202 __FLOG_VA((_L8(" file size %d"), fileSize)); |
|
203 |
|
204 //file modified time |
|
205 const TInt KTimeStringLen=0x0f;// YYYYMMDDThhmmss(.s), we exclude tenths of seconds and use length 15, (MTP 1.0 spec, section 3.2.5) |
|
206 TBuf<KTimeStringLen> modifiedTimeBuffer; |
|
207 _LIT(KTimeFormat,"%Y%M%DT%H%M%T%S"); |
|
208 modifiedTime.FormatL(modifiedTimeBuffer, KTimeFormat); |
|
209 |
|
210 CMTPTypeString* dateString = CMTPTypeString::NewLC(modifiedTimeBuffer); |
|
211 iObjectInfoToBuildP->SetStringL(CMTPTypeObjectInfo::EDateModified, dateString->StringChars()); |
|
212 //file creation time, set it as the same as modified time, as Symbian does not support this field |
|
213 iObjectInfoToBuildP->SetStringL(CMTPTypeObjectInfo::EDateCreated, dateString->StringChars()); |
|
214 CleanupStack::PopAndDestroy(dateString); |
|
215 |
|
216 if (!aDiscoveryFile) |
|
217 { |
|
218 CleanupStack::PopAndDestroy(&file); |
|
219 } |
|
220 |
|
221 __FLOG_VA((_L16("<< CMTPPictBridgeDpGetObjectInfo::SetFileSizeDateL %S"),&modifiedTimeBuffer)); |
|
222 } |
|
223 |