|
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 /** |
|
17 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #include <mtp/mtpdatatypeconstants.h> |
|
22 #include <mtp/mtpprotocolconstants.h> |
|
23 |
|
24 #include "mtpusbdatatypeconstants.h" |
|
25 #include "tmtpusbparameterpayloadblock.h" |
|
26 |
|
27 // Dataset element metadata. |
|
28 const TMTPUsbParameterPayloadBlock::TElementInfo TMTPUsbParameterPayloadBlock::iElementMetaData[ENumElements] = |
|
29 { |
|
30 {EMTPTypeUINT32, 0, KMTPTypeUINT32Size}, // EParameter1 |
|
31 {EMTPTypeUINT32, 4, KMTPTypeUINT32Size}, // EParameter2 |
|
32 {EMTPTypeUINT32, 8, KMTPTypeUINT32Size}, // EParameter3 |
|
33 {EMTPTypeUINT32, 12, KMTPTypeUINT32Size}, // EParameter4 |
|
34 {EMTPTypeUINT32, 16, KMTPTypeUINT32Size}, // EParameter5 |
|
35 }; |
|
36 |
|
37 /** |
|
38 Constructor. |
|
39 */ |
|
40 EXPORT_C TMTPUsbParameterPayloadBlock::TMTPUsbParameterPayloadBlock() : |
|
41 iElementInfo(iElementMetaData, ENumElements), |
|
42 iBuffer(KMaxSize), |
|
43 iNumParameters(0) |
|
44 { |
|
45 SetBuffer(iBuffer); |
|
46 } |
|
47 |
|
48 /** |
|
49 Provides the number of parameters in the block which are set. |
|
50 @return the number of set parameters. |
|
51 */ |
|
52 EXPORT_C TUint TMTPUsbParameterPayloadBlock::NumParameters() const |
|
53 { |
|
54 return iNumParameters; |
|
55 } |
|
56 |
|
57 /** |
|
58 Copies up to five parameter values into the parameter block dataset |
|
59 from the specified dataset. The paramters to be copied should be non null paramter or valid null paramter. |
|
60 @param aFrom The parameter values source dataset. This dataset should define three or five contiguous 32-bit parameter values starting at the specified offset. |
|
61 @param aParamStartOffset The element ID of the first in the set of contiguous |
|
62 source dataset parameter values. |
|
63 @param aParamEndOffset The element ID of the last in the set of contiguous |
|
64 source dataset parameter values. |
|
65 @param aIsNullParamValid a boolean value to check if a null parameter is valid. A value of ETrue means a null parameter is valid; EFalse means invalid. |
|
66 @param aNumOfNullParam the number of valid null parameters to be copied. |
|
67 */ |
|
68 EXPORT_C void TMTPUsbParameterPayloadBlock::CopyIn(const TMTPTypeFlatBase& aFrom, TUint aParamStartOffset, TUint aParamEndOffset, TBool aIsNullParamValid, TUint aNumOfNullParam) |
|
69 { |
|
70 __ASSERT_DEBUG((aParamEndOffset >= aParamStartOffset && (aParamEndOffset - aParamStartOffset + 1) <= ENumElements), User::Invariant()); |
|
71 TUint32 parameter = KMTPNotSpecified32; |
|
72 TUint numberOfNullParam = 0; |
|
73 TUint loopCount = aParamEndOffset - aParamStartOffset; |
|
74 |
|
75 for (TUint i(TMTPUsbParameterPayloadBlock::EParameter1); i <= loopCount; i++) |
|
76 { |
|
77 parameter = aFrom.Uint32(aParamStartOffset + i); |
|
78 if (parameter != KMTPNotSpecified32) |
|
79 { |
|
80 SetUint32(i, parameter); |
|
81 } |
|
82 else if(aIsNullParamValid && (numberOfNullParam < aNumOfNullParam)) |
|
83 { |
|
84 SetUint32(i, parameter); |
|
85 numberOfNullParam++; |
|
86 } |
|
87 } |
|
88 } |
|
89 |
|
90 /** |
|
91 Copies the non-null parameter values from the parameter block dataset into the |
|
92 specified dataset. Note: the number of parameters to be copied out depends on two conditions: |
|
93 1. The number of parameters contained in this USB parameter block dataset. |
|
94 2. The number of parameters to be copied out to the parameter values sink dataset, which is (aParamEndOffset - aParamStartOffset + 1) by the caller. |
|
95 @param aTo The parameter values sink dataset. This dataset should define three or five contiguous 32-bit parameter values starting at the specified offset. |
|
96 @param aParamStartOffset the element ID of the first in the set of contiguous sink dataset parameter values. |
|
97 @param aParamEndOffset the element ID of the last in the set of contiguous sink dataset parameter values. |
|
98 */ |
|
99 EXPORT_C void TMTPUsbParameterPayloadBlock::CopyOut(TMTPTypeFlatBase& aTo, TUint aParamStartOffset, TUint aParamEndOffset) |
|
100 { |
|
101 __ASSERT_DEBUG((aParamEndOffset >= aParamStartOffset && (aParamEndOffset - aParamStartOffset + 1) <= ENumElements), User::Invariant()); |
|
102 TUint loopCount = aParamEndOffset - aParamStartOffset; |
|
103 for (TUint i(TMTPUsbParameterPayloadBlock::EParameter1); (i < iNumParameters && i <= loopCount); i++) |
|
104 { |
|
105 aTo.SetUint32((aParamStartOffset + i), Uint32(i)); |
|
106 } |
|
107 } |
|
108 |
|
109 /** |
|
110 Resets the dataset. |
|
111 */ |
|
112 EXPORT_C void TMTPUsbParameterPayloadBlock::Reset() |
|
113 { |
|
114 TMTPTypeFlatBase::Reset(); |
|
115 iNumParameters = 0; |
|
116 } |
|
117 |
|
118 EXPORT_C void TMTPUsbParameterPayloadBlock::SetUint32(TInt aElementId, TUint32 aData) |
|
119 { |
|
120 // Recalculate iNumParameters. |
|
121 TUint num((aElementId - EParameter1) + 1); |
|
122 |
|
123 if (num > iNumParameters) |
|
124 { |
|
125 iNumParameters = num; |
|
126 } |
|
127 |
|
128 // Set the element value. |
|
129 TMTPTypeFlatBase::SetUint32(aElementId, aData); |
|
130 |
|
131 } |
|
132 |
|
133 EXPORT_C TUint32 TMTPUsbParameterPayloadBlock::Uint32(TInt aElementId) const |
|
134 { |
|
135 __ASSERT_DEBUG((aElementId < iNumParameters), User::Invariant()); |
|
136 return TMTPTypeFlatBase::Uint32(aElementId); |
|
137 } |
|
138 |
|
139 EXPORT_C TInt TMTPUsbParameterPayloadBlock::FirstReadChunk(TPtrC8& aChunk) const |
|
140 { |
|
141 TInt ret(TMTPTypeFlatBase::FirstReadChunk(aChunk)); |
|
142 TUint64 size(Size()); |
|
143 |
|
144 if (size < aChunk.Size()) |
|
145 { |
|
146 // Truncate the buffer at the last set parameter. |
|
147 aChunk.Set(aChunk.Left(size)); |
|
148 } |
|
149 |
|
150 return ret; |
|
151 } |
|
152 |
|
153 EXPORT_C TUint64 TMTPUsbParameterPayloadBlock::Size() const |
|
154 { |
|
155 return (iNumParameters * KMTPTypeUINT32Size); |
|
156 } |
|
157 |
|
158 EXPORT_C TUint TMTPUsbParameterPayloadBlock::Type() const |
|
159 { |
|
160 return EMTPUsbTypeParameterPayloadBlock; |
|
161 } |
|
162 |
|
163 EXPORT_C TBool TMTPUsbParameterPayloadBlock::CommitRequired() const |
|
164 { |
|
165 return ETrue; |
|
166 } |
|
167 |
|
168 EXPORT_C MMTPType* TMTPUsbParameterPayloadBlock::CommitChunkL(TPtr8& /*aChunk*/) |
|
169 { |
|
170 iNumParameters = 0; |
|
171 |
|
172 // Recalculate iNumParameters. |
|
173 for (TUint i(EParameter1); (i <= EParameter5); i++) |
|
174 { |
|
175 if (TMTPTypeFlatBase::Uint32(i) != KMTPNotSpecified32) |
|
176 { |
|
177 iNumParameters = (i + 1); |
|
178 } |
|
179 } |
|
180 return NULL; |
|
181 } |
|
182 |
|
183 EXPORT_C const TMTPTypeFlatBase::TElementInfo& TMTPUsbParameterPayloadBlock::ElementInfo(TInt aElementId) const |
|
184 { |
|
185 __ASSERT_DEBUG((aElementId < ENumElements), User::Invariant()); |
|
186 return iElementInfo[aElementId]; |
|
187 } |
|
188 |