libzypp  17.32.5
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;
26 
31  class IODevice : public Base
32  {
34  public:
35 
36  enum OpenModeFlag {
37  Closed = 0x0,
38  ReadOnly = 0x1,
39  WriteOnly = 0x2,
41  };
42  ZYPP_DECLARE_FLAGS( OpenMode, OpenModeFlag );
43 
44  using Ptr = std::shared_ptr<IODevice>;
45  using WeakPtr = std::weak_ptr<IODevice>;
46 
47  IODevice();
48  virtual void close ();
49 
50  void setReadChannel ( uint channel );
51  uint currentReadChannel () const;
52  int readChannelCount () const;
53 
54  bool canRead () const;
55  bool canWrite () const;
56  bool isOpen () const;
57 
58  ByteArray readAll ();
59  ByteArray read ( int64_t maxSize );
60  int64_t read ( char *buf, int64_t maxSize );
61  virtual ByteArray readLine (const int64_t maxSize = 0 );
62  virtual int64_t bytesAvailable () const;
63  bool canReadLine () const;
64 
65  ByteArray readAll ( uint channel );
66  ByteArray read ( uint channel, int64_t maxSize );
67  int64_t read ( uint channel, char *buf, int64_t maxSize );
68 
74  ByteArray channelReadLine ( uint channel, int64_t maxSize = 0 );
75 
85  virtual int64_t channelReadLine ( uint channel, char *buf, const int64_t maxSize );
86  virtual int64_t bytesAvailable( uint channel ) const;
87 
91  bool canReadLine ( uint channel ) const;
92 
93  int64_t write ( const ByteArray &data );
94  int64_t write ( const char *data, int64_t len );
95 
104  bool waitForReadyRead(int timeout);
105 
111  virtual bool waitForReadyRead(uint channel, int timeout) = 0;
112 
113 
118 
123 
129 
134 
135  protected:
137  virtual bool open ( const OpenMode mode );
138  virtual int64_t rawBytesAvailable ( uint channel ) const = 0;
139  virtual int64_t writeData ( const char *data, int64_t count ) = 0;
140  virtual int64_t readData ( uint channel, char *buffer, int64_t bufsize ) = 0;
141  virtual void readChannelChanged ( uint channel ) = 0;
142  void setReadChannelCount ( uint channels );
143  };
144  ZYPP_DECLARE_OPERATORS_FOR_FLAGS( IODevice::OpenMode );
145 
146 }
147 
148 #endif
bool canReadLine() const
Definition: iodevice.cc:88
virtual int64_t rawBytesAvailable(uint channel) const =0
uint currentReadChannel() const
Definition: iodevice.cc:57
bool canRead() const
Definition: iodevice.cc:73
ZYPP_DECLARE_FLAGS(OpenMode, OpenModeFlag)
std::weak_ptr< Base > WeakPtr
Definition: base.h:66
SignalProxy< void(int64_t)> sigBytesWritten()
Definition: iodevice.cc:334
int readChannelCount() const
Definition: iodevice.cc:65
virtual bool open(const OpenMode mode)
Definition: iodevice.cc:16
void setReadChannelCount(uint channels)
Definition: iodevice.cc:37
ByteArray readAll()
Definition: iodevice.cc:103
void setReadChannel(uint channel)
Definition: iodevice.cc:44
ByteArray channelReadLine(uint channel, int64_t maxSize=0)
Definition: iodevice.cc:170
bool isOpen() const
Definition: iodevice.cc:83
ZYPP_DECLARE_PRIVATE(IODevice)
ZYPP_DECLARE_OPERATORS_FOR_FLAGS(IODevice::OpenMode)
virtual int64_t writeData(const char *data, int64_t count)=0
virtual void readChannelChanged(uint channel)=0
int64_t write(const ByteArray &data)
Definition: iodevice.cc:301
ByteArray read(int64_t maxSize)
Definition: iodevice.cc:109
SignalProxy< void(uint)> sigChannelReadyRead()
Definition: iodevice.cc:329
SignalProxy< void()> sigReadyRead()
Definition: iodevice.cc:324
SignalProxy< void()> sigAllBytesWritten()
Definition: iodevice.cc:339
virtual int64_t bytesAvailable() const
Definition: iodevice.cc:97
virtual ByteArray readLine(const int64_t maxSize=0)
Definition: iodevice.cc:124
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:78
bool waitForReadyRead(int timeout)
Definition: iodevice.cc:315
std::shared_ptr< Base > Ptr
Definition: base.h:65