22#ifndef ESI_TYPED_PORTS_H
23#define ESI_TYPED_PORTS_H
55 using std::runtime_error::runtime_error;
73 return {(bv->getWidth() + 7) / 8, bv->getWidth()};
81 if constexpr (std::is_integral_v<T> && !std::is_same_v<T, bool>) {
83 std::vector<uint8_t> buf(wi.
bytes, 0);
84 std::memcpy(buf.data(), &data, std::min(wi.
bytes,
sizeof(T)));
87 }
else if constexpr (std::is_base_of_v<SegmentedMessageData, T>) {
88 return data.toMessageData();
90 return MessageData(
reinterpret_cast<const uint8_t *
>(&data),
sizeof(T));
104 if constexpr (std::is_integral_v<T> && !std::is_same_v<T, bool>) {
109 std::memcpy(&val, msg.
getBytes(), std::min(wi.
bytes,
sizeof(T)));
111 if constexpr (std::is_signed_v<T>) {
113 size_t signByte = signBit / 8;
114 uint8_t signMask = uint8_t(1) << (signBit % 8);
115 if (signByte < wi.
bytes && (msg.
getBytes()[signByte] & signMask)) {
118 val |=
static_cast<T
>(~T(0)) << wi.
bitWidth;
141template <
typename T,
typename =
void>
165 bool push(std::unique_ptr<SegmentedMessageData> &msg) {
166 std::scoped_lock<std::mutex> lock(
mutex);
168 throw std::runtime_error(
"PODTypeDeserializer::push: null message");
186 std::scoped_lock<std::mutex> lock(
mutex);
205template <
typename T,
typename =
void>
212 using type =
typename T::TypeDeserializer;
245 bool push(std::unique_ptr<SegmentedMessageData> &msg) {
246 std::scoped_lock<std::mutex> lock(
mutex);
248 throw std::runtime_error(
249 "QueuedDecodeTypeDeserializer::push: null message");
256 throw std::runtime_error(
257 "QueuedDecodeTypeDeserializer::push: decode must consume the "
259 for (std::unique_ptr<T> &value : decoded) {
261 throw std::runtime_error(
262 "QueuedDecodeTypeDeserializer::push: null decoded output");
276 std::scoped_lock<std::mutex> lock(
mutex);
292 throw std::runtime_error(
293 "QueuedDecodeTypeDeserializer::poke: null pending output");
339 "header and data frames must be the same width");
346 const uint8_t *bytes = flat.
getBytes();
350 while (offset < size) {
352 size_t chunk = std::min(needed, size - offset);
366 count_type batchCount = T::_headerCount(frame);
367 if (batchCount == 0) {
371 throw std::runtime_error(
372 "SerialListTypeDeserializer: footer received before any "
408template <
typename T,
typename =
void>
413 : std::is_convertible<decltype(T::_ESI_ID), std::string_view> {};
420template <
typename T,
typename =
void>
425 : std::is_convertible<decltype(T::_ESI_WINDOW_ID), std::string_view> {};
441template <
typename T, std::
size_t N>
456 if (
auto *windowType =
dynamic_cast<const WindowType *
>(portType)) {
458 if (std::string_view(windowType->getID()) != T::_ESI_WINDOW_ID)
460 "ESI window mismatch: C++ type has _ESI_WINDOW_ID '" +
461 std::string(T::_ESI_WINDOW_ID) +
"' but port window type is '" +
462 windowType->toString(
true) +
"'");
465 "ESI type mismatch: port is a window type ('" +
466 windowType->toString(
true) +
467 "') but C++ type has no _ESI_WINDOW_ID");
472 std::string(
"ESI type mismatch: C++ type has _ESI_WINDOW_ID '") +
473 std::string(T::_ESI_WINDOW_ID) +
"' but port type is not a window: '" +
479 if (std::string_view(portType->
getID()) != T::_ESI_ID)
481 "ESI type mismatch: C++ type has _ESI_ID '" +
482 std::string(T::_ESI_ID) +
"' but port type is '" +
484 }
else if constexpr (std::is_void_v<T>) {
485 if (!
dynamic_cast<const VoidType *
>(portType))
487 "void, but port type is '" +
490 }
else if constexpr (std::is_same_v<T, bool>) {
492 auto *bits =
dynamic_cast<const BitsType *
>(portType);
493 if (!bits || bits->getWidth() > 1)
495 "ESI type mismatch: expected BitsType with width <= 1 for "
496 "bool, but port type is '" +
503 using Element =
typename T::value_type;
504 constexpr size_t N = std::tuple_size<T>::value;
505 auto *arr =
dynamic_cast<const ArrayType *
>(portType);
508 "ESI type mismatch: expected ArrayType for std::array, but port "
511 if (arr->getSize() != N)
513 std::to_string(arr->getSize()) +
514 " does not match std::array size " +
517 }
else if constexpr (std::is_integral_v<T> && std::is_signed_v<T>) {
518 auto *sint =
dynamic_cast<const SIntType *
>(portType);
521 "ESI type mismatch: expected SIntType for signed integer, "
522 "but port type is '" +
524 if (sint->getWidth() >
sizeof(T) * 8)
526 "ESI type mismatch: SIntType width " +
527 std::to_string(sint->getWidth()) +
" does not fit in " +
528 std::to_string(
sizeof(T) * 8) +
"-bit signed integer");
530 if (
sizeof(T) > 1 && sint->getWidth() <= (
sizeof(T) / 2) * 8)
532 std::to_string(sint->getWidth()) +
533 " should use a smaller C++ type than " +
534 std::to_string(
sizeof(T) * 8) +
"-bit");
535 }
else if constexpr (std::is_integral_v<T> && std::is_unsigned_v<T>) {
537 auto *uintPort =
dynamic_cast<const UIntType *
>(portType);
538 auto *bits =
dynamic_cast<const BitsType *
>(portType);
539 if (!uintPort && !bits)
541 "ESI type mismatch: expected UIntType or BitsType for unsigned "
542 "integer, but port type is '" +
544 uint64_t width = uintPort ? uintPort->getWidth() : bits->getWidth();
545 if (width >
sizeof(T) * 8)
547 "ESI type mismatch: bit width " + std::to_string(width) +
548 " does not fit in " + std::to_string(
sizeof(T) * 8) +
549 "-bit unsigned integer");
551 if (
sizeof(T) > 1 && width <= (
sizeof(T) / 2) * 8)
553 std::to_string(width) +
554 " should use a smaller C++ type than " +
555 std::to_string(
sizeof(T) * 8) +
"-bit");
558 std::string(
"Cannot verify type compatibility for C++ type '") +
559 typeid(T).name() +
"' against ESI port type '" +
577 std::string(
"ESI type mismatch: C++ type has _ESI_WINDOW_ID '") +
578 std::string(T::_ESI_WINDOW_ID) +
579 "' but port is not a window type ('" +
581 : std::string(
"<null>")) +
586 "ESI type mismatch: port is a window type ('" +
588 "') but C++ type has no _ESI_WINDOW_ID");
590 const Type *forwardType =
591 windowType ?
static_cast<const Type *
>(windowType) : port->
getType();
603template <
typename T,
bool SkipTypeCheck = false>
634 throw std::invalid_argument(
635 "TypedWritePort::connect: null data fetch callback");
640 if constexpr (std::is_base_of_v<SegmentedMessageData, T>) {
641 rawFetch = [fetch = std::move(fetch)]()
642 -> std::unique_ptr<SegmentedMessageData> {
return fetch(); };
644 rawFetch = [fetch = std::move(fetch),
646 wireInfo_]() -> std::unique_ptr<SegmentedMessageData> {
647 std::unique_ptr<T> value = fetch();
650 return std::make_unique<MessageData>(
654 inner->connect(std::move(rawFetch), std::move(onError), opts);
664 void write(std::unique_ptr<T> &data) {
666 throw std::runtime_error(
"TypedWritePort::write: null unique_ptr");
667 if constexpr (std::is_base_of_v<SegmentedMessageData, T>) {
668 inner->write(std::move(data));
685 throw std::runtime_error(
"TypedWritePort::tryWrite: null unique_ptr");
686 if constexpr (std::is_base_of_v<SegmentedMessageData, T>) {
687 std::unique_ptr<SegmentedMessageData> msg(data.release());
690 written =
inner->tryWrite(msg);
692 data.reset(
static_cast<T *
>(msg.release()));
697 data.reset(
static_cast<T *
>(msg.release()));
748 throw std::invalid_argument(
749 "TypedWritePort::connect: null data fetch callback");
752 [fetch = std::move(fetch)]() -> std::unique_ptr<SegmentedMessageData> {
755 return std::make_unique<MessageData>(std::vector<uint8_t>{0});
757 std::move(onError), opts);
797template <
typename T,
bool SkipTypeCheck = false>
828 [
this](std::unique_ptr<SegmentedMessageData> &msg) ->
bool {
844 void connect(std::function<
bool(
const T &)> callback,
847 connect([cb = std::move(callback)](
848 std::unique_ptr<T> &value) ->
bool {
return cb(*value); },
866 [
this](std::unique_ptr<SegmentedMessageData> &msg) ->
bool {
882 std::future<std::unique_ptr<T>> f =
readAsync();
892 throw std::runtime_error(
893 "Cannot read from a callback channel. `connect()` without a "
894 "callback specified to use polling mode.");
896 throw std::runtime_error(
897 "Cannot read from a disconnected channel. `connect()` first.");
900 throw std::runtime_error(
901 "Cannot read from a disconnected channel. `connect()` first.");
903 std::future<std::unique_ptr<T>> future =
pollingState->readAsync();
949 throw std::runtime_error(
"Channel already connected");
950 if constexpr (SkipTypeCheck) {
1003 [cb = std::move(callback)](
MessageData) ->
bool {
return cb(); }, opts);
1008 inner->read(outData);
1012 auto innerFuture =
inner->readAsync();
1014 std::launch::deferred,
1015 [f = std::move(innerFuture)]()
mutable ->
void { f.get(); });
1062template <
typename T>
1064 return std::async(std::launch::deferred,
1065 [fut = std::move(inner)]()
mutable -> T {
1066 std::unique_ptr<T> v = fut.get();
1068 throw std::runtime_error(
1069 "TypedFunction: deserializer produced a null "
1071 return std::move(*v);
1079 "TypedFunction: null Function pointer (getAs failed or wrong type)");
1084 throw std::runtime_error(
"TypedFunction: must be 'connect'ed before "
1090 throw std::runtime_error(
"TypedFunction is already connected");
1095template <
typename ArgT,
typename ResultT,
bool SkipTypeCheck = false>
1116 std::future<ResultT>
call(
const ArgT &arg) {
1124 std::scoped_lock<std::mutex> lock(
callMutex);
1133 typename First,
typename... Rest,
1134 typename = std::enable_if_t<
1135 std::is_constructible_v<ArgT, First, Rest...> &&
1136 (!std::is_same_v<std::decay_t<First>, ArgT> ||
sizeof...(Rest) != 0)>>
1137 std::future<ResultT>
call(First &&first, Rest &&...rest) {
1138 return call(ArgT(std::forward<First>(first), std::forward<Rest>(rest)...));
1142 template <
typename... Args>
1144 ->
decltype(this->
call(std::forward<Args>(args)...)) {
1145 return call(std::forward<Args>(args)...);
1153 std::optional<TypedWritePort<ArgT, SkipTypeCheck>>
argPort;
1159template <
typename ResultT,
bool SkipTypeCheck>
1182 std::scoped_lock<std::mutex> lock(
callMutex);
1201template <
typename ArgT,
bool SkipTypeCheck>
1221 std::future<void>
call(
const ArgT &arg) {
1224 std::scoped_lock<std::mutex> lock(
callMutex);
1233 typename First,
typename... Rest,
1234 typename = std::enable_if_t<
1235 std::is_constructible_v<ArgT, First, Rest...> &&
1236 (!std::is_same_v<std::decay_t<First>, ArgT> ||
sizeof...(Rest) != 0)>>
1237 std::future<void>
call(First &&first, Rest &&...rest) {
1238 return call(ArgT(std::forward<First>(first), std::forward<Rest>(rest)...));
1242 template <
typename... Args>
1244 ->
decltype(this->
call(std::forward<Args>(args)...)) {
1245 return call(std::forward<Args>(args)...);
1253 std::optional<TypedWritePort<ArgT, SkipTypeCheck>>
argPort;
1259template <
bool SkipTypeCheck>
1282 std::scoped_lock<std::mutex> lock(
callMutex);
1338 "TypedCallback: null Callback pointer (getAs failed or wrong type)");
1344 throw std::runtime_error(
"TypedCallback is already connected");
1349template <
typename ArgT,
typename ResultT,
bool SkipTypeCheck = false>
1357 void connect(std::function<ResultT(
const ArgT &)> callback,
1358 bool quick =
false) {
1373 [
this](
const ArgT &arg) ->
bool {
1386 std::optional<TypedReadPort<ArgT, SkipTypeCheck>>
argPort;
1387 std::optional<TypedWritePort<ResultT, SkipTypeCheck>>
resultPort;
1392template <
typename ResultT,
bool SkipTypeCheck>
1400 void connect(std::function<ResultT()> callback,
bool quick =
false) {
1426 std::optional<TypedWritePort<ResultT, SkipTypeCheck>>
resultPort;
1431template <
typename ArgT,
bool SkipTypeCheck>
1439 void connect(std::function<
void(
const ArgT &)> callback,
bool quick =
false) {
1451 [
this](
const ArgT &arg) ->
bool {
1464 std::optional<TypedReadPort<ArgT, SkipTypeCheck>>
argPort;
1470template <
bool SkipTypeCheck>
1478 void connect(std::function<
void()> callback,
bool quick =
false) {
1517template <
typename T>
1558 BundlePort *port =
module->resolvePort(AppIDPath{id}, lastLookup);
1561 "' not found in module");
1568template <
typename T>
1571 T *result = port.
getAs<T>();
1574 "' has unexpected type (expected " +
1575 typeid(T).name() +
")");
1582 const std::string &name) {
1583 std::vector<uint32_t> indices;
1584 for (
const auto &[appid, port] : module->
getPorts())
1585 if (appid.name == name && appid.idx.has_value())
1586 indices.push_back(appid.idx.value());
1587 std::sort(indices.begin(), indices.end());
assert(baseType &&"element must be base type")
Arrays have a compile time specified (static) size and an element type.
Bit vectors include signed, unsigned, and signless integers.
Bits are just an array of bits.
Services provide connections to 'bundles' – collections of named, unidirectional communication channe...
T * getAs() const
Cast this Bundle port to a subclass which is actually useful.
Unidirectional channels are the basic communication primitive between the host and accelerator.
const Type * getType() const
const WindowType * getWindowType() const
If this port carries a windowed type, return the original WindowType (whose intoType is what getType(...
Represents either the top level or an instance of a hardware module.
const std::map< AppID, BundlePort & > & getPorts() const
Access the module's ports by ID.
const T & operator[](int idx) const
std::map< int, T > ports_
IndexedPorts(std::map< int, T > &&ports)
IndexedPorts & operator=(const IndexedPorts &)=delete
IndexedPorts(IndexedPorts &&)=default
IndexedPorts & operator=(IndexedPorts &&)=default
bool contains(int idx) const
IndexedPorts(const IndexedPorts &)=delete
A concrete flat message backed by a single vector of bytes.
const uint8_t * getBytes() const
const T * as() const
Cast to a type.
size_t getSize() const
Get the size of the data in bytes.
detail::TypedReadOwnedCallback< T > OutputCallback
QueuedDecodeTypeDeserializer(OutputCallback output)
virtual ~QueuedDecodeTypeDeserializer()=default
std::queue< std::unique_ptr< SerialCoordOutputBatch > > pendingOutputs
bool poke()
Retry delivery of any typed outputs which were previously blocked by the client callback.
bool push(std::unique_ptr< SegmentedMessageData > &msg)
Push one raw message into the deserializer.
virtual DecodedOutputs decode(std::unique_ptr< SegmentedMessageData > &msg)=0
Decode one raw message into zero or more typed outputs.
std::vector< std::unique_ptr< T > > DecodedOutputs
A ChannelPort which reads data from the accelerator.
virtual void connect(ReadCallback callback, const ConnectOptions &options={})
static constexpr uint64_t DefaultMaxDataQueueMsgs
Default max data queue size set at connect time.
const MessageData & asMessageData(MessageData &scratch) const
Return this message as a MessageData without copying if it already is one.
std::vector< data_frame > pending_frames_
typename Base::DecodedOutputs DecodedOutputs
DecodedOutputs decode(std::unique_ptr< SegmentedMessageData > &msg) override
Decode one raw message into zero or more typed outputs.
typename Base::OutputCallback OutputCallback
std::optional< header_frame > pending_header_
SerialListTypeDeserializer(OutputCallback output)
QueuedDecodeTypeDeserializer< T > Base
typename T::header_frame header_frame
static constexpr size_t kFrameSize
typename T::count_type count_type
typename T::data_frame data_frame
std::vector< uint8_t > partial_
Root class of the ESI type system.
std::string toString(bool oneLine=false) const
services::CallService::Callback * inner
std::optional< TypedReadPort< ArgT, SkipTypeCheck > > argPort
std::optional< TypedWritePort< void > > resultPort
const services::CallService::Callback & raw() const
std::function< void(const ArgT &)> userCallback
void connect(std::function< void(const ArgT &)> callback, bool quick=false)
TypedCallback(const TypedCallback &)=delete
services::CallService::Callback & raw()
TypedCallback & operator=(const TypedCallback &)=delete
TypedCallback(services::CallService::Callback *cb)
std::optional< TypedWritePort< ResultT, SkipTypeCheck > > resultPort
services::CallService::Callback & raw()
std::optional< TypedReadPort< void > > argPort
TypedCallback(const TypedCallback &)=delete
void connect(std::function< ResultT()> callback, bool quick=false)
TypedCallback(services::CallService::Callback *cb)
std::function< ResultT()> userCallback
const services::CallService::Callback & raw() const
services::CallService::Callback * inner
TypedCallback & operator=(const TypedCallback &)=delete
std::optional< TypedWritePort< void > > resultPort
std::optional< TypedReadPort< void > > argPort
TypedCallback(services::CallService::Callback *cb)
services::CallService::Callback & raw()
std::function< void()> userCallback
void connect(std::function< void()> callback, bool quick=false)
TypedCallback & operator=(const TypedCallback &)=delete
TypedCallback(const TypedCallback &)=delete
const services::CallService::Callback & raw() const
services::CallService::Callback * inner
services::CallService::Callback * inner
std::optional< TypedReadPort< ArgT, SkipTypeCheck > > argPort
services::CallService::Callback & raw()
void connect(std::function< ResultT(const ArgT &)> callback, bool quick=false)
TypedCallback(services::CallService::Callback *cb)
std::optional< TypedWritePort< ResultT, SkipTypeCheck > > resultPort
TypedCallback & operator=(const TypedCallback &)=delete
std::function< ResultT(const ArgT &)> userCallback
const services::CallService::Callback & raw() const
TypedCallback(const TypedCallback &)=delete
auto operator()(Args &&...args) -> decltype(this->call(std::forward< Args >(args)...))
Function-call operator overloads: forward to call().
TypedFunction & operator=(const TypedFunction &)=delete
std::optional< TypedWritePort< ArgT, SkipTypeCheck > > argPort
std::future< void > call(First &&first, Rest &&...rest)
Emplace-style call: constructs ArgT in-place from the forwarded arguments and forwards to call(const ...
TypedFunction(const TypedFunction &)=delete
std::optional< TypedReadPort< void > > resultPort
const services::FuncService::Function & raw() const
services::FuncService::Function & raw()
std::future< void > call(const ArgT &arg)
services::FuncService::Function * inner
TypedFunction(services::FuncService::Function *func)
std::optional< TypedReadPort< ResultT, SkipTypeCheck > > resultPort
std::future< ResultT > call()
TypedFunction & operator=(const TypedFunction &)=delete
std::optional< TypedWritePort< void > > argPort
services::FuncService::Function & raw()
TypedFunction(const TypedFunction &)=delete
services::FuncService::Function * inner
std::future< ResultT > operator()()
Function-call operator overload: forwards to call().
const services::FuncService::Function & raw() const
TypedFunction(services::FuncService::Function *func)
const services::FuncService::Function & raw() const
TypedFunction(const TypedFunction &)=delete
TypedFunction & operator=(const TypedFunction &)=delete
services::FuncService::Function * inner
std::future< void > call()
TypedFunction(services::FuncService::Function *func)
std::optional< TypedWritePort< void > > argPort
std::optional< TypedReadPort< void > > resultPort
services::FuncService::Function & raw()
std::future< void > operator()()
Function-call operator overload: forwards to call().
std::optional< TypedWritePort< ArgT, SkipTypeCheck > > argPort
std::optional< TypedReadPort< ResultT, SkipTypeCheck > > resultPort
std::future< ResultT > call(First &&first, Rest &&...rest)
Emplace-style call: constructs ArgT in-place from the forwarded arguments and forwards to call(const ...
TypedFunction(const TypedFunction &)=delete
services::FuncService::Function & raw()
auto operator()(Args &&...args) -> decltype(this->call(std::forward< Args >(args)...))
Function-call operator overloads: forward to call().
std::future< ResultT > call(const ArgT &arg)
TypedFunction & operator=(const TypedFunction &)=delete
const services::FuncService::Function & raw() const
TypedFunction(services::FuncService::Function *func)
Implicit conversion from Function* (returned by getAs<>()).
services::FuncService::Function * inner
TypedReadPort(const TypedReadPort &)=delete
TypedReadPort & operator=(TypedReadPort &&)=delete
TypedReadPort & operator=(const TypedReadPort &)=delete
TypedReadPort(ReadChannelPort &port)
TypedReadPort(ReadChannelPort *port)
TypedReadPort(TypedReadPort &&)=delete
std::future< void > readAsync()
void connect(const ChannelPort::ConnectOptions &opts={std::nullopt, false})
void connect(std::function< bool()> callback, const ChannelPort::ConnectOptions &opts={std::nullopt, false})
const ReadChannelPort & raw() const
TypedReadPort(ReadChannelPort &port)
detail::DeserializerFor< T > Deserializer
TypedReadPort & operator=(const TypedReadPort &)=delete
std::unique_ptr< T > read()
Blocking typed read in polling mode.
void connect(const ChannelPort::ConnectOptions &opts={std::nullopt, false})
Connect in polling mode.
uint64_t maxDataQueueMsgs
void disconnect()
Disconnect the typed port and abandon any pending polling reads.
void setMaxDataQueueMsgs(uint64_t maxMsgs)
Set the maximum number of decoded typed values buffered in polling mode.
void emplaceDeserializer(detail::DeserializerOutputCallback< T > callback)
void connect(std::function< bool(const T &)> callback, const ChannelPort::ConnectOptions &opts={std::nullopt, false})
Connect a non-owning typed callback.
const ReadChannelPort & raw() const
TypedReadPort & operator=(TypedReadPort &&)=delete
std::optional< PollingState > pollingState
TypedReadPort(const TypedReadPort &)=delete
std::optional< Deserializer > deserializer
void connect(detail::TypedReadOwnedCallback< T > callback, const ChannelPort::ConnectOptions &opts={std::nullopt, false})
Connect an owning typed callback.
detail::PollingBuffer< std::unique_ptr< T > > PollingState
std::future< std::unique_ptr< T > > readAsync()
Asynchronous typed read in polling mode.
TypedReadPort(ReadChannelPort *port)
TypedReadPort(TypedReadPort &&)=delete
TypedWritePort(WriteChannelPort &port)
std::function< bool()> DataFetchCallback
Callback mode data source: returns true if a message should be written, or false if none is available...
TypedWritePort(WriteChannelPort *port)
void notifyAsyncDataAvailable()
See WriteChannelPort::notifyAsyncDataAvailable().
void connect(const ChannelPort::ConnectOptions &opts={std::nullopt, false})
const WriteChannelPort & raw() const
void connect(DataFetchCallback fetch, WriteChannelPort::WriteErrorCallback onError, const ChannelPort::ConnectOptions &opts={std::nullopt, false})
Connect in callback mode.
const WriteChannelPort & raw() const
std::function< std::unique_ptr< T >()> DataFetchCallback
Callback mode data source: returns the next value to write, or nullptr if none is available yet.
void connect(const ChannelPort::ConnectOptions &opts={std::nullopt, false})
void write(std::unique_ptr< T > &data)
Write by taking ownership.
bool tryWrite(const T &data)
bool tryWrite(std::unique_ptr< T > &data)
Non-blocking write by taking ownership.
void notifyAsyncDataAvailable()
See WriteChannelPort::notifyAsyncDataAvailable().
TypedWritePort(WriteChannelPort &port)
void write(const T &data)
TypedWritePort(WriteChannelPort *port)
void connect(DataFetchCallback fetch, WriteChannelPort::WriteErrorCallback onError, const ChannelPort::ConnectOptions &opts={std::nullopt, false})
Connect in callback mode.
The "void" type is a special type which can be used to represent no type.
Windows represent a fixed-size sliding window over a stream of data.
A ChannelPort which sends data to the accelerator.
virtual void connect(const ConnectOptions &options={}) override
Connect in sync mode. Throws if connected in callback mode.
std::function< void(std::exception_ptr)> WriteErrorCallback
Callback mode error handler.
std::function< std::unique_ptr< SegmentedMessageData >()> DataFetchCallback
Callback mode data source.
Default deserializer for simple 1:1 typed reads.
bool push(std::unique_ptr< SegmentedMessageData > &msg)
TypedReadOwnedCallback< T > OutputCallback
std::unique_ptr< T > pendingOutput
PODTypeDeserializer(OutputCallback output, WireInfo wireInfo)
Shared queue/promise helper for polling-style read APIs.
A function call which gets attached to a service port.
A function call which gets attached to a service port.
constexpr bool has_type_deserializer_v
std::function< bool(std::unique_ptr< T > &)> TypedReadOwnedCallback
Owning callback used by typed read deserializers.
ChannelPort::ConnectOptions typedFunctionConnectOptions()
Standard ConnectOptions for typed function ports: untranslated frames so the deserializer can see raw...
void throwAlreadyConnected()
Throw a clear "already connected" error from connect() paths.
typename DeserializerSelector< T >::type DeserializerFor
void throwNullFunction()
Throw the standard "null Function pointer" error used by every TypedFunction specialization.
void throwNotConnected()
Throw a clear "not connected" error from call() paths.
void throwCallbackAlreadyConnected()
Throw a clear "already connected" error from TypedCallback connect() paths.
void throwNullCallback()
Throw the standard "null Callback pointer" error used by every TypedCallback specialization.
typename DeserializerFor< T >::OutputCallback DeserializerOutputCallback
std::future< T > awaitDecoded(std::future< std::unique_ptr< T > > inner)
Convert a std::future<std::unique_ptr<T>> (as returned by TypedReadPort::readAsync()) into a std::fut...
std::string toString(const std::any &a)
'Stringify' a std::any. This is used to log std::any values by some loggers.
void verifyTypeCompatibility(const Type *portType)
MessageData toMessageData(const T &data, WireInfo wi)
Pack a C++ integral value into a MessageData with the given wire byte count.
std::vector< uint32_t > findPortIndices(HWModule *module, const std::string &name)
Return a sorted vector of the idx values for every port whose AppID name matches name.
WireInfo getWireInfo(const Type *portType)
BundlePort & findPortOrThrow(HWModule *module, const AppID &id)
Look up a BundlePort by AppID in module.
constexpr bool has_esi_id_v
T * findPortAsOrThrow(HWModule *module, const AppID &id)
Look up a BundlePort by AppID and cast it to T.
constexpr bool has_esi_window_id_v
constexpr bool is_std_array_v
T fromMessageData(const MessageData &msg, WireInfo wi)
Unpack a MessageData into a C++ integral value with the given wire info.
const Type * unwrapTypeAlias(const Type *type)
Unwrap TypeAliasType (possibly recursively) to get the underlying type.
Compute the wire byte count for a port type.
typename T::TypeDeserializer type
PODTypeDeserializer< T > type