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