MtpProperty.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #ifndef _MTP_PROPERTY_H
  17. #define _MTP_PROPERTY_H
  18. #include "MtpTypes.h"
  19. #include <string>
  20. namespace android {
  21. class MtpDataPacket;
  22. struct MtpPropertyValue {
  23. union {
  24. int8_t i8;
  25. uint8_t u8;
  26. int16_t i16;
  27. uint16_t u16;
  28. int32_t i32;
  29. uint32_t u32;
  30. int64_t i64;
  31. uint64_t u64;
  32. int128_t i128;
  33. uint128_t u128;
  34. } u;
  35. // string in UTF8 format
  36. char* str;
  37. };
  38. class MtpProperty {
  39. public:
  40. MtpPropertyCode mCode;
  41. MtpDataType mType;
  42. bool mWriteable;
  43. MtpPropertyValue mDefaultValue;
  44. MtpPropertyValue mCurrentValue;
  45. // for array types
  46. uint32_t mDefaultArrayLength;
  47. MtpPropertyValue* mDefaultArrayValues;
  48. uint32_t mCurrentArrayLength;
  49. MtpPropertyValue* mCurrentArrayValues;
  50. enum {
  51. kFormNone = 0,
  52. kFormRange = 1,
  53. kFormEnum = 2,
  54. kFormDateTime = 3,
  55. };
  56. uint32_t mGroupCode;
  57. uint8_t mFormFlag;
  58. // for range form
  59. MtpPropertyValue mMinimumValue;
  60. MtpPropertyValue mMaximumValue;
  61. MtpPropertyValue mStepSize;
  62. // for enum form
  63. uint16_t mEnumLength;
  64. MtpPropertyValue* mEnumValues;
  65. public:
  66. MtpProperty();
  67. MtpProperty(MtpPropertyCode propCode,
  68. MtpDataType type,
  69. bool writeable = false,
  70. int defaultValue = 0);
  71. virtual ~MtpProperty();
  72. MtpPropertyCode getPropertyCode() const { return mCode; }
  73. MtpDataType getDataType() const { return mType; }
  74. bool read(MtpDataPacket& packet);
  75. void write(MtpDataPacket& packet);
  76. void setDefaultValue(const uint16_t* string);
  77. void setCurrentValue(const uint16_t* string);
  78. void setCurrentValue(MtpDataPacket& packet);
  79. const MtpPropertyValue& getCurrentValue() { return mCurrentValue; }
  80. void setFormRange(int min, int max, int step);
  81. void setFormEnum(const int* values, int count);
  82. void setFormDateTime();
  83. void print();
  84. inline bool isDeviceProperty() const {
  85. return ( ((mCode & 0xF000) == 0x5000)
  86. || ((mCode & 0xF800) == 0xD000));
  87. }
  88. private:
  89. bool readValue(MtpDataPacket& packet, MtpPropertyValue& value);
  90. void writeValue(MtpDataPacket& packet, MtpPropertyValue& value);
  91. MtpPropertyValue* readArrayValues(MtpDataPacket& packet, uint32_t& length);
  92. void writeArrayValues(MtpDataPacket& packet,
  93. MtpPropertyValue* values, uint32_t length);
  94. void print(MtpPropertyValue& value, std::string& buffer);
  95. };
  96. }; // namespace android
  97. #endif // _MTP_PROPERTY_H