21 #ifndef TERMINAL_SIM_HPP_INCLUDED 22 #define TERMINAL_SIM_HPP_INCLUDED 32 namespace mptl {
namespace sim {
47 static std::atomic<bool> terminal_rx_thread_terminate;
48 static std::atomic<bool> terminal_tx_thread_terminate;
55 static void terminal_rx_thread() {
58 cinfd[0].fd = fileno(stdin);
59 cinfd[0].events = POLLIN;
62 while(!terminal_rx_thread_terminate)
71 Tp::stream_device_type::rx_fifo.push(c);
83 static void terminal_tx_thread() {
85 while(!terminal_tx_thread_terminate)
88 while(Tp::stream_device_type::tx_fifo.pop(c)) {
102 typename rx_trigger_regmask_type,
103 typename tx_trigger_regmask_type
108 if(reaction.
bits_set< rx_trigger_regmask_type >()) {
109 reaction.
info(
"terminal: starting RX thread");
110 terminal_rx_thread_terminate =
false;
111 std::thread(terminal_rx_thread).detach();
113 else if(reaction.
bits_cleared< rx_trigger_regmask_type >()) {
114 reaction.
info(
"terminal: stopping RX thread");
115 terminal_rx_thread_terminate =
true;
119 if(reaction.
bits_set< tx_trigger_regmask_type >()) {
120 reaction.
info(
"terminal: starting TX thread");
121 terminal_tx_thread_terminate =
false;
122 std::thread(terminal_tx_thread).detach();
124 else if(reaction.
bits_cleared< tx_trigger_regmask_type >()) {
125 reaction.
info(
"terminal: stopping TX thread");
126 terminal_tx_thread_terminate =
true;
136 #endif // TERMINAL_SIM_HPP_INCLUDED void info(const std::string &str) const
bool bits_set(void) const
void react(void)
Definition: terminal_sim.hpp:105
ostream< Tp > & flush(ostream< Tp > &st)
manipulator, flushes the output stream
Definition: poorman_ostream.hpp:69
Simulate a terminal (Tp) on stdin/stdout, by starting rx/tx threads directly manipulating the fifo of...
Definition: terminal_sim.hpp:43
stdio_terminal(reg_reaction const &r)
Definition: terminal_sim.hpp:99
bool bits_cleared(void) const