MtpProperty.h revision e3e76c456baee122de6715ae280130abaddc906c
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 22namespace android { 23 24class MtpDataPacket; 25 26class MtpProperty { 27public: 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 46 uint32_t mGroupCode; 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 58public: 59 MtpProperty(); 60 MtpProperty(MtpPropertyCode propCode, 61 MtpDataType type, 62 bool writeable = false, 63 int defaultValue = 0); 64 virtual ~MtpProperty(); 65 66 inline MtpPropertyCode getPropertyCode() const { return mCode; } 67 68 void read(MtpDataPacket& packet); 69 void write(MtpDataPacket& packet); 70 71 void print(); 72 73 inline bool isDeviceProperty() const { 74 return ( ((mCode & 0xF000) == 0x5000) 75 || ((mCode & 0xF800) == 0xD000)); 76 } 77 78private: 79 void readValue(MtpDataPacket& packet, MtpPropertyValue& value); 80 void writeValue(MtpDataPacket& packet, MtpPropertyValue& value); 81 MtpPropertyValue* readArrayValues(MtpDataPacket& packet, int& length); 82 void writeArrayValues(MtpDataPacket& packet, 83 MtpPropertyValue* values, int length); 84}; 85 86}; // namespace android 87 88#endif // _MTP_PROPERTY_H 89