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