rlogconnector.h 4.3 KB

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