Move node() == nullptr check into //aos:configuration
This simplifies the code surprisingly significantly for dealing with
single node systems.
Change-Id: Ib317e16a9055fbf1341a194120a5b34f05b2d8f8
diff --git a/aos/configuration.cc b/aos/configuration.cc
index 112c567..4a98297 100644
--- a/aos/configuration.cc
+++ b/aos/configuration.cc
@@ -643,10 +643,17 @@
}
bool ChannelIsSendableOnNode(const Channel *channel, const Node *node) {
+ if (node == nullptr) {
+ return true;
+ }
return (channel->source_node()->string_view() == node->name()->string_view());
}
bool ChannelIsReadableOnNode(const Channel *channel, const Node *node) {
+ if (node == nullptr) {
+ return true;
+ }
+
if (channel->source_node()->string_view() == node->name()->string_view()) {
return true;
}
diff --git a/aos/events/event_loop.cc b/aos/events/event_loop.cc
index ee3365d..a370ca8 100644
--- a/aos/events/event_loop.cc
+++ b/aos/events/event_loop.cc
@@ -361,14 +361,12 @@
// Since we are using a RawSender, validity isn't checked. So check it
// ourselves.
- if (node() != nullptr) {
- if (!configuration::ChannelIsSendableOnNode(channel, node())) {
- LOG(FATAL) << "Channel { \"name\": \"/aos"
- << channel->name()->string_view() << "\", \"type\": \""
- << channel->type()->string_view()
- << "\" } is not able to be sent on this node. Check your "
- "configuration.";
- }
+ if (!configuration::ChannelIsSendableOnNode(channel, node())) {
+ LOG(FATAL) << "Channel { \"name\": \"/aos"
+ << channel->name()->string_view() << "\", \"type\": \""
+ << channel->type()->string_view()
+ << "\" } is not able to be sent on this node. Check your "
+ "configuration.";
}
CHECK(channel != nullptr) << ": Channel { \"name\": \"/aos\", \"type\": \""
<< timing::Report::GetFullyQualifiedName()
diff --git a/aos/events/event_loop.h b/aos/events/event_loop.h
index 4ac6e6d..ea2bf6e 100644
--- a/aos/events/event_loop.h
+++ b/aos/events/event_loop.h
@@ -370,14 +370,11 @@
<< ": Channel { \"name\": \"" << channel_name << "\", \"type\": \""
<< T::GetFullyQualifiedName() << "\" } not found in config.";
- if (node() != nullptr) {
- if (!configuration::ChannelIsReadableOnNode(channel, node())) {
- LOG(FATAL)
- << "Channel { \"name\": \"" << channel_name << "\", \"type\": \""
- << T::GetFullyQualifiedName()
- << "\" } is not able to be fetched on this node. Check your "
- "configuration.";
- }
+ if (!configuration::ChannelIsReadableOnNode(channel, node())) {
+ LOG(FATAL) << "Channel { \"name\": \"" << channel_name
+ << "\", \"type\": \"" << T::GetFullyQualifiedName()
+ << "\" } is not able to be fetched on this node. Check your "
+ "configuration.";
}
return Fetcher<T>(MakeRawFetcher(channel));
@@ -394,13 +391,11 @@
<< ": Channel { \"name\": \"" << channel_name << "\", \"type\": \""
<< T::GetFullyQualifiedName() << "\" } not found in config.";
- if (node() != nullptr) {
- if (!configuration::ChannelIsSendableOnNode(channel, node())) {
- LOG(FATAL) << "Channel { \"name\": \"" << channel_name
- << "\", \"type\": \"" << T::GetFullyQualifiedName()
- << "\" } is not able to be sent on this node. Check your "
- "configuration.";
- }
+ if (!configuration::ChannelIsSendableOnNode(channel, node())) {
+ LOG(FATAL) << "Channel { \"name\": \"" << channel_name
+ << "\", \"type\": \"" << T::GetFullyQualifiedName()
+ << "\" } is not able to be sent on this node. Check your "
+ "configuration.";
}
return Sender<T>(MakeRawSender(channel));
diff --git a/aos/events/event_loop_tmpl.h b/aos/events/event_loop_tmpl.h
index 0d7b419..60e8216 100644
--- a/aos/events/event_loop_tmpl.h
+++ b/aos/events/event_loop_tmpl.h
@@ -36,13 +36,11 @@
<< ": Channel { \"name\": \"" << channel_name << "\", \"type\": \""
<< T::GetFullyQualifiedName() << "\" } not found in config.";
- if (node() != nullptr) {
- if (!configuration::ChannelIsReadableOnNode(channel, node())) {
- LOG(FATAL) << "Channel { \"name\": \"" << channel_name
- << "\", \"type\": \"" << T::GetFullyQualifiedName()
- << "\" } is not able to be watched on this node. Check your "
- "configuration.";
- }
+ if (!configuration::ChannelIsReadableOnNode(channel, node())) {
+ LOG(FATAL) << "Channel { \"name\": \"" << channel_name << "\", \"type\": \""
+ << T::GetFullyQualifiedName()
+ << "\" } is not able to be watched on this node. Check your "
+ "configuration.";
}
return MakeRawWatcher(
diff --git a/aos/events/shm_event_loop.cc b/aos/events/shm_event_loop.cc
index 0ca713f..e30e2f2 100644
--- a/aos/events/shm_event_loop.cc
+++ b/aos/events/shm_event_loop.cc
@@ -550,14 +550,11 @@
::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.";
- }
+ 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));
@@ -575,13 +572,11 @@
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.";
- }
+ 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>(
diff --git a/aos/events/simulated_event_loop.cc b/aos/events/simulated_event_loop.cc
index 578e151..a2740e4 100644
--- a/aos/events/simulated_event_loop.cc
+++ b/aos/events/simulated_event_loop.cc
@@ -473,13 +473,11 @@
ChannelIndex(channel);
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.";
- }
+ 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.";
}
std::unique_ptr<SimulatedWatcher> shm_watcher(
@@ -500,13 +498,11 @@
const Channel *channel) {
ChannelIndex(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.";
- }
+ 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 GetSimulatedChannel(channel)->MakeRawFetcher(this);