blob: 47b3dea35a3cff99d6ab15c0cbc480c3d04d12a9 [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>
23
24namespace android {
25namespace hardware {
26
27struct GrantorDescriptor {
28 uint32_t flags;
29 uint32_t fdIndex;
30 uint32_t offset;
31 uint32_t extent;
32};
33
34enum GrantorType : int { READPTRPOS = 0, WRITEPTRPOS, DATAPTRPOS };
35
36struct MQDescriptor {
37 MQDescriptor(
38 const std::vector<GrantorDescriptor>& grantors,
39 native_handle_t* nhandle, int32_t flags, size_t size);
40
41 ~MQDescriptor();
42
43 explicit MQDescriptor(const MQDescriptor &other);
44 MQDescriptor &operator=(const MQDescriptor &other) = delete;
45
46 size_t getSize() const;
47
48 size_t getQuantum() const;
49
50 int32_t getFlags() const;
51 void* mapGrantorDescr(uint32_t grantor_idx);
52 void unmapGrantorDescr(void* address, uint32_t grantor_idx);
53
54 ::android::status_t readEmbeddedFromParcel(
55 const ::android::hardware::Parcel &parcel,
56 size_t parentHandle,
57 size_t parentOffset);
58
59 ::android::status_t writeEmbeddedToParcel(
60 ::android::hardware::Parcel *parcel,
61 size_t parentHandle,
62 size_t parentOffset) const;
63
64 bool isHandleValid() const { return mHandle != nullptr; }
65 size_t countGrantors() const { return mGrantors.size(); }
66
67private:
68 ::android::hardware::hidl_vec<GrantorDescriptor> mGrantors;
69 const ::native_handle_t *mHandle;
70 uint32_t mQuantum;
71 uint32_t mFlags;
72};
73
74inline size_t MQDescriptor::getSize() const {
75 return mGrantors[DATAPTRPOS].extent;
76}
77
78inline size_t MQDescriptor::getQuantum() const { return mQuantum; }
79
80inline int32_t MQDescriptor::getFlags() const { return mFlags; }
81
82} // namespace hardware
83} // namespace android
84
85#endif // FMSGQ_DESCRIPTOR_H