ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
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
16namespace ChimeraTK {
17
18 class EventFile;
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);
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
The base class for backends providing IO functionality for the Device class.
void startThread(std::promise< void > subscriptionDonePromise)
Definition EventFile.cc:125
void timerEvent(const boost::system::error_code &ec)
Definition EventFile.cc:101
void handleEvent(const boost::system::error_code &ec, std::size_t bytes_transferred)
Definition EventFile.cc:76
void start(std::promise< void > subscriptionDonePromise)
Definition EventFile.cc:29
boost::asio::steady_timer timer
Definition EventFile.h:38
void readEvent(const boost::system::error_code &ec)
Definition EventFile.cc:61
const int timerSleepSec
Definition EventFile.h:39