blob: 1294c5298228e8d647bbd57d256050dcd38dfdf7 [file] [log] [blame]
xshu5899e8e2018-01-09 15:36:03 -08001/*
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
xshu4cb33162018-01-24 15:40:06 -080017#include <android-base/logging.h>
18
xshu5899e8e2018-01-09 15:36:03 -080019#include "ringbuffer.h"
20
21namespace android {
22namespace hardware {
23namespace wifi {
Jong Wook Kimda830c92018-07-23 15:29:38 -070024namespace V1_3 {
xshu5899e8e2018-01-09 15:36:03 -080025namespace 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 }
xshu4cb33162018-01-24 15:40:06 -080033 if (input.size() > maxSize_) {
34 LOG(INFO) << "Oversized message of " << input.size()
35 << " bytes is dropped";
36 return;
37 }
xshu5899e8e2018-01-09 15:36:03 -080038 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
Jong Wook Kimda830c92018-07-23 15:29:38 -070051} // namespace V1_3
xshu5899e8e2018-01-09 15:36:03 -080052} // namespace wifi
53} // namespace hardware
54} // namespace android