blob: b62c5e94f8911d4f36e7bbd50356e92f853b9f59 [file] [log] [blame]
Austin Schuh36a2c3e2021-02-18 22:28:38 -08001#ifndef AOS_NETWORK_TIMESTAMP_CHANNEL_
2#define AOS_NETWORK_TIMESTAMP_CHANNEL_
3
4#include <vector>
5
6#include "absl/container/btree_map.h"
7#include "aos/configuration.h"
8#include "aos/events/event_loop.h"
9#include "aos/network/remote_message_generated.h"
10#include "glog/logging.h"
11
12namespace aos {
13namespace message_bridge {
14
15// Class to manage lifetime, and creating senders for channels and connections.
16class ChannelTimestampSender {
17 public:
18 ChannelTimestampSender(aos::EventLoop *event_loop);
19
20 aos::Sender<RemoteMessage> *SenderForChannel(const Channel *channel,
21 const Connection *connection);
22
23 private:
24 aos::EventLoop *event_loop_;
25
26 // We've got 3 cases to consider.
27 // 1) The old single channel per connection exists.
28 // 2) A new channel per channel exists.
29 // 3) Both exist.
30 //
31 // I want the default to be such that if no channel is found, we explode
32 // looking for the single channel per channel. This means users will add the
33 // new channel when blindly fixing errors, which is what we want.
34 //
35 // I'd prefer 3) to be an error, but don't have strong opinions. We will
36 // still be correct if it gets used, as long as everything is consistent.
37
38 // List of Senders per node.
39 std::vector<aos::Sender<RemoteMessage>> timestamp_loggers_;
40
41 // Mapping from channel and connection to logger.
42 absl::btree_map<std::pair<const Channel *, const Connection *>,
43 std::unique_ptr<aos::Sender<RemoteMessage>>>
44 channel_timestamp_loggers_;
45};
46
47} // namespace message_bridge
48} // namespace aos
49
50#endif // AOS_NETWORK_TIMESTAMP_CHANNEL_