|
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 |
|
19 #include <mtp/cmtptypefile.h> |
|
20 #include <mtp/cmtpobjectmetadata.h> |
|
21 #include <mtp/mmtpdataproviderframework.h> |
|
22 #include <mtp/mmtpobjectmgr.h> |
|
23 #include <mtp/mmtpstoragemgr.h> |
|
24 #include <mtp/mtpprotocolconstants.h> |
|
25 #include <mtp/tmtptyperequest.h> |
|
26 #include "cmtppictbridgedpgetobject.h" |
|
27 #include "cmtppictbridgeprinter.h" |
|
28 #include "mtppictbridgedppanic.h" |
|
29 #include "cmtprequestchecker.h" |
|
30 #include "cptpserver.h" |
|
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 // |
|
42 //============================================================================= |
|
43 MMTPRequestProcessor* CMTPPictBridgeDpGetObject::NewL( |
|
44 MMTPDataProviderFramework& aFramework, |
|
45 MMTPConnection& aConnection, |
|
46 CMTPPictBridgeDataProvider& aDataProvider) |
|
47 { |
|
48 CMTPPictBridgeDpGetObject* self = new (ELeave) CMTPPictBridgeDpGetObject(aFramework, aConnection, aDataProvider); |
|
49 CleanupStack::PushL(self); |
|
50 self->ConstructL(); |
|
51 CleanupStack::Pop(self); |
|
52 return self; |
|
53 } |
|
54 |
|
55 /** |
|
56 Destructor |
|
57 */ |
|
58 CMTPPictBridgeDpGetObject::~CMTPPictBridgeDpGetObject() |
|
59 { |
|
60 __FLOG(_L8("~CMTPPictBridgeDpGetObject")); |
|
61 delete iFileObject; |
|
62 __FLOG_CLOSE; |
|
63 } |
|
64 |
|
65 /** |
|
66 Standard c++ constructor |
|
67 */ |
|
68 CMTPPictBridgeDpGetObject::CMTPPictBridgeDpGetObject( |
|
69 MMTPDataProviderFramework& aFramework, |
|
70 MMTPConnection& aConnection, |
|
71 CMTPPictBridgeDataProvider& aDataProvider): |
|
72 CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPGetObjectPolicy)/sizeof(TMTPRequestElementInfo), KMTPGetObjectPolicy), |
|
73 iPictBridgeDP(aDataProvider), |
|
74 iError(EMTPRespCodeOK) |
|
75 { |
|
76 } |
|
77 |
|
78 /** |
|
79 Second-phase constructor. |
|
80 */ |
|
81 void CMTPPictBridgeDpGetObject::ConstructL() |
|
82 { |
|
83 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
84 } |
|
85 |
|
86 /** |
|
87 GetObject request handler |
|
88 */ |
|
89 void CMTPPictBridgeDpGetObject::ServiceL() |
|
90 { |
|
91 __FLOG(_L8(">> CMTPPictBridgeDpGetObject::ServiceL")); |
|
92 __ASSERT_DEBUG(iRequestChecker, Panic(EMTPPictBridgeDpRequestCheckNull)); |
|
93 TUint32 objectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
|
94 //does not take ownership |
|
95 CMTPObjectMetaData* objectInfo = iRequestChecker->GetObjectInfo(objectHandle); |
|
96 if (!objectInfo) |
|
97 { |
|
98 __FLOG_VA((_L8(">> CMTPPictBridgeDpGetObject::ServiceL no object info for objectHandle %d"), objectHandle)); |
|
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 iPictBridgeDP.PtpServer()->Printer()->DpsFileSent(KErrBadHandle); |
|
104 } |
|
105 else |
|
106 { |
|
107 BuildFileObjectL(objectInfo->DesC(CMTPObjectMetaData::ESuid)); |
|
108 SendDataL(*iFileObject); |
|
109 iPictBridgeDP.PtpServer()->Printer()->DpsFileSent(KErrNone); |
|
110 } |
|
111 __FLOG(_L8("<< CMTPPictBridgeDpGetObject::ServiceL")); |
|
112 } |
|
113 |
|
114 //============================================================================= |
|
115 // |
|
116 //============================================================================= |
|
117 void CMTPPictBridgeDpGetObject::BuildFileObjectL(const TDesC& aFileName) |
|
118 { |
|
119 __FLOG(_L8(">> CMTPPictBridgeDpGetObject::BuildFileObjectL")); |
|
120 delete iFileObject; |
|
121 iFileObject = NULL; |
|
122 iFileObject = CMTPTypeFile::NewL(iFramework.Fs(), aFileName, EFileRead); |
|
123 __FLOG(_L8("<< CMTPPictBridgeDpGetObject::BuildFileObjectL")); |
|
124 } |
|
125 |
|
126 |
|
127 //============================================================================= |
|
128 // |
|
129 //============================================================================= |
|
130 TBool CMTPPictBridgeDpGetObject::DoHandleResponsePhaseL() |
|
131 { |
|
132 __FLOG(_L8(">> CMTPPictBridgeDpGetObject::DoHandleResponsePhaseL")); |
|
133 TMTPResponseCode responseCode = (iCancelled ? EMTPRespCodeIncompleteTransfer : iError); |
|
134 SendResponseL(responseCode); |
|
135 __FLOG(_L8("<< CMTPPictBridgeDpGetObject::DoHandleResponsePhaseL")); |
|
136 return EFalse; |
|
137 } |
|
138 |