MtpProperty.h revision 2bb8c0e7c4e4093f4161ff5e98cef51c87193859
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, bool deviceProp); 69 void write(MtpDataPacket& packet); 70 71 void print(); 72 73private: 74 void readValue(MtpDataPacket& packet, MtpPropertyValue& value); 75 void writeValue(MtpDataPacket& packet, MtpPropertyValue& value); 76 MtpPropertyValue* readArrayValues(MtpDataPacket& packet, int& length); 77 void writeArrayValues(MtpDataPacket& packet, MtpPropertyValue* values, int length); 78}; 79 80}; // namespace android 81 82#endif // _MTP_PROPERTY_H 83