|
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 #include <mtp/cmtptypearray.h> |
|
17 #include <mtp/mmtpdataproviderframework.h> |
|
18 #include <mtp/tmtptyperequest.h> |
|
19 #include <mtp/cmtpobjectmetadata.h> |
|
20 #include <mtp/mmtpreferencemgr.h> |
|
21 #include <mtp/mmtpobjectmgr.h> |
|
22 |
|
23 #include "cmtpimagedpsetobjectreferences.h" |
|
24 #include "mtpimagedputilits.h" |
|
25 #include "cmtpimagedp.h" |
|
26 |
|
27 __FLOG_STMT(_LIT8(KComponent,"SetObjectReferences");) |
|
28 |
|
29 /** |
|
30 Two-phase construction method |
|
31 @param aPlugin The data provider plugin |
|
32 @param aFramework The data provider framework |
|
33 @param aConnection The connection from which the request comes |
|
34 @return a pointer to the created request processor object |
|
35 */ |
|
36 MMTPRequestProcessor* CMTPImageDpSetObjectReferences::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection, CMTPImageDataProvider& /*aDataProvider*/) |
|
37 { |
|
38 CMTPImageDpSetObjectReferences* self = new (ELeave) CMTPImageDpSetObjectReferences(aFramework, aConnection); |
|
39 CleanupStack::PushL(self); |
|
40 self->ConstructL(); |
|
41 CleanupStack::Pop(self); |
|
42 return self; |
|
43 } |
|
44 |
|
45 /** |
|
46 Destructor |
|
47 */ |
|
48 CMTPImageDpSetObjectReferences::~CMTPImageDpSetObjectReferences() |
|
49 { |
|
50 __FLOG(_L8(">> CMTPImageDpSetObjectReferences::~CMTPImageDpSetObjectReferences")); |
|
51 delete iReferences; |
|
52 __FLOG(_L8("<< CMTPImageDpSetObjectReferences::~CMTPImageDpSetObjectReferences")); |
|
53 __FLOG_CLOSE; |
|
54 } |
|
55 |
|
56 /** |
|
57 Standard c++ constructor |
|
58 */ |
|
59 CMTPImageDpSetObjectReferences::CMTPImageDpSetObjectReferences(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) |
|
60 :CMTPRequestProcessor(aFramework, aConnection, 0, NULL) |
|
61 { |
|
62 } |
|
63 |
|
64 /** |
|
65 Second phase constructor |
|
66 */ |
|
67 void CMTPImageDpSetObjectReferences::ConstructL() |
|
68 { |
|
69 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
70 __FLOG(_L8(">> CMTPImageDpSetObjectReferences::ConstructL")); |
|
71 __FLOG(_L8("<< CMTPImageDpSetObjectReferences::ConstructL")); |
|
72 } |
|
73 |
|
74 TMTPResponseCode CMTPImageDpSetObjectReferences::CheckRequestL() |
|
75 { |
|
76 __FLOG(_L8(">> CMTPImageDpSetObjectReferences::CheckRequestL")); |
|
77 |
|
78 TUint32 objectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
|
79 CMTPObjectMetaData* objectInfo = CMTPObjectMetaData::NewLC(); |
|
80 TMTPResponseCode responseCode = MTPImageDpUtilits::VerifyObjectHandleL(iFramework, objectHandle, *objectInfo); |
|
81 CleanupStack::PopAndDestroy(objectInfo); |
|
82 __FLOG_VA((_L8("CheckRequestL - Exit with responseCode = 0x%04X"), responseCode)); |
|
83 __FLOG(_L8("<< CMTPImageDpSetObjectReferences::CheckRequestL")); |
|
84 return responseCode; |
|
85 } |
|
86 |
|
87 |
|
88 /** |
|
89 Apply the references to the specified object |
|
90 @return EFalse |
|
91 */ |
|
92 TBool CMTPImageDpSetObjectReferences::DoHandleResponsePhaseL() |
|
93 { |
|
94 if(!VerifyReferenceHandlesL()) |
|
95 { |
|
96 SendResponseL(EMTPRespCodeInvalidObjectReference); |
|
97 } |
|
98 else |
|
99 { |
|
100 MMTPReferenceMgr& referenceMgr = iFramework.ReferenceMgr(); |
|
101 TUint32 objectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
|
102 referenceMgr.SetReferencesL(TMTPTypeUint32(objectHandle), *iReferences); |
|
103 SendResponseL(EMTPRespCodeOK); |
|
104 } |
|
105 return EFalse; |
|
106 } |
|
107 |
|
108 /** |
|
109 GetReferences request handler |
|
110 */ |
|
111 void CMTPImageDpSetObjectReferences::ServiceL() |
|
112 { |
|
113 __FLOG(_L8(">> CMTPImageDpCopyObject::ServiceL")); |
|
114 delete iReferences; |
|
115 iReferences = NULL; |
|
116 iReferences = CMTPTypeArray::NewL(EMTPTypeAUINT32); |
|
117 ReceiveDataL(*iReferences); |
|
118 __FLOG(_L8("<< CMTPImageDpCopyObject::ServiceL")); |
|
119 } |
|
120 |
|
121 TBool CMTPImageDpSetObjectReferences::HasDataphase() const |
|
122 { |
|
123 return ETrue; |
|
124 } |
|
125 |
|
126 /** |
|
127 Verify if the references are valid handles to objects |
|
128 @return ETrue if all the references are good, otherwise, EFalse |
|
129 */ |
|
130 TBool CMTPImageDpSetObjectReferences::VerifyReferenceHandlesL() const |
|
131 { |
|
132 __ASSERT_DEBUG(iReferences, User::Invariant()); |
|
133 TBool result = ETrue; |
|
134 TInt count = iReferences->NumElements(); |
|
135 CMTPObjectMetaData* object(CMTPObjectMetaData::NewLC()); |
|
136 MMTPObjectMgr& objectMgr = iFramework.ObjectMgr(); |
|
137 TMTPTypeUint32 handle; |
|
138 for(TInt i = 0; i < count; i++) |
|
139 { |
|
140 iReferences->ElementL(i, handle); |
|
141 if(!objectMgr.ObjectL(handle, *object)) |
|
142 { |
|
143 result = EFalse; |
|
144 break; |
|
145 } |
|
146 } |
|
147 CleanupStack::PopAndDestroy(object); |
|
148 return result; |
|
149 } |
|
150 |
|
151 |