blob: f7980457295a538468b078a736e3ea9519541120 [file] [log] [blame]
Bjorn Terelius36411852015-07-30 12:45:18 +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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_
12#define LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_
Bjorn Terelius36411852015-07-30 12:45:18 +020013
kwibergb25345e2016-03-12 06:10:44 -080014#include <memory>
Bjorn Terelius36411852015-07-30 12:45:18 +020015#include <string>
16
Elad Alon5fd6e5e2017-10-05 10:19:29 +020017#include "logging/rtc_event_log/events/rtc_event.h"
Elad Alon83ccca12017-10-04 13:18:26 +020018#include "logging/rtc_event_log/output/rtc_event_log_output.h"
Bjorn Terelius36411852015-07-30 12:45:18 +020019
20namespace webrtc {
21
terelius4311ba52016-04-22 12:40:37 -070022class Clock;
Elad Alon5fd6e5e2017-10-05 10:19:29 +020023
terelius429c3452016-01-21 05:42:04 -080024enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket };
25
Bjorn Terelius36411852015-07-30 12:45:18 +020026class RtcEventLog {
27 public:
Elad Alon83ccca12017-10-04 13:18:26 +020028 enum : size_t { kUnlimitedOutput = 0 };
29
Elad Alon4a87e1c2017-10-03 16:11:34 +020030 // TODO(eladalon): Two stages are upcoming.
31 // 1. Extend this to actually support the new encoding.
32 // 2. Get rid of the legacy encoding, allowing us to get rid of this enum.
33 enum class EncodingType { Legacy };
34
Bjorn Terelius36411852015-07-30 12:45:18 +020035 virtual ~RtcEventLog() {}
36
terelius4311ba52016-04-22 12:40:37 -070037 // Factory method to create an RtcEventLog object.
Elad Alon5fd6e5e2017-10-05 10:19:29 +020038 static std::unique_ptr<RtcEventLog> Create(EncodingType encoding_type);
nisse30612762016-12-20 05:03:58 -080039 // TODO(nisse): webrtc::Clock is deprecated. Delete this method and
40 // above forward declaration of Clock when
Elad Alon4a87e1c2017-10-03 16:11:34 +020041 // webrtc/system_wrappers/include/clock.h is deleted.
Elad Alon5fd6e5e2017-10-05 10:19:29 +020042 static std::unique_ptr<RtcEventLog> Create(const Clock* clock,
43 EncodingType encoding_type) {
Elad Alon4a87e1c2017-10-03 16:11:34 +020044 return Create(encoding_type);
nisse30612762016-12-20 05:03:58 -080045 }
Bjorn Terelius36411852015-07-30 12:45:18 +020046
ivoc14d5dbe2016-07-04 07:06:55 -070047 // Create an RtcEventLog object that does nothing.
48 static std::unique_ptr<RtcEventLog> CreateNull();
49
Elad Alon83ccca12017-10-04 13:18:26 +020050 // Starts logging to a given output. The output might be limited in size,
51 // and may close itself once it has reached the maximum size.
52 virtual bool StartLogging(std::unique_ptr<RtcEventLogOutput> output) = 0;
53
eladalon248fd4f2017-09-06 05:18:15 -070054 // Stops logging to file and waits until the file has been closed, after
55 // which it would be permissible to read and/or modify it.
Bjorn Terelius36411852015-07-30 12:45:18 +020056 virtual void StopLogging() = 0;
57
Elad Alon4a87e1c2017-10-03 16:11:34 +020058 // Log an RTC event (the type of event is determined by the subclass).
59 virtual void Log(std::unique_ptr<RtcEvent> event) = 0;
Bjorn Terelius36411852015-07-30 12:45:18 +020060};
61
Stefan Holmer13181032016-07-29 14:48:54 +020062// No-op implementation is used if flag is not set, or in tests.
perkj33bb86d2017-05-29 02:46:05 -070063class RtcEventLogNullImpl : public RtcEventLog {
Stefan Holmer13181032016-07-29 14:48:54 +020064 public:
Elad Alon83ccca12017-10-04 13:18:26 +020065 bool StartLogging(std::unique_ptr<RtcEventLogOutput> output) override {
66 return false;
67 }
Stefan Holmer13181032016-07-29 14:48:54 +020068 void StopLogging() override {}
Elad Alon4a87e1c2017-10-03 16:11:34 +020069 void Log(std::unique_ptr<RtcEvent> event) override {}
Stefan Holmer13181032016-07-29 14:48:54 +020070};
71
Bjorn Terelius36411852015-07-30 12:45:18 +020072} // namespace webrtc
73
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020074#endif // LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_