FauxEventHandler.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <swarmio/Exception.h>
4 #include <swarmio/data/discovery/Schema.pb.h>
6 #include <map>
7 #include <iostream>
8 
9 namespace swarmio::simulator
10 {
17  {
18  private:
19 
24  std::string _name;
25 
30  std::map<std::string, data::discovery::Type> _parameters;
31 
32  public:
33 
39  FauxEventHandler(const std::string& name)
40  : _name(name) { }
41 
48  void AddParameter(const std::string& key, data::discovery::Type type)
49  {
50  _parameters[key] = type;
51  }
52 
61  virtual void EventWasTriggered(const Node* node, const data::event::Notification& event) override { }
62 
70  virtual data::discovery::Schema DescribeEvent(const std::string& name) override
71  {
72  if (name == _name)
73  {
74  data::discovery::Schema schema;
75  for (auto p : _parameters)
76  {
77  (*schema.mutable_fields())[p.first].set_type(p.second);
78  }
79  return schema;
80  }
81  else
82  {
83  throw Exception("Fake event handler queried for unknown event.");
84  }
85  }
86 
92  const std::string& GetName() const
93  {
94  return _name;
95  }
96  };
97 }
98 
A special event handler that serves discovery information and ignores the event itself.
const std::string & GetName() const
Get the name of the event.
Exception class thrown by all library classes.
virtual data::discovery::Schema DescribeEvent(const std::string &name) override
Handlers may add parameter descriptors to the event descriptor when asked to do so by overriding this...
virtual void EventWasTriggered(const Node *node, const data::event::Notification &event) override
Handlers are notified using this method when an event has been triggered.
void AddParameter(const std::string &key, data::discovery::Type type)
Add a new parameter to serve for discovery.
std::map< std::string, data::discovery::Type > _parameters
Parameters.
Abstract base class for Event handlers.
Definition: Handler.h:13
Represents a Node the Endpoint knows about and can send messages to.
FauxEventHandler(const std::string &name)
Create a new fake event handler.


swarmros
Author(s):
autogenerated on Fri Apr 3 2020 03:42:48