1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#ifndef CEPH_RGW_FORMATS_H
#define CEPH_RGW_FORMATS_H
#include <list>
#include <stdint.h>
#include <string>
#include "common/Formatter.h"
struct plain_stack_entry {
int size;
bool is_array;
};
/* FIXME: this class is mis-named.
* FIXME: This was a hack to send certain swift messages.
* There is a much better way to do this.
*/
class RGWFormatter_Plain : public Formatter {
public:
RGWFormatter_Plain();
virtual ~RGWFormatter_Plain();
virtual void flush(ostream& os);
virtual void reset();
virtual void open_array_section(const char *name);
virtual void open_array_section_in_ns(const char *name, const char *ns);
virtual void open_object_section(const char *name);
virtual void open_object_section_in_ns(const char *name, const char *ns);
virtual void close_section();
virtual void dump_unsigned(const char *name, uint64_t u);
virtual void dump_int(const char *name, int64_t u);
virtual void dump_float(const char *name, double d);
virtual void dump_string(const char *name, std::string s);
virtual std::ostream& dump_stream(const char *name);
virtual void dump_format(const char *name, const char *fmt, ...);
virtual int get_len() const;
virtual void write_raw_data(const char *data);
private:
void write_data(const char *fmt, ...);
void dump_value_int(const char *name, const char *fmt, ...);
char *buf;
int len;
int max_len;
std::list<struct plain_stack_entry> stack;
size_t min_stack_level;
};
class RGWFormatterFlusher {
protected:
Formatter *formatter;
bool flushed;
bool started;
virtual void do_flush() = 0;
virtual void do_start(int ret) {}
void set_formatter(Formatter *f) {
formatter = f;
}
public:
RGWFormatterFlusher(Formatter *f) : formatter(f), flushed(false), started(false) {}
virtual ~RGWFormatterFlusher() {}
void flush() {
do_flush();
flushed = true;
}
virtual void start(int client_ret) {
if (!started)
do_start(client_ret);
started = true;
}
Formatter *get_formatter() { return formatter; }
bool did_flush() { return flushed; }
bool did_start() { return started; }
};
class RGWStreamFlusher : public RGWFormatterFlusher {
ostream& os;
protected:
virtual void do_flush() {
formatter->flush(os);
}
public:
RGWStreamFlusher(Formatter *f, ostream& _os) : RGWFormatterFlusher(f), os(_os) {}
};
#endif
|