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 | #include "ringbuffer.h" |
| 18 | |
| 19 | namespace android { |
| 20 | namespace hardware { |
| 21 | namespace wifi { |
| 22 | namespace V1_2 { |
| 23 | namespace implementation { |
| 24 | |
| 25 | Ringbuffer::Ringbuffer(size_t maxSize) : size_(0), maxSize_(maxSize) {} |
| 26 | |
| 27 | void 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 | |
| 39 | const 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 |