|
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 <f32file.h> |
|
17 |
|
18 #include <mtp/cmtptypefile.h> |
|
19 #include <mtp/cmtpobjectmetadata.h> |
|
20 #include <mtp/mmtpdataproviderframework.h> |
|
21 #include <mtp/mmtpobjectmgr.h> |
|
22 #include <mtp/mmtpstoragemgr.h> |
|
23 #include <mtp/mtpprotocolconstants.h> |
|
24 #include <mtp/tmtptyperequest.h> |
|
25 |
|
26 #include "cmtpgetobject.h" |
|
27 #include "mtpdppanic.h" |
|
28 |
|
29 // Class constants. |
|
30 __FLOG_STMT(_LIT8(KComponent,"GetObject");) |
|
31 |
|
32 /** |
|
33 Verification data for the GetNumObjects request |
|
34 */ |
|
35 const TMTPRequestElementInfo KMTPGetObjectPolicy[] = |
|
36 { |
|
37 {TMTPTypeRequest::ERequestParameter1, EMTPElementTypeObjectHandle, EMTPElementAttrFile, 0, 0, 0} |
|
38 }; |
|
39 |
|
40 /** |
|
41 Two-phase construction method |
|
42 @param aPlugin The data provider plugin |
|
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 EXPORT_C MMTPRequestProcessor* CMTPGetObject::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) |
|
48 { |
|
49 CMTPGetObject* self = new (ELeave) CMTPGetObject(aFramework, aConnection); |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL(); |
|
52 CleanupStack::Pop(self); |
|
53 return self; |
|
54 } |
|
55 |
|
56 /** |
|
57 Destructor |
|
58 */ |
|
59 EXPORT_C CMTPGetObject::~CMTPGetObject() |
|
60 { |
|
61 __FLOG(_L8("~CMTPGetObject - Entry")); |
|
62 delete iFileObject; |
|
63 __FLOG(_L8("~CMTPGetObject - Exit")); |
|
64 __FLOG_CLOSE; |
|
65 } |
|
66 |
|
67 /** |
|
68 Standard c++ constructor |
|
69 */ |
|
70 CMTPGetObject::CMTPGetObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) : |
|
71 CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPGetObjectPolicy)/sizeof(TMTPRequestElementInfo), KMTPGetObjectPolicy), |
|
72 iError(EMTPRespCodeOK) |
|
73 { |
|
74 |
|
75 } |
|
76 |
|
77 /** |
|
78 Second-phase constructor. |
|
79 */ |
|
80 void CMTPGetObject::ConstructL() |
|
81 { |
|
82 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
83 __FLOG(_L8("ConstructL - Entry")); |
|
84 __FLOG(_L8("ConstructL - Exit")); |
|
85 } |
|
86 |
|
87 /** |
|
88 GetObject request handler |
|
89 */ |
|
90 void CMTPGetObject::ServiceL() |
|
91 { |
|
92 __FLOG(_L8("ServiceL - Entry")); |
|
93 __ASSERT_DEBUG(iRequestChecker, Panic(EMTPDpRequestCheckNull)); |
|
94 TUint32 objectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
|
95 //does not take ownership |
|
96 CMTPObjectMetaData* objectInfo = iRequestChecker->GetObjectInfo(objectHandle); |
|
97 if (!objectInfo) |
|
98 { |
|
99 // The object handle has already been checked, so an invalid handle can |
|
100 // only occur if it was invalidated during a context switch between |
|
101 // the validation time and now. |
|
102 iError = EMTPRespCodeInvalidObjectHandle; |
|
103 } |
|
104 else if ( objectInfo->Uint(CMTPObjectMetaData::EFormatCode)==EMTPFormatCodeAssociation |
|
105 && objectInfo->Uint(CMTPObjectMetaData::EFormatSubCode)==EMTPAssociationTypeGenericFolder) |
|
106 { |
|
107 iError = EMTPRespCodeInvalidObjectHandle; |
|
108 } |
|
109 else |
|
110 { |
|
111 BuildFileObjectL(objectInfo->DesC(CMTPObjectMetaData::ESuid)); |
|
112 SendDataL(*iFileObject); |
|
113 } |
|
114 __FLOG(_L8("ServiceL - Exit")); |
|
115 } |
|
116 |
|
117 |
|
118 /** |
|
119 Build the file object data set for the file requested |
|
120 @param aFileName The file name of the requested object |
|
121 */ |
|
122 void CMTPGetObject::BuildFileObjectL(const TDesC& aFileName) |
|
123 { |
|
124 __FLOG(_L8("BuildFileObjectL - Entry")); |
|
125 delete iFileObject; |
|
126 iFileObject = NULL; |
|
127 iFileObject = CMTPTypeFile::NewL(iFramework.Fs(), aFileName, EFileRead); |
|
128 __FLOG(_L8("BuildFileObjectL - Exit")); |
|
129 } |
|
130 |
|
131 |
|
132 /** |
|
133 Handle the response phase of the current request |
|
134 @return EFalse |
|
135 */ |
|
136 TBool CMTPGetObject::DoHandleResponsePhaseL() |
|
137 { |
|
138 __FLOG(_L8("DoHandleResponsePhaseL - Entry")); |
|
139 TMTPResponseCode responseCode = (iCancelled ? EMTPRespCodeIncompleteTransfer : iError); |
|
140 SendResponseL(responseCode); |
|
141 __FLOG(_L8("DoHandleResponsePhaseL - Exit")); |
|
142 return EFalse; |
|
143 } |