blob: 80c0c1104522fe0f471a22c6908d3bffba282e1d [file] [log] [blame]
xshu5899e8e2018-01-09 15:36:03 -08001/*
Gabriel Birene58e2632022-07-15 23:25:39 +00002 * Copyright (C) 2022 The Android Open Source Project
xshu5899e8e2018-01-09 15:36:03 -08003 *
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
Gabriel Birene58e2632022-07-15 23:25:39 +000023namespace aidl {
xshu5899e8e2018-01-09 15:36:03 -080024namespace android {
25namespace hardware {
26namespace wifi {
xshu5899e8e2018-01-09 15:36:03 -080027
28/**
29 * Ringbuffer object used to store debug data.
30 */
31class Ringbuffer {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080032 public:
Sunil Ravi07ef1912022-05-17 18:01:06 -070033 // Error codes for the append ring buffer operation
34 enum AppendStatus {
35 SUCCESS,
36 FAIL_GENERIC,
37 FAIL_IP_BUFFER_ZERO,
38 FAIL_IP_BUFFER_EXCEEDED_MAXSIZE,
39 FAIL_RING_BUFFER_CORRUPTED
40 };
xshu5899e8e2018-01-09 15:36:03 -080041 explicit Ringbuffer(size_t maxSize);
42
43 // Appends the data buffer and deletes from the front until buffer is
44 // within |maxSize_|.
Sunil Ravi07ef1912022-05-17 18:01:06 -070045 enum AppendStatus append(const std::vector<uint8_t>& input);
xshu5899e8e2018-01-09 15:36:03 -080046 const std::list<std::vector<uint8_t>>& getData() const;
xshuc905ea62021-07-11 19:57:02 -070047 void clear();
xshu5899e8e2018-01-09 15:36:03 -080048
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080049 private:
xshu5899e8e2018-01-09 15:36:03 -080050 std::list<std::vector<uint8_t>> data_;
51 size_t size_;
52 size_t maxSize_;
53};
54
xshu5899e8e2018-01-09 15:36:03 -080055} // namespace wifi
56} // namespace hardware
57} // namespace android
Gabriel Birene58e2632022-07-15 23:25:39 +000058} // namespace aidl
xshu5899e8e2018-01-09 15:36:03 -080059
60#endif // RINGBUFFER_H_