diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2008-05-07 15:52:31 +0000 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2008-05-07 15:52:31 +0000 |
commit | ce7c6f7be5c55999d8a93b22ec5df83c684e293a (patch) | |
tree | 16ed4a8ac393f495cbb7e1b4643f196c43e2a912 /tools | |
parent | 7cd808417a5f6256e95340850bc292b5d819a94c (diff) |
Update code-gen tools from telepathy-glib
Diffstat (limited to 'tools')
-rw-r--r-- | tools/c-constants-generator.xsl | 182 | ||||
-rw-r--r-- | tools/c-interfaces-generator.xsl | 2 | ||||
-rw-r--r-- | tools/check-coding-style.mk | 4 | ||||
-rw-r--r-- | tools/doc-generator.xsl | 352 | ||||
-rw-r--r-- | tools/glib-ginterface-gen.py | 79 | ||||
-rw-r--r-- | tools/libglibcodegen.py | 27 |
6 files changed, 532 insertions, 114 deletions
diff --git a/tools/c-constants-generator.xsl b/tools/c-constants-generator.xsl index 2838ee17e..18b2e495d 100644 --- a/tools/c-constants-generator.xsl +++ b/tools/c-constants-generator.xsl @@ -12,7 +12,7 @@ version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. +Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software @@ -58,22 +58,31 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. </xsl:otherwise> </xsl:choose> </xsl:variable> -/** - * <xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/>: -<xsl:apply-templates mode="flag-or-enumvalue-gtkdoc"> - <xsl:with-param name="value-prefix" select="$value-prefix"/> -</xsl:apply-templates> * -<xsl:if test="tp:docstring"> - * <![CDATA[<xsl:value-of select="translate(string (tp:docstring), ' ', ' ')"/>]]> - * -</xsl:if> * Bitfield/set of flags generated from the Telepathy specification. - */ -typedef enum { -<xsl:apply-templates> - <xsl:with-param name="value-prefix" select="$value-prefix"/> -</xsl:apply-templates>} <xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/>; - -</xsl:template> + <xsl:text>/** </xsl:text> + <xsl:text> * </xsl:text> + <xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/> + <xsl:text>: </xsl:text> + <xsl:apply-templates mode="flag-or-enumvalue-gtkdoc"> + <xsl:with-param name="value-prefix" select="$value-prefix"/> + </xsl:apply-templates> + <xsl:text> * </xsl:text> + <xsl:if test="tp:docstring"> + <xsl:text> * <![CDATA[</xsl:text> + <xsl:value-of select="translate(string (tp:docstring), ' ', ' ')"/> + <xsl:text>]]> </xsl:text> + <xsl:text> * </xsl:text> + </xsl:if> + <xsl:text> * Bitfield/set of flags generated from the Telepathy specification. </xsl:text> + <xsl:text> */ </xsl:text> + <xsl:text>typedef enum { </xsl:text> + <xsl:apply-templates> + <xsl:with-param name="value-prefix" select="$value-prefix"/> + </xsl:apply-templates> + <xsl:text>} </xsl:text> + <xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/> + <xsl:text>; </xsl:text> + <xsl:text> </xsl:text> + </xsl:template> <xsl:template match="text()" mode="flag-or-enumvalue-gtkdoc"/> @@ -129,29 +138,46 @@ typedef enum { </xsl:otherwise> </xsl:choose> </xsl:variable> -/** - * <xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/>: -<xsl:apply-templates mode="flag-or-enumvalue-gtkdoc"> - <xsl:with-param name="value-prefix" select="$value-prefix"/> -</xsl:apply-templates> * -<xsl:if test="tp:docstring"> - * <![CDATA[[<xsl:value-of select="translate(string (tp:docstring), ' ', ' ')"/>]]> - * -</xsl:if> * Enumeration generated from the Telepathy specification. - */ -typedef enum { -<xsl:apply-templates> - <xsl:with-param name="value-prefix" select="$value-prefix"/> -</xsl:apply-templates>} <xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/>; - -/** - * NUM_<xsl:value-of select="translate(concat($upper-case-prefix, $name-plural), $lower, $upper)"/>: - * - * 1 higher than the highest valid value of #<xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/>. - */ -#define NUM_<xsl:value-of select="translate(concat($upper-case-prefix, $name-plural), $lower, $upper)"/> (<xsl:value-of select="tp:enumvalue[position() = last()]/@value"/>+1) - -</xsl:template> + <xsl:text>/** </xsl:text> + <xsl:text> * </xsl:text> + <xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/> + <xsl:text>: </xsl:text> + <xsl:apply-templates mode="flag-or-enumvalue-gtkdoc"> + <xsl:with-param name="value-prefix" select="$value-prefix"/> + </xsl:apply-templates> + <xsl:text> * </xsl:text> + <xsl:if test="tp:docstring"> + <xsl:text> * <![CDATA[</xsl:text> + <xsl:value-of select="translate(string (tp:docstring), ' ', ' ')"/> + <xsl:text>]]> </xsl:text> + <xsl:text> * </xsl:text> + </xsl:if> + <xsl:text> * Bitfield/set of flags generated from the Telepathy specification. </xsl:text> + <xsl:text> */ </xsl:text> + <xsl:text>typedef enum { </xsl:text> + <xsl:apply-templates> + <xsl:with-param name="value-prefix" select="$value-prefix"/> + </xsl:apply-templates> + <xsl:text>} </xsl:text> + <xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/> + <xsl:text>; </xsl:text> + <xsl:text> </xsl:text> + <xsl:text>/** </xsl:text> + <xsl:text> * NUM_</xsl:text> + <xsl:value-of select="translate(concat($upper-case-prefix, $name-plural), $lower, $upper)"/> + <xsl:text>: </xsl:text> + <xsl:text> * </xsl:text> + <xsl:text> * 1 higher than the highest valid value of #</xsl:text> + <xsl:value-of select="translate(concat($mixed-case-prefix, $name), '_', '')"/> + <xsl:text>. </xsl:text> + <xsl:text> */ </xsl:text> + <xsl:text>#define NUM_</xsl:text> + <xsl:value-of select="translate(concat($upper-case-prefix, $name-plural), $lower, $upper)"/> + <xsl:text> (</xsl:text> + <xsl:value-of select="tp:enumvalue[position() = last()]/@value"/> + <xsl:text>+1) </xsl:text> + <xsl:text> </xsl:text> + </xsl:template> <xsl:template match="tp:flags/tp:flag"> <xsl:param name="value-prefix"/> @@ -168,11 +194,20 @@ typedef enum { <xsl:variable name="name" select="translate(concat($upper-case-prefix, $value-prefix, '_', $suffix), $lower, $upper)"/> <xsl:if test="@name and @suffix and @name != @suffix"> - <xsl:message terminate="yes">Flag name <xsl:value-of select="@name"/> != suffix <xsl:value-of select="@suffix"/> -</xsl:message> + <xsl:message terminate="yes"> + <xsl:text>Flag name </xsl:text> + <xsl:value-of select="@name"/> + <xsl:text> != suffix </xsl:text> + <xsl:value-of select="@suffix"/> + <xsl:text> </xsl:text> + </xsl:message> </xsl:if> - <xsl:text> </xsl:text><xsl:value-of select="$name"/> = <xsl:value-of select="@value"/>, -</xsl:template> + <xsl:text> </xsl:text> + <xsl:value-of select="$name"/> + <xsl:text> = </xsl:text> + <xsl:value-of select="@value"/> + <xsl:text>, </xsl:text> + </xsl:template> <xsl:template match="tp:enum/tp:enumvalue"> <xsl:param name="value-prefix"/> @@ -189,27 +224,36 @@ typedef enum { <xsl:variable name="name" select="translate(concat($upper-case-prefix, $value-prefix, '_', $suffix), $lower, $upper)"/> <xsl:if test="@name and @suffix and @name != @suffix"> - <xsl:message terminate="yes">Flag name <xsl:value-of select="@name"/> != suffix <xsl:value-of select="@suffix"/> -</xsl:message> + <xsl:message terminate="yes"> + <xsl:text>Enumvalue name </xsl:text> + <xsl:value-of select="@name"/> + <xsl:text> != suffix </xsl:text> + <xsl:value-of select="@suffix"/> + <xsl:text> </xsl:text> + </xsl:message> </xsl:if> <xsl:if test="preceding-sibling::tp:enumvalue and number(preceding-sibling::tp:enumvalue[1]/@value) > number(@value)"> - <xsl:message terminate="yes">Enum values must be in ascending numeric order, -but <xsl:value-of select="$name"/> is less than the previous value -</xsl:message> + <xsl:message terminate="yes"> + <xsl:text>Enum values must be in ascending numeric order, but </xsl:text> + <xsl:value-of select="$name"/> + <xsl:text> is less than the previous value</xsl:text> + </xsl:message> </xsl:if> - <xsl:text> </xsl:text><xsl:value-of select="$name"/> = <xsl:value-of select="@value"/>, -</xsl:template> + <xsl:text> </xsl:text> + <xsl:value-of select="$name"/> + <xsl:text> = </xsl:text> + <xsl:value-of select="@value"/> + <xsl:text>, </xsl:text> + </xsl:template> <xsl:template match="tp:flag"> - <xsl:message terminate="yes">tp:flag found outside tp:flags -</xsl:message> + <xsl:message terminate="yes">tp:flag found outside tp:flags </xsl:message> </xsl:template> <xsl:template match="tp:enumvalue"> - <xsl:message terminate="yes">tp:enumvalue found outside tp:enum -</xsl:message> + <xsl:message terminate="yes">tp:enumvalue found outside tp:enum </xsl:message> </xsl:template> <xsl:template match="text()"/> @@ -227,7 +271,8 @@ but <xsl:value-of select="$name"/> is less than the previous value <xsl:text>, version </xsl:text> <xsl:value-of select="tp:version"/> </xsl:if> - <xsl:text> </xsl:text> + <xsl:text> </xsl:text> + <xsl:text> </xsl:text> <xsl:for-each select="tp:copyright"> <xsl:value-of select="."/> <xsl:text> </xsl:text> @@ -235,21 +280,18 @@ but <xsl:value-of select="$name"/> is less than the previous value <xsl:value-of select="tp:license"/> <xsl:text> </xsl:text> <xsl:value-of select="tp:docstring"/> - <xsl:text> */ - -#ifdef __cplusplus -extern "C" { -#endif - -</xsl:text> + <xsl:text> </xsl:text> + <xsl:text> */ </xsl:text> + <xsl:text> </xsl:text> + <xsl:text>#ifdef __cplusplus </xsl:text> + <xsl:text>extern "C" { </xsl:text> + <xsl:text>#endif </xsl:text> + <xsl:text> </xsl:text> <xsl:apply-templates/> - <xsl:text> - -#ifdef __cplusplus -} -#endif - -</xsl:text> + <xsl:text> </xsl:text> + <xsl:text>#ifdef __cplusplus </xsl:text> + <xsl:text>} </xsl:text> + <xsl:text>#endif </xsl:text> </xsl:template> </xsl:stylesheet> diff --git a/tools/c-interfaces-generator.xsl b/tools/c-interfaces-generator.xsl index 38cbd7e51..f965a7051 100644 --- a/tools/c-interfaces-generator.xsl +++ b/tools/c-interfaces-generator.xsl @@ -12,7 +12,7 @@ version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. +Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software diff --git a/tools/check-coding-style.mk b/tools/check-coding-style.mk index de3f6ec72..1499f2f05 100644 --- a/tools/check-coding-style.mk +++ b/tools/check-coding-style.mk @@ -1,6 +1,4 @@ -check-local: check-coding-style - -check-coding-style: +check-local:: @fail=0; \ if test -n "$(check_misc_sources)"; then \ tools_dir=$(top_srcdir)/tools \ diff --git a/tools/doc-generator.xsl b/tools/doc-generator.xsl index dbd761f9a..a820e46d8 100644 --- a/tools/doc-generator.xsl +++ b/tools/doc-generator.xsl @@ -2,7 +2,7 @@ The master copy of this stylesheet is in the Telepathy spec repository - please make any changes there. -Copyright (C) 2006, 2007 Collabora Limited +Copyright (C) 2006-2008 Collabora Limited This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -21,11 +21,18 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tp="http://telepathy.freedesktop.org/wiki/DbusSpec#extensions-v0" - exclude-result-prefixes="tp"> + xmlns:html="http://www.w3.org/1999/xhtml" + exclude-result-prefixes="tp html"> <!--Don't move the declaration of the HTML namespace up here - XMLNSs don't work ideally in the presence of two things that want to use the absence of a prefix, sadly. --> + <xsl:template match="html:*" mode="html"> + <xsl:copy> + <xsl:apply-templates mode="html"/> + </xsl:copy> + </xsl:template> + <xsl:template match="*" mode="identity"> <xsl:copy> <xsl:apply-templates mode="identity"/> @@ -33,7 +40,13 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA </xsl:template> <xsl:template match="tp:docstring"> - <xsl:apply-templates select="node()" mode="identity"/> + <xsl:apply-templates select="text() | html:* | tp:rationale" mode="html"/> + </xsl:template> + + <xsl:template match="tp:rationale" mode="html"> + <div xmlns="http://www.w3.org/1999/xhtml" class="rationale"> + <xsl:apply-templates select="node()" mode="html"/> + </div> </xsl:template> <xsl:template match="tp:errors"> @@ -41,6 +54,43 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA <xsl:apply-templates/> </xsl:template> + <xsl:template match="tp:generic-types"> + <h1 xmlns="http://www.w3.org/1999/xhtml">Generic types</h1> + <xsl:call-template name="do-types"/> + </xsl:template> + + <xsl:template name="do-types"> + <xsl:if test="tp:simple-type"> + <h2 xmlns="http://www.w3.org/1999/xhtml">Simple types</h2> + <xsl:apply-templates select="tp:simple-type"/> + </xsl:if> + + <xsl:if test="tp:enum"> + <h2 xmlns="http://www.w3.org/1999/xhtml">Enumerated types:</h2> + <xsl:apply-templates select="tp:enum"/> + </xsl:if> + + <xsl:if test="tp:flags"> + <h2 xmlns="http://www.w3.org/1999/xhtml">Sets of flags:</h2> + <xsl:apply-templates select="tp:flags"/> + </xsl:if> + + <xsl:if test="tp:struct"> + <h2 xmlns="http://www.w3.org/1999/xhtml">Structure types</h2> + <xsl:apply-templates select="tp:struct"/> + </xsl:if> + + <xsl:if test="tp:mapping"> + <h2 xmlns="http://www.w3.org/1999/xhtml">Mapping types</h2> + <xsl:apply-templates select="tp:mapping"/> + </xsl:if> + + <xsl:if test="tp:external-type"> + <h2 xmlns="http://www.w3.org/1999/xhtml">Types defined elsewhere</h2> + <dl><xsl:apply-templates select="tp:external-type"/></dl> + </xsl:if> + </xsl:template> + <xsl:template match="tp:error"> <h2 xmlns="http://www.w3.org/1999/xhtml"><a name="{concat(../@namespace, '.', translate(@name, ' ', ''))}"></a><xsl:value-of select="concat(../@namespace, '.', translate(@name, ' ', ''))"/></h2> <xsl:apply-templates select="tp:docstring"/> @@ -53,7 +103,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA </xsl:template> <xsl:template match="/tp:spec/tp:license"> <div xmlns="http://www.w3.org/1999/xhtml" class="license"> - <xsl:apply-templates mode="identity"/> + <xsl:apply-templates mode="html"/> </div> </xsl:template> @@ -63,6 +113,14 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA <xsl:template match="interface"> <h1 xmlns="http://www.w3.org/1999/xhtml"><a name="{@name}"></a><xsl:value-of select="@name"/></h1> + <xsl:if test="@tp:causes-havoc"> + <p xmlns="http://www.w3.org/1999/xhtml" class="causes-havoc"> + This interface is <xsl:value-of select="@tp:causes-havoc"/> + and is likely to cause havoc to your API/ABI if bindings are generated. + Don't include it in libraries that care about compatibility. + </p> + </xsl:if> + <xsl:if test="tp:requires"> <p>Implementations of this interface must also implement:</p> <ul xmlns="http://www.w3.org/1999/xhtml"> @@ -96,30 +154,45 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA <xsl:choose> <xsl:when test="tp:property"> - <h2 xmlns="http://www.w3.org/1999/xhtml">Properties:</h2> + <h2 xmlns="http://www.w3.org/1999/xhtml">Telepathy Properties:</h2> + <p xmlns="http://www.w3.org/1999/xhtml">Accessed using the + <a href="#org.freedesktop.Telepathy.Properties">Telepathy + Properties</a> interface.</p> <dl xmlns="http://www.w3.org/1999/xhtml"> <xsl:apply-templates select="tp:property"/> </dl> </xsl:when> <xsl:otherwise> - <p xmlns="http://www.w3.org/1999/xhtml">Interface has no properties.</p> + <p xmlns="http://www.w3.org/1999/xhtml">Interface has no Telepathy + properties.</p> </xsl:otherwise> </xsl:choose> - <xsl:if test="tp:enum"> - <h2 xmlns="http://www.w3.org/1999/xhtml">Enumerated types:</h2> - <xsl:apply-templates select="tp:enum"/> - </xsl:if> + <xsl:choose> + <xsl:when test="property"> + <h2 xmlns="http://www.w3.org/1999/xhtml">D-Bus core Properties:</h2> + <p xmlns="http://www.w3.org/1999/xhtml">Accessed using the + org.freedesktop.DBus.Properties interface.</p> + <dl xmlns="http://www.w3.org/1999/xhtml"> + <xsl:apply-templates select="property"/> + </dl> + </xsl:when> + <xsl:otherwise> + <p xmlns="http://www.w3.org/1999/xhtml">Interface has no D-Bus core + properties.</p> + </xsl:otherwise> + </xsl:choose> - <xsl:if test="tp:flags"> - <h2 xmlns="http://www.w3.org/1999/xhtml">Sets of flags:</h2> - <xsl:apply-templates select="tp:flags"/> - </xsl:if> + <xsl:call-template name="do-types"/> </xsl:template> <xsl:template match="tp:flags"> - <h3 xmlns="http://www.w3.org/1999/xhtml"><xsl:value-of select="@name"/></h3> + <h3> + <a name="type-{@name}"> + <xsl:value-of select="@name"/> + </a> + </h3> <xsl:apply-templates select="tp:docstring" /> <dl xmlns="http://www.w3.org/1999/xhtml"> <xsl:variable name="value-prefix"> @@ -148,7 +221,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA <xsl:template match="tp:enum"> <h3 xmlns="http://www.w3.org/1999/xhtml"> - <a name="{concat(../@name, concat('.', @name))}"> + <a name="type-{@name}"> <xsl:value-of select="@name"/> </a> </h3> @@ -178,6 +251,36 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA </dl> </xsl:template> + <xsl:template match="property"> + <dt xmlns="http://www.w3.org/1999/xhtml"> + <a name="{concat(../@name, '.', @name)}"> + <code><xsl:value-of select="@name"/></code> + </a> + <xsl:text> - </xsl:text> + <code><xsl:value-of select="@type"/></code> + <xsl:call-template name="parenthesized-tp-type"/> + <xsl:text>, </xsl:text> + <xsl:choose> + <xsl:when test="@access = 'read'"> + <xsl:text>read-only</xsl:text> + </xsl:when> + <xsl:when test="@access = 'write'"> + <xsl:text>write-only</xsl:text> + </xsl:when> + <xsl:when test="@access = 'readwrite'"> + <xsl:text>read/write</xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:text>access: </xsl:text> + <code><xsl:value-of select="@access"/></code> + </xsl:otherwise> + </xsl:choose> + </dt> + <dd xmlns="http://www.w3.org/1999/xhtml"> + <xsl:apply-templates select="tp:docstring"/> + </dd> + </xsl:template> + <xsl:template match="tp:property"> <dt xmlns="http://www.w3.org/1999/xhtml"> <xsl:if test="@name"> @@ -190,6 +293,119 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA </dd> </xsl:template> + <xsl:template match="tp:mapping"> + <div xmlns="http://www.w3.org/1999/xhtml" class="struct"> + <h3> + <a name="type-{@name}"> + <xsl:value-of select="@name"/> + </a> - a{ + <xsl:for-each select="tp:member"> + <xsl:value-of select="@type"/> + <xsl:text>: </xsl:text> + <xsl:value-of select="@name"/> + <xsl:if test="position() != last()"> → </xsl:if> + </xsl:for-each> + } + </h3> + <div class="docstring"> + <xsl:apply-templates select="tp:docstring"/> + <xsl:if test="string(@array-name) != ''"> + <p>In bindings that need a separate name, arrays of + <xsl:value-of select="@name"/> should be called + <xsl:value-of select="@array-name"/>.</p> + </xsl:if> + </div> + <div> + <h4>Members</h4> + <dl> + <xsl:apply-templates select="tp:member" mode="members-in-docstring"/> + </dl> + </div> + </div> + </xsl:template> + + <xsl:template match="tp:docstring" mode="in-index"/> + + <xsl:template match="tp:simple-type | tp:enum | tp:flags | tp:external-type" + mode="in-index"> + - <xsl:value-of select="@type"/> + </xsl:template> + + <xsl:template match="tp:simple-type"> + <div xmlns="http://www.w3.org/1999/xhtml" class="simple-type"> + <h3> + <a name="type-{@name}"> + <xsl:value-of select="@name"/> + </a> - <xsl:value-of select="@type"/> + </h3> + <div class="docstring"> + <xsl:apply-templates select="tp:docstring"/> + </div> + </div> + </xsl:template> + + <xsl:template match="tp:external-type"> + <div xmlns="http://www.w3.org/1999/xhtml" class="external-type"> + <dt> + <a name="type-{@name}"> + <xsl:value-of select="@name"/> + </a> - <xsl:value-of select="@type"/> + </dt> + <dd>Defined by: <xsl:value-of select="@from"/></dd> + </div> + </xsl:template> + + <xsl:template match="tp:struct" mode="in-index"> + - ( <xsl:for-each select="tp:member"> + <xsl:value-of select="@type"/> + <xsl:if test="position() != last()">, </xsl:if> + </xsl:for-each> ) + </xsl:template> + + <xsl:template match="tp:mapping" mode="in-index"> + - a{ <xsl:for-each select="tp:member"> + <xsl:value-of select="@type"/> + <xsl:if test="position() != last()"> → </xsl:if> + </xsl:for-each> } + </xsl:template> + + <xsl:template match="tp:struct"> + <div xmlns="http://www.w3.org/1999/xhtml" class="struct"> + <h3> + <a name="type-{@name}"> + <xsl:value-of select="@name"/> + </a> - ( + <xsl:for-each select="tp:member"> + <xsl:value-of select="@type"/> + <xsl:text>: </xsl:text> + <xsl:value-of select="@name"/> + <xsl:if test="position() != last()">, </xsl:if> + </xsl:for-each> + ) + </h3> + <div class="docstring"> + <xsl:apply-templates select="tp:docstring"/> + </div> + <xsl:choose> + <xsl:when test="string(@array-name) != ''"> + <p>In bindings that need a separate name, arrays of + <xsl:value-of select="@name"/> should be called + <xsl:value-of select="@array-name"/>.</p> + </xsl:when> + <xsl:otherwise> + <p>Arrays of <xsl:value-of select="@name"/> don't generally + make sense.</p> + </xsl:otherwise> + </xsl:choose> + <div> + <h4>Members</h4> + <dl> + <xsl:apply-templates select="tp:member" mode="members-in-docstring"/> + </dl> + </div> + </div> + </xsl:template> + <xsl:template match="method"> <div xmlns="http://www.w3.org/1999/xhtml" class="method"> <h3 xmlns="http://www.w3.org/1999/xhtml"> @@ -247,10 +463,67 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA </div> </xsl:template> + <xsl:template name="parenthesized-tp-type"> + <xsl:if test="@tp:type"> + <xsl:variable name="tp-type" select="@tp:type"/> + <xsl:variable name="single-type"> + <xsl:choose> + <xsl:when test="contains($tp-type, '[]')"> + <xsl:value-of select="substring-before($tp-type, '[]')"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="$tp-type"/> + </xsl:otherwise> + </xsl:choose> + </xsl:variable> + <xsl:choose> + <xsl:when test="//tp:simple-type[@name=$tp-type]" /> + <xsl:when test="//tp:simple-type[concat(@name, '[]')=$tp-type]" /> + <xsl:when test="//tp:struct[concat(@name, '[]')=$tp-type][string(@array-name) != '']" /> + <xsl:when test="//tp:mapping[concat(@name, '[]')=$tp-type][string(@array-name) != '']" /> + <xsl:when test="//tp:struct[@name=$tp-type]" /> + <xsl:when test="//tp:enum[@name=$tp-type]" /> + <xsl:when test="//tp:enum[concat(@name, '[]')=$tp-type]" /> + <xsl:when test="//tp:flags[@name=$tp-type]" /> + <xsl:when test="//tp:flags[concat(@name, '[]')=$tp-type]" /> + <xsl:when test="//tp:mapping[@name=$tp-type]" /> + <xsl:when test="//tp:external-type[concat(@name, '[]')=$tp-type]" /> + <xsl:when test="//tp:external-type[@name=$tp-type]" /> + <xsl:otherwise> + <xsl:message terminate="yes"> + <xsl:text>ERR: Unable to find type '</xsl:text> + <xsl:value-of select="$tp-type"/> + <xsl:text>' </xsl:text> + </xsl:message> + </xsl:otherwise> + </xsl:choose> + (<a href="#type-{$single-type}"><xsl:value-of select="$tp-type"/></a>) + </xsl:if> + </xsl:template> + + <xsl:template match="tp:member" mode="members-in-docstring"> + <dt xmlns="http://www.w3.org/1999/xhtml"> + <code><xsl:value-of select="@name"/></code> - + <code><xsl:value-of select="@type"/></code> + <xsl:call-template name="parenthesized-tp-type"/> + </dt> + <dd xmlns="http://www.w3.org/1999/xhtml"> + <xsl:choose> + <xsl:when test="tp:docstring"> + <xsl:apply-templates select="tp:docstring" /> + </xsl:when> + <xsl:otherwise> + <em>(undocumented)</em> + </xsl:otherwise> + </xsl:choose> + </dd> + </xsl:template> + <xsl:template match="arg" mode="parameters-in-docstring"> <dt xmlns="http://www.w3.org/1999/xhtml"> <code><xsl:value-of select="@name"/></code> - <code><xsl:value-of select="@type"/></code> + <xsl:call-template name="parenthesized-tp-type"/> </dt> <dd xmlns="http://www.w3.org/1999/xhtml"> <xsl:apply-templates select="tp:docstring" /> @@ -263,6 +536,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA <code><xsl:value-of select="@name"/></code> - </xsl:if> <code><xsl:value-of select="@type"/></code> + <xsl:call-template name="parenthesized-tp-type"/> </dt> <dd xmlns="http://www.w3.org/1999/xhtml"> <xsl:apply-templates select="tp:docstring"/> @@ -420,13 +694,14 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA float: right; font-style: italic; } - .method { + .method, .signal, .property { margin-left: 1em; margin-right: 4em; } - .signal { - margin-left: 1em; - margin-right: 4em; + .rationale { + font-style: italic; + border-left: 0.25em solid #808080; + padding-left: 0.5em; } </style> @@ -441,14 +716,39 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA <xsl:apply-templates select="tp:copyright"/> <xsl:apply-templates select="tp:license"/> <xsl:apply-templates select="tp:docstring"/> - <h2>Interfaces</h2> - <ul> - <xsl:for-each select="node/interface"> + + <h2>Interfaces</h2> + <ul> + <xsl:for-each select="//node/interface"> <li><code><a href="#{@name}"><xsl:value-of select="@name"/></a></code></li> - </xsl:for-each> - </ul> - <xsl:apply-templates select="node"/> + </xsl:for-each> + </ul> + + <xsl:apply-templates select="//node"/> + <xsl:apply-templates select="tp:generic-types"/> <xsl:apply-templates select="tp:errors"/> + + <h1>Index</h1> + <h2>Index of interfaces</h2> + <ul> + <xsl:for-each select="//node/interface"> + <li><code><a href="#{@name}"><xsl:value-of select="@name"/></a></code></li> + </xsl:for-each> + </ul> + <h2>Index of types</h2> + <ul> + <xsl:for-each select="//tp:simple-type | //tp:enum | //tp:flags | //tp:mapping | //tp:struct | //tp:external-type"> + <xsl:sort select="@name"/> + <li> + <code> + <a href="#type-{@name}"> + <xsl:value-of select="@name"/> + </a> + </code> + <xsl:apply-templates mode="in-index" select="."/> + </li> + </xsl:for-each> + </ul> </body> </html> </xsl:template> diff --git a/tools/glib-ginterface-gen.py b/tools/glib-ginterface-gen.py index f80613145..36f3242b0 100644 --- a/tools/glib-ginterface-gen.py +++ b/tools/glib-ginterface-gen.py @@ -16,11 +16,11 @@ # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Library General Public License for more details. +# Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import sys import os.path @@ -89,7 +89,11 @@ class Generator(object): interface = interfaces[0] self.iface_name = interface.getAttribute('name') - tmp = node.getAttribute('causes-havoc') + tmp = interface.getAttribute('tp:implement-service') + if tmp == "no": + return + + tmp = interface.getAttribute('tp:causes-havoc') if tmp and not self.allow_havoc: raise AssertionError('%s is %s' % (self.iface_name, tmp)) @@ -99,6 +103,9 @@ class Generator(object): methods = interface.getElementsByTagName('method') signals = interface.getElementsByTagName('signal') + properties = interface.getElementsByTagName('property') + # Don't put properties in dbus-glib glue + glue_properties = [] self.b('struct _%s%sClass {' % (self.Prefix, node_name_mixed)) self.b(' GTypeInterface parent_class;') @@ -196,16 +203,45 @@ class Generator(object): for signal in signals: base_init_code.extend(self.do_signal(signal)) - self.b('static void') - self.b('%s%s_base_init (gpointer klass)' + self.b('static inline void') + self.b('%s%s_base_init_once (gpointer klass G_GNUC_UNUSED)' % (self.prefix_, node_name_lc)) self.b('{') - self.b(' static gboolean initialized = FALSE;') - self.b('') - self.b(' if (initialized)') - self.b(' return;') + self.b(' static TpDBusPropertiesMixinPropInfo properties[%d] = {' + % (len(properties) + 1)) + + for m in properties: + access = m.getAttribute('access') + assert access in ('read', 'write', 'readwrite') + + if access == 'read': + flags = 'TP_DBUS_PROPERTIES_MIXIN_FLAG_READ' + elif access == 'write': + flags = 'TP_DBUS_PROPERTIES_MIXIN_FLAG_WRITE' + else: + flags = ('TP_DBUS_PROPERTIES_MIXIN_FLAG_READ | ' + 'TP_DBUS_PROPERTIES_MIXIN_FLAG_WRITE') + + self.b(' { 0, %s, "%s", 0, NULL, NULL }, /* %s */' + % (flags, m.getAttribute('type'), m.getAttribute('name'))) + + self.b(' { 0, 0, NULL, 0, NULL, NULL }') + self.b(' };') + self.b(' static TpDBusPropertiesMixinIfaceInfo interface =') + self.b(' { 0, properties, NULL, NULL };') self.b('') - self.b(' initialized = TRUE;') + self.b(' interface.dbus_interface = g_quark_from_static_string ' + '("%s");' % self.iface_name) + + for i, m in enumerate(properties): + self.b(' properties[%d].name = g_quark_from_static_string ("%s");' + % (i, m.getAttribute('name'))) + self.b(' properties[%d].type = %s;' + % (i, type_to_gtype(m.getAttribute('type'))[1])) + + self.b(' tp_svc_interface_set_dbus_properties_info (%s, &interface);' + % self.current_gtype) + self.b('') for s in base_init_code: self.b(s) @@ -215,6 +251,21 @@ class Generator(object): % (self.prefix_, node_name_lc)) self.b('}') + self.b('static void') + self.b('%s%s_base_init (gpointer klass)' + % (self.prefix_, node_name_lc)) + self.b('{') + self.b(' static gboolean initialized = FALSE;') + self.b('') + self.b(' if (!initialized)') + self.b(' {') + self.b(' initialized = TRUE;') + self.b(' %s%s_base_init_once (klass);' + % (self.prefix_, node_name_lc)) + self.b(' }') + # insert anything we need to do per implementation here + self.b('}') + self.h('') self.b('static const DBusGMethodInfo _%s%s_methods[] = {' @@ -235,7 +286,9 @@ class Generator(object): self.b(' %d,' % len(methods)) self.b('"' + method_blob.replace('\0', '\\0') + '",') self.b('"' + self.get_signal_glue(signals).replace('\0', '\\0') + '",') - self.b('"\\0"') + self.b('"' + + self.get_property_glue(glue_properties).replace('\0', '\\0') + + '",') self.b('};') self.b('') @@ -299,6 +352,9 @@ class Generator(object): return '\0'.join(info) + '\0\0' + # the implementation can be the same + get_property_glue = get_signal_glue + def get_method_impl_names(self, method): dbus_method_name = method.getAttribute('name') class_member_name = camelcase_to_lower(dbus_method_name) @@ -552,6 +608,7 @@ class Generator(object): def __call__(self): self.h('#include <glib-object.h>') self.h('#include <dbus/dbus-glib.h>') + self.h('#include <telepathy-glib/dbus-properties-mixin.h>') self.h('') self.h('G_BEGIN_DECLS') self.h('') diff --git a/tools/libglibcodegen.py b/tools/libglibcodegen.py index 025b13e4b..d465b7406 100644 --- a/tools/libglibcodegen.py +++ b/tools/libglibcodegen.py @@ -14,11 +14,11 @@ please make any changes there. # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Library General Public License for more details. +# Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA from string import ascii_letters, digits @@ -115,6 +115,22 @@ def escape_as_identifier(identifier): return ''.join(ret) +def get_docstring(element): + docstring = None + for x in element.childNodes: + if x.namespaceURI == NS_TP and x.localName == 'docstring': + docstring = x + if docstring is not None: + docstring = docstring.toxml().replace('\n', ' ').strip() + if docstring.startswith('<tp:docstring>'): + docstring = docstring[14:].lstrip() + if docstring.endswith('</tp:docstring>'): + docstring = docstring[:-15].rstrip() + if docstring in ('<tp:docstring/>', ''): + docstring = '' + return docstring + + def signal_to_marshal_type(signal): """ return a list of strings indicating the marshalling type for this signal. @@ -276,7 +292,7 @@ def type_to_gtype(s): elif s == 'ab': #boolean array return ("GArray *", "DBUS_TYPE_G_BOOLEAN_ARRAY", "BOXED", True) elif s == 'ao': #object path array - return ("GArray *", "DBUS_TYPE_G_OBJECT_ARRAY", "BOXED", True) + return ("GPtrArray *", "DBUS_TYPE_G_OBJECT_ARRAY", "BOXED", True) elif s == 'a{ss}': #hash table of string to string return ("GHashTable *", "DBUS_TYPE_G_STRING_STRING_HASHTABLE", "BOXED", False) elif s[:2] == 'a{': #some arbitrary hash tables @@ -297,3 +313,8 @@ def type_to_gtype(s): # we just don't know .. raise Exception, "don't know the GType for " + s + + +def xml_escape(s): + s = s.replace('&', '&').replace("'", ''').replace('"', '"') + return s.replace('<', '<').replace('>', '>') |