blob: cebaf84e40f146e4cc35848a5a4540d124b5d044 [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>
Danil Chapovaloved69d412019-05-29 10:24:36 +020016#include <functional>
Danil Chapovalovb32f2c72019-05-22 13:39:25 +020017#include <memory>
18
Danil Chapovalovb32f2c72019-05-22 13:39:25 +020019#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"
Danil Chapovalovb32f2c72019-05-22 13:39:25 +020022
23namespace webrtc {
24
25class 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
Danil Chapovalovb32f2c72019-05-22 13:39:25 +020034 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
Sebastian Jansson58c71db2019-05-22 16:20:56 +020045 // 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.
49 virtual void StopLogging(std::function<void()> callback) {
50 StopLogging();
51 callback();
52 }
53
Danil Chapovalovb32f2c72019-05-22 13:39:25 +020054 // 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.
59class RtcEventLogNull final : public RtcEventLog {
60 public:
61 bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,
62 int64_t output_period_ms) override;
63 void StopLogging() override {}
64 void Log(std::unique_ptr<RtcEvent> event) override {}
65};
66
Danil Chapovalovb32f2c72019-05-22 13:39:25 +020067} // namespace webrtc
68
69#endif // API_RTC_EVENT_LOG_RTC_EVENT_LOG_H_