10namespace io = boost::asio;
14 : _owner{owner}, _ctx{}, _sd{_ctx, owner._file},
15 _thread{&
EventThread::start, this,
std::move(subscriptionDonePromise)} {
17 std::cout <<
"XDMA: EventThread " << _owner._file.
name() <<
" ctor\n";
23 std::cout <<
"XDMA: EventThread " << _owner._file.
name() <<
" dtor\n" << std::endl;
32 subscriptionDonePromise.set_value();
51 std::cout <<
"XDMA: waitForEvent " << _owner._file.
name() <<
"\n";
55 _sd.async_wait(io::posix::stream_descriptor::wait_read,
63 std::cout <<
"XDMA: readEvent " << _owner._file.
name() <<
"\n";
66 const std::string msg =
"EventThread::readEvent() I/O error: " + ec.message();
69 _sd.async_read_some(io::buffer(_result),
71 std::placeholders::_1,
78 std::cout <<
"XDMA: handleEvent " << _owner._file.
name() <<
"\n";
81 const std::string msg =
"EventThread::handleEvent() I/O error: " + ec.message();
84 if(bytes_transferred !=
sizeof(_result[0])) {
85 throw runtime_error(
"EventThread::handleEvent() incomplete read");
88 uint32_t numInterrupts = _result[0];
90 std::cout <<
"XDMA: Event " << _owner._file.
name() <<
" received: " << bytes_transferred <<
" bytes, "
91 << numInterrupts <<
" interrupts\n";
95 if(numInterrupts != 0) {
96 _owner._asyncDomain->distribute(
nullptr);
103 std::cout <<
"XDMA: timerEvent for " << _owner._file.
name() <<
"\n";
106 const std::string msg =
"EventThread::timerEvent() I/O error: " + ec.message();
118 : _backend(backend), _file{devicePath +
"/events" +
std::
to_string(interruptIdx), O_RDONLY},
119 _asyncDomain{asyncDomain} {}
122 _evtThread.reset(
nullptr);
127 subscriptionDonePromise.set_value();
130 _evtThread = std::make_unique<EventThread>(*
this, std::move(subscriptionDonePromise));
The base class for backends providing IO functionality for the Device class.
virtual void setException(const std::string &message) noexcept=0
Set the backend into an exception state.
void startThread(std::promise< void > subscriptionDonePromise)
void timerEvent(const boost::system::error_code &ec)
void handleEvent(const boost::system::error_code &ec, std::size_t bytes_transferred)
void start(std::promise< void > subscriptionDonePromise)
boost::asio::steady_timer timer
void readEvent(const boost::system::error_code &ec)
Exception thrown when a runtime error has occured.
const char * what() const noexcept override
Return the message describing what exactly went wrong.
std::string to_string(Boolean &value)