1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/ExternalDataSource.h
12 #ifndef ZYPP_EXTERNALDATASOURCE_H
13 #define ZYPP_EXTERNALDATASOURCE_H
20 namespace externalprogram {
23 * @short Bidirectional stream to external data
25 class ExternalDataSource
33 size_t linebuffer_size;
37 * Create a new instance.
38 * @param inputfile The stream for reading
39 * @param outputfile The stream for writing
40 * Either can be NULL if no reading/writing is allowed.
42 ExternalDataSource(FILE *inputfile = 0, FILE *outputfile = 0);
45 * Implicitly close the connection.
47 virtual ~ExternalDataSource();
50 * Send some data to the output stream.
51 * @param buffer The data to send
52 * @param length The size of it
54 bool send (const char *buffer, size_t length);
57 * Send some data down the stream.
58 * @param string The data to send
60 bool send (std::string s);
63 * Read some data from the input stream.
64 * @param buffer Where to put the data
65 * @param length How much to read at most
66 * Returns the amount actually received
68 size_t receive(char *buffer, size_t length);
71 * Read one line from the input stream.
72 * Returns the line read, including the terminator.
74 std::string receiveLine();
77 * Read characters into a string until character c is
78 * read. C is put at the end of the string.
80 std::string receiveUpto(char c);
82 * Set the blocking mode of the input stream.
83 * @param mode True if the reader should be blocked waiting for input.
84 * This is the initial default.
86 void setBlocking(bool mode);
89 * Close the input and output streams.
94 * Return the input stream.
96 FILE *inputFile() const { return inputfile; }
99 * Return the output stream.
101 FILE *outputFile() const { return outputfile; }
104 } // namespace externalprogram
107 #endif // ZYPP_EXTERNALDATASOURCE_H