Go to the documentation of this file.
14 : eventDistributor(eventDistributor_), scheduler(scheduler_)
15 , rs232InputFilenameSetting(
16 commandController,
"rs232-inputfilename",
17 "filename of the file where the RS232 input is read from",
19 , rs232OutputFilenameSetting(
20 commandController,
"rs232-outputfilename",
21 "filename of the file where the RS232 output is written to",
36 auto outName = rs232OutputFilenameSetting.
getString();
44 auto inName = rs232InputFilenameSetting.
getString();
58 thread = std::thread([
this]() { run(); });
74 static const std::string name(
"rs232-tester");
80 return "RS232 tester pluggable. Reads all data from file specified "
81 "with the 'rs-232-inputfilename' setting. Writes all data "
82 "to the file specified with the 'rs232-outputfilename' "
86 void RS232Tester::run()
89 while (!feof(inFile.get())) {
91 if (poller.
poll(fileno(inFile.get()))) {
96 size_t num = fread(&buf, 1, 1, inFile.get());
104 std::lock_guard<std::mutex> lock(mutex);
115 if (!conn->acceptsData()) {
116 std::lock_guard<std::mutex> lock(mutex);
120 if (!conn->ready())
return;
122 std::lock_guard<std::mutex> lock(mutex);
123 if (queue.
empty())
return;
128 int RS232Tester::signalEvent(
const std::shared_ptr<const Event>& )
133 std::lock_guard<std::mutex> lock(mutex);
143 if (outFile.is_open()) {
150 template<
typename Archive>
void serialize(Archive &ar, unsigned version)
zstring_view getString() const noexcept
FILE_t openFile(zstring_view filename, zstring_view mode)
Call fopen() in a platform-independent manner.
bool aborted()
Returns true iff abort() was called.
void signal(EmuTime::param time) override
bool poll(int fd)
Waits for an event to occur on the given file descriptor.
Thrown when a plug action fails.
std::string_view getDescription() const override
Description for this pluggable.
void plugHelper(Connector &connector, EmuTime::param time) override
Connector * getConnector() const
Get the connector this Pluggable is plugged into.
void unplugHelper(EmuTime::param time) override
void setDataBits(DataBits bits) override=0
void recvByte(byte value, EmuTime::param time) override
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
void setConnector(Connector *conn)
RS232Tester(EventDistributor &eventDistributor, Scheduler &scheduler, CommandController &commandController)
Represents something you can plug devices into.
const std::string & getName() const override
Name used to identify this pluggable.
@ OPENMSX_RS232_TESTER_EVENT
void registerEventListener(EventType type, EventListener &listener, Priority priority=OTHER)
Registers a given object to receive certain events.
bool isPluggedIn() const
Returns true if this pluggable is currently plugged into a connector.
void unregisterEventListener(EventType type, EventListener &listener)
Unregisters a previously registered event listener.
void abort()
Aborts a poll in progress and any future poll attempts.
EmuTime::param getCurrentTime() const
Get the current scheduler time.
This file implemented 3 utility functions:
REGISTER_POLYMORPHIC_INITIALIZER(Pluggable, CassettePlayer, "CassettePlayer")
void openofstream(std::ofstream &stream, zstring_view filename)
Open an ofstream in a platform-independent manner.
void distributeEvent(const EventPtr &event)
Schedule the given event for delivery.