blob: 2bdbfd32627d5c6438169022604fd403495eb1e1 [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 {
Shruti Bihani9d9c3162023-07-06 08:41:56 +000029 // pointer str initialized to NULL so that free operation
30 // is not called for pre-assigned value
31 MtpPropertyValue() : str (NULL) {}
Mike Lockwooddde37202010-09-25 21:21:05 -040032 union {
33 int8_t i8;
34 uint8_t u8;
35 int16_t i16;
36 uint16_t u16;
37 int32_t i32;
38 uint32_t u32;
39 int64_t i64;
40 uint64_t u64;
41 int128_t i128;
42 uint128_t u128;
43 } u;
44 // string in UTF8 format
45 char* str;
46};
47
Mike Lockwooda6c490b2010-06-05 22:45:01 -040048class MtpProperty {
49public:
50 MtpPropertyCode mCode;
51 MtpDataType mType;
52 bool mWriteable;
53 MtpPropertyValue mDefaultValue;
54 MtpPropertyValue mCurrentValue;
55
56 // for array types
Mike Lockwoodab063842014-11-12 14:20:06 -080057 uint32_t mDefaultArrayLength;
Mike Lockwooda6c490b2010-06-05 22:45:01 -040058 MtpPropertyValue* mDefaultArrayValues;
Mike Lockwoodab063842014-11-12 14:20:06 -080059 uint32_t mCurrentArrayLength;
Mike Lockwooda6c490b2010-06-05 22:45:01 -040060 MtpPropertyValue* mCurrentArrayValues;
61
62 enum {
63 kFormNone = 0,
64 kFormRange = 1,
65 kFormEnum = 2,
Mike Lockwoodb892d0e2010-11-23 18:38:55 -050066 kFormDateTime = 3,
Mike Lockwooda6c490b2010-06-05 22:45:01 -040067 };
Mike Lockwood2bb8c0e2010-08-09 14:49:28 -040068
69 uint32_t mGroupCode;
Mike Lockwooda6c490b2010-06-05 22:45:01 -040070 uint8_t mFormFlag;
71
72 // for range form
73 MtpPropertyValue mMinimumValue;
74 MtpPropertyValue mMaximumValue;
75 MtpPropertyValue mStepSize;
76
77 // for enum form
Mike Lockwoodab063842014-11-12 14:20:06 -080078 uint16_t mEnumLength;
Mike Lockwooda6c490b2010-06-05 22:45:01 -040079 MtpPropertyValue* mEnumValues;
80
81public:
82 MtpProperty();
Mike Lockwood21ef7d02010-06-30 17:00:35 -040083 MtpProperty(MtpPropertyCode propCode,
84 MtpDataType type,
85 bool writeable = false,
86 int defaultValue = 0);
Mike Lockwooda6c490b2010-06-05 22:45:01 -040087 virtual ~MtpProperty();
88
Daichi Hirono66a9abe2016-03-24 20:56:13 +090089 MtpPropertyCode getPropertyCode() const { return mCode; }
90 MtpDataType getDataType() const { return mType; }
Mike Lockwood21ef7d02010-06-30 17:00:35 -040091
Mike Lockwoodab063842014-11-12 14:20:06 -080092 bool read(MtpDataPacket& packet);
Mike Lockwood21ef7d02010-06-30 17:00:35 -040093 void write(MtpDataPacket& packet);
Mike Lockwooda6c490b2010-06-05 22:45:01 -040094
Mike Lockwooddde37202010-09-25 21:21:05 -040095 void setDefaultValue(const uint16_t* string);
96 void setCurrentValue(const uint16_t* string);
James Wei8d96aa82021-06-19 20:48:10 +080097 void setCurrentValue(const char* string);
Daichi Hirono66a9abe2016-03-24 20:56:13 +090098 void setCurrentValue(MtpDataPacket& packet);
99 const MtpPropertyValue& getCurrentValue() { return mCurrentValue; }
Mike Lockwooddde37202010-09-25 21:21:05 -0400100
Mike Lockwood01817262010-11-10 12:48:39 -0500101 void setFormRange(int min, int max, int step);
102 void setFormEnum(const int* values, int count);
Mike Lockwoodb892d0e2010-11-23 18:38:55 -0500103 void setFormDateTime();
Mike Lockwood01817262010-11-10 12:48:39 -0500104
Mike Lockwooda6c490b2010-06-05 22:45:01 -0400105 void print();
106
Mike Lockwoode3e76c42010-09-02 14:57:30 -0400107 inline bool isDeviceProperty() const {
108 return ( ((mCode & 0xF000) == 0x5000)
109 || ((mCode & 0xF800) == 0xD000));
110 }
111
Mike Lockwooda6c490b2010-06-05 22:45:01 -0400112private:
Mike Lockwoodab063842014-11-12 14:20:06 -0800113 bool readValue(MtpDataPacket& packet, MtpPropertyValue& value);
Mike Lockwood21ef7d02010-06-30 17:00:35 -0400114 void writeValue(MtpDataPacket& packet, MtpPropertyValue& value);
Mike Lockwoodab063842014-11-12 14:20:06 -0800115 MtpPropertyValue* readArrayValues(MtpDataPacket& packet, uint32_t& length);
Mike Lockwoode3e76c42010-09-02 14:57:30 -0400116 void writeArrayValues(MtpDataPacket& packet,
Mike Lockwoodab063842014-11-12 14:20:06 -0800117 MtpPropertyValue* values, uint32_t length);
Jerry Zhangbc1d4b42018-03-27 15:25:03 -0700118 void print(MtpPropertyValue& value, std::string& buffer);
Mike Lockwooda6c490b2010-06-05 22:45:01 -0400119};
120
121}; // namespace android
122
123#endif // _MTP_PROPERTY_H