blob: 5511f2ffbafc055fbe820b1936495826e1dce2c9 [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
17#include "ringbuffer.h"
18
19namespace android {
20namespace hardware {
21namespace wifi {
22namespace V1_2 {
23namespace implementation {
24
25Ringbuffer::Ringbuffer(size_t maxSize) : size_(0), maxSize_(maxSize) {}
26
27void Ringbuffer::append(const std::vector<uint8_t>& input) {
28 if (input.size() == 0) {
29 return;
30 }
31 data_.push_back(input);
32 size_ += input.size() * sizeof(input[0]);
33 while (size_ > maxSize_) {
34 size_ -= data_.front().size() * sizeof(data_.front()[0]);
35 data_.pop_front();
36 }
37}
38
39const std::list<std::vector<uint8_t>>& Ringbuffer::getData() const {
40 return data_;
41}
42
43} // namespace implementation
44} // namespace V1_2
45} // namespace wifi
46} // namespace hardware
47} // namespace android