/src/mozilla-central/media/mtransport/rlogconnector.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
5 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | // Some of this code is cut-and-pasted from nICEr. Copyright is: |
8 | | |
9 | | /* |
10 | | Copyright (c) 2007, Adobe Systems, Incorporated |
11 | | All rights reserved. |
12 | | |
13 | | Redistribution and use in source and binary forms, with or without |
14 | | modification, are permitted provided that the following conditions are |
15 | | met: |
16 | | |
17 | | * Redistributions of source code must retain the above copyright |
18 | | notice, this list of conditions and the following disclaimer. |
19 | | |
20 | | * Redistributions in binary form must reproduce the above copyright |
21 | | notice, this list of conditions and the following disclaimer in the |
22 | | documentation and/or other materials provided with the distribution. |
23 | | |
24 | | * Neither the name of Adobe Systems, Network Resonance nor the names of its |
25 | | contributors may be used to endorse or promote products derived from |
26 | | this software without specific prior written permission. |
27 | | |
28 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
29 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
30 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
31 | | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
32 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
33 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
34 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
35 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
36 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
37 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
38 | | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
39 | | */ |
40 | | |
41 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
42 | | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
43 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
44 | | |
45 | | /* Original author: bcampen@mozilla.com */ |
46 | | |
47 | | /* |
48 | | This file defines an r_dest_vlog that can be used to accumulate log messages |
49 | | for later inspection/filtering. The intent is to use this for interactive |
50 | | debug purposes on an about:webrtc page or similar. |
51 | | */ |
52 | | |
53 | | #ifndef rlogconnector_h__ |
54 | | #define rlogconnector_h__ |
55 | | |
56 | | #include <stdint.h> |
57 | | |
58 | | #include <deque> |
59 | | #include <string> |
60 | | #include <vector> |
61 | | |
62 | | #include "mozilla/Mutex.h" |
63 | | |
64 | | #include "m_cpp_utils.h" |
65 | | |
66 | | namespace mozilla { |
67 | | |
68 | | class RLogConnector { |
69 | | public: |
70 | | /* |
71 | | NB: These are not threadsafe, nor are they safe to call during static |
72 | | init/deinit. |
73 | | */ |
74 | | static RLogConnector* CreateInstance(); |
75 | | static RLogConnector* GetInstance(); |
76 | | static void DestroyInstance(); |
77 | | |
78 | | /* |
79 | | Retrieves log statements that match a given substring, subject to a |
80 | | limit. |matching_logs| will be filled in chronological order (front() |
81 | | is oldest, back() is newest). |limit| == 0 will be interpreted as no |
82 | | limit. |
83 | | */ |
84 | | void Filter(const std::string& substring, |
85 | | uint32_t limit, |
86 | | std::deque<std::string>* matching_logs); |
87 | | |
88 | | void FilterAny(const std::vector<std::string>& substrings, |
89 | | uint32_t limit, |
90 | | std::deque<std::string>* matching_logs); |
91 | | |
92 | | inline void GetAny(uint32_t limit, |
93 | 0 | std::deque<std::string>* matching_logs) { |
94 | 0 | Filter("", limit, matching_logs); |
95 | 0 | } |
96 | | |
97 | | void SetLogLimit(uint32_t new_limit); |
98 | | void Log(int level, std::string&& log); |
99 | | void Clear(); |
100 | | |
101 | | // Methods to signal when a PeerConnection exists in a Private Window. |
102 | | void EnterPrivateMode(); |
103 | | void ExitPrivateMode(); |
104 | | |
105 | | private: |
106 | | RLogConnector(); |
107 | | ~RLogConnector(); |
108 | | void RemoveOld(); |
109 | | void AddMsg(std::string&& msg); |
110 | | |
111 | | static RLogConnector* instance; |
112 | | |
113 | | /* |
114 | | * Might be worthwhile making this a circular buffer, but I think it is |
115 | | * preferable to take up as little space as possible if no logging is |
116 | | * happening/the ringbuffer is not being used. |
117 | | */ |
118 | | std::deque<std::string> log_messages_; |
119 | | /* Max size of log buffer (should we use time-depth instead/also?) */ |
120 | | uint32_t log_limit_; |
121 | | OffTheBooksMutex mutex_; |
122 | | uint32_t disableCount_; |
123 | | |
124 | | DISALLOW_COPY_ASSIGN(RLogConnector); |
125 | | }; // class RLogConnector |
126 | | |
127 | | } // namespace mozilla |
128 | | |
129 | | #endif // rlogconnector_h__ |