libzypp 17.37.17
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
19#include <zypp-core/zyppng/base/Base>
20#include <zypp-core/zyppng/base/Signals>
21#include <zypp-core/zyppng/core/ByteArray>
22
23namespace zyppng {
24
25 class IODevicePrivate;
27
32 class IODevice : public Base
33 {
35 public:
36
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
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:
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 );
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
IODeviceOStreamBuf(IODeviceRef dev)
Definition iodevice.cc:394
int_type overflow(int_type __c) override
Definition iodevice.cc:397
IODeviceOStreamBuf & operator=(const IODeviceOStreamBuf &)=default
IODeviceOStreamBuf(IODeviceOStreamBuf &&)=default
IODeviceOStreamBuf(const IODeviceOStreamBuf &)=default
IODeviceOStreamBuf & operator=(IODeviceOStreamBuf &&)=default
ByteArray channelReadUntil(uint channel, const char delim, int64_t maxSize=0)
Definition iodevice.cc:188
virtual void readChannelChanged(uint channel)=0
bool canReadLine() const
Definition iodevice.cc:100
virtual int64_t writeData(const char *data, int64_t count)=0
virtual bool waitForReadyRead(uint channel, int timeout)=0
virtual int64_t bytesPending() const =0
virtual ByteArray readLine(const int64_t maxSize=0)
Definition iodevice.cc:142
SignalProxy< void(uint)> sigChannelReadyRead()
Definition iodevice.cc:373
SignalProxy< void(uint) > sigReadChannelFinished()
Definition iodevice.cc:388
void setReadChannelCount(uint channels)
Definition iodevice.cc:37
SignalProxy< void()> sigReadyRead()
Definition iodevice.cc:368
virtual int64_t bytesAvailable() const
Definition iodevice.cc:109
virtual int64_t rawBytesAvailable(uint channel) const =0
SignalProxy< void(int64_t)> sigBytesWritten()
Definition iodevice.cc:378
bool canWrite() const
Definition iodevice.cc:90
virtual int64_t readData(uint channel, char *buffer, int64_t bufsize)=0
bool waitForReadyRead(int timeout)
Definition iodevice.cc:359
void finishReadChannel(uint channel)
Definition iodevice.cc:44
bool canReadUntil(uint channel, const char delim) const
Definition iodevice.cc:329
int64_t readBufferCount() const
Definition iodevice.cc:115
ByteArray readAll()
Definition iodevice.cc:121
ZYPP_DECLARE_FLAGS(OpenMode, OpenModeFlag)
virtual void close()
Definition iodevice.cc:30
std::weak_ptr< IODevice > WeakPtr
Definition iodevice.h:46
bool canRead() const
Definition iodevice.cc:85
SignalProxy< void()> sigAllBytesWritten()
Definition iodevice.cc:383
void setReadChannel(uint channel)
Definition iodevice.cc:56
uint currentReadChannel() const
Definition iodevice.cc:69
bool isOpen() const
Definition iodevice.cc:95
ByteArray read(int64_t maxSize)
Definition iodevice.cc:127
ByteArray channelReadLine(uint channel, int64_t maxSize=0)
Definition iodevice.cc:250
int64_t write(const ByteArray &data)
Definition iodevice.cc:345
virtual bool open(const OpenMode mode)
Definition iodevice.cc:16
int readChannelCount() const
Definition iodevice.cc:77
std::shared_ptr< IODevice > Ptr
Definition iodevice.h:45
#define ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Name)
Definition Flags.h:177
#define ZYPP_DECLARE_PRIVATE(Class)
Definition zyppglobal.h:87
#define ZYPP_FWD_DECL_TYPE_WITH_REFS(T)
Definition zyppglobal.h:126