sbus_codegen revision 4f7f714e118e95896fac5239c7a8b529c39a4758
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# Stef Walter <stefw@redhat.com>
3970098dcd2a7122541667b4b56cea8abce8ccf2Mark Andrews# Copyright (C) 2014 Red Hat
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# This program is free software; you can redistribute it and/or modify
fcc9f7f86c2fa2ceb8a5c16dc934fea7fa6887f2Andreas Gustafsson# it under the terms of the GNU General Public License as published by
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# the Free Software Foundation; either version 3 of the License, or
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# (at your option) any later version.
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# This program is distributed in the hope that it will be useful,
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# but WITHOUT ANY WARRANTY; without even the implied warranty of
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# GNU General Public License for more details.
fcc9f7f86c2fa2ceb8a5c16dc934fea7fa6887f2Andreas Gustafsson# You should have received a copy of the GNU General Public License
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# along with this program. If not, see <http://www.gnu.org/licenses/>.
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# Some parser code from GLib
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# Copyright (C) 2008-2011 Red Hat, Inc.
3970098dcd2a7122541667b4b56cea8abce8ccf2Mark Andrews# This library is free software; you can redistribute it and/or
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# modify it under the terms of the GNU Lesser General Public
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# License as published by the Free Software Foundation; either
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# version 2 of the License, or (at your option) any later version.
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# This library is distributed in the hope that it will be useful,
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# but WITHOUT ANY WARRANTY; without even the implied warranty of
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# Lesser General Public License for more details.
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# You should have received a copy of the GNU Lesser General
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# Public License along with this library; if not, write to the
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# Boston, MA 02111-1307, USA.
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# Portions by: David Zeuthen <davidz@redhat.com>
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# DBus interfaces are defined here:
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# The introspection data format has become the standard way to represent a
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# DBus interface. For many examples see /usr/share/dbus-1/interfaces/ on a
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# typical linux machine.
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# A word about annotations. These are extra flags or values that can be
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# assigned to anything. So far, the codegen supports this annotation:
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# - An annotation specified in the specification that tells us what C symbol
3970098dcd2a7122541667b4b56cea8abce8ccf2Mark Andrews# to generate for a given interface or method. By default the codegen will
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# build up a symbol name from the DBus name.
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# -----------------------------------------------------------------------------
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce # Lets us print problems like a compiler would
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce return "%s:%d: %s" % (self.file, self.line, message)
1fa26403d7679235a30fbf6289f68fed5872df30Mark Andrews return self.annotations.get("org.freedesktop.DBus.GLib.CSymbol", self.name)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# The basic types that we support marshalling right now. These
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# are the ones we can pass as basic arguments to libdbus directly.
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# If the dbus and sssd types are identical we pass things directly.
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# otherwise some copying is necessary.
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce 'b': ( "DBUS_TYPE_BOOLEAN", "dbus_bool_t", "bool" ),
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson 'n': ( "DBUS_TYPE_INT16", "int16_t", "int16_t" ),
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson 'q': ( "DBUS_TYPE_UINT16", "uint16_t", "uint16_t" ),
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce 'u': ( "DBUS_TYPE_UINT32", "uint32_t", "uint32_t" ),
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson 'x': ( "DBUS_TYPE_INT64", "int64_t", "int64_t" ),
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson 't': ( "DBUS_TYPE_UINT64", "uint64_t", "uint64_t" ),
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce 's': ( "DBUS_TYPE_STRING", "const char *", "const char *" ),
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce 'o': ( "DBUS_TYPE_OBJECT_PATH", "const char *", "const char *" ),
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce type = type[1:]
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce (self.dbus_constant, self.dbus_type, self.sssd_type) = BASIC_TYPES[type]
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce # If types are not identical, we can't do array (yet)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce self.is_basic = (self.dbus_type == self.sssd_type)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce if not self.only_basic_args() and not self.use_raw_handler():
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce raise DBusXmlException("Method has complex arguments and requires " +
fcc9f7f86c2fa2ceb8a5c16dc934fea7fa6887f2Andreas Gustafsson "the 'org.freedesktop.sssd.RawHandler' annotation")
fcc9f7f86c2fa2ceb8a5c16dc934fea7fa6887f2Andreas Gustafsson return "%s_%s" % (self.iface.c_name(), self.c_name())
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce return self.annotations.get(anno, self.iface.annotations.get(anno)) == 'true'
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce return "".join([arg.type for arg in self.in_args])
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce return "%s_%s" % (self.iface.c_name(), self.c_name())
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce raise DBusXmlException('Invalid access type %s'%self.access)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce return "%s_%s" % (self.iface.c_name(), self.c_name())
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce return "%s_get_%s" % (self.iface.c_name(), self.c_name())
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce sig = "void (*%s)(struct sbus_request *, void *data, %s *" % (name, self.sssd_type)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce return self.annotations.get("org.freedesktop.DBus.GLib.CSymbol",
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# -----------------------------------------------------------------------------
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce# Code Generation
c71787bd6356c92e9c7d0a174cd63ab17fcf34c6Eric Luce # NOTE: Would like to use the following syntax for this function
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce # but need to wait until python3 until it is supported:
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce assert not kwargs, "unknown keyword argument(s): %s" % str(kwargs)
b9c96971964d87c2705c8dc29300ff8103479ee6Andreas Gustafssondef method_function_pointer(meth, name, with_names=False):
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce return "int (*%s)(struct sbus_request *%s, void *%s%s)" % \
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("/* invokes a handler with a '%s' DBus signature */", signature)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("static int invoke_%s_method(struct sbus_request *dbus_req, void *function_ptr);", signature)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("/* invokes a handler with a '%s' DBus signature */", signature)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("static int invoke_%s_method(struct sbus_request *dbus_req, void *function_ptr)", signature)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" int (*handler)(struct sbus_request *, void *%s) = function_ptr;", method_arg_types(args))
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" if (!sbus_request_parse_or_finish(dbus_req,")
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" return (handler)(dbus_req, dbus_req->intf->instance_data", new_line=False)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" %s", prop.getter_signature("%shandler" % prefix), new_line=False)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("/* invokes a getter with an array of '%s' DBus type */", prop.dbus_type)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("/* invokes a getter with a '%s' DBus type */", prop.dbus_type)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("static int %s(struct sbus_request *dbus_req, void *function_ptr)",
3970098dcd2a7122541667b4b56cea8abce8ccf2Mark Andrews out(" %s", prop.getter_signature("handler"), new_line=False)
3970098dcd2a7122541667b4b56cea8abce8ccf2Mark Andrews out(" (handler)(dbus_req, dbus_req->intf->instance_data, &prop_val", new_line=False)
3970098dcd2a7122541667b4b56cea8abce8ccf2Mark Andrews out(" out_val = prop_val == NULL ? \"\" : prop_val;")
3970098dcd2a7122541667b4b56cea8abce8ccf2Mark Andrews out(" out_val = prop_val == NULL ? \"/\" : prop_val;")
3970098dcd2a7122541667b4b56cea8abce8ccf2Mark Andrews 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)
3970098dcd2a7122541667b4b56cea8abce8ccf2Mark Andrews out(" return sbus_request_return_as_variant(dbus_req, %s, &out_val);", prop.dbus_constant)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("/* invokes GetAll for the '%s' interface */", iface.name)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("static int invoke_%s_get_all(struct sbus_request *dbus_req, void *function_ptr)",
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" struct sbus_interface *intf = dbus_req->intf;")
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" const struct sbus_property_meta *property;")
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce iface_types = [ p.type for p in iface.properties ]
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce for prop in [ p for p in prop_invokers.values() if p.type in iface_types ]:
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" reply = dbus_message_new_method_return(dbus_req->message);")
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" dbus_message_iter_init_append(reply, &iter);")
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" property = sbus_meta_find_property(intf->vtable->meta, \"%s\");", prop.c_name())
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" if (property != NULL && property->flags & SBUS_PROPERTY_READABLE) {")
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" %s_handler = VTABLE_FUNC(intf->vtable, property->vtable_offset_get);", prop.type)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" (%s_handler)(dbus_req, dbus_req->intf->instance_data, &%s_prop_val", prop.type, prop.type, new_line=False)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" %s_out_val = %s_prop_val == NULL ? \"\" : %s_prop_val;",
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" %s_out_val = %s_prop_val == NULL ? \"/\" : %s_prop_val;",
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson out(" %s_out_val = %s_prop_val;", prop.type, prop.type)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce 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)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" ret = sbus_add_variant_to_dict(&iter_dict, \"%s\", %s, &%s_out_val);", prop.c_name(), prop.dbus_constant, prop.type)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" dbret = dbus_message_iter_close_container(&iter, &iter_dict);")
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" return sbus_request_finish(dbus_req, reply);")
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("static int %s(struct sbus_request *dbus_req, void *function_ptr);",
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce meth.fq_c_name(), method_arg_types(meth.out_args, with_names=True))
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" %s cast_%s = arg_%s;", arg.dbus_type, arg.c_name(), arg.c_name())
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" return sbus_request_return_and_finish(req,")
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("%s, &cast_%s,", arg.dbus_constant, arg.c_name())
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("%s, &arg_%s,", arg.dbus_constant, arg.c_name())
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("/* arguments for %s.%s */", parent.iface.name, parent.name)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("const struct sbus_arg_meta %s%s[] = {", parent.fq_c_name(), suffix)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("const struct sbus_method_meta %s__methods[] = {", iface.c_name())
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" offsetof(struct %s, %s),", iface.c_name(), meth.c_name())
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("const struct sbus_signal_meta %s__signals[] = {", iface.c_name())
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("const struct sbus_property_meta %s__properties[] = {", iface.c_name())
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" SBUS_PROPERTY_READABLE | SBUS_PROPERTY_WRITABLE,")
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" offsetof(struct %s, %s),", iface.c_name(), prop.getter_name())
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("extern const struct sbus_interface_meta %s_meta;", iface.c_name())
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("const struct sbus_interface_meta %s_meta = {", iface.c_name())
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" invoke_%s_get_all, /* GetAll invoker */", iface.c_name())
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Lucedef generate_source(ifaces, filename, include_header=None):
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("/* The following definitions are auto-generated from %s */", basename)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("#include \"%s\"", os.path.basename(include_header))
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce # always generate getall, for interfaces without properties
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce meth.fq_c_name(), method_arg_types(meth.out_args, with_names=True))
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" struct sbus_vtable vtable; /* derive from sbus_vtable */")
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out(" %s;", method_function_pointer(meth, meth.c_name(), with_names=True))
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("#define %s \"%s\"", iface.c_name().upper(), iface.name)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("#define %s \"%s\"", meth.fq_c_name().upper(), meth.name)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("#define %s \"%s\"", sig.fq_c_name().upper(), sig.name)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("#define %s \"%s\"", prop.fq_c_name().upper(), prop.name)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce guard = "__%s__" % re.sub(r'([^_A-Z0-9])', "_", basename.upper())
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("/* The following declarations are auto-generated from %s */", basename)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce out("/* ------------------------------------------------------------------------")
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson out(" * Various constants of interface and method names mostly for use by clients")
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson out("/* ------------------------------------------------------------------------")
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson out(" * These structures are filled in by implementors of the different")
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson out(" * dbus interfaces to handle method calls.")
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson out(" * Handler functions of type sbus_msg_handler_fn accept raw messages,")
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson out(" * other handlers are typed appropriately. If a handler that is")
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson out(" * set to NULL is invoked it will result in a")
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson out(" * org.freedesktop.DBus.Error.NotSupported error for the caller.")
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson out(" * Handlers have a matching xxx_finish() function (unless the method has")
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson out(" * accepts raw messages). These finish functions the")
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson out(" * sbus_request_return_and_finish() with the appropriate arguments to")
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson out(" * construct a valid reply. Once a finish function has been called, the")
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson out(" * @dbus_req it was called with is freed and no longer valid.")
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson out("/* ------------------------------------------------------------------------")
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson out(" * These structure definitions are filled in with the information about")
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson out(" * the interfaces, methods, properties and so on.")
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson out(" * The actual definitions are found in the accompanying C file next")
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson# -----------------------------------------------------------------------------
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson# XML Interface Parsing
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson raise DBusXmlException("Missing attribute '%s'" % name)
5f09ce124cad9712a9675f17f83ddc915e734909Andreas Gustafsson raise DBusXmlException("Empty attribute '%s'" % name)
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce parser.CharacterDataHandler = self.handle_char_data
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce parser.StartElementHandler = self.handle_start_element
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce parser.EndElementHandler = self.handle_end_element
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce elif self.cur_object and name == STATE_ANNOTATION:
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce self.cur_object.annotations[expect_attr(attrs, 'name')] = val
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson method = Method(self.cur_object, expect_attr(attrs, 'name'))
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce signal = Signal(self.cur_object, expect_attr(attrs, 'name'))
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce raise DBusXmlException('Invalid direction "%s"' % direction)
f1fd37f759991616d454ce371a2390da45141593Andreas Gustafsson assert False, 'Unhandled state "%s" while entering element with name "%s"' % (self.state, name)
0a792c72e6b4aefed6fb9dcbf004f1100fe9dfe7Andreas Gustafsson parser = optparse.OptionParser("usage: %prog [options] introspect.xml ...")
727f5b8846457a33d06f515a10a7e1aa849ddf18Andreas Gustafsson parser.set_description("sbus_codegen generates sbus interface structures \
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce print >> sys.stderr, "sbus_codegen: no input file specified"
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce print >> sys.stderr, "sbus_codegen: specify --mode=header or --mode=source"
f293a69bcd1c1dd7bdac8f4102fc2398b9e475c8Eric Luce generate_header(parser.parsed_interfaces, filename)