|
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 |
|
23 #include <mtp/tmtptyperequest.h> |
|
24 #include <mtp/mmtpdataproviderframework.h> |
|
25 #include <mtp/mtpprotocolconstants.h> |
|
26 #include <mtp/mmtpobjectmgr.h> |
|
27 #include <mtp/cmtpobjectmetadata.h> |
|
28 #include <mtp/cmtptypefile.h> |
|
29 |
|
30 #include "cmtpimagedpgetpartialobject.h" |
|
31 #include "mtpimagedppanic.h" |
|
32 #include "mtpimagedpconst.h" |
|
33 #include "cmtpimagedp.h" |
|
34 #include "mtpimagedputilits.h" |
|
35 #include "cmtpimagedpobjectpropertymgr.h" |
|
36 |
|
37 __FLOG_STMT(_LIT8(KComponent,"ImageDpGetPartialObject");) |
|
38 /** |
|
39 Verification data for the GetPartialObject request |
|
40 */ |
|
41 |
|
42 /** |
|
43 Two-phase construction method |
|
44 @param aFramework The data provider framework |
|
45 @param aConnection The connection from which the request comes |
|
46 @return a pointer to the created request processor object |
|
47 */ |
|
48 MMTPRequestProcessor* CMTPImageDpGetPartialObject::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection,CMTPImageDataProvider& aDataProvider) |
|
49 { |
|
50 CMTPImageDpGetPartialObject* self = new (ELeave) CMTPImageDpGetPartialObject(aFramework, aConnection, aDataProvider); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL(); |
|
53 CleanupStack::Pop(self); |
|
54 return self; |
|
55 } |
|
56 |
|
57 /** |
|
58 Destructor |
|
59 */ |
|
60 CMTPImageDpGetPartialObject::~CMTPImageDpGetPartialObject() |
|
61 { |
|
62 __FLOG(_L8(">> CMTPImageDpGetPartialObject::~CMTPImageDpGetPartialObject")); |
|
63 delete iFileObject; |
|
64 delete iObjectMeta; |
|
65 __FLOG(_L8("<< CMTPImageDpGetPartialObject::~CMTPImageDpGetPartialObject")); |
|
66 __FLOG_CLOSE; |
|
67 } |
|
68 |
|
69 /** |
|
70 Standard c++ constructor |
|
71 @param aFramework The data provider framework |
|
72 @param aConnection The connection from which the request comes |
|
73 */ |
|
74 CMTPImageDpGetPartialObject::CMTPImageDpGetPartialObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection, CMTPImageDataProvider& /*aDataProvider*/) |
|
75 :CMTPRequestProcessor(aFramework, aConnection, 0, NULL), |
|
76 iFs(iFramework.Fs()) |
|
77 { |
|
78 } |
|
79 |
|
80 /** |
|
81 Second-phase construction |
|
82 */ |
|
83 void CMTPImageDpGetPartialObject::ConstructL() |
|
84 { |
|
85 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
86 __FLOG(_L8(">> CMTPImageDpGetPartialObject::ConstructL")); |
|
87 iObjectMeta = CMTPObjectMetaData::NewL(); |
|
88 __FLOG(_L8("<< CMTPImageDpGetPartialObject::ConstructL")); |
|
89 } |
|
90 |
|
91 /** |
|
92 Check the GetPartialObject reqeust |
|
93 @return EMTPRespCodeOK if the request is good, otherwise, one of the error response codes |
|
94 */ |
|
95 TMTPResponseCode CMTPImageDpGetPartialObject::CheckRequestL() |
|
96 { |
|
97 __FLOG(_L8(">> CMTPImageDpGetPartialObject::CheckRequestL")); |
|
98 TMTPResponseCode result = CMTPRequestProcessor::CheckRequestL(); |
|
99 if(result == EMTPRespCodeOK) |
|
100 { |
|
101 result = MTPImageDpUtilits::VerifyObjectHandleL(iFramework, Request().Uint32(TMTPTypeRequest::ERequestParameter1), *iObjectMeta); |
|
102 } |
|
103 if(result == EMTPRespCodeOK && !VerifyParametersL()) |
|
104 { |
|
105 result = EMTPRespCodeInvalidParameter; |
|
106 } |
|
107 __FLOG_VA((_L8("<< CMTPImageDpGetPartialObject::CheckRequestL 0x%x"), result)); |
|
108 __FLOG(_L8("<< CMTPImageDpGetPartialObject::CheckRequestL")); |
|
109 return result; |
|
110 } |
|
111 |
|
112 /** |
|
113 Verify if the parameter of the request (i.e. offset) is good. |
|
114 @return ETrue if the parameter is good, otherwise, EFalse |
|
115 */ |
|
116 TBool CMTPImageDpGetPartialObject::VerifyParametersL() |
|
117 { |
|
118 __FLOG(_L8(">> CMTPImageDpGetPartialObject::VerifyParametersL")); |
|
119 TBool result = EFalse; |
|
120 iOffset = Request().Uint32(TMTPTypeRequest::ERequestParameter2); |
|
121 iMaxLength = Request().Uint32(TMTPTypeRequest::ERequestParameter3); |
|
122 |
|
123 TEntry fileEntry; |
|
124 User::LeaveIfError(iFs.Entry(iObjectMeta->DesC(CMTPObjectMetaData::ESuid), fileEntry)); |
|
125 if((iOffset < fileEntry.iSize)) |
|
126 { |
|
127 result = ETrue; |
|
128 } |
|
129 __FLOG_VA((_L8("<< CMTPImageDpGetPartialObject::VerifyParametersL %d"), result)); |
|
130 return result; |
|
131 } |
|
132 /** |
|
133 GetPartialObject request handler |
|
134 Send the partial object data to the initiator |
|
135 */ |
|
136 void CMTPImageDpGetPartialObject::ServiceL() |
|
137 { |
|
138 // Get file information |
|
139 __FLOG(_L8(">> CMTPImageDpGetPartialObject::ServiceL")); |
|
140 // Pass the complete file back to the host |
|
141 iFileObject = CMTPTypeFile::NewL(iFramework.Fs(), iObjectMeta->DesC(CMTPObjectMetaData::ESuid), (TFileMode)(EFileRead | EFileShareReadersOnly), iMaxLength, iOffset); |
|
142 SendDataL(*iFileObject); |
|
143 __FLOG(_L8("<< CMTPImageDpGetPartialObject::ServiceL")); |
|
144 } |
|
145 |
|
146 |
|
147 /** |
|
148 Signal to the initiator how much data has been sent |
|
149 @return EFalse |
|
150 */ |
|
151 TBool CMTPImageDpGetPartialObject::DoHandleResponsePhaseL() |
|
152 { |
|
153 __FLOG(_L8(">> CMTPImageDpGetPartialObject::DoHandleResponsePhaseL")); |
|
154 TUint32 dataLength = iFileObject->GetByteSent(); |
|
155 SendResponseL(EMTPRespCodeOK, 1, &dataLength); |
|
156 __FLOG(_L8("<< CMTPImageDpGetPartialObject::DoHandleResponsePhaseL")); |
|
157 return EFalse; |
|
158 } |