blob: 03c08e1eedd8059e1388b9c26018fa591b8dd04f [file] [log] [blame]
Mike Lockwooda6c490b2010-06-05 22:45:01 -04001/*
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
Mike Lockwooddde37202010-09-25 21:21:05 -040026struct 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
Mike Lockwooda6c490b2010-06-05 22:45:01 -040043class MtpProperty {
44public:
45 MtpPropertyCode mCode;
46 MtpDataType mType;
47 bool mWriteable;
48 MtpPropertyValue mDefaultValue;
49 MtpPropertyValue mCurrentValue;
50
51 // for array types
Mike Lockwoodab063842014-11-12 14:20:06 -080052 uint32_t mDefaultArrayLength;
Mike Lockwooda6c490b2010-06-05 22:45:01 -040053 MtpPropertyValue* mDefaultArrayValues;
Mike Lockwoodab063842014-11-12 14:20:06 -080054 uint32_t mCurrentArrayLength;
Mike Lockwooda6c490b2010-06-05 22:45:01 -040055 MtpPropertyValue* mCurrentArrayValues;
56
57 enum {
58 kFormNone = 0,
59 kFormRange = 1,
60 kFormEnum = 2,
Mike Lockwoodb892d0e2010-11-23 18:38:55 -050061 kFormDateTime = 3,
Mike Lockwooda6c490b2010-06-05 22:45:01 -040062 };
Mike Lockwood2bb8c0e2010-08-09 14:49:28 -040063
64 uint32_t mGroupCode;
Mike Lockwooda6c490b2010-06-05 22:45:01 -040065 uint8_t mFormFlag;
66
67 // for range form
68 MtpPropertyValue mMinimumValue;
69 MtpPropertyValue mMaximumValue;
70 MtpPropertyValue mStepSize;
71
72 // for enum form
Mike Lockwoodab063842014-11-12 14:20:06 -080073 uint16_t mEnumLength;
Mike Lockwooda6c490b2010-06-05 22:45:01 -040074 MtpPropertyValue* mEnumValues;
75
76public:
77 MtpProperty();
Mike Lockwood21ef7d02010-06-30 17:00:35 -040078 MtpProperty(MtpPropertyCode propCode,
79 MtpDataType type,
80 bool writeable = false,
81 int defaultValue = 0);
Mike Lockwooda6c490b2010-06-05 22:45:01 -040082 virtual ~MtpProperty();
83
Daichi Hirono66a9abe2016-03-24 20:56:13 +090084 MtpPropertyCode getPropertyCode() const { return mCode; }
85 MtpDataType getDataType() const { return mType; }
Mike Lockwood21ef7d02010-06-30 17:00:35 -040086
Mike Lockwoodab063842014-11-12 14:20:06 -080087 bool read(MtpDataPacket& packet);
Mike Lockwood21ef7d02010-06-30 17:00:35 -040088 void write(MtpDataPacket& packet);
Mike Lockwooda6c490b2010-06-05 22:45:01 -040089
Mike Lockwooddde37202010-09-25 21:21:05 -040090 void setDefaultValue(const uint16_t* string);
91 void setCurrentValue(const uint16_t* string);
Daichi Hirono66a9abe2016-03-24 20:56:13 +090092 void setCurrentValue(MtpDataPacket& packet);
93 const MtpPropertyValue& getCurrentValue() { return mCurrentValue; }
Mike Lockwooddde37202010-09-25 21:21:05 -040094
Mike Lockwood01817262010-11-10 12:48:39 -050095 void setFormRange(int min, int max, int step);
96 void setFormEnum(const int* values, int count);
Mike Lockwoodb892d0e2010-11-23 18:38:55 -050097 void setFormDateTime();
Mike Lockwood01817262010-11-10 12:48:39 -050098
Mike Lockwooda6c490b2010-06-05 22:45:01 -040099 void print();
Mike Lockwood0c7c7c72010-12-07 11:24:28 -0800100 void print(MtpPropertyValue& value, MtpString& buffer);
Mike Lockwooda6c490b2010-06-05 22:45:01 -0400101
Mike Lockwoode3e76c42010-09-02 14:57:30 -0400102 inline bool isDeviceProperty() const {
103 return ( ((mCode & 0xF000) == 0x5000)
104 || ((mCode & 0xF800) == 0xD000));
105 }
106
Mike Lockwooda6c490b2010-06-05 22:45:01 -0400107private:
Mike Lockwoodab063842014-11-12 14:20:06 -0800108 bool readValue(MtpDataPacket& packet, MtpPropertyValue& value);
Mike Lockwood21ef7d02010-06-30 17:00:35 -0400109 void writeValue(MtpDataPacket& packet, MtpPropertyValue& value);
Mike Lockwoodab063842014-11-12 14:20:06 -0800110 MtpPropertyValue* readArrayValues(MtpDataPacket& packet, uint32_t& length);
Mike Lockwoode3e76c42010-09-02 14:57:30 -0400111 void writeArrayValues(MtpDataPacket& packet,
Mike Lockwoodab063842014-11-12 14:20:06 -0800112 MtpPropertyValue* values, uint32_t length);
Mike Lockwooda6c490b2010-06-05 22:45:01 -0400113};
114
115}; // namespace android
116
117#endif // _MTP_PROPERTY_H