Refactoring: Changed all check parameters starting with a 'p' to the new rulespec...
[check_mk.git] / livestatus / src / OutputBuffer.h
blob34f7f477440726ca2471154b60cf1629560bd11a
1 // +------------------------------------------------------------------+
2 // | ____ _ _ __ __ _ __ |
3 // | / ___| |__ ___ ___| | __ | \/ | |/ / |
4 // | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
5 // | | |___| | | | __/ (__| < | | | | . \ |
6 // | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
7 // | |
8 // | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
9 // +------------------------------------------------------------------+
11 // This file is part of Check_MK.
12 // The official homepage is at http://mathias-kettner.de/check_mk.
14 // check_mk is free software; you can redistribute it and/or modify it
15 // under the terms of the GNU General Public License as published by
16 // the Free Software Foundation in version 2. check_mk is distributed
17 // in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
18 // out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19 // PARTICULAR PURPOSE. See the GNU General Public License for more de-
20 // tails. You should have received a copy of the GNU General Public
21 // License along with GNU Make; see the file COPYING. If not, write
22 // to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 // Boston, MA 02110-1301 USA.
25 #ifndef OutputBuffer_h
26 #define OutputBuffer_h
28 #include "config.h" // IWYU pragma: keep
29 #include <sstream>
30 #include <string>
31 class Logger;
33 class OutputBuffer {
34 public:
35 // TODO(sp) Replace this plus its string message with std::error_code
36 enum class ResponseCode {
37 ok = 200,
38 invalid_header = 400,
39 not_found = 404,
40 limit_exceeded = 413,
41 incomplete_request = 451,
42 invalid_request = 452,
45 enum class ResponseHeader { off, fixed16 };
47 OutputBuffer(int fd, const bool &termination_flag, Logger *logger);
48 ~OutputBuffer();
50 bool shouldTerminate() const { return _termination_flag; }
52 std::ostream &os() { return _os; }
54 void setResponseHeader(ResponseHeader r) { _response_header = r; }
56 void setError(ResponseCode code, const std::string &message);
58 Logger *getLogger() const { return _logger; }
60 private:
61 const int _fd;
62 const bool &_termination_flag;
63 Logger *const _logger;
64 std::ostringstream _os;
65 ResponseHeader _response_header;
66 ResponseCode _response_code;
67 std::string _error_message;
69 void flush();
70 void writeData(std::ostringstream &os);
73 #endif // OutputBuffer_h