Change the event-loop restriction
It's weird but acceptable to create as many fetchers as you want.
RobotState is a common thing that multiple people want. We don't want
to support senders and watchers on the same loop (do you get your own
messages?) until there's a valid use case.
Change-Id: I215f452311d3f47ffd487d78885ae2848c6ffe9b
diff --git a/aos/events/simulated-event-loop.cc b/aos/events/simulated-event-loop.cc
index e82c381..a23b18c 100644
--- a/aos/events/simulated-event-loop.cc
+++ b/aos/events/simulated-event-loop.cc
@@ -1,4 +1,7 @@
#include "aos/events/simulated-event-loop.h"
+
+#include <algorithm>
+
#include "aos/queue.h"
namespace aos {
@@ -80,13 +83,13 @@
std::unique_ptr<RawSender> SimulatedEventLoop::MakeRawSender(
const std::string &path, const QueueTypeInfo &type) {
+ Take(path);
::std::pair<::std::string, QueueTypeInfo> key(path, type);
return GetSimulatedQueue(key)->MakeRawSender();
}
std::unique_ptr<RawFetcher> SimulatedEventLoop::MakeRawFetcher(
const std::string &path, const QueueTypeInfo &type) {
- Take(path);
::std::pair<::std::string, QueueTypeInfo> key(path, type);
return GetSimulatedQueue(key)->MakeRawFetcher();
}
@@ -116,12 +119,15 @@
return std::unique_ptr<RawFetcher>(new SimulatedFetcher(this));
}
-void SimulatedEventLoop::Take(const std::string &path) {
+void SimulatedEventLoop::Take(const ::std::string &path) {
if (is_running()) {
::aos::Die("Cannot add new objects while running.\n");
}
- if (!taken_.emplace(path).second) {
- ::aos::Die("%s already has a listener / watcher.", path.c_str());
+ const auto prior = ::std::find(taken_.begin(), taken_.end(), path);
+ if (prior != taken_.end()) {
+ ::aos::Die("%s is already being used.", path.c_str());
+ } else {
+ taken_.emplace_back(path);
}
}
} // namespace aos