Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_ |
| 12 | #define LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_ |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 13 | |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame] | 14 | #include <memory> |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 15 | #include <string> |
| 16 | |
Elad Alon | 5fd6e5e | 2017-10-05 10:19:29 +0200 | [diff] [blame^] | 17 | #include "logging/rtc_event_log/events/rtc_event.h" |
Elad Alon | 83ccca1 | 2017-10-04 13:18:26 +0200 | [diff] [blame] | 18 | #include "logging/rtc_event_log/output/rtc_event_log_output.h" |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 22 | class Clock; |
Elad Alon | 5fd6e5e | 2017-10-05 10:19:29 +0200 | [diff] [blame^] | 23 | |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 24 | enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket }; |
| 25 | |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 26 | class RtcEventLog { |
| 27 | public: |
Elad Alon | 83ccca1 | 2017-10-04 13:18:26 +0200 | [diff] [blame] | 28 | enum : size_t { kUnlimitedOutput = 0 }; |
| 29 | |
Elad Alon | 4a87e1c | 2017-10-03 16:11:34 +0200 | [diff] [blame] | 30 | // 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 Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 35 | virtual ~RtcEventLog() {} |
| 36 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 37 | // Factory method to create an RtcEventLog object. |
Elad Alon | 5fd6e5e | 2017-10-05 10:19:29 +0200 | [diff] [blame^] | 38 | static std::unique_ptr<RtcEventLog> Create(EncodingType encoding_type); |
nisse | 3061276 | 2016-12-20 05:03:58 -0800 | [diff] [blame] | 39 | // TODO(nisse): webrtc::Clock is deprecated. Delete this method and |
| 40 | // above forward declaration of Clock when |
Elad Alon | 4a87e1c | 2017-10-03 16:11:34 +0200 | [diff] [blame] | 41 | // webrtc/system_wrappers/include/clock.h is deleted. |
Elad Alon | 5fd6e5e | 2017-10-05 10:19:29 +0200 | [diff] [blame^] | 42 | static std::unique_ptr<RtcEventLog> Create(const Clock* clock, |
| 43 | EncodingType encoding_type) { |
Elad Alon | 4a87e1c | 2017-10-03 16:11:34 +0200 | [diff] [blame] | 44 | return Create(encoding_type); |
nisse | 3061276 | 2016-12-20 05:03:58 -0800 | [diff] [blame] | 45 | } |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 46 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 47 | // Create an RtcEventLog object that does nothing. |
| 48 | static std::unique_ptr<RtcEventLog> CreateNull(); |
| 49 | |
Elad Alon | 83ccca1 | 2017-10-04 13:18:26 +0200 | [diff] [blame] | 50 | // 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 | |
eladalon | 248fd4f | 2017-09-06 05:18:15 -0700 | [diff] [blame] | 54 | // 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 Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 56 | virtual void StopLogging() = 0; |
| 57 | |
Elad Alon | 4a87e1c | 2017-10-03 16:11:34 +0200 | [diff] [blame] | 58 | // Log an RTC event (the type of event is determined by the subclass). |
| 59 | virtual void Log(std::unique_ptr<RtcEvent> event) = 0; |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 60 | }; |
| 61 | |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 62 | // No-op implementation is used if flag is not set, or in tests. |
perkj | 33bb86d | 2017-05-29 02:46:05 -0700 | [diff] [blame] | 63 | class RtcEventLogNullImpl : public RtcEventLog { |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 64 | public: |
Elad Alon | 83ccca1 | 2017-10-04 13:18:26 +0200 | [diff] [blame] | 65 | bool StartLogging(std::unique_ptr<RtcEventLogOutput> output) override { |
| 66 | return false; |
| 67 | } |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 68 | void StopLogging() override {} |
Elad Alon | 4a87e1c | 2017-10-03 16:11:34 +0200 | [diff] [blame] | 69 | void Log(std::unique_ptr<RtcEvent> event) override {} |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 70 | }; |
| 71 | |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 72 | } // namespace webrtc |
| 73 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 74 | #endif // LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_ |