blob: 327b61ccca20c7d6d6f9841d2e3e195a8310e25b [file] [log] [blame]
Andreas Huber0a451282016-08-30 11:27:24 -07001/*
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 _FMSGQ_DESCRIPTOR_H
18#define _FMSGQ_DESCRIPTOR_H
19
20#include <android-base/macros.h>
21#include <cutils/native_handle.h>
22#include <hidl/HidlSupport.h>
Hridya Valsaraju4fe70f02016-09-20 21:02:51 -070023#include <utils/NativeHandle.h>
Andreas Huber0a451282016-08-30 11:27:24 -070024
25namespace android {
26namespace hardware {
27
28struct GrantorDescriptor {
29 uint32_t flags;
30 uint32_t fdIndex;
31 uint32_t offset;
32 uint32_t extent;
33};
34
35enum GrantorType : int { READPTRPOS = 0, WRITEPTRPOS, DATAPTRPOS };
36
37struct MQDescriptor {
38 MQDescriptor(
39 const std::vector<GrantorDescriptor>& grantors,
40 native_handle_t* nhandle, int32_t flags, size_t size);
41
42 ~MQDescriptor();
43
44 explicit MQDescriptor(const MQDescriptor &other);
45 MQDescriptor &operator=(const MQDescriptor &other) = delete;
46
47 size_t getSize() const;
48
49 size_t getQuantum() const;
50
51 int32_t getFlags() const;
Andreas Huber0a451282016-08-30 11:27:24 -070052
53 ::android::status_t readEmbeddedFromParcel(
54 const ::android::hardware::Parcel &parcel,
55 size_t parentHandle,
56 size_t parentOffset);
57
58 ::android::status_t writeEmbeddedToParcel(
59 ::android::hardware::Parcel *parcel,
60 size_t parentHandle,
61 size_t parentOffset) const;
62
63 bool isHandleValid() const { return mHandle != nullptr; }
64 size_t countGrantors() const { return mGrantors.size(); }
Hridya Valsaraju4fe70f02016-09-20 21:02:51 -070065 std::vector<GrantorDescriptor> getGrantors() const;
66 const sp<NativeHandle> getNativeHandle() const;
Andreas Huber0a451282016-08-30 11:27:24 -070067
68private:
69 ::android::hardware::hidl_vec<GrantorDescriptor> mGrantors;
Hridya Valsaraju4fe70f02016-09-20 21:02:51 -070070 ::native_handle_t *mHandle;
Andreas Huber0a451282016-08-30 11:27:24 -070071 uint32_t mQuantum;
72 uint32_t mFlags;
73};
Hridya Valsaraju4fe70f02016-09-20 21:02:51 -070074} // namespace hardware
75} // namespace android
Andreas Huber0a451282016-08-30 11:27:24 -070076
77#endif // FMSGQ_DESCRIPTOR_H