RADLib
RADical C++ application framework
RADCore::RADIODevice Class Referenceabstract

Abstract byte-oriented IO device similar to QIODevice. More...

#include <RADCore.h>

+ Inheritance diagram for RADCore::RADIODevice:
+ Collaboration diagram for RADCore::RADIODevice:

Public Member Functions

virtual ~RADIODevice ()=default
 Destroys the IO device. More...
 
virtual bool open (OpenMode mode)=0
 Opens the device with mode. More...
 
virtual void close ()=0
 Closes the device. More...
 
virtual bool isOpen () const =0
 Returns true when open. More...
 
virtual ssize_t readData (void *buffer, size_t maxBytes)=0
 Reads raw bytes into buffer. More...
 
virtual ssize_t writeData (const void *data, size_t size)=0
 Writes raw bytes from data. More...
 
std::vector< uint8_t > read (size_t maxBytes)
 Reads up to maxBytes into a byte vector. More...
 
std::vector< uint8_t > readAll (size_t chunkSize=8192)
 Reads all available data in chunks. More...
 
ssize_t write (const std::vector< uint8_t > &data)
 Writes a byte vector. More...
 
ssize_t write (const std::string &text)
 Writes string bytes. 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() > readyRead
 Raised when data is available to read. More...
 
RADCore::Event< void(size_t) > bytesWritten
 Raised after bytes are written. More...
 
RADCore::Event< void(std::string) > errorOccurred
 Raised when an IO error occurs. More...
 

Detailed Description

Abstract byte-oriented IO device similar to QIODevice.

Constructor & Destructor Documentation

◆ ~RADIODevice()

virtual RADCore::RADIODevice::~RADIODevice ( )
virtualdefault

Destroys the IO device.

Member Function Documentation

◆ close()

virtual void RADCore::RADIODevice::close ( )
pure virtual

◆ isOpen()

virtual bool RADCore::RADIODevice::isOpen ( ) const
pure virtual

◆ open()

virtual bool RADCore::RADIODevice::open ( OpenMode  mode)
pure virtual

◆ read()

std::vector<uint8_t> RADCore::RADIODevice::read ( size_t  maxBytes)

Reads up to maxBytes into a byte vector.

◆ readAll()

std::vector<uint8_t> RADCore::RADIODevice::readAll ( size_t  chunkSize = 8192)

Reads all available data in chunks.

◆ readData()

virtual ssize_t RADCore::RADIODevice::readData ( void *  buffer,
size_t  maxBytes 
)
pure virtual

◆ write() [1/2]

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

Writes string bytes.

◆ write() [2/2]

ssize_t RADCore::RADIODevice::write ( const std::vector< uint8_t > &  data)

Writes a byte vector.

◆ writeData()

virtual ssize_t RADCore::RADIODevice::writeData ( const void *  data,
size_t  size 
)
pure virtual

Member Data Documentation

◆ bytesWritten

RADCore::Event<void (size_t) > RADCore::RADIODevice::bytesWritten

Raised after bytes are written.

◆ errorOccurred

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

Raised when an IO error occurs.

◆ readyRead

RADCore::Event<void () > RADCore::RADIODevice::readyRead

Raised when data is available to read.


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