BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
CommandDispatcher.h
1 #pragma once
2 
3 #include <Poco/SharedPtr.h>
4 
5 #include "core/CommandDispatcherListener.h"
6 #include "core/CommandHandler.h"
7 #include "util/EventSource.h"
8 #include "util/Loggable.h"
9 
10 namespace BeeeOn {
11 
12 class CommandDispatcher : protected Loggable {
13 public:
14  virtual ~CommandDispatcher();
15 
16  /*
17  * Register a command handler for command dispatching.
18  */
19  void registerHandler(Poco::SharedPtr<CommandHandler> handler);
20 
21  /*
22  * The operation might be asynchronous. The result of the command can come
23  * later. The given instance of result must ensure that the result
24  * will be set to Result::SUCCESS or Result::ERROR after the execution of
25  * CommandHandler::handle().
26  */
27  void dispatch(Command::Ptr cmd, Answer::Ptr answer);
28 
29  void registerListener(CommandDispatcherListener::Ptr listener);
30  void setEventsExecutor(AsyncExecutor::Ptr executor);
31 
32 protected:
33  virtual void dispatchImpl(Command::Ptr cmd, Answer::Ptr answer) = 0;
34 
35 protected:
36  std::list<Poco::SharedPtr<CommandHandler>> m_commandHandlers;
37 
38 private:
40 };
41 
42 }
EventSource implements common logic for firing events to listeners.
Definition: EventSource.h:24
Definition: Loggable.h:19
Definition: CommandDispatcher.h:12