MT Showcase SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
GraphConsumer.hpp
1 #pragma once
2 
3 #include <Radiant/Flags.hpp>
4 #include <unordered_map>
5 #include <folly/Executor.h>
6 
7 #include "Graph.hpp"
8 #include "Hashes.hpp"
9 
10 namespace Showcase
11 {
12 
15 
18 
22  class SHOWCASE_API GraphConsumer : public std::enable_shared_from_this<GraphConsumer>
23  {
24  public:
25  GraphConsumer(Radiant::FlagsT<GraphEventSource> monitorFlags);
26  virtual ~GraphConsumer();
27 
28  void setMonitorFlags(Radiant::FlagsT<GraphEventSource> monitorFlags);
29  Radiant::FlagsT<GraphEventSource> monitorFlags() const;
30 
39  void initStreams(GraphPtr graph, const GraphNode& node, int consume=0);
40 
42  GraphPtr sourceGraph() const;
43 
45  PropertyEventStreamPtr propertyStream();
46 
47 
48  protected:
53  virtual std::shared_ptr<folly::Executor> getExecutor() { return nullptr; }
54 
55  void initPropertyListener();
56  void initChildListener();
57  void initEdgePropertyListener(const EdgeId& id);
58 
59  virtual void onChildEvent(const NodeEvent& ev) = 0;
60  virtual void onPropertyEvent(const PropertyEvent& ev) = 0;
61  virtual void onEdgePropertyEvent(const PropertyEvent& ev, const EdgeId& id) = 0;
62 
63  private:
65  void onChildEventInternal(const NodeEvent& ev, bool consume=false);
66 
67  NodeEventStreamPtr m_childrenStream;
68  PropertyEventStreamPtr m_propertyStream;
69  std::unordered_map<EdgeId, PropertyEventStreamPtr> m_edgePropertyStreams;
70 
71  std::mutex m_edgeStreamMutex;
72 
73  std::weak_ptr<Graph> m_graph;
74 
75  Radiant::FlagsT<GraphEventSource> m_eventsToMonitor;
76  };
77 
78 }