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();
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  string_ref 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
string_ref getDescription() const override
Description for this pluggable.
Definition: RS232Tester.cc:78
Represents something you can plug devices into.
Definition: Connector.hh:20
RS232Tester(EventDistributor &eventDistributor, Scheduler &scheduler, CommandController &commandController)
Definition: RS232Tester.cc:11
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
This class implements a subset of the proposal for std::string_ref (proposed for the next c++ standar...
Definition: string_ref.hh:18
const std::string & getName() const override
Name used to identify this pluggable.
Definition: RS232Tester.cc:72
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void plugHelper(Connector &connector, EmuTime::param time) override
Definition: RS232Tester.cc:33
void serialize(Archive &ar, unsigned version)
Definition: RS232Tester.cc:151
Polls for events on a given file descriptor.
Definition: Poller.hh:13
void recvByte(byte value, EmuTime::param time) override
Definition: RS232Tester.cc:141
void unplugHelper(EmuTime::param time) override
Definition: RS232Tester.cc:61
void signal(EmuTime::param time) override
Definition: RS232Tester.cc:112
std::unique_ptr< FILE, FClose > FILE_t