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 "Thread.hh"
6 #include "EventListener.hh"
7 #include "FileOperations.hh"
8 #include "Semaphore.hh"
9 #include "openmsx.hh"
10 #include "circular_buffer.hh"
11 #include <fstream>
12 #include <cstdio>
13 #include <memory>
14 
15 namespace openmsx {
16 
17 class EventDistributor;
18 class Scheduler;
19 class CommandController;
20 class FilenameSetting;
21 
22 class RS232Tester final : public RS232Device, private Runnable
23  , private EventListener
24 {
25 public:
26  RS232Tester(EventDistributor& eventDistributor, Scheduler& scheduler,
28  ~RS232Tester();
29 
30  // Pluggable
31  void plugHelper(Connector& connector, EmuTime::param time) override;
32  void unplugHelper(EmuTime::param time) override;
33  const std::string& getName() const override;
34  string_ref getDescription() const override;
35 
36  // input
37  void signal(EmuTime::param time) override;
38 
39  // output
40  void recvByte(byte value, EmuTime::param time) override;
41 
42  template<typename Archive>
43  void serialize(Archive& ar, unsigned version);
44 
45 private:
46  // Runnable
47  void run() override;
48 
49  // EventListener
50  int signalEvent(const std::shared_ptr<const Event>& event) override;
51 
52  EventDistributor& eventDistributor;
53  Scheduler& scheduler;
54  Thread thread;
56  cb_queue<byte> queue;
57  Semaphore lock; // to protect queue
58 
59  std::ofstream outFile;
60 
61  const std::unique_ptr<FilenameSetting> rs232InputFilenameSetting;
62  const std::unique_ptr<FilenameSetting> rs232OutputFilenameSetting;
63 };
64 
65 } // namespace openmsx
66 
67 #endif
string_ref getDescription() const override
Description for this pluggable.
Definition: RS232Tester.cc:81
Represents something you can plug devices into.
Definition: Connector.hh:21
RS232Tester(EventDistributor &eventDistributor, Scheduler &scheduler, CommandController &commandController)
Definition: RS232Tester.cc:13
unsigned char byte
8 bit unsigned integer
Definition: openmsx.hh:33
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:75
void plugHelper(Connector &connector, EmuTime::param time) override
Definition: RS232Tester.cc:36
void serialize(Archive &ar, unsigned version)
Definition: RS232Tester.cc:147
commandController(commandController_)
void recvByte(byte value, EmuTime::param time) override
Definition: RS232Tester.cc:137
void unplugHelper(EmuTime::param time) override
Definition: RS232Tester.cc:64
void signal(EmuTime::param time) override
Definition: RS232Tester.cc:108
std::unique_ptr< FILE, FClose > FILE_t