blob: bfd5f7f59ad61f4a553e3f200cd8b69f2d3735f8 [file] [log] [blame]
Mike Lockwooda6c490b2010-06-05 22:45: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
17#ifndef _MTP_PROPERTY_H
18#define _MTP_PROPERTY_H
19
20#include "MtpTypes.h"
21
Jerry Zhangbc1d4b42018-03-27 15:25:03 -070022#include <string>
23
Mike Lockwooda6c490b2010-06-05 22:45:01 -040024namespace android {
25
26class MtpDataPacket;
27
Mike Lockwooddde37202010-09-25 21:21:05 -040028struct MtpPropertyValue {
29 union {
30 int8_t i8;
31 uint8_t u8;
32 int16_t i16;
33 uint16_t u16;
34 int32_t i32;
35 uint32_t u32;
36 int64_t i64;
37 uint64_t u64;
38 int128_t i128;
39 uint128_t u128;
40 } u;
41 // string in UTF8 format
42 char* str;
43};
44
Mike Lockwooda6c490b2010-06-05 22:45:01 -040045class MtpProperty {
46public:
47 MtpPropertyCode mCode;
48 MtpDataType mType;
49 bool mWriteable;
50 MtpPropertyValue mDefaultValue;
51 MtpPropertyValue mCurrentValue;
52
53 // for array types
Mike Lockwoodab063842014-11-12 14:20:06 -080054 uint32_t mDefaultArrayLength;
Mike Lockwooda6c490b2010-06-05 22:45:01 -040055 MtpPropertyValue* mDefaultArrayValues;
Mike Lockwoodab063842014-11-12 14:20:06 -080056 uint32_t mCurrentArrayLength;
Mike Lockwooda6c490b2010-06-05 22:45:01 -040057 MtpPropertyValue* mCurrentArrayValues;
58
59 enum {
60 kFormNone = 0,
61 kFormRange = 1,
62 kFormEnum = 2,
Mike Lockwoodb892d0e2010-11-23 18:38:55 -050063 kFormDateTime = 3,
Mike Lockwooda6c490b2010-06-05 22:45:01 -040064 };
Mike Lockwood2bb8c0e2010-08-09 14:49:28 -040065
66 uint32_t mGroupCode;
Mike Lockwooda6c490b2010-06-05 22:45:01 -040067 uint8_t mFormFlag;
68
69 // for range form
70 MtpPropertyValue mMinimumValue;
71 MtpPropertyValue mMaximumValue;
72 MtpPropertyValue mStepSize;
73
74 // for enum form
Mike Lockwoodab063842014-11-12 14:20:06 -080075 uint16_t mEnumLength;
Mike Lockwooda6c490b2010-06-05 22:45:01 -040076 MtpPropertyValue* mEnumValues;
77
78public:
79 MtpProperty();
Mike Lockwood21ef7d02010-06-30 17:00:35 -040080 MtpProperty(MtpPropertyCode propCode,
81 MtpDataType type,
82 bool writeable = false,
83 int defaultValue = 0);
Mike Lockwooda6c490b2010-06-05 22:45:01 -040084 virtual ~MtpProperty();
85
Daichi Hirono66a9abe2016-03-24 20:56:13 +090086 MtpPropertyCode getPropertyCode() const { return mCode; }
87 MtpDataType getDataType() const { return mType; }
Mike Lockwood21ef7d02010-06-30 17:00:35 -040088
Mike Lockwoodab063842014-11-12 14:20:06 -080089 bool read(MtpDataPacket& packet);
Mike Lockwood21ef7d02010-06-30 17:00:35 -040090 void write(MtpDataPacket& packet);
Mike Lockwooda6c490b2010-06-05 22:45:01 -040091
Mike Lockwooddde37202010-09-25 21:21:05 -040092 void setDefaultValue(const uint16_t* string);
93 void setCurrentValue(const uint16_t* string);
Daichi Hirono66a9abe2016-03-24 20:56:13 +090094 void setCurrentValue(MtpDataPacket& packet);
95 const MtpPropertyValue& getCurrentValue() { return mCurrentValue; }
Mike Lockwooddde37202010-09-25 21:21:05 -040096
Mike Lockwood01817262010-11-10 12:48:39 -050097 void setFormRange(int min, int max, int step);
98 void setFormEnum(const int* values, int count);
Mike Lockwoodb892d0e2010-11-23 18:38:55 -050099 void setFormDateTime();
Mike Lockwood01817262010-11-10 12:48:39 -0500100
Mike Lockwooda6c490b2010-06-05 22:45:01 -0400101 void print();
102
Mike Lockwoode3e76c42010-09-02 14:57:30 -0400103 inline bool isDeviceProperty() const {
104 return ( ((mCode & 0xF000) == 0x5000)
105 || ((mCode & 0xF800) == 0xD000));
106 }
107
Mike Lockwooda6c490b2010-06-05 22:45:01 -0400108private:
Mike Lockwoodab063842014-11-12 14:20:06 -0800109 bool readValue(MtpDataPacket& packet, MtpPropertyValue& value);
Mike Lockwood21ef7d02010-06-30 17:00:35 -0400110 void writeValue(MtpDataPacket& packet, MtpPropertyValue& value);
Mike Lockwoodab063842014-11-12 14:20:06 -0800111 MtpPropertyValue* readArrayValues(MtpDataPacket& packet, uint32_t& length);
Mike Lockwoode3e76c42010-09-02 14:57:30 -0400112 void writeArrayValues(MtpDataPacket& packet,
Mike Lockwoodab063842014-11-12 14:20:06 -0800113 MtpPropertyValue* values, uint32_t length);
Jerry Zhangbc1d4b42018-03-27 15:25:03 -0700114 void print(MtpPropertyValue& value, std::string& buffer);
Mike Lockwooda6c490b2010-06-05 22:45:01 -0400115};
116
117}; // namespace android
118
119#endif // _MTP_PROPERTY_H