libzypp 17.37.17
zyppng::AsyncDataSource Class Reference

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

Inheritance diagram for zyppng::AsyncDataSource:

Public Types

enum  ChannelCloseReason { RemoteClose , AccessError , InternalError , UserRequest }
using Ptr = std::shared_ptr<AsyncDataSource>
using WeakPtr = std::weak_ptr<AsyncDataSource>
Public Types inherited from zyppng::IODevice
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

bool openFds (const std::vector< int > &readFds, int writeFd=-1)
void close () override
virtual void closeWriteChannel ()
bool waitForReadyRead (uint channel, int timeout) override
void flush ()
SignalProxy< void(AsyncDataSource::ChannelCloseReason)> sigWriteFdClosed ()
SignalProxy< void(uint, AsyncDataSource::ChannelCloseReason)> sigReadFdClosed ()
bool readFdOpen () const
bool readFdOpen (uint channel) const
int64_t bytesPending () const override
bool waitForReadyRead (int timeout)
Public Member Functions inherited from zyppng::IODevice
 ZYPP_DECLARE_FLAGS (OpenMode, OpenModeFlag)
 IODevice ()
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)
bool waitForReadyRead (int timeout)
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)

Static Public Member Functions

static Ptr create ()
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 Member Functions

 AsyncDataSource ()
 AsyncDataSource (AsyncDataSourcePrivate &d)
int64_t writeData (const char *data, int64_t count) override
Protected Member Functions inherited from zyppng::IODevice
 IODevice (IODevicePrivate &d)
void setReadChannelCount (uint channels)
void finishReadChannel (uint channel)
Protected Member Functions inherited from zyppng::Base
 Base (BasePrivate &dd)

Private Member Functions

int64_t readData (uint channel, char *buffer, int64_t bufsize) override
int64_t rawBytesAvailable (uint channel) const override
void readChannelChanged (uint channel) override
virtual bool open (const OpenMode mode)

Additional Inherited Members

Protected Attributes inherited from zyppng::Base
std::unique_ptr< BasePrivated_ptr

Detailed Description

Definition at line 11 of file asyncdatasource.h.

Member Typedef Documentation

◆ Ptr

Definition at line 23 of file asyncdatasource.h.

◆ WeakPtr

Definition at line 24 of file asyncdatasource.h.

Member Enumeration Documentation

◆ ChannelCloseReason

Enumerator
RemoteClose 
AccessError 
InternalError 
UserRequest 

Definition at line 16 of file asyncdatasource.h.

Constructor & Destructor Documentation

◆ AsyncDataSource() [1/2]

zyppng::AsyncDataSource::AsyncDataSource ( )
protected

Definition at line 139 of file asyncdatasource.cpp.

◆ AsyncDataSource() [2/2]

zyppng::AsyncDataSource::AsyncDataSource ( AsyncDataSourcePrivate & d)
protected

Definition at line 142 of file asyncdatasource.cpp.

Member Function Documentation

◆ create()

AsyncDataSource::Ptr zyppng::AsyncDataSource::create ( )
static

Definition at line 146 of file asyncdatasource.cpp.

◆ openFds()

bool zyppng::AsyncDataSource::openFds ( const std::vector< int > & readFds,
int writeFd = -1 )

Borrows the given fd's and starts reading/writing to them if data is available. Note that AsyncDataSource does not take ownership of the FDs, they need to be closed explicitely after they were released with close

Definition at line 152 of file asyncdatasource.cpp.

◆ close()

void zyppng::AsyncDataSource::close ( )
overridevirtual

Closes the AsyncDataSource and releases the used fd's to the calling code. They are NOT closed.

Reimplemented from zyppng::IODevice.

Reimplemented in zyppng::Process.

Definition at line 260 of file asyncdatasource.cpp.

◆ closeWriteChannel()

void zyppng::AsyncDataSource::closeWriteChannel ( )
virtual

Reimplemented in zyppng::Process.

Definition at line 283 of file asyncdatasource.cpp.

◆ waitForReadyRead() [1/2]

bool zyppng::AsyncDataSource::waitForReadyRead ( uint channel,
int timeout )
overridevirtual

Blocks the current event loop to wait until all bytes currently in the buffer have been written to the write fd.

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

Implements zyppng::IODevice.

Definition at line 303 of file asyncdatasource.cpp.

◆ flush()

void zyppng::AsyncDataSource::flush ( )

Blocks the current event loop to wait until all bytes currently in the buffer have been written to the write fd.

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

Definition at line 334 of file asyncdatasource.cpp.

◆ sigWriteFdClosed()

SignalProxy< void(AsyncDataSource::ChannelCloseReason)> zyppng::AsyncDataSource::sigWriteFdClosed ( )

Signal is emitted always when the write channel is closed. All data that was not written yet will be discarded and canWrite() will return false.

Definition at line 353 of file asyncdatasource.cpp.

◆ sigReadFdClosed()

SignalProxy< void(uint, AsyncDataSource::ChannelCloseReason)> zyppng::AsyncDataSource::sigReadFdClosed ( )

Signal is emitted always when the write channel is closed, for example when the write side of a pipe is closed. All data still residing in the read buffer can still be read.

Definition at line 358 of file asyncdatasource.cpp.

◆ readFdOpen() [1/2]

bool zyppng::AsyncDataSource::readFdOpen ( ) const

Returns true as long as the default read channel was not closed ( e.g. sigReadFdClosed was emitted )

Definition at line 363 of file asyncdatasource.cpp.

◆ readFdOpen() [2/2]

bool zyppng::AsyncDataSource::readFdOpen ( uint channel) const

Returns true as long as the given read channel was not closed ( e.g. sigReadFdClosed was emitted )

Definition at line 371 of file asyncdatasource.cpp.

◆ bytesPending()

int64_t zyppng::AsyncDataSource::bytesPending ( ) const
overridevirtual

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

Implements zyppng::IODevice.

Definition at line 382 of file asyncdatasource.cpp.

◆ writeData()

int64_t zyppng::AsyncDataSource::writeData ( const char * data,
int64_t count )
overrideprotectedvirtual

Implements zyppng::IODevice.

Definition at line 203 of file asyncdatasource.cpp.

◆ readData()

int64_t zyppng::AsyncDataSource::readData ( uint channel,
char * buffer,
int64_t bufsize )
overrideprivatevirtual

Implements zyppng::IODevice.

Definition at line 214 of file asyncdatasource.cpp.

◆ rawBytesAvailable()

int64_t zyppng::AsyncDataSource::rawBytesAvailable ( uint channel) const
overrideprivatevirtual

Implements zyppng::IODevice.

Definition at line 237 of file asyncdatasource.cpp.

◆ readChannelChanged()

void zyppng::AsyncDataSource::readChannelChanged ( uint channel)
overrideprivatevirtual

Implements zyppng::IODevice.

Definition at line 251 of file asyncdatasource.cpp.

◆ waitForReadyRead() [2/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 141 of file iodevice.cc.

◆ open()

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

Reimplemented from zyppng::IODevice.

Definition at line 180 of file iodevice.cc.


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