|
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 <mtp/tmtptyperequest.h> |
|
17 #include <mtp/mmtpdataproviderframework.h> |
|
18 #include <mtp/mmtpobjectmgr.h> |
|
19 #include <mtp/mmtpdataprovider.h> |
|
20 #include <mtp/cmtpdataproviderplugin.h> |
|
21 |
|
22 #include "cmtpdataprovidercontroller.h" |
|
23 #include "cmtpdataprovider.h" |
|
24 |
|
25 #include "cmtpgetnumobjects.h" |
|
26 #include "mtpdevicedpconst.h" |
|
27 #include "mtpdevdppanic.h" |
|
28 |
|
29 /** |
|
30 Verification data for GetNumObjects request |
|
31 */ |
|
32 const TMTPRequestElementInfo KMTPGetNumObjectsPolicy[] = |
|
33 { |
|
34 {TMTPTypeRequest::ERequestParameter1, EMTPElementTypeStorageId, EMTPElementAttrNone, 1, KMTPStorageAll, 0}, |
|
35 {TMTPTypeRequest::ERequestParameter2, EMTPElementTypeFormatCode, EMTPElementAttrNone, 1, 0, 0}, |
|
36 {TMTPTypeRequest::ERequestParameter3, EMTPElementTypeObjectHandle, EMTPElementAttrDir, 2, KMTPHandleAll, 0} |
|
37 }; |
|
38 |
|
39 /** |
|
40 Two-phase construction method |
|
41 @param aPlugin The data provider plugin |
|
42 @param aFramework The data provider framework |
|
43 @param aConnection The connection from which the request comes |
|
44 @return a pointer to the created request processor object |
|
45 */ |
|
46 MMTPRequestProcessor* CMTPGetNumObjects::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) |
|
47 { |
|
48 CMTPGetNumObjects* self = new (ELeave) CMTPGetNumObjects(aFramework, aConnection); |
|
49 CleanupStack::PushL(self); |
|
50 self->ConstructL(); |
|
51 CleanupStack::Pop(); |
|
52 return self; |
|
53 } |
|
54 |
|
55 /** |
|
56 Destructor |
|
57 */ |
|
58 CMTPGetNumObjects::~CMTPGetNumObjects() |
|
59 { |
|
60 iSingletons.Close(); |
|
61 } |
|
62 /** |
|
63 Standard c++ constructor |
|
64 */ |
|
65 CMTPGetNumObjects::CMTPGetNumObjects(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) : |
|
66 CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPGetNumObjectsPolicy)/sizeof(TMTPRequestElementInfo), KMTPGetNumObjectsPolicy) |
|
67 { |
|
68 |
|
69 } |
|
70 |
|
71 /** |
|
72 Second phase constructor. |
|
73 */ |
|
74 void CMTPGetNumObjects::ConstructL() |
|
75 { |
|
76 iSingletons.OpenL(); |
|
77 } |
|
78 |
|
79 TMTPResponseCode CMTPGetNumObjects::CheckRequestL() |
|
80 { |
|
81 TMTPResponseCode responseCode = CMTPRequestProcessor::CheckRequestL(); |
|
82 if(responseCode == EMTPRespCodeOK) |
|
83 { |
|
84 TUint32 formatCode = Request().Uint32(TMTPTypeRequest::ERequestParameter2); |
|
85 if(formatCode != 0 && !IsSupportedFormatL(formatCode)) |
|
86 { |
|
87 responseCode = EMTPRespCodeInvalidObjectFormatCode; |
|
88 } |
|
89 } |
|
90 return responseCode; |
|
91 } |
|
92 |
|
93 |
|
94 /** |
|
95 GetNumObjects request handler |
|
96 */ |
|
97 void CMTPGetNumObjects::ServiceL() |
|
98 { |
|
99 TMTPObjectMgrQueryParams params(Request().Uint32(TMTPTypeRequest::ERequestParameter1), Request().Uint32(TMTPTypeRequest::ERequestParameter2), Request().Uint32(TMTPTypeRequest::ERequestParameter3)); |
|
100 TUint32 count = iFramework.ObjectMgr().CountL(params); |
|
101 SendResponseL(EMTPRespCodeOK, 1, &count); |
|
102 } |
|
103 |
|
104 /** |
|
105 Check if the format code is supported by the current installed data providers |
|
106 */ |
|
107 TBool CMTPGetNumObjects::IsSupportedFormatL(TUint32 aFormatCode) |
|
108 { |
|
109 TBool supported(EFalse); |
|
110 |
|
111 CMTPDataProviderController& dps(iSingletons.DpController()); |
|
112 const TInt count(dps.Count()); |
|
113 for (TInt i(0); ((i < count) && (!supported)); i++) |
|
114 { |
|
115 CMTPDataProvider& dp = dps.DataProviderByIndexL(i); |
|
116 if (dp.DataProviderId() != dps.ProxyDpId()) |
|
117 { |
|
118 supported = ( |
|
119 dp.Supported(EObjectCaptureFormats, aFormatCode) || |
|
120 dp.Supported(EObjectPlaybackFormats, aFormatCode)); |
|
121 } |
|
122 } |
|
123 return supported; |
|
124 } |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |