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 | |
| 22 | namespace android { |
| 23 | |
| 24 | class MtpDataPacket; |
| 25 | |
| 26 | class MtpProperty { |
| 27 | public: |
| 28 | MtpPropertyCode mCode; |
| 29 | MtpDataType mType; |
| 30 | bool mWriteable; |
| 31 | MtpPropertyValue mDefaultValue; |
| 32 | MtpPropertyValue mCurrentValue; |
| 33 | |
| 34 | // for array types |
| 35 | int mDefaultArrayLength; |
| 36 | MtpPropertyValue* mDefaultArrayValues; |
| 37 | int mCurrentArrayLength; |
| 38 | MtpPropertyValue* mCurrentArrayValues; |
| 39 | |
| 40 | enum { |
| 41 | kFormNone = 0, |
| 42 | kFormRange = 1, |
| 43 | kFormEnum = 2, |
| 44 | }; |
| 45 | uint8_t mFormFlag; |
| 46 | |
| 47 | // for range form |
| 48 | MtpPropertyValue mMinimumValue; |
| 49 | MtpPropertyValue mMaximumValue; |
| 50 | MtpPropertyValue mStepSize; |
| 51 | |
| 52 | // for enum form |
| 53 | int mEnumLength; |
| 54 | MtpPropertyValue* mEnumValues; |
| 55 | |
| 56 | public: |
| 57 | MtpProperty(); |
Mike Lockwood | 21ef7d0 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 58 | MtpProperty(MtpPropertyCode propCode, |
| 59 | MtpDataType type, |
| 60 | bool writeable = false, |
| 61 | int defaultValue = 0); |
Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 62 | virtual ~MtpProperty(); |
| 63 | |
Mike Lockwood | 21ef7d0 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 64 | inline MtpPropertyCode getPropertyCode() const { return mCode; } |
| 65 | |
| 66 | void read(MtpDataPacket& packet, bool deviceProp); |
| 67 | void write(MtpDataPacket& packet); |
Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 68 | |
| 69 | void print(); |
| 70 | |
| 71 | private: |
| 72 | void readValue(MtpDataPacket& packet, MtpPropertyValue& value); |
Mike Lockwood | 21ef7d0 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 73 | void writeValue(MtpDataPacket& packet, MtpPropertyValue& value); |
Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 74 | MtpPropertyValue* readArrayValues(MtpDataPacket& packet, int& length); |
Mike Lockwood | 21ef7d0 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 75 | void writeArrayValues(MtpDataPacket& packet, MtpPropertyValue* values, int length); |
Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | }; // namespace android |
| 79 | |
| 80 | #endif // _MTP_PROPERTY_H |