rtc_event_log.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef API_RTC_EVENT_LOG_RTC_EVENT_LOG_H_
  11. #define API_RTC_EVENT_LOG_RTC_EVENT_LOG_H_
  12. #include <cstddef>
  13. #include <cstdint>
  14. #include <functional>
  15. #include <memory>
  16. #include "api/rtc_event_log/rtc_event.h"
  17. #include "api/rtc_event_log_output.h"
  18. #include "api/task_queue/task_queue_factory.h"
  19. namespace webrtc {
  20. class RtcEventLog {
  21. public:
  22. enum : size_t { kUnlimitedOutput = 0 };
  23. enum : int64_t { kImmediateOutput = 0 };
  24. // TODO(eladalon): Get rid of the legacy encoding and this enum once all
  25. // clients have migrated to the new format.
  26. enum class EncodingType { Legacy, NewFormat };
  27. virtual ~RtcEventLog() = default;
  28. // Starts logging to a given output. The output might be limited in size,
  29. // and may close itself once it has reached the maximum size.
  30. virtual bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,
  31. int64_t output_period_ms) = 0;
  32. // Stops logging to file and waits until the file has been closed, after
  33. // which it would be permissible to read and/or modify it.
  34. virtual void StopLogging() = 0;
  35. // Stops logging to file and calls |callback| when the file has been closed.
  36. // Note that it is not safe to call any other members, including the
  37. // destructor, until the callback has been called.
  38. // TODO(srte): Remove default implementation when it's safe to do so.
  39. virtual void StopLogging(std::function<void()> callback) {
  40. StopLogging();
  41. callback();
  42. }
  43. // Log an RTC event (the type of event is determined by the subclass).
  44. virtual void Log(std::unique_ptr<RtcEvent> event) = 0;
  45. };
  46. // No-op implementation is used if flag is not set, or in tests.
  47. class RtcEventLogNull final : public RtcEventLog {
  48. public:
  49. bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,
  50. int64_t output_period_ms) override;
  51. void StopLogging() override {}
  52. void Log(std::unique_ptr<RtcEvent> event) override {}
  53. };
  54. } // namespace webrtc
  55. #endif // API_RTC_EVENT_LOG_RTC_EVENT_LOG_H_