HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
executorErrorLogger.h
Go to the documentation of this file.
1 //
2 // Copyright 2025 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_EXEC_VDF_EXECUTOR_ERROR_LOGGER_H
8 #define PXR_EXEC_VDF_EXECUTOR_ERROR_LOGGER_H
9 
10 #include "pxr/pxr.h"
11 
12 #include "pxr/exec/vdf/api.h"
13 #include <tbb/concurrent_unordered_map.h>
14 #include <atomic>
15 
17 
18 /// \file
19 
20 class VdfNode;
21 
22 ////////////////////////////////////////////////////////////////////////////////
23 ///
24 /// \class VdfExecutorErrorLogger
25 ///
26 /// A client may instantiate an object of this class and set it in an executor,
27 /// to collect errors that may have been reported by nodes during a call to
28 /// Run() on the executor.
29 ///
30 /// Since since API is used by executors it is partly thread-safe as noted
31 /// below.
32 ///
34 {
35 public:
36 
37  /// Ctor.
38  ///
39  VDF_API
41 
42  /// Dtor.
43  ///
44  VDF_API
46 
47  /// A thread safe map from node pointer to string for logging warnings.
48  ///
49  using NodeToStringMap =
50  tbb::concurrent_unordered_map<const VdfNode *, std::string>;
51 
52  /// \name Accessors API
53  /// @{
54 
55  /// Returns a map that maps nodes to warning strings that were
56  /// encountered during a call to Run().
57  ///
58  VDF_API
59  const NodeToStringMap &GetWarnings() const;
60 
61  /// @}
62 
63 
64  /// \name Reporting API
65  /// @{
66 
67  /// Reports warnings using node debug names. Usually a client will
68  /// want to use GetWarnings() and report more meaningful messages.
69  ///
70  VDF_API
71  void ReportWarnings() const;
72 
73  /// Prints out default warning message based on \p node's debug name.
74  ///
75  VDF_API
76  static void IssueDefaultWarning(
77  const VdfNode &node,
78  const std::string &warning);
79 
80  /// @}
81 
82 
83  /// \name Logging API
84  /// @{
85 
86  /// Logs a warning against \p node. Concatenates existing warnings, if any.
87  /// This is thread-safe.
88  ///
89  VDF_API
90  void LogWarning(const VdfNode &node, const std::string &warning) const;
91 
92  /// @}
93 
94 private:
95 
96  // Holds warnings emitted by nodes during execution.
97  mutable std::atomic<NodeToStringMap *> _warnings;
98 };
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 
103 
104 #endif
VDF_API VdfExecutorErrorLogger()
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
Definition: node.h:52
#define VDF_API
Definition: api.h:25
VDF_API void LogWarning(const VdfNode &node, const std::string &warning) const
static VDF_API void IssueDefaultWarning(const VdfNode &node, const std::string &warning)
VDF_API ~VdfExecutorErrorLogger()
tbb::concurrent_unordered_map< const VdfNode *, std::string > NodeToStringMap
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
VDF_API const NodeToStringMap & GetWarnings() const
VDF_API void ReportWarnings() const