michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Some of this code is cut-and-pasted from nICEr. Copyright is: michael@0: michael@0: /* michael@0: Copyright (c) 2007, Adobe Systems, Incorporated michael@0: All rights reserved. michael@0: michael@0: Redistribution and use in source and binary forms, with or without michael@0: modification, are permitted provided that the following conditions are michael@0: met: michael@0: michael@0: * Redistributions of source code must retain the above copyright michael@0: notice, this list of conditions and the following disclaimer. michael@0: michael@0: * Redistributions in binary form must reproduce the above copyright michael@0: notice, this list of conditions and the following disclaimer in the michael@0: documentation and/or other materials provided with the distribution. michael@0: michael@0: * Neither the name of Adobe Systems, Network Resonance nor the names of its michael@0: contributors may be used to endorse or promote products derived from michael@0: this software without specific prior written permission. michael@0: michael@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT michael@0: OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, michael@0: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT michael@0: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, michael@0: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY michael@0: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT michael@0: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE michael@0: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* Original author: bcampen@mozilla.com */ michael@0: michael@0: /* michael@0: This file defines an r_dest_vlog that can be used to accumulate log messages michael@0: for later inspection/filtering. The intent is to use this for interactive michael@0: debug purposes on an about:webrtc page or similar. michael@0: */ michael@0: michael@0: #ifndef rlogringbuffer_h__ michael@0: #define rlogringbuffer_h__ michael@0: michael@0: #include michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #include "mozilla/Mutex.h" michael@0: michael@0: #include "m_cpp_utils.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: class RLogRingBuffer { michael@0: public: michael@0: /* michael@0: NB: These are not threadsafe, nor are they safe to call during static michael@0: init/deinit. michael@0: */ michael@0: static RLogRingBuffer* CreateInstance(); michael@0: static RLogRingBuffer* GetInstance(); michael@0: static void DestroyInstance(); michael@0: michael@0: /* michael@0: Retrieves log statements that match a given substring, subject to a michael@0: limit. |matching_logs| will be filled in chronological order (front() michael@0: is oldest, back() is newest). |limit| == 0 will be interpreted as no michael@0: limit. michael@0: */ michael@0: void Filter(const std::string& substring, michael@0: uint32_t limit, michael@0: std::deque* matching_logs); michael@0: michael@0: void FilterAny(const std::vector& substrings, michael@0: uint32_t limit, michael@0: std::deque* matching_logs); michael@0: michael@0: inline void GetAny(uint32_t limit, michael@0: std::deque* matching_logs) { michael@0: Filter("", limit, matching_logs); michael@0: } michael@0: michael@0: void SetLogLimit(uint32_t new_limit); michael@0: michael@0: void Log(std::string&& log); michael@0: michael@0: private: michael@0: RLogRingBuffer(); michael@0: ~RLogRingBuffer(); michael@0: void RemoveOld(); michael@0: static RLogRingBuffer* instance; michael@0: michael@0: /* michael@0: * Might be worthwhile making this a circular buffer, but I think it is michael@0: * preferable to take up as little space as possible if no logging is michael@0: * happening/the ringbuffer is not being used. michael@0: */ michael@0: std::deque log_messages_; michael@0: /* Max size of log buffer (should we use time-depth instead/also?) */ michael@0: uint32_t log_limit_; michael@0: OffTheBooksMutex mutex_; michael@0: michael@0: DISALLOW_COPY_ASSIGN(RLogRingBuffer); michael@0: }; // class RLogRingBuffer michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif // rlogringbuffer_h__ michael@0: michael@0: