sbus_codegen revision b07852825eeb63a78e1b3863e42b3f328430da18
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafsson# Stef Walter <stefw@redhat.com>
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Copyright (C) 2014 Red Hat
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafsson# This program is free software; you can redistribute it and/or modify
19c7b1a0293498a3e36692c59646ed6e15ffc8d0Tinderbox User# it under the terms of the GNU General Public License as published by
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt# the Free Software Foundation; either version 3 of the License, or
83a28ca274521e15086fc39febde507bcc4e145eMark Andrews# (at your option) any later version.
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt# This program is distributed in the hope that it will be useful,
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt# but WITHOUT ANY WARRANTY; without even the implied warranty of
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt# GNU General Public License for more details.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# You should have received a copy of the GNU General Public License
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafsson# along with this program. If not, see <http://www.gnu.org/licenses/>.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# Some parser code from GLib
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafsson# Copyright (C) 2008-2011 Red Hat, Inc.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# This library is free software; you can redistribute it and/or
194e2dfffa6a167b8eef0ad11864026b423a1c30Mark Andrews# modify it under the terms of the GNU Lesser General Public
194e2dfffa6a167b8eef0ad11864026b423a1c30Mark Andrews# License as published by the Free Software Foundation; either
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# version 2 of the License, or (at your option) any later version.
c1a883f2e04d94e99c433b1f6cfd0c0338f4ed85Mark Andrews# This library is distributed in the hope that it will be useful,
938440694b33cd752e9e4b71a526368b4811c177Tinderbox User# but WITHOUT ANY WARRANTY; without even the implied warranty of
19c7b1a0293498a3e36692c59646ed6e15ffc8d0Tinderbox User# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Lesser General Public License for more details.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# You should have received a copy of the GNU Lesser General
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# Public License along with this library; if not, write to the
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafsson# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# Boston, MA 02111-1307, USA.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# Portions by: David Zeuthen <davidz@redhat.com>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# DBus interfaces are defined here:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# The introspection data format has become the standard way to represent a
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafsson# DBus interface. For many examples see /usr/share/dbus-1/interfaces/ on a
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafsson# typical linux machine.
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafsson# A word about annotations. These are extra flags or values that can be
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafsson# assigned to anything. So far, the codegen supports this annotation:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# - An annotation specified in the specification that tells us what C symbol
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# to generate for a given interface or method. By default the codegen will
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# build up a symbol name from the DBus name.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# -----------------------------------------------------------------------------
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafsson # Lets us print problems like a compiler would
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return "%s:%d: %s" % (self.file, self.line, message)
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafsson raise DBusXmlException('No name on element')
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return self.annotations.get("org.freedesktop.DBus.GLib.CSymbol", self.name)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# The basic types that we support marshalling right now. These
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt# are the ones we can pass as basic arguments to libdbus directly.
30eec077db2bdcb6f2a0dc388a3cdde2ede75ec1Mark Andrews# If the dbus and sssd types are identical we pass things directly.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# otherwise some copying is necessary.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'y': ( "DBUS_TYPE_BYTE", "uint8_t", "uint8_t" ),
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'b': ( "DBUS_TYPE_BOOLEAN", "dbus_bool_t", "bool" ),
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'n': ( "DBUS_TYPE_INT16", "int16_t", "int16_t" ),
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'q': ( "DBUS_TYPE_UINT16", "uint16_t", "uint16_t" ),
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'i': ( "DBUS_TYPE_INT32", "int32_t", "int32_t" ),
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'u': ( "DBUS_TYPE_UINT32", "uint32_t", "uint32_t" ),
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'x': ( "DBUS_TYPE_INT64", "int64_t", "int64_t" ),
821350367e2c7313c02eb275e8e05d5193b47cfdJeremy C. Reed 't': ( "DBUS_TYPE_UINT64", "uint64_t", "uint64_t" ),
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'd': ( "DBUS_TYPE_DOUBLE", "double", "double" ),
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 's': ( "DBUS_TYPE_STRING", "const char *", "const char *" ),
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein 'o': ( "DBUS_TYPE_OBJECT_PATH", "const char *", "const char *" ),
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein type = type[1:]
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein (self.dbus_constant, self.dbus_type, self.sssd_type) = BASIC_TYPES[type]
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein # If types are not identical, we can't do array (yet)
8eea877894ea5bcf5cdd9ca124a8601ad421d753Andreas Gustafsson self.is_basic = (self.dbus_type == self.sssd_type)
8eea877894ea5bcf5cdd9ca124a8601ad421d753Andreas Gustafsson if not self.only_basic_args() and not self.use_raw_handler():
8eea877894ea5bcf5cdd9ca124a8601ad421d753Andreas Gustafsson raise DBusXmlException("Method has complex arguments and requires " +
8eea877894ea5bcf5cdd9ca124a8601ad421d753Andreas Gustafsson "the 'org.freedesktop.sssd.RawHandler' annotation")
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafsson return "%s_%s" % (self.iface.c_name(), self.c_name())
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return self.annotations.get(anno, self.iface.annotations.get(anno)) == 'true'
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return "".join([arg.type for arg in self.in_args])
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return "%s_%s" % (self.iface.c_name(), self.c_name())
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein raise DBusXmlException('Invalid access type %s'%self.access)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return "%s_%s" % (self.iface.c_name(), self.c_name())
14a656f94b1fd0ababd84a772228dfa52276ba15Evan Hunt sig = "void (*%s)(struct sbus_request *, void *data, " % (name)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return "sbus_invoke_get_%s" % self.get_invoker_name()
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return self.get_invoker_signature(self.getter_name())
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return self.annotations.get("org.freedesktop.DBus.GLib.CSymbol",
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# -----------------------------------------------------------------------------
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein# Code Generation
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein # NOTE: Would like to use the following syntax for this function
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein # but need to wait until python3 until it is supported:
30eec077db2bdcb6f2a0dc388a3cdde2ede75ec1Mark Andrews assert not kwargs, "unknown keyword argument(s): %s" % str(kwargs)
if with_names:
if with_names:
return str
for meth in iface.methods:
return invokers
for sig in iface.signals:
if sig.args:
if sig.args:
for prop in properties:
elif prop.readable:
elif prop.writable:
if prop.readable:
if iface.methods:
if iface.signals:
if iface.properties:
if include_header:
if iface.methods:
if iface.signals:
if iface.properties:
for meth in iface.methods:
for prop in iface.properties:
for meth in iface.methods:
for sig in iface.signals:
for prop in iface.properties:
for meth in iface.methods:
self.state_stack = []
try:
if self.state == STATE_IGNORED:
elif self.cur_object and name == STATE_ANNOTATION:
elif self.state == STATE_TOP:
if name == STATE_NODE:
elif self.state == STATE_NODE:
if name == STATE_INTERFACE:
elif self.state == STATE_INTERFACE:
if name == STATE_METHOD:
elif name == STATE_SIGNAL:
elif name == STATE_PROPERTY:
elif self.state == STATE_METHOD:
elif self.state == STATE_SIGNAL:
elif self.state == STATE_PROPERTY:
elif self.state == STATE_ARG:
if options.output:
if options.output:
try: