#!/usr/bin/env ruby # # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. # $: << ".." # Include .. in load path require 'cppgen' class ConstantsGen < CppGen def initialize(outdir, amqp) super(outdir, amqp) @namespace="qpid::framing" @dir="qpid/framing" end def constants_h() public_api("#{@dir}/constants.h") h_file("#{@dir}/constants.h") { namespace(@namespace) { # Constants for class/method names. scope("enum AmqpConstant {","};") { l=[] l.concat @amqp.constants.map { |c| "#{c.name.shout}=#{c.value}" } @amqp.classes.each { |c| l << "#{c.name.shout}_CLASS_ID=#{c.code}" l.concat c.methods_.map { |m| "#{c.name.shout}_#{m.name.shout}_METHOD_ID=#{m.code}" } } genl l.join(",\n") } } } end def typecode_enum(t) "TYPE_CODE_#{t.name.shout}" end def typecode_h_cpp path="#{@dir}/TypeCode" public_api(path+".h") h_file(path) { include("") include("\"qpid/sys/IntegerTypes.h\"") namespace(@namespace) { scope("enum TypeCode {", "};") { genl @amqp.types.map { |t| "#{typecode_enum t} = #{t.code}" if t.code }.compact.join(",\n") } genl <") namespace(@namespace) { scope("const char* typeName(TypeCode t) {") { scope("switch (t) {") { @amqp.types.each { |t| genl "case #{typecode_enum t}: return \"#{t.name}\";" if t.code } genl "default: break;" } genl "return 0;"; } genl <" include "" namespace("qpid::framing") { create_exception("execution", "error-code", "SessionException", "InvalidArgumentException") # FIXME aconway 2008-10-07: there are no good exception codes in 0-10 for an invalid code. # The following choices are arbitrary. create_exception("connection", "close-code", "ConnectionException", "FramingErrorException") create_exception("session", "detach-code", "ChannelException", "NotAttachedException") } } end def generate() constants_h enum_h reply_exceptions_h reply_exceptions_cpp typecode_h_cpp end end ConstantsGen.new($outdir, $amqp).generate();