Andreas Huber | 0a45128 | 2016-08-30 11:27:24 -0700 | [diff] [blame] | 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 _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 Valsaraju | 4fe70f0 | 2016-09-20 21:02:51 -0700 | [diff] [blame] | 23 | #include <utils/NativeHandle.h> |
Andreas Huber | 0a45128 | 2016-08-30 11:27:24 -0700 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | namespace hardware { |
| 27 | |
Hridya Valsaraju | 62bb7a0 | 2016-09-23 10:44:04 -0700 | [diff] [blame^] | 28 | typedef uint64_t RingBufferPosition; |
| 29 | |
Andreas Huber | 0a45128 | 2016-08-30 11:27:24 -0700 | [diff] [blame] | 30 | struct GrantorDescriptor { |
| 31 | uint32_t flags; |
| 32 | uint32_t fdIndex; |
| 33 | uint32_t offset; |
Hridya Valsaraju | 62bb7a0 | 2016-09-23 10:44:04 -0700 | [diff] [blame^] | 34 | size_t extent; |
Andreas Huber | 0a45128 | 2016-08-30 11:27:24 -0700 | [diff] [blame] | 35 | }; |
| 36 | |
Andreas Huber | 0a45128 | 2016-08-30 11:27:24 -0700 | [diff] [blame] | 37 | struct MQDescriptor { |
| 38 | MQDescriptor( |
| 39 | const std::vector<GrantorDescriptor>& grantors, |
Hridya Valsaraju | 62bb7a0 | 2016-09-23 10:44:04 -0700 | [diff] [blame^] | 40 | 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 Huber | 0a45128 | 2016-08-30 11:27:24 -0700 | [diff] [blame] | 44 | |
| 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 Huber | 0a45128 | 2016-08-30 11:27:24 -0700 | [diff] [blame] | 55 | |
| 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 Valsaraju | 4fe70f0 | 2016-09-20 21:02:51 -0700 | [diff] [blame] | 68 | std::vector<GrantorDescriptor> getGrantors() const; |
| 69 | const sp<NativeHandle> getNativeHandle() const; |
Hridya Valsaraju | 62bb7a0 | 2016-09-23 10:44:04 -0700 | [diff] [blame^] | 70 | /* |
| 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 Huber | 0a45128 | 2016-08-30 11:27:24 -0700 | [diff] [blame] | 76 | |
| 77 | private: |
| 78 | ::android::hardware::hidl_vec<GrantorDescriptor> mGrantors; |
Hridya Valsaraju | 4fe70f0 | 2016-09-20 21:02:51 -0700 | [diff] [blame] | 79 | ::native_handle_t *mHandle; |
Andreas Huber | 0a45128 | 2016-08-30 11:27:24 -0700 | [diff] [blame] | 80 | uint32_t mQuantum; |
| 81 | uint32_t mFlags; |
| 82 | }; |
Hridya Valsaraju | 4fe70f0 | 2016-09-20 21:02:51 -0700 | [diff] [blame] | 83 | } // namespace hardware |
| 84 | } // namespace android |
Andreas Huber | 0a45128 | 2016-08-30 11:27:24 -0700 | [diff] [blame] | 85 | |
| 86 | #endif // FMSGQ_DESCRIPTOR_H |