libzypp  17.25.1
ExternalDataSource.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #ifndef ZYPP_EXTERNALDATASOURCE_H
13 #define ZYPP_EXTERNALDATASOURCE_H
14 
15 #include <stdio.h>
16 
17 #include <string>
18 #include <optional>
19 #include <zypp/base/IOTools.h>
20 
21 namespace zypp {
22  namespace externalprogram {
23 
28  {
29  protected:
30  FILE *inputfile;
31  FILE *outputfile;
32 
33  private:
34  char *linebuffer;
36 
37  public:
44  ExternalDataSource( FILE *inputfile = 0, FILE *outputfile = 0 );
45 
49  virtual ~ExternalDataSource ();
50 
56  bool send( const char *buffer, size_t length );
57 
62  bool send( std::string s );
63 
70  size_t receive( char *buffer, size_t length );
71 
76  std::string receiveLine();
77 
85  std::string receiveLine( io::timeout_type timeout );
86 
92  std::string receiveUpto( char c );
93 
101  std::string receiveUpto( char c, io::timeout_type timeout );
102 
108  void setBlocking( bool mode );
109 
113  virtual int close();
114 
118  FILE *inputFile() const { return inputfile; }
119 
123  FILE *outputFile() const { return outputfile; }
124  };
125 
126  } // namespace externalprogram
127 } // namespace zypp
128 
129 #endif // ZYPP_EXTERNALDATASOURCE_H
130 
zypp::externalprogram::ExternalDataSource::close
virtual int close()
Close the input and output streams.
Definition: ExternalDataSource.cc:135
zypp::externalprogram::ExternalDataSource::receive
size_t receive(char *buffer, size_t length)
Read some data from the input stream.
Definition: ExternalDataSource.cc:101
zypp::externalprogram::ExternalDataSource::linebuffer_size
size_t linebuffer_size
Definition: ExternalDataSource.h:35
zypp::externalprogram::ExternalDataSource::~ExternalDataSource
virtual ~ExternalDataSource()
Implicitly close the connection.
Definition: ExternalDataSource.cc:43
zypp::externalprogram::ExternalDataSource::send
bool send(const char *buffer, size_t length)
Send some data to the output stream.
Definition: ExternalDataSource.cc:52
zypp::io::timeout_type
size_t timeout_type
Definition: IOTools.h:61
zypp::externalprogram::ExternalDataSource::receiveUpto
std::string receiveUpto(char c)
Read characters into a string until delimiter c or EOF is read.
Definition: ExternalDataSource.cc:73
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::externalprogram::ExternalDataSource::outputFile
FILE * outputFile() const
Return the output stream.
Definition: ExternalDataSource.h:123
zypp::externalprogram::ExternalDataSource::inputfile
FILE * inputfile
Definition: ExternalDataSource.h:30
IOTools.h
zypp::externalprogram::ExternalDataSource::setBlocking
void setBlocking(bool mode)
Set the blocking mode of the input stream.
Definition: ExternalDataSource.cc:109
zypp::externalprogram::ExternalDataSource::receiveLine
std::string receiveLine()
Read one line from the input stream.
Definition: ExternalDataSource.cc:115
timeout
time_t timeout
Definition: MediaCurl.cc:67
zypp::externalprogram::ExternalDataSource::outputfile
FILE * outputfile
Definition: ExternalDataSource.h:31
zypp::externalprogram::ExternalDataSource::linebuffer
char * linebuffer
Definition: ExternalDataSource.h:34
zypp::externalprogram::ExternalDataSource
Bidirectional stream to external data.
Definition: ExternalDataSource.h:27
zypp::externalprogram::ExternalDataSource::ExternalDataSource
ExternalDataSource(FILE *inputfile=0, FILE *outputfile=0)
Create a new instance.
Definition: ExternalDataSource.cc:34
zypp::externalprogram::ExternalDataSource::inputFile
FILE * inputFile() const
Return the input stream.
Definition: ExternalDataSource.h:118