1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef PLATFORM_BASE_TRACE_LOGGING_ACTIVATION_H_ 6 #define PLATFORM_BASE_TRACE_LOGGING_ACTIVATION_H_ 7 8 namespace openscreen { 9 10 class TraceLoggingPlatform; 11 12 // Start or Stop trace logging. It is illegal to call StartTracing() a second 13 // time without having called StopTracing() to stop the prior tracing session. 14 // 15 // Note that StopTracing() may block until all threads have returned from any 16 // in-progress calls into the TraceLoggingPlatform's methods. 17 void StartTracing(TraceLoggingPlatform* destination); 18 void StopTracing(); 19 20 // An immutable, non-copyable and non-movable smart pointer that references the 21 // current trace logging destination. If tracing was active when this class was 22 // intantiated, the pointer is valid for the life of the instance, and can be 23 // used to directly invoke the methods of the TraceLoggingPlatform API. If 24 // tracing was not active when this class was intantiated, the pointer is null 25 // for the life of the instance and must not be dereferenced. 26 // 27 // An instance should be short-lived, as a platform's call to StopTracing() will 28 // be blocked until there are no instances remaining. 29 // 30 // NOTE: This is generally not used directly, but instead via the 31 // util/trace_logging macros. 32 class CurrentTracingDestination { 33 public: 34 CurrentTracingDestination(); 35 ~CurrentTracingDestination(); 36 37 explicit operator bool() const noexcept { return !!destination_; } 38 TraceLoggingPlatform* operator->() const noexcept { return destination_; } 39 40 private: 41 CurrentTracingDestination(const CurrentTracingDestination&) = delete; 42 CurrentTracingDestination(CurrentTracingDestination&&) = delete; 43 CurrentTracingDestination& operator=(const CurrentTracingDestination&) = 44 delete; 45 CurrentTracingDestination& operator=(CurrentTracingDestination&&) = delete; 46 47 // The destination at the time this class was constructed, and is valid for 48 // the lifetime of this class. This is nullptr if tracing was inactive. 49 TraceLoggingPlatform* const destination_; 50 }; 51 52 } // namespace openscreen 53 54 #endif // PLATFORM_BASE_TRACE_LOGGING_ACTIVATION_H_ 55