Add basic support for nodes
This adds the infrastructure and configuration language to describe a
multinode world. This only checks that if there are multiple nodes
setup, everything is both configured for multiple nodes, and that we are
listening and sending data on the correct node per the configuration.
Change-Id: I658ba05620337a210d677c43e5eb840e05f96051
diff --git a/aos/events/shm_event_loop.cc b/aos/events/shm_event_loop.cc
index e549d57..e696f36 100644
--- a/aos/events/shm_event_loop.cc
+++ b/aos/events/shm_event_loop.cc
@@ -126,6 +126,8 @@
void *data_;
};
+namespace {
+
// Returns the portion of the path after the last /.
std::string_view Filename(std::string_view path) {
auto last_slash_pos = path.find_last_of("/");
@@ -135,15 +137,23 @@
: path.substr(last_slash_pos + 1, path.size());
}
-ShmEventLoop::ShmEventLoop(const Configuration *configuration)
- : EventLoop(configuration), name_(Filename(program_invocation_name)) {}
+const Node *MaybeMyNode(const Configuration *configuration) {
+ if (!configuration->has_nodes()) {
+ return nullptr;
+ }
-namespace {
+ return configuration::GetMyNode(configuration);
+}
namespace chrono = ::std::chrono;
} // namespace
+ShmEventLoop::ShmEventLoop(const Configuration *configuration)
+ : EventLoop(configuration),
+ name_(Filename(program_invocation_name)),
+ node_(MaybeMyNode(configuration)) {}
+
namespace internal {
class SimpleShmFetcher {
@@ -508,6 +518,16 @@
::std::unique_ptr<RawFetcher> ShmEventLoop::MakeRawFetcher(
const Channel *channel) {
+
+ if (node() != nullptr) {
+ if (!configuration::ChannelIsReadableOnNode(channel, node())) {
+ LOG(FATAL) << "Channel { \"name\": \"" << channel->name()->string_view()
+ << "\", \"type\": \"" << channel->type()->string_view()
+ << "\" } is not able to be fetched on this node. Check your "
+ "configuration.";
+ }
+ }
+
return ::std::unique_ptr<RawFetcher>(new internal::ShmFetcher(this, channel));
}
@@ -523,6 +543,15 @@
std::function<void(const Context &context, const void *message)> watcher) {
Take(channel);
+ if (node() != nullptr) {
+ if (!configuration::ChannelIsReadableOnNode(channel, node())) {
+ LOG(FATAL) << "Channel { \"name\": \"" << channel->name()->string_view()
+ << "\", \"type\": \"" << channel->type()->string_view()
+ << "\" } is not able to be watched on this node. Check your "
+ "configuration.";
+ }
+ }
+
NewWatcher(::std::unique_ptr<WatcherState>(
new internal::WatcherState(this, channel, std::move(watcher))));
}