libzypp 17.37.17
zyppng::IODevice Class Referenceabstract

#include <zypp-core/zyppng/io/iodevice.h>

Inheritance diagram for zyppng::IODevice:

Public Types

enum  OpenModeFlag { Closed = 0x0 , ReadOnly = 0x1 , WriteOnly = 0x2 , ReadWrite = ReadOnly | WriteOnly }
using Ptr = std::shared_ptr<IODevice>
using WeakPtr = std::weak_ptr<IODevice>
Public Types inherited from zyppng::Base
using Ptr = std::shared_ptr<Base>
using WeakPtr = std::weak_ptr<Base>

Public Member Functions

 ZYPP_DECLARE_FLAGS (OpenMode, OpenModeFlag)
 IODevice ()
virtual void close ()
void setReadChannel (uint channel)
uint currentReadChannel () const
int readChannelCount () const
bool canRead () const
bool canWrite () const
bool isOpen () const
ByteArray readAll ()
ByteArray read (int64_t maxSize)
int64_t read (char *buf, int64_t maxSize)
virtual ByteArray readLine (const int64_t maxSize=0)
virtual int64_t bytesAvailable () const
int64_t readBufferCount () const
bool canReadLine () const
ByteArray readAll (uint channel)
ByteArray read (uint channel, int64_t maxSize)
int64_t read (uint channel, char *buf, int64_t maxSize)
ByteArray channelReadUntil (uint channel, const char delim, int64_t maxSize=0)
ByteArray channelReadLine (uint channel, int64_t maxSize=0)
int64_t channelReadLine (uint channel, char *buf, const int64_t maxSize)
virtual int64_t bytesAvailable (uint channel) const
int64_t readBufferCount (uint channel) const
virtual int64_t channelReadUntil (uint channel, char *buf, const char delimiter, const int64_t maxSize)
bool canReadLine (uint channel) const
bool canReadUntil (uint channel, const char delim) const
int64_t write (const ByteArray &data)
int64_t write (const char *data, int64_t len)
virtual int64_t bytesPending () const =0
bool waitForReadyRead (int timeout)
virtual bool waitForReadyRead (uint channel, int timeout)=0
SignalProxy< void()> sigReadyRead ()
SignalProxy< void(uint)> sigChannelReadyRead ()
SignalProxy< void(int64_t)> sigBytesWritten ()
SignalProxy< void()> sigAllBytesWritten ()
SignalProxy< void(uint) > sigReadChannelFinished ()
Public Member Functions inherited from zyppng::Base
 Base ()
virtual ~Base ()
WeakPtr parent () const
void addChild (const Base::Ptr &child)
void removeChild (const Ptr &child)
const std::unordered_set< Ptr > & children () const
std::thread::id threadId () const
template<typename T>
std::vector< std::weak_ptr< T > > findChildren () const
template<typename T>
std::shared_ptr< T > shared_this () const
template<typename T>
std::shared_ptr< T > shared_this ()
template<typename T>
std::weak_ptr< T > weak_this () const
template<typename T>
std::weak_ptr< T > weak_this ()
template<typename SenderFunc, typename ReceiverFunc>
auto connect (SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
template<typename SenderFunc, typename ReceiverFunc, typename ... Tracker>
std::enable_if_t< std::is_member_function_pointer_v< SenderFunc >, connectionconnectFunc (SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers)

Protected Member Functions

 IODevice (IODevicePrivate &d)
virtual bool open (const OpenMode mode)
virtual int64_t rawBytesAvailable (uint channel) const =0
virtual int64_t writeData (const char *data, int64_t count)=0
virtual int64_t readData (uint channel, char *buffer, int64_t bufsize)=0
virtual void readChannelChanged (uint channel)=0
void setReadChannelCount (uint channels)
void finishReadChannel (uint channel)
Protected Member Functions inherited from zyppng::Base
 Base (BasePrivate &dd)

Additional Inherited Members

Static Public Member Functions inherited from zyppng::Base
template<typename Obj, typename Functor>
static decltype(auto) make_base_slot (Obj *o, Functor &&f)
template<typename SenderFunc, typename ReceiverFunc>
static auto connect (typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
template<typename SenderFunc, typename ReceiverFunc, typename ... Tracker>
static auto connectFunc (typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers)
Protected Attributes inherited from zyppng::Base
std::unique_ptr< BasePrivated_ptr

Detailed Description

The IODevice class represents a async sequential IO device, like a Socket or Pipe, to receive and or send data.

Definition at line 32 of file iodevice.h.

Member Typedef Documentation

◆ Ptr

using zyppng::IODevice::Ptr = std::shared_ptr<IODevice>

Definition at line 45 of file iodevice.h.

◆ WeakPtr

using zyppng::IODevice::WeakPtr = std::weak_ptr<IODevice>

Definition at line 46 of file iodevice.h.

Member Enumeration Documentation

◆ OpenModeFlag

Enumerator
Closed 
ReadOnly 
WriteOnly 
ReadWrite 

Definition at line 37 of file iodevice.h.

Constructor & Destructor Documentation

◆ IODevice() [1/2]

zyppng::IODevice::IODevice ( )

Definition at line 10 of file iodevice.cc.

◆ IODevice() [2/2]

zyppng::IODevice::IODevice ( IODevicePrivate & d)
protected

Definition at line 13 of file iodevice.cc.

Member Function Documentation

◆ ZYPP_DECLARE_FLAGS()

zyppng::IODevice::ZYPP_DECLARE_FLAGS ( OpenMode ,
OpenModeFlag  )

◆ close()

void zyppng::IODevice::close ( )
virtual

Reimplemented in zyppng::AsyncDataSource, zyppng::Process, and zyppng::Socket.

Definition at line 30 of file iodevice.cc.

◆ setReadChannel()

void zyppng::IODevice::setReadChannel ( uint channel)

Definition at line 56 of file iodevice.cc.

◆ currentReadChannel()

uint zyppng::IODevice::currentReadChannel ( ) const

Definition at line 69 of file iodevice.cc.

◆ readChannelCount()

int zyppng::IODevice::readChannelCount ( ) const

Definition at line 77 of file iodevice.cc.

◆ canRead()

bool zyppng::IODevice::canRead ( ) const

Definition at line 85 of file iodevice.cc.

◆ canWrite()

bool zyppng::IODevice::canWrite ( ) const

Definition at line 90 of file iodevice.cc.

◆ isOpen()

bool zyppng::IODevice::isOpen ( ) const

Definition at line 95 of file iodevice.cc.

◆ readAll() [1/2]

ByteArray zyppng::IODevice::readAll ( )

Definition at line 121 of file iodevice.cc.

◆ read() [1/4]

ByteArray zyppng::IODevice::read ( int64_t maxSize)

Definition at line 127 of file iodevice.cc.

◆ read() [2/4]

int64_t zyppng::IODevice::read ( char * buf,
int64_t maxSize )

Definition at line 134 of file iodevice.cc.

◆ readLine()

ByteArray zyppng::IODevice::readLine ( const int64_t maxSize = 0)
virtual

Definition at line 142 of file iodevice.cc.

◆ bytesAvailable() [1/2]

int64_t zyppng::IODevice::bytesAvailable ( ) const
virtual

Definition at line 109 of file iodevice.cc.

◆ readBufferCount() [1/2]

int64_t zyppng::IODevice::readBufferCount ( ) const

Definition at line 115 of file iodevice.cc.

◆ canReadLine() [1/2]

bool zyppng::IODevice::canReadLine ( ) const

Definition at line 100 of file iodevice.cc.

◆ readAll() [2/2]

ByteArray zyppng::IODevice::readAll ( uint channel)

Definition at line 150 of file iodevice.cc.

◆ read() [3/4]

ByteArray zyppng::IODevice::read ( uint channel,
int64_t maxSize )

Definition at line 155 of file iodevice.cc.

◆ read() [4/4]

int64_t zyppng::IODevice::read ( uint channel,
char * buf,
int64_t maxSize )

Definition at line 166 of file iodevice.cc.

◆ channelReadUntil() [1/2]

ByteArray zyppng::IODevice::channelReadUntil ( uint channel,
const char delim,
int64_t maxSize = 0 )

Convenience function that reads a line from the device into a ByteArray. Since this function has no way to signal if a error happened, a empty ByteArray is returned if there was no data or if a error occured.

Definition at line 188 of file iodevice.cc.

◆ channelReadLine() [1/2]

ByteArray zyppng::IODevice::channelReadLine ( uint channel,
int64_t maxSize = 0 )

Convenience function that reads a line from the device into a ByteArray. Since this function has no way to signal if a error happened, a empty ByteArray is returned if there was no data or if a error occured.

Definition at line 250 of file iodevice.cc.

◆ channelReadLine() [2/2]

int64_t zyppng::IODevice::channelReadLine ( uint channel,
char * buf,
const int64_t maxSize )

Reads data from the device until one of the following conditions are met:

  • A
    is encountered
  • maxSize nr of bytes have been read
  • a error occurs on the device

If bytes have been read from the device this always returns the number of bytes that have been read, otherwise if no data was read 0 is returned or if a error occurs -1 is returned.

Definition at line 255 of file iodevice.cc.

◆ bytesAvailable() [2/2]

int64_t zyppng::IODevice::bytesAvailable ( uint channel) const
virtual

Definition at line 313 of file iodevice.cc.

◆ readBufferCount() [2/2]

int64_t zyppng::IODevice::readBufferCount ( uint channel) const

Returns the number of bytes currently buffered in the read buffer channel

Definition at line 321 of file iodevice.cc.

◆ channelReadUntil() [2/2]

int64_t zyppng::IODevice::channelReadUntil ( uint channel,
char * buf,
const char delimiter,
const int64_t maxSize )
virtual

Reads data from the device until one of the following conditions are met:

  • The delimiter is encountered
  • maxSize nr of bytes have been read
  • a error occurs on the device

If bytes have been read from the device this always returns the number of bytes that have been read, otherwise if no data was read 0 is returned or if a error occurs -1 is returned.

Definition at line 260 of file iodevice.cc.

◆ canReadLine() [2/2]

bool zyppng::IODevice::canReadLine ( uint channel) const

Returns true if a line can be read from the currently buffered data in the given channel

Definition at line 337 of file iodevice.cc.

◆ canReadUntil()

bool zyppng::IODevice::canReadUntil ( uint channel,
const char delim ) const

Returns true if delim can be found in the currently buffered data

Definition at line 329 of file iodevice.cc.

◆ write() [1/2]

int64_t zyppng::IODevice::write ( const ByteArray & data)

Definition at line 345 of file iodevice.cc.

◆ write() [2/2]

int64_t zyppng::IODevice::write ( const char * data,
int64_t len )

Definition at line 352 of file iodevice.cc.

◆ bytesPending()

virtual int64_t zyppng::IODevice::bytesPending ( ) const
pure virtual

Returns the current number of bytes that are not yet written to the device.

Implemented in zyppng::AsyncDataSource, and zyppng::Socket.

◆ waitForReadyRead() [1/2]

bool zyppng::IODevice::waitForReadyRead ( int timeout)

Blocks the current event loop to wait until there are bytes available to read from the device. This always operates on the read channel that is selected as the default when the function is first called, even if the default channel would be changed during the wait.

See also
zyppng::IODevice::currentReadChannel
Note
do not use until there is a very good reason, like event processing should not continue until readyRead was sent

Definition at line 359 of file iodevice.cc.

◆ waitForReadyRead() [2/2]

virtual bool zyppng::IODevice::waitForReadyRead ( uint channel,
int timeout )
pure virtual

Blocks the current event loop to wait until there are bytes available to read from the given read channel.

Note
do not use until there is a very good reason, like event processing should not continue until readyRead was sent

Implemented in zyppng::AsyncDataSource, and zyppng::Socket.

◆ sigReadyRead()

SignalProxy< void()> zyppng::IODevice::sigReadyRead ( )

Signal is emitted when there is data available to read on the current default read channel

Definition at line 368 of file iodevice.cc.

◆ sigChannelReadyRead()

SignalProxy< void(uint)> zyppng::IODevice::sigChannelReadyRead ( )

Signal is emitted when there is data available on the given channel

Definition at line 373 of file iodevice.cc.

◆ sigBytesWritten()

SignalProxy< void(int64_t)> zyppng::IODevice::sigBytesWritten ( )

Signal is emitted every time bytes have been written to the underlying device. This can be used to track how much data was actually sent.

Definition at line 378 of file iodevice.cc.

◆ sigAllBytesWritten()

SignalProxy< void()> zyppng::IODevice::sigAllBytesWritten ( )

Signal is emitted every time all bytes have been written to the underlying device.

Definition at line 383 of file iodevice.cc.

◆ sigReadChannelFinished()

SignalProxy< void(uint)> zyppng::IODevice::sigReadChannelFinished ( )

Emitted when the backing device of the given read channel is closed, data might be still available in the buffer to read

Definition at line 388 of file iodevice.cc.

◆ open()

bool zyppng::IODevice::open ( const OpenMode mode)
protectedvirtual

Reimplemented in zyppng::AsyncDataSource.

Definition at line 16 of file iodevice.cc.

◆ rawBytesAvailable()

virtual int64_t zyppng::IODevice::rawBytesAvailable ( uint channel) const
protectedpure virtual

◆ writeData()

virtual int64_t zyppng::IODevice::writeData ( const char * data,
int64_t count )
protectedpure virtual

◆ readData()

virtual int64_t zyppng::IODevice::readData ( uint channel,
char * buffer,
int64_t bufsize )
protectedpure virtual

◆ readChannelChanged()

virtual void zyppng::IODevice::readChannelChanged ( uint channel)
protectedpure virtual

◆ setReadChannelCount()

void zyppng::IODevice::setReadChannelCount ( uint channels)
protected

Definition at line 37 of file iodevice.cc.

◆ finishReadChannel()

void zyppng::IODevice::finishReadChannel ( uint channel)
protected

Definition at line 44 of file iodevice.cc.


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