blob: 5839f4b2b0168a0419226c06840f4e9b619d7376 [file] [log] [blame]
Danil Chapovalovb32f2c72019-05-22 13:39:25 +02001/*
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 <memory>
17
18#include "absl/memory/memory.h"
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#include "rtc_base/deprecation.h"
23
24namespace webrtc {
25
26class RtcEventLog {
27 public:
28 enum : size_t { kUnlimitedOutput = 0 };
29 enum : int64_t { kImmediateOutput = 0 };
30
31 // TODO(eladalon): Get rid of the legacy encoding and this enum once all
32 // clients have migrated to the new format.
33 enum class EncodingType { Legacy, NewFormat };
34
35 // Factory method to create an RtcEventLog object.
36 // Create RtcEventLog with an RtcEventLogFactory instead.
37 RTC_DEPRECATED
38 static std::unique_ptr<RtcEventLog> Create(
39 EncodingType encoding_type,
40 TaskQueueFactory* task_queue_factory);
41
42 // Create an RtcEventLog object that does nothing.
43 RTC_DEPRECATED
44 static std::unique_ptr<RtcEventLog> CreateNull();
45
46 virtual ~RtcEventLog() = default;
47
48 // Starts logging to a given output. The output might be limited in size,
49 // and may close itself once it has reached the maximum size.
50 virtual bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,
51 int64_t output_period_ms) = 0;
52
53 // Stops logging to file and waits until the file has been closed, after
54 // which it would be permissible to read and/or modify it.
55 virtual void StopLogging() = 0;
56
57 // Log an RTC event (the type of event is determined by the subclass).
58 virtual void Log(std::unique_ptr<RtcEvent> event) = 0;
59};
60
61// No-op implementation is used if flag is not set, or in tests.
62class RtcEventLogNull final : public RtcEventLog {
63 public:
64 bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,
65 int64_t output_period_ms) override;
66 void StopLogging() override {}
67 void Log(std::unique_ptr<RtcEvent> event) override {}
68};
69
70inline std::unique_ptr<RtcEventLog> RtcEventLog::CreateNull() {
71 return absl::make_unique<RtcEventLogNull>();
72}
73
74} // namespace webrtc
75
76#endif // API_RTC_EVENT_LOG_RTC_EVENT_LOG_H_