All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
diagnosticDelegate.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXRUSDMAYA_DIAGNOSTICDELEGATE_H
25 #define PXRUSDMAYA_DIAGNOSTICDELEGATE_H
26 
28 
29 #include "usdMaya/api.h"
30 
31 #include "pxr/pxr.h"
32 
33 #include "pxr/base/tf/diagnosticMgr.h"
34 
35 #include "pxr/usd/usdUtils/coalescingDiagnosticDelegate.h"
36 
37 #include <maya/MGlobal.h>
38 
39 #include <atomic>
40 #include <memory>
41 
42 PXR_NAMESPACE_OPEN_SCOPE
43 
45 
62 public:
63  PXRUSDMAYA_API
64  ~UsdMayaDiagnosticDelegate() override;
65 
66  PXRUSDMAYA_API
67  void IssueError(const TfError& err) override;
68  PXRUSDMAYA_API
69  void IssueStatus(const TfStatus& status) override;
70  PXRUSDMAYA_API
71  void IssueWarning(const TfWarning& warning) override;
72  PXRUSDMAYA_API
73  void IssueFatalError(
74  const TfCallContext& context,
75  const std::string& msg) override;
76 
79  PXRUSDMAYA_API
80  static void InstallDelegate();
83  PXRUSDMAYA_API
84  static void RemoveDelegate();
88  PXRUSDMAYA_API
89  static int GetBatchCount();
90 
91 private:
92  friend class UsdMayaDiagnosticBatchContext;
93 
94  std::atomic_int _batchCount;
95  std::unique_ptr<UsdUtilsCoalescingDiagnosticDelegate> _batchedStatuses;
96  std::unique_ptr<UsdUtilsCoalescingDiagnosticDelegate> _batchedWarnings;
97 
99 
100  void _StartBatch();
101  void _EndBatch();
102  void _FlushBatch();
103 };
104 
122 {
123 public:
127  PXRUSDMAYA_API
129  PXRUSDMAYA_API
130  ~UsdMayaDiagnosticBatchContext();
131 
133  const UsdMayaDiagnosticBatchContext&) = delete;
134  UsdMayaDiagnosticBatchContext& operator=(
135  const UsdMayaDiagnosticBatchContext&) = delete;
136 
137 private:
141  std::weak_ptr<UsdMayaDiagnosticDelegate> _delegate;
142 };
143 
144 PXR_NAMESPACE_CLOSE_SCOPE
145 
146 #endif
As long as a batch context remains alive (process-wide), the UsdMayaDiagnosticDelegate will save diag...
PXRUSDMAYA_API void IssueFatalError(const TfCallContext &context, const std::string &msg) override
Called when a TF_FATAL_ERROR is issued (or a failed TF_AXIOM).
static PXRUSDMAYA_API int GetBatchCount()
Returns the number of active batch contexts associated with the global delegate.
PXRUSDMAYA_API void IssueWarning(const TfWarning &warning) override
Called when a TF_WARNING() is issued.
static PXRUSDMAYA_API void InstallDelegate()
Installs a shared delegate globally.
PXRUSDMAYA_API UsdMayaDiagnosticBatchContext()
Constructs a batch context, causing all subsequent diagnostic messages to be batched on all threads...
PXRUSDMAYA_API void IssueStatus(const TfStatus &status) override
Called when a TF_STATUS() is issued.
PXRUSDMAYA_API void IssueError(const TfError &err) override
Called when a TfError is posted.
Represents an object that contains information about a status message.
Definition: status.h:44
Represents an object that contains error information.
Definition: error.h:49
static PXRUSDMAYA_API void RemoveDelegate()
Removes the global shared delegate, if it exists.
Converts Tf diagnostics into native Maya infos, warnings, and errors.
Represents an object that contains information about a warning.
Definition: warning.h:44
One may set a delegate with the TfDiagnosticMgr which will be called to respond to errors and diagnos...