Danil Chapovalov | b32f2c7 | 2019-05-22 13:39:25 +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 | |
| 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 Chapovalov | ed69d41 | 2019-05-29 10:24:36 +0200 | [diff] [blame] | 16 | #include <functional> |
Danil Chapovalov | b32f2c7 | 2019-05-22 13:39:25 +0200 | [diff] [blame] | 17 | #include <memory> |
| 18 | |
Danil Chapovalov | b32f2c7 | 2019-05-22 13:39:25 +0200 | [diff] [blame] | 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" |
Danil Chapovalov | b32f2c7 | 2019-05-22 13:39:25 +0200 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | |
| 25 | class 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 Chapovalov | b32f2c7 | 2019-05-22 13:39:25 +0200 | [diff] [blame] | 34 | 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 Jansson | 58c71db | 2019-05-22 16:20:56 +0200 | [diff] [blame] | 45 | // 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 Chapovalov | b32f2c7 | 2019-05-22 13:39:25 +0200 | [diff] [blame] | 54 | // 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. |
| 59 | class 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 Chapovalov | b32f2c7 | 2019-05-22 13:39:25 +0200 | [diff] [blame] | 67 | } // namespace webrtc |
| 68 | |
| 69 | #endif // API_RTC_EVENT_LOG_RTC_EVENT_LOG_H_ |