openMSX
RS232Tester.hh
Go to the documentation of this file.
1 #ifndef RS232TESTER_HH
2 #define RS232TESTER_HH
3 
4 #include "RS232Device.hh"
5 #include "EventListener.hh"
6 #include "FilenameSetting.hh"
7 #include "FileOperations.hh"
8 #include "openmsx.hh"
9 #include "circular_buffer.hh"
10 #include "Poller.hh"
11 #include <fstream>
12 #include <mutex>
13 #include <thread>
14 #include <cstdio>
15 
16 namespace openmsx {
17 
18 class EventDistributor;
19 class Scheduler;
20 class CommandController;
21 
22 class RS232Tester final : public RS232Device, private EventListener
23 {
24 public:
25  RS232Tester(EventDistributor& eventDistributor, Scheduler& scheduler,
26  CommandController& commandController);
27  ~RS232Tester() override;
28 
29  // Pluggable
30  void plugHelper(Connector& connector, EmuTime::param time) override;
31  void unplugHelper(EmuTime::param time) override;
32  const std::string& getName() const override;
33  std::string_view getDescription() const override;
34 
35  // input
36  void signal(EmuTime::param time) override;
37 
38  // output
39  void recvByte(byte value, EmuTime::param time) override;
40 
41  template<typename Archive>
42  void serialize(Archive& ar, unsigned version);
43 
44 private:
45  void run();
46 
47  // EventListener
48  int signalEvent(const std::shared_ptr<const Event>& event) override;
49 
50  EventDistributor& eventDistributor;
51  Scheduler& scheduler;
52  std::thread thread;
54  cb_queue<byte> queue;
55  std::mutex mutex; // to protect queue
56  Poller poller;
57 
58  std::ofstream outFile;
59 
60  FilenameSetting rs232InputFilenameSetting;
61  FilenameSetting rs232OutputFilenameSetting;
62 };
63 
64 } // namespace openmsx
65 
66 #endif
openmsx::RS232Tester::serialize
void serialize(Archive &ar, unsigned version)
Definition: RS232Tester.cc:151
openmsx.hh
openmsx::Scheduler
Definition: Scheduler.hh:33
openmsx::CommandController
Definition: CommandController.hh:17
openmsx::FileOperations::FILE_t
std::unique_ptr< FILE, FClose > FILE_t
Definition: FileOperations.hh:16
openmsx::RS232Tester::signal
void signal(EmuTime::param time) override
Definition: RS232Tester.cc:112
openmsx::FilenameSetting
Definition: FilenameSetting.hh:8
EventListener.hh
openmsx::RS232Tester::getDescription
std::string_view getDescription() const override
Description for this pluggable.
Definition: RS232Tester.cc:78
openmsx::EventDistributor
Definition: EventDistributor.hh:16
openmsx::RS232Tester::plugHelper
void plugHelper(Connector &connector, EmuTime::param time) override
Definition: RS232Tester.cc:33
cb_queue< byte >
openmsx::Poller
Polls for events on a given file descriptor.
Definition: Poller.hh:13
openmsx::RS232Tester::unplugHelper
void unplugHelper(EmuTime::param time) override
Definition: RS232Tester.cc:61
openmsx::RS232Tester::recvByte
void recvByte(byte value, EmuTime::param time) override
Definition: RS232Tester.cc:141
FilenameSetting.hh
openmsx::RS232Device
Definition: RS232Device.hh:9
openmsx::EventListener
Definition: EventListener.hh:10
Poller.hh
FileOperations.hh
openmsx::RS232Tester
Definition: RS232Tester.hh:22
RS232Device.hh
openmsx::RS232Tester::RS232Tester
RS232Tester(EventDistributor &eventDistributor, Scheduler &scheduler, CommandController &commandController)
Definition: RS232Tester.cc:11
openmsx::Connector
Represents something you can plug devices into.
Definition: Connector.hh:20
openmsx::RS232Tester::getName
const std::string & getName() const override
Name used to identify this pluggable.
Definition: RS232Tester.cc:72
openmsx::Scheduler
Scheduler
Definition: Scheduler.cc:133
circular_buffer.hh
openmsx::RS232Tester::~RS232Tester
~RS232Tester() override
Definition: RS232Tester.cc:27
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5