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> |
Bjorn Terelius | de93943 | 2017-11-20 17:38:14 +0100 | [diff] [blame] | 16 | #include <utility> |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 17 | |
Elad Alon | 8081073 | 2017-10-06 13:07:32 +0200 | [diff] [blame] | 18 | #include "api/rtceventlogoutput.h" |
Elad Alon | 604c14d | 2017-10-05 12:47:06 +0000 | [diff] [blame] | 19 | #include "logging/rtc_event_log/events/rtc_event.h" |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | |
Danil Chapovalov | d312a91 | 2017-10-05 12:25:18 +0000 | [diff] [blame] | 23 | class Clock; |
Elad Alon | 604c14d | 2017-10-05 12:47:06 +0000 | [diff] [blame] | 24 | |
terelius | 429c345 | 2016-01-21 05:42:04 -0800 | [diff] [blame] | 25 | enum PacketDirection { kIncomingPacket = 0, kOutgoingPacket }; |
| 26 | |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 27 | class RtcEventLog { |
| 28 | public: |
Elad Alon | 83ccca1 | 2017-10-04 13:18:26 +0200 | [diff] [blame] | 29 | enum : size_t { kUnlimitedOutput = 0 }; |
Bjorn Terelius | de93943 | 2017-11-20 17:38:14 +0100 | [diff] [blame] | 30 | enum : int64_t { kImmediateOutput = 0 }; |
Elad Alon | 83ccca1 | 2017-10-04 13:18:26 +0200 | [diff] [blame] | 31 | |
Elad Alon | 4a87e1c | 2017-10-03 16:11:34 +0200 | [diff] [blame] | 32 | // TODO(eladalon): Two stages are upcoming. |
| 33 | // 1. Extend this to actually support the new encoding. |
| 34 | // 2. Get rid of the legacy encoding, allowing us to get rid of this enum. |
| 35 | enum class EncodingType { Legacy }; |
| 36 | |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 37 | virtual ~RtcEventLog() {} |
| 38 | |
terelius | 4311ba5 | 2016-04-22 12:40:37 -0700 | [diff] [blame] | 39 | // Factory method to create an RtcEventLog object. |
Elad Alon | 604c14d | 2017-10-05 12:47:06 +0000 | [diff] [blame] | 40 | static std::unique_ptr<RtcEventLog> Create(EncodingType encoding_type); |
nisse | 3061276 | 2016-12-20 05:03:58 -0800 | [diff] [blame] | 41 | // TODO(nisse): webrtc::Clock is deprecated. Delete this method and |
| 42 | // above forward declaration of Clock when |
Elad Alon | 4a87e1c | 2017-10-03 16:11:34 +0200 | [diff] [blame] | 43 | // webrtc/system_wrappers/include/clock.h is deleted. |
Elad Alon | 604c14d | 2017-10-05 12:47:06 +0000 | [diff] [blame] | 44 | static std::unique_ptr<RtcEventLog> Create(const Clock* clock, |
| 45 | EncodingType encoding_type) { |
Elad Alon | 4a87e1c | 2017-10-03 16:11:34 +0200 | [diff] [blame] | 46 | return Create(encoding_type); |
nisse | 3061276 | 2016-12-20 05:03:58 -0800 | [diff] [blame] | 47 | } |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 48 | |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 49 | // Create an RtcEventLog object that does nothing. |
| 50 | static std::unique_ptr<RtcEventLog> CreateNull(); |
| 51 | |
Elad Alon | 83ccca1 | 2017-10-04 13:18:26 +0200 | [diff] [blame] | 52 | // Starts logging to a given output. The output might be limited in size, |
| 53 | // and may close itself once it has reached the maximum size. |
Bjorn Terelius | de93943 | 2017-11-20 17:38:14 +0100 | [diff] [blame] | 54 | virtual bool StartLogging(std::unique_ptr<RtcEventLogOutput> output, |
| 55 | int64_t output_period_ms) = 0; |
Elad Alon | 83ccca1 | 2017-10-04 13:18:26 +0200 | [diff] [blame] | 56 | |
eladalon | 248fd4f | 2017-09-06 05:18:15 -0700 | [diff] [blame] | 57 | // Stops logging to file and waits until the file has been closed, after |
| 58 | // which it would be permissible to read and/or modify it. |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 59 | virtual void StopLogging() = 0; |
| 60 | |
Elad Alon | 4a87e1c | 2017-10-03 16:11:34 +0200 | [diff] [blame] | 61 | // Log an RTC event (the type of event is determined by the subclass). |
| 62 | virtual void Log(std::unique_ptr<RtcEvent> event) = 0; |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 63 | }; |
| 64 | |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 65 | // No-op implementation is used if flag is not set, or in tests. |
perkj | 33bb86d | 2017-05-29 02:46:05 -0700 | [diff] [blame] | 66 | class RtcEventLogNullImpl : public RtcEventLog { |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 67 | public: |
Bjorn Terelius | de93943 | 2017-11-20 17:38:14 +0100 | [diff] [blame] | 68 | bool StartLogging(std::unique_ptr<RtcEventLogOutput> output, |
| 69 | int64_t output_period_ms) override { |
Elad Alon | 83ccca1 | 2017-10-04 13:18:26 +0200 | [diff] [blame] | 70 | return false; |
| 71 | } |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 72 | void StopLogging() override {} |
Elad Alon | 4a87e1c | 2017-10-03 16:11:34 +0200 | [diff] [blame] | 73 | void Log(std::unique_ptr<RtcEvent> event) override {} |
Stefan Holmer | 1318103 | 2016-07-29 14:48:54 +0200 | [diff] [blame] | 74 | }; |
| 75 | |
Bjorn Terelius | 3641185 | 2015-07-30 12:45:18 +0200 | [diff] [blame] | 76 | } // namespace webrtc |
| 77 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 78 | #endif // LOGGING_RTC_EVENT_LOG_RTC_EVENT_LOG_H_ |