Move log reader and writer over to split timestamp channels
Reuse TimestampChannel (and split it up further) to implement naming and
finding channels for log reader and writer. Test both the old and new
timestamp configuration.
Once the config changes go in for y2020, this should fix reading the log
file James broke.
Change-Id: I6b09eec69c064ded3b3c149e0fdf23162bd352cf
diff --git a/aos/network/timestamp_channel.h b/aos/network/timestamp_channel.h
index b62c5e9..1702632 100644
--- a/aos/network/timestamp_channel.h
+++ b/aos/network/timestamp_channel.h
@@ -1,6 +1,7 @@
#ifndef AOS_NETWORK_TIMESTAMP_CHANNEL_
#define AOS_NETWORK_TIMESTAMP_CHANNEL_
+#include <string_view>
#include <vector>
#include "absl/container/btree_map.h"
@@ -12,6 +13,30 @@
namespace aos {
namespace message_bridge {
+// Class to find the corresponding channel where timestamps for a specified data
+// channel and connection will be logged.
+class ChannelTimestampFinder {
+ public:
+ ChannelTimestampFinder(aos::EventLoop *event_loop)
+ : ChannelTimestampFinder(event_loop->configuration(), event_loop->name(),
+ event_loop->node()) {}
+ ChannelTimestampFinder(const Configuration *configuration,
+ const std::string_view name, const Node *node);
+
+ // Finds the timestamp logging channel for the provided data channel and
+ // connection.
+ const Channel *ForChannel(const Channel *channel,
+ const Connection *connection);
+ std::string SplitChannelName(const Channel *channel,
+ const Connection *connection);
+ std::string CombinedChannelName(std::string_view remote_node);
+
+ private:
+ const Configuration *configuration_;
+ const std::string_view name_;
+ const Node *node_;
+};
+
// Class to manage lifetime, and creating senders for channels and connections.
class ChannelTimestampSender {
public:
@@ -35,13 +60,15 @@
// I'd prefer 3) to be an error, but don't have strong opinions. We will
// still be correct if it gets used, as long as everything is consistent.
- // List of Senders per node.
- std::vector<aos::Sender<RemoteMessage>> timestamp_loggers_;
-
// Mapping from channel and connection to logger.
absl::btree_map<std::pair<const Channel *, const Connection *>,
- std::unique_ptr<aos::Sender<RemoteMessage>>>
+ std::shared_ptr<aos::Sender<RemoteMessage>>>
channel_timestamp_loggers_;
+
+ // Mapping from channel to RemoteMessage sender. This is the channel that
+ // timestamps are published to.
+ absl::btree_map<const Channel *, std::shared_ptr<aos::Sender<RemoteMessage>>>
+ timestamp_loggers_;
};
} // namespace message_bridge