• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 #ifndef API_RTC_EVENT_LOG_RTC_EVENT_LOG_H_
12 #define API_RTC_EVENT_LOG_RTC_EVENT_LOG_H_
13 
14 #include <cstddef>
15 #include <cstdint>
16 #include <functional>
17 #include <memory>
18 
19 #include "api/rtc_event_log/rtc_event.h"
20 #include "api/rtc_event_log_output.h"
21 #include "api/task_queue/task_queue_factory.h"
22 
23 namespace webrtc {
24 
25 class RtcEventLog {
26  public:
27   enum : size_t { kUnlimitedOutput = 0 };
28   enum : int64_t { kImmediateOutput = 0 };
29 
30   // TODO(eladalon):  Get rid of the legacy encoding and this enum once all
31   // clients have migrated to the new format.
32   enum class EncodingType { Legacy, NewFormat };
33 
34   virtual ~RtcEventLog() = default;
35 
36   // Starts logging to a given output. The output might be limited in size,
37   // and may close itself once it has reached the maximum size.
38   virtual bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,
39                             int64_t output_period_ms) = 0;
40 
41   // Stops logging to file and waits until the file has been closed, after
42   // which it would be permissible to read and/or modify it.
43   virtual void StopLogging() = 0;
44 
45   // Stops logging to file and calls |callback| when the file has been closed.
46   // Note that it is not safe to call any other members, including the
47   // destructor, until the callback has been called.
48   // TODO(srte): Remove default implementation when it's safe to do so.
StopLogging(std::function<void ()> callback)49   virtual void StopLogging(std::function<void()> callback) {
50     StopLogging();
51     callback();
52   }
53 
54   // Log an RTC event (the type of event is determined by the subclass).
55   virtual void Log(std::unique_ptr<RtcEvent> event) = 0;
56 };
57 
58 // No-op implementation is used if flag is not set, or in tests.
59 class RtcEventLogNull final : public RtcEventLog {
60  public:
61   bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,
62                     int64_t output_period_ms) override;
StopLogging()63   void StopLogging() override {}
Log(std::unique_ptr<RtcEvent> event)64   void Log(std::unique_ptr<RtcEvent> event) override {}
65 };
66 
67 }  // namespace webrtc
68 
69 #endif  // API_RTC_EVENT_LOG_RTC_EVENT_LOG_H_
70