MtpObjectInfo.cpp revision e13401bf532c7e4bf9ab82c7e9b13642838a927d
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#include <stdlib.h>
18
19#include "MtpDataPacket.h"
20#include "MtpObjectInfo.h"
21#include "MtpStringBuffer.h"
22#include "MtpUtils.h"
23
24namespace android {
25
26MtpObjectInfo::MtpObjectInfo(MtpObjectHandle handle)
27    :   mHandle(handle),
28        mStorageID(0),
29        mFormat(0),
30        mProtectionStatus(0),
31        mCompressedSize(0),
32        mThumbFormat(0),
33        mThumbCompressedSize(0),
34        mThumbPixWidth(0),
35        mThumbPixHeight(0),
36        mImagePixWidth(0),
37        mImagePixHeight(0),
38        mImagePixDepth(0),
39        mParent(0),
40        mAssociationType(0),
41        mAssociationDesc(0),
42        mSequenceNumber(0),
43        mName(NULL),
44        mDateCreated(0),
45        mDateModified(0),
46        mKeywords(NULL)
47{
48}
49
50MtpObjectInfo::~MtpObjectInfo() {
51    if (mName)
52        free(mName);
53    if (mKeywords)
54        free(mKeywords);
55}
56
57void MtpObjectInfo::read(MtpDataPacket& packet) {
58    MtpStringBuffer string;
59    time_t time;
60
61    mStorageID = packet.getUInt32();
62    mFormat = packet.getUInt16();
63    mProtectionStatus = packet.getUInt16();
64    mCompressedSize = packet.getUInt32();
65    mThumbFormat = packet.getUInt16();
66    mCompressedSize = packet.getUInt32();
67    mThumbPixWidth = packet.getUInt32();
68    mThumbPixHeight = packet.getUInt32();
69    mImagePixWidth = packet.getUInt32();
70    mImagePixHeight = packet.getUInt32();
71    mImagePixDepth = packet.getUInt32();
72    mParent = packet.getUInt32();
73    mAssociationType = packet.getUInt16();
74    mAssociationDesc = packet.getUInt32();
75    mSequenceNumber = packet.getUInt32();
76
77    packet.getString(string);
78    mName = strdup((const char *)string);
79
80    packet.getString(string);
81    if (parseDateTime((const char*)string, time))
82        mDateCreated = time;
83
84    packet.getString(string);
85    if (parseDateTime((const char*)string, time))
86        mDateModified = time;
87
88    packet.getString(string);
89    mKeywords = strdup((const char *)string);
90}
91
92void MtpObjectInfo::print() {
93    printf("MtpObject Info %08X: %s\n", mHandle, mName);
94}
95
96}  // namespace android
97