| e8555c89 Andy McCall |
1 |
#ifndef RS232NET_HH |
| 2 |
#define RS232NET_HH |
| 3 |
|
| 4 |
#include "RS232Device.hh" |
| 5 |
|
| 6 |
#include "BooleanSetting.hh" |
| 7 |
#include "EventListener.hh" |
| 8 |
#include "Socket.hh" |
| 9 |
#include "StringSetting.hh" |
| 10 |
|
| 11 |
#include "Poller.hh" |
| 12 |
#include "circular_buffer.hh" |
| 13 |
|
| 14 |
#include <atomic> |
| 15 |
#include <cstdint> |
| 16 |
#include <mutex> |
| 17 |
#include <optional> |
| 18 |
#include <span> |
| 19 |
#include <thread> |
| 20 |
|
| 21 |
namespace openmsx { |
| 22 |
|
| 23 |
class EventDistributor; |
| 24 |
class Scheduler; |
| 25 |
class CommandController; |
| 26 |
|
| 27 |
class RS232Net final : public RS232Device, private EventListener |
| 28 |
{ |
| 29 |
public: |
| 30 |
|
| 31 |
struct NetworkSocketAddress { |
| 32 |
int domain; |
| 33 |
socklen_t len; |
| 34 |
union { |
| 35 |
struct sockaddr generic; |
| 36 |
struct sockaddr_in ipv4; |
| 37 |
struct sockaddr_in6 ipv6; |
| 38 |
} address; |
| 39 |
}; |
| 40 |
|
| 41 |
public: |
| 42 |
RS232Net(EventDistributor& eventDistributor, Scheduler& scheduler, |
| 43 |
CommandController& commandController); |
| 44 |
~RS232Net() override; |
| 45 |
|
| 46 |
|
| 47 |
void plugHelper(Connector& connector, EmuTime time) override; |
| 48 |
void unplugHelper(EmuTime time) override; |
| 49 |
[[nodiscard]] zstring_view getName() const override; |
| 50 |
[[nodiscard]] zstring_view getDescription() const override; |
| 51 |
|
| 52 |
|
| 53 |
void signal(EmuTime time) override; |
| 54 |
|
| 55 |
|
| 56 |
void recvByte(uint8_t value, EmuTime time) override; |
| 57 |
|
| 58 |
[[nodiscard]] std::optional<bool> getDSR(EmuTime time) const override; |
| 59 |
[[nodiscard]] std::optional<bool> getCTS(EmuTime time) const override; |
| 60 |
[[nodiscard]] std::optional<bool> getDCD(EmuTime time) const override; |
| 61 |
[[nodiscard]] std::optional<bool> getRI(EmuTime time) const override; |
| 62 |
void setDTR(bool status, EmuTime time) override; |
| 63 |
void setRTS(bool status, EmuTime time) override; |
| 64 |
|
| 65 |
template<typename Archive> |
| 66 |
void serialize(Archive& ar, unsigned version); |
| 67 |
|
| 68 |
private: |
| 69 |
void run(); |
| 70 |
|
| 71 |
|
| 72 |
bool signalEvent(const Event& event) override; |
| 73 |
|
| 74 |
bool net_put(std::span<const char> buf); |
| 75 |
void open_socket(const NetworkSocketAddress& socket_address); |
| 76 |
|
| 77 |
private: |
| 78 |
[[no_unique_address]] SocketActivator socketActivator; |
| 79 |
EventDistributor& eventDistributor; |
| 80 |
Scheduler& scheduler; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
StringSetting rs232NetAddressSetting; |
| 85 |
BooleanSetting rs232NetUseIP232; |
| 86 |
|
| 87 |
std::thread thread; |
| 88 |
std::mutex mutex; |
| 89 |
std::optional<Poller> poller; |
| 90 |
cb_queue<char> queue; |
| 91 |
std::atomic<SOCKET> sockfd; |
| 92 |
|
| 93 |
|
| 94 |
std::atomic<bool> DCD; |
| 95 |
std::atomic<bool> RI; |
| 96 |
|
| 97 |
|
| 98 |
bool DTR; |
| 99 |
bool RTS; |
| 100 |
|
| 101 |
|
| 102 |
bool IP232; |
| 103 |
}; |
| 104 |
|
| 105 |
} |
| 106 |
|
| 107 |
#endif |