blob: 50192d73025cbb3feb948e62bd17ce92b9fc9383 [file] [log] [blame]
bigbiff bigbiffc7eee6f2014-09-02 18:59: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 * Copyright (C) 2014 TeamWin - bigbiff and Dees_Troy mtp database conversion to C++
17 */
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
56void MtpObjectInfo::read(MtpDataPacket& packet) {
57 MtpStringBuffer string;
58 time_t time;
59
60 mStorageID = packet.getUInt32();
61 mFormat = packet.getUInt16();
62 mProtectionStatus = packet.getUInt16();
63 mCompressedSize = packet.getUInt32();
64 mThumbFormat = packet.getUInt16();
65 mThumbCompressedSize = packet.getUInt32();
66 mThumbPixWidth = packet.getUInt32();
67 mThumbPixHeight = packet.getUInt32();
68 mImagePixWidth = packet.getUInt32();
69 mImagePixHeight = packet.getUInt32();
70 mImagePixDepth = packet.getUInt32();
71 mParent = packet.getUInt32();
72 mAssociationType = packet.getUInt16();
73 mAssociationDesc = packet.getUInt32();
74 mSequenceNumber = packet.getUInt32();
75
76 packet.getString(string);
77 mName = strdup((const char *)string);
78
79 packet.getString(string);
80 if (parseDateTime((const char*)string, time))
81 mDateCreated = time;
82
83 packet.getString(string);
84 if (parseDateTime((const char*)string, time))
85 mDateModified = time;
86
87 packet.getString(string);
88 mKeywords = strdup((const char *)string);
89}
90
91void MtpObjectInfo::print() {
92 MTPI("MtpObject Info %08X: %s\n", mHandle, mName);
93 MTPI(" mStorageID: %08X mFormat: %04X mProtectionStatus: %d\n",
94 mStorageID, mFormat, mProtectionStatus);
95 MTPI(" mCompressedSize: %d mThumbFormat: %04X mThumbCompressedSize: %d\n",
96 mCompressedSize, mFormat, mThumbCompressedSize);
97 MTPI(" mThumbPixWidth: %d mThumbPixHeight: %d\n", mThumbPixWidth, mThumbPixHeight);
98 MTPI(" mImagePixWidth: %d mImagePixHeight: %d mImagePixDepth: %d\n",
99 mImagePixWidth, mImagePixHeight, mImagePixDepth);
100 MTPI(" mParent: %08X mAssociationType: %04X mAssociationDesc: %04X\n",
101 mParent, mAssociationType, mAssociationDesc);
102 MTPI(" mSequenceNumber: %d mDateCreated: %ld mDateModified: %ld mKeywords: %s\n",
103 mSequenceNumber, mDateCreated, mDateModified, mKeywords);
104}
105