| Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 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 | #ifndef _MTP_PROPERTY_H |
| 18 | #define _MTP_PROPERTY_H |
| 19 | |
| 20 | #include "MtpTypes.h" |
| 21 | |
| Jerry Zhang | bc1d4b4 | 2018-03-27 15:25:03 -0700 | [diff] [blame] | 22 | #include <string> |
| 23 | |
| Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 24 | namespace android { |
| 25 | |
| 26 | class MtpDataPacket; |
| 27 | |
| Mike Lockwood | dde3720 | 2010-09-25 21:21:05 -0400 | [diff] [blame] | 28 | struct MtpPropertyValue { |
| Shruti Bihani | 9d9c316 | 2023-07-06 08:41:56 +0000 | [diff] [blame] | 29 | // pointer str initialized to NULL so that free operation |
| 30 | // is not called for pre-assigned value |
| 31 | MtpPropertyValue() : str (NULL) {} |
| Mike Lockwood | dde3720 | 2010-09-25 21:21:05 -0400 | [diff] [blame] | 32 | 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 Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 48 | class MtpProperty { |
| 49 | public: |
| 50 | MtpPropertyCode mCode; |
| 51 | MtpDataType mType; |
| 52 | bool mWriteable; |
| 53 | MtpPropertyValue mDefaultValue; |
| 54 | MtpPropertyValue mCurrentValue; |
| 55 | |
| 56 | // for array types |
| Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame] | 57 | uint32_t mDefaultArrayLength; |
| Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 58 | MtpPropertyValue* mDefaultArrayValues; |
| Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame] | 59 | uint32_t mCurrentArrayLength; |
| Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 60 | MtpPropertyValue* mCurrentArrayValues; |
| 61 | |
| 62 | enum { |
| 63 | kFormNone = 0, |
| 64 | kFormRange = 1, |
| 65 | kFormEnum = 2, |
| Mike Lockwood | b892d0e | 2010-11-23 18:38:55 -0500 | [diff] [blame] | 66 | kFormDateTime = 3, |
| Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 67 | }; |
| Mike Lockwood | 2bb8c0e | 2010-08-09 14:49:28 -0400 | [diff] [blame] | 68 | |
| 69 | uint32_t mGroupCode; |
| Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 70 | uint8_t mFormFlag; |
| 71 | |
| 72 | // for range form |
| 73 | MtpPropertyValue mMinimumValue; |
| 74 | MtpPropertyValue mMaximumValue; |
| 75 | MtpPropertyValue mStepSize; |
| 76 | |
| 77 | // for enum form |
| Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame] | 78 | uint16_t mEnumLength; |
| Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 79 | MtpPropertyValue* mEnumValues; |
| 80 | |
| 81 | public: |
| 82 | MtpProperty(); |
| Mike Lockwood | 21ef7d0 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 83 | MtpProperty(MtpPropertyCode propCode, |
| 84 | MtpDataType type, |
| 85 | bool writeable = false, |
| 86 | int defaultValue = 0); |
| Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 87 | virtual ~MtpProperty(); |
| 88 | |
| Daichi Hirono | 66a9abe | 2016-03-24 20:56:13 +0900 | [diff] [blame] | 89 | MtpPropertyCode getPropertyCode() const { return mCode; } |
| 90 | MtpDataType getDataType() const { return mType; } |
| Mike Lockwood | 21ef7d0 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 91 | |
| Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame] | 92 | bool read(MtpDataPacket& packet); |
| Mike Lockwood | 21ef7d0 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 93 | void write(MtpDataPacket& packet); |
| Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 94 | |
| Mike Lockwood | dde3720 | 2010-09-25 21:21:05 -0400 | [diff] [blame] | 95 | void setDefaultValue(const uint16_t* string); |
| 96 | void setCurrentValue(const uint16_t* string); |
| James Wei | 8d96aa8 | 2021-06-19 20:48:10 +0800 | [diff] [blame] | 97 | void setCurrentValue(const char* string); |
| Daichi Hirono | 66a9abe | 2016-03-24 20:56:13 +0900 | [diff] [blame] | 98 | void setCurrentValue(MtpDataPacket& packet); |
| 99 | const MtpPropertyValue& getCurrentValue() { return mCurrentValue; } |
| Mike Lockwood | dde3720 | 2010-09-25 21:21:05 -0400 | [diff] [blame] | 100 | |
| Mike Lockwood | 0181726 | 2010-11-10 12:48:39 -0500 | [diff] [blame] | 101 | void setFormRange(int min, int max, int step); |
| 102 | void setFormEnum(const int* values, int count); |
| Mike Lockwood | b892d0e | 2010-11-23 18:38:55 -0500 | [diff] [blame] | 103 | void setFormDateTime(); |
| Mike Lockwood | 0181726 | 2010-11-10 12:48:39 -0500 | [diff] [blame] | 104 | |
| Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 105 | void print(); |
| 106 | |
| Mike Lockwood | e3e76c4 | 2010-09-02 14:57:30 -0400 | [diff] [blame] | 107 | inline bool isDeviceProperty() const { |
| 108 | return ( ((mCode & 0xF000) == 0x5000) |
| 109 | || ((mCode & 0xF800) == 0xD000)); |
| 110 | } |
| 111 | |
| Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 112 | private: |
| Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame] | 113 | bool readValue(MtpDataPacket& packet, MtpPropertyValue& value); |
| Mike Lockwood | 21ef7d0 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 114 | void writeValue(MtpDataPacket& packet, MtpPropertyValue& value); |
| Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame] | 115 | MtpPropertyValue* readArrayValues(MtpDataPacket& packet, uint32_t& length); |
| Mike Lockwood | e3e76c4 | 2010-09-02 14:57:30 -0400 | [diff] [blame] | 116 | void writeArrayValues(MtpDataPacket& packet, |
| Mike Lockwood | ab06384 | 2014-11-12 14:20:06 -0800 | [diff] [blame] | 117 | MtpPropertyValue* values, uint32_t length); |
| Jerry Zhang | bc1d4b4 | 2018-03-27 15:25:03 -0700 | [diff] [blame] | 118 | void print(MtpPropertyValue& value, std::string& buffer); |
| Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 119 | }; |
| 120 | |
| 121 | }; // namespace android |
| 122 | |
| 123 | #endif // _MTP_PROPERTY_H |