15899e8e9a13117fa73864a2e96ee6bdba048397fxshu/* 25899e8e9a13117fa73864a2e96ee6bdba048397fxshu * Copyright (C) 2018 The Android Open Source Project 35899e8e9a13117fa73864a2e96ee6bdba048397fxshu * 45899e8e9a13117fa73864a2e96ee6bdba048397fxshu * Licensed under the Apache License, Version 2.0 (the "License"); 55899e8e9a13117fa73864a2e96ee6bdba048397fxshu * you may not use this file except in compliance with the License. 65899e8e9a13117fa73864a2e96ee6bdba048397fxshu * You may obtain a copy of the License at 75899e8e9a13117fa73864a2e96ee6bdba048397fxshu * 85899e8e9a13117fa73864a2e96ee6bdba048397fxshu * http://www.apache.org/licenses/LICENSE-2.0 95899e8e9a13117fa73864a2e96ee6bdba048397fxshu * 105899e8e9a13117fa73864a2e96ee6bdba048397fxshu * Unless required by applicable law or agreed to in writing, software 115899e8e9a13117fa73864a2e96ee6bdba048397fxshu * distributed under the License is distributed on an "AS IS" BASIS, 125899e8e9a13117fa73864a2e96ee6bdba048397fxshu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135899e8e9a13117fa73864a2e96ee6bdba048397fxshu * See the License for the specific language governing permissions and 145899e8e9a13117fa73864a2e96ee6bdba048397fxshu * limitations under the License. 155899e8e9a13117fa73864a2e96ee6bdba048397fxshu */ 165899e8e9a13117fa73864a2e96ee6bdba048397fxshu 174cb3316da4b2a92a7dfc9c555fc184ea0d29ca41xshu#include <android-base/logging.h> 184cb3316da4b2a92a7dfc9c555fc184ea0d29ca41xshu 195899e8e9a13117fa73864a2e96ee6bdba048397fxshu#include "ringbuffer.h" 205899e8e9a13117fa73864a2e96ee6bdba048397fxshu 215899e8e9a13117fa73864a2e96ee6bdba048397fxshunamespace android { 225899e8e9a13117fa73864a2e96ee6bdba048397fxshunamespace hardware { 235899e8e9a13117fa73864a2e96ee6bdba048397fxshunamespace wifi { 245899e8e9a13117fa73864a2e96ee6bdba048397fxshunamespace V1_2 { 255899e8e9a13117fa73864a2e96ee6bdba048397fxshunamespace implementation { 265899e8e9a13117fa73864a2e96ee6bdba048397fxshu 275899e8e9a13117fa73864a2e96ee6bdba048397fxshuRingbuffer::Ringbuffer(size_t maxSize) : size_(0), maxSize_(maxSize) {} 285899e8e9a13117fa73864a2e96ee6bdba048397fxshu 295899e8e9a13117fa73864a2e96ee6bdba048397fxshuvoid Ringbuffer::append(const std::vector<uint8_t>& input) { 305899e8e9a13117fa73864a2e96ee6bdba048397fxshu if (input.size() == 0) { 315899e8e9a13117fa73864a2e96ee6bdba048397fxshu return; 325899e8e9a13117fa73864a2e96ee6bdba048397fxshu } 334cb3316da4b2a92a7dfc9c555fc184ea0d29ca41xshu if (input.size() > maxSize_) { 344cb3316da4b2a92a7dfc9c555fc184ea0d29ca41xshu LOG(INFO) << "Oversized message of " << input.size() 354cb3316da4b2a92a7dfc9c555fc184ea0d29ca41xshu << " bytes is dropped"; 364cb3316da4b2a92a7dfc9c555fc184ea0d29ca41xshu return; 374cb3316da4b2a92a7dfc9c555fc184ea0d29ca41xshu } 385899e8e9a13117fa73864a2e96ee6bdba048397fxshu data_.push_back(input); 395899e8e9a13117fa73864a2e96ee6bdba048397fxshu size_ += input.size() * sizeof(input[0]); 405899e8e9a13117fa73864a2e96ee6bdba048397fxshu while (size_ > maxSize_) { 415899e8e9a13117fa73864a2e96ee6bdba048397fxshu size_ -= data_.front().size() * sizeof(data_.front()[0]); 425899e8e9a13117fa73864a2e96ee6bdba048397fxshu data_.pop_front(); 435899e8e9a13117fa73864a2e96ee6bdba048397fxshu } 445899e8e9a13117fa73864a2e96ee6bdba048397fxshu} 455899e8e9a13117fa73864a2e96ee6bdba048397fxshu 465899e8e9a13117fa73864a2e96ee6bdba048397fxshuconst std::list<std::vector<uint8_t>>& Ringbuffer::getData() const { 475899e8e9a13117fa73864a2e96ee6bdba048397fxshu return data_; 485899e8e9a13117fa73864a2e96ee6bdba048397fxshu} 495899e8e9a13117fa73864a2e96ee6bdba048397fxshu 505899e8e9a13117fa73864a2e96ee6bdba048397fxshu} // namespace implementation 515899e8e9a13117fa73864a2e96ee6bdba048397fxshu} // namespace V1_2 525899e8e9a13117fa73864a2e96ee6bdba048397fxshu} // namespace wifi 535899e8e9a13117fa73864a2e96ee6bdba048397fxshu} // namespace hardware 545899e8e9a13117fa73864a2e96ee6bdba048397fxshu} // namespace android 55