<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:annotation>
        <xs:documentation xml:lang="en">
            GAPI XML schema.
            Copyright 2013 Bertrand Lorentz.

            This program is free software; you can redistribute it and/or
            modify it under the terms of version 2 of the Lesser GNU General
            Public License as published by the Free Software Foundation.

            This program 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
            Lesser General Public License for more details.

            You should have received a copy of the GNU Lesser General Public
            License along with this program; if not, write to the
            Free Software	Foundation, Inc., 51 Franklin Street, Fifth Floor,
            Boston, MA  02110-1301  USA
        </xs:documentation>
    </xs:annotation>

    <!-- Top-level tag-->
	<xs:element name="api">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="namespace" type="namespaceType" maxOccurs="unbounded"/>
                <xs:element name="symbol" type="symbolType" maxOccurs="unbounded" minOccurs="0"/>
            </xs:sequence>
            <xs:attribute name="parser_version" type="xs:positiveInteger"/>
        </xs:complexType>
    </xs:element>

    <xs:complexType name="namespaceType">
        <xs:choice maxOccurs="unbounded">
            <xs:element name="enum" type="enumType"/>
            <xs:element name="callback" type="callbackType"/>
            <xs:element name="interface" type="interfaceType"/>
            <xs:element name="object" type="objectType"/>
            <xs:element name="struct" type="structType"/>
            <xs:element name="boxed" type="boxedType"/>
            <xs:element name="alias" type="aliasType"/>
            <xs:element name="class" type="classType"/>
        </xs:choice>
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="library" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="symbolType">
        <xs:attribute name="type" type="xs:string"/>
        <xs:attribute name="cname" type="xs:string"/>
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="default_value" type="xs:string" use="optional"/>
        <xs:attribute name="marshal_type" type="xs:string" use="optional"/>
        <xs:attribute name="call_fmt" type="xs:string" use="optional"/>
        <xs:attribute name="from_fmt" type="xs:string" use="optional"/>
    </xs:complexType>

    <!-- Definitions for Generatables -->
    <xs:complexType name="aliasType">
        <xs:sequence>
            <xs:element name="field" type="fieldType" maxOccurs="unbounded" minOccurs="0"/>
        </xs:sequence>
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="cname" type="xs:string"/>
        <xs:attribute name="type" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="boxedType">
        <xs:choice maxOccurs="unbounded" minOccurs="0">
            <xs:element name="method" type="methodType"/>
            <xs:element name="constructor" type="constructorType"/>
            <xs:element name="field" type="fieldType"/>
        </xs:choice>
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="cname" type="xs:string"/>
        <xs:attribute name="opaque" type="xs:boolean" use="optional"/>
        <xs:attribute name="hidden" type="xs:boolean" use="optional"/>
        <xs:attribute name="noequals" type="xs:boolean" use="optional"/>
        <xs:attribute name="nohash" type="xs:boolean" use="optional"/>
    </xs:complexType>

    <xs:complexType name="callbackType">
        <xs:sequence>
            <xs:element name="return-type" type="return-typeType"/>
            <xs:element name="parameters" minOccurs="0">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="parameter" type="method-parameterType" maxOccurs="unbounded" minOccurs="0"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="cname" type="xs:string"/>
        <xs:attribute name="hidden" type="xs:boolean" use="optional"/>
    </xs:complexType>

    <xs:complexType name="classType">
        <xs:sequence>
            <xs:element name="method" type="methodType" maxOccurs="unbounded" minOccurs="0"/>
        </xs:sequence>
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="cname" type="xs:string"/>
        <xs:attribute name="hidden" type="xs:boolean" use="optional"/>
        <xs:attribute name="internal" type="xs:boolean" use="optional"/>
    </xs:complexType>

    <xs:complexType name="enumType">
        <xs:sequence>
            <xs:element name="member" maxOccurs="unbounded" minOccurs="0">
                <xs:complexType>
                    <xs:attribute name="cname" type="xs:string"/>
                    <xs:attribute name="name" type="xs:string"/>
                    <xs:attribute name="value" type="xs:string"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="cname" type="xs:string"/>
        <xs:attribute name="gtype" type="xs:string" use="optional"/>
        <xs:attribute name="type" type="xs:string" use="optional"/>
        <xs:attribute name="deprecated" type="xs:boolean" use="optional"/>
        <xs:attribute name="hidden" type="xs:boolean" use="optional"/>
    </xs:complexType>

    <xs:complexType name="interfaceType">
        <xs:choice maxOccurs="unbounded" minOccurs="0">
            <xs:element name="class_struct" type="class_structType"/>
            <xs:element name="constructor" type="constructorType"/>
            <xs:element name="property" type="propertyType"/>
            <xs:element name="method" type="methodType"/>
            <xs:element name="virtual_method" type="virtual_methodType"/>
            <xs:element name="signal" type="signalType"/>
        </xs:choice>
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="cname" type="xs:string"/>
        <xs:attribute name="consume_only" type="xs:boolean" use="optional"/>
        <xs:attribute name="hidden" type="xs:boolean" use="optional"/>
    </xs:complexType>

    <xs:complexType name="objectType">
        <xs:choice maxOccurs="unbounded" minOccurs="0">
            <xs:element name="class_struct" type="class_structType"/>
            <xs:element name="implements" type="implementsType"/>
            <xs:element name="constructor" type="constructorType"/>
            <xs:element name="field" type="fieldType"/>
            <xs:element name="property" type="propertyType"/>
            <xs:element name="childprop" type="propertyType"/>
            <xs:element name="method" type="methodType"/>
            <xs:element name="virtual_method" type="virtual_methodType"/>
            <xs:element name="signal" type="signalType"/>
            <xs:element name="static-string" type="static-stringType"/>
            <xs:element name="custom-attribute" type="xs:string"/>
        </xs:choice>
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="cname" type="xs:string"/>
        <xs:attribute name="hidden" type="xs:boolean" use="optional"/>
        <xs:attribute name="parent" type="xs:string" use="optional"/>
    </xs:complexType>

    <xs:complexType name="structType">
        <xs:choice maxOccurs="unbounded" minOccurs="0">
            <xs:element name="method" type="methodType"/>
            <xs:element name="constructor" type="constructorType"/>
            <xs:element name="field" type="fieldType"/>
            <xs:element name="callback" type="callbackType"/>
        </xs:choice>
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="cname" type="xs:string"/>
        <xs:attribute name="deprecated" type="xs:boolean" use="optional"/>
        <xs:attribute name="hidden" type="xs:boolean" use="optional"/>
        <xs:attribute name="opaque" type="xs:boolean" use="optional"/>
    </xs:complexType>


    <!-- Definitions for the elements in Generatables -->
    <xs:complexType name="class_structType">
        <xs:choice maxOccurs="unbounded">
            <xs:element name="field" type="fieldType" maxOccurs="unbounded"/>
            <xs:element name="method" maxOccurs="unbounded" minOccurs="0">
                <xs:complexType>
                    <xs:attribute name="vm" type="xs:string" use="optional"/>
                    <xs:attribute name="signal_vm" type="xs:string" use="optional"/>
                </xs:complexType>
            </xs:element>
        </xs:choice>
        <xs:attribute name="cname" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="constructorType">
        <xs:choice maxOccurs="unbounded" minOccurs="0">
            <xs:element name="parameters">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="parameter" type="constructor-parameterType" maxOccurs="unbounded" minOccurs="0"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="return-type" type="return-typeType"/>
        </xs:choice>
        <xs:attribute name="cname" type="xs:string"/>
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="deprecated" type="xs:boolean" use="optional"/>
        <xs:attribute name="hidden" type="xs:boolean" use="optional"/>
        <xs:attribute name="preferred" type="xs:boolean" use="optional"/>
        <xs:attribute name="shared" type="xs:boolean" use="optional"/>
    </xs:complexType>

	<xs:complexType name="fieldType">
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="cname" type="xs:string"/>
        <xs:attribute name="type" type="xs:string"/>
        <xs:attribute name="array" type="xs:boolean" use="optional"/>
        <xs:attribute name="array_len" type="xs:positiveInteger" use="optional"/>
        <xs:attribute name="hidden" type="xs:boolean" use="optional"/>
        <xs:attribute name="access" type="xs:string" use="optional"/>
        <xs:attribute name="writeable" type="xs:boolean" use="optional"/>
        <xs:attribute name="bits" type="xs:positiveInteger" use="optional"/>
    </xs:complexType>

    <xs:complexType name="implementsType">
        <xs:sequence>
            <xs:element name="interface" maxOccurs="unbounded">
                <xs:complexType>
                    <xs:attribute name="cname" type="xs:string"/>
                    <xs:attribute name="hidden" type="xs:boolean" use="optional"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

   <xs:complexType name="methodType">
        <xs:sequence>
            <xs:element name="return-type" type="return-typeType"/>
            <xs:element name="parameters" minOccurs="0">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="parameter" type="method-parameterType" maxOccurs="unbounded" minOccurs="0"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="cname" type="xs:string"/>
        <xs:attribute name="shared" type="xs:boolean" use="optional"/>
        <xs:attribute name="new_flag" type="xs:boolean" use="optional"/>
        <xs:attribute name="library" type="xs:string" use="optional"/>
        <xs:attribute name="deprecated" type="xs:boolean" use="optional"/>
        <xs:attribute name="hidden" type="xs:boolean" use="optional"/>
    </xs:complexType>

    <xs:complexType name="propertyType">
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="cname" type="xs:string"/>
        <xs:attribute name="type" type="xs:string"/>
        <xs:attribute name="construct" type="xs:boolean" use="optional"/>
        <xs:attribute name="construct-only" type="xs:boolean" use="optional"/>
        <xs:attribute name="new_flag" type="xs:boolean" use="optional"/>
        <xs:attribute name="hidden" type="xs:boolean" use="optional"/>
        <xs:attribute name="readable" type="xs:boolean" use="optional"/>
        <xs:attribute name="writeable" type="xs:boolean" use="optional"/>
    </xs:complexType>

    <xs:complexType name="signalType">
        <xs:complexContent>
            <xs:extension base="methodType">
                <xs:attribute name="when" type="whenType" use="optional"/>
                <xs:attribute name="field_name" type="xs:string" use="optional"/>
                <xs:attribute name="block_glue" type="xs:boolean" use="optional"/>
                <xs:attribute name="manual" type="xs:boolean" use="optional"/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="static-stringType">
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="cname" type="xs:string"/>
        <xs:attribute name="value" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="virtual_methodType">
        <xs:complexContent>
            <xs:extension base="methodType">
                <xs:attribute name="override_in" type="override_inType" use="optional"/>
                <xs:attribute name="padding" type="xs:boolean" use="optional"/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <!-- Definitions for lower-level elements -->
    <xs:complexType name="parameterType">
        <xs:attribute name="type" type="xs:string"/>
        <xs:attribute name="name" type="xs:string"/>
        <xs:attribute name="array" type="xs:boolean" use="optional"/>
        <xs:attribute name="array_len" type="xs:positiveInteger" use="optional"/>
        <xs:attribute name="null_term_array" type="xs:boolean" use="optional"/>
        <xs:attribute name="ellipsis" type="xs:boolean" use="optional"/>
        <xs:attribute name="owned" type="xs:boolean" use="optional"/>
        <xs:attribute name="printf_format" type="xs:boolean" use="optional"/>
        <xs:attribute name="printf_format_args" type="xs:boolean" use="optional"/>
        <xs:attribute name="scope" type="scopeType" use="optional"/>
    </xs:complexType>

    <xs:complexType name="constructor-parameterType">
        <xs:complexContent>
            <xs:extension base="parameterType">
                <xs:attribute name="property_name" type="xs:string" use="optional"/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="method-parameterType">
        <xs:complexContent>
            <xs:extension base="parameterType">
                <xs:attribute name="pass_as" type="pass_asType" use="optional"/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="return-typeType">
        <xs:attribute name="type" type="xs:string"/>
        <xs:attribute name="element_type" type="xs:string" use="optional"/>
        <xs:attribute name="owned" type="xs:boolean" use="optional"/>
        <xs:attribute name="elements_owned" type="xs:boolean" use="optional"/>
        <xs:attribute name="null_term_array" type="xs:boolean" use="optional"/>
        <xs:attribute name="array_length_param" type="xs:string" use="optional"/>
    </xs:complexType>

    <!-- Definitions for allowed values -->
    <xs:simpleType name="pass_asType">
        <xs:restriction base="xs:string">
            <xs:enumeration value="out"/>
            <xs:enumeration value="ref"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="override_inType">
        <xs:restriction base="xs:string">
            <xs:enumeration value="declaring_class"/>
            <xs:enumeration value="implementing_class"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="scopeType">
        <xs:restriction base="xs:string">
            <xs:enumeration value="call"/>
            <xs:enumeration value="async"/>
            <xs:enumeration value="notify"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="whenType">
        <xs:restriction base="xs:string">
            <xs:enumeration value="CLEANUP"/>
            <xs:enumeration value="FIRST"/>
            <xs:enumeration value="LAST"/>
        </xs:restriction>
    </xs:simpleType>

</xs:schema>