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_TYPES_H_ 6 #define PLATFORM_BASE_TRACE_LOGGING_TYPES_H_ 7 8 #include <stdint.h> 9 10 #include <limits> 11 12 namespace openscreen { 13 14 // Define TraceId type here since other TraceLogging files import it. 15 using TraceId = uint64_t; 16 17 // kEmptyTraceId is the Trace ID when tracing at a global level, not inside any 18 // tracing block - ie this will be the parent ID for a top level tracing block. 19 constexpr TraceId kEmptyTraceId = 0x0; 20 21 // kUnsetTraceId is the Trace ID passed in to the tracing library when no user- 22 // specified value is desired. 23 constexpr TraceId kUnsetTraceId = std::numeric_limits<TraceId>::max(); 24 25 // A class to represent the current TraceId Hirearchy and for the user to 26 // pass around as needed. 27 struct TraceIdHierarchy { 28 TraceId current; 29 TraceId parent; 30 TraceId root; 31 EmptyTraceIdHierarchy32 static constexpr TraceIdHierarchy Empty() { 33 return {kEmptyTraceId, kEmptyTraceId, kEmptyTraceId}; 34 } 35 HasCurrentTraceIdHierarchy36 bool HasCurrent() { return current != kUnsetTraceId; } HasParentTraceIdHierarchy37 bool HasParent() { return parent != kUnsetTraceId; } HasRootTraceIdHierarchy38 bool HasRoot() { return root != kUnsetTraceId; } 39 }; 40 41 inline bool operator==(const TraceIdHierarchy& lhs, 42 const TraceIdHierarchy& rhs) { 43 return lhs.current == rhs.current && lhs.parent == rhs.parent && 44 lhs.root == rhs.root; 45 } 46 47 inline bool operator!=(const TraceIdHierarchy& lhs, 48 const TraceIdHierarchy& rhs) { 49 return !(lhs == rhs); 50 } 51 52 // BitFlags to represent the supported tracing categories. 53 // NOTE: These are currently placeholder values and later changes should feel 54 // free to edit them. 55 struct TraceCategory { 56 enum Value : uint64_t { 57 kAny = std::numeric_limits<uint64_t>::max(), 58 kMdns = 0x01 << 0, 59 kQuic = 0x01 << 1, 60 kSsl = 0x01 << 2, 61 kPresentation = 0x01 << 3, 62 kStandaloneReceiver = 0x01 << 4, 63 kDiscovery = 0x01 << 5, 64 kStandaloneSender = 0x01 << 6, 65 kReceiver = 0x01 << 7, 66 kSender = 0x01 << 8 67 }; 68 }; 69 70 } // namespace openscreen 71 72 #endif // PLATFORM_BASE_TRACE_LOGGING_TYPES_H_ 73