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