RADLib
RADical C++ application framework
RADCore::RADPtyProcess Class Reference

PTY-backed process helper for terminal applications. More...

#include <RADCore.h>

+ Inheritance diagram for RADCore::RADPtyProcess:
+ Collaboration diagram for RADCore::RADPtyProcess:

Public Member Functions

 RADPtyProcess ()
 Creates a non-running PTY process. More...
 
 ~RADPtyProcess () override
 Stops and cleans up the PTY process if needed. More...
 
bool start (const std::string &program={}, const std::vector< std::string > &arguments={}, uint16_t rows=30, uint16_t columns=120)
 Starts program in a PTY; empty program selects the user's shell. More...
 
bool waitForFinished (int timeoutMs=-1)
 Waits for process exit; timeoutMs < 0 waits indefinitely. More...
 
void kill ()
 Sends a kill request to the child. More...
 
void close ()
 Closes the PTY handle. More...
 
ssize_t readData (void *buffer, size_t maxBytes)
 Reads bytes from the PTY. More...
 
ssize_t writeData (const void *data, size_t size)
 Writes bytes to the PTY. More...
 
ssize_t write (const std::string &text)
 Writes string bytes to the PTY. More...
 
bool resizeTerminal (uint16_t rows, uint16_t columns)
 Resizes the PTY terminal dimensions. More...
 
ProcessState state () const
 Returns process state. More...
 
int exitCode () const
 Returns exit code after finish. More...
 
- Public Member Functions inherited from RADCore::RADObject
 RADObject ()
 Creates a RADObject bound to the current thread. More...
 
virtual ~RADObject ()
 Disconnects tracked event links and releases lifetime token. More...
 
void registerLink (const ConnectionRecord &record)
 Registers a connection for cleanup when this object is destroyed. More...
 
std::thread::id threadId () const
 Returns the thread id this object is currently associated with. More...
 
EventLoopassociatedEventLoop () const
 Returns the associated event loop, if any. More...
 
ThreadAffinity threadAffinity () const
 Returns both thread id and associated loop atomically. More...
 
std::weak_ptr< void > lifetimeToken () const
 Returns a weak token used to drop queued callbacks after destruction. More...
 
void moveToThread (std::thread::id tId, EventLoop *loop=nullptr)
 Moves the object's affinity to tId and optional loop. More...
 

Public Attributes

RADCore::Event< void() > started
 Raised when the child starts. More...
 
RADCore::Event< void(int) > finished
 Raised with exit code when the child exits. More...
 
RADCore::Event< void(std::string) > errorOccurred
 Raised when PTY/process operations fail. More...
 

Detailed Description

PTY-backed process helper for terminal applications.

Constructor & Destructor Documentation

◆ RADPtyProcess()

RADCore::RADPtyProcess::RADPtyProcess ( )

Creates a non-running PTY process.

◆ ~RADPtyProcess()

RADCore::RADPtyProcess::~RADPtyProcess ( )
override

Stops and cleans up the PTY process if needed.

Member Function Documentation

◆ close()

void RADCore::RADPtyProcess::close ( )

Closes the PTY handle.

◆ exitCode()

int RADCore::RADPtyProcess::exitCode ( ) const

Returns exit code after finish.

◆ kill()

void RADCore::RADPtyProcess::kill ( )

Sends a kill request to the child.

◆ readData()

ssize_t RADCore::RADPtyProcess::readData ( void *  buffer,
size_t  maxBytes 
)

Reads bytes from the PTY.

◆ resizeTerminal()

bool RADCore::RADPtyProcess::resizeTerminal ( uint16_t  rows,
uint16_t  columns 
)

Resizes the PTY terminal dimensions.

◆ start()

bool RADCore::RADPtyProcess::start ( const std::string &  program = {},
const std::vector< std::string > &  arguments = {},
uint16_t  rows = 30,
uint16_t  columns = 120 
)

Starts program in a PTY; empty program selects the user's shell.

◆ state()

ProcessState RADCore::RADPtyProcess::state ( ) const

Returns process state.

◆ waitForFinished()

bool RADCore::RADPtyProcess::waitForFinished ( int  timeoutMs = -1)

Waits for process exit; timeoutMs < 0 waits indefinitely.

◆ write()

ssize_t RADCore::RADPtyProcess::write ( const std::string &  text)

Writes string bytes to the PTY.

◆ writeData()

ssize_t RADCore::RADPtyProcess::writeData ( const void *  data,
size_t  size 
)

Writes bytes to the PTY.

Member Data Documentation

◆ errorOccurred

RADCore::Event<void (std::string) > RADCore::RADPtyProcess::errorOccurred

Raised when PTY/process operations fail.

◆ finished

RADCore::Event<void (int) > RADCore::RADPtyProcess::finished

Raised with exit code when the child exits.

◆ started

RADCore::Event<void () > RADCore::RADPtyProcess::started

Raised when the child starts.


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