|
1 // Copyright (c) 2008-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 @internalComponent |
|
18 */ |
|
19 |
|
20 #include <mtp/mtpprotocolconstants.h> |
|
21 #include "ptpipdatatypes.h" |
|
22 #include "tptpiprequestpayload.h" |
|
23 |
|
24 // Dataset element metadata. |
|
25 const TPTPIPTypeRequestPayload::TElementInfo |
|
26 TPTPIPTypeRequestPayload::iElementMetaData[ENumElements] = |
|
27 { |
|
28 {EMTPTypeUINT32, 0, KMTPTypeUINT32Size }, // EDataPhase |
|
29 {EMTPTypeUINT16, 4, KMTPTypeUINT16Size }, // EOpCode |
|
30 {EMTPTypeUINT32, 6, KMTPTypeUINT32Size }, // ETransactionId |
|
31 {EMTPTypeUINT32, 10, KMTPTypeUINT32Size }, // EParameter1 |
|
32 {EMTPTypeUINT32, 14, KMTPTypeUINT32Size }, // EParameter2 |
|
33 {EMTPTypeUINT32, 18, KMTPTypeUINT32Size }, // EParameter3 |
|
34 {EMTPTypeUINT32, 22, KMTPTypeUINT32Size }, // EParameter4 |
|
35 {EMTPTypeUINT32, 26, KMTPTypeUINT32Size } // EParameter5 |
|
36 }; |
|
37 |
|
38 /** |
|
39 Constructor. |
|
40 */ |
|
41 EXPORT_C TPTPIPTypeRequestPayload::TPTPIPTypeRequestPayload( ) : |
|
42 iElementInfo(iElementMetaData, ENumElements), |
|
43 iBuffer(KSize), |
|
44 //iNumParameters(0) |
|
45 iMaxSetParam(0) |
|
46 { |
|
47 SetBuffer (iBuffer ); |
|
48 } |
|
49 |
|
50 /** |
|
51 Provides the number of parameters in the block which are set. |
|
52 @return the number of set parameters. |
|
53 */ |
|
54 EXPORT_C TUint TPTPIPTypeRequestPayload::NumParameters() const |
|
55 { |
|
56 //return iNumParameters; |
|
57 //return (iMaxSetParam - EParameter1 + 1); |
|
58 return (iMaxSetParam > 0 )? (iMaxSetParam - EParameter1 + 1) : 0; |
|
59 } |
|
60 |
|
61 /** |
|
62 Copies up to five parameter values into the parameter block dataset from the specified dataset. |
|
63 The paramters to be copied should be non null paramter or valid null paramter. |
|
64 |
|
65 @param aFrom The parameter values source dataset. This dataset should define three or five contiguous 32-bit parameter values starting at the specified offset. |
|
66 @param aParamStartOffset The element ID of the first in the set of contiguous |
|
67 source dataset parameter values. |
|
68 @param aParamEndOffset The element ID of the last in the set of contiguous |
|
69 source dataset parameter values. |
|
70 @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. |
|
71 @param aNumOfNullParam the number of valid null parameters to be copied. |
|
72 */ |
|
73 EXPORT_C void TPTPIPTypeRequestPayload::CopyIn( const TMTPTypeFlatBase& aFrom, |
|
74 TUint aParamStartOffset, TUint aParamEndOffset, |
|
75 TBool aIsNullParamValid, TUint aNumOfNullParam ) |
|
76 |
|
77 { |
|
78 __ASSERT_DEBUG((aParamEndOffset >= aParamStartOffset && (aParamEndOffset - aParamStartOffset + 1) <= ENumElements), User::Invariant()); |
|
79 TUint32 parameter = 0; |
|
80 TUint numberOfNullParam = 0; |
|
81 |
|
82 for (TUint t(EParameter1), s(aParamStartOffset); s <= aParamEndOffset; t++, s++) |
|
83 { |
|
84 parameter = aFrom.Uint32(s); |
|
85 if (parameter != KMTPNotSpecified32) |
|
86 { |
|
87 SetUint32(t, parameter); |
|
88 } |
|
89 else if(aIsNullParamValid && (numberOfNullParam < aNumOfNullParam)) |
|
90 { |
|
91 SetUint32(t, parameter); |
|
92 numberOfNullParam++; |
|
93 } |
|
94 } |
|
95 |
|
96 } |
|
97 |
|
98 /** |
|
99 Copies the non-null parameter values from the parameter block dataset into the specified dataset. |
|
100 Note: the number of parameters to be copied out depends on two conditions: |
|
101 1. The number of parameters contained in this parameter block dataset. |
|
102 2. The number of parameters to be copied out to the parameter values sink dataset, |
|
103 which is (aParamEndOffset - aParamStartOffset + 1) by the caller. |
|
104 |
|
105 @param aTo The parameter values sink dataset. This dataset should define three or five contiguous 32-bit parameter values starting at the specified offset. |
|
106 @param aParamStartOffset the element ID of the first in the set of contiguous sink dataset parameter values. |
|
107 @param aParamEndOffset the element ID of the last in the set of contiguous sink dataset parameter values. |
|
108 */ |
|
109 EXPORT_C void TPTPIPTypeRequestPayload::CopyOut( TMTPTypeFlatBase& aTo, |
|
110 TUint aParamStartOffset, TUint aParamEndOffset ) |
|
111 { |
|
112 __ASSERT_DEBUG((aParamEndOffset >= aParamStartOffset && (aParamEndOffset - aParamStartOffset + 1) <= ENumElements), User::Invariant()); |
|
113 for (TUint s(EParameter1), t(aParamStartOffset); (s <= iMaxSetParam && t <= aParamEndOffset); s++, t++) |
|
114 { |
|
115 aTo.SetUint32((t), Uint32(s)); |
|
116 } |
|
117 } |
|
118 |
|
119 /** |
|
120 Resets the dataset. |
|
121 */ |
|
122 EXPORT_C void TPTPIPTypeRequestPayload::Reset( ) |
|
123 { |
|
124 TMTPTypeFlatBase::Reset(); |
|
125 iMaxSetParam = 0; |
|
126 } |
|
127 |
|
128 /** |
|
129 Setter for the op code. |
|
130 */ |
|
131 EXPORT_C void TPTPIPTypeRequestPayload::SetUint16(TInt aElementId, TUint16 aData) |
|
132 { |
|
133 __ASSERT_DEBUG((aElementId == EOpCode), User::Invariant()); |
|
134 TMTPTypeFlatBase::SetUint16(aElementId, aData); |
|
135 } |
|
136 |
|
137 /** |
|
138 Getter for the op code. |
|
139 */ |
|
140 EXPORT_C TUint16 TPTPIPTypeRequestPayload::Uint16(TInt aElementId) const |
|
141 { |
|
142 __ASSERT_DEBUG((aElementId == EOpCode), User::Invariant()); |
|
143 return TMTPTypeFlatBase::Uint16(aElementId); |
|
144 } |
|
145 |
|
146 /** |
|
147 Setter for the parameters, data phase and tran id |
|
148 */ |
|
149 EXPORT_C void TPTPIPTypeRequestPayload::SetUint32(TInt aElementId, TUint32 aData ) |
|
150 { |
|
151 __ASSERT_DEBUG((aElementId != EOpCode), User::Invariant()); |
|
152 if (aElementId >= EParameter1) |
|
153 { |
|
154 if (aElementId > iMaxSetParam) |
|
155 iMaxSetParam = aElementId; |
|
156 /** |
|
157 // Recalculate iNumParameters. |
|
158 TInt num((aElementId - EParameter1) + 1); |
|
159 |
|
160 if (num > iNumParameters) |
|
161 { |
|
162 iNumParameters = num; |
|
163 } |
|
164 */ |
|
165 } |
|
166 |
|
167 // Set the element value. |
|
168 TMTPTypeFlatBase::SetUint32(aElementId, aData); |
|
169 } |
|
170 |
|
171 /** |
|
172 Getter for the parameters, data phase and tran id. |
|
173 */ |
|
174 EXPORT_C TUint32 TPTPIPTypeRequestPayload::Uint32(TInt aElementId) const |
|
175 { |
|
176 // __ASSERT_DEBUG((aElementId < iMaxSetParam ), User::Invariant()); |
|
177 // __ASSERT_DEBUG((aElementId != EOpCode), User::Invariant()); |
|
178 return TMTPTypeFlatBase::Uint32(aElementId); |
|
179 } |
|
180 |
|
181 /** |
|
182 todo |
|
183 */ |
|
184 EXPORT_C TInt TPTPIPTypeRequestPayload::FirstReadChunk(TPtrC8& aChunk) const |
|
185 { |
|
186 TInt ret(TMTPTypeFlatBase::FirstReadChunk(aChunk)); |
|
187 TUint64 size(Size()); |
|
188 |
|
189 if (size < aChunk.Size()) |
|
190 { |
|
191 // Truncate the buffer at the last set parameter. |
|
192 aChunk.Set(aChunk.Left(size)); |
|
193 } |
|
194 |
|
195 return ret; |
|
196 } |
|
197 |
|
198 EXPORT_C TUint64 TPTPIPTypeRequestPayload::Size() const |
|
199 { |
|
200 return (NumParameters() * KMTPTypeUINT32Size + KHeaderElementsSize); |
|
201 } |
|
202 |
|
203 EXPORT_C TUint TPTPIPTypeRequestPayload::Type() const |
|
204 { |
|
205 return EPTPIPTypeRequestPayload; |
|
206 } |
|
207 |
|
208 EXPORT_C TBool TPTPIPTypeRequestPayload::CommitRequired() const |
|
209 { |
|
210 return ETrue; |
|
211 } |
|
212 |
|
213 /** |
|
214 Reset the value of the max set param. |
|
215 */ |
|
216 EXPORT_C MMTPType* TPTPIPTypeRequestPayload::CommitChunkL(TPtr8& /*aChunk*/) |
|
217 { |
|
218 // iNumParameters = 0; |
|
219 |
|
220 // Recalculate iNumParameters. |
|
221 for (TUint i(EParameter1); (i <= EParameter5); i++) |
|
222 { |
|
223 if (TMTPTypeFlatBase::Uint32(i) != KMTPNotSpecified32) |
|
224 { |
|
225 //iNumParameters = (i - EParameter1 + 1 ); |
|
226 iMaxSetParam = i; |
|
227 } |
|
228 } |
|
229 return NULL; |
|
230 } |
|
231 |
|
232 EXPORT_C const TMTPTypeFlatBase::TElementInfo& TPTPIPTypeRequestPayload::ElementInfo(TInt aElementId) const |
|
233 { |
|
234 return iElementInfo[aElementId]; |
|
235 } |
|
236 |