blob: 017d875671ead605e6482b7c323f5a63a0f0dcb8 [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#ifndef _MTP_PROPERTY_H
20#define _MTP_PROPERTY_H
21
22#include "MtpTypes.h"
23
24
25class MtpDataPacket;
26
27struct MtpPropertyValue {
28 union {
29 int8_t i8;
30 uint8_t u8;
31 int16_t i16;
32 uint16_t u16;
33 int32_t i32;
34 uint32_t u32;
35 int64_t i64;
36 uint64_t u64;
37 int128_t i128;
38 uint128_t u128;
39 } u;
40 // string in UTF8 format
41 char* str;
42};
43
44class MtpProperty {
45public:
46 MtpPropertyCode mCode;
47 MtpDataType mType;
48 bool mWriteable;
49 MtpPropertyValue mDefaultValue;
50 MtpPropertyValue mCurrentValue;
51
52 // for array types
53 int mDefaultArrayLength;
54 MtpPropertyValue* mDefaultArrayValues;
55 int mCurrentArrayLength;
56 MtpPropertyValue* mCurrentArrayValues;
57
58 enum {
59 kFormNone = 0,
60 kFormRange = 1,
61 kFormEnum = 2,
62 kFormDateTime = 3,
63 };
64
65 uint32_t mGroupCode;
66 uint8_t mFormFlag;
67
68 // for range form
69 MtpPropertyValue mMinimumValue;
70 MtpPropertyValue mMaximumValue;
71 MtpPropertyValue mStepSize;
72
73 // for enum form
74 int mEnumLength;
75 MtpPropertyValue* mEnumValues;
76
77public:
78 MtpProperty();
79 MtpProperty(MtpPropertyCode propCode,
80 MtpDataType type,
81 bool writeable = false,
82 int defaultValue = 0);
83 virtual ~MtpProperty();
84
85 inline MtpPropertyCode getPropertyCode() const { return mCode; }
86
87 void read(MtpDataPacket& packet);
88 void write(MtpDataPacket& packet);
89
90 void setDefaultValue(const uint16_t* string);
91 void setCurrentValue(const uint16_t* string);
92
93 void setFormRange(int min, int max, int step);
94 void setFormEnum(const int* values, int count);
95 void setFormDateTime();
96
97 void print();
98 void print(MtpPropertyValue& value, MtpString& buffer);
99
100 inline bool isDeviceProperty() const {
101 return ( ((mCode & 0xF000) == 0x5000)
102 || ((mCode & 0xF800) == 0xD000));
103 }
104
105private:
106 void readValue(MtpDataPacket& packet, MtpPropertyValue& value);
107 void writeValue(MtpDataPacket& packet, MtpPropertyValue& value);
108 MtpPropertyValue* readArrayValues(MtpDataPacket& packet, int& length);
109 void writeArrayValues(MtpDataPacket& packet,
110 MtpPropertyValue* values, int length);
111};
112
113
114#endif // _MTP_PROPERTY_H