ChimeraTK-DeviceAccess  03.18.00
EventFile.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2 // SPDX-License-Identifier: LGPL-3.0-or-later
3 #pragma once
4 
5 #include "async/DomainImpl.h"
6 #include "DeviceFile.h"
7 
8 #include <boost/asio.hpp>
9 #include <boost/asio/posix/stream_descriptor.hpp>
10 
11 #include <functional>
12 #include <memory>
13 #include <string>
14 #include <thread>
15 
16 namespace ChimeraTK {
17 
18  class EventFile;
19  class EventThread {
20  EventFile& _owner;
21 
22  boost::asio::io_context _ctx;
23  boost::asio::posix::stream_descriptor _sd;
24  std::thread _thread;
25 
26  std::array<uint32_t, 1> _result;
27 
28  public:
29  EventThread() = delete;
30  EventThread(EventFile& owner, std::promise<void> subscriptionDonePromise);
31  ~EventThread();
32 
33  void start(std::promise<void> subscriptionDonePromise);
34  void waitForEvent();
35  void readEvent(const boost::system::error_code& ec);
36  void handleEvent(const boost::system::error_code& ec, std::size_t bytes_transferred);
37  void timerEvent(const boost::system::error_code& ec);
38  boost::asio::steady_timer timer{_ctx};
39  const int timerSleepSec = 1;
40  };
41 
42  // Event files are device files that are used to signal interrupt events to userspace
43  class EventFile {
44  friend class EventThread;
45  DeviceBackend* _backend; // needed for reporting exceptions
46  DeviceFile _file;
47  boost::shared_ptr<async::DomainImpl<std::nullptr_t>> _asyncDomain;
48 
49  std::unique_ptr<EventThread> _evtThread;
50 
51  public:
52  EventFile() = delete;
53  EventFile(DeviceBackend* backend, const std::string& devicePath, size_t interruptIdx,
54  boost::shared_ptr<async::DomainImpl<std::nullptr_t>> asyncDomain);
55  // EventFile(EventFile&& d) = default;
56  ~EventFile();
57 
58  void startThread(std::promise<void> subscriptionDonePromise);
59  };
60 
61 } // namespace ChimeraTK
ChimeraTK::EventFile::startThread
void startThread(std::promise< void > subscriptionDonePromise)
Definition: EventFile.cc:125
DeviceFile.h
ChimeraTK::EventThread::timer
boost::asio::steady_timer timer
Definition: EventFile.h:38
ChimeraTK::DeviceFile
Definition: DeviceFile.h:12
ChimeraTK::EventFile::EventFile
EventFile()=delete
DomainImpl.h
ChimeraTK::DeviceBackend
The base class for backends providing IO functionality for the Device class.
Definition: DeviceBackend.h:28
ChimeraTK::EventThread::readEvent
void readEvent(const boost::system::error_code &ec)
Definition: EventFile.cc:61
ChimeraTK::EventFile::~EventFile
~EventFile()
Definition: EventFile.cc:121
ChimeraTK::EventThread::timerSleepSec
const int timerSleepSec
Definition: EventFile.h:39
ChimeraTK::EventThread
Definition: EventFile.h:19
ChimeraTK::EventThread::start
void start(std::promise< void > subscriptionDonePromise)
Definition: EventFile.cc:29
ChimeraTK::EventThread::timerEvent
void timerEvent(const boost::system::error_code &ec)
Definition: EventFile.cc:101
ChimeraTK::async::DomainImpl
Definition: DomainImpl.h:15
ChimeraTK::EventThread::waitForEvent
void waitForEvent()
Definition: EventFile.cc:49
ChimeraTK::EventFile
Definition: EventFile.h:43
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::EventThread::EventThread
EventThread()=delete
ChimeraTK::EventThread::handleEvent
void handleEvent(const boost::system::error_code &ec, std::size_t bytes_transferred)
Definition: EventFile.cc:76
ChimeraTK::EventThread::~EventThread
~EventThread()
Definition: EventFile.cc:21