Async 1.8.0
AsyncPtyStreamBuf_demo.cpp

An example of how to use the AsyncPtyStreamBuf class

#include <sigc++/bind.h>
#include <string>
#include <cstdlib>
#include <ostream>
#include <iostream>
#include <AsyncPty.h>
#include <AsyncTimer.h>
using namespace std;
void write_to_stream(ostream *os)
{
*os << "Hello, PTY\n";
}
void data_received(const void *buf, size_t len)
{
cout << "Received: ";
cout.write(static_cast<const char *>(buf), len);
}
int main(void)
{
string pty_slave_path("/tmp/testpty");
Async::Pty pty(pty_slave_path);
if (!pty.open())
{
cout << "Failed to open PTY " << pty_slave_path << endl;
exit(1);
}
pty.dataReceived.connect(sigc::ptr_fun(&data_received));
ostream os(&psb);
// Flush the stream buffer after every write
os.setf(ios::unitbuf);
cout << "\nThis demo app will write a line of text every second to a PTY.\n";
cout << "To see the printouts, in another console do:\n";
cout << "\n\tcat /tmp/testpty\n\n";
cout << "Or to also echo back the received text to the PTY:\n";
cout << "\n\ttee /tmp/testpty </tmp/testpty\n\n";
// Start a timer that periodically calls function write_to_stream
sigc::slot<void, ostream*> timer_handler = sigc::ptr_fun(&write_to_stream);
t.expired.connect(sigc::hide(sigc::bind(timer_handler, &os)));
app.exec();
}
The core class for writing asyncronous cpp applications.
A stream buffer for writing to a PTY.
A class that wrap up some functionality to use a PTY.
Contains a single shot or periodic timer that emits a signal on timeout.
An application class for writing non GUI applications.
void exec(void)
Execute the application main loop.
A stream buffer class to stream characters to a PTY.
A wrapper class for using a PTY.
Definition AsyncPty.h:125
A class that produces timer events.
Definition AsyncTimer.h:117
@ TYPE_PERIODIC
A timer that restarts itself every time it expires.
Definition AsyncTimer.h:125