blob: 64cfb9305ec01ad45d330cf36fa1db0adea79961 [file] [log] [blame]
Mike Lockwood90f48732010-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
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 };
Mike Lockwood97c8d902010-08-09 14:49:28 -040045
46 uint32_t mGroupCode;
Mike Lockwood90f48732010-06-05 22:45:01 -040047 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();
Mike Lockwood767c5e42010-06-30 17:00:35 -040060 MtpProperty(MtpPropertyCode propCode,
61 MtpDataType type,
62 bool writeable = false,
63 int defaultValue = 0);
Mike Lockwood90f48732010-06-05 22:45:01 -040064 virtual ~MtpProperty();
65
Mike Lockwood767c5e42010-06-30 17:00:35 -040066 inline MtpPropertyCode getPropertyCode() const { return mCode; }
67
Mike Lockwood59e3f0d2010-09-02 14:57:30 -040068 void read(MtpDataPacket& packet);
Mike Lockwood767c5e42010-06-30 17:00:35 -040069 void write(MtpDataPacket& packet);
Mike Lockwood90f48732010-06-05 22:45:01 -040070
71 void print();
72
Mike Lockwood59e3f0d2010-09-02 14:57:30 -040073 inline bool isDeviceProperty() const {
74 return ( ((mCode & 0xF000) == 0x5000)
75 || ((mCode & 0xF800) == 0xD000));
76 }
77
Mike Lockwood90f48732010-06-05 22:45:01 -040078private:
79 void readValue(MtpDataPacket& packet, MtpPropertyValue& value);
Mike Lockwood767c5e42010-06-30 17:00:35 -040080 void writeValue(MtpDataPacket& packet, MtpPropertyValue& value);
Mike Lockwood90f48732010-06-05 22:45:01 -040081 MtpPropertyValue* readArrayValues(MtpDataPacket& packet, int& length);
Mike Lockwood59e3f0d2010-09-02 14:57:30 -040082 void writeArrayValues(MtpDataPacket& packet,
83 MtpPropertyValue* values, int length);
Mike Lockwood90f48732010-06-05 22:45:01 -040084};
85
86}; // namespace android
87
88#endif // _MTP_PROPERTY_H