xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 RINGBUFFER_H_ |
| 18 | #define RINGBUFFER_H_ |
| 19 | |
| 20 | #include <list> |
| 21 | #include <vector> |
| 22 | |
| 23 | namespace android { |
| 24 | namespace hardware { |
| 25 | namespace wifi { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 26 | namespace V1_6 { |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 27 | namespace implementation { |
| 28 | |
| 29 | /** |
| 30 | * Ringbuffer object used to store debug data. |
| 31 | */ |
| 32 | class Ringbuffer { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 33 | public: |
Sunil Ravi | 07ef191 | 2022-05-17 18:01:06 -0700 | [diff] [blame^] | 34 | // Error codes for the append ring buffer operation |
| 35 | enum AppendStatus { |
| 36 | SUCCESS, |
| 37 | FAIL_GENERIC, |
| 38 | FAIL_IP_BUFFER_ZERO, |
| 39 | FAIL_IP_BUFFER_EXCEEDED_MAXSIZE, |
| 40 | FAIL_RING_BUFFER_CORRUPTED |
| 41 | }; |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 42 | explicit Ringbuffer(size_t maxSize); |
| 43 | |
| 44 | // Appends the data buffer and deletes from the front until buffer is |
| 45 | // within |maxSize_|. |
Sunil Ravi | 07ef191 | 2022-05-17 18:01:06 -0700 | [diff] [blame^] | 46 | enum AppendStatus append(const std::vector<uint8_t>& input); |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 47 | const std::list<std::vector<uint8_t>>& getData() const; |
xshu | c905ea6 | 2021-07-11 19:57:02 -0700 | [diff] [blame] | 48 | void clear(); |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 49 | |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 50 | private: |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 51 | std::list<std::vector<uint8_t>> data_; |
| 52 | size_t size_; |
| 53 | size_t maxSize_; |
| 54 | }; |
| 55 | |
| 56 | } // namespace implementation |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 57 | } // namespace V1_6 |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame] | 58 | } // namespace wifi |
| 59 | } // namespace hardware |
| 60 | } // namespace android |
| 61 | |
| 62 | #endif // RINGBUFFER_H_ |