summaryrefslogtreecommitdiff
path: root/cpp/rubygen/templates/Proxy.rb
blob: 41e0cc18823f61fe1881eb7bcad645198887dfb4 (plain)
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
#!/usr/bin/env ruby
$: << ".."                      # Include .. in load path
require 'cppgen'

class ProxyGen < CppGen
    
  def initialize(chassis, outdir, amqp)
    super(outdir, amqp)
    @chassis=chassis
    @classname="AMQP_#{@chassis.caps}Proxy"
    @filename="qpid/framing/#{@classname}"
  end

  def proxy_member(c) c.name.lcaps+"Proxy"; end
  
  def inner_class_decl(c)
    cname=c.name.caps
    cpp_class(cname) {
          gen <<EOS          
ChannelAdapter& channel;

public:
#{cname}(ChannelAdapter& ch) : channel(ch) {}
virtual ~#{cname}() {}

static #{cname}& get(#{@classname}& proxy) { return proxy.get#{cname}(); }

EOS
      c.methods_on(@chassis).each { |m|
        genl "virtual void #{m.cppname}(#{m.signature.join(",\n            ")});"
        genl
      }}
  end

  def inner_class_defn(c)
    cname=c.cppname
    c.methods_on(@chassis).each { |m| 
      genl "void #{@classname}::#{cname}::#{m.cppname}(#{m.signature.join(", ")})"
      scope { 
        params=(["channel.getVersion()"]+m.param_names).join(", ")
        genl "channel.send(#{m.body_name}(#{params}));"
      }}
  end

  def generate
    # .h file
    h_file(@filename) {
      include "qpid/framing/Proxy.h"
      namespace("qpid::framing") { 
        cpp_class(@classname, "public Proxy") {
          public
          genl "#{@classname}(ChannelAdapter& ch);"
          genl
          @amqp.classes.each { |c|
            inner_class_decl(c)
            genl
            genl "#{c.cppname}& get#{c.cppname}() { return #{proxy_member(c)}; }"
            genl 
          }
          private
          @amqp.classes.each{ |c| gen c.cppname+" "+proxy_member(c)+";\n" }
        }}}

  # .cpp file
  cpp_file(@filename) {
      include "<sstream>"
      include "#{@classname}.h"
      include "qpid/framing/ChannelAdapter.h"
      include "qpid/framing/amqp_types_full.h"
      Amqp.methods_on(@chassis).each { |m| include "qpid/framing/"+m.body_name }
      genl
      namespace("qpid::framing") { 
        genl "#{@classname}::#{@classname}(ChannelAdapter& ch) :"
        gen "    Proxy(ch)"
        @amqp.classes.each { |c| gen ",\n    "+proxy_member(c)+"(channel)" }
        genl "{}\n"
        @amqp.classes.each { |c| inner_class_defn(c) }
      }}
   end
end


ProxyGen.new("client", Outdir, Amqp).generate;
ProxyGen.new("server", Outdir, Amqp).generate;