HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
reporterDataSourceCollector.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_BASE_TRACE_REPORTER_DATA_SOURCE_COLLECTOR_H
9 #define PXR_BASE_TRACE_REPORTER_DATA_SOURCE_COLLECTOR_H
10 
11 #include "pxr/pxr.h"
12 
13 #include "pxr/base/trace/api.h"
17 
19 
20 #include <tbb/concurrent_queue.h>
21 
22 #include <vector>
23 
25 
27 
28 ////////////////////////////////////////////////////////////////////////////////
29 /// \class TraceReporterDataSourceCollector
30 ///
31 /// This class is an implementation of TraceReporterDataSourceBase which
32 /// retrieves TraceCollections from the TraceCollector singleton.
33 ///
36 public:
38  using ThisPtr = TraceReporterDataSourceCollectorPtr;
39  using ThisRefPtr = std::unique_ptr<This>;
40 
41  /// Creates a new TraceReporterDataSourceCollector.
42  static ThisRefPtr New() {
43  return ThisRefPtr(new This());
44  }
45 
46  /// Creates a new TraceReporterDataSourceCollector which will only listen to
47  /// the TraceCollectionAvailable notice when \p accept returns true.
48  /// \p accept must be thread-safe.
49  static ThisRefPtr New(std::function<bool()> accept) {
50  return ThisRefPtr(new This(std::move(accept)));
51  }
52 
53  /// Removes all references to TraceCollections.
54  TRACE_API void Clear() override;
55 
56  /// Returns the next TraceCollections which need to be processed.
57  TRACE_API std::vector<CollectionPtr> ConsumeData() override;
58 
59 private:
61  TRACE_API TraceReporterDataSourceCollector(std::function<bool()> accept);
62 
63  // Add the new collection to the pending queue.
64  void _OnTraceCollection(const TraceCollectionAvailable&);
65 
66  std::function<bool()> _accept;
67  tbb::concurrent_queue<CollectionPtr> _pendingCollections;
68 };
69 
71 
72 #endif // PXR_BASE_TRACE_REPORTER_DATA_SOURCE_COLLECTOR_H
static ThisRefPtr New(std::function< bool()> accept)
TRACE_API void Clear() override
Removes all references to TraceCollections.
TraceReporterDataSourceCollector This
static ThisRefPtr New()
Creates a new TraceReporterDataSourceCollector.
TraceReporterDataSourceCollectorPtr ThisPtr
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_WEAK_PTRS(TraceReporterDataSourceCollector)
TRACE_API std::vector< CollectionPtr > ConsumeData() override
Returns the next TraceCollections which need to be processed.
#define TRACE_API
Definition: api.h:23