1/*
2 * Copyright (C) 2016 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 ANDROID_MEDIA_MIDI_DEVICE_INFO_H
18#define ANDROID_MEDIA_MIDI_DEVICE_INFO_H
19
20#include <binder/Parcelable.h>
21#include <binder/PersistableBundle.h>
22#include <utils/String16.h>
23#include <utils/Vector.h>
24
25namespace android {
26namespace media {
27namespace midi {
28
29class MidiDeviceInfo : public Parcelable {
30public:
31    MidiDeviceInfo() = default;
32    virtual ~MidiDeviceInfo() = default;
33    MidiDeviceInfo(const MidiDeviceInfo& midiDeviceInfo) = default;
34
35    status_t writeToParcel(Parcel* parcel) const override;
36    status_t readFromParcel(const Parcel* parcel) override;
37
38    int getType() const { return mType; }
39    int getUid() const { return mId; }
40    bool isPrivate() const { return mIsPrivate; }
41    const Vector<String16>& getInputPortNames() const { return mInputPortNames; }
42    const Vector<String16>&  getOutputPortNames() const { return mOutputPortNames; }
43    String16 getProperty(const char* propertyName);
44
45    // The constants need to be kept in sync with MidiDeviceInfo.java
46    enum {
47        TYPE_USB = 1,
48        TYPE_VIRTUAL = 2,
49        TYPE_BLUETOOTH = 3,
50    };
51    static const char* const PROPERTY_NAME;
52    static const char* const PROPERTY_MANUFACTURER;
53    static const char* const PROPERTY_PRODUCT;
54    static const char* const PROPERTY_VERSION;
55    static const char* const PROPERTY_SERIAL_NUMBER;
56    static const char* const PROPERTY_ALSA_CARD;
57    static const char* const PROPERTY_ALSA_DEVICE;
58
59    friend bool operator==(const MidiDeviceInfo& lhs, const MidiDeviceInfo& rhs);
60    friend bool operator!=(const MidiDeviceInfo& lhs, const MidiDeviceInfo& rhs) {
61        return !(lhs == rhs);
62    }
63
64private:
65    status_t readStringVector(
66            const Parcel* parcel, Vector<String16> *vectorPtr, size_t defaultLength);
67    status_t writeStringVector(Parcel* parcel, const Vector<String16>& vector) const;
68
69    int32_t mType;
70    int32_t mId;
71    Vector<String16> mInputPortNames;
72    Vector<String16> mOutputPortNames;
73    os::PersistableBundle mProperties;
74    bool mIsPrivate;
75};
76
77}  // namespace midi
78}  // namespace media
79}  // namespace android
80
81#endif  // ANDROID_MEDIA_MIDI_DEVICE_INFO_H
82