libzypp: zypp-core/ng/io/iodevice.h Source File

libzypp 17.38.9

iodevice.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\----------------------------------------------------------------------/
9*
10* This file contains private API, this might break at any time between releases.
11* You have been warned!
12*
13*/
14
15#ifndef ZYPPNG_IO_IODEVICE_DEFINED
16#define ZYPPNG_IO_IODEVICE_DEFINED
17
18#include <zypp-core/base/Flags.h>
19#include <zypp-core/ng/base/Base>
20#include <zypp-core/ng/base/Signals>
21#include <zypp-core/ng/core/ByteArray>
22
23namespace zyppng {
24
25 class IODevicePrivate;
26 ZYPP_FWD_DECL_TYPE_WITH_REFS(IODevice);
27
32 class IODevice : public Base
33 {
34 ZYPP_DECLARE_PRIVATE(IODevice)
35 public:
36
37 enum OpenModeFlag {
38 Closed = 0x0,
39 ReadOnly = 0x1,
40 WriteOnly = 0x2,
41 ReadWrite = ReadOnly | WriteOnly
42 };
43 ZYPP_DECLARE_FLAGS( OpenMode, OpenModeFlag );
44
45 using Ptr = std::shared_ptr<IODevice>;
46 using WeakPtr = std::weak_ptr<IODevice>;
47
48 IODevice();
49 virtual void close ();
50
51 void setReadChannel ( uint channel );
52 uint currentReadChannel () const;
53 int readChannelCount () const;
54
55 bool canRead () const;
56 bool canWrite () const;
57 bool isOpen () const;
58
59 ByteArray readAll ();
60 ByteArray read ( int64_t maxSize );
61 int64_t read ( char *buf, int64_t maxSize );
62 virtual ByteArray readLine (const int64_t maxSize = 0 );
63 virtual int64_t bytesAvailable () const;
64 int64_t readBufferCount() const;
65 bool canReadLine () const;
66
67 ByteArray readAll ( uint channel );
68 ByteArray read ( uint channel, int64_t maxSize );
69 int64_t read ( uint channel, char *buf, int64_t maxSize );
70
71
77 ByteArray channelReadUntil ( uint channel, const char delim, int64_t maxSize = 0 );
78
84 ByteArray channelReadLine ( uint channel, int64_t maxSize = 0 );
85
95 int64_t channelReadLine ( uint channel, char *buf, const int64_t maxSize );
96 virtual int64_t bytesAvailable( uint channel ) const;
97
101 int64_t readBufferCount( uint channel ) const;
102
112 virtual int64_t channelReadUntil ( uint channel, char *buf, const char delimiter, const int64_t maxSize );
113
117 bool canReadLine ( uint channel ) const;
118
122 bool canReadUntil ( uint channel, const char delim ) const;
123
124
125 int64_t write ( const ByteArray &data );
126 int64_t write ( const char *data, int64_t len );
127
131 virtual int64_t bytesPending() const = 0;
132
141 bool waitForReadyRead(int timeout);
142
148 virtual bool waitForReadyRead(uint channel, int timeout) = 0;
149
150
154 SignalProxy<void ()> sigReadyRead ();
155
159 SignalProxy<void (uint)> sigChannelReadyRead ();
160
165 SignalProxy< void (int64_t)> sigBytesWritten ();
166
170 SignalProxy< void ()> sigAllBytesWritten ();
171
176 SignalProxy< void(uint) >sigReadChannelFinished();
177
178 protected:
179 IODevice( IODevicePrivate &d );
180 virtual bool open ( const OpenMode mode );
181 virtual int64_t rawBytesAvailable ( uint channel ) const = 0;
182 virtual int64_t writeData ( const char *data, int64_t count ) = 0;
183 virtual int64_t readData ( uint channel, char *buffer, int64_t bufsize ) = 0;
184 virtual void readChannelChanged ( uint channel ) = 0;
185 void setReadChannelCount ( uint channels );
186 void finishReadChannel ( uint channel );
187 };
188 ZYPP_DECLARE_OPERATORS_FOR_FLAGS( IODevice::OpenMode );
189
190
195 class IODeviceOStreamBuf : public std::streambuf
196 {
197 public:
198 IODeviceOStreamBuf( IODeviceRef dev );
199 IODeviceOStreamBuf(const IODeviceOStreamBuf &) = default;
200 IODeviceOStreamBuf(IODeviceOStreamBuf &&) = default;
201 IODeviceOStreamBuf &operator=(const IODeviceOStreamBuf &) = default;
202 IODeviceOStreamBuf &operator=(IODeviceOStreamBuf &&) = default;
203
204 // basic_streambuf interface
205 protected:
206 int_type overflow(int_type __c) override;
207
208 private:
209 IODeviceRef _dev;
210 };
211}
212
213#endif
Flags.h
ZYPP_DECLARE_OPERATORS_FOR_FLAGS
#define ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Name)
relates: Flags
Definition Flags.h:177
zypp::ByteArray
Definition ByteArray.h:20
zyppng::Base::data
void * data(uint32_t quark)
Definition base.cc:82
zyppng::Base::Base
Base()
Definition base.cc:20
zyppng::IODeviceOStreamBuf::IODeviceOStreamBuf
IODeviceOStreamBuf(IODeviceRef dev)
Definition iodevice.cc:394
zyppng::IODeviceOStreamBuf::overflow
int_type overflow(int_type __c) override
Definition iodevice.cc:397
zyppng::IODeviceOStreamBuf::_dev
IODeviceRef _dev
Definition iodevice.h:209
zyppng::IODeviceOStreamBuf::operator=
IODeviceOStreamBuf & operator=(const IODeviceOStreamBuf &)=default
zyppng::IODeviceOStreamBuf::IODeviceOStreamBuf
IODeviceOStreamBuf(IODeviceOStreamBuf &&)=default
zyppng::IODeviceOStreamBuf::IODeviceOStreamBuf
IODeviceOStreamBuf(const IODeviceOStreamBuf &)=default
zyppng::IODeviceOStreamBuf::operator=
IODeviceOStreamBuf & operator=(IODeviceOStreamBuf &&)=default
zyppng::IODevicePrivate
Definition iodevice_p.h:35
zyppng::IODevice
Definition iodevice.h:33
zyppng::IODevice::channelReadUntil
ByteArray channelReadUntil(uint channel, const char delim, int64_t maxSize=0)
Definition iodevice.cc:188
zyppng::IODevice::readChannelChanged
virtual void readChannelChanged(uint channel)=0
zyppng::IODevice::canReadLine
bool canReadLine() const
Definition iodevice.cc:100
zyppng::IODevice::writeData
virtual int64_t writeData(const char *data, int64_t count)=0
zyppng::IODevice::waitForReadyRead
virtual bool waitForReadyRead(uint channel, int timeout)=0
zyppng::IODevice::bytesPending
virtual int64_t bytesPending() const =0
zyppng::IODevice::readLine
virtual ByteArray readLine(const int64_t maxSize=0)
Definition iodevice.cc:142
zyppng::IODevice::sigChannelReadyRead
SignalProxy< void(uint)> sigChannelReadyRead()
Definition iodevice.cc:373
zyppng::IODevice::sigReadChannelFinished
SignalProxy< void(uint) > sigReadChannelFinished()
Definition iodevice.cc:388
zyppng::IODevice::setReadChannelCount
void setReadChannelCount(uint channels)
Definition iodevice.cc:37
zyppng::IODevice::sigReadyRead
SignalProxy< void()> sigReadyRead()
Definition iodevice.cc:368
zyppng::IODevice::bytesAvailable
virtual int64_t bytesAvailable() const
Definition iodevice.cc:109
zyppng::IODevice::rawBytesAvailable
virtual int64_t rawBytesAvailable(uint channel) const =0
zyppng::IODevice::sigBytesWritten
SignalProxy< void(int64_t)> sigBytesWritten()
Definition iodevice.cc:378
zyppng::IODevice::canWrite
bool canWrite() const
Definition iodevice.cc:90
zyppng::IODevice::readData
virtual int64_t readData(uint channel, char *buffer, int64_t bufsize)=0
zyppng::IODevice::waitForReadyRead
bool waitForReadyRead(int timeout)
Definition iodevice.cc:359
zyppng::IODevice::finishReadChannel
void finishReadChannel(uint channel)
Definition iodevice.cc:44
zyppng::IODevice::canReadUntil
bool canReadUntil(uint channel, const char delim) const
Definition iodevice.cc:329
zyppng::IODevice::readBufferCount
int64_t readBufferCount() const
Definition iodevice.cc:115
zyppng::IODevice::readAll
ByteArray readAll()
Definition iodevice.cc:121
zyppng::IODevice::ZYPP_DECLARE_FLAGS
ZYPP_DECLARE_FLAGS(OpenMode, OpenModeFlag)
zyppng::IODevice::OpenModeFlag
OpenModeFlag
Definition iodevice.h:37
zyppng::IODevice::WriteOnly
@ WriteOnly
Definition iodevice.h:40
zyppng::IODevice::ReadOnly
@ ReadOnly
Definition iodevice.h:39
zyppng::IODevice::Closed
@ Closed
Definition iodevice.h:38
zyppng::IODevice::ReadWrite
@ ReadWrite
Definition iodevice.h:41
zyppng::IODevice::close
virtual void close()
Definition iodevice.cc:30
zyppng::IODevice::WeakPtr
std::weak_ptr< IODevice > WeakPtr
Definition iodevice.h:46
zyppng::IODevice::canRead
bool canRead() const
Definition iodevice.cc:85
zyppng::IODevice::sigAllBytesWritten
SignalProxy< void()> sigAllBytesWritten()
Definition iodevice.cc:383
zyppng::IODevice::setReadChannel
void setReadChannel(uint channel)
Definition iodevice.cc:56
zyppng::IODevice::currentReadChannel
uint currentReadChannel() const
Definition iodevice.cc:69
zyppng::IODevice::isOpen
bool isOpen() const
Definition iodevice.cc:95
zyppng::IODevice::read
ByteArray read(int64_t maxSize)
Definition iodevice.cc:127
zyppng::IODevice::channelReadLine
ByteArray channelReadLine(uint channel, int64_t maxSize=0)
Definition iodevice.cc:250
zyppng::IODevice::IODevice
IODevice()
Definition iodevice.cc:10
zyppng::IODevice::write
int64_t write(const ByteArray &data)
Definition iodevice.cc:345
zyppng::IODevice::open
virtual bool open(const OpenMode mode)
Definition iodevice.cc:16
zyppng::IODevice::readChannelCount
int readChannelCount() const
Definition iodevice.cc:77
zyppng::IODevice::Ptr
std::shared_ptr< IODevice > Ptr
Definition iodevice.h:45
zyppng::SignalProxy
Definition signals.h:325
zyppng
Definition MediaNetworkRequestExecutor.h:16
ZYPP_DECLARE_PRIVATE
#define ZYPP_DECLARE_PRIVATE(Class)
Definition zyppglobal.h:80
ZYPP_FWD_DECL_TYPE_WITH_REFS
#define ZYPP_FWD_DECL_TYPE_WITH_REFS(T)
Definition zyppglobal.h:119