fixup Fix to build with libxml 2.12.x (fixes #505)
[platform/upstream/libzypp.git] / zypp / base / ExternalDataSource.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/ExternalDataSource.h
10  */
11
12 #ifndef ZYPP_EXTERNALDATASOURCE_H
13 #define ZYPP_EXTERNALDATASOURCE_H
14
15 #include <stdio.h>
16
17 #include <string>
18
19 namespace zypp {
20   namespace externalprogram {
21
22     /**
23      * @short Bidirectional stream to external data
24      */
25     class ExternalDataSource
26     {
27     protected:
28       FILE *inputfile;
29       FILE *outputfile;
30
31     private:
32       char *linebuffer;
33       size_t linebuffer_size;
34
35     public:
36       /**
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.
41        */
42       ExternalDataSource(FILE *inputfile = 0, FILE *outputfile = 0);
43
44       /**
45        * Implicitly close the connection.
46        */
47       virtual ~ExternalDataSource();
48
49       /**
50        * Send some data to the output stream.
51        * @param buffer The data to send
52        * @param length The size of it
53        */
54       bool send (const char *buffer, size_t length);
55
56       /**
57        * Send some data down the stream.
58        * @param string The data to send
59        */
60       bool send (std::string s);
61
62       /**
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
67        */
68       size_t receive(char *buffer, size_t length);
69
70       /**
71        * Read one line from the input stream.
72        * Returns the line read, including the terminator.
73        */
74       std::string receiveLine();
75
76       /**
77        * Read characters into a string until character c is
78        * read. C is put at the end of the string.
79        */
80       std::string receiveUpto(char c);
81       /**
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.
85        */
86       void setBlocking(bool mode);
87
88       /**
89        * Close the input and output streams.
90        */
91       virtual int close();
92
93       /**
94        * Return the input stream.
95        */
96       FILE *inputFile() const  { return inputfile; }
97
98       /**
99        * Return the output stream.
100        */
101       FILE *outputFile() const { return outputfile; }
102     };
103
104   } // namespace externalprogram
105 } // namespace zypp
106
107 #endif // ZYPP_EXTERNALDATASOURCE_H
108