libzypp 17.32.5
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
 
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 channelReadLine (uint channel, int64_t maxSize=0)
 
virtual int64_t channelReadLine (uint channel, char *buf, const int64_t maxSize)
 
virtual int64_t bytesAvailable (uint channel) const
 
bool canReadLine (uint channel) const
 
int64_t write (const ByteArray &data)
 
int64_t write (const char *data, int64_t len)
 
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 ()
 
- 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)
 
- Protected Member Functions inherited from zyppng::Base
 Base (BasePrivate &dd)
 

Private Member Functions

 ZYPP_DECLARE_PRIVATE (IODevice)
 

Additional Inherited Members

- Static Public Member Functions inherited from zyppng::Base
template<typename Obj , typename Functor >
static decltype(automake_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 31 of file iodevice.h.

Member Typedef Documentation

◆ Ptr

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

Definition at line 44 of file iodevice.h.

◆ WeakPtr

Definition at line 45 of file iodevice.h.

Member Enumeration Documentation

◆ OpenModeFlag

Enumerator
Closed 
ReadOnly 
WriteOnly 
ReadWrite 

Definition at line 36 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_PRIVATE()

zyppng::IODevice::ZYPP_DECLARE_PRIVATE ( IODevice )
private

◆ 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 44 of file iodevice.cc.

◆ currentReadChannel()

uint zyppng::IODevice::currentReadChannel ( ) const

Definition at line 57 of file iodevice.cc.

◆ readChannelCount()

int zyppng::IODevice::readChannelCount ( ) const

Definition at line 65 of file iodevice.cc.

◆ canRead()

bool zyppng::IODevice::canRead ( ) const

Definition at line 73 of file iodevice.cc.

◆ canWrite()

bool zyppng::IODevice::canWrite ( ) const

Definition at line 78 of file iodevice.cc.

◆ isOpen()

bool zyppng::IODevice::isOpen ( ) const

Definition at line 83 of file iodevice.cc.

◆ readAll() [1/2]

ByteArray zyppng::IODevice::readAll ( )

Definition at line 103 of file iodevice.cc.

◆ read() [1/4]

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

Definition at line 109 of file iodevice.cc.

◆ read() [2/4]

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

Definition at line 116 of file iodevice.cc.

◆ readLine()

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

Definition at line 124 of file iodevice.cc.

◆ bytesAvailable() [1/2]

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

Definition at line 97 of file iodevice.cc.

◆ canReadLine() [1/2]

bool zyppng::IODevice::canReadLine ( ) const

Definition at line 88 of file iodevice.cc.

◆ readAll() [2/2]

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

Definition at line 132 of file iodevice.cc.

◆ read() [3/4]

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

Definition at line 137 of file iodevice.cc.

◆ read() [4/4]

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

Definition at line 148 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 170 of file iodevice.cc.

◆ channelReadLine() [2/2]

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

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 232 of file iodevice.cc.

◆ bytesAvailable() [2/2]

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

Definition at line 285 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 293 of file iodevice.cc.

◆ write() [1/2]

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

Definition at line 301 of file iodevice.cc.

◆ write() [2/2]

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

Definition at line 308 of file iodevice.cc.

◆ 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 315 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, 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 324 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 329 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 334 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 339 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.


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