Switch name Producer/Consumer -> Sender/Receiver

The producer/consumer was created for:
https://github.com/ArthurSonzogni/FTXUI/pull/11

This patch makes rename everything from Producer/Consumer toward
Sender/Receiver.
This commit is contained in:
ArthurSonzogni
2020-03-25 00:07:41 +01:00
parent 09a1b16613
commit 0a7b556a12
7 changed files with 128 additions and 126 deletions

View File

@@ -36,7 +36,7 @@ Event Event::Special(const std::string& input) {
return event;
}
void ParseUTF8(Consumer<char>& in, Producer<Event>& out, std::string& input) {
void ParseUTF8(Receiver<char>& in, Sender<Event>& out, std::string& input) {
char c;
char mask = 0b11000000;
for (int i = 0; i < 3; ++i) {
@@ -50,7 +50,7 @@ void ParseUTF8(Consumer<char>& in, Producer<Event>& out, std::string& input) {
out->Send(Event::Character(input));
}
void ParseCSI(Consumer<char>& in, Producer<Event>& out, std::string& input) {
void ParseCSI(Receiver<char>& in, Sender<Event>& out, std::string& input) {
char c;
while (1) {
if (!in->Receive(&c))
@@ -72,7 +72,7 @@ void ParseCSI(Consumer<char>& in, Producer<Event>& out, std::string& input) {
}
}
void ParseDCS(Consumer<char>& in, Producer<Event>& out, std::string& input) {
void ParseDCS(Receiver<char>& in, Sender<Event>& out, std::string& input) {
char c;
// Parse until the string terminator ST.
while (1) {
@@ -90,7 +90,7 @@ void ParseDCS(Consumer<char>& in, Producer<Event>& out, std::string& input) {
}
}
void ParseOSC(Consumer<char>& in, Producer<Event>& out, std::string& input) {
void ParseOSC(Receiver<char>& in, Sender<Event>& out, std::string& input) {
char c;
// Parse until the string terminator ST.
while (1) {
@@ -108,7 +108,7 @@ void ParseOSC(Consumer<char>& in, Producer<Event>& out, std::string& input) {
}
}
void ParseESC(Consumer<char>& in, Producer<Event>& out, std::string& input) {
void ParseESC(Receiver<char>& in, Sender<Event>& out, std::string& input) {
char c;
if (!in->Receive(&c))
return;
@@ -129,7 +129,7 @@ void ParseESC(Consumer<char>& in, Producer<Event>& out, std::string& input) {
}
// static
void Event::Convert(Consumer<char>& in, Producer<Event>& out, char c) {
void Event::Convert(Receiver<char>& in, Sender<Event>& out, char c) {
std::string input;
input += c;

View File

@@ -58,8 +58,8 @@ void OnResize(int /* signal */) {
ScreenInteractive::ScreenInteractive(int dimx, int dimy, Dimension dimension)
: Screen(dimx, dimy), dimension_(dimension) {
event_consumer_ = MakeConsumer<Event>();
event_producer_ = event_consumer_->MakeProducer();
event_receiver_ = MakeReceiver<Event>();
event_sender_ = event_receiver_->MakeSender();
}
ScreenInteractive::~ScreenInteractive() {}
@@ -85,7 +85,7 @@ ScreenInteractive ScreenInteractive::FitComponent() {
}
void ScreenInteractive::PostEvent(Event event) {
event_producer_->Send(event);
event_sender_->Send(event);
}
void ScreenInteractive::Loop(Component* component) {
@@ -140,25 +140,25 @@ void ScreenInteractive::Loop(Component* component) {
std::cout << std::endl;
});
auto char_consumer = MakeConsumer<char>();
auto char_receiver = MakeReceiver<char>();
// Spawn a thread to produce char.
auto char_producer = char_consumer->MakeProducer();
auto char_sender = char_receiver->MakeSender();
std::thread read_char([&] {
// TODO(arthursonzogni): Use a timeout so that it doesn't block even if the
// user doesn't generate new chars.
while (!quit_)
char_producer->Send((char)getchar());
char_producer.reset();
char_sender->Send((char)getchar());
char_sender.reset();
});
// Spawn a thread producing events and consumer chars.
auto event_producer = event_consumer_->MakeProducer();
auto event_sender = event_receiver_->MakeSender();
std::thread convert_char_to_event([&] {
char c;
while (char_consumer->Receive(&c))
Event::Convert(char_consumer, event_producer, c);
event_producer.reset();
while (char_receiver->Receive(&c))
Event::Convert(char_receiver, event_sender, c);
event_sender.reset();
});
// The main loop.
@@ -168,7 +168,7 @@ void ScreenInteractive::Loop(Component* component) {
std::cout << ToString() << set_cursor_position << std::flush;
Clear();
Event event;
if (event_consumer_->Receive(&event))
if (event_receiver_->Receive(&event))
component->OnEvent(event);
}
read_char.join();