Add channel method to fetchers and senders.
This makes it easy to figure out which channel a fetcher or sender
is connected to.
Also add a test to confirm that the channel pointer points to a channel
inside configuration() for the event loop.
Change-Id: Iee0edca66394ef825dac482d7e3f568c6ed3441f
diff --git a/aos/events/event_loop.h b/aos/events/event_loop.h
index f614517..278fc9c 100644
--- a/aos/events/event_loop.h
+++ b/aos/events/event_loop.h
@@ -34,7 +34,7 @@
// fetchers.
class RawFetcher {
public:
- RawFetcher() {}
+ RawFetcher(const Channel *channel) : channel_(channel) {}
virtual ~RawFetcher() {}
// Non-blocking fetch of the next message in the queue. Returns true if there
@@ -50,19 +50,22 @@
const Context &context() const { return context_; }
+ const Channel *channel() const { return channel_; }
+
protected:
RawFetcher(const RawFetcher &) = delete;
RawFetcher &operator=(const RawFetcher &) = delete;
void *data_ = nullptr;
Context context_;
+ const Channel *channel_;
};
// Raw version of sender. Sends a block of data. This is used for reflection
// and as a building block to implement typed senders.
class RawSender {
public:
- RawSender() {}
+ RawSender(const Channel *channel) : channel_(channel) {}
virtual ~RawSender() {}
// Sends a message without copying it. The users starts by copying up to
@@ -78,9 +81,13 @@
// Returns the name of this sender.
virtual const absl::string_view name() const = 0;
+ const Channel *channel() const { return channel_; }
+
protected:
RawSender(const RawSender &) = delete;
RawSender &operator=(const RawSender &) = delete;
+
+ const Channel *channel_;
};
@@ -306,11 +313,14 @@
// Returns the configuration that this event loop was built with.
const Configuration *configuration() const { return configuration_; }
+ // Will send new messages from channel (path, type).
+ virtual std::unique_ptr<RawSender> MakeRawSender(const Channel *channel) = 0;
+
protected:
void set_is_running(bool value) { is_running_.store(value); }
- // Will send new messages from channel (path, type).
- virtual std::unique_ptr<RawSender> MakeRawSender(const Channel *channel) = 0;
+ // Validates that channel exists inside configuration_.
+ void ValidateChannel(const Channel *channel);
private:
::std::atomic<bool> is_running_{false};