Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 1 | #ifndef AOS_EVENTS_SIMULATED_NETWORK_BRIDGE_H_ |
| 2 | #define AOS_EVENTS_SIMULATED_NETWORK_BRIDGE_H_ |
| 3 | |
| 4 | #include "aos/events/event_loop.h" |
| 5 | #include "aos/events/simulated_event_loop.h" |
| 6 | |
| 7 | namespace aos { |
| 8 | namespace message_bridge { |
| 9 | |
| 10 | class RawMessageDelayer; |
| 11 | |
| 12 | // This class moves messages between nodes. It is implemented as a separate |
| 13 | // class because it would have been even harder to manage forwarding in the |
| 14 | // SimulatedEventLoopFactory. |
| 15 | class SimulatedMessageBridge { |
| 16 | public: |
| 17 | // Constructs the bridge. |
| 18 | SimulatedMessageBridge( |
| 19 | SimulatedEventLoopFactory *simulated_event_loop_factory); |
| 20 | ~SimulatedMessageBridge(); |
| 21 | |
Austin Schuh | 6f3babe | 2020-01-26 20:34:50 -0800 | [diff] [blame] | 22 | // Disables forwarding for this channel. This should be used very rarely only |
| 23 | // for things like the logger. |
| 24 | void DisableForwarding(const Channel *channel); |
| 25 | |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 26 | private: |
| 27 | // Map of nodes to event loops. This is a member variable so that the |
| 28 | // lifetime of the event loops matches the lifetime of the bridge. |
| 29 | std::map<const Node *, std::unique_ptr<aos::EventLoop>> event_loop_map_; |
| 30 | |
Austin Schuh | 898f497 | 2020-01-11 17:21:25 -0800 | [diff] [blame] | 31 | // List of delayers used to resend the messages. |
| 32 | using DelayersVector = std::vector<std::unique_ptr<RawMessageDelayer>>; |
| 33 | std::vector<std::unique_ptr<DelayersVector>> delayers_list_; |
| 34 | }; |
| 35 | |
| 36 | } // namespace message_bridge |
| 37 | } // namespace aos |
| 38 | |
| 39 | #endif // AOS_EVENTS_SIMULATED_NETWORK_BRIDGE_H_ |