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