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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
#!/usr/bin/env ruby
# Usage: output_directory xml_spec_file [xml_spec_file...]
#
$: << '..'
require 'cppgen'
class SessionGen < CppGen
def initialize(outdir, amqp)
super(outdir, amqp)
@chassis="server"
@classname="Session"
end
def declare_method (m)
gen "Response #{m.amqp_parent.name.lcaps}#{m.name.caps}("
if (m.content())
params=m.signature + ["const MethodContent& content"]
else
params=m.signature
end
indent { gen params.join(",\n") }
gen ");\n\n"
end
def declare_class(c)
c.amqp_methods_on(@chassis).each { |m| declare_method(m) }
end
def define_method (m)
gen "Response Session::#{m.amqp_parent.name.lcaps}#{m.name.caps}("
if (m.content())
params=m.signature + ["const MethodContent& content"]
else
params=m.signature
end
indent { gen params.join(",\n") }
gen "){\n\n"
indent (2) {
gen "return impl->send(#{m.body_name}("
params = ["version"] + m.param_names
gen params.join(", ")
other_params=[]
if (m.content())
other_params << "content"
end
if m.responses().empty?
other_params << "false"
else
other_params << "true"
end
gen "), #{other_params.join(", ")});\n"
}
gen "}\n\n"
end
def define_class(c)
c.amqp_methods_on(@chassis).each { |m| define_method(m) }
end
def generate()
excludes = ["channel", "connection", "session", "execution"]
h_file("qpid/client/#{@classname}.h") {
gen <<EOS
#include <sstream>
#include "qpid/framing/amqp_framing.h"
#include "qpid/framing/ProtocolVersion.h"
#include "qpid/framing/MethodContent.h"
#include "qpid/client/ConnectionImpl.h"
#include "qpid/client/Response.h"
#include "qpid/client/SessionCore.h"
namespace qpid {
namespace client {
using std::string;
using framing::Content;
using framing::FieldTable;
using framing::MethodContent;
using framing::SequenceNumberSet;
class #{@classname} {
ConnectionImpl::shared_ptr parent;
SessionCore::shared_ptr impl;
framing::ProtocolVersion version;
public:
#{@classname}(ConnectionImpl::shared_ptr, SessionCore::shared_ptr);
~#{@classname}();
ReceivedContent::shared_ptr get() { return impl->get(); }
void setSynchronous(bool sync) { impl->setSync(sync); }
void close();
EOS
indent { @amqp.amqp_classes.each { |c| declare_class(c) if !excludes.include?(c.name) } }
gen <<EOS
}; /* class #{@classname} */
}
}
EOS
}
# .cpp file
cpp_file("qpid/client/#{@classname}.cpp") {
gen <<EOS
#include "#{@classname}.h"
#include "qpid/framing/all_method_bodies.h"
using std::string;
using namespace qpid::framing;
namespace qpid {
namespace client {
#{@classname}::#{@classname}(ConnectionImpl::shared_ptr _parent, SessionCore::shared_ptr _impl) : parent(_parent), impl(_impl) {}
#{@classname}::~#{@classname}()
{
impl->stop();
if (parent) {
parent->released(impl);
parent.reset();
}
}
void #{@classname}::close()
{
impl->close();
if (parent) {
parent->released(impl);
parent.reset();
}
}
EOS
@amqp.amqp_classes.each { |c| define_class(c) if !excludes.include?(c.name) }
gen <<EOS
}} // namespace qpid::client
EOS
}
end
end
SessionGen.new(ARGV[0], Amqp).generate()
|