Refactor GetChannel in event_loop.h
We were duplicating the GetChannel call in multiple spots to implement
multiple behaviors. Refactor the GetChannel call out to simplify the
other pieces of code.
Change-Id: I85494e64a974e03391e821ac7a0dea1aa1837859
diff --git a/aos/events/event_loop.h b/aos/events/event_loop.h
index 0534242..5320e1e 100644
--- a/aos/events/event_loop.h
+++ b/aos/events/event_loop.h
@@ -484,10 +484,14 @@
// Returns true if the channel exists in the configuration.
template <typename T>
- bool HasChannel(const std::string_view channel_name) {
+ const Channel *GetChannel(const std::string_view channel_name) {
return configuration::GetChannel(configuration(), channel_name,
T::GetFullyQualifiedName(), name(), node(),
- true) != nullptr;
+ true);
+ }
+ template <typename T>
+ bool HasChannel(const std::string_view channel_name) {
+ return GetChannel<T>(channel_name) != nullptr;
}
// Note, it is supported to create:
@@ -498,9 +502,7 @@
// sent to the provided channel.
template <typename T>
Fetcher<T> MakeFetcher(const std::string_view channel_name) {
- const Channel *channel =
- configuration::GetChannel(configuration(), channel_name,
- T::GetFullyQualifiedName(), name(), node());
+ const Channel *channel = GetChannel<T>(channel_name);
CHECK(channel != nullptr)
<< ": Channel { \"name\": \"" << channel_name << "\", \"type\": \""
<< T::GetFullyQualifiedName() << "\" } not found in config.";
@@ -519,9 +521,7 @@
// the provided channel.
template <typename T>
Sender<T> MakeSender(const std::string_view channel_name) {
- const Channel *channel =
- configuration::GetChannel(configuration(), channel_name,
- T::GetFullyQualifiedName(), name(), node());
+ const Channel *channel = GetChannel<T>(channel_name);
CHECK(channel != nullptr)
<< ": Channel { \"name\": \"" << channel_name << "\", \"type\": \""
<< T::GetFullyQualifiedName() << "\" } not found in config for "