Usd Notice Framework 0.8.1
Loading...
Searching...
No Matches
dispatcher.h
Go to the documentation of this file.
1#ifndef USD_NOTICE_FRAMEWORK_DISPATCHER_H
2#define USD_NOTICE_FRAMEWORK_DISPATCHER_H
3
5
6#include "unf/broker.h"
7#include "unf/notice.h"
8
9#include <pxr/base/tf/refBase.h>
10#include <pxr/base/tf/refPtr.h>
11#include <pxr/base/tf/type.h>
12#include <pxr/base/tf/weakBase.h>
13#include <pxr/pxr.h>
14#include <pxr/usd/usd/common.h>
15
16namespace unf {
17
24 public:
26 UNF_API virtual ~Dispatcher() { Revoke(); };
27
35 UNF_API virtual std::string GetIdentifier() const = 0;
36
38 UNF_API virtual void Register() = 0;
39
41 UNF_API virtual void Revoke();
42
43 protected:
45 UNF_API Dispatcher(const BrokerWeakPtr&);
46
64 template <class InputNotice, class OutputNotice>
65 void _Register()
66 {
67 auto self = PXR_NS::TfCreateWeakPtr(this);
68 auto cb = &Dispatcher::_OnReceiving<InputNotice, OutputNotice>;
69 _keys.push_back(
70 PXR_NS::TfNotice::Register(self, cb, _broker->GetStage()));
71 }
72
81 template <class InputNotice, class OutputNotice>
82 void _OnReceiving(const InputNotice& notice)
83 {
84 PXR_NS::TfRefPtr<OutputNotice> _notice = OutputNotice::Create(notice);
85 _broker->Send(_notice);
86 }
87
90
92 std::vector<PXR_NS::TfNotice::Key> _keys;
93};
94
102 public:
103 virtual std::string GetIdentifier() const override
104 {
105 return "StageDispatcher";
106 }
107
111 virtual void Register() override;
112
113 private:
114 StageDispatcher(const BrokerWeakPtr& broker);
115
117 friend class Broker;
118};
119
128 public:
131 const BrokerWeakPtr& broker) const = 0;
132};
133
141template <class T>
143 public:
146 const BrokerWeakPtr& broker) const override
147 {
148 return PXR_NS::TfCreateRefPtr(new T(broker));
149 }
150};
151
165template <class T, class... Bases>
167{
168 PXR_NS::TfType::Define<T, PXR_NS::TfType::Bases<Bases...> >()
169 .template SetFactory<DispatcherFactoryImpl<T> >();
170}
171
172} // namespace unf
173
174#endif // USD_NOTICE_FRAMEWORK_DISPATCHER_H
Intermediate object between the Usd Stage and any clients that needs asynchronous handling and upstre...
Definition broker.h:46
Templated factory class which creates a specific type of Dispatcher.
Definition dispatcher.h:142
virtual PXR_NS::TfRefPtr< Dispatcher > New(const BrokerWeakPtr &broker) const override
Create a Dispatcher and return reference pointer.
Definition dispatcher.h:145
Interface for building Dispatcher type.
Definition dispatcher.h:127
virtual PXR_NS::TfRefPtr< Dispatcher > New(const BrokerWeakPtr &broker) const =0
Base constructor to create a Dispatcher.
Interface for objects emitting standalone notices triggered by incoming PXR_NS::TfNotice derived noti...
Definition dispatcher.h:23
UNF_API Dispatcher(const BrokerWeakPtr &)
Create a dispatcher targeting a Broker.
virtual UNF_API ~Dispatcher()
Revoke all registered listeners on destruction.
Definition dispatcher.h:26
void _OnReceiving(const InputNotice &notice)
Convenient templated method to emit a OutputNotice notice from an incoming InputNotice notice.
Definition dispatcher.h:82
virtual UNF_API void Revoke()
Revoke all registered listeners.
BrokerWeakPtr _broker
Broker that the dispatcher is attached to.
Definition dispatcher.h:89
virtual UNF_API void Register()=0
Register listeners to PXR_NS::TfNotice derived notices.
virtual UNF_API std::string GetIdentifier() const =0
Get unique string identifier.
void _Register()
Convenient templated method to register a listener for incoming InputNotice notice which emits a Outp...
Definition dispatcher.h:65
std::vector< PXR_NS::TfNotice::Key > _keys
List of handle-objects used for registering listeners.
Definition dispatcher.h:92
Default dispatcher which emits UnfNotice::StageNotice derived notices corresponding to each PXR_NS::U...
Definition dispatcher.h:101
virtual void Register() override
Register listeners to each PXR_NS::UsdNotice::StageNotice derived notices.
virtual std::string GetIdentifier() const override
Get unique string identifier.
Definition dispatcher.h:103
void DispatcherDefine()
Define a PXR_NS::TfType for a specific type of Dispatcher.
Definition dispatcher.h:166