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 "Semaphore.hh"
8 #include "openmsx.hh"
9 #include "serialize_meta.hh"
10 #include <fstream>
11 #include <cstdio>
12 #include <deque>
13 #include <memory>
14 
15 namespace openmsx {
16 
17 class EventDistributor;
18 class Scheduler;
19 class CommandController;
20 class FilenameSetting;
21 
22 class RS232Tester : public RS232Device, private Runnable, private EventListener
23 {
24 public:
25  RS232Tester(EventDistributor& eventDistributor, Scheduler& scheduler,
26  CommandController& commandController);
27  virtual ~RS232Tester();
28 
29  // Pluggable
30  virtual void plugHelper(Connector& connector, EmuTime::param time);
31  virtual void unplugHelper(EmuTime::param time);
32  virtual const std::string& getName() const;
33  virtual string_ref getDescription() const;
34 
35  // input
36  virtual void signal(EmuTime::param time);
37 
38  // output
39  virtual void recvByte(byte value, EmuTime::param time);
40 
41  template<typename Archive>
42  void serialize(Archive& ar, unsigned version);
43 
44 private:
45  // Runnable
46  virtual void run();
47 
48  // EventListener
49  virtual int signalEvent(const std::shared_ptr<const Event>& event);
50 
51  EventDistributor& eventDistributor;
52  Scheduler& scheduler;
53  Thread thread;
54  FILE* inFile;
55  std::deque<byte> queue;
56  Semaphore lock; // to protect queue
57 
58  std::ofstream outFile;
59 
60  const std::unique_ptr<FilenameSetting> rs232InputFilenameSetting;
61  const std::unique_ptr<FilenameSetting> rs232OutputFilenameSetting;
62 };
63 
64 } // namespace openmsx
65 
66 #endif