blob: 1294c5298228e8d647bbd57d256050dcd38dfdf7 [file] [log] [blame]
Alessandro Astone62b19f42019-09-10 23:32:56 +02001/*
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#include <android-base/logging.h>
18
19#include "ringbuffer.h"
20
21namespace android {
22namespace hardware {
23namespace wifi {
24namespace V1_3 {
25namespace implementation {
26
27Ringbuffer::Ringbuffer(size_t maxSize) : size_(0), maxSize_(maxSize) {}
28
29void Ringbuffer::append(const std::vector<uint8_t>& input) {
30 if (input.size() == 0) {
31 return;
32 }
33 if (input.size() > maxSize_) {
34 LOG(INFO) << "Oversized message of " << input.size()
35 << " bytes is dropped";
36 return;
37 }
38 data_.push_back(input);
39 size_ += input.size() * sizeof(input[0]);
40 while (size_ > maxSize_) {
41 size_ -= data_.front().size() * sizeof(data_.front()[0]);
42 data_.pop_front();
43 }
44}
45
46const std::list<std::vector<uint8_t>>& Ringbuffer::getData() const {
47 return data_;
48}
49
50} // namespace implementation
51} // namespace V1_3
52} // namespace wifi
53} // namespace hardware
54} // namespace android