Exemplo n.º 1
0
    def do_prop(self, prop):
        name = prop.getAttribute('name')
        access = prop.getAttribute('access')
        gettername = name
        settername = None

        sig = prop.getAttribute('type')
        tptype = prop.getAttributeNS(NS_TP, 'type')
        binding = binding_from_usage(sig, tptype, self.custom_lists, (sig, tptype) in self.externals, self.typesnamespace)

        if 'write' in access:
            settername = 'set' + name

        if 'read' in access:
            self.h("""
    /**
     * Asynchronous getter for the remote object property "%(name)s" of type %(val)s.
     *
%(docstring)s\
     *
     * \\return A pending variant which will emit finished when the property has been
     *          retrieved.
     */
    inline Tp::PendingVariant *%(gettername)s() const
    {
        return internalRequestProperty(QLatin1String("%(name)s"));
    }
""" % {'name' : name,
       'docstring' : format_docstring(prop, '     * ').replace('*/',
           '*/'),
       'val' : binding.val,
       'name' : name,
       'gettername' : 'requestProperty' + name})

        if 'write' in access:
            self.h("""
    /**
     * Asynchronous setter for the remote object property "%(name)s" of type %(type)s.
     *
%(docstring)s\
     *
     * \\return A pending operation which will emit finished when the property has been
     *          set.
     */
    inline Tp::PendingOperation *%(settername)s(%(type)s newValue)
    {
        return internalSetProperty(QLatin1String("%(name)s"), QVariant::fromValue(newValue));
    }
""" % {'name' : name,
       'docstring' : format_docstring(prop, '     * ').replace('*/',
           '*/'),
       'type' : binding.val,
       'name' : name,
       'settername' : 'setProperty' + name})
Exemplo n.º 2
0
    def do_signal(self, signal):
        name = signal.getAttribute('name')
        argnames, argdocstrings, argbindings = extract_arg_or_member_info(
            get_by_path(signal, 'arg'), self.custom_lists, self.externals,
            self.typesnamespace, '     *     ')

        self.h("""
    /**
     * Represents the signal "%s" on the remote object.
%s\
""" % (name, format_docstring(signal, '     * ')))

        for i in xrange(len(argnames)):
            assert argnames[
                i] != None, 'Name missing from argument at index %d for signal %s' % (
                    i, name)
            if argdocstrings[i]:
                self.h("""\
     *
     * \\param %s
%s\
""" % (argnames[i], argdocstrings[i]))

        self.h("""\
     */
    void %s(%s);
""" % (name, ', '.join([
            '%s %s' % (binding.inarg, name)
            for binding, name in zip(argbindings, argnames)
        ])))
    def do_val(self, val, prefix, last):
        name = (val.getAttribute('suffix') or val.getAttribute('name')).replace('_', '')
        self.h("""\
%s\
    %s = %s,

""" % (format_docstring(val, self.refs, indent='     * ', brackets=('    /**', '     */')), prefix + name, val.getAttribute('value')))
Exemplo n.º 4
0
    def do_signal(self, signal):
        name = signal.getAttribute("name")
        argnames, argdocstrings, argbindings = extract_arg_or_member_info(
            get_by_path(signal, "arg"), self.custom_lists, self.externals, self.typesnamespace, "     *     "
        )

        self.h(
            """
    /**
     * Represents the signal "%s" on the remote object.
%s\
"""
            % (name, format_docstring(signal, "     * "))
        )

        for i in xrange(len(argnames)):
            assert argnames[i] != None, "Name missing from argument at index %d for signal %s" % (i, name)
            if argdocstrings[i]:
                self.h(
                    """\
     *
     * \\param %s
%s\
"""
                    % (argnames[i], argdocstrings[i])
                )

        self.h(
            """\
     */
    void %s(%s);
"""
            % (name, ", ".join(["%s %s" % (binding.inarg, name) for binding, name in zip(argbindings, argnames)]))
        )
    def do_val(self, val, prefix, last):
        name = (val.getAttribute('suffix')
                or val.getAttribute('name')).replace('_', '')
        self.h("""\
%s\
    %s = %s,

""" % (format_docstring(val, indent='     * ', brackets=(
            '    /**', '     */')), prefix + name, val.getAttribute('value')))
    def do_flags(self, flags):
        singular = flags.getAttribute('singular') or \
                   flags.getAttribute('value-prefix')

        using_name = False
        if not singular:
            using_name = True
            singular = flags.getAttribute('name')

        if singular.endswith('lags'):
            singular = singular[:-1]

        if using_name and singular.endswith('s'):
            singular = singular[:-1]

        singular = singular.replace('_', '')
        plural = (flags.getAttribute('plural') or flags.getAttribute('name')
                  or singular + 's').replace('_', '')
        self.h("""\
/**
 * \\ingroup flagtypeconsts
 *
 * Flag type generated from the specification.
 */
enum %(singular)s
{
""" % {'singular': singular})

        flagvalues = get_by_path(flags, 'flag')

        for flag in flagvalues:
            self.do_val(flag, singular, flag == flagvalues[-1])

        self.h("""\
    %s = 0xffffffffU
""" % ("_" + singular + "Padding"))

        self.h(
            """\
};

/**
 * \\typedef QFlags<%(singular)s> %(plural)s
 * \\ingroup flagtypeconsts
 *
 * Type representing combinations of #%(singular)s values.
%(docstring)s\
 */
typedef QFlags<%(singular)s> %(plural)s;
Q_DECLARE_OPERATORS_FOR_FLAGS(%(plural)s)

""" % {
                'singular': singular,
                'plural': plural,
                'docstring': format_docstring(flags)
            })
    def do_prop(self, prop):
        name = prop.getAttribute('name')
        access = prop.getAttribute('access')
        gettername = name
        settername = None

        sig = prop.getAttribute('type')
        tptype = prop.getAttributeNS(NS_TP, 'type')
        binding = binding_from_usage(sig, tptype, self.custom_lists, (sig, tptype) in self.externals, self.typesnamespace)

        if 'write' in access:
            settername = 'set' + name

        self.h("""
    /**
     * Represents property "%(name)s" on the remote object.
%(docstring)s\
     */
    Q_PROPERTY(%(val)s %(name)s READ %(gettername)s%(maybesettername)s)

    /**
     * Getter for the remote object property "%(name)s".
     *
     * Don't use this: it blocks the main loop.
     *
     * \\return The value of the property, or a default-constructed value
     *          if the property is not readable.
     */
    inline %(val)s %(gettername)s() const TELEPATHY_GNUC_DEPRECATED
    {
        return %(getter-return)s;
    }
""" % {'name' : name,
       'docstring' : format_docstring(prop, '     * ').replace('*/',
           '&#42;&#47;'),
       'val' : binding.val,
       'name' : name,
       'gettername' : gettername,
       'maybesettername' : settername and (' WRITE ' + settername) or '',
       'getter-return' : 'read' in access and ('qvariant_cast<%s>(internalPropGet("%s"))' % (binding.val, name)) or binding.val + '()'})

        if settername:
            self.h("""
    /**
     * Setter for the remote object property "%s".
     *
     * Don't use this: it blocks the main loop.
     *
     * \\param newValue The value to set the property to.
     */
    inline void %s(%s newValue) TELEPATHY_GNUC_DEPRECATED
    {
        internalPropSet("%s", QVariant::fromValue(newValue));
    }
""" % (name, settername, binding.inarg, name))
    def do_enum(self, enum):
        singular = enum.getAttribute('singular') or \
                   enum.getAttribute('name')
        value_prefix = enum.getAttribute('singular') or \
                       enum.getAttribute('value-prefix') or \
                       enum.getAttribute('name')

        if singular.endswith('lags'):
            singular = singular[:-1]

        plural = enum.getAttribute('plural') or singular + 's'
        singular = singular.replace('_', '')
        value_prefix = value_prefix.replace('_', '')
        vals = get_by_path(enum, 'enumvalue')

        self.h("""\
/**
 * \\enum %(singular)s
 * \\ingroup enumtypeconsts
 *
 * Enumerated type generated from the specification.
%(docstring)s\
 */
enum %(singular)s
{
""" % {
            'singular': singular,
            'docstring': format_docstring(enum)
        })

        for val in vals:
            self.do_val(val, value_prefix, val == vals[-1])

        self.h("""\
    %s = 0xffffffffU
};

""" % ("_" + singular + "Padding"))

        self.h(
            """\
/**
 * \\ingroup enumtypeconsts
 *
 * 1 higher than the highest valid value of %(singular)s.
 */
const int NUM_%(upper-plural)s = (%(last-val)s+1);

""" % {
                'singular': singular,
                'upper-plural': plural.upper(),
                'last-val': vals[-1].getAttribute('value')
            })
    def do_flags(self, flags):
        singular = flags.getAttribute('singular') or \
                   flags.getAttribute('value-prefix')

        using_name = False
        if not singular:
            using_name = True
            singular = flags.getAttribute('name')

        if singular.endswith('lags'):
            singular = singular[:-1]

        if using_name and singular.endswith('s'):
            singular = singular[:-1]

        singular = singular.replace('_', '')
        plural = (flags.getAttribute('plural') or flags.getAttribute('name') or singular + 's').replace('_', '')
        self.h("""\
/**
 * \\ingroup flagtypeconsts
 *
 * Flag type generated from the specification.
 */
enum %(singular)s
{
""" % {'singular' : singular})

        flagvalues = get_by_path(flags, 'flag')

        for flag in flagvalues:
            self.do_val(flag, singular, flag == flagvalues[-1])

        self.h("""\
    %s = 0xffffffffU
""" % ("_" + singular + "Padding"))

        self.h("""\
};

/**
 * \\typedef QFlags<%(singular)s> %(plural)s
 * \\ingroup flagtypeconsts
 *
 * Type representing combinations of #%(singular)s values.
%(docstring)s\
 */
typedef QFlags<%(singular)s> %(plural)s;
Q_DECLARE_OPERATORS_FOR_FLAGS(%(plural)s)

""" % {'singular' : singular, 'plural' : plural, 'docstring' : format_docstring(flags, self.refs)})
    def do_enum(self, enum):
        singular = enum.getAttribute('singular') or \
                   enum.getAttribute('name')
        value_prefix = enum.getAttribute('singular') or \
                       enum.getAttribute('value-prefix') or \
                       enum.getAttribute('name')

        if singular.endswith('lags'):
            singular = singular[:-1]

        plural = enum.getAttribute('plural') or singular + 's'
        singular = singular.replace('_', '')
        value_prefix = value_prefix.replace('_', '')
        vals = get_by_path(enum, 'enumvalue')

        self.h("""\
/**
 * \\enum %(singular)s
 * \\ingroup enumtypeconsts
 *
 * Enumerated type generated from the specification.
%(docstring)s\
 */
enum %(singular)s
{
""" % {'singular' : singular, 'docstring' : format_docstring(enum, self.refs)})

        for val in vals:
            self.do_val(val, value_prefix, val == vals[-1])

        self.h("""\
    %s = 0xffffffffU
};

""" % ("_" + singular + "Padding"))

        self.h("""\
/**
 * \\ingroup enumtypeconsts
 *
 * 1 higher than the highest valid value of %(singular)s.
 */
const int NUM_%(upper-plural)s = (%(last-val)s+1);

""" % {'singular' : singular,
       'upper-plural' : plural.upper(),
       'last-val' : vals[-1].getAttribute('value')})
Exemplo n.º 11
0
    def do_prop(self, prop):
        name = prop.getAttribute('name')
        access = prop.getAttribute('access')
        gettername = name
        settername = None

        sig = prop.getAttribute('type')
        tptype = prop.getAttributeNS(NS_TP, 'type')
        binding = binding_from_usage(sig, tptype, self.custom_lists,
                                     (sig, tptype) in self.externals,
                                     self.typesnamespace)

        if 'write' in access:
            settername = 'set' + name

        if 'read' in access:
            self.h(
                """
    /**
     * Asynchronous getter for the remote object property "%(name)s" of type %(val)s.
     *
%(docstring)s\
     *
     * \\return A pending variant which will emit finished when the property has been
     *          retrieved.
     */
    inline Tp::PendingVariant *%(gettername)s() const
    {
        return internalRequestProperty(QLatin1String("%(name)s"));
    }
""" % {
                    'name':
                    name,
                    'docstring':
                    format_docstring(prop, '     * ').replace(
                        '*/', '&#42;&#47;'),
                    'val':
                    binding.val,
                    'name':
                    name,
                    'gettername':
                    'requestProperty' + name
                })

        if 'write' in access:
            self.h(
                """
    /**
     * Asynchronous setter for the remote object property "%(name)s" of type %(type)s.
     *
%(docstring)s\
     *
     * \\return A pending operation which will emit finished when the property has been
     *          set.
     */
    inline Tp::PendingOperation *%(settername)s(%(type)s newValue)
    {
        return internalSetProperty(QLatin1String("%(name)s"), QVariant::fromValue(newValue));
    }
""" % {
                    'name':
                    name,
                    'docstring':
                    format_docstring(prop, '     * ').replace(
                        '*/', '&#42;&#47;'),
                    'type':
                    binding.val,
                    'name':
                    name,
                    'settername':
                    'setProperty' + name
                })
Exemplo n.º 12
0
    def __call__(self):
        # Header
        self.h('/* Generated from ')
        self.h(get_descendant_text(get_by_path(self.spec, 'title')))
        version = get_by_path(self.spec, "version")

        if version:
            self.h(', version ' + get_descendant_text(version))

        self.h("""
 */
 """)

        if self.must_define:
            self.h("""
#ifndef %s
#error %s
#endif
""" % (self.must_define, self.must_define))

        self.h("""
#include <QFlags>

/**
 * \\addtogroup typesconstants Types and constants
 *
 * Enumerated, flag, structure, list and mapping types and utility constants.
 */

/**
 * \\defgroup flagtypeconsts Flag type constants
 * \\ingroup typesconstants
 *
 * Types generated from the specification representing bit flag constants and
 * combinations of them (bitfields).
 */

/**
 * \\defgroup enumtypeconsts Enumerated type constants
 * \\ingroup typesconstants
 *
 * Types generated from the specification representing enumerated types ie.
 * types the values of which are mutually exclusive integral constants.
 */

/**
 * \\defgroup ifacestrconsts Interface string constants
 * \\ingroup typesconstants
 *
 * D-Bus interface names of the interfaces in the specification.
 */

/**
 * \\defgroup errorstrconsts Error string constants
 * \\ingroup typesconstants
 *
 * Names of the D-Bus errors in the specification.
 */
""")

        # Begin namespace
        self.h("""
namespace %s
{
""" % self.namespace)

        # Flags
        for flags in self.spec.getElementsByTagNameNS(NS_TP, 'flags'):
            self.do_flags(flags)

        # Enums
        for enum in self.spec.getElementsByTagNameNS(NS_TP, 'enum'):
            self.do_enum(enum)

        # End namespace
        self.h("""\
}

""")

        # Interface names
        for iface in self.spec.getElementsByTagName('interface'):
            self.h("""\
/**
 * \\ingroup ifacestrconsts
 *
 * The interface name "%(name)s".
 */
#define %(DEFINE)s "%(name)s"

""" % {'name' : iface.getAttribute('name'),
       'DEFINE' : self.prefix + 'INTERFACE_' + get_by_path(iface, '../@name').upper().replace('/', '')})

        # Error names
        for error in get_by_path(self.spec, 'errors/error'):
            name = error.getAttribute('name')
            fullname = get_by_path(error, '../@namespace') + '.' + name.replace(' ', '')
            define = self.prefix + 'ERROR_' + name.replace(' ', '_').replace('.', '_').upper()
            self.h("""\
/**
 * \\ingroup errorstrconsts
 *
 * The error name "%(fullname)s".
%(docstring)s\
 */
#define %(DEFINE)s "%(fullname)s"

""" % {'fullname' : fullname,
       'docstring': format_docstring(error),
       'DEFINE' : define})
    def output_by_depinfo(self, depinfo):
        names, docstrings, bindings = extract_arg_or_member_info(get_by_path(depinfo.el, 'member'), self.custom_lists, self.externals, None, '     * ', ('    /**', '     */'))
        members = len(names)

        if depinfo.el.localName == 'struct':
            if members == 0:
                raise EmptyStruct(depinfo.binding.val)

            self.decl("""\
/**
 * \\struct %(name)s
 * \\ingroup struct
%(headercmd)s\
 *
 * Structure type generated from the specification.
%(docstring)s\
 */
struct %(visibility)s %(name)s
{
""" % {
        'name' : depinfo.binding.val,
        'headercmd': get_headerfile_cmd(self.realinclude, self.prettyinclude),
        'docstring' : format_docstring(depinfo.el),
        'visibility': self.visibility,
        })

            for i in xrange(members):
                self.decl("""\
%s\
    %s %s;
""" % (docstrings[i], bindings[i].val, names[i]))

            self.decl("""\
};

""")

            self.both('%s bool operator==(%s v1, %s v2)' %
                    (self.visibility,
                     depinfo.binding.inarg,
                     depinfo.binding.inarg))
            self.decl(';\n')
            self.impl("""
{""")
            if (bindings[0].val != 'QDBusVariant'):
                self.impl("""
    return ((v1.%s == v2.%s)""" % (names[0], names[0]))
            else:
                self.impl("""
    return ((v1.%s.variant() == v2.%s.variant())""" % (names[0], names[0]))
            for i in xrange(1, members):
                if (bindings[i].val != 'QDBusVariant'):
                    self.impl("""
            && (v1.%s == v2.%s)""" % (names[i], names[i]))
                else:
                    self.impl("""
            && (v1.%s.variant() == v2.%s.variant())""" % (names[i], names[i]))
            self.impl("""
            );
}

""")

            self.decl('inline bool operator!=(%s v1, %s v2)' %
                      (depinfo.binding.inarg, depinfo.binding.inarg))
            self.decl("""
{
    return !operator==(v1, v2);
}
""")

            self.both('%s QDBusArgument& operator<<(QDBusArgument& arg, %s val)' %
                    (self.visibility, depinfo.binding.inarg))
            self.decl(';\n')
            self.impl("""
{
    arg.beginStructure();
    arg << %s;
    arg.endStructure();
    return arg;
}

""" % ' << '.join(['val.' + name for name in names]))

            self.both('%s const QDBusArgument& operator>>(const QDBusArgument& arg, %s val)' %
                    (self.visibility, depinfo.binding.outarg))
            self.decl(';\n\n')
            self.impl("""
{
    arg.beginStructure();
    arg >> %s;
    arg.endStructure();
    return arg;
}

""" % ' >> '.join(['val.' + name for name in names]))
        elif depinfo.el.localName == 'mapping':
            if members != 2:
                raise MalformedMapping(depinfo.binding.val, members)

            realtype = 'QMap<%s, %s>' % (bindings[0].val, (bindings[1].val.endswith('>') and bindings[1].val + ' ') or bindings[1].val)
            self.decl("""\
/**
 * \\struct %s
 * \\ingroup mapping
%s\
 *
 * Mapping type generated from the specification. Convertible with
 * %s, but needed to have a discrete type in the Qt4 type system.
%s\
 */
""" % (depinfo.binding.val, get_headerfile_cmd(self.realinclude, self.prettyinclude), realtype, format_docstring(depinfo.el)))
            self.decl(self.faketype(depinfo.binding.val, realtype))
        else:
            raise WTF(depinfo.el.localName)

        self.to_declare.append(self.namespace + '::' + depinfo.binding.val)

        if depinfo.binding.array_val:
            self.to_declare.append('%s::%s' % (self.namespace, depinfo.binding.array_val))
            self.decl("""\
/**
 * \\ingroup list
%s\
 *
 * Array of %s values.
 */
typedef %s %s;

""" % (get_headerfile_cmd(self.realinclude, self.prettyinclude), depinfo.binding.val, 'QList<%s>' % depinfo.binding.val, depinfo.binding.array_val))

        i = depinfo.binding.array_depth
        while i > 1:
            i -= 1
            self.to_declare.append('%s::%s%s' % (self.namespace, depinfo.binding.array_val, ('List' * i)))
            list_of = depinfo.binding.array_val + ('List' * (i-1))
            self.decl("""\
/**
 * \\ingroup list
%s\
 *
 * Array of %s values.
 */
typedef QList<%s> %sList;

""" % (get_headerfile_cmd(self.realinclude, self.prettyinclude), list_of, list_of, list_of))
Exemplo n.º 14
0
    def do_method(self, method):
        name = method.getAttribute("name")
        args = get_by_path(method, "arg")
        argnames, argdocstrings, argbindings = extract_arg_or_member_info(
            args, self.custom_lists, self.externals, self.typesnamespace, "     *     "
        )

        inargs = []
        outargs = []

        for i in xrange(len(args)):
            if args[i].getAttribute("direction") == "out":
                outargs.append(i)
            else:
                inargs.append(i)
                assert argnames[i] != None, "No argument name for input argument at index %d for method %s" % (i, name)

        rettypes = ", ".join([argbindings[i].val for i in outargs])
        params = ", ".join([argbindings[i].inarg + " " + argnames[i] for i in inargs])

        self.h(
            """
    /**
     * Begins a call to the D-Bus method "%s" on the remote object.
%s\
"""
            % (name, format_docstring(method, "     * "))
        )

        for i in inargs:
            if argdocstrings[i]:
                self.h(
                    """\
     *
     * \\param %s
%s\
"""
                    % (argnames[i], argdocstrings[i])
                )

        for i in outargs:
            if argdocstrings[i]:
                self.h(
                    """\
     *
     * \\return
%s\
"""
                    % argdocstrings[i]
                )

        self.h(
            """\
     */
    inline QDBusPendingReply<%(rettypes)s> %(name)s(%(params)s)
    {
        if (!invalidationReason().isEmpty()) {
            return QDBusPendingReply<%(rettypes)s>(QDBusMessage::createError(
                invalidationReason(),
                invalidationMessage()
            ));
        }

"""
            % {"rettypes": rettypes, "name": name, "params": params}
        )

        if inargs:
            self.h(
                """
        QList<QVariant> argumentList;
        argumentList << %s;
        return asyncCallWithArgumentList(QLatin1String("%s"), argumentList);
    }
"""
                % (" << ".join(["QVariant::fromValue(%s)" % argnames[i] for i in inargs]), name)
            )
        else:
            self.h(
                """
        return asyncCall(QLatin1String("%s"));
    }
"""
                % name
            )
Exemplo n.º 15
0
    def do_prop(self, prop):
        name = prop.getAttribute("name")
        access = prop.getAttribute("access")
        gettername = name
        settername = None

        sig = prop.getAttribute("type")
        tptype = prop.getAttributeNS(NS_TP, "type")
        binding = binding_from_usage(
            sig, tptype, self.custom_lists, (sig, tptype) in self.externals, self.typesnamespace
        )

        if "write" in access:
            settername = "set" + name

        self.h(
            """
    /**
     * Represents property "%(name)s" on the remote object.
%(docstring)s\
     */
    Q_PROPERTY(%(val)s %(name)s READ %(gettername)s%(maybesettername)s)

    /**
     * Getter for the remote object property "%(name)s".
     *
     * Don't use this: it blocks the main loop.
     *
     * \\return The value of the property, or a default-constructed value
     *          if the property is not readable.
     */
    inline %(val)s %(gettername)s() const TELEPATHY_GNUC_DEPRECATED
    {
        return %(getter-return)s;
    }
"""
            % {
                "name": name,
                "docstring": format_docstring(prop, "     * ").replace("*/", "&#42;&#47;"),
                "val": binding.val,
                "name": name,
                "gettername": gettername,
                "maybesettername": settername and (" WRITE " + settername) or "",
                "getter-return": "read" in access
                and ('qvariant_cast<%s>(internalPropGet("%s"))' % (binding.val, name))
                or binding.val + "()",
            }
        )

        if settername:
            self.h(
                """
    /**
     * Setter for the remote object property "%s".
     *
     * Don't use this: it blocks the main loop.
     *
     * \\param newValue The value to set the property to.
     */
    inline void %s(%s newValue) TELEPATHY_GNUC_DEPRECATED
    {
        internalPropSet("%s", QVariant::fromValue(newValue));
    }
"""
                % (name, settername, binding.inarg, name)
            )
Exemplo n.º 16
0
    def do_method(self, method):
        name = method.getAttribute('name')
        args = get_by_path(method, 'arg')
        argnames, argdocstrings, argbindings = extract_arg_or_member_info(
            args, self.custom_lists, self.externals, self.typesnamespace,
            '     *     ')

        inargs = []
        outargs = []

        for i in xrange(len(args)):
            if args[i].getAttribute('direction') == 'out':
                outargs.append(i)
            else:
                inargs.append(i)
                assert argnames[
                    i] != None, 'No argument name for input argument at index %d for method %s' % (
                        i, name)

        rettypes = ', '.join([argbindings[i].val for i in outargs])
        params = ', '.join(
            [argbindings[i].inarg + ' ' + argnames[i] for i in inargs])

        self.h("""
    /**
     * Begins a call to the D-Bus method "%s" on the remote object.
%s\
""" % (name, format_docstring(method, '     * ')))

        for i in inargs:
            if argdocstrings[i]:
                self.h("""\
     *
     * \\param %s
%s\
""" % (argnames[i], argdocstrings[i]))

        for i in outargs:
            if argdocstrings[i]:
                self.h("""\
     *
     * \\return
%s\
""" % argdocstrings[i])

        self.h("""\
     */
    inline QDBusPendingReply<%(rettypes)s> %(name)s(%(params)s)
    {
        if (!invalidationReason().isEmpty()) {
            return QDBusPendingReply<%(rettypes)s>(QDBusMessage::createError(
                invalidationReason(),
                invalidationMessage()
            ));
        }

""" % {
            'rettypes': rettypes,
            'name': name,
            'params': params
        })

        if inargs:
            self.h("""
        QList<QVariant> argumentList;
        argumentList << %s;
        return asyncCallWithArgumentList(QLatin1String("%s"), argumentList);
    }
""" % (' << '.join(['QVariant::fromValue(%s)' % argnames[i]
                    for i in inargs]), name))
        else:
            self.h("""
        return asyncCall(QLatin1String("%s"));
    }
""" % name)
    def __call__(self):
        # Header
        self.h('/* Generated from ')
        self.h(get_descendant_text(get_by_path(self.spec, 'title')))
        version = get_by_path(self.spec, "version")

        if version:
            self.h(', version ' + get_descendant_text(version))

        self.h("""
 */
 """)

        if self.must_define:
            self.h("""
#ifndef %s
#error %s
#endif
""" % (self.must_define, self.must_define))

        self.h("""
#include <QFlags>

/**
 * \\addtogroup typesconstants Types and constants
 *
 * Enumerated, flag, structure, list and mapping types and utility constants.
 */

/**
 * \\defgroup flagtypeconsts Flag type constants
 * \\ingroup typesconstants
 *
 * Types generated from the specification representing bit flag constants and
 * combinations of them (bitfields).
 */

/**
 * \\defgroup enumtypeconsts Enumerated type constants
 * \\ingroup typesconstants
 *
 * Types generated from the specification representing enumerated types ie.
 * types the values of which are mutually exclusive integral constants.
 */

/**
 * \\defgroup ifacestrconsts Interface string constants
 * \\ingroup typesconstants
 *
 * D-Bus interface names of the interfaces in the specification.
 */

/**
 * \\defgroup errorstrconsts Error string constants
 * \\ingroup typesconstants
 *
 * Names of the D-Bus errors in the specification.
 */
""")

        # Begin namespace
        self.h("""
namespace %s
{
""" % self.namespace)

        # Flags
        for flags in self.spec.getElementsByTagNameNS(NS_TP, 'flags'):
            self.do_flags(flags)

        # Enums
        for enum in self.spec.getElementsByTagNameNS(NS_TP, 'enum'):
            self.do_enum(enum)

        # End namespace
        self.h("""\
}

""")

        # Interface names
        for iface in self.spec.getElementsByTagName('interface'):
            if self.old_prefix:
                self.h(
                    """\
/**
 * \\ingroup ifacestrconsts
 *
 * The interface name "%(name)s".
 */
#define %(DEFINE)s "%(name)s"

""" % {
                        'name':
                        iface.getAttribute('name'),
                        'DEFINE':
                        self.old_prefix + 'INTERFACE_' + get_by_path(
                            iface, '../@name').upper().replace('/', '')
                    })

            if self.define_prefix:
                self.h(
                    """\
/**
 * \\ingroup ifacestrconsts
 *
 * The interface name "%(name)s" as a QLatin1String, usable in QString requiring contexts even when
 * building with Q_NO_CAST_FROM_ASCII defined.
 */
#define %(DEFINE)s QLatin1String("%(name)s")

""" % {
                        'name':
                        iface.getAttribute('name'),
                        'DEFINE':
                        self.define_prefix + 'IFACE_' + get_by_path(
                            iface, '../@name').upper().replace('/', '')
                    })

        # Error names
        for error in get_by_path(self.spec, 'errors/error'):
            name = error.getAttribute('name')
            fullname = get_by_path(
                error, '../@namespace') + '.' + name.replace(' ', '')

            if self.old_prefix:
                define = self.old_prefix + 'ERROR_' + name.replace(
                    ' ', '_').replace('.', '_').upper()
                self.h(
                    """\
/**
 * \\ingroup errorstrconsts
 *
 * The error name "%(fullname)s".
%(docstring)s\
 */
#define %(DEFINE)s "%(fullname)s"

""" % {
                        'fullname': fullname,
                        'docstring': format_docstring(error),
                        'DEFINE': define
                    })

            if self.define_prefix:
                define = self.define_prefix + 'ERROR_' + name.replace(
                    ' ', '_').replace('.', '_').upper()
                self.h(
                    """\
/**
 * \\ingroup errorstrconsts
 *
 * The error name "%(fullname)s" as a QLatin1String, usable in QString requiring contexts even when
 * building with Q_NO_CAST_FROM_ASCII defined.
%(docstring)s\
 */
#define %(DEFINE)s QLatin1String("%(fullname)s")

""" % {
                        'fullname': fullname,
                        'docstring': format_docstring(error),
                        'DEFINE': define
                    })
Exemplo n.º 18
0
    def do_method(self, method):
        name = method.getAttribute('name')
        args = get_by_path(method, 'arg')
        argnames, argdocstrings, argbindings = extract_arg_or_member_info(
            args, self.custom_lists, self.externals, self.typesnamespace,
            '     *     ')

        inargs = []
        outargs = []

        for i in xrange(len(args)):
            if args[i].getAttribute('direction') == 'out':
                outargs.append(i)
            else:
                inargs.append(i)
                assert argnames[
                    i] != None, 'No argument name for input argument at index %d for method %s' % (
                        i, name)

        rettypes = ', '.join([argbindings[i].val for i in outargs])
        params = ', '.join(
            [argbindings[i].inarg + ' ' + argnames[i] for i in inargs])
        if params:
            params += ', int timeout = -1'
        else:
            params = 'int timeout = -1'

        self.h("""
    /**
     * Begins a call to the D-Bus method "%s" on the remote object.
%s\
     *
     * Note that \\a timeout is ignored as of now. It will be used once
     * http://bugreports.qt.nokia.com/browse/QTBUG-11775 is fixed.
     *
""" % (name, format_docstring(method, '     * ')))

        for i in inargs:
            if argdocstrings[i]:
                self.h("""\
     *
     * \\param %s
%s\
""" % (argnames[i], argdocstrings[i]))

        self.h("""\
     * \\param timeout The timeout in milliseconds.
""")

        for i in outargs:
            if argdocstrings[i]:
                self.h("""\
     *
     * \\return
%s\
""" % argdocstrings[i])

        self.h("""\
     */
    inline QDBusPendingReply<%(rettypes)s> %(name)s(%(params)s)
    {
        if (!invalidationReason().isEmpty()) {
            return QDBusPendingReply<%(rettypes)s>(QDBusMessage::createError(
                invalidationReason(),
                invalidationMessage()
            ));
        }
""" % {
            'rettypes': rettypes,
            'name': name,
            'params': params
        })

        if inargs:
            self.h("""
        QDBusMessage callMessage = QDBusMessage::createMethodCall(this->service(), this->path(),
                this->staticInterfaceName(), QLatin1String("%s"));
        callMessage << %s;
        return this->connection().asyncCall(callMessage, timeout);
    }
""" % (name, ' << '.join(
                ['QVariant::fromValue(%s)' % argnames[i] for i in inargs])))
        else:
            self.h("""
        QDBusMessage callMessage = QDBusMessage::createMethodCall(this->service(), this->path(),
                this->staticInterfaceName(), QLatin1String("%s"));
        return this->connection().asyncCall(callMessage, timeout);
    }
""" % name)
Exemplo n.º 19
0
    def output_by_depinfo(self, depinfo):
        names, docstrings, bindings = extract_arg_or_member_info(
            get_by_path(depinfo.el, 'member'), self.custom_lists,
            self.externals, None, '     * ', ('    /**', '     */'))
        members = len(names)

        if depinfo.el.localName == 'struct':
            assert members > 0, 'tp:struct %s should have some members' % depinfo.binding.val
            self.decl(
                """\
/**
 * \\struct %(name)s
 * \\ingroup struct
%(headercmd)s\
 *
 * Structure type generated from the specification.
%(docstring)s\
 */
struct TELEPATHY_QT4_EXPORT %(name)s
{
""" % {
                    'name':
                    depinfo.binding.val,
                    'headercmd':
                    get_headerfile_cmd(self.realinclude, self.prettyinclude),
                    'docstring':
                    format_docstring(depinfo.el)
                })

            for i in xrange(members):
                self.decl("""\
%s\
    %s %s;
""" % (docstrings[i], bindings[i].val, names[i]))

            self.decl("""\
};

""")

            self.both('bool operator==(%s v1, %s v2)' %
                      (depinfo.binding.inarg, depinfo.binding.inarg))
            self.decl(';\n')
            self.impl("""
{""")
            if (bindings[0].val != 'QDBusVariant'):
                self.impl("""
    return ((v1.%s == v2.%s)""" % (names[0], names[0]))
            else:
                self.impl("""
    return ((v1.%s.variant() == v2.%s.variant())""" % (names[0], names[0]))
            for i in xrange(1, members):
                if (bindings[i].val != 'QDBusVariant'):
                    self.impl("""
            && (v1.%s == v2.%s)""" % (names[i], names[i]))
                else:
                    self.impl("""
            && (v1.%s.variant() == v2.%s.variant())""" % (names[i], names[i]))
            self.impl("""
            );
}

""")

            self.decl('inline bool operator!=(%s v1, %s v2)' %
                      (depinfo.binding.inarg, depinfo.binding.inarg))
            self.decl("""
{
    return !operator==(v1, v2);
}
""")

            self.both('QDBusArgument& operator<<(QDBusArgument& arg, %s val)' %
                      depinfo.binding.inarg)
            self.decl(';\n')
            self.impl("""
{
    arg.beginStructure();
    arg << %s;
    arg.endStructure();
    return arg;
}

""" % ' << '.join(['val.' + name for name in names]))

            self.both(
                'const QDBusArgument& operator>>(const QDBusArgument& arg, %s val)'
                % depinfo.binding.outarg)
            self.decl(';\n\n')
            self.impl("""
{
    arg.beginStructure();
    arg >> %s;
    arg.endStructure();
    return arg;
}

""" % ' >> '.join(['val.' + name for name in names]))
        elif depinfo.el.localName == 'mapping':
            assert members == 2, 'tp:mapping %s should have 2 members' % depinfo.binding.val
            realtype = 'QMap<%s, %s>' % (bindings[0].val,
                                         (bindings[1].val.endswith('>')
                                          and bindings[1].val + ' ')
                                         or bindings[1].val)
            self.decl("""\
/**
 * \\struct %s
 * \\ingroup mapping
%s\
 *
 * Mapping type generated from the specification. Convertible with
 * %s, but needed to have a discrete type in the Qt4 type system.
%s\
 */
""" % (depinfo.binding.val,
            get_headerfile_cmd(self.realinclude, self.prettyinclude), realtype,
            format_docstring(depinfo.el)))
            self.decl(self.faketype(depinfo.binding.val, realtype))
        else:
            assert False

        self.to_declare.append(self.namespace + '::' + depinfo.binding.val)

        if depinfo.binding.array_val:
            self.to_declare.append('%s::%s' %
                                   (self.namespace, depinfo.binding.array_val))
            self.decl("""\
/**
 * \\ingroup list
%s\
 *
 * Array of %s values.
 */
typedef %s %s;

""" % (get_headerfile_cmd(self.realinclude,
                          self.prettyinclude), depinfo.binding.val,
            'QList<%s>' % depinfo.binding.val, depinfo.binding.array_val))

        i = depinfo.binding.array_depth
        while i > 1:
            i -= 1
            self.to_declare.append('%s::%s%s' %
                                   (self.namespace, depinfo.binding.array_val,
                                    ('List' * i)))
            list_of = depinfo.binding.array_val + ('List' * (i - 1))
            self.decl("""\
/**
 * \\ingroup list
%s\
 *
 * Array of %s values.
 */
typedef QList<%s> %sList;

""" % (get_headerfile_cmd(self.realinclude,
                          self.prettyinclude), list_of, list_of, list_of))
Exemplo n.º 20
0
    def do_prop(self, prop):
        name = prop.getAttribute('name')
        access = prop.getAttribute('access')
        gettername = name
        settername = None

        sig = prop.getAttribute('type')
        tptype = prop.getAttributeNS(NS_TP, 'type')
        binding = binding_from_usage(sig, tptype, self.custom_lists,
                                     (sig, tptype) in self.externals,
                                     self.typesnamespace)

        if 'write' in access:
            settername = 'set' + name

        self.h(
            """
    /**
     * Represents property "%(name)s" on the remote object.
%(docstring)s\
     */
    Q_PROPERTY(%(val)s %(name)s READ %(gettername)s%(maybesettername)s)

    /**
     * Getter for the remote object property "%(name)s".
     *
     * Don't use this: it blocks the main loop.
     *
     * \\return The value of the property, or a default-constructed value
     *          if the property is not readable.
     */
    inline %(val)s %(gettername)s() const TELEPATHY_GNUC_DEPRECATED
    {
        return %(getter-return)s;
    }
""" % {
                'name':
                name,
                'docstring':
                format_docstring(prop, '     * ').replace('*/', '&#42;&#47;'),
                'val':
                binding.val,
                'name':
                name,
                'gettername':
                gettername,
                'maybesettername':
                settername and (' WRITE ' + settername) or '',
                'getter-return':
                'read' in access and
                ('qvariant_cast<%s>(internalPropGet("%s"))' %
                 (binding.val, name)) or binding.val + '()'
            })

        if settername:
            self.h("""
    /**
     * Setter for the remote object property "%s".
     *
     * Don't use this: it blocks the main loop.
     *
     * \\param newValue The value to set the property to.
     */
    inline void %s(%s newValue) TELEPATHY_GNUC_DEPRECATED
    {
        internalPropSet("%s", QVariant::fromValue(newValue));
    }
""" % (name, settername, binding.inarg, name))
Exemplo n.º 21
0
    def do_method(self, method):
        name = method.getAttribute('name')
        args = get_by_path(method, 'arg')
        argnames, argdocstrings, argbindings = extract_arg_or_member_info(args, self.custom_lists, self.externals, self.typesnamespace, '     *     ')

        inargs = []
        outargs = []

        for i in xrange(len(args)):
            if args[i].getAttribute('direction') == 'out':
                outargs.append(i)
            else:
                inargs.append(i)
                assert argnames[i] != None, 'No argument name for input argument at index %d for method %s' % (i, name)

        rettypes = ', '.join([argbindings[i].val for i in outargs])
        params = ', '.join([argbindings[i].inarg + ' ' + argnames[i] for i in inargs])
        if params:
            params += ', int timeout = -1'
        else:
            params = 'int timeout = -1'

        self.h("""
    /**
     * Begins a call to the D-Bus method "%s" on the remote object.
%s\
     *
     * Note that \\a timeout is ignored as of now. It will be used once
     * http://bugreports.qt.nokia.com/browse/QTBUG-11775 is fixed.
     *
""" % (name, format_docstring(method, '     * ')))

        for i in inargs:
            if argdocstrings[i]:
                self.h("""\
     *
     * \\param %s
%s\
""" % (argnames[i], argdocstrings[i]))

        self.h("""\
     * \\param timeout The timeout in milliseconds.
""")

        for i in outargs:
            if argdocstrings[i]:
                self.h("""\
     *
     * \\return
%s\
""" % argdocstrings[i])

        self.h("""\
     */
    inline QDBusPendingReply<%(rettypes)s> %(name)s(%(params)s)
    {
        if (!invalidationReason().isEmpty()) {
            return QDBusPendingReply<%(rettypes)s>(QDBusMessage::createError(
                invalidationReason(),
                invalidationMessage()
            ));
        }
""" % {'rettypes' : rettypes,
       'name' : name,
       'params' : params})

        if inargs:
            self.h("""
        QDBusMessage callMessage = QDBusMessage::createMethodCall(this->service(), this->path(),
                this->staticInterfaceName(), QLatin1String("%s"));
        callMessage << %s;
        return this->connection().asyncCall(callMessage, timeout);
    }
""" % (name, ' << '.join(['QVariant::fromValue(%s)' % argnames[i] for i in inargs])))
        else:
            self.h("""
        QDBusMessage callMessage = QDBusMessage::createMethodCall(this->service(), this->path(),
                this->staticInterfaceName(), QLatin1String("%s"));
        return this->connection().asyncCall(callMessage, timeout);
    }
""" % name)
    def do_val(self, val, prefix, last):
        name = (val.getAttribute('suffix') or val.getAttribute('name')).replace('_', '')
        stdout.write("""\
%s\
     %s = %s%s
""" % (format_docstring(val, indent='     * ', brackets=('    /**', '     */')), prefix + name, val.getAttribute('value'), (not last and ',\n') or ''))