router.h
Go to the documentation of this file.
1 #ifndef SKYWAY_ROUTER_H
2 #define SKYWAY_ROUTER_H
3 
4 #include <fruit/fruit.h>
5 #include <rapidjson/document.h>
6 #include <rapidjson/stringbuffer.h>
7 #include <rapidjson/writer.h>
8 #include <ros/ros.h>
9 
10 #include "ffi/ros_functions.h"
14 
15 using namespace rapidjson;
16 using fruit::Component;
17 using fruit::Injector;
18 
19 class Router {
20  public:
21  virtual ~Router() = default;
22  virtual void OnCreatePeer(char* peer_id, char* token) {}
23  virtual PluginResult OnConnectData(std::string target_ip,
24  uint16_t target_port,
25  std::string plugin_type,
26  std::string plugin_param) = 0;
27  virtual void OnDeleteData(uint16_t port_num) {}
28 };
29 
30 class RouterImpl : public Router {
31  private:
32  std::string peer_id_ = "";
33  std::string token_ = "";
34  // factories
37  // ROS Serviceの実体
38  std::unique_ptr<ControlService> control_service_;
39  std::unique_ptr<EventsService> event_service_;
40 
41  // pluginの実体を管理する
42  std::unordered_map<std::string, std::unique_ptr<PluginRouter>> plugin_map_;
43  std::shared_ptr<IPluginRouterFactory> plugin_router_factory_;
44 
45  void shutdown(int signal);
46  std::string on_control_message(std::string);
47  std::string on_event_request();
48 
49  public:
50  RouterImpl() = delete;
51  INJECT(
52  RouterImpl(ControlServiceFactory control_service_factory,
53  EventsServiceFactory event_service_factory,
54  std::shared_ptr<IPluginRouterFactory> plugin_router_factory));
55 
57  control_service_->Shutdown();
58  event_service_->Shutdown();
59  }
60 
61  virtual void OnCreatePeer(char* peer_id, char* token) override;
62  virtual PluginResult OnConnectData(std::string target_ip, uint16_t,
63  std::string, std::string) override;
64  virtual void OnDeleteData(uint16_t port_num) override;
65 };
66 
67 Component<Router> getRouterComponent();
68 
69 #endif // SKYWAY_ROUTER_H
RouterImpl::plugin_map_
std::unordered_map< std::string, std::unique_ptr< PluginRouter > > plugin_map_
Definition: router.h:42
Router::OnDeleteData
virtual void OnDeleteData(uint16_t port_num)
Definition: router.h:27
RouterImpl::event_service_
std::unique_ptr< EventsService > event_service_
Definition: router.h:39
RouterImpl
Definition: router.h:30
ros.h
RouterImpl::event_service_factory_
EventsServiceFactory event_service_factory_
Definition: router.h:36
RouterImpl::control_service_factory_
ControlServiceFactory control_service_factory_
Definition: router.h:35
control_service.h
ros_functions.h
RouterImpl::plugin_router_factory_
std::shared_ptr< IPluginRouterFactory > plugin_router_factory_
Definition: router.h:43
shutdown
ROSCONSOLE_DECL void shutdown()
Router
Definition: router.h:19
RouterImpl::~RouterImpl
~RouterImpl()
Definition: router.h:56
ControlServiceFactory
std::function< std::unique_ptr< ControlService >(std::string, std::function< std::string(std::string)>)> ControlServiceFactory
Definition: control_service.h:54
plugin_router_factory.h
EventsServiceFactory
std::function< std::unique_ptr< EventsService >(std::string, std::function< std::string()>)> EventsServiceFactory
Definition: events_service.h:52
getRouterComponent
Component< Router > getRouterComponent()
Definition: router.cpp:101
PluginResult
Definition: plugin_router.h:14
Router::OnCreatePeer
virtual void OnCreatePeer(char *peer_id, char *token)
Definition: router.h:22
events_service.h
RouterImpl::control_service_
std::unique_ptr< ControlService > control_service_
Definition: router.h:38


skyway
Author(s): Toshiya Nakakura
autogenerated on Thu Oct 26 2023 02:42:21