MtpProperty.h revision 0181726d0cc2d0fc6f6a53b6479dcf0fc41b9499
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 26struct 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 43class MtpProperty { 44public: 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, 61 }; 62 63 uint32_t mGroupCode; 64 uint8_t mFormFlag; 65 66 // for range form 67 MtpPropertyValue mMinimumValue; 68 MtpPropertyValue mMaximumValue; 69 MtpPropertyValue mStepSize; 70 71 // for enum form 72 int mEnumLength; 73 MtpPropertyValue* mEnumValues; 74 75public: 76 MtpProperty(); 77 MtpProperty(MtpPropertyCode propCode, 78 MtpDataType type, 79 bool writeable = false, 80 int defaultValue = 0); 81 virtual ~MtpProperty(); 82 83 inline MtpPropertyCode getPropertyCode() const { return mCode; } 84 85 void read(MtpDataPacket& packet); 86 void write(MtpDataPacket& packet); 87 88 void setDefaultValue(const uint16_t* string); 89 void setCurrentValue(const uint16_t* string); 90 91 void setFormRange(int min, int max, int step); 92 void setFormEnum(const int* values, int count); 93 94 void print(); 95 96 inline bool isDeviceProperty() const { 97 return ( ((mCode & 0xF000) == 0x5000) 98 || ((mCode & 0xF800) == 0xD000)); 99 } 100 101private: 102 void readValue(MtpDataPacket& packet, MtpPropertyValue& value); 103 void writeValue(MtpDataPacket& packet, MtpPropertyValue& value); 104 MtpPropertyValue* readArrayValues(MtpDataPacket& packet, int& length); 105 void writeArrayValues(MtpDataPacket& packet, 106 MtpPropertyValue* values, int length); 107}; 108 109}; // namespace android 110 111#endif // _MTP_PROPERTY_H 112