Mike Lockwood | e13401b | 2010-05-19 15:12:14 -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 | |
Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 17 | #define LOG_TAG "MtpObjectInfo" |
Mike Lockwood | e13401b | 2010-05-19 15:12:14 -0400 | [diff] [blame] | 18 | |
Mike Lockwood | b14e588 | 2010-06-29 18:11:52 -0400 | [diff] [blame] | 19 | #include "MtpDebug.h" |
Mike Lockwood | e13401b | 2010-05-19 15:12:14 -0400 | [diff] [blame] | 20 | #include "MtpDataPacket.h" |
| 21 | #include "MtpObjectInfo.h" |
| 22 | #include "MtpStringBuffer.h" |
| 23 | #include "MtpUtils.h" |
| 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | MtpObjectInfo::MtpObjectInfo(MtpObjectHandle handle) |
| 28 | : mHandle(handle), |
| 29 | mStorageID(0), |
| 30 | mFormat(0), |
| 31 | mProtectionStatus(0), |
| 32 | mCompressedSize(0), |
| 33 | mThumbFormat(0), |
| 34 | mThumbCompressedSize(0), |
| 35 | mThumbPixWidth(0), |
| 36 | mThumbPixHeight(0), |
| 37 | mImagePixWidth(0), |
| 38 | mImagePixHeight(0), |
| 39 | mImagePixDepth(0), |
| 40 | mParent(0), |
| 41 | mAssociationType(0), |
| 42 | mAssociationDesc(0), |
| 43 | mSequenceNumber(0), |
| 44 | mName(NULL), |
| 45 | mDateCreated(0), |
| 46 | mDateModified(0), |
| 47 | mKeywords(NULL) |
| 48 | { |
| 49 | } |
| 50 | |
| 51 | MtpObjectInfo::~MtpObjectInfo() { |
| 52 | if (mName) |
| 53 | free(mName); |
| 54 | if (mKeywords) |
| 55 | free(mKeywords); |
| 56 | } |
| 57 | |
Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame^] | 58 | bool MtpObjectInfo::read(MtpDataPacket& packet) { |
Mike Lockwood | e13401b | 2010-05-19 15:12:14 -0400 | [diff] [blame] | 59 | MtpStringBuffer string; |
| 60 | time_t time; |
| 61 | |
Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame^] | 62 | if (!packet.getUInt32(mStorageID)) return false; |
| 63 | if (!packet.getUInt16(mFormat)) return false; |
| 64 | if (!packet.getUInt16(mProtectionStatus)) return false; |
| 65 | if (!packet.getUInt32(mCompressedSize)) return false; |
| 66 | if (!packet.getUInt16(mThumbFormat)) return false; |
| 67 | if (!packet.getUInt32(mThumbCompressedSize)) return false; |
| 68 | if (!packet.getUInt32(mThumbPixWidth)) return false; |
| 69 | if (!packet.getUInt32(mThumbPixHeight)) return false; |
| 70 | if (!packet.getUInt32(mImagePixWidth)) return false; |
| 71 | if (!packet.getUInt32(mImagePixHeight)) return false; |
| 72 | if (!packet.getUInt32(mImagePixDepth)) return false; |
| 73 | if (!packet.getUInt32(mParent)) return false; |
| 74 | if (!packet.getUInt16(mAssociationType)) return false; |
| 75 | if (!packet.getUInt32(mAssociationDesc)) return false; |
| 76 | if (!packet.getUInt32(mSequenceNumber)) return false; |
Mike Lockwood | e13401b | 2010-05-19 15:12:14 -0400 | [diff] [blame] | 77 | |
Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame^] | 78 | if (!packet.getString(string)) return false; |
Mike Lockwood | e13401b | 2010-05-19 15:12:14 -0400 | [diff] [blame] | 79 | mName = strdup((const char *)string); |
| 80 | |
Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame^] | 81 | if (!packet.getString(string)) return false; |
Mike Lockwood | e13401b | 2010-05-19 15:12:14 -0400 | [diff] [blame] | 82 | if (parseDateTime((const char*)string, time)) |
| 83 | mDateCreated = time; |
| 84 | |
Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame^] | 85 | if (!packet.getString(string)) return false; |
Mike Lockwood | e13401b | 2010-05-19 15:12:14 -0400 | [diff] [blame] | 86 | if (parseDateTime((const char*)string, time)) |
| 87 | mDateModified = time; |
| 88 | |
Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame^] | 89 | if (!packet.getString(string)) return false; |
Mike Lockwood | e13401b | 2010-05-19 15:12:14 -0400 | [diff] [blame] | 90 | mKeywords = strdup((const char *)string); |
Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame^] | 91 | |
| 92 | return true; |
Mike Lockwood | e13401b | 2010-05-19 15:12:14 -0400 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void MtpObjectInfo::print() { |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 96 | ALOGD("MtpObject Info %08X: %s\n", mHandle, mName); |
| 97 | ALOGD(" mStorageID: %08X mFormat: %04X mProtectionStatus: %d\n", |
Mike Lockwood | 0ef2bf5 | 2010-06-08 07:33:14 -0400 | [diff] [blame] | 98 | mStorageID, mFormat, mProtectionStatus); |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 99 | ALOGD(" mCompressedSize: %d mThumbFormat: %04X mThumbCompressedSize: %d\n", |
Mike Lockwood | 0ef2bf5 | 2010-06-08 07:33:14 -0400 | [diff] [blame] | 100 | mCompressedSize, mFormat, mThumbCompressedSize); |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 101 | ALOGD(" mThumbPixWidth: %d mThumbPixHeight: %d\n", mThumbPixWidth, mThumbPixHeight); |
| 102 | ALOGD(" mImagePixWidth: %d mImagePixHeight: %d mImagePixDepth: %d\n", |
Mike Lockwood | 0ef2bf5 | 2010-06-08 07:33:14 -0400 | [diff] [blame] | 103 | mImagePixWidth, mImagePixHeight, mImagePixDepth); |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 104 | ALOGD(" mParent: %08X mAssociationType: %04X mAssociationDesc: %04X\n", |
Mike Lockwood | 0ef2bf5 | 2010-06-08 07:33:14 -0400 | [diff] [blame] | 105 | mParent, mAssociationType, mAssociationDesc); |
Steve Block | b8a8052 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 106 | ALOGD(" mSequenceNumber: %d mDateCreated: %ld mDateModified: %ld mKeywords: %s\n", |
Mike Lockwood | 0ef2bf5 | 2010-06-08 07:33:14 -0400 | [diff] [blame] | 107 | mSequenceNumber, mDateCreated, mDateModified, mKeywords); |
Mike Lockwood | e13401b | 2010-05-19 15:12:14 -0400 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | } // namespace android |