1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/ExternalDataSource.h
12 #ifndef ZYPP_EXTERNALDATASOURCE_H
13 #define ZYPP_EXTERNALDATASOURCE_H
19 #include <zypp/base/IOTools.h>
22 namespace externalprogram {
25 * @short Bidirectional stream to external data
27 class ExternalDataSource
35 size_t linebuffer_size;
39 * Create a new instance.
40 * @param inputfile The stream for reading
41 * @param outputfile The stream for writing
42 * Either can be NULL if no reading/writing is allowed.
44 ExternalDataSource( FILE *inputfile = 0, FILE *outputfile = 0 );
47 * Implicitly close the connection.
49 virtual ~ExternalDataSource ();
52 * Send some data to the output stream.
53 * @param buffer The data to send
54 * @param length The size of it
56 bool send( const char *buffer, size_t length );
59 * Send some data down the stream.
60 * @param string The data to send
62 bool send( std::string s );
65 * Read some data from the input stream.
66 * @param buffer Where to put the data
67 * @param length How much to read at most
68 * Returns the amount actually received
70 size_t receive( char *buffer, size_t length );
73 * Read one line from the input stream.
74 * Returns the line read, including the terminator.
76 std::string receiveLine();
79 * Read one line from the input stream.
80 * Returns the line read, including the terminator.
81 * \note The delimiter is not removed from the string.
82 * \note The \a timeout value is to be specified in milliseconds.
83 * \throws io::TimeoutException if the timeout is reached
85 std::string receiveLine( io::timeout_type timeout );
88 * Read characters into a string until delimiter \a c or EOF is
90 * \note The delimiter is not removed from the string.
92 std::string receiveUpto( char c );
95 * Read characters into a string until delimiter \a c or EOF is
96 * read or the \a timeout is reached.
97 * \note The delimiter is not removed from the string.
98 * \note The \a timeout value is to be specified in milliseconds.
99 * \throws io::TimeoutException if the timeout is reached
101 std::string receiveUpto( char c, io::timeout_type timeout );
104 * Set the blocking mode of the input stream.
105 * @param mode True if the reader should be blocked waiting for input.
106 * This is the initial default.
108 void setBlocking( bool mode );
111 * Close the input and output streams.
116 * Return the input stream.
118 FILE *inputFile() const { return inputfile; }
121 * Return the output stream.
123 FILE *outputFile() const { return outputfile; }
126 } // namespace externalprogram
129 #endif // ZYPP_EXTERNALDATASOURCE_H