blob: 8016c352dbbc6a1e5ac3b99d6bd39087c71f436d [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 Lockwood90f48732010-06-05 22:45:01 -0400125 mCode = packet.getUInt16();
Mike Lockwoodbf1dbd12010-12-07 13:51:54 -0800126 bool deviceProp = isDeviceProperty();
Mike Lockwood90f48732010-06-05 22:45:01 -0400127 mType = packet.getUInt16();
128 mWriteable = (packet.getUInt8() == 1);
129 switch (mType) {
130 case MTP_TYPE_AINT8:
131 case MTP_TYPE_AUINT8:
132 case MTP_TYPE_AINT16:
133 case MTP_TYPE_AUINT16:
134 case MTP_TYPE_AINT32:
135 case MTP_TYPE_AUINT32:
136 case MTP_TYPE_AINT64:
137 case MTP_TYPE_AUINT64:
138 case MTP_TYPE_AINT128:
139 case MTP_TYPE_AUINT128:
140 mDefaultArrayValues = readArrayValues(packet, mDefaultArrayLength);
Mike Lockwood564ff842010-09-25 08:37:59 -0400141 if (deviceProp)
142 mCurrentArrayValues = readArrayValues(packet, mCurrentArrayLength);
Mike Lockwood90f48732010-06-05 22:45:01 -0400143 break;
144 default:
145 readValue(packet, mDefaultValue);
Mike Lockwood564ff842010-09-25 08:37:59 -0400146 if (deviceProp)
Mike Lockwood767c5e42010-06-30 17:00:35 -0400147 readValue(packet, mCurrentValue);
Mike Lockwood90f48732010-06-05 22:45:01 -0400148 }
Mike Lockwood564ff842010-09-25 08:37:59 -0400149 if (!deviceProp)
150 mGroupCode = packet.getUInt32();
Mike Lockwood90f48732010-06-05 22:45:01 -0400151 mFormFlag = packet.getUInt8();
152
153 if (mFormFlag == kFormRange) {
154 readValue(packet, mMinimumValue);
155 readValue(packet, mMaximumValue);
156 readValue(packet, mStepSize);
157 } else if (mFormFlag == kFormEnum) {
158 mEnumLength = packet.getUInt16();
159 mEnumValues = new MtpPropertyValue[mEnumLength];
160 for (int i = 0; i < mEnumLength; i++)
161 readValue(packet, mEnumValues[i]);
162 }
163}
164
Mike Lockwood767c5e42010-06-30 17:00:35 -0400165void MtpProperty::write(MtpDataPacket& packet) {
Mike Lockwood564ff842010-09-25 08:37:59 -0400166 bool deviceProp = isDeviceProperty();
167
Mike Lockwood767c5e42010-06-30 17:00:35 -0400168 packet.putUInt16(mCode);
169 packet.putUInt16(mType);
170 packet.putUInt8(mWriteable ? 1 : 0);
171
172 switch (mType) {
173 case MTP_TYPE_AINT8:
174 case MTP_TYPE_AUINT8:
175 case MTP_TYPE_AINT16:
176 case MTP_TYPE_AUINT16:
177 case MTP_TYPE_AINT32:
178 case MTP_TYPE_AUINT32:
179 case MTP_TYPE_AINT64:
180 case MTP_TYPE_AUINT64:
181 case MTP_TYPE_AINT128:
182 case MTP_TYPE_AUINT128:
183 writeArrayValues(packet, mDefaultArrayValues, mDefaultArrayLength);
Mike Lockwood564ff842010-09-25 08:37:59 -0400184 if (deviceProp)
185 writeArrayValues(packet, mCurrentArrayValues, mCurrentArrayLength);
Mike Lockwood767c5e42010-06-30 17:00:35 -0400186 break;
187 default:
188 writeValue(packet, mDefaultValue);
Mike Lockwood564ff842010-09-25 08:37:59 -0400189 if (deviceProp)
190 writeValue(packet, mCurrentValue);
Mike Lockwood767c5e42010-06-30 17:00:35 -0400191 }
Mike Lockwood97c8d902010-08-09 14:49:28 -0400192 packet.putUInt32(mGroupCode);
Mike Lockwood564ff842010-09-25 08:37:59 -0400193 if (!deviceProp)
194 packet.putUInt8(mFormFlag);
Mike Lockwood767c5e42010-06-30 17:00:35 -0400195 if (mFormFlag == kFormRange) {
196 writeValue(packet, mMinimumValue);
197 writeValue(packet, mMaximumValue);
198 writeValue(packet, mStepSize);
199 } else if (mFormFlag == kFormEnum) {
200 packet.putUInt16(mEnumLength);
201 for (int i = 0; i < mEnumLength; i++)
202 writeValue(packet, mEnumValues[i]);
203 }
204}
205
Mike Lockwooda2a21282010-09-25 21:21:05 -0400206void MtpProperty::setDefaultValue(const uint16_t* string) {
207 free(mDefaultValue.str);
208 if (string) {
209 MtpStringBuffer buffer(string);
210 mDefaultValue.str = strdup(buffer);
211 }
212 else
213 mDefaultValue.str = NULL;
214}
215
216void MtpProperty::setCurrentValue(const uint16_t* string) {
217 free(mCurrentValue.str);
218 if (string) {
219 MtpStringBuffer buffer(string);
220 mCurrentValue.str = strdup(buffer);
221 }
222 else
223 mCurrentValue.str = NULL;
224}
225
Mike Lockwood4a65e282010-11-10 12:48:39 -0500226void MtpProperty::setFormRange(int min, int max, int step) {
227 mFormFlag = kFormRange;
228 switch (mType) {
229 case MTP_TYPE_INT8:
230 mMinimumValue.u.i8 = min;
231 mMaximumValue.u.i8 = max;
232 mStepSize.u.i8 = step;
233 break;
234 case MTP_TYPE_UINT8:
235 mMinimumValue.u.u8 = min;
236 mMaximumValue.u.u8 = max;
237 mStepSize.u.u8 = step;
238 break;
239 case MTP_TYPE_INT16:
240 mMinimumValue.u.i16 = min;
241 mMaximumValue.u.i16 = max;
242 mStepSize.u.i16 = step;
243 break;
244 case MTP_TYPE_UINT16:
245 mMinimumValue.u.u16 = min;
246 mMaximumValue.u.u16 = max;
247 mStepSize.u.u16 = step;
248 break;
249 case MTP_TYPE_INT32:
250 mMinimumValue.u.i32 = min;
251 mMaximumValue.u.i32 = max;
252 mStepSize.u.i32 = step;
253 break;
254 case MTP_TYPE_UINT32:
255 mMinimumValue.u.u32 = min;
256 mMaximumValue.u.u32 = max;
257 mStepSize.u.u32 = step;
258 break;
259 case MTP_TYPE_INT64:
260 mMinimumValue.u.i64 = min;
261 mMaximumValue.u.i64 = max;
262 mStepSize.u.i64 = step;
263 break;
264 case MTP_TYPE_UINT64:
265 mMinimumValue.u.u64 = min;
266 mMaximumValue.u.u64 = max;
267 mStepSize.u.u64 = step;
268 break;
269 default:
270 LOGE("unsupported type for MtpProperty::setRange");
271 break;
272 }
273}
274
275void MtpProperty::setFormEnum(const int* values, int count) {
276 mFormFlag = kFormEnum;
277 delete[] mEnumValues;
278 mEnumValues = new MtpPropertyValue[count];
279 mEnumLength = count;
280
281 for (int i = 0; i < count; i++) {
282 int value = *values++;
283 switch (mType) {
284 case MTP_TYPE_INT8:
285 mEnumValues[i].u.i8 = value;
286 break;
287 case MTP_TYPE_UINT8:
288 mEnumValues[i].u.u8 = value;
289 break;
290 case MTP_TYPE_INT16:
291 mEnumValues[i].u.i16 = value;
292 break;
293 case MTP_TYPE_UINT16:
294 mEnumValues[i].u.u16 = value;
295 break;
296 case MTP_TYPE_INT32:
297 mEnumValues[i].u.i32 = value;
298 break;
299 case MTP_TYPE_UINT32:
300 mEnumValues[i].u.u32 = value;
301 break;
302 case MTP_TYPE_INT64:
303 mEnumValues[i].u.i64 = value;
304 break;
305 case MTP_TYPE_UINT64:
306 mEnumValues[i].u.u64 = value;
307 break;
308 default:
309 LOGE("unsupported type for MtpProperty::setEnum");
310 break;
311 }
312 }
313}
314
Mike Lockwood5b19af02010-11-23 18:38:55 -0500315void MtpProperty::setFormDateTime() {
316 mFormFlag = kFormDateTime;
317}
318
Mike Lockwood90f48732010-06-05 22:45:01 -0400319void MtpProperty::print() {
Mike Lockwoode4880e42010-12-07 11:24:28 -0800320 MtpString buffer;
321 bool deviceProp = isDeviceProperty();
322 if (deviceProp)
323 LOGI(" %s (%04X)", MtpDebug::getDevicePropCodeName(mCode), mCode);
324 else
325 LOGI(" %s (%04X)", MtpDebug::getObjectPropCodeName(mCode), mCode);
326 LOGI(" type %04X", mType);
327 LOGI(" writeable %s", (mWriteable ? "true" : "false"));
328 buffer = " default value: ";
329 print(mDefaultValue, buffer);
330 LOGI("%s", (const char *)buffer);
331 if (deviceProp) {
332 buffer = " current value: ";
333 print(mCurrentValue, buffer);
334 LOGI("%s", (const char *)buffer);
335 }
336 switch (mFormFlag) {
337 case kFormNone:
338 break;
339 case kFormRange:
340 buffer = " Range (";
341 print(mMinimumValue, buffer);
342 buffer += ", ";
343 print(mMaximumValue, buffer);
344 buffer += ", ";
345 print(mStepSize, buffer);
Mike Lockwood365e03e2010-12-08 16:08:01 -0800346 buffer += ")";
Mike Lockwoode4880e42010-12-07 11:24:28 -0800347 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