41 virtual void connect(std::optional<unsigned> bufferSize = std::nullopt) = 0;
70 virtual void connectImpl(std::optional<unsigned> bufferSize) {}
79 connect(std::optional<unsigned> bufferSize = std::nullopt)
override {
110 return mode != Mode::Disconnected;
125 std::optional<unsigned> bufferSize = std::nullopt);
137 connect(std::optional<unsigned> bufferSize = std::nullopt)
override;
140 virtual std::future<MessageData>
readAsync();
145 std::future<MessageData> f =
readAsync();
147 outData = std::move(f.get());
189 return bundleDir == BundleType::Direction::To;
213 template <
typename T>
215 return const_cast<T *
>(
dynamic_cast<const T *
>(
this));
223 result |= channel.second.poll();
Services provide connections to 'bundles' – collections of named, unidirectional communication channe...
virtual ~BundlePort()=default
std::map< std::string, ChannelPort & > channels
ReadChannelPort & getRawRead(const std::string &name) const
WriteChannelPort & getRawWrite(const std::string &name) const
Get access to the raw byte streams of a channel.
bool poll()
Calls poll on all channels in the bundle and returns true if any of them returned true.
const std::map< std::string, ChannelPort & > & getChannels() const
T * getAs() const
Cast this Bundle port to a subclass which is actually useful.
static bool isWrite(BundleType::Direction bundleDir)
Compute the direction of a channel given the bundle direction and the bundle port's direction.
BundlePort(AppID id, std::map< std::string, ChannelPort & > channels)
Construct a port.
AppID getID() const
Get the ID of the port.
Unidirectional channels are the basic communication primitive between the host and accelerator.
ChannelPort(const Type *type)
virtual void disconnect()=0
virtual void connect(std::optional< unsigned > bufferSize=std::nullopt)=0
Set up a connection to the accelerator.
virtual void connectImpl(std::optional< unsigned > bufferSize)
Called by all connect methods to let backends initiate the underlying connections.
virtual bool pollImpl()
Method called by poll() to actually poll the channel if the channel is connected.
const Type * getType() const
bool poll()
Poll for incoming data.
virtual bool isConnected() const =0
A logical chunk of data representing serialized data.
A ChannelPort which reads data from the accelerator.
virtual std::future< MessageData > readAsync()
Asynchronous read.
virtual bool isConnected() const override
std::mutex pollingM
Mutex to protect the two queues used for polling.
virtual void connect(std::function< bool(MessageData)> callback, std::optional< unsigned > bufferSize=std::nullopt)
std::function< bool(MessageData)> callback
Backends call this callback when new data is available.
Mode
Indicates the current mode of the channel.
std::queue< MessageData > dataQueue
Store incoming data here if there are no outstanding promises to be fulfilled.
static constexpr uint64_t DefaultMaxDataQueueMsgs
Default max data queue size set at connect time.
std::queue< std::promise< MessageData > > promiseQueue
Promises to be fulfilled when data is available.
void setMaxDataQueueMsgs(uint64_t maxMsgs)
Set maximum number of messages to store in the dataQueue.
uint64_t maxDataQueueMsgs
Maximum number of messages to store in dataQueue. 0 means no limit.
virtual void disconnect() override
virtual void read(MessageData &outData)
Specify a buffer to read into.
ReadChannelPort(const Type *type)
Root class of the ESI type system.
A ChannelPort which sends data to the accelerator.
virtual bool isConnected() const override
virtual void disconnect() override
virtual void write(const MessageData &)=0
A very basic blocking write API.
virtual bool tryWrite(const MessageData &data)=0
A basic non-blocking write API.
virtual void connect(std::optional< unsigned > bufferSize=std::nullopt) override
Set up a connection to the accelerator.