HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
diagnosticTransport.h
Go to the documentation of this file.
1 //
2 // Copyright 2026 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_BASE_TF_DIAGNOSTIC_TRANSPORT_H
8 #define PXR_BASE_TF_DIAGNOSTIC_TRANSPORT_H
9 
10 /// \file tf/diagnosticTransport.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/base/tf/api.h"
15 #include "pxr/base/tf/error.h"
16 #include "pxr/base/tf/status.h"
17 #include "pxr/base/tf/warning.h"
18 
19 #include <functional>
20 #include <optional>
21 #include <string>
22 #include <type_traits>
23 #include <vector>
24 
26 
27 class TfDiagnosticMgr;
28 class TfDiagnosticTrap;
29 
30 /// \class TfDiagnosticTransport
31 /// \ingroup group_tf_Diagnostic
32 ///
33 /// A facility for transporting diagnostics from thread to thread.
34 ///
35 /// Typical use is to install a \c TfDiagnosticTrap in a child thread to
36 /// intercept diagnostics, then call \c TfDiagnosticTrap::Transport() to move
37 /// the accumulated diagnostics into a \c TfDiagnosticTransport. The parent
38 /// thread then calls \c Post() after joining to re-post the transported
39 /// diagnostics to its own thread, where they will be caught by any active \c
40 /// TfDiagnosticTrap or forwarded to diagnostic delegates.
41 ///
42 /// Example usage:
43 /// \code
44 /// tbb::concurrent_vector<TfDiagnosticTransport> transports;
45 ///
46 /// // In each child task:
47 /// TfDiagnosticTrap trap;
48 /// DoWork();
49 /// if (!trap.IsClean()) {
50 /// transports.push_back(trap.Transport());
51 /// }
52 ///
53 /// // After joining, on the parent thread:
54 /// for (auto &transport : transports) {
55 /// transport.Post();
56 /// }
57 /// \endcode
58 ///
59 /// \note \c TfDiagnosticTransport has no thread affinity of its own. \c Post()
60 /// should be called on the thread that should receive the diagnostics.
62 {
63 public:
64  /// Construct an empty TfDiagnosticTransport.
65  TfDiagnosticTransport() = default;
66 
69 
72 
73  /// Return true if this transport contains no diagnostics.
74  bool IsEmpty() const {
75  return _container.IsEmpty();
76  }
77 
78  /// Post all contained diagnostics to the current thread in the order they
79  /// were originally issued, leaving this transport empty.
80  void Post() {
81  _container.Post();
82  }
83 
84 private:
85  friend class TfDiagnosticTrap;
86 
87  // TfDiagnosticTrap calls this to implement Transport().
88  explicit TfDiagnosticTransport(Tf_DiagnosticContainer &&container)
89  : _container(std::move(container))
90  {}
91 
92  Tf_DiagnosticContainer _container;
93 };
94 
96 
97 #endif // PXR_BASE_TF_DIAGNOSTIC_TRANSPORT_H
bool IsEmpty() const
Return true if this transport contains no diagnostics.
TfDiagnosticTransport()=default
Construct an empty TfDiagnosticTransport.
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
TfDiagnosticTransport & operator=(TfDiagnosticTransport &&)=default
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74