diff options
| author | Alan Conway <aconway@apache.org> | 2006-10-16 13:50:26 +0000 |
|---|---|---|
| committer | Alan Conway <aconway@apache.org> | 2006-10-16 13:50:26 +0000 |
| commit | 8a6ab3aa61d441b9210c05c84dc9998acfc38737 (patch) | |
| tree | 1eb9d7f39b5c2d04a85a1f66caef3d398567b740 /cpp/etc | |
| parent | 9a808fb13aba243d41bbdab75158dae5939a80a4 (diff) | |
| download | qpid-python-8a6ab3aa61d441b9210c05c84dc9998acfc38737.tar.gz | |
Build system reorg, see README and Makefile comments for details.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@464494 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/etc')
| -rw-r--r-- | cpp/etc/stylesheets/amqp_client.xsl | 155 | ||||
| -rw-r--r-- | cpp/etc/stylesheets/amqp_client_handler_impl.xsl | 187 | ||||
| -rw-r--r-- | cpp/etc/stylesheets/amqp_client_operations.xsl | 105 | ||||
| -rw-r--r-- | cpp/etc/stylesheets/amqp_consts.xsl | 77 | ||||
| -rw-r--r-- | cpp/etc/stylesheets/amqp_server.xsl | 187 | ||||
| -rw-r--r-- | cpp/etc/stylesheets/amqp_server_handler_impl.xsl | 187 | ||||
| -rw-r--r-- | cpp/etc/stylesheets/amqp_server_operations.xsl | 113 | ||||
| -rw-r--r-- | cpp/etc/stylesheets/code_gen.xsl | 91 | ||||
| -rw-r--r-- | cpp/etc/stylesheets/code_utils.xsl | 210 | ||||
| -rw-r--r-- | cpp/etc/stylesheets/convert_0.81.xsl | 407 | ||||
| -rw-r--r-- | cpp/etc/stylesheets/cpp.xsl | 315 | ||||
| -rw-r--r-- | cpp/etc/stylesheets/framing.xsl | 49 | ||||
| -rw-r--r-- | cpp/etc/stylesheets/prepare1.xsl | 104 | ||||
| -rw-r--r-- | cpp/etc/stylesheets/prepare2.xsl | 54 | ||||
| -rw-r--r-- | cpp/etc/stylesheets/prepare3.xsl | 54 | ||||
| -rw-r--r-- | cpp/etc/stylesheets/registry.xsl | 12 | ||||
| -rw-r--r-- | cpp/etc/stylesheets/utils.xsl | 194 |
17 files changed, 2501 insertions, 0 deletions
diff --git a/cpp/etc/stylesheets/amqp_client.xsl b/cpp/etc/stylesheets/amqp_client.xsl new file mode 100644 index 0000000000..4673d44316 --- /dev/null +++ b/cpp/etc/stylesheets/amqp_client.xsl @@ -0,0 +1,155 @@ +<?xml version='1.0'?> +<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amqp="http://amqp.org"> + + <xsl:import href="code_utils.xsl"/> + + <!-- + ================== + Template: client_h + ================== + Client header file. + --> + <xsl:template match="amqp" mode="client_h"> + <xsl:param name="domain-cpp-table"/> + <xsl:result-document href="AMQP_ServerProxy.h" format="textFormat"> + <xsl:value-of select="amqp:copyright()"/> + <xsl:text> +#ifndef _AMQP_ServerProxy_ +#define _AMQP_ServerProxy_ + +#include "AMQP_ServerOperations.h" +#include "qpid/framing/FieldTable.h" +#include "qpid/framing/OutputHandler.h" + +namespace qpid { +namespace framing { + +class AMQP_ServerProxy : virtual public AMQP_ServerOperations +{ + OutputHandler* out; + + public: + AMQP_ServerProxy(OutputHandler* _out); + virtual ~AMQP_ServerProxy() {}

</xsl:text> + <xsl:for-each select="class"> + <xsl:variable name="class" select="amqp:cpp-class-name(@name)"/> + <xsl:if test="doc"> + <xsl:text>
/**
===== Class: </xsl:text><xsl:value-of select="$class"/><xsl:text> =====
</xsl:text> + <xsl:value-of select="amqp:process-docs(doc)"/> + <xsl:text>
*/
</xsl:text> + </xsl:if> + <xsl:text> class </xsl:text><xsl:value-of select="$class"/><xsl:text> : virtual public AMQP_ServerOperations::</xsl:text><xsl:value-of select="$class"/><xsl:text>Handler + { + OutputHandler* out; + + public: + /* Constructors and destructors */ + </xsl:text><xsl:value-of select="$class"/><xsl:text>(OutputHandler* _out); + virtual ~</xsl:text><xsl:value-of select="$class"/><xsl:text>(); + + /* Protocol methods */
</xsl:text> + <xsl:for-each select="method"> + <xsl:if test="chassis[@name='server']"> + <xsl:variable name="method" select="amqp:cpp-name(@name)"/> + <xsl:if test="doc"> + <xsl:text>
/**
----- Method: </xsl:text><xsl:value-of select="$class"/><xsl:text>.</xsl:text><xsl:value-of select="$method"/><xsl:text> -----
</xsl:text> + <xsl:value-of select="amqp:process-docs(doc)"/> + <xsl:text>
*/
</xsl:text> + </xsl:if> + <xsl:for-each select="rule"> + <xsl:text>
/**
</xsl:text> + <xsl:text>Rule "</xsl:text><xsl:value-of select="@name"/><xsl:text>":
</xsl:text><xsl:value-of select="amqp:process-docs(doc)"/> + <xsl:text>
*/
</xsl:text> + </xsl:for-each> + <xsl:text> virtual void </xsl:text><xsl:value-of select="$method"/> + <xsl:text>( u_int16_t channel</xsl:text><xsl:if test="field"><xsl:text>,
 </xsl:text> + <xsl:for-each select="field"> + <xsl:variable name="domain-cpp-type" select="amqp:cpp-lookup(@domain, $domain-cpp-table)"/> + <xsl:value-of select="concat($domain-cpp-type, amqp:cpp-arg-ref($domain-cpp-type), ' ', amqp:cpp-name(@name))"/> + <xsl:if test="position()!=last()"> + <xsl:text>,
 </xsl:text> + </xsl:if> + </xsl:for-each> + </xsl:if> + <xsl:text> );
</xsl:text> + </xsl:if> + </xsl:for-each> + <xsl:text> }; /* class </xsl:text><xsl:value-of select="$class"/><xsl:text> */
</xsl:text> + </xsl:for-each> + <xsl:text>}; /* class AMQP_ServerProxy */ + +} /* namespace framing */ +} /* namespace qpid */ + +#endif
</xsl:text> + </xsl:result-document> + </xsl:template> + + + <!-- + ==================== + Template: client_cpp + ==================== + Client body. + --> + <xsl:template match="amqp" mode="client_cpp"> + <xsl:param name="domain-cpp-table"/> + <xsl:result-document href="AMQP_ServerProxy.cpp" format="textFormat"> + <xsl:value-of select="amqp:copyright()"/> + <xsl:text> + +#include "AMQP_ServerProxy.h" + +namespace qpid { +namespace framing { + +AMQP_ServerProxy::AMQP_ServerProxy(OutputHandler* _out) : + out(_out) +{ +}

</xsl:text> + <xsl:for-each select="class"> + <xsl:variable name="class" select="amqp:cpp-class-name(@name)"/> + <xsl:text>
/* ++++++++++ Class: </xsl:text><xsl:value-of select="$class"/><xsl:text> ++++++++++ */ + +AMQP_ServerProxy::</xsl:text><xsl:value-of select="$class"/><xsl:text>::</xsl:text><xsl:value-of select="$class"/><xsl:text>(OutputHandler* _out) : + out(_out) +{ +} + +AMQP_ServerProxy::</xsl:text><xsl:value-of select="$class"/><xsl:text>::~</xsl:text><xsl:value-of select="$class"/><xsl:text>() {}

</xsl:text> + <xsl:for-each select="method"> + <xsl:if test="chassis[@name='server']"> + <xsl:text>void AMQP_ServerProxy::</xsl:text><xsl:value-of select="$class"/><xsl:text>::</xsl:text> + <xsl:value-of select="amqp:cpp-name(@name)"/><xsl:text>( u_int16_t channel</xsl:text><xsl:if test="field"> + <xsl:text>,
 </xsl:text> + <xsl:for-each select="field"> + <xsl:variable name="domain-cpp-type" select="amqp:cpp-lookup(@domain, $domain-cpp-table)"/> + <xsl:value-of select="concat($domain-cpp-type, amqp:cpp-arg-ref($domain-cpp-type), ' ', amqp:cpp-name(@name))"/> + <xsl:if test="position()!=last()"> + <xsl:text>,
 </xsl:text> + </xsl:if> + </xsl:for-each> + </xsl:if> + <xsl:text> ) +{ + out->send( new AMQFrame( channel, + new </xsl:text><xsl:value-of select="concat($class, amqp:field-name(@name), 'Body')"/><xsl:text>( </xsl:text> + <xsl:for-each select="field"> + <xsl:value-of select="amqp:cpp-name(@name)"/> + <xsl:if test="position()!=last()"> + <xsl:text>,
 </xsl:text> + </xsl:if> + </xsl:for-each> + <xsl:text> ) ) ); +}

</xsl:text> + </xsl:if> + </xsl:for-each> + </xsl:for-each> + <xsl:text> + +} /* namespace framing */ +} /* namespace qpid */
</xsl:text> + </xsl:result-document> + </xsl:template> + +</xsl:stylesheet> diff --git a/cpp/etc/stylesheets/amqp_client_handler_impl.xsl b/cpp/etc/stylesheets/amqp_client_handler_impl.xsl new file mode 100644 index 0000000000..cc636ea846 --- /dev/null +++ b/cpp/etc/stylesheets/amqp_client_handler_impl.xsl @@ -0,0 +1,187 @@ +<?xml version='1.0'?> +<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amqp="http://amqp.org"> + + <xsl:import href="code_utils.xsl"/> + + <!-- + =============================== + Template: client_handler_impl_h + =============================== + Template to generate the AMQP_ClientHandlerImpl class header file. + --> + <xsl:template match="amqp" mode="client_handler_impl_h"> + <xsl:param name="domain-cpp-table"/> + <xsl:result-document href="AMQP_ClientHandlerImpl.h" format="textFormat"> + <xsl:value-of select="amqp:copyright()"/> + <xsl:text> +#ifndef _AMQP_ClientHandlerImpl_ +#define _AMQP_ClientHandlerImpl_ + +#include "AMQP_ClientOperations.h" +#include "qpid/framing/FieldTable.h" + +namespace qpid { +namespace framing { + +class AMQP_ClientHandlerImpl : virtual public AMQP_ClientOperations +{
</xsl:text> + + <!-- List of pointers to each inner class instance --> + <xsl:for-each select="class"> + <xsl:variable name="class" select="concat(amqp:cpp-class-name(@name), 'Handler')"/> + <xsl:text> AMQP_ClientOperations::</xsl:text><xsl:value-of select="$class"/><xsl:text>* </xsl:text> + <xsl:value-of select="$class"/><xsl:text>Ptr;
</xsl:text> + </xsl:for-each> + <xsl:text> + public: + AMQP_ClientHandlerImpl(); + virtual ~AMQP_ClientHandlerImpl();

</xsl:text> + + <!-- List of functions to return pointer to each inner class instance --> + <xsl:for-each select="class"> + <xsl:variable name="class" select="concat(amqp:cpp-class-name(@name), 'Handler')"/> + <xsl:text> inline AMQP_ClientOperations::</xsl:text> + <xsl:value-of select="$class"/><xsl:text>* get</xsl:text><xsl:value-of select="$class"/> + <xsl:text>() { return </xsl:text><xsl:value-of select="$class"/><xsl:text>Ptr; }
</xsl:text> + </xsl:for-each> + <xsl:text>
</xsl:text> + + <!-- Inner classes --> + <xsl:for-each select="class"> + <xsl:variable name="class" select="concat(amqp:cpp-class-name(@name), 'Handler')"/> + + <!-- Inner class documentation & rules --> + <xsl:if test="doc"> + <xsl:text>
/**
</xsl:text> + <xsl:text>===== Class: </xsl:text><xsl:value-of select="$class"/><xsl:text>Impl =====
</xsl:text> + <xsl:value-of select="amqp:process-docs(doc)"/> + <xsl:text>*/
</xsl:text> + </xsl:if> + + <!-- Inner class definition --> + <xsl:text> class </xsl:text><xsl:value-of select="$class"/> + <xsl:text>Impl : virtual public AMQP_ClientOperations::</xsl:text><xsl:value-of select="$class"/> + <xsl:text>
 { + public: + /* Constructors and destructors */ + </xsl:text><xsl:value-of select="$class"/><xsl:text>Impl(); + virtual ~</xsl:text><xsl:value-of select="$class"/><xsl:text>Impl(); + + /* Protocol methods */
</xsl:text> + + <!-- Inner class methods (only if the chassis is set to "client") --> + <xsl:for-each select="method"> + <xsl:if test="chassis[@name='client']"> + <xsl:variable name="method" select="amqp:cpp-name(@name)"/> + + <!-- Inner class method documentation & rules --> + <xsl:if test="doc"> + <xsl:text>
/**
</xsl:text> + <xsl:text>----- Method: </xsl:text><xsl:value-of select="$class"/> + <xsl:text>Impl.</xsl:text><xsl:value-of select="@name"/><xsl:text> -----
</xsl:text> + <xsl:value-of select="amqp:process-docs(doc)"/> + <xsl:text>*/
</xsl:text> + </xsl:if> + <xsl:for-each select="rule"> + <xsl:text>
/**
</xsl:text> + <xsl:text>Rule "</xsl:text><xsl:value-of select="@name"/><xsl:text>":
</xsl:text> + <xsl:value-of select="amqp:process-docs(doc)"/> + <xsl:text>*/
</xsl:text> + </xsl:for-each> + + <!-- Inner class method definition --> + <xsl:text>
 virtual void </xsl:text><xsl:value-of select="$method"/> + <xsl:text>( u_int16_t channel</xsl:text> + + <!-- Inner class method parameter definition --> + <xsl:if test="field"> + <xsl:text>,
 </xsl:text> + <xsl:for-each select="field"> + <xsl:variable name="domain-cpp-type" select="amqp:cpp-lookup(@domain, $domain-cpp-table)"/> + <xsl:value-of select="concat($domain-cpp-type, amqp:cpp-arg-ref($domain-cpp-type), ' ', amqp:cpp-name(@name))"/> + <xsl:if test="position()!=last()"> + <xsl:text>,
 </xsl:text> + </xsl:if> + </xsl:for-each> + </xsl:if> + <xsl:text> );
</xsl:text> + </xsl:if> + </xsl:for-each> + <xsl:text>
 }; /* class </xsl:text><xsl:value-of select="$class"/><xsl:text>Impl */
</xsl:text> + </xsl:for-each> + <xsl:text>
}; /* AMQP_ClientHandlerImpl */ + +} /* namespace framing */ +} /* namespace qpid */ + +#endif
</xsl:text> + </xsl:result-document> + </xsl:template> + + <!-- + ================================= + Template: client_handler_impl_cpp + ================================= + Template to generate the AMQP_ClientHandlerImpl class stubs. + --> + <xsl:template match="amqp" mode="client_handler_impl_cpp"> + <xsl:param name="domain-cpp-table"/> + <xsl:result-document href="AMQP_ClientHandlerImpl.cpp" format="textFormat"> + <xsl:value-of select="amqp:copyright()"/> + <xsl:text> +#include "AMQP_ClientHandlerImpl.h" + +namespace qpid { +namespace framing { + +AMQP_ClientHandlerImpl::AMQP_ClientHandlerImpl() :
 </xsl:text> + <xsl:for-each select="class"> + <xsl:variable name="class" select="amqp:cpp-class-name(@name)"/> + <xsl:value-of select="$class"/> + <xsl:text>HandlerPtr( new </xsl:text><xsl:value-of select="$class"/><xsl:text>HandlerImpl() )</xsl:text> + <xsl:if test="position()!=last()"> + <xsl:text>,
 </xsl:text> + </xsl:if> + </xsl:for-each> + <xsl:text> +{ +} + +AMQP_ClientHandlerImpl::~AMQP_ClientHandlerImpl() +{
</xsl:text> + <xsl:for-each select="class"> + <xsl:text> delete </xsl:text><xsl:value-of select="amqp:cpp-class-name(@name)"/><xsl:text>HandlerPtr;
</xsl:text> + </xsl:for-each>} + + <xsl:for-each select="class"> + <xsl:variable name="class" select="amqp:cpp-class-name(@name)"/> + <xsl:text>
/* ===== Class: </xsl:text><xsl:value-of select="$class"/><xsl:text>HandlerImpl ===== */

</xsl:text> + <xsl:text>AMQP_ClientHandlerImpl::</xsl:text><xsl:value-of select="$class"/><xsl:text>HandlerImpl::</xsl:text> + <xsl:value-of select="$class"/><xsl:text>HandlerImpl()
{
}

</xsl:text> + <xsl:text>AMQP_ClientHandlerImpl::</xsl:text><xsl:value-of select="$class"/><xsl:text>HandlerImpl::~</xsl:text> + <xsl:value-of select="$class"/><xsl:text>HandlerImpl()
{
}

</xsl:text> + <xsl:for-each select="method"> + <xsl:if test="chassis[@name='client']"> + <xsl:text>void AMQP_ClientHandlerImpl::</xsl:text><xsl:value-of select="$class"/><xsl:text>HandlerImpl::</xsl:text> + <xsl:value-of select="amqp:cpp-name(@name)"/><xsl:text>( u_int16_t /*channel*/</xsl:text> + <xsl:if test="field"> + <xsl:text>,
 </xsl:text> + <xsl:for-each select="field"> + <xsl:variable name="domain-cpp-type" select="amqp:cpp-lookup(@domain, $domain-cpp-table)"/> + <xsl:value-of select="concat($domain-cpp-type, amqp:cpp-arg-ref($domain-cpp-type), ' /*', amqp:cpp-name(@name), '*/')"/> + <xsl:if test="position()!=last()"> + <xsl:text>,
 </xsl:text> + </xsl:if> + </xsl:for-each> + </xsl:if><xsl:text> )
{
}

</xsl:text> + </xsl:if> + </xsl:for-each> + </xsl:for-each> + <xsl:text> + +} /* namespace framing */ +} /* namespace qpid */

</xsl:text> + </xsl:result-document> + </xsl:template> + +</xsl:stylesheet> diff --git a/cpp/etc/stylesheets/amqp_client_operations.xsl b/cpp/etc/stylesheets/amqp_client_operations.xsl new file mode 100644 index 0000000000..ee87cac56a --- /dev/null +++ b/cpp/etc/stylesheets/amqp_client_operations.xsl @@ -0,0 +1,105 @@ +<?xml version='1.0'?> +<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amqp="http://amqp.org"> + + <xsl:import href="code_utils.xsl"/> + + <!-- + ============================= + Template: client-operations-h + ============================= + Template to generate the AMQP_ClientHandler virtual class. This is the pure + virtual class from which the AMQP_Server and AMQP_ClientHandlerImpl classes + are derived. + --> + <xsl:template match="amqp" mode="client-operations-h"> + <xsl:param name="domain-cpp-table"/> + <xsl:result-document href="AMQP_ClientOperations.h" format="textFormat"> + <xsl:value-of select="amqp:copyright()"/> + <xsl:text> +#ifndef _AMQP_ClientOperations_ +#define _AMQP_ClientOperations_ + +#include "AMQP_Constants.h" +#include "qpid/framing/FieldTable.h" + +namespace qpid { +namespace framing { + +class AMQP_ClientOperations +{ + public: + AMQP_ClientOperations() {} + virtual ~AMQP_ClientOperations() {} + inline u_int16_t getAmqpMajor() { return (u_int16_t)</xsl:text><xsl:value-of select="@major"/><xsl:text>; } + inline u_int16_t getAmqpMinor() { return (u_int16_t)</xsl:text><xsl:value-of select="@minor"/><xsl:text>; }

</xsl:text> + + <!-- Inner classes --> + <xsl:for-each select="class"> + <xsl:variable name="class" select="concat(amqp:cpp-class-name(@name), 'Handler')"/> + + <!-- Inner class documentation & rules --> + <xsl:if test="doc"> + <xsl:text>
/**
===== Class: </xsl:text><xsl:value-of select="$class"/><xsl:text> =====
</xsl:text> + <xsl:value-of select="amqp:process-docs(doc)"/> + <xsl:text>*/
</xsl:text> + </xsl:if> + + <!-- Inner class definition --> + <xsl:text> class </xsl:text><xsl:value-of select="$class"/><xsl:text> + { + public: + /* Constructors and destructors */ + </xsl:text><xsl:value-of select="$class"/><xsl:text>() {} + virtual ~</xsl:text><xsl:value-of select="$class"/><xsl:text>() {} + + /* Protocol methods */
</xsl:text> + + <!-- Inner class methods (only if the chassis is set to "client") --> + <xsl:for-each select="method"> + <xsl:if test="chassis[@name='client']"> + <xsl:variable name="method" select="amqp:cpp-name(@name)"/> + + <!-- Inner class method documentation & rules --> + <xsl:if test="doc"> + <xsl:text>
/**
----- Method: </xsl:text><xsl:value-of select="$class"/><xsl:text>.</xsl:text> + <xsl:value-of select="@name"/><xsl:text> -----
</xsl:text> + <xsl:value-of select="amqp:process-docs(doc)"/> + <xsl:text>*/
</xsl:text> + </xsl:if> + <xsl:for-each select="rule"> + <xsl:text>
/**
</xsl:text> + <xsl:text>Rule "</xsl:text><xsl:value-of select="@name"/><xsl:text>":
</xsl:text> + <xsl:value-of select="amqp:process-docs(doc)"/> + <xsl:text>*/
</xsl:text> + </xsl:for-each> + + <!-- Inner class method definition --> + <xsl:text> virtual void </xsl:text><xsl:value-of select="$method"/> + <xsl:text>( u_int16_t channel</xsl:text> + + <!-- Inner class method parameter definition --> + <xsl:if test="field"> + <xsl:text>,
 </xsl:text> + <xsl:for-each select="field"> + <xsl:variable name="domain-cpp-type" select="amqp:cpp-lookup(@domain, $domain-cpp-table)"/> + <xsl:value-of select="concat($domain-cpp-type, amqp:cpp-arg-ref($domain-cpp-type), ' ', amqp:cpp-name(@name))"/> + <xsl:if test="position()!=last()"> + <xsl:text>,
 </xsl:text> + </xsl:if> + </xsl:for-each> + </xsl:if> + <xsl:text> ) = 0;
</xsl:text> + </xsl:if> + </xsl:for-each> + <xsl:text>
 }; /* class </xsl:text><xsl:value-of select="$class"/><xsl:text> */
</xsl:text> + </xsl:for-each> + <xsl:text>
}; /* class AMQP_ClientOperations */ + +} /* namespace framing */ +} /* namespace qpid */ + +#endif
</xsl:text> + </xsl:result-document> + </xsl:template> + +</xsl:stylesheet> diff --git a/cpp/etc/stylesheets/amqp_consts.xsl b/cpp/etc/stylesheets/amqp_consts.xsl new file mode 100644 index 0000000000..783f9f5271 --- /dev/null +++ b/cpp/etc/stylesheets/amqp_consts.xsl @@ -0,0 +1,77 @@ +<?xml version='1.0'?> +<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amqp="http://amqp.org"> + + <xsl:import href="code_utils.xsl"/> + <xsl:output method="text" indent="yes" name="textFormat"/> + + <xsl:template match="/"> + <xsl:apply-templates select="amqp" mode="domain-table"/> + <xsl:apply-templates select="amqp" mode="domain-consts"/> + </xsl:template> + + <!-- + ====================== + Template: domain-table + ====================== + Generates the domain name to C++ type lookup table + which is required for later generation. + Format: + <domains> + <domain doamin-name="dname1" cpp-type="type1"/> + <domain doamin-name="dname2" cpp-type="type2"/> + ... + </domains> + --> + <xsl:template match="amqp" mode="domain-table"> + <domains><xsl:text>
</xsl:text> + <xsl:for-each select="domain"> + <xsl:text> </xsl:text><domain> + <xsl:attribute name="domain-name"> + <xsl:value-of select="@name"/> + </xsl:attribute> + <xsl:attribute name="cpp-type"> + <xsl:value-of select="amqp:cpp-type(@type)"/> + </xsl:attribute> + </domain><xsl:text>
</xsl:text> + </xsl:for-each> + </domains> + </xsl:template> + + <!-- + ======================= + Template: domain-consts + ======================= + Generates a header file (AMQP_Constants.h) containing definitions of + all the <constant> declarations in the AMQP XML specification. + --> + <xsl:template match="amqp" mode="domain-consts"> + <xsl:result-document href="AMQP_Constants.h" format="textFormat"> + <xsl:value-of select="amqp:copyright()"/> + <xsl:text> +#ifndef _AMQP_Constants_ +#define _AMQP_Constants_ + +#include "qpid/framing/amqp_types.h" + +namespace qpid { +namespace framing { + +/**** Constants ****/

</xsl:text> + <xsl:for-each select="constant"> + <xsl:if test="doc"> + <xsl:text>
/*
</xsl:text> + <xsl:value-of select="normalize-space(doc)"/> + <xsl:text>
*/
</xsl:text> + </xsl:if> + <xsl:text>const u_int16_t </xsl:text><xsl:value-of select="concat('AMQP_', upper-case(amqp:cpp-name(@name)), ' = ', @value)"/><xsl:text>;
</xsl:text> + </xsl:for-each> + <xsl:text> + +} /* namespace framing */ +} /* namespace qpid */ + +#endif
</xsl:text> + </xsl:result-document> + </xsl:template> + +</xsl:stylesheet> diff --git a/cpp/etc/stylesheets/amqp_server.xsl b/cpp/etc/stylesheets/amqp_server.xsl new file mode 100644 index 0000000000..ee50d7f331 --- /dev/null +++ b/cpp/etc/stylesheets/amqp_server.xsl @@ -0,0 +1,187 @@ +<?xml version='1.0'?> +<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amqp="http://amqp.org"> + + <xsl:import href="code_utils.xsl"/> + + <!-- + ================== + Template: server_h + ================== + Server header file. + --> + <xsl:template match="amqp" mode="server_h"> + <xsl:param name="domain-cpp-table"/> + <xsl:result-document href="AMQP_ClientProxy.h" format="textFormat"> + <xsl:value-of select="amqp:copyright()"/> +#ifndef _AMQP_ClientProxy_ +#define _AMQP_ClientProxy_ + +#include "AMQP_ClientOperations.h" +#include "qpid/framing/FieldTable.h" +#include "qpid/framing/OutputHandler.h" + +namespace qpid { +namespace framing { + +class AMQP_ClientProxy : virtual public AMQP_ClientOperations +{ + public: + + AMQP_ClientProxy(OutputHandler* _out); + virtual ~AMQP_ClientProxy() {}; + + <!-- inner classes --> + <xsl:for-each select="class"> + <xsl:variable name="class" select="amqp:cpp-class-name(@name)"/> + <xsl:if test="doc"> + <xsl:text>
/**
===== Class: </xsl:text><xsl:value-of select="$class"/><xsl:text> =====
</xsl:text> + <xsl:value-of select="amqp:process-docs(doc)"/> + <xsl:text>
*/
</xsl:text> + </xsl:if> + <xsl:text> class </xsl:text><xsl:value-of select="$class"/><xsl:text> : virtual public AMQP_ClientOperations::</xsl:text><xsl:value-of select="$class"/><xsl:text>Handler + { + OutputHandler* out; + + public: + /* Constructors and destructors */ + </xsl:text><xsl:value-of select="$class"/><xsl:text>(OutputHandler* _out); + virtual ~</xsl:text><xsl:value-of select="$class"/><xsl:text>(); + + /* Protocol methods */
</xsl:text> + <xsl:for-each select="method"> + <xsl:if test="chassis[@name='client']"> + <xsl:variable name="method" select="amqp:cpp-name(@name)"/> + <xsl:if test="doc"> + <xsl:text>
/**
----- Method: </xsl:text><xsl:value-of select="$class"/><xsl:text>.</xsl:text><xsl:value-of select="$method"/><xsl:text> -----
</xsl:text> + <xsl:value-of select="amqp:process-docs(doc)"/> + <xsl:text>
*/
</xsl:text> + </xsl:if> + <xsl:for-each select="rule"> + <xsl:text>
/**
</xsl:text> + <xsl:text>Rule "</xsl:text><xsl:value-of select="@name"/><xsl:text>":
</xsl:text><xsl:value-of select="amqp:process-docs(doc)"/> + <xsl:text>
*/
</xsl:text> + </xsl:for-each> + <xsl:text> virtual void </xsl:text><xsl:value-of select="$method"/> + <xsl:text>( u_int16_t channel</xsl:text><xsl:if test="field"><xsl:text>,
 </xsl:text> + <xsl:for-each select="field"> + <xsl:variable name="domain-cpp-type" select="amqp:cpp-lookup(@domain, $domain-cpp-table)"/> + <xsl:value-of select="concat($domain-cpp-type, amqp:cpp-arg-ref($domain-cpp-type), ' ', amqp:cpp-name(@name))"/> + <xsl:if test="position()!=last()"> + <xsl:text>,
 </xsl:text> + </xsl:if> + </xsl:for-each> + </xsl:if> + <xsl:text> );
</xsl:text> + </xsl:if> + </xsl:for-each> + <xsl:text> }; /* class </xsl:text><xsl:value-of select="$class"/> */ + </xsl:for-each> + + <!-- Accessors for each nested class instance --> + <xsl:for-each select="class"> + <xsl:value-of select="concat(amqp:cpp-class-name(@name), '& get', amqp:cpp-class-name(@name), '()')"/>; + </xsl:for-each> + + private: + + OutputHandler* out; + + <!-- An instance of each nested class --> + <xsl:for-each select="class"> + <xsl:value-of select="concat(amqp:cpp-class-name(@name), ' ', amqp:cpp-name(@name))"/>; + </xsl:for-each> + + + + }; /* class AMQP_ClientProxy */ + +} /* namespace framing */ +} /* namespace qpid */ + +#endif +</xsl:result-document> + </xsl:template> + + + <!-- + ==================== + Template: server_cpp + ==================== + Server body. + --> + <xsl:template match="amqp" mode="server_cpp"> + <xsl:param name="domain-cpp-table"/> + <xsl:result-document href="AMQP_ClientProxy.cpp" format="textFormat"> + <xsl:value-of select="amqp:copyright()"/> + +#include "AMQP_ClientProxy.h" + +namespace qpid { +namespace framing { + +AMQP_ClientProxy::AMQP_ClientProxy(OutputHandler* _out) : + out(_out), + <!-- Initialisation of each nested class instance --> + <xsl:for-each select="class"> + <xsl:value-of select="concat(amqp:cpp-name(@name), '(_out)')"/> + <xsl:if test="position()!=last()">, + </xsl:if> + </xsl:for-each> + +{ +} + + <xsl:for-each select="class"> + <xsl:variable name="class" select="amqp:cpp-class-name(@name)"/> + <xsl:text>
/* ++++++++++ Class: </xsl:text><xsl:value-of select="$class"/><xsl:text> ++++++++++ */ + +AMQP_ClientProxy::</xsl:text><xsl:value-of select="$class"/><xsl:text>::</xsl:text><xsl:value-of select="$class"/><xsl:text>(OutputHandler* _out) : + out(_out) +{ +} + +AMQP_ClientProxy::</xsl:text><xsl:value-of select="$class"/><xsl:text>::~</xsl:text><xsl:value-of select="$class"/><xsl:text>() {}

</xsl:text> + <xsl:for-each select="method"> + <xsl:if test="chassis[@name='client']"> + <xsl:text>void AMQP_ClientProxy::</xsl:text><xsl:value-of select="$class"/><xsl:text>::</xsl:text> + <xsl:value-of select="amqp:cpp-name(@name)"/><xsl:text>( u_int16_t channel</xsl:text><xsl:if test="field"> + <xsl:text>,
 </xsl:text> + <xsl:for-each select="field"> + <xsl:variable name="domain-cpp-type" select="amqp:cpp-lookup(@domain, $domain-cpp-table)"/> + <xsl:value-of select="concat($domain-cpp-type, amqp:cpp-arg-ref($domain-cpp-type), ' ', amqp:cpp-name(@name))"/> + <xsl:if test="position()!=last()"> + <xsl:text>,
 </xsl:text> + </xsl:if> + </xsl:for-each> + </xsl:if> + <xsl:text> ) +{ + out->send( new AMQFrame( channel, + new </xsl:text><xsl:value-of select="concat($class, amqp:field-name(@name), 'Body')"/><xsl:text>( </xsl:text> + <xsl:for-each select="field"> + <xsl:value-of select="amqp:cpp-name(@name)"/> + <xsl:if test="position()!=last()"> + <xsl:text>,
 </xsl:text> + </xsl:if> + </xsl:for-each> + <xsl:text> ) ) ); +}

</xsl:text> + </xsl:if> + </xsl:for-each> + </xsl:for-each> + + <!-- Accessors for each nested class instance --> + <xsl:for-each select="class"> + <xsl:value-of select="concat('AMQP_ClientProxy::', amqp:cpp-class-name(@name), '& AMQP_ClientProxy::get', amqp:cpp-class-name(@name), '()')"/>{ + <xsl:value-of select="concat(' return ', amqp:cpp-name(@name))"/>; + } + + </xsl:for-each> + + <xsl:text> +} /* namespace framing */ +} /* namespace qpid */
</xsl:text> + </xsl:result-document> + </xsl:template> + +</xsl:stylesheet> diff --git a/cpp/etc/stylesheets/amqp_server_handler_impl.xsl b/cpp/etc/stylesheets/amqp_server_handler_impl.xsl new file mode 100644 index 0000000000..c55e3f7cd1 --- /dev/null +++ b/cpp/etc/stylesheets/amqp_server_handler_impl.xsl @@ -0,0 +1,187 @@ +<?xml version='1.0'?> +<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amqp="http://amqp.org"> + + <xsl:import href="code_utils.xsl"/> + + <!-- + =============================== + Template: server_handler_impl_h + =============================== + Template to generate the AMQP_ServerHandlerImpl class header file. + --> + <xsl:template match="amqp" mode="server_handler_impl_h"> + <xsl:param name="domain-cpp-table"/> + <xsl:result-document href="AMQP_ServerHandlerImpl.h" format="textFormat"> + <xsl:value-of select="amqp:copyright()"/> + <xsl:text> +#ifndef _AMQP_ServerHandlerImpl_ +#define _AMQP_ServerHandlerImpl_ + +#include "AMQP_ServerOperations.h" +#include "qpid/framing/FieldTable.h" + +namespace qpid { +namespace framing { + +class AMQP_ServerHandlerImpl : virtual public AMQP_ServerOperations +{
</xsl:text> + + <!-- List of pointers to each inner class instance --> + <xsl:for-each select="class"> + <xsl:variable name="class" select="concat(amqp:cpp-class-name(@name), 'Handler')"/> + <xsl:text> AMQP_ServerOperations::</xsl:text><xsl:value-of select="$class"/><xsl:text>* </xsl:text> + <xsl:value-of select="$class"/><xsl:text>Ptr;
</xsl:text> + </xsl:for-each> + <xsl:text> + public: + AMQP_ServerHandlerImpl(); + virtual ~AMQP_ServerHandlerImpl();

</xsl:text> + + <!-- List of functions to return pointer to each inner class instance --> + <xsl:for-each select="class"> + <xsl:variable name="class" select="concat(amqp:cpp-class-name(@name), 'Handler')"/> + <xsl:text> virtual inline AMQP_ServerOperations::</xsl:text> + <xsl:value-of select="$class"/><xsl:text>* get</xsl:text><xsl:value-of select="$class"/> + <xsl:text>() { return </xsl:text><xsl:value-of select="$class"/><xsl:text>Ptr; }
</xsl:text> + </xsl:for-each> + <xsl:text>
</xsl:text> + + <!-- Inner classes --> + <xsl:for-each select="class"> + <xsl:variable name="class" select="concat(amqp:cpp-class-name(@name), 'Handler')"/> + + <!-- Inner class documentation & rules --> + <xsl:if test="doc"> + <xsl:text>
/**
</xsl:text> + <xsl:text>===== Class: </xsl:text><xsl:value-of select="$class"/><xsl:text>Impl =====
</xsl:text> + <xsl:value-of select="amqp:process-docs(doc)"/> + <xsl:text>*/
</xsl:text> + </xsl:if> + + <!-- Inner class definition --> + <xsl:text> class </xsl:text><xsl:value-of select="$class"/> + <xsl:text>Impl : virtual public AMQP_ServerOperations::</xsl:text><xsl:value-of select="$class"/> + <xsl:text>
 { + public: + /* Constructors and destructors */ + </xsl:text><xsl:value-of select="$class"/><xsl:text>Impl(); + virtual ~</xsl:text><xsl:value-of select="$class"/><xsl:text>Impl(); + + /* Protocol methods */
</xsl:text> + + <!-- Inner class methods (only if the chassis is set to "server") --> + <xsl:for-each select="method"> + <xsl:if test="chassis[@name='server']"> + <xsl:variable name="method" select="amqp:cpp-name(@name)"/> + + <!-- Inner class method documentation & rules --> + <xsl:if test="doc"> + <xsl:text>
/**
</xsl:text> + <xsl:text>----- Method: </xsl:text><xsl:value-of select="$class"/> + <xsl:text>Impl.</xsl:text><xsl:value-of select="@name"/><xsl:text> -----
</xsl:text> + <xsl:value-of select="amqp:process-docs(doc)"/> + <xsl:text>*/
</xsl:text> + </xsl:if> + <xsl:for-each select="rule"> + <xsl:text>
/**
</xsl:text> + <xsl:text>Rule "</xsl:text><xsl:value-of select="@name"/><xsl:text>":
</xsl:text> + <xsl:value-of select="amqp:process-docs(doc)"/> + <xsl:text>*/
</xsl:text> + </xsl:for-each> + + <!-- Inner class method definition --> + <xsl:text>
 virtual void </xsl:text><xsl:value-of select="$method"/> + <xsl:text>( u_int16_t channel</xsl:text> + + <!-- Inner class method parameter definition --> + <xsl:if test="field"> + <xsl:text>,
 </xsl:text> + <xsl:for-each select="field"> + <xsl:variable name="domain-cpp-type" select="amqp:cpp-lookup(@domain, $domain-cpp-table)"/> + <xsl:value-of select="concat($domain-cpp-type, amqp:cpp-arg-ref($domain-cpp-type), ' ', amqp:cpp-name(@name))"/> + <xsl:if test="position()!=last()"> + <xsl:text>,
 </xsl:text> + </xsl:if> + </xsl:for-each> + </xsl:if> + <xsl:text> );
</xsl:text> + </xsl:if> + </xsl:for-each> + <xsl:text>
 }; /* class </xsl:text><xsl:value-of select="$class"/><xsl:text>Impl */
</xsl:text> + </xsl:for-each> + <xsl:text>
}; /* AMQP_ServerHandlerImpl */ + +} /* namespace framing */ +} /* namespace qpid */ + +#endif
</xsl:text> + </xsl:result-document> + </xsl:template> + + <!-- + ================================= + Template: server_handler_impl_cpp + ================================= + Template to generate the AMQP_ServerHandlerImpl class stubs. + --> + <xsl:template match="amqp" mode="server_handler_impl_cpp"> + <xsl:param name="domain-cpp-table"/> + <xsl:result-document href="AMQP_ServerHandlerImpl.cpp" format="textFormat"> + <xsl:value-of select="amqp:copyright()"/> + <xsl:text> +#include "AMQP_ServerHandlerImpl.h" + +namespace qpid { +namespace framing { + +AMQP_ServerHandlerImpl::AMQP_ServerHandlerImpl() :
 </xsl:text> + <xsl:for-each select="class"> + <xsl:variable name="class" select="amqp:cpp-class-name(@name)"/> + <xsl:value-of select="$class"/> + <xsl:text>HandlerPtr( new </xsl:text><xsl:value-of select="$class"/><xsl:text>HandlerImpl() )</xsl:text> + <xsl:if test="position()!=last()"> + <xsl:text>,
 </xsl:text> + </xsl:if> + </xsl:for-each> + <xsl:text> +{ +} + +AMQP_ServerHandlerImpl::~AMQP_ServerHandlerImpl() +{
</xsl:text> + <xsl:for-each select="class"> + <xsl:text> delete </xsl:text><xsl:value-of select="amqp:cpp-class-name(@name)"/><xsl:text>HandlerPtr;
</xsl:text> + </xsl:for-each>} + + <xsl:for-each select="class"> + <xsl:variable name="class" select="amqp:cpp-class-name(@name)"/> + <xsl:text>
/* ===== Class: </xsl:text><xsl:value-of select="$class"/><xsl:text>HandlerImpl ===== */

</xsl:text> + <xsl:text>AMQP_ServerHandlerImpl::</xsl:text><xsl:value-of select="$class"/><xsl:text>HandlerImpl::</xsl:text> + <xsl:value-of select="$class"/><xsl:text>HandlerImpl()
{
}

</xsl:text> + <xsl:text>AMQP_ServerHandlerImpl::</xsl:text><xsl:value-of select="$class"/><xsl:text>HandlerImpl::~</xsl:text> + <xsl:value-of select="$class"/><xsl:text>HandlerImpl()
{
}

</xsl:text> + <xsl:for-each select="method"> + <xsl:if test="chassis[@name='server']"> + <xsl:text>void AMQP_ServerHandlerImpl::</xsl:text><xsl:value-of select="$class"/><xsl:text>HandlerImpl::</xsl:text> + <xsl:value-of select="amqp:cpp-name(@name)"/><xsl:text>( u_int16_t /*channel*/</xsl:text> + <xsl:if test="field"> + <xsl:text>,
 </xsl:text> + <xsl:for-each select="field"> + <xsl:variable name="domain-cpp-type" select="amqp:cpp-lookup(@domain, $domain-cpp-table)"/> + <xsl:value-of select="concat($domain-cpp-type, amqp:cpp-arg-ref($domain-cpp-type), ' /*', amqp:cpp-name(@name), '*/')"/> + <xsl:if test="position()!=last()"> + <xsl:text>,
 </xsl:text> + </xsl:if> + </xsl:for-each> + </xsl:if><xsl:text> )
{
}

</xsl:text> + </xsl:if> + </xsl:for-each> + </xsl:for-each> + <xsl:text> + +} /* namespace framing */ +} /* namespace qpid */

</xsl:text> + </xsl:result-document> + </xsl:template> + +</xsl:stylesheet> diff --git a/cpp/etc/stylesheets/amqp_server_operations.xsl b/cpp/etc/stylesheets/amqp_server_operations.xsl new file mode 100644 index 0000000000..aad474295c --- /dev/null +++ b/cpp/etc/stylesheets/amqp_server_operations.xsl @@ -0,0 +1,113 @@ +<?xml version='1.0'?> +<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amqp="http://amqp.org"> + + <xsl:import href="code_utils.xsl"/> + + <!-- + ============================= + Template: server-operations-h + ============================= + Template to generate the AMQP_ServerHandler virtual class. This is the pure + virtual class from which the AMQP_Client and AMQP_ServerHandlerImpl classes + are derived. + --> + <xsl:template match="amqp" mode="server-operations-h"> + <xsl:param name="domain-cpp-table"/> + <xsl:result-document href="AMQP_ServerOperations.h" format="textFormat"> + <xsl:value-of select="amqp:copyright()"/> + <xsl:text> +#ifndef _AMQP_ServerOperations_ +#define _AMQP_ServerOperations_ + +#include "AMQP_Constants.h" +#include "qpid/framing/FieldTable.h" + +namespace qpid { +namespace framing { + +class AMQP_ServerOperations +{ + public: + AMQP_ServerOperations() {} + virtual ~AMQP_ServerOperations() {} + inline u_int16_t getAmqpMajor() { return (u_int16_t)</xsl:text><xsl:value-of select="@major"/><xsl:text>; } + inline u_int16_t getAmqpMinor() { return (u_int16_t)</xsl:text><xsl:value-of select="@minor"/><xsl:text>; }

</xsl:text> + + <!-- Inner classes --> + <xsl:for-each select="class"> + <xsl:variable name="class" select="concat(amqp:cpp-class-name(@name), 'Handler')"/> + + <!-- Inner class documentation & rules --> + <xsl:if test="doc"> + <xsl:text>
/**
===== Class: </xsl:text><xsl:value-of select="$class"/><xsl:text> =====
</xsl:text> + <xsl:value-of select="amqp:process-docs(doc)"/> + <xsl:text>*/
</xsl:text> + </xsl:if> + + <!-- Inner class definition --> + <xsl:text> class </xsl:text><xsl:value-of select="$class"/><xsl:text> + { + public: + /* Constructors and destructors */ + </xsl:text><xsl:value-of select="$class"/><xsl:text>() {} + virtual ~</xsl:text><xsl:value-of select="$class"/><xsl:text>() {} + + /* Protocol methods */
</xsl:text> + + <!-- Inner class methods (only if the chassis is set to "server") --> + <xsl:for-each select="method"> + <xsl:if test="chassis[@name='server']"> + <xsl:variable name="method" select="amqp:cpp-name(@name)"/> + + <!-- Inner class method documentation & rules --> + <xsl:if test="doc"> + <xsl:text>
/**
----- Method: </xsl:text><xsl:value-of select="$class"/><xsl:text>.</xsl:text> + <xsl:value-of select="@name"/><xsl:text> -----
</xsl:text> + <xsl:value-of select="amqp:process-docs(doc)"/> + <xsl:text>*/
</xsl:text> + </xsl:if> + <xsl:for-each select="rule"> + <xsl:text>
/**
</xsl:text> + <xsl:text>Rule "</xsl:text><xsl:value-of select="@name"/><xsl:text>":
</xsl:text> + <xsl:value-of select="amqp:process-docs(doc)"/> + <xsl:text>*/
</xsl:text> + </xsl:for-each> + + <!-- Inner class method definition --> + <xsl:text> virtual void </xsl:text><xsl:value-of select="$method"/> + <xsl:text>( u_int16_t channel</xsl:text> + + <!-- Inner class method parameter definition --> + <xsl:if test="field"> + <xsl:text>,
 </xsl:text> + <xsl:for-each select="field"> + <xsl:variable name="domain-cpp-type" select="amqp:cpp-lookup(@domain, $domain-cpp-table)"/> + <xsl:value-of select="concat($domain-cpp-type, amqp:cpp-arg-ref($domain-cpp-type), ' ', amqp:cpp-name(@name))"/> + <xsl:if test="position()!=last()"> + <xsl:text>,
 </xsl:text> + </xsl:if> + </xsl:for-each> + </xsl:if> + <xsl:text> ) = 0;
</xsl:text> + </xsl:if> + </xsl:for-each> + <xsl:text> }; /* class </xsl:text><xsl:value-of select="$class"/><xsl:text> */
</xsl:text> + </xsl:for-each> + + <xsl:for-each select="class"> + <xsl:variable name="class" select="concat(amqp:cpp-class-name(@name), 'Handler')"/> + <xsl:text> virtual AMQP_ServerOperations::</xsl:text> + <xsl:value-of select="$class"/><xsl:text>* get</xsl:text><xsl:value-of select="$class"/> + <xsl:text>() = 0;</xsl:text> + </xsl:for-each> + + <xsl:text>}; /* class AMQP_ServerOperations */ + +} /* namespace framing */ +} /* namespace qpid */ + +#endif
</xsl:text> + </xsl:result-document> + </xsl:template> + +</xsl:stylesheet> diff --git a/cpp/etc/stylesheets/code_gen.xsl b/cpp/etc/stylesheets/code_gen.xsl new file mode 100644 index 0000000000..5e9f4ef8f0 --- /dev/null +++ b/cpp/etc/stylesheets/code_gen.xsl @@ -0,0 +1,91 @@ +<?xml version='1.0'?> +<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amqp="http://amqp.org"> + + <xsl:import href="convert_0.81.xsl"/> + <xsl:import href="amqp_consts.xsl"/> + <xsl:import href="amqp_server_operations.xsl"/> + <xsl:import href="amqp_client_operations.xsl"/> + <xsl:import href="amqp_server.xsl"/> + <xsl:import href="amqp_client.xsl"/> + <xsl:import href="amqp_server_handler_impl.xsl"/> + <xsl:import href="amqp_client_handler_impl.xsl"/> + + <xsl:output method="text" indent="yes" name="textFormat"/> + <xsl:key name="domain-lookup" match="domains/domain" use="@domain-name"/> + + <xsl:template match="/"> + + <!-- 0. Convert to 0.81 format --> + <!-- + NOTE: The XML specification change from 0.8 to 0.81 is primarily a change to + the XML itself, not the protocol it represents. However, at the time of this + commit, the 0.81 specification has not been approved by the AMQP working group, + so this converter from the 0.8 format to the 0.81 format has been included as + a temporary measure. When the 0.81 format becomes official, then this conversion + should be removed, and all of the templates below will revert to select=".". + + TODO: Remove this conversion when the new 0.81 spec is checked in. + --> + <xsl:variable name="format-v081"> + <xsl:apply-templates mode="do-amqp" select="amqp"/> + </xsl:variable> + <!-- == Uncomment this to view output for debugging == + <xsl:result-document href="convert_081.out"> + <xsl:copy-of select="$format-v081"/> + </xsl:result-document> + --> + + <!-- 1. Domain to C++ type lookup table --> + <xsl:variable name="domain-cpp-table"> + <xsl:apply-templates mode="domain-table" select="$format-v081"/> + </xsl:variable> + <!-- == Uncomment this to view output for debugging == + <xsl:result-document href="domain_cpp_table.out"> + <xsl:copy-of select="$domain-cpp-table"/> + </xsl:result-document> + --> + + <!-- 2. Constant declarations (AMQP_Constants.h) --> + <xsl:apply-templates mode="domain-consts" select="$format-v081"/> + + <!-- 3. Client and server handler pure virtual classes --> + <xsl:apply-templates mode="server-operations-h" select="$format-v081"> + <xsl:with-param name="domain-cpp-table" select="$domain-cpp-table"/> + </xsl:apply-templates> + <xsl:apply-templates mode="client-operations-h" select="$format-v081"> + <xsl:with-param name="domain-cpp-table" select="$domain-cpp-table"/> + </xsl:apply-templates> + + <!-- 4. Client and server output classes --> + <xsl:apply-templates mode="server_h" select="$format-v081"> + <xsl:with-param name="domain-cpp-table" select="$domain-cpp-table"/> + </xsl:apply-templates> + <xsl:apply-templates mode="client_h" select="$format-v081"> + <xsl:with-param name="domain-cpp-table" select="$domain-cpp-table"/> + </xsl:apply-templates> + <xsl:apply-templates mode="server_cpp" select="$format-v081"> + <xsl:with-param name="domain-cpp-table" select="$domain-cpp-table"/> + </xsl:apply-templates> + <xsl:apply-templates mode="client_cpp" select="$format-v081"> + <xsl:with-param name="domain-cpp-table" select="$domain-cpp-table"/> + </xsl:apply-templates> + + <!-- 5. Client and server handler stub classes --> + <xsl:apply-templates mode="server_handler_impl_h" select="$format-v081"> + <xsl:with-param name="domain-cpp-table" select="$domain-cpp-table"/> + </xsl:apply-templates> + <xsl:apply-templates mode="client_handler_impl_h" select="$format-v081"> + <xsl:with-param name="domain-cpp-table" select="$domain-cpp-table"/> + </xsl:apply-templates> + <!-- TODO: Find a way to only run the .cpp stub generator when required, as + running this will overwrite any stub code in existance! --> + <xsl:apply-templates mode="server_handler_impl_cpp" select="$format-v081"> + <xsl:with-param name="domain-cpp-table" select="$domain-cpp-table"/> + </xsl:apply-templates> + <xsl:apply-templates mode="client_handler_impl_cpp" select="$format-v081"> + <xsl:with-param name="domain-cpp-table" select="$domain-cpp-table"/> + </xsl:apply-templates> + + </xsl:template> + +</xsl:stylesheet> diff --git a/cpp/etc/stylesheets/code_utils.xsl b/cpp/etc/stylesheets/code_utils.xsl new file mode 100644 index 0000000000..f4a0f6e5ce --- /dev/null +++ b/cpp/etc/stylesheets/code_utils.xsl @@ -0,0 +1,210 @@ +<?xml version='1.0'?> +<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amqp="http://amqp.org"> + + <!-- + ======================== + Function: amqp:copyright + ======================== + Print out a standard Apache copyright notice and generated code warning. + --> + <xsl:function name="amqp:copyright">/** +* +* Copyright (c) 2006 The Apache Software Foundation +* +* Licensed 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. +* +*/ + +/** +* +* NOTE: This file is generated directly from the AMQP XML specification. +* === DO NOT EDIT === +* +*/
</xsl:function> + + <!-- + ========================== + Function: amqp:upper-first + ========================== + Convert the first character of the parameter to upper-case + --> + <xsl:function name="amqp:upper-first"> + <xsl:param name="in"/> + <xsl:value-of select="concat(upper-case(substring($in, 1, 1)), substring($in, 2))"/> + </xsl:function> + + <!-- + ======================== + Function: amqp:cpp-name-1 + ======================== + Convert parameter "name" to a valid C++ identifier, finding spaces and '-'s + in the parameter name and replacing them with '_' chars. Also check for C++ + reserved words and prefix them with '_'. No capitalization is performed. + --> + <xsl:function name="amqp:cpp-name-1"> + <xsl:param name="name"/> + <xsl:choose> + <!-- C++ reserved words. --> + <xsl:when test="$name='delete'">delete_</xsl:when> + <xsl:when test="$name='return'">return_</xsl:when> + <!-- Change unsuitable C++ identifier characters. --> + <xsl:otherwise><xsl:value-of select="translate($name, ' -', '__')"/></xsl:otherwise> + </xsl:choose> + </xsl:function> + + <!-- + ======================= + Function: amqp:cpp-name + ======================= + Convert parameter "name" to a valid, camel cased C++ name. + --> + <xsl:function name="amqp:cpp-name"> + <xsl:param name="name"/> + <xsl:value-of select="amqp:cpp-name-1(amqp:camel-case($name))"/> + </xsl:function> + + <!-- + ============================= + Function: amqp:cpp-class-name + ============================= + Convert parameter "name" to a valid C++ identifier, finding spaces and '-'s + in the parameter name and replacing them with '_' chars. Also check for C++ + reserved words and prefix them with '_'. First letter only is capitalized. + --> + <xsl:function name="amqp:cpp-class-name"> + <xsl:param name="name"/> + <xsl:value-of select="amqp:upper-first(amqp:cpp-name($name))"/> + </xsl:function> + + <!-- + ========================= + Function: amqp:camel-case + ========================= + *** NOTE: Only works with *one* of either '-' or ' '. If a name contains 2 or + *** more of these characters, then this will break. + Convert parameter "name" to camel case, where words are separated by ' ' or '-' + --> + <xsl:function name="amqp:camel-case"> + <xsl:param name="name"/> + <xsl:choose> + <xsl:when test="contains($name, ' ')"> + <xsl:value-of select="concat(substring-before($name, ' '), amqp:upper-first(substring-after($name, ' ')))"/> + </xsl:when> + <xsl:when test="contains($name, '-')"> + <xsl:value-of select="concat(substring-before($name, '-'), amqp:upper-first(substring-after($name, '-')))"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$name"/> + </xsl:otherwise> + </xsl:choose> + </xsl:function> + + <!-- + ========================= + Function: amqp:field-name + ========================= + Get a valid field name, processing spaces and '-'s where appropriate + --> + <xsl:function name="amqp:field-name"> + <xsl:param name="name"/> + <xsl:value-of select="amqp:upper-first(amqp:camel-case($name))"/> + </xsl:function> + + <!-- + ======================= + Function: amqp:cpp-type + ======================= + Map the set of simple AMQP types to C++ types. Also map the AMQP table + domain to appropriate C++ class. + --> + <xsl:function name="amqp:cpp-type"> + <xsl:param name="type"/> + <xsl:choose> + <!-- Simple AMQP domain types --> + <xsl:when test="$type='octet'">u_int8_t</xsl:when> + <xsl:when test="$type='short'">u_int16_t</xsl:when> + <xsl:when test="$type='shortstr'">string</xsl:when> + <xsl:when test="$type='longstr'">string</xsl:when> + <xsl:when test="$type='bit'">bool</xsl:when> + <xsl:when test="$type='long'">u_int32_t</xsl:when> + <xsl:when test="$type='longlong'">u_int64_t</xsl:when> + <xsl:when test="$type='timestamp'">u_int64_t</xsl:when> + <!-- AMQP structures --> + <xsl:when test="$type='table'">FieldTable</xsl:when> + <!-- Fallback: unknown type --> + <xsl:otherwise>unknown_type /* WARNING: undefined type */</xsl:otherwise> + </xsl:choose> + </xsl:function> + + <!-- + ========================== + Function: amqp:cpp-arg-ref + ========================== + Determines whether a C++ reference is required for an argument. + --> + <xsl:function name="amqp:cpp-arg-ref"> + <xsl:param name="type"/> + <xsl:choose> + <xsl:when test="$type='string'">&</xsl:when> + <xsl:when test="$type='FieldTable'">&</xsl:when> + </xsl:choose> + </xsl:function> + + <!-- + ========================= + Function: amqp:cpp-lookup + ========================= + Template and function for looking up the cpp type from the domain name. + The template runs on a lookup table XML generated by the "domain_table" + template in amqp_domaintypes.xsl. + --> + <xsl:template match="/" mode="cpp-lookup"> + <xsl:param name="domain-name"/> + <xsl:for-each select="key('domain-lookup', $domain-name)"> + <xsl:value-of select="@cpp-type"/> + </xsl:for-each> + </xsl:template> + + <xsl:function name="amqp:cpp-lookup"> + <xsl:param name="domain-name"/> + <xsl:param name="domain-cpp-table"/> + <xsl:apply-templates mode="cpp-lookup" select="$domain-cpp-table"> + <xsl:with-param name="domain-name" select="$domain-name"/> + </xsl:apply-templates> + </xsl:function> + + <!-- + ========================= + Function: amqp:cpp-lookup + ========================= + Template and function for processing the possibly multiple <doc> elements + within a node. + --> + <xsl:template match="doc" mode="process-doc-elts"> + <xsl:for-each select="."> + <xsl:choose> + <xsl:when test=".[@type='grammar']"><xsl:value-of select="."/></xsl:when> + <xsl:when test=".[@type='scenario']"><xsl:value-of select="concat('
Test Scenario: ', normalize-space(.))"/></xsl:when> + <xsl:otherwise><xsl:value-of select="normalize-space(.)"/></xsl:otherwise> + </xsl:choose> + </xsl:for-each> + </xsl:template> + + <xsl:function name="amqp:process-docs"> + <xsl:param name="doc-elts"/> + <xsl:apply-templates mode="process-doc-elts" select="$doc-elts"/> + </xsl:function> + + +</xsl:stylesheet> + diff --git a/cpp/etc/stylesheets/convert_0.81.xsl b/cpp/etc/stylesheets/convert_0.81.xsl new file mode 100644 index 0000000000..9924f165da --- /dev/null +++ b/cpp/etc/stylesheets/convert_0.81.xsl @@ -0,0 +1,407 @@ +<?xml version='1.0'?> +<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amqp="http://amqp.org"> + +<xsl:template match="/"> + <xsl:apply-templates select="/" mode="do-amqp"/> +</xsl:template> + +<!-- ====== + <amqp> + ====== --> +<xsl:template match="amqp" mode="do-amqp"> + +<!-- <xsl:text>
</xsl:text> --> +<xsl:element name= "amqp"> +<xsl:attribute name="major"><xsl:value-of select="@major"/></xsl:attribute> +<xsl:attribute name="minor"><xsl:value-of select="@minor"/></xsl:attribute> +<xsl:attribute name="port"><xsl:value-of select="@port"/></xsl:attribute> +<xsl:attribute name="comment"><xsl:value-of select="@comment"/></xsl:attribute> +<xsl:text>
</xsl:text> + +<!-- constant elements --> +<xsl:text>
</xsl:text> +<xsl:text> </xsl:text><xsl:comment> + ==================== + Constants + ==================== + </xsl:comment><xsl:text>
</xsl:text> +<xsl:text>
</xsl:text> +<xsl:apply-templates select="constant" mode="do-constant"> +<xsl:with-param name="indent" select="' '"/> +</xsl:apply-templates> + +<!-- domain elements --> +<xsl:text>
</xsl:text> +<xsl:text> </xsl:text><xsl:comment> + ==================== + Domains + ==================== + </xsl:comment><xsl:text>
</xsl:text> +<xsl:text>
</xsl:text> +<xsl:apply-templates select="domain" mode="do-domain"> +<xsl:with-param name="indent" select="' '"/> +</xsl:apply-templates> + +<!-- required elementary domain definition elements added into v0.81 --> +<xsl:text>
</xsl:text> +<xsl:text> </xsl:text><xsl:comment> Elementary domains </xsl:comment><xsl:text>
</xsl:text> +<xsl:text> </xsl:text><xsl:element name="domain"> + <xsl:attribute name="name">bit</xsl:attribute> + <xsl:attribute name="type">bit</xsl:attribute> + <xsl:attribute name="label">single bit</xsl:attribute> +</xsl:element><xsl:text>
</xsl:text> +<xsl:text> </xsl:text><xsl:element name="domain"> + <xsl:attribute name="name">octet</xsl:attribute> + <xsl:attribute name="type">octet</xsl:attribute> + <xsl:attribute name="label">single octet</xsl:attribute> +</xsl:element><xsl:text>
</xsl:text> +<xsl:text> </xsl:text><xsl:element name="domain"> + <xsl:attribute name="name">short</xsl:attribute> + <xsl:attribute name="type">short</xsl:attribute> + <xsl:attribute name="label">16-bit integer</xsl:attribute> +</xsl:element><xsl:text>
</xsl:text> +<xsl:text> </xsl:text><xsl:element name="domain"> + <xsl:attribute name="name">long</xsl:attribute> + <xsl:attribute name="type">long</xsl:attribute> + <xsl:attribute name="label">32-bit integer</xsl:attribute> +</xsl:element><xsl:text>
</xsl:text> +<xsl:text> </xsl:text><xsl:element name="domain"> + <xsl:attribute name="name">longlong</xsl:attribute> + <xsl:attribute name="type">longlong</xsl:attribute> + <xsl:attribute name="label">64-bit integer</xsl:attribute> +</xsl:element><xsl:text>
</xsl:text> +<xsl:text> </xsl:text><xsl:element name="domain"> + <xsl:attribute name="name">shortstr</xsl:attribute> + <xsl:attribute name="type">shortstr</xsl:attribute> + <xsl:attribute name="label">short string</xsl:attribute> +</xsl:element><xsl:text>
</xsl:text> +<xsl:text> </xsl:text><xsl:element name="domain"> + <xsl:attribute name="name">longstr</xsl:attribute> + <xsl:attribute name="type">longstr</xsl:attribute> + <xsl:attribute name="label">long string</xsl:attribute> +</xsl:element><xsl:text>
</xsl:text> +<xsl:text> </xsl:text><xsl:element name="domain"> + <xsl:attribute name="name">timestamp</xsl:attribute> + <xsl:attribute name="type">timestamp</xsl:attribute> + <xsl:attribute name="label">64-bit timestamp</xsl:attribute> +</xsl:element><xsl:text>
</xsl:text> +<xsl:text> </xsl:text><xsl:element name="domain"> + <xsl:attribute name="name">table</xsl:attribute> + <xsl:attribute name="type">table</xsl:attribute> + <xsl:attribute name="label">field table</xsl:attribute> +</xsl:element><xsl:text>
</xsl:text> + +<!-- class elements --> +<xsl:text>
</xsl:text> +<xsl:text> </xsl:text><xsl:comment> + ==================== + Classes + ==================== + </xsl:comment><xsl:text>
</xsl:text> +<xsl:apply-templates select="class" mode="do-class"> +<xsl:with-param name="indent" select="' '"/> +</xsl:apply-templates> + +</xsl:element><!-- amqp --> +<!-- <xsl:text>
</xsl:text> --> +</xsl:template> + +<!-- ========== + <constant> + ========== --> +<xsl:template match="constant" mode="do-constant"> +<xsl:param name="indent"/> +<xsl:variable name="constant" select="translate(@name, ' ', '-')"/> + +<xsl:value-of select="$indent"/><xsl:element name="constant"> +<xsl:attribute name="name"><xsl:value-of select="$constant"/></xsl:attribute> +<xsl:attribute name="value"><xsl:value-of select="@value"/></xsl:attribute> +<xsl:if test="@class"> +<xsl:attribute name="class"><xsl:value-of select="translate(@class, ' ', '-')"/></xsl:attribute> +</xsl:if> + +<!-- If there is content, place in child <doc> element --> +<xsl:if test="string-length(.) > 0"> +<xsl:text>
</xsl:text> +<xsl:value-of select="$indent"/><xsl:text> </xsl:text><xsl:element name="doc"><xsl:text>
</xsl:text> +<xsl:value-of select="$indent"/><xsl:text> </xsl:text><xsl:value-of select="normalize-space(.)"/><xsl:text>
</xsl:text> +<xsl:value-of select="$indent"/><xsl:text> </xsl:text></xsl:element><xsl:text>
</xsl:text> +<xsl:value-of select="$indent"/> +</xsl:if> + +</xsl:element><xsl:text>
</xsl:text> + +</xsl:template> + +<!-- ======== + <domain> + ======== --> +<xsl:template match="domain" mode="do-domain"> +<xsl:param name="indent"/> +<xsl:variable name="domain" select="translate(@name, ' ', '-')"/> + +<xsl:value-of select="$indent"/><xsl:element name="domain"> +<xsl:attribute name="name"><xsl:value-of select="$domain"/></xsl:attribute> +<xsl:attribute name="type"><xsl:value-of select="@type"/></xsl:attribute> +<xsl:if test="doc|assert|rule"><xsl:text>
</xsl:text></xsl:if> + +<!-- doc elements --> +<xsl:apply-templates select="doc" mode="do-doc"> +<xsl:with-param name="indent" select="concat($indent, ' ')"/> +</xsl:apply-templates> + +<!-- assert elements --> +<xsl:apply-templates select="assert" mode="do-assert"> +<xsl:with-param name="indent" select="concat($indent, ' ')"/> +</xsl:apply-templates> + +<!-- rule elements --> +<xsl:apply-templates select="rule" mode="do-rule"> +<xsl:with-param name="indent" select="concat($indent, ' ')"/> +<xsl:with-param name="label" select="$domain"/> +</xsl:apply-templates> + +<xsl:if test="doc|assert|rule"><xsl:value-of select="$indent"/></xsl:if></xsl:element><xsl:text>
</xsl:text> + +</xsl:template> + +<!-- ======== + <class> + ======== --> + +<xsl:template match="class" mode="do-class"> +<xsl:param name="indent"/> +<xsl:variable name="class" select="translate(@name, ' ', '-')"/> + +<!-- Ignore class test - removed from 0.81 --> +<xsl:if test="not($class = 'test')"> +<xsl:text>
</xsl:text><xsl:value-of select="$indent"/><xsl:comment><xsl:value-of select="concat(' == Class: ', $class, ' == ')"/></xsl:comment><xsl:text>
</xsl:text> +<xsl:value-of select="$indent"/><xsl:element name="class"> +<xsl:attribute name="name"><xsl:value-of select="$class"/></xsl:attribute> +<xsl:attribute name="handler"><xsl:value-of select="@handler"/></xsl:attribute> +<xsl:attribute name="index"><xsl:value-of select="@index"/></xsl:attribute> +<xsl:if test="doc|chassis|rule|field|method"><xsl:text>
</xsl:text></xsl:if> + +<!-- doc elements --> +<xsl:apply-templates select="doc" mode="do-doc"> +<xsl:with-param name="indent" select="concat($indent, ' ')"/> +<xsl:with-param name="label" select="$class"/> +</xsl:apply-templates> + +<!-- chassis elements --> +<xsl:apply-templates select="chassis" mode="do-chassis"> +<xsl:with-param name="indent" select="concat($indent, ' ')"/> +</xsl:apply-templates> + +<!-- rule elements --> +<xsl:apply-templates select="rule" mode="do-rule"> +<xsl:with-param name="indent" select="concat($indent, ' ')"/> +<xsl:with-param name="label" select="$class"/> +</xsl:apply-templates> + +<!-- field elements --> +<xsl:apply-templates select="field" mode="do-field"> +<xsl:with-param name="indent" select="concat($indent, ' ')"/> +<xsl:with-param name="label" select="$class"/> +</xsl:apply-templates> + +<!-- method elements --> +<xsl:apply-templates select="method" mode="do-method"> +<xsl:with-param name="indent" select="concat($indent, ' ')"/> +<xsl:with-param name="label" select="$class"/> +</xsl:apply-templates> + +<xsl:if test="doc|chassis|rule|field|method"><xsl:value-of select="$indent"/></xsl:if></xsl:element><xsl:text>
</xsl:text> +</xsl:if> +</xsl:template> + +<!-- ======== + <method> + ======== --> + +<xsl:template match="method" mode="do-method"> +<xsl:param name="indent"/> +<xsl:param name="label"/> +<xsl:variable name="method" select="translate(@name, ' ', '-')"/> + +<xsl:text>
</xsl:text><xsl:value-of select="$indent"/><xsl:comment><xsl:value-of select="concat(' == Method: ', $label, '.', $method, ' == ')"/></xsl:comment><xsl:text>
</xsl:text> +<xsl:value-of select="$indent"/><xsl:element name="method"> +<xsl:attribute name="name"><xsl:value-of select="$method"/></xsl:attribute> +<xsl:if test="@synchronous"><xsl:attribute name="synchronous"><xsl:value-of select="@synchronous"/></xsl:attribute></xsl:if> +<xsl:attribute name="index"><xsl:value-of select="@index"/></xsl:attribute> +<xsl:if test="doc|chassis|response|rule|field"><xsl:text>
</xsl:text></xsl:if> + +<!-- doc elements --> +<xsl:apply-templates select="doc" mode="do-doc"> +<xsl:with-param name="indent" select="concat($indent, ' ')"/> +<xsl:with-param name="label" select="concat($label, '.', $method)"/> +</xsl:apply-templates> + +<!-- chassis and response elements --> +<xsl:apply-templates select="chassis" mode="do-chassis"> +<xsl:with-param name="indent" select="concat($indent, ' ')"/> +</xsl:apply-templates> +<xsl:apply-templates select="response" mode="do-response"> +<xsl:with-param name="indent" select="concat($indent, ' ')"/> +</xsl:apply-templates> + +<!-- rule elements --> +<xsl:apply-templates select="rule" mode="do-rule"> +<xsl:with-param name="indent" select="concat($indent, ' ')"/> +<xsl:with-param name="label" select="concat($label, '.', $method)"/> +</xsl:apply-templates> + +<!-- field elements --> +<xsl:apply-templates select="field" mode="do-field"> +<xsl:with-param name="indent" select="concat($indent, ' ')"/> +<xsl:with-param name="label" select="concat($label, '.', $method)"/> +</xsl:apply-templates> + +<xsl:if test="doc|chassis|response|rule|field"><xsl:value-of select="$indent"/></xsl:if></xsl:element><xsl:text>
</xsl:text> + +</xsl:template> + +<!-- ======== + <field> + ======== --> + +<xsl:template match="field" mode="do-field"> +<xsl:param name="indent"/> +<xsl:param name="label"/> +<xsl:variable name="field" select="translate(@name, ' ', '-')"/> + +<xsl:value-of select="$indent"/><xsl:element name="field"> +<xsl:attribute name="name"><xsl:value-of select="$field"/></xsl:attribute> +<xsl:if test="@type"> +<xsl:attribute name="domain"><xsl:value-of select="translate(@type, ' ', '-')"/></xsl:attribute> +</xsl:if> +<xsl:if test="@domain"> +<xsl:attribute name="domain"><xsl:value-of select="translate(@domain, ' ', '-')"/></xsl:attribute> +</xsl:if> +<xsl:if test="doc|rule|assert"><xsl:text>
</xsl:text></xsl:if> + +<!-- doc elements --> +<xsl:apply-templates select="doc" mode="do-doc"> +<xsl:with-param name="indent" select="concat($indent, ' ')"/> +<xsl:with-param name="label" select="concat($label, '.', $field)"/> +</xsl:apply-templates> + +<!-- rule elements --> +<xsl:apply-templates select="rule" mode="do-rule"> +<xsl:with-param name="indent" select="concat($indent, ' ')"/> +<xsl:with-param name="label" select="concat($label, '.', $field)"/> +</xsl:apply-templates> + +<!-- assert elements --> +<xsl:apply-templates select="assert" mode="do-assert"> +<xsl:with-param name="indent" select="concat($indent, ' ')"/> +</xsl:apply-templates> + +<xsl:if test="doc|rule|assert"><xsl:value-of select="$indent"/></xsl:if></xsl:element><xsl:text>
</xsl:text> + +</xsl:template> + +<!-- ======== + <assert> + ======== --> +<xsl:template match="assert" mode="do-assert"> +<xsl:param name="indent"/> + +<xsl:value-of select="$indent"/><xsl:element name="assert"> +<xsl:attribute name="check"><xsl:value-of select="@check"/></xsl:attribute> +<xsl:if test="@value"><xsl:attribute name="value"><xsl:value-of select="@value"/></xsl:attribute></xsl:if> +<xsl:if test="@rule"><xsl:attribute name="rule"><xsl:value-of select="@rule"/></xsl:attribute></xsl:if> + +<xsl:apply-templates select="doc" mode="do-doc"> +<xsl:with-param name="indent" select="concat($indent, ' ')"/> +</xsl:apply-templates> + +</xsl:element><xsl:text>
</xsl:text> + +</xsl:template> + +<!-- ======== + <rule> + ======== --> +<xsl:template match="rule" mode="do-rule"> +<xsl:param name="indent"/> +<xsl:param name="label"/> + +<xsl:value-of select="$indent"/><xsl:element name="rule"> +<xsl:attribute name="name">rule_<xsl:value-of select="$label"/>_<xsl:number format="01"/></xsl:attribute> + +<!-- If there is content, place in child <doc> element --> + +<xsl:if test="string-length(.) > 0"> +<xsl:text>
</xsl:text> +<xsl:value-of select="$indent"/><xsl:text> </xsl:text><xsl:element name="doc"><xsl:text>
</xsl:text> +<xsl:value-of select="$indent"/><xsl:text> </xsl:text><xsl:value-of select="normalize-space(.)"/><xsl:text>
</xsl:text> +<xsl:value-of select="$indent"/><xsl:text> </xsl:text></xsl:element><xsl:text>
</xsl:text> +<xsl:value-of select="$indent"/> +</xsl:if> + +</xsl:element><xsl:text>
</xsl:text> + +</xsl:template> + +<!-- ========= + <chassis> + ========= --> +<xsl:template match="chassis" mode="do-chassis"> +<xsl:param name="indent"/> + +<xsl:value-of select="$indent"/><xsl:element name="chassis"> +<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute> +<xsl:attribute name="implement"><xsl:value-of select="@implement"/></xsl:attribute> +</xsl:element><xsl:text>
</xsl:text> + +</xsl:template> + +<!-- ========== + <response> + ========== --> +<xsl:template match="response" mode="do-response"> +<xsl:param name="indent"/> + +<xsl:value-of select="$indent"/><xsl:element name="response"> +<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute> +</xsl:element><xsl:text>
</xsl:text> + +</xsl:template> + +<!-- ===== + <doc> + ===== --> +<xsl:template match="doc" mode="do-doc"> +<xsl:param name="indent"/> +<xsl:param name="label"/> + +<!-- Handle cases of <doc name="rule>...</doc>: turn them into <rule><doc>...</doc></rule> --> +<xsl:if test="@name = 'rule'"> +<xsl:value-of select="$indent"/><xsl:element name="rule"> +<xsl:if test="@test"><xsl:attribute name="name"><xsl:value-of select="@test"/></xsl:attribute></xsl:if> +<xsl:if test="not(@test)"><xsl:attribute name="name">doc_rule_<xsl:value-of select="$label"/>_<xsl:number format="01"/></xsl:attribute></xsl:if> +<xsl:text>
</xsl:text> +<xsl:value-of select="concat($indent, ' ')"/><xsl:element name="doc"><xsl:text>
</xsl:text> +<xsl:value-of select="concat($indent, ' ')"/><xsl:text> </xsl:text><xsl:value-of select="normalize-space(.)"/><xsl:text>
</xsl:text> +<xsl:value-of select="concat($indent, ' ')"/></xsl:element><xsl:text>
</xsl:text> +<xsl:value-of select="$indent"/></xsl:element><xsl:text>
</xsl:text> +</xsl:if> + +<!-- Normal <doc>...</doc> elements --> +<xsl:if test="not(@name = 'rule')"> +<xsl:value-of select="$indent"/><xsl:element name="doc"> +<xsl:if test="@name = 'grammar'"> +<xsl:attribute name="type">grammar</xsl:attribute> +<xsl:value-of select="$indent"/><xsl:text> </xsl:text><xsl:value-of select="."/> +</xsl:if> +<xsl:if test="not(@name = 'grammar')"> +<xsl:text>
</xsl:text> +<xsl:value-of select="$indent"/><xsl:text> </xsl:text><xsl:value-of select="normalize-space(.)"/><xsl:text>
</xsl:text> +</xsl:if> +<xsl:value-of select="$indent"/></xsl:element><xsl:text>
</xsl:text> +</xsl:if> + +</xsl:template> + +</xsl:stylesheet> diff --git a/cpp/etc/stylesheets/cpp.xsl b/cpp/etc/stylesheets/cpp.xsl new file mode 100644 index 0000000000..51facee294 --- /dev/null +++ b/cpp/etc/stylesheets/cpp.xsl @@ -0,0 +1,315 @@ +<?xml version='1.0'?> +<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amqp="http://amqp.org"> + +<!-- this class contains the templates for generating C++ source code for a given framing model --> + +<xsl:import href="utils.xsl"/> +<xsl:output method="text" indent="yes" name="textFormat"/> + +<xsl:template match="/"> + <xsl:apply-templates mode="generate-multi" select="frames"/> + <xsl:apply-templates mode="method-list-header" select="frames"/> + <xsl:apply-templates mode="method-list-source" select="frames"/> + <xsl:apply-templates mode="method-interface" select="frames"/> +</xsl:template> + +<!-- processes all frames outputting the classes in a single stream --> +<xsl:template match="frames" mode="generate-single"> + <xsl:result-document href="amqp_methods.h" format="textFormat"> +#include "qpid/framing/amqp_framing.h" + <xsl:for-each select="frame"> + <xsl:call-template name="generate-class"> + <xsl:with-param name="f" select="."/> + </xsl:call-template> + </xsl:for-each> + </xsl:result-document> +</xsl:template> + +<!-- generates seperate file for each class/frame --> +<xsl:template match="frame" mode="generate-multi"> + <xsl:variable name="uri" select="concat(@name, '.h')"/> + <xsl:result-document href="{$uri}" format="textFormat"> +#include "qpid/framing/amqp_types.h" +#include "AMQP_ServerOperations.h" +#include "qpid/framing/AMQMethodBody.h" +#include "qpid/framing/Buffer.h" +#include "qpid/framing/FieldTable.h" + +#ifndef _<xsl:value-of select="@name"/>_ +#define _<xsl:value-of select="@name"/>_ + +namespace qpid { +namespace framing { + + <xsl:call-template name="generate-class"> + <xsl:with-param name="f" select="."/> + </xsl:call-template> +} +} + +#endif + +</xsl:result-document> +</xsl:template> + + +<!-- main class generation template --> +<xsl:template name="generate-class"> + <xsl:param name="f"/> +/** + * This class is autogenerated, do not modify. [From <xsl:value-of select="$f/parent::frames/@protocol"/>] + */ +class <xsl:value-of select="$f/@name"/> : virtual public AMQMethodBody +{ + <xsl:for-each select="$f/field"> + <xsl:value-of select="@cpp-type"/> + <xsl:text> </xsl:text> + <xsl:value-of select="@name"/>; + </xsl:for-each> + +public: + typedef std::tr1::shared_ptr<<xsl:value-of select="$f/@name"/>> shared_ptr; + + virtual ~<xsl:value-of select="$f/@name"/>() {} + + <xsl:for-each select="$f/field"> + inline <xsl:value-of select="concat(@cpp-arg-type, ' get', amqp:upper-first(@name), '() { return ', @name)"/>; } + </xsl:for-each> + + + inline void print(std::ostream& out) const{ + out << "<xsl:value-of select="$f/@declaration_name"/>" + <xsl:for-each select="$f/field"> + <xsl:text> << ", </xsl:text> + <xsl:value-of select="@name"/>="<< + <xsl:value-of select="@name"/> + </xsl:for-each> + ; + } + + inline u_int16_t amqpClassId() const { + return <xsl:value-of select="$f/@class-id"/>; + } + + inline u_int16_t amqpMethodId() const { + return <xsl:value-of select="$f/@method-id"/>; + } + + inline u_int32_t bodySize() const { + <xsl:choose> + <xsl:when test="$f/field"> + return + <xsl:for-each select="$f/field"> + <xsl:if test="position() != 1">+ + </xsl:if> + <xsl:value-of select="amqp:field-length(.)"/> + </xsl:for-each> + ; + </xsl:when> + <xsl:otherwise>return 0;</xsl:otherwise> + </xsl:choose> + } + + <xsl:if test="@server='true'"> + inline void invoke(AMQP_ServerOperations& target, u_int16_t channel) { + <xsl:if test="field"> + <xsl:value-of select="concat('target.get', amqp:upper-first(parent::class/@name), 'Handler()->', @invocation_name, '(channel, ')"/> + <xsl:value-of select="$f/field/@name" separator=", "/>); + </xsl:if> + <xsl:if test="not(field)"> + <xsl:value-of select="concat('target.get', amqp:upper-first(parent::class/@name), 'Handler()->', @invocation_name, '(channel)')"/>; + </xsl:if> + } + </xsl:if> + + inline void encodeContent(Buffer& <xsl:if test="$f/field">buffer</xsl:if>) const + { + <xsl:if test="$f/field[@type='bit']"> + u_int8_t flags = 0; + <xsl:for-each select="$f/field[@type='bit']"> + <xsl:value-of select="concat('flags |= ', @name,' << (', @boolean-index, ' - 1)')"/>; + </xsl:for-each> + </xsl:if> + <xsl:for-each select="$f/field"> + <xsl:if test="@type != 'bit'"> + <xsl:value-of select="amqp:encoder(.)"/>; + </xsl:if> + <xsl:if test="@type = 'bit' and @boolean-index = 1"> + <xsl:text>buffer.putOctet(flags)</xsl:text>; + </xsl:if> + </xsl:for-each> + } + + inline void decodeContent(Buffer& <xsl:if test="$f/field">buffer</xsl:if>) + { + <xsl:for-each select="$f/field"> + <xsl:choose> + <xsl:when test="@type = 'bit' and @boolean-index = 1"> + <xsl:text>u_int8_t flags = buffer.getOctet()</xsl:text>; + <xsl:value-of select="amqp:decoder(.)"/>; + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="amqp:decoder(.)"/>; + </xsl:otherwise> + </xsl:choose> + </xsl:for-each> + } + + <xsl:if test="$f/field"> + <!-- only generate overloaded constructor if there are fields in this method --> + inline <xsl:value-of select="$f/@name"/>(<xsl:value-of select="$f/field/concat(@cpp-arg-type, ' _', @name)" separator=", "/>) : <xsl:value-of select="$f/field/concat(@name, '(_', @name, ')')" separator=", "/> + { + } + </xsl:if> + + inline <xsl:value-of select="$f/@name"/>() + { + } +}; + +</xsl:template> + +<xsl:template match="frames" mode="method-list-header"> +<xsl:result-document href="amqp_methods.h" format="textFormat"> +/** + * This file is autogenerated, do not modify. + */ + +#ifndef AMQ_METHODS_H +#define AMQ_METHODS_H + + <xsl:for-each select="class/frame"> +#include "<xsl:value-of select="@name"/>.h" + </xsl:for-each> + +namespace qpid { +namespace framing { + + <xsl:for-each select="class/frame"> +const <xsl:value-of select="concat(@name, ' ', @declaration_name)"/>; + </xsl:for-each> + +AMQMethodBody* createAMQMethodBody(u_int16_t classId, u_int16_t methodId); + +} +} + +#endif +</xsl:result-document> +</xsl:template> + +<xsl:template match="frames" mode="method-list-source"> + <xsl:result-document href="amqp_methods.cpp" format="textFormat"> +#include "amqp_methods.h" +#include "qpid/QpidError.h" + +namespace qpid { +namespace framing { +/** + * This method is autogenerated, do not modify. + */ +AMQMethodBody* createAMQMethodBody(u_int16_t classId, u_int16_t methodId){ + switch(classId * 1000 + methodId) + { + <xsl:for-each select="class/frame"> + <xsl:text>case </xsl:text> + <xsl:value-of select="@class-id"/> + <xsl:text> * 1000 + </xsl:text> + <xsl:value-of select="@method-id"/> + <xsl:text>: return new </xsl:text> + <xsl:value-of select="@name"/>(); + </xsl:for-each> + } + THROW_QPID_ERROR(FRAMING_ERROR, "Unknown method"); +} + +} +} +</xsl:result-document> +</xsl:template> + +<xsl:template match="frames" mode="generate-interface"> + <xsl:result-document href="AMQPServer.h" format="textFormat"> +#include "qpid/framing/amqp_types.h" +#include "qpid/framing/FieldTable.h" + +#ifndef _AMQPServer_ +#define _AMQPServer_ + +namespace qpid { +namespace framing { + +class AMQPServer +{ + public: + + <xsl:for-each select="class"> + class <xsl:value-of select="concat(amqp:upper-first(@name), 'Handler')"/>{ + public: + <xsl:for-each select="frame[@server='true']"> + <xsl:if test="field"> + virtual void <xsl:value-of select="@invocation_name"/>(u_int16_t channel, <xsl:value-of select="field/concat(@cpp-arg-type, ' ', @name)" separator=", "/>) = 0; + </xsl:if> + <xsl:if test="not(field)"> + virtual void <xsl:value-of select="@invocation_name"/>(u_int16_t channel) = 0; + </xsl:if> + </xsl:for-each> + virtual ~<xsl:value-of select="concat(amqp:upper-first(@name), 'Handler')"/>(){} + }; + + virtual <xsl:value-of select="concat(amqp:upper-first(@name), 'Handler* get', amqp:upper-first(@name), 'Handler')"/>() = 0; + + </xsl:for-each> + virtual ~AMQPServer(){} +}; + +} +} + +#endif +</xsl:result-document> + + <xsl:result-document href="AMQPClient.h" format="textFormat"> +#include "qpid/framing/amqp_types.h" +#include "qpid/framing/FieldTable.h" + +#ifndef _AMQPClient_ +#define _AMQPClient_ + +namespace qpid { +namespace framing { + +class AMQPClient +{ + public: + + <xsl:for-each select="class"> + class <xsl:value-of select="concat(amqp:upper-first(@name), 'Handler')"/>{ + public: + <xsl:for-each select="frame[@client='true']"> + <xsl:if test="field"> + virtual void <xsl:value-of select="@invocation_name"/>(u_int16_t channel, <xsl:value-of select="field/concat(@cpp-arg-type, ' ', @name)" separator=", "/>) = 0; + </xsl:if> + <xsl:if test="not(field)"> + virtual void <xsl:value-of select="@invocation_name"/>(u_int16_t channel) = 0; + </xsl:if> + </xsl:for-each> + virtual ~<xsl:value-of select="concat(amqp:upper-first(@name), 'Handler')"/>(){} + }; + + virtual <xsl:value-of select="concat(amqp:upper-first(@name), 'Handler* get', amqp:upper-first(@name), 'Handler')"/>() = 0; + + </xsl:for-each> + + virtual ~AMQPClient(){} +}; + +} +} + +#endif +</xsl:result-document> + +</xsl:template> + +</xsl:stylesheet> diff --git a/cpp/etc/stylesheets/framing.xsl b/cpp/etc/stylesheets/framing.xsl new file mode 100644 index 0000000000..c63e719a77 --- /dev/null +++ b/cpp/etc/stylesheets/framing.xsl @@ -0,0 +1,49 @@ +<?xml version='1.0'?> +<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amqp="http://amqp.org"> + +<xsl:import href="prepare1.xsl"/> +<xsl:import href="prepare2.xsl"/> +<xsl:import href="prepare3.xsl"/> +<xsl:import href="cpp.xsl"/> + +<xsl:output indent="yes"/> +<xsl:output method="text" indent="yes" name="textFormat"/> + +<xsl:template match="/"> + <xsl:variable name="prepare1"> + <xsl:apply-templates mode="prepare1" select="."/> + </xsl:variable> + + <xsl:variable name="prepare2"> + <xsl:apply-templates mode="prepare2" select="$prepare1"/> + </xsl:variable> + + <xsl:variable name="model"> + <xsl:apply-templates mode="prepare3" select="$prepare2"/> + </xsl:variable> + + <xsl:apply-templates mode="generate-multi" select="$model"/> + <xsl:apply-templates mode="method-list-header" select="$model"/> + <xsl:apply-templates mode="method-list-source" select="$model"/> + + <!-- these interfaces are now generated by the new scripts from kim --> + <!-- e.g. those of the form amqp-server/client-*.xsl --> + <!-- xsl:apply-templates mode="generate-interface" select="$model"/ --> + + <!-- dump out the intermediary files for debugging --> + <!-- + <xsl:result-document href="prepare1.out"> + <xsl:copy-of select="$prepare1"/> + </xsl:result-document> + + <xsl:result-document href="prepare2.out"> + <xsl:copy-of select="$prepare2"/> + </xsl:result-document> + + <xsl:result-document href="model.out"> + <xsl:copy-of select="$model"/> + </xsl:result-document> + --> +</xsl:template> + +</xsl:stylesheet> diff --git a/cpp/etc/stylesheets/prepare1.xsl b/cpp/etc/stylesheets/prepare1.xsl new file mode 100644 index 0000000000..2aeda89677 --- /dev/null +++ b/cpp/etc/stylesheets/prepare1.xsl @@ -0,0 +1,104 @@ +<?xml version='1.0'?> +<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amqp="http://amqp.org"> + +<xsl:import href="utils.xsl"/> + +<xsl:output indent="yes"/> +<xsl:param name="asl_base"/> + +<!-- pre-process, phase 1 --> + +<xsl:template match="/"> + <xsl:apply-templates select="protocol" mode="prepare1"/> +</xsl:template> + +<xsl:template match="amqp" mode="prepare1"> + <frames> + <xsl:attribute name="protocol"> + <xsl:value-of select="@comment"/> + <xsl:text> (</xsl:text> + <xsl:text>major=</xsl:text><xsl:value-of select="@major"/> + <xsl:text>, minor=</xsl:text><xsl:value-of select="@minor"/> + <xsl:text>)</xsl:text> + </xsl:attribute> + <xsl:apply-templates mode="prepare1" select="inherit"/> + <xsl:apply-templates mode="prepare1" select="include"/> + <xsl:apply-templates mode="prepare1" select="domain"/> + <xsl:apply-templates mode="prepare1" select="class"/> + </frames> +</xsl:template> + +<xsl:template match="include" mode="prepare1"> + <xsl:if test="@filename != 'asl_constants.asl'"> + <!-- skip asl_constants.asl, we don't need it and it is not well formed so causes error warnings --> + <xsl:apply-templates select="document(@filename)" mode="prepare1"/> + </xsl:if> +</xsl:template> + +<xsl:template match="inherit" mode="prepare1"> + <xsl:variable name="ibase" select="concat('file:///', $asl_base, '/', @name, '.asl')"/> + <xsl:choose> + <xsl:when test="document($ibase)"> + <xsl:apply-templates select="document($ibase)" mode="prepare1"/> + </xsl:when> + <xsl:otherwise> + <xsl:message> + Could not inherit from <xsl:value-of select="$ibase"/>; file not found. + </xsl:message> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +<xsl:template match="class[@index]" mode="prepare1"> +<xsl:if test="not(@name = 'test')"> + <class> + <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute> + <xsl:apply-templates select="method" mode="prepare1"/> + </class> +</xsl:if> +</xsl:template> + +<xsl:template match="method" mode="prepare1"> + <xsl:if test="parent::class[@index]"><!-- there is a template class that has no index, which we want to skip --> + <frame> + <xsl:attribute name="name"><xsl:value-of select="amqp:class-name(parent::class/@name, @name)"/></xsl:attribute> + <xsl:attribute name="class-id"><xsl:value-of select="parent::class/@index"/></xsl:attribute> + <xsl:if test="@index"> + <xsl:attribute name="method-id"><xsl:value-of select="@index"/></xsl:attribute> + </xsl:if> + <xsl:if test="not(@index)"> + <xsl:attribute name="method-id"><xsl:number count="method"/></xsl:attribute> + </xsl:if> + <xsl:attribute name="invocation_name"> + <xsl:value-of select="amqp:keyword-check(amqp:field-name(@name))"/> + </xsl:attribute> + <xsl:attribute name="declaration_name"> + <xsl:value-of select="amqp:method-name(parent::class/@name, @name)"/> + </xsl:attribute> + <xsl:if test="chassis[@name='client']"> + <xsl:attribute name="client">true</xsl:attribute> + </xsl:if> + <xsl:if test="chassis[@name='server']"> + <xsl:attribute name="server">true</xsl:attribute> + </xsl:if> + <xsl:apply-templates select="field" mode="prepare1"/> + </frame> + </xsl:if> +</xsl:template> + +<xsl:template match="domain" mode="prepare1"> + <domain> + <name><xsl:value-of select="@name"/></name> + <type><xsl:value-of select="@type"/></type> + </domain> +</xsl:template> + +<xsl:template match="field" mode="prepare1"> + <field> + <xsl:copy-of select="@name"/> + <xsl:copy-of select="@type"/> + <xsl:copy-of select="@domain"/> + </field> +</xsl:template> + +</xsl:stylesheet> diff --git a/cpp/etc/stylesheets/prepare2.xsl b/cpp/etc/stylesheets/prepare2.xsl new file mode 100644 index 0000000000..331319de57 --- /dev/null +++ b/cpp/etc/stylesheets/prepare2.xsl @@ -0,0 +1,54 @@ +<?xml version='1.0'?> +<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amqp="http://amqp.org"> + +<xsl:import href="utils.xsl"/> + +<xsl:output indent="yes"/> + +<!-- pre-process, phase 2 --> + +<xsl:key name="domain-lookup" match="domain" use="name"/> + +<xsl:template match="/"> + <xsl:apply-templates mode="prepare2" select="frames"/> +</xsl:template> + +<xsl:template match="field[@domain]" mode="prepare2"> + <field> + <xsl:variable name="t1" select="key('domain-lookup', @domain)/type"/> + <xsl:attribute name="name"><xsl:value-of select="amqp:field-name(@name)"/></xsl:attribute> + <xsl:attribute name="type"><xsl:value-of select="$t1"/></xsl:attribute> + </field> +</xsl:template> + +<xsl:template match="field[@type]" mode="prepare2"> + <field> + <xsl:attribute name="name"><xsl:value-of select="amqp:field-name(@name)"/></xsl:attribute> + <xsl:attribute name="type"><xsl:value-of select="@type"/></xsl:attribute> + </field> +</xsl:template> + +<xsl:template match="frames" mode="prepare2"> + <frames> + <xsl:copy-of select="@protocol"/> + <xsl:apply-templates mode="prepare2"/> + </frames> +</xsl:template> + +<xsl:template match="class" mode="prepare2"> + <class> + <xsl:copy-of select="@*"/> + <xsl:apply-templates mode="prepare2"/> + </class> +</xsl:template> + +<xsl:template match="frame" mode="prepare2"> + <xsl:element name="{name()}"> + <xsl:copy-of select="@*"/> + <xsl:apply-templates mode="prepare2" select="field"/> + </xsl:element> +</xsl:template> + +<xsl:template match="domain" mode="prepare2"></xsl:template> + +</xsl:stylesheet> diff --git a/cpp/etc/stylesheets/prepare3.xsl b/cpp/etc/stylesheets/prepare3.xsl new file mode 100644 index 0000000000..27a4764e4f --- /dev/null +++ b/cpp/etc/stylesheets/prepare3.xsl @@ -0,0 +1,54 @@ +<?xml version='1.0'?> +<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amqp="http://amqp.org"> + +<xsl:import href="utils.xsl"/> + +<xsl:output indent="yes"/> + +<!-- final preparation of the model --> + +<xsl:template match="/"> + <xsl:apply-templates mode="prepare3"/> +</xsl:template> + +<xsl:template match="frames" mode="prepare3"> + <frames> + <xsl:copy-of select="@protocol"/> + <xsl:apply-templates mode="prepare3"/> + </frames> +</xsl:template> + +<xsl:template match="class" mode="prepare3"> + <class> + <xsl:copy-of select="@*"/> + <xsl:apply-templates mode="prepare3"/> + </class> +</xsl:template> + +<xsl:template match="frame" mode="prepare3"> + <xsl:element name="frame"> + <xsl:copy-of select="@*"/> + <xsl:if test="field[@type='bit']"> + <xsl:attribute name="has-bit-field">true</xsl:attribute> + <xsl:attribute name="bit-field-count"><xsl:value-of select="count(field[@type='bit'])"/></xsl:attribute> + </xsl:if> + <xsl:apply-templates mode="prepare3"/> + </xsl:element> +</xsl:template> + + +<xsl:template match="field" mode="prepare3"> + <field> + <xsl:attribute name="type"><xsl:value-of select="@type"/></xsl:attribute> + <!-- ensure the field name is processed to be a valid java name --> + <xsl:attribute name="name"><xsl:value-of select="amqp:field-name(@name)"/></xsl:attribute> + <!-- add some attributes to make code generation easier --> + <xsl:attribute name="cpp-type"><xsl:value-of select="amqp:cpp-type(@type)"/></xsl:attribute> + <xsl:attribute name="cpp-arg-type"><xsl:value-of select="amqp:cpp-arg-type(@type)"/></xsl:attribute> + <xsl:if test="@type='bit'"> + <xsl:attribute name="boolean-index"><xsl:number count="field[@type='bit']"/></xsl:attribute> + </xsl:if> + </field> +</xsl:template> + +</xsl:stylesheet> diff --git a/cpp/etc/stylesheets/registry.xsl b/cpp/etc/stylesheets/registry.xsl new file mode 100644 index 0000000000..a818a0a871 --- /dev/null +++ b/cpp/etc/stylesheets/registry.xsl @@ -0,0 +1,12 @@ +<?xml version='1.0'?> +<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amqp="http://amqp.org"> + +<xsl:import href="java.xsl"/> + +<xsl:output method="text" indent="yes" name="textFormat"/> + +<xsl:template match="/"> + <xsl:apply-templates mode="generate-registry" select="registries"/> +</xsl:template> + +</xsl:stylesheet> diff --git a/cpp/etc/stylesheets/utils.xsl b/cpp/etc/stylesheets/utils.xsl new file mode 100644 index 0000000000..70743112a9 --- /dev/null +++ b/cpp/etc/stylesheets/utils.xsl @@ -0,0 +1,194 @@ +<?xml version='1.0'?> +<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:amqp="http://amqp.org"> + +<!-- This file contains functions that are used in the generation of the java classes for framing --> + +<!-- retrieve the java type of a given amq type --> +<xsl:function name="amqp:cpp-type"> + <xsl:param name="t"/> + <xsl:choose> + <xsl:when test="$t='octet'">u_int8_t</xsl:when> + <xsl:when test="$t='short'">u_int16_t</xsl:when> + <xsl:when test="$t='shortstr'">string</xsl:when> + <xsl:when test="$t='longstr'">string</xsl:when> + <xsl:when test="$t='bit'">bool</xsl:when> + <xsl:when test="$t='long'">u_int32_t</xsl:when> + <xsl:when test="$t='longlong'">u_int64_t</xsl:when> + <xsl:when test="$t='table'">FieldTable</xsl:when> + <xsl:otherwise>Object /*WARNING: undefined type*/</xsl:otherwise> + </xsl:choose> +</xsl:function> +<xsl:function name="amqp:cpp-arg-type"> + <xsl:param name="t"/> + <xsl:choose> + <xsl:when test="$t='octet'">u_int8_t</xsl:when> + <xsl:when test="$t='short'">u_int16_t</xsl:when> + <xsl:when test="$t='shortstr'">const string&</xsl:when> + <xsl:when test="$t='longstr'">const string&</xsl:when> + <xsl:when test="$t='bit'">bool</xsl:when> + <xsl:when test="$t='long'">u_int32_t</xsl:when> + <xsl:when test="$t='longlong'">u_int64_t</xsl:when> + <xsl:when test="$t='table'">FieldTable&</xsl:when> + <xsl:otherwise>Object /*WARNING: undefined type*/</xsl:otherwise> + </xsl:choose> +</xsl:function> + +<!-- retrieve the code to get the field size of a given amq type --> +<xsl:function name="amqp:field-length"> + <xsl:param name="f"/> + <xsl:choose> + <xsl:when test="$f/@type='bit' and $f/@boolean-index=1"> + <xsl:value-of select="concat('1 /*', $f/@name, '*/')"/> + </xsl:when> + <xsl:when test="$f/@type='bit' and $f/@boolean-index > 1"> + <xsl:value-of select="concat('0 /*', $f/@name, '*/')"/> + </xsl:when> + <xsl:when test="$f/@type='char'"> + <xsl:value-of select="concat('1 /*', $f/@name, '*/')"/> + </xsl:when> + <xsl:when test="$f/@type='octet'"> + <xsl:value-of select="concat('1 /*', $f/@name, '*/')"/> + </xsl:when> + <xsl:when test="$f/@type='short'"> + <xsl:value-of select="concat('2 /*', $f/@name, '*/')"/> + </xsl:when> + <xsl:when test="$f/@type='long'"> + <xsl:value-of select="concat('4 /*', $f/@name, '*/')"/> + </xsl:when> + <xsl:when test="$f/@type='longlong'"> + <xsl:value-of select="concat('8 /*', $f/@name, '*/')"/> + </xsl:when> + <xsl:when test="$f/@type='shortstr'"> + <xsl:value-of select="concat('1 + ', $f/@name, '.length()')"/> + </xsl:when> + <xsl:when test="$f/@type='longstr'"> + <xsl:value-of select="concat('4 + ', $f/@name, '.length()')"/> + </xsl:when> + <xsl:when test="$f/@type='table'"> + <xsl:value-of select="concat($f/@name, '.size()')"/> + </xsl:when> + <xsl:otherwise><xsl:text>/* WARNING: COULD NOT DETERMINE FIELD SIZE */</xsl:text></xsl:otherwise> + </xsl:choose> +</xsl:function> + +<!-- retrieve the code to encode a field of a given amq type --> +<!-- Note: + This method will not provide an encoder for a bit field. + Bit fields should be encoded together separately. --> + +<xsl:function name="amqp:encoder"> + <xsl:param name="f"/> + <xsl:choose> + <xsl:when test="$f/@type='octet'"> + <xsl:value-of select="concat('buffer.putOctet(', $f/@name, ')')"/> + </xsl:when> + <xsl:when test="$f/@type='short'"> + <xsl:value-of select="concat('buffer.putShort(', $f/@name, ')')"/> + </xsl:when> + <xsl:when test="$f/@type='long'"> + <xsl:value-of select="concat('buffer.putLong(', $f/@name, ')')"/> + </xsl:when> + <xsl:when test="$f/@type='longlong'"> + <xsl:value-of select="concat('buffer.putLongLong(', $f/@name, ')')"/> + </xsl:when> + <xsl:when test="$f/@type='shortstr'"> + <xsl:value-of select="concat('buffer.putShortString(', $f/@name, ')')"/> + </xsl:when> + <xsl:when test="$f/@type='longstr'"> + <xsl:value-of select="concat('buffer.putLongString(', $f/@name, ')')"/> + </xsl:when> + <xsl:when test="$f/@type='table'"> + <xsl:value-of select="concat('buffer.putFieldTable(', $f/@name, ')')"/> + </xsl:when> + <xsl:otherwise><xsl:text>/* WARNING: COULD NOT DETERMINE ENCODER */</xsl:text></xsl:otherwise> + </xsl:choose> +</xsl:function> + +<!-- retrieve the code to decode a field of a given amq type --> +<xsl:function name="amqp:decoder"> + <xsl:param name="f"/> + <xsl:choose> + <xsl:when test="$f/@type='bit'"> + <xsl:value-of select="concat($f/@name, ' = (1 << (', $f/@boolean-index, ' - 1)) & flags;')"/> + </xsl:when> + <xsl:when test="$f/@type='octet'"> + <xsl:value-of select="concat($f/@name, ' = buffer.getOctet()')"/> + </xsl:when> + <xsl:when test="$f/@type='short'"> + <xsl:value-of select="concat($f/@name, ' = buffer.getShort()')"/> + </xsl:when> + <xsl:when test="$f/@type='long'"> + <xsl:value-of select="concat($f/@name, ' = buffer.getLong()')"/> + </xsl:when> + <xsl:when test="$f/@type='longlong'"> + <xsl:value-of select="concat($f/@name, ' = buffer.getLongLong()')"/> + </xsl:when> + <xsl:when test="$f/@type='shortstr'"> + <xsl:value-of select="concat('buffer.getShortString(', $f/@name), ')'"/> + </xsl:when> + <xsl:when test="$f/@type='longstr'"> + <xsl:value-of select="concat('buffer.getLongString(', $f/@name), ')'"/> + </xsl:when> + <xsl:when test="$f/@type='table'"> + <xsl:value-of select="concat('buffer.getFieldTable(', $f/@name, ')')"/> + </xsl:when> + <xsl:otherwise><xsl:text>/* WARNING: COULD NOT DETERMINE DECODER */</xsl:text></xsl:otherwise> + </xsl:choose> +</xsl:function> + +<!-- create the class name for a frame, based on class and method (passed in) --> +<xsl:function name="amqp:class-name"> + <xsl:param name="class"/> + <xsl:param name="method"/> + <xsl:value-of select="concat(amqp:upper-first($class),amqp:upper-first(amqp:field-name($method)), 'Body')"/> +</xsl:function> + +<!-- create the class name for a frame, based on class and method (passed in) --> +<xsl:function name="amqp:method-name"> + <xsl:param name="class"/> + <xsl:param name="method"/> + <xsl:value-of select="concat(translate($class, '- ', '__'), '_', translate($method, '- ', '__'))"/> +</xsl:function> + +<!-- get a valid field name, processing spaces and '-'s where appropriate --> +<xsl:function name="amqp:field-name"> + <xsl:param name="name"/> + <xsl:choose> + <xsl:when test="contains($name, ' ')"> + <xsl:value-of select="concat(substring-before($name, ' '), amqp:upper-first(substring-after($name, ' ')))"/> + </xsl:when> + <xsl:when test="contains($name, '-')"> + <xsl:value-of select="concat(substring-before($name, '-'), amqp:upper-first(substring-after($name, '-')))"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$name"/> + </xsl:otherwise> + </xsl:choose> +</xsl:function> + +<!-- convert the first character of the input to upper-case --> +<xsl:function name="amqp:upper-first"> + <xsl:param name="in"/> + <xsl:value-of select="concat(upper-case(substring($in, 1, 1)), substring($in, 2))"/> +</xsl:function> + + +<xsl:function name="amqp:keyword-check"> + <xsl:param name="in"/> + <xsl:choose> + <xsl:when test="contains($in, 'delete')"> + <xsl:value-of select="concat($in, '_')"/> + </xsl:when> + <xsl:when test="contains($in, 'string')"> + <xsl:value-of select="concat($in, '_')"/> + </xsl:when> + <xsl:when test="contains($in, 'return')"> + <xsl:value-of select="concat($in, '_')"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$in"/> + </xsl:otherwise> + </xsl:choose> +</xsl:function> + +</xsl:stylesheet> |
