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 | |
| 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 | }; |
Mike Lockwood | 97c8d90 | 2010-08-09 14:49:28 -0400 | [diff] [blame] | 45 | |
| 46 | uint32_t mGroupCode; |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 47 | uint8_t mFormFlag; |
| 48 | |
| 49 | // for range form |
| 50 | MtpPropertyValue mMinimumValue; |
| 51 | MtpPropertyValue mMaximumValue; |
| 52 | MtpPropertyValue mStepSize; |
| 53 | |
| 54 | // for enum form |
| 55 | int mEnumLength; |
| 56 | MtpPropertyValue* mEnumValues; |
| 57 | |
| 58 | public: |
| 59 | MtpProperty(); |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 60 | MtpProperty(MtpPropertyCode propCode, |
| 61 | MtpDataType type, |
| 62 | bool writeable = false, |
| 63 | int defaultValue = 0); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 64 | virtual ~MtpProperty(); |
| 65 | |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 66 | inline MtpPropertyCode getPropertyCode() const { return mCode; } |
| 67 | |
Mike Lockwood | 59e3f0d | 2010-09-02 14:57:30 -0400 | [diff] [blame] | 68 | void read(MtpDataPacket& packet); |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 69 | void write(MtpDataPacket& packet); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 70 | |
| 71 | void print(); |
| 72 | |
Mike Lockwood | 59e3f0d | 2010-09-02 14:57:30 -0400 | [diff] [blame] | 73 | inline bool isDeviceProperty() const { |
| 74 | return ( ((mCode & 0xF000) == 0x5000) |
| 75 | || ((mCode & 0xF800) == 0xD000)); |
| 76 | } |
| 77 | |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 78 | private: |
| 79 | void readValue(MtpDataPacket& packet, MtpPropertyValue& value); |
Mike Lockwood | 767c5e4 | 2010-06-30 17:00:35 -0400 | [diff] [blame] | 80 | void writeValue(MtpDataPacket& packet, MtpPropertyValue& value); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 81 | MtpPropertyValue* readArrayValues(MtpDataPacket& packet, int& length); |
Mike Lockwood | 59e3f0d | 2010-09-02 14:57:30 -0400 | [diff] [blame] | 82 | void writeArrayValues(MtpDataPacket& packet, |
| 83 | MtpPropertyValue* values, int length); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | }; // namespace android |
| 87 | |
| 88 | #endif // _MTP_PROPERTY_H |