blob: c01a9026b61ae50f9ac28784a9e06c79b6f052e9 [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
Hridya Valsaraju62bb7a02016-09-23 10:44:04 -070028typedef uint64_t RingBufferPosition;
29
Andreas Huber0a451282016-08-30 11:27:24 -070030struct GrantorDescriptor {
31 uint32_t flags;
32 uint32_t fdIndex;
33 uint32_t offset;
Hridya Valsaraju62bb7a02016-09-23 10:44:04 -070034 size_t extent;
Andreas Huber0a451282016-08-30 11:27:24 -070035};
36
Andreas Huber0a451282016-08-30 11:27:24 -070037struct MQDescriptor {
38 MQDescriptor(
39 const std::vector<GrantorDescriptor>& grantors,
Hridya Valsaraju62bb7a02016-09-23 10:44:04 -070040 native_handle_t* nHandle, int32_t flags, size_t size);
41
42 MQDescriptor(size_t bufferSize, native_handle_t* nHandle, int32_t flags,
43 size_t messageSize);
Andreas Huber0a451282016-08-30 11:27:24 -070044
45 ~MQDescriptor();
46
47 explicit MQDescriptor(const MQDescriptor &other);
48 MQDescriptor &operator=(const MQDescriptor &other) = delete;
49
50 size_t getSize() const;
51
52 size_t getQuantum() const;
53
54 int32_t getFlags() const;
Andreas Huber0a451282016-08-30 11:27:24 -070055
56 ::android::status_t readEmbeddedFromParcel(
57 const ::android::hardware::Parcel &parcel,
58 size_t parentHandle,
59 size_t parentOffset);
60
61 ::android::status_t writeEmbeddedToParcel(
62 ::android::hardware::Parcel *parcel,
63 size_t parentHandle,
64 size_t parentOffset) const;
65
66 bool isHandleValid() const { return mHandle != nullptr; }
67 size_t countGrantors() const { return mGrantors.size(); }
Hridya Valsaraju4fe70f02016-09-20 21:02:51 -070068 std::vector<GrantorDescriptor> getGrantors() const;
69 const sp<NativeHandle> getNativeHandle() const;
Hridya Valsaraju62bb7a02016-09-23 10:44:04 -070070 /*
71 * There should atleast be GrantorDescriptors for the read counter, write
72 * counter and data buffer.
73 */
74 static constexpr int32_t kMinGrantorCount = 3;
75 enum GrantorType : int { READPTRPOS = 0, WRITEPTRPOS, DATAPTRPOS };
Andreas Huber0a451282016-08-30 11:27:24 -070076
77private:
78 ::android::hardware::hidl_vec<GrantorDescriptor> mGrantors;
Hridya Valsaraju4fe70f02016-09-20 21:02:51 -070079 ::native_handle_t *mHandle;
Andreas Huber0a451282016-08-30 11:27:24 -070080 uint32_t mQuantum;
81 uint32_t mFlags;
82};
Hridya Valsaraju4fe70f02016-09-20 21:02:51 -070083} // namespace hardware
84} // namespace android
Andreas Huber0a451282016-08-30 11:27:24 -070085
86#endif // FMSGQ_DESCRIPTOR_H