ChimeraTK-DeviceAccess 03.28.00
Loading...
Searching...
No Matches
Connection.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 <boost/array.hpp>
6#include <boost/asio.hpp>
7#include <boost/asio/buffer.hpp>
8#include <boost/asio/deadline_timer.hpp>
9#include <boost/make_shared.hpp>
10#include <boost/shared_ptr.hpp>
11
12#include <chrono>
13#include <memory>
14#include <thread>
15#include <vector>
16
17namespace ChimeraTK::Rebot {
18
20 class Connection {
21 public:
24 Connection(std::string address, std::string port, uint32_t connectionTimeout_sec);
25
27 void open();
28
30 void close();
31
33 std::vector<uint32_t> read(uint32_t numWordsToRead);
34
36 void write(const std::vector<uint32_t>& data);
37
39 bool isOpen();
40
41 private:
42 std::string address_;
43 const std::string port_;
44 boost::asio::io_context ioContext_;
45 boost::asio::ip::tcp::socket s_;
46 boost::asio::deadline_timer disconnectTimer_;
47 boost::asio::deadline_timer::duration_type connectionTimeout_;
48
49 std::mutex _closeMutex; // prevent concurrent close from the backend and the connection timeout
50
51 void disconnectionTimerStart();
52 void disconnectionTimerCancel(const boost::system::error_code& ec);
53 };
54} // namespace ChimeraTK::Rebot
Handles the communication over TCP protocol with RebotDevice-based devices.
Definition Connection.h:20
void close()
Closes a connection with the device.
Definition Connection.cc:50
bool isOpen()
Get the connection state.
Definition Connection.cc:64
void open()
Opens a connection to the device.
Definition Connection.cc:17