Async 1.8.0
Async::PtyStreamBuf Class Reference

A stream buffer class to stream characters to a PTY. More...

#include <AsyncPtyStreamBuf.h>

Inheritance diagram for Async::PtyStreamBuf:

Public Member Functions

 PtyStreamBuf (Pty *pty, std::size_t buf_size=256)
 Default constructor.
 
 ~PtyStreamBuf (void)
 Destructor.
 
Ptypty (void) const
 Return the PTY this stream is attached to.
 

Detailed Description

A stream buffer class to stream characters to a PTY.

Author
Tobias Blomberg / SM0SVX
Date
2014-12-20

This class can be used to write data to a UNIX 98 PTY using the standard streaming interface. The typical usage pattern is to first create an instance of a Pty. Then an instance of this class is created, the stream buffer. Lastly a std::ostream can be created with the stream buffer as an argument to the constructor. The std::ostream can then be used as any other output stream.

#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
Examples
AsyncPtyStreamBuf_demo.cpp.

Definition at line 124 of file AsyncPtyStreamBuf.h.

Constructor & Destructor Documentation

◆ PtyStreamBuf()

Async::PtyStreamBuf::PtyStreamBuf ( Pty * pty,
std::size_t buf_size = 256 )
explicit

Default constructor.

Parameters
ptyA previously created PTY object
buf_sizeThe buffer size

◆ ~PtyStreamBuf()

Async::PtyStreamBuf::~PtyStreamBuf ( void )

Destructor.

Member Function Documentation

◆ pty()

Pty * Async::PtyStreamBuf::pty ( void ) const
inline

Return the PTY this stream is attached to.

Returns
The PTY

Definition at line 143 of file AsyncPtyStreamBuf.h.


The documentation for this class was generated from the following file: