sbus_codegen revision e8058322725ba050014777ee2484f7e833ab1e3a
0ad489b182ebb3789322345e22cf750f88ae167and# Stef Walter <stefw@redhat.com>
0ad489b182ebb3789322345e22cf750f88ae167and# Copyright (C) 2014 Red Hat
0ad489b182ebb3789322345e22cf750f88ae167and# This program is free software; you can redistribute it and/or modify
0ad489b182ebb3789322345e22cf750f88ae167and# it under the terms of the GNU General Public License as published by
0ad489b182ebb3789322345e22cf750f88ae167and# the Free Software Foundation; either version 3 of the License, or
0ad489b182ebb3789322345e22cf750f88ae167and# (at your option) any later version.
0ad489b182ebb3789322345e22cf750f88ae167and# This program is distributed in the hope that it will be useful,
0ad489b182ebb3789322345e22cf750f88ae167and# but WITHOUT ANY WARRANTY; without even the implied warranty of
0ad489b182ebb3789322345e22cf750f88ae167and# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0ad489b182ebb3789322345e22cf750f88ae167and# GNU General Public License for more details.
0ad489b182ebb3789322345e22cf750f88ae167and# You should have received a copy of the GNU General Public License
0ad489b182ebb3789322345e22cf750f88ae167and# along with this program. If not, see <http://www.gnu.org/licenses/>.
0ad489b182ebb3789322345e22cf750f88ae167and# Some parser code from GLib
0ad489b182ebb3789322345e22cf750f88ae167and# Copyright (C) 2008-2011 Red Hat, Inc.
0ad489b182ebb3789322345e22cf750f88ae167and# This library is free software; you can redistribute it and/or
0ad489b182ebb3789322345e22cf750f88ae167and# modify it under the terms of the GNU Lesser General Public
0ad489b182ebb3789322345e22cf750f88ae167and# License as published by the Free Software Foundation; either
0ad489b182ebb3789322345e22cf750f88ae167and# version 2 of the License, or (at your option) any later version.
0ad489b182ebb3789322345e22cf750f88ae167and# This library is distributed in the hope that it will be useful,
0ad489b182ebb3789322345e22cf750f88ae167and# but WITHOUT ANY WARRANTY; without even the implied warranty of
0ad489b182ebb3789322345e22cf750f88ae167and# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0ad489b182ebb3789322345e22cf750f88ae167and# Lesser General Public License for more details.
0ad489b182ebb3789322345e22cf750f88ae167and# You should have received a copy of the GNU Lesser General
0ad489b182ebb3789322345e22cf750f88ae167and# Public License along with this library; if not, write to the
0ad489b182ebb3789322345e22cf750f88ae167and# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
0ad489b182ebb3789322345e22cf750f88ae167and# Boston, MA 02111-1307, USA.
0ad489b182ebb3789322345e22cf750f88ae167and# Portions by: David Zeuthen <davidz@redhat.com>
0ad489b182ebb3789322345e22cf750f88ae167and# DBus interfaces are defined here:
0ad489b182ebb3789322345e22cf750f88ae167and# http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format
0ad489b182ebb3789322345e22cf750f88ae167and# The introspection data format has become the standard way to represent a
0ad489b182ebb3789322345e22cf750f88ae167and# DBus interface. For many examples see /usr/share/dbus-1/interfaces/ on a
0ad489b182ebb3789322345e22cf750f88ae167and# typical linux machine.
0ad489b182ebb3789322345e22cf750f88ae167and# A word about annotations. These are extra flags or values that can be
0ad489b182ebb3789322345e22cf750f88ae167and# assigned to anything. So far, the codegen supports this annotation:
0ad489b182ebb3789322345e22cf750f88ae167and# - An annotation specified in the specification that tells us what C symbol
0ad489b182ebb3789322345e22cf750f88ae167and# to generate for a given interface or method. By default the codegen will
0ad489b182ebb3789322345e22cf750f88ae167and# build up a symbol name from the DBus name.
0ad489b182ebb3789322345e22cf750f88ae167and# -----------------------------------------------------------------------------
0ad489b182ebb3789322345e22cf750f88ae167and # Lets us print problems like a compiler would
0ad489b182ebb3789322345e22cf750f88ae167and return self.annotations.get("org.freedesktop.DBus.GLib.CSymbol", self.name)
0ad489b182ebb3789322345e22cf750f88ae167and# The basic types that we support marshalling right now. These
0ad489b182ebb3789322345e22cf750f88ae167and# are the ones we can pass as basic arguments to libdbus directly.
0ad489b182ebb3789322345e22cf750f88ae167and# If the dbus and sssd types are identical we pass things directly.
0ad489b182ebb3789322345e22cf750f88ae167and# otherwise some copying is necessary.
0ad489b182ebb3789322345e22cf750f88ae167and 's': ( "DBUS_TYPE_STRING", "const char *", "const char *" ),
0ad489b182ebb3789322345e22cf750f88ae167and 'o': ( "DBUS_TYPE_OBJECT_PATH", "const char *", "const char *" ),
0ad489b182ebb3789322345e22cf750f88ae167and type = type[1:]
0ad489b182ebb3789322345e22cf750f88ae167and (self.dbus_constant, self.dbus_type, self.sssd_type) = BASIC_TYPES[type]
0ad489b182ebb3789322345e22cf750f88ae167and if not self.only_basic_args() and not self.use_raw_handler():
0ad489b182ebb3789322345e22cf750f88ae167and raise DBusXmlException("Method has complex arguments and requires " +
0ad489b182ebb3789322345e22cf750f88ae167and return self.annotations.get(anno, self.iface.annotations.get(anno)) == 'true'
0ad489b182ebb3789322345e22cf750f88ae167and raise DBusXmlException('Invalid access type %s'%self.access)
0ad489b182ebb3789322345e22cf750f88ae167and return "%s_get_%s" % (self.iface.c_name(), self.c_name())
0ad489b182ebb3789322345e22cf750f88ae167and sig = "void (*%s)(struct sbus_request *, void *data, %s *" % (name, self.sssd_type)
0ad489b182ebb3789322345e22cf750f88ae167and return self.annotations.get("org.freedesktop.DBus.GLib.CSymbol",
if with_names:
if with_names:
return str
out(" return sbus_request_return_array_as_variant(dbus_req, %s, (uint8_t*)out_val, prop_len, sizeof(%s));", prop.dbus_constant, prop.sssd_type)
if iface.properties:
iface_types = [ p.type for p in iface.properties ]
for prop in iface.properties:
out(" (%s_handler)(dbus_req, dbus_req->intf->handler_data, &%s_prop_val", prop.type, prop.type, new_line=False)
out(" ret = sbus_add_array_as_variant_to_dict(&iter_dict, \"%s\", %s, (uint8_t*)%s_out_val, %s_prop_len, sizeof(%s));", prop.c_name(), prop.dbus_constant, prop.type, prop.type, prop.sssd_type)
out(" ret = sbus_add_variant_to_dict(&iter_dict, \"%s\", %s, &%s_out_val);", prop.c_name(), prop.dbus_constant, prop.type)
for meth in iface.methods:
return invokers
for prop in iface.properties:
return invokers
if prop.readable:
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: