Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 1 | /* |
| 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 Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 18 | |
| 19 | #include "MtpDataPacket.h" |
| 20 | #include "MtpProperty.h" |
| 21 | #include "MtpStringBuffer.h" |
| 22 | #include "MtpUtils.h" |
| 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | MtpProperty::MtpProperty() |
| 27 | : mCode(0), |
| 28 | mType(0), |
| 29 | mWriteable(false), |
| 30 | mDefaultArrayLength(0), |
| 31 | mDefaultArrayValues(NULL), |
| 32 | mCurrentArrayLength(0), |
| 33 | mCurrentArrayValues(NULL), |
Mike Lockwood | 97c8d90 | 2010-08-09 14:49:28 -0400 | [diff] [blame] | 34 | mGroupCode(0), |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 35 | mFormFlag(kFormNone), |
| 36 | mEnumLength(0), |
| 37 | mEnumValues(NULL) |
| 38 | { |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 39 | memset(&mDefaultValue, 0, sizeof(mDefaultValue)); |
| 40 | memset(&mCurrentValue, 0, sizeof(mCurrentValue)); |
| 41 | memset(&mMinimumValue, 0, sizeof(mMinimumValue)); |
| 42 | memset(&mMaximumValue, 0, sizeof(mMaximumValue)); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 43 | } |
| 44 | |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 45 | MtpProperty::MtpProperty(MtpPropertyCode propCode, |
| 46 | MtpDataType type, |
| 47 | bool writeable, |
| 48 | int defaultValue) |
| 49 | : mCode(propCode), |
| 50 | mType(type), |
| 51 | mWriteable(writeable), |
| 52 | mDefaultArrayLength(0), |
| 53 | mDefaultArrayValues(NULL), |
| 54 | mCurrentArrayLength(0), |
| 55 | mCurrentArrayValues(NULL), |
Mike Lockwood | 97c8d90 | 2010-08-09 14:49:28 -0400 | [diff] [blame] | 56 | mGroupCode(0), |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 57 | mFormFlag(kFormNone), |
| 58 | mEnumLength(0), |
| 59 | mEnumValues(NULL) |
| 60 | { |
| 61 | memset(&mDefaultValue, 0, sizeof(mDefaultValue)); |
| 62 | memset(&mCurrentValue, 0, sizeof(mCurrentValue)); |
| 63 | memset(&mMinimumValue, 0, sizeof(mMinimumValue)); |
| 64 | memset(&mMaximumValue, 0, sizeof(mMaximumValue)); |
| 65 | |
| 66 | if (defaultValue) { |
| 67 | switch (type) { |
| 68 | case MTP_TYPE_INT8: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 69 | mDefaultValue.u.i8 = defaultValue; |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 70 | break; |
| 71 | case MTP_TYPE_UINT8: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 72 | mDefaultValue.u.u8 = defaultValue; |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 73 | break; |
| 74 | case MTP_TYPE_INT16: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 75 | mDefaultValue.u.i16 = defaultValue; |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 76 | break; |
| 77 | case MTP_TYPE_UINT16: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 78 | mDefaultValue.u.u16 = defaultValue; |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 79 | break; |
| 80 | case MTP_TYPE_INT32: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 81 | mDefaultValue.u.i32 = defaultValue; |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 82 | break; |
| 83 | case MTP_TYPE_UINT32: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 84 | mDefaultValue.u.u32 = defaultValue; |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 85 | break; |
| 86 | case MTP_TYPE_INT64: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 87 | mDefaultValue.u.i64 = defaultValue; |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 88 | break; |
| 89 | case MTP_TYPE_UINT64: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 90 | mDefaultValue.u.u64 = defaultValue; |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 91 | break; |
| 92 | default: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 93 | LOGE("unknown type %04X in MtpProperty::MtpProperty", type); |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 98 | MtpProperty::~MtpProperty() { |
| 99 | if (mType == MTP_TYPE_STR) { |
| 100 | // free all strings |
| 101 | free(mDefaultValue.str); |
| 102 | free(mCurrentValue.str); |
| 103 | free(mMinimumValue.str); |
| 104 | free(mMaximumValue.str); |
| 105 | if (mDefaultArrayValues) { |
| 106 | for (int i = 0; i < mDefaultArrayLength; i++) |
| 107 | free(mDefaultArrayValues[i].str); |
| 108 | } |
| 109 | if (mCurrentArrayValues) { |
| 110 | for (int i = 0; i < mCurrentArrayLength; i++) |
| 111 | free(mCurrentArrayValues[i].str); |
| 112 | } |
| 113 | if (mEnumValues) { |
| 114 | for (int i = 0; i < mEnumLength; i++) |
| 115 | free(mEnumValues[i].str); |
| 116 | } |
| 117 | } |
| 118 | delete[] mDefaultArrayValues; |
| 119 | delete[] mCurrentArrayValues; |
| 120 | delete[] mEnumValues; |
| 121 | } |
| 122 | |
Mike Lockwood | 59e3f0d | 2010-09-02 14:57:30 -0400 | [diff] [blame] | 123 | void MtpProperty::read(MtpDataPacket& packet) { |
Mike Lockwood | 564ff84 | 2010-09-25 08:37:59 -0400 | [diff] [blame] | 124 | bool deviceProp = isDeviceProperty(); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 125 | |
| 126 | mCode = packet.getUInt16(); |
| 127 | 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 Lockwood | 564ff84 | 2010-09-25 08:37:59 -0400 | [diff] [blame] | 141 | if (deviceProp) |
| 142 | mCurrentArrayValues = readArrayValues(packet, mCurrentArrayLength); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 143 | break; |
| 144 | default: |
| 145 | readValue(packet, mDefaultValue); |
Mike Lockwood | 564ff84 | 2010-09-25 08:37:59 -0400 | [diff] [blame] | 146 | if (deviceProp) |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 147 | readValue(packet, mCurrentValue); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 148 | } |
Mike Lockwood | 564ff84 | 2010-09-25 08:37:59 -0400 | [diff] [blame] | 149 | if (!deviceProp) |
| 150 | mGroupCode = packet.getUInt32(); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 151 | 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 Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 165 | void MtpProperty::write(MtpDataPacket& packet) { |
Mike Lockwood | 564ff84 | 2010-09-25 08:37:59 -0400 | [diff] [blame] | 166 | bool deviceProp = isDeviceProperty(); |
| 167 | |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 168 | 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 Lockwood | 564ff84 | 2010-09-25 08:37:59 -0400 | [diff] [blame] | 184 | if (deviceProp) |
| 185 | writeArrayValues(packet, mCurrentArrayValues, mCurrentArrayLength); |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 186 | break; |
| 187 | default: |
| 188 | writeValue(packet, mDefaultValue); |
Mike Lockwood | 564ff84 | 2010-09-25 08:37:59 -0400 | [diff] [blame] | 189 | if (deviceProp) |
| 190 | writeValue(packet, mCurrentValue); |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 191 | } |
Mike Lockwood | 97c8d90 | 2010-08-09 14:49:28 -0400 | [diff] [blame] | 192 | packet.putUInt32(mGroupCode); |
Mike Lockwood | 564ff84 | 2010-09-25 08:37:59 -0400 | [diff] [blame] | 193 | if (!deviceProp) |
| 194 | packet.putUInt8(mFormFlag); |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 195 | 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 Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 206 | void 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 | |
| 216 | void 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 Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 226 | void MtpProperty::print() { |
Mike Lockwood | 456d8e6 | 2010-07-27 11:50:34 -0400 | [diff] [blame] | 227 | LOGV("MtpProperty %04X\n", mCode); |
| 228 | LOGV(" type %04X\n", mType); |
| 229 | LOGV(" writeable %s\n", (mWriteable ? "true" : "false")); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | void MtpProperty::readValue(MtpDataPacket& packet, MtpPropertyValue& value) { |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 233 | MtpStringBuffer stringBuffer; |
| 234 | |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 235 | switch (mType) { |
| 236 | case MTP_TYPE_INT8: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 237 | case MTP_TYPE_AINT8: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 238 | value.u.i8 = packet.getInt8(); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 239 | break; |
| 240 | case MTP_TYPE_UINT8: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 241 | case MTP_TYPE_AUINT8: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 242 | value.u.u8 = packet.getUInt8(); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 243 | break; |
| 244 | case MTP_TYPE_INT16: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 245 | case MTP_TYPE_AINT16: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 246 | value.u.i16 = packet.getInt16(); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 247 | break; |
| 248 | case MTP_TYPE_UINT16: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 249 | case MTP_TYPE_AUINT16: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 250 | value.u.u16 = packet.getUInt16(); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 251 | break; |
| 252 | case MTP_TYPE_INT32: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 253 | case MTP_TYPE_AINT32: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 254 | value.u.i32 = packet.getInt32(); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 255 | break; |
| 256 | case MTP_TYPE_UINT32: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 257 | case MTP_TYPE_AUINT32: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 258 | value.u.u32 = packet.getUInt32(); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 259 | break; |
| 260 | case MTP_TYPE_INT64: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 261 | case MTP_TYPE_AINT64: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 262 | value.u.i64 = packet.getInt64(); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 263 | break; |
| 264 | case MTP_TYPE_UINT64: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 265 | case MTP_TYPE_AUINT64: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 266 | value.u.u64 = packet.getUInt64(); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 267 | break; |
| 268 | case MTP_TYPE_INT128: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 269 | case MTP_TYPE_AINT128: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 270 | packet.getInt128(value.u.i128); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 271 | break; |
| 272 | case MTP_TYPE_UINT128: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 273 | case MTP_TYPE_AUINT128: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 274 | packet.getUInt128(value.u.u128); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 275 | break; |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 276 | case MTP_TYPE_STR: |
| 277 | packet.getString(stringBuffer); |
| 278 | value.str = strdup(stringBuffer); |
| 279 | break; |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 280 | default: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 281 | LOGE("unknown type %04X in MtpProperty::readValue", mType); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 285 | void MtpProperty::writeValue(MtpDataPacket& packet, MtpPropertyValue& value) { |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 286 | MtpStringBuffer stringBuffer; |
| 287 | |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 288 | switch (mType) { |
| 289 | case MTP_TYPE_INT8: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 290 | case MTP_TYPE_AINT8: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 291 | packet.putInt8(value.u.i8); |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 292 | break; |
| 293 | case MTP_TYPE_UINT8: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 294 | case MTP_TYPE_AUINT8: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 295 | packet.putUInt8(value.u.u8); |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 296 | break; |
| 297 | case MTP_TYPE_INT16: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 298 | case MTP_TYPE_AINT16: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 299 | packet.putInt16(value.u.i16); |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 300 | break; |
| 301 | case MTP_TYPE_UINT16: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 302 | case MTP_TYPE_AUINT16: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 303 | packet.putUInt16(value.u.u16); |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 304 | break; |
| 305 | case MTP_TYPE_INT32: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 306 | case MTP_TYPE_AINT32: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 307 | packet.putInt32(value.u.i32); |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 308 | break; |
| 309 | case MTP_TYPE_UINT32: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 310 | case MTP_TYPE_AUINT32: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 311 | packet.putUInt32(value.u.u32); |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 312 | break; |
| 313 | case MTP_TYPE_INT64: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 314 | case MTP_TYPE_AINT64: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 315 | packet.putInt64(value.u.i64); |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 316 | break; |
| 317 | case MTP_TYPE_UINT64: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 318 | case MTP_TYPE_AUINT64: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 319 | packet.putUInt64(value.u.u64); |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 320 | break; |
| 321 | case MTP_TYPE_INT128: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 322 | case MTP_TYPE_AINT128: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 323 | packet.putInt128(value.u.i128); |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 324 | break; |
| 325 | case MTP_TYPE_UINT128: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 326 | case MTP_TYPE_AUINT128: |
Mike Lockwood | a2a2128 | 2010-09-25 21:21:05 -0400 | [diff] [blame^] | 327 | packet.putUInt128(value.u.u128); |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 328 | break; |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 329 | case MTP_TYPE_STR: |
| 330 | if (value.str) |
| 331 | packet.putString(value.str); |
| 332 | else |
| 333 | packet.putEmptyString(); |
| 334 | break; |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 335 | default: |
Mike Lockwood | 9bbc2ea | 2010-07-20 09:47:41 -0400 | [diff] [blame] | 336 | LOGE("unknown type %04X in MtpProperty::writeValue", mType); |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 340 | MtpPropertyValue* MtpProperty::readArrayValues(MtpDataPacket& packet, int& length) { |
| 341 | length = packet.getUInt32(); |
| 342 | if (length == 0) |
| 343 | return NULL; |
| 344 | MtpPropertyValue* result = new MtpPropertyValue[length]; |
| 345 | for (int i = 0; i < length; i++) |
| 346 | readValue(packet, result[i]); |
| 347 | return result; |
| 348 | } |
| 349 | |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 350 | void MtpProperty::writeArrayValues(MtpDataPacket& packet, MtpPropertyValue* values, int length) { |
| 351 | packet.putUInt32(length); |
| 352 | for (int i = 0; i < length; i++) |
| 353 | writeValue(packet, values[i]); |
| 354 | } |
| 355 | |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 356 | } // namespace android |