Kaspersky Neuromorphic Platform  1.0.0
API Reference
Loading...
Searching...
No Matches
input_channel.h
Go to the documentation of this file.
1
21#pragma once
22
23#include <knp/core/core.h>
24
25#include <utility>
26#include <vector>
27
28#include "input_converter.h"
29
30
35{
36
40class KNP_DECLSPEC InputChannel
41{
42public:
49 InputChannel(const core::UID &channel_uid, core::MessageEndpoint &&endpoint, const DataGenerator &generator)
50 : base_{channel_uid}, endpoint_(std::move(endpoint)), generator_(generator)
51 {
52 }
53
57 InputChannel(const core::UID &channel_uid, core::MessageEndpoint &&endpoint, DataGenerator &&generator)
58 : base_{channel_uid}, endpoint_(std::move(endpoint)), generator_(std::move(generator))
59 {
60 }
61
65 InputChannel(InputChannel &&) = default;
66
70 virtual ~InputChannel() = default;
71
72public:
77 [[nodiscard]] const auto &get_uid() const { return base_.uid_; }
83 [[nodiscard]] auto &get_tags() { return base_.tags_; }
84
85public:
92 virtual bool send(core::Step step) { return send_data(generator_(step), step); }
93
94protected:
101 bool send_data(const core::messaging::SpikeData &spikes, core::Step step)
102 {
103 if (spikes.empty())
104 {
105 return false;
106 }
107
108 core::messaging::SpikeMessage message{{get_uid(), step}, spikes};
109 endpoint_.send_message(message);
110 return true;
111 }
112
113private:
114 core::BaseData base_;
115
119 core::MessageEndpoint endpoint_;
120
124 DataGenerator generator_;
125};
126
127
135inline void connect_input(
136 const InputChannel &channel, core::MessageEndpoint &target_endpoint, const core::UID &receiver_uid)
137{
138 target_endpoint.subscribe<core::messaging::SpikeMessage>(receiver_uid, {channel.get_uid()});
139}
140
141} // namespace knp::framework::io::input
Subscription< MessageType > & subscribe(const UID &receiver, const std::vector< UID > &senders)
Add a subscription to messages of the specified type from senders with given UIDs.
The InputChannel class is a definition of an input channel.
const auto & get_uid() const
Get backend UID.
virtual bool send(core::Step step)
Read data from input stream, form a spike message and send it to an endpoint.
auto & get_tags()
Get tags used by the backend.
InputChannel(InputChannel &&)=default
Move constructor.
InputChannel(const core::UID &channel_uid, core::MessageEndpoint &&endpoint, const DataGenerator &generator)
Input channel constructor.
virtual ~InputChannel()=default
Virtual default destructor of input channel.
InputChannel(const core::UID &channel_uid, core::MessageEndpoint &&endpoint, DataGenerator &&generator)
Input channel constructor.
bool send_data(const core::messaging::SpikeData &spikes, core::Step step)
Send spike messages to message endpoint.
Class definition for core library basic entities.
Header for input converter.
Input channel namespace.
void connect_input(const InputChannel &channel, core::MessageEndpoint &target_endpoint, const core::UID &receiver_uid)
Connect input channel to a target entity.
std::function< core::messaging::SpikeData(core::Step)> DataGenerator
Functor used for generating input spike messages.