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 */
17 #include <android-base/logging.h>
19 #include "ringbuffer.h"
21 namespace android {
22 namespace hardware {
23 namespace wifi {
24 namespace V1_2 {
25 namespace implementation {
27 Ringbuffer::Ringbuffer(size_t maxSize) : size_(0), maxSize_(maxSize) {}
29 void 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 }
46 const std::list<std::vector<uint8_t>>& Ringbuffer::getData() const {
47 return data_;
48 }
50 } // namespace implementation
51 } // namespace V1_2
52 } // namespace wifi
53 } // namespace hardware
54 } // namespace android