blob: 3b38720c2d75cc62525c62ca56eb62f2ba592860 [file] [log] [blame]
Mike Lockwood90f48732010-06-05 22:45:01 -04001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "MtpProperty"
Mike Lockwood90f48732010-06-05 22:45:01 -040018
19#include "MtpDataPacket.h"
Mike Lockwoode4880e42010-12-07 11:24:28 -080020#include "MtpDebug.h"
Mike Lockwood90f48732010-06-05 22:45:01 -040021#include "MtpProperty.h"
22#include "MtpStringBuffer.h"
23#include "MtpUtils.h"
24
25namespace android {
26
27MtpProperty::MtpProperty()
28 : mCode(0),
29 mType(0),
30 mWriteable(false),
31 mDefaultArrayLength(0),
32 mDefaultArrayValues(NULL),
33 mCurrentArrayLength(0),
34 mCurrentArrayValues(NULL),
Mike Lockwood97c8d902010-08-09 14:49:28 -040035 mGroupCode(0),
Mike Lockwood90f48732010-06-05 22:45:01 -040036 mFormFlag(kFormNone),
37 mEnumLength(0),
38 mEnumValues(NULL)
39{
Mike Lockwooda2a21282010-09-25 21:21:05 -040040 memset(&mDefaultValue, 0, sizeof(mDefaultValue));
41 memset(&mCurrentValue, 0, sizeof(mCurrentValue));
42 memset(&mMinimumValue, 0, sizeof(mMinimumValue));
43 memset(&mMaximumValue, 0, sizeof(mMaximumValue));
Mike Lockwood90f48732010-06-05 22:45:01 -040044}
45
Mike Lockwood767c5e42010-06-30 17:00:35 -040046MtpProperty::MtpProperty(MtpPropertyCode propCode,
47 MtpDataType type,
48 bool writeable,
49 int defaultValue)
50 : mCode(propCode),
51 mType(type),
52 mWriteable(writeable),
53 mDefaultArrayLength(0),
54 mDefaultArrayValues(NULL),
55 mCurrentArrayLength(0),
56 mCurrentArrayValues(NULL),
Mike Lockwood7d7fb632010-12-01 18:46:23 -050057 mGroupCode(0),
Mike Lockwood767c5e42010-06-30 17:00:35 -040058 mFormFlag(kFormNone),
59 mEnumLength(0),
60 mEnumValues(NULL)
61{
62 memset(&mDefaultValue, 0, sizeof(mDefaultValue));
63 memset(&mCurrentValue, 0, sizeof(mCurrentValue));
64 memset(&mMinimumValue, 0, sizeof(mMinimumValue));
65 memset(&mMaximumValue, 0, sizeof(mMaximumValue));
66
67 if (defaultValue) {
68 switch (type) {
69 case MTP_TYPE_INT8:
Mike Lockwooda2a21282010-09-25 21:21:05 -040070 mDefaultValue.u.i8 = defaultValue;
Mike Lockwood767c5e42010-06-30 17:00:35 -040071 break;
72 case MTP_TYPE_UINT8:
Mike Lockwooda2a21282010-09-25 21:21:05 -040073 mDefaultValue.u.u8 = defaultValue;
Mike Lockwood767c5e42010-06-30 17:00:35 -040074 break;
75 case MTP_TYPE_INT16:
Mike Lockwooda2a21282010-09-25 21:21:05 -040076 mDefaultValue.u.i16 = defaultValue;
Mike Lockwood767c5e42010-06-30 17:00:35 -040077 break;
78 case MTP_TYPE_UINT16:
Mike Lockwooda2a21282010-09-25 21:21:05 -040079 mDefaultValue.u.u16 = defaultValue;
Mike Lockwood767c5e42010-06-30 17:00:35 -040080 break;
81 case MTP_TYPE_INT32:
Mike Lockwooda2a21282010-09-25 21:21:05 -040082 mDefaultValue.u.i32 = defaultValue;
Mike Lockwood767c5e42010-06-30 17:00:35 -040083 break;
84 case MTP_TYPE_UINT32:
Mike Lockwooda2a21282010-09-25 21:21:05 -040085 mDefaultValue.u.u32 = defaultValue;
Mike Lockwood767c5e42010-06-30 17:00:35 -040086 break;
87 case MTP_TYPE_INT64:
Mike Lockwooda2a21282010-09-25 21:21:05 -040088 mDefaultValue.u.i64 = defaultValue;
Mike Lockwood767c5e42010-06-30 17:00:35 -040089 break;
90 case MTP_TYPE_UINT64:
Mike Lockwooda2a21282010-09-25 21:21:05 -040091 mDefaultValue.u.u64 = defaultValue;
Mike Lockwood767c5e42010-06-30 17:00:35 -040092 break;
93 default:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -040094 LOGE("unknown type %04X in MtpProperty::MtpProperty", type);
Mike Lockwood767c5e42010-06-30 17:00:35 -040095 }
96 }
97}
98
Mike Lockwood90f48732010-06-05 22:45:01 -040099MtpProperty::~MtpProperty() {
100 if (mType == MTP_TYPE_STR) {
101 // free all strings
102 free(mDefaultValue.str);
103 free(mCurrentValue.str);
104 free(mMinimumValue.str);
105 free(mMaximumValue.str);
106 if (mDefaultArrayValues) {
107 for (int i = 0; i < mDefaultArrayLength; i++)
108 free(mDefaultArrayValues[i].str);
109 }
110 if (mCurrentArrayValues) {
111 for (int i = 0; i < mCurrentArrayLength; i++)
112 free(mCurrentArrayValues[i].str);
113 }
114 if (mEnumValues) {
115 for (int i = 0; i < mEnumLength; i++)
116 free(mEnumValues[i].str);
117 }
118 }
119 delete[] mDefaultArrayValues;
120 delete[] mCurrentArrayValues;
121 delete[] mEnumValues;
122}
123
Mike Lockwood59e3f0d2010-09-02 14:57:30 -0400124void MtpProperty::read(MtpDataPacket& packet) {
Mike Lockwood564ff842010-09-25 08:37:59 -0400125 bool deviceProp = isDeviceProperty();
Mike Lockwood90f48732010-06-05 22:45:01 -0400126
127 mCode = packet.getUInt16();
128 mType = packet.getUInt16();
129 mWriteable = (packet.getUInt8() == 1);
130 switch (mType) {
131 case MTP_TYPE_AINT8:
132 case MTP_TYPE_AUINT8:
133 case MTP_TYPE_AINT16:
134 case MTP_TYPE_AUINT16:
135 case MTP_TYPE_AINT32:
136 case MTP_TYPE_AUINT32:
137 case MTP_TYPE_AINT64:
138 case MTP_TYPE_AUINT64:
139 case MTP_TYPE_AINT128:
140 case MTP_TYPE_AUINT128:
141 mDefaultArrayValues = readArrayValues(packet, mDefaultArrayLength);
Mike Lockwood564ff842010-09-25 08:37:59 -0400142 if (deviceProp)
143 mCurrentArrayValues = readArrayValues(packet, mCurrentArrayLength);
Mike Lockwood90f48732010-06-05 22:45:01 -0400144 break;
145 default:
146 readValue(packet, mDefaultValue);
Mike Lockwood564ff842010-09-25 08:37:59 -0400147 if (deviceProp)
Mike Lockwood767c5e42010-06-30 17:00:35 -0400148 readValue(packet, mCurrentValue);
Mike Lockwood90f48732010-06-05 22:45:01 -0400149 }
Mike Lockwood564ff842010-09-25 08:37:59 -0400150 if (!deviceProp)
151 mGroupCode = packet.getUInt32();
Mike Lockwood90f48732010-06-05 22:45:01 -0400152 mFormFlag = packet.getUInt8();
153
154 if (mFormFlag == kFormRange) {
155 readValue(packet, mMinimumValue);
156 readValue(packet, mMaximumValue);
157 readValue(packet, mStepSize);
158 } else if (mFormFlag == kFormEnum) {
159 mEnumLength = packet.getUInt16();
160 mEnumValues = new MtpPropertyValue[mEnumLength];
161 for (int i = 0; i < mEnumLength; i++)
162 readValue(packet, mEnumValues[i]);
163 }
164}
165
Mike Lockwood767c5e42010-06-30 17:00:35 -0400166void MtpProperty::write(MtpDataPacket& packet) {
Mike Lockwood564ff842010-09-25 08:37:59 -0400167 bool deviceProp = isDeviceProperty();
168
Mike Lockwood767c5e42010-06-30 17:00:35 -0400169 packet.putUInt16(mCode);
170 packet.putUInt16(mType);
171 packet.putUInt8(mWriteable ? 1 : 0);
172
173 switch (mType) {
174 case MTP_TYPE_AINT8:
175 case MTP_TYPE_AUINT8:
176 case MTP_TYPE_AINT16:
177 case MTP_TYPE_AUINT16:
178 case MTP_TYPE_AINT32:
179 case MTP_TYPE_AUINT32:
180 case MTP_TYPE_AINT64:
181 case MTP_TYPE_AUINT64:
182 case MTP_TYPE_AINT128:
183 case MTP_TYPE_AUINT128:
184 writeArrayValues(packet, mDefaultArrayValues, mDefaultArrayLength);
Mike Lockwood564ff842010-09-25 08:37:59 -0400185 if (deviceProp)
186 writeArrayValues(packet, mCurrentArrayValues, mCurrentArrayLength);
Mike Lockwood767c5e42010-06-30 17:00:35 -0400187 break;
188 default:
189 writeValue(packet, mDefaultValue);
Mike Lockwood564ff842010-09-25 08:37:59 -0400190 if (deviceProp)
191 writeValue(packet, mCurrentValue);
Mike Lockwood767c5e42010-06-30 17:00:35 -0400192 }
Mike Lockwood97c8d902010-08-09 14:49:28 -0400193 packet.putUInt32(mGroupCode);
Mike Lockwood564ff842010-09-25 08:37:59 -0400194 if (!deviceProp)
195 packet.putUInt8(mFormFlag);
Mike Lockwood767c5e42010-06-30 17:00:35 -0400196 if (mFormFlag == kFormRange) {
197 writeValue(packet, mMinimumValue);
198 writeValue(packet, mMaximumValue);
199 writeValue(packet, mStepSize);
200 } else if (mFormFlag == kFormEnum) {
201 packet.putUInt16(mEnumLength);
202 for (int i = 0; i < mEnumLength; i++)
203 writeValue(packet, mEnumValues[i]);
204 }
205}
206
Mike Lockwooda2a21282010-09-25 21:21:05 -0400207void MtpProperty::setDefaultValue(const uint16_t* string) {
208 free(mDefaultValue.str);
209 if (string) {
210 MtpStringBuffer buffer(string);
211 mDefaultValue.str = strdup(buffer);
212 }
213 else
214 mDefaultValue.str = NULL;
215}
216
217void MtpProperty::setCurrentValue(const uint16_t* string) {
218 free(mCurrentValue.str);
219 if (string) {
220 MtpStringBuffer buffer(string);
221 mCurrentValue.str = strdup(buffer);
222 }
223 else
224 mCurrentValue.str = NULL;
225}
226
Mike Lockwood4a65e282010-11-10 12:48:39 -0500227void MtpProperty::setFormRange(int min, int max, int step) {
228 mFormFlag = kFormRange;
229 switch (mType) {
230 case MTP_TYPE_INT8:
231 mMinimumValue.u.i8 = min;
232 mMaximumValue.u.i8 = max;
233 mStepSize.u.i8 = step;
234 break;
235 case MTP_TYPE_UINT8:
236 mMinimumValue.u.u8 = min;
237 mMaximumValue.u.u8 = max;
238 mStepSize.u.u8 = step;
239 break;
240 case MTP_TYPE_INT16:
241 mMinimumValue.u.i16 = min;
242 mMaximumValue.u.i16 = max;
243 mStepSize.u.i16 = step;
244 break;
245 case MTP_TYPE_UINT16:
246 mMinimumValue.u.u16 = min;
247 mMaximumValue.u.u16 = max;
248 mStepSize.u.u16 = step;
249 break;
250 case MTP_TYPE_INT32:
251 mMinimumValue.u.i32 = min;
252 mMaximumValue.u.i32 = max;
253 mStepSize.u.i32 = step;
254 break;
255 case MTP_TYPE_UINT32:
256 mMinimumValue.u.u32 = min;
257 mMaximumValue.u.u32 = max;
258 mStepSize.u.u32 = step;
259 break;
260 case MTP_TYPE_INT64:
261 mMinimumValue.u.i64 = min;
262 mMaximumValue.u.i64 = max;
263 mStepSize.u.i64 = step;
264 break;
265 case MTP_TYPE_UINT64:
266 mMinimumValue.u.u64 = min;
267 mMaximumValue.u.u64 = max;
268 mStepSize.u.u64 = step;
269 break;
270 default:
271 LOGE("unsupported type for MtpProperty::setRange");
272 break;
273 }
274}
275
276void MtpProperty::setFormEnum(const int* values, int count) {
277 mFormFlag = kFormEnum;
278 delete[] mEnumValues;
279 mEnumValues = new MtpPropertyValue[count];
280 mEnumLength = count;
281
282 for (int i = 0; i < count; i++) {
283 int value = *values++;
284 switch (mType) {
285 case MTP_TYPE_INT8:
286 mEnumValues[i].u.i8 = value;
287 break;
288 case MTP_TYPE_UINT8:
289 mEnumValues[i].u.u8 = value;
290 break;
291 case MTP_TYPE_INT16:
292 mEnumValues[i].u.i16 = value;
293 break;
294 case MTP_TYPE_UINT16:
295 mEnumValues[i].u.u16 = value;
296 break;
297 case MTP_TYPE_INT32:
298 mEnumValues[i].u.i32 = value;
299 break;
300 case MTP_TYPE_UINT32:
301 mEnumValues[i].u.u32 = value;
302 break;
303 case MTP_TYPE_INT64:
304 mEnumValues[i].u.i64 = value;
305 break;
306 case MTP_TYPE_UINT64:
307 mEnumValues[i].u.u64 = value;
308 break;
309 default:
310 LOGE("unsupported type for MtpProperty::setEnum");
311 break;
312 }
313 }
314}
315
Mike Lockwood5b19af02010-11-23 18:38:55 -0500316void MtpProperty::setFormDateTime() {
317 mFormFlag = kFormDateTime;
318}
319
Mike Lockwood90f48732010-06-05 22:45:01 -0400320void MtpProperty::print() {
Mike Lockwoode4880e42010-12-07 11:24:28 -0800321 MtpString buffer;
322 bool deviceProp = isDeviceProperty();
323 if (deviceProp)
324 LOGI(" %s (%04X)", MtpDebug::getDevicePropCodeName(mCode), mCode);
325 else
326 LOGI(" %s (%04X)", MtpDebug::getObjectPropCodeName(mCode), mCode);
327 LOGI(" type %04X", mType);
328 LOGI(" writeable %s", (mWriteable ? "true" : "false"));
329 buffer = " default value: ";
330 print(mDefaultValue, buffer);
331 LOGI("%s", (const char *)buffer);
332 if (deviceProp) {
333 buffer = " current value: ";
334 print(mCurrentValue, buffer);
335 LOGI("%s", (const char *)buffer);
336 }
337 switch (mFormFlag) {
338 case kFormNone:
339 break;
340 case kFormRange:
341 buffer = " Range (";
342 print(mMinimumValue, buffer);
343 buffer += ", ";
344 print(mMaximumValue, buffer);
345 buffer += ", ";
346 print(mStepSize, buffer);
347 LOGI("%s", (const char *)buffer);
348 break;
349 case kFormEnum:
350 buffer = " Enum { ";
351 for (int i = 0; i < mEnumLength; i++) {
352 print(mEnumValues[i], buffer);
353 buffer += " ";
354 }
355 buffer += "}";
356 LOGI("%s", (const char *)buffer);
357 break;
358 case kFormDateTime:
359 LOGI(" DateTime\n");
360 break;
361 default:
362 LOGI(" form %d\n", mFormFlag);
363 break;
364 }
365}
366
367void MtpProperty::print(MtpPropertyValue& value, MtpString& buffer) {
368 switch (mType) {
369 case MTP_TYPE_INT8:
370 buffer.appendFormat("%d", value.u.i8);
371 break;
372 case MTP_TYPE_UINT8:
373 buffer.appendFormat("%d", value.u.u8);
374 break;
375 case MTP_TYPE_INT16:
376 buffer.appendFormat("%d", value.u.i16);
377 break;
378 case MTP_TYPE_UINT16:
379 buffer.appendFormat("%d", value.u.u16);
380 break;
381 case MTP_TYPE_INT32:
382 buffer.appendFormat("%d", value.u.i32);
383 break;
384 case MTP_TYPE_UINT32:
385 buffer.appendFormat("%d", value.u.u32);
386 break;
387 case MTP_TYPE_INT64:
388 buffer.appendFormat("%lld", value.u.i64);
389 break;
390 case MTP_TYPE_UINT64:
391 buffer.appendFormat("%lld", value.u.u64);
392 break;
393 case MTP_TYPE_INT128:
394 buffer.appendFormat("%08X%08X%08X%08X", value.u.i128[0], value.u.i128[1],
395 value.u.i128[2], value.u.i128[3]);
396 break;
397 case MTP_TYPE_UINT128:
398 buffer.appendFormat("%08X%08X%08X%08X", value.u.u128[0], value.u.u128[1],
399 value.u.u128[2], value.u.u128[3]);
400 break;
401 case MTP_TYPE_STR:
402 buffer.appendFormat("%s", value.str);
403 break;
404 default:
405 LOGE("unsupported type for MtpProperty::print\n");
406 break;
407 }
Mike Lockwood90f48732010-06-05 22:45:01 -0400408}
409
410void MtpProperty::readValue(MtpDataPacket& packet, MtpPropertyValue& value) {
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400411 MtpStringBuffer stringBuffer;
412
Mike Lockwood90f48732010-06-05 22:45:01 -0400413 switch (mType) {
414 case MTP_TYPE_INT8:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400415 case MTP_TYPE_AINT8:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400416 value.u.i8 = packet.getInt8();
Mike Lockwood90f48732010-06-05 22:45:01 -0400417 break;
418 case MTP_TYPE_UINT8:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400419 case MTP_TYPE_AUINT8:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400420 value.u.u8 = packet.getUInt8();
Mike Lockwood90f48732010-06-05 22:45:01 -0400421 break;
422 case MTP_TYPE_INT16:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400423 case MTP_TYPE_AINT16:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400424 value.u.i16 = packet.getInt16();
Mike Lockwood90f48732010-06-05 22:45:01 -0400425 break;
426 case MTP_TYPE_UINT16:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400427 case MTP_TYPE_AUINT16:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400428 value.u.u16 = packet.getUInt16();
Mike Lockwood90f48732010-06-05 22:45:01 -0400429 break;
430 case MTP_TYPE_INT32:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400431 case MTP_TYPE_AINT32:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400432 value.u.i32 = packet.getInt32();
Mike Lockwood90f48732010-06-05 22:45:01 -0400433 break;
434 case MTP_TYPE_UINT32:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400435 case MTP_TYPE_AUINT32:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400436 value.u.u32 = packet.getUInt32();
Mike Lockwood90f48732010-06-05 22:45:01 -0400437 break;
438 case MTP_TYPE_INT64:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400439 case MTP_TYPE_AINT64:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400440 value.u.i64 = packet.getInt64();
Mike Lockwood90f48732010-06-05 22:45:01 -0400441 break;
442 case MTP_TYPE_UINT64:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400443 case MTP_TYPE_AUINT64:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400444 value.u.u64 = packet.getUInt64();
Mike Lockwood90f48732010-06-05 22:45:01 -0400445 break;
446 case MTP_TYPE_INT128:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400447 case MTP_TYPE_AINT128:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400448 packet.getInt128(value.u.i128);
Mike Lockwood90f48732010-06-05 22:45:01 -0400449 break;
450 case MTP_TYPE_UINT128:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400451 case MTP_TYPE_AUINT128:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400452 packet.getUInt128(value.u.u128);
Mike Lockwood90f48732010-06-05 22:45:01 -0400453 break;
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400454 case MTP_TYPE_STR:
455 packet.getString(stringBuffer);
456 value.str = strdup(stringBuffer);
457 break;
Mike Lockwood90f48732010-06-05 22:45:01 -0400458 default:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400459 LOGE("unknown type %04X in MtpProperty::readValue", mType);
Mike Lockwood90f48732010-06-05 22:45:01 -0400460 }
461}
462
Mike Lockwood767c5e42010-06-30 17:00:35 -0400463void MtpProperty::writeValue(MtpDataPacket& packet, MtpPropertyValue& value) {
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400464 MtpStringBuffer stringBuffer;
465
Mike Lockwood767c5e42010-06-30 17:00:35 -0400466 switch (mType) {
467 case MTP_TYPE_INT8:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400468 case MTP_TYPE_AINT8:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400469 packet.putInt8(value.u.i8);
Mike Lockwood767c5e42010-06-30 17:00:35 -0400470 break;
471 case MTP_TYPE_UINT8:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400472 case MTP_TYPE_AUINT8:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400473 packet.putUInt8(value.u.u8);
Mike Lockwood767c5e42010-06-30 17:00:35 -0400474 break;
475 case MTP_TYPE_INT16:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400476 case MTP_TYPE_AINT16:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400477 packet.putInt16(value.u.i16);
Mike Lockwood767c5e42010-06-30 17:00:35 -0400478 break;
479 case MTP_TYPE_UINT16:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400480 case MTP_TYPE_AUINT16:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400481 packet.putUInt16(value.u.u16);
Mike Lockwood767c5e42010-06-30 17:00:35 -0400482 break;
483 case MTP_TYPE_INT32:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400484 case MTP_TYPE_AINT32:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400485 packet.putInt32(value.u.i32);
Mike Lockwood767c5e42010-06-30 17:00:35 -0400486 break;
487 case MTP_TYPE_UINT32:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400488 case MTP_TYPE_AUINT32:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400489 packet.putUInt32(value.u.u32);
Mike Lockwood767c5e42010-06-30 17:00:35 -0400490 break;
491 case MTP_TYPE_INT64:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400492 case MTP_TYPE_AINT64:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400493 packet.putInt64(value.u.i64);
Mike Lockwood767c5e42010-06-30 17:00:35 -0400494 break;
495 case MTP_TYPE_UINT64:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400496 case MTP_TYPE_AUINT64:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400497 packet.putUInt64(value.u.u64);
Mike Lockwood767c5e42010-06-30 17:00:35 -0400498 break;
499 case MTP_TYPE_INT128:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400500 case MTP_TYPE_AINT128:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400501 packet.putInt128(value.u.i128);
Mike Lockwood767c5e42010-06-30 17:00:35 -0400502 break;
503 case MTP_TYPE_UINT128:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400504 case MTP_TYPE_AUINT128:
Mike Lockwooda2a21282010-09-25 21:21:05 -0400505 packet.putUInt128(value.u.u128);
Mike Lockwood767c5e42010-06-30 17:00:35 -0400506 break;
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400507 case MTP_TYPE_STR:
508 if (value.str)
509 packet.putString(value.str);
510 else
511 packet.putEmptyString();
512 break;
Mike Lockwood767c5e42010-06-30 17:00:35 -0400513 default:
Mike Lockwood9bbc2ea2010-07-20 09:47:41 -0400514 LOGE("unknown type %04X in MtpProperty::writeValue", mType);
Mike Lockwood767c5e42010-06-30 17:00:35 -0400515 }
516}
517
Mike Lockwood90f48732010-06-05 22:45:01 -0400518MtpPropertyValue* MtpProperty::readArrayValues(MtpDataPacket& packet, int& length) {
519 length = packet.getUInt32();
520 if (length == 0)
521 return NULL;
522 MtpPropertyValue* result = new MtpPropertyValue[length];
523 for (int i = 0; i < length; i++)
524 readValue(packet, result[i]);
525 return result;
526}
527
Mike Lockwood767c5e42010-06-30 17:00:35 -0400528void MtpProperty::writeArrayValues(MtpDataPacket& packet, MtpPropertyValue* values, int length) {
529 packet.putUInt32(length);
530 for (int i = 0; i < length; i++)
531 writeValue(packet, values[i]);
532}
533
Mike Lockwood90f48732010-06-05 22:45:01 -0400534} // namespace android