sbus_codegen revision 58229439447d5617913a5a2e173b78105c694842
2de31518c3da27092120b40fc373cecf600d64e6Brian Wellington# Stef Walter <stefw@redhat.com>
2de31518c3da27092120b40fc373cecf600d64e6Brian Wellington# Copyright (C) 2014 Red Hat
4ae3a03bb7dbb050adddc051a5df6f3de057eb27Andreas Gustafsson# This program is free software; you can redistribute it and/or modify
4ae3a03bb7dbb050adddc051a5df6f3de057eb27Andreas Gustafsson# it under the terms of the GNU General Public License as published by
4ae3a03bb7dbb050adddc051a5df6f3de057eb27Andreas Gustafsson# the Free Software Foundation; either version 3 of the License, or
10e22ebcc3629be94d37bf408157e2c5ee5740e0Andreas Gustafsson# (at your option) any later version.
2732332fe53d00592109ef69c0075fcc2ad09db9Brian Wellington# This program is distributed in the hope that it will be useful,
2732332fe53d00592109ef69c0075fcc2ad09db9Brian Wellington# but WITHOUT ANY WARRANTY; without even the implied warranty of
2732332fe53d00592109ef69c0075fcc2ad09db9Brian Wellington# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8fa78d9ad5f5ab6c69d1d52b00b1ffcdf1bd5bebMichael Sawyer# GNU General Public License for more details.
8fa78d9ad5f5ab6c69d1d52b00b1ffcdf1bd5bebMichael Sawyer# You should have received a copy of the GNU General Public License
e544b507b8019a62c5d2716281f6832519a8791dDavid Lawrence# along with this program. If not, see <http://www.gnu.org/licenses/>.
09de21079e902c7356d936ef4f2a31060b36e5f3Brian Wellington# Some parser code from GLib
ee4429e13e08f30c366cdc5d10585388b8a9f212Michael Sawyer# Copyright (C) 2008-2011 Red Hat, Inc.
b8b9fa222645f250a0f09eb30da5af752941660cDavid Lawrence# This library is free software; you can redistribute it and/or
b8b9fa222645f250a0f09eb30da5af752941660cDavid Lawrence# modify it under the terms of the GNU Lesser General Public
3c7ce471aa8a1a9c5bc0ca9e41f406bdc9f0b2aeAndreas Gustafsson# License as published by the Free Software Foundation; either
8aff41ca8ac8dbd9671f3da824406a8783db49d1Brian Wellington# version 2 of the License, or (at your option) any later version.
8aff41ca8ac8dbd9671f3da824406a8783db49d1Brian Wellington# This library is distributed in the hope that it will be useful,
c9d7e543d0da2996d1cc52d3c5920141df49a4ecBrian Wellington# but WITHOUT ANY WARRANTY; without even the implied warranty of
c9d7e543d0da2996d1cc52d3c5920141df49a4ecBrian Wellington# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6dbf9cbe6a39a00de910ef843b9f864abf68bc40Brian Wellington# Lesser General Public License for more details.
6dbf9cbe6a39a00de910ef843b9f864abf68bc40Brian Wellington# You should have received a copy of the GNU Lesser General
17aac384e029f5dd3314876058c7501f4d84b90bBrian Wellington# Public License along with this library; if not, write to the
17aac384e029f5dd3314876058c7501f4d84b90bBrian Wellington# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
833535ea78ec7a15376b862fd288ffd00f808666Brian Wellington# Boston, MA 02111-1307, USA.
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington# Portions by: David Zeuthen <davidz@redhat.com>
3c7ce471aa8a1a9c5bc0ca9e41f406bdc9f0b2aeAndreas Gustafsson# DBus interfaces are defined here:
3c7ce471aa8a1a9c5bc0ca9e41f406bdc9f0b2aeAndreas Gustafsson# http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format
3562c9dc12f06eb964ccefd3291a012f4e6b1743Brian Wellington# The introspection data format has become the standard way to represent a
3562c9dc12f06eb964ccefd3291a012f4e6b1743Brian Wellington# DBus interface. For many examples see /usr/share/dbus-1/interfaces/ on a
4d5c668a91c6e5a26653031dd137292bfc03da52Andreas Gustafsson# typical linux machine.
f437f6ffae28f88334cf47ce8f948cbf40331ffaAndreas Gustafsson# A word about annotations. These are extra flags or values that can be
704d6eeab1d8d6a2aeb99c37fa5a97322d9340fcBrian Wellington# assigned to anything. So far, the codegen supports this annotation:
ed8ba54e644957e0ebd51601552193275299ca8dAndreas Gustafsson# - An annotation specified in the specification that tells us what C symbol
ed8ba54e644957e0ebd51601552193275299ca8dAndreas Gustafsson# to generate for a given interface or method. By default the codegen will
ed8ba54e644957e0ebd51601552193275299ca8dAndreas Gustafsson# build up a symbol name from the DBus name.
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafsson# -----------------------------------------------------------------------------
f8abaa0fae7f75d9601c10b6a4af8dd907494d45Mark Andrews # Lets us print problems like a compiler would
1addbb84718fdb7635459ed05f060be086e88f35Andreas Gustafsson return "%s:%d: %s" % (self.file, self.line, message)
90cd33e0baf23574a88a4c967afec8b95a1801deAndreas Gustafsson return self.annotations.get("org.freedesktop.DBus.GLib.CSymbol", self.name)
517950ae99fa271b034a5cfec1c9fbb62696f975Mark Andrews# The basic types that we support marshalling right now. These
517950ae99fa271b034a5cfec1c9fbb62696f975Mark Andrews# are the ones we can pass as basic arguments to libdbus directly.
517950ae99fa271b034a5cfec1c9fbb62696f975Mark Andrews# If the dbus and sssd types are identical we pass things directly.
f9870620b346ed267023dc98ee81adcfef2e16b7Andreas Gustafsson# otherwise some copying is necessary.
dfd7798d8b870abf03795d8095297a4b982ab6e9Mark Andrews 'y': ( "DBUS_TYPE_BYTE", "uint8_t", "uint8_t" ),
19ff7edc1a6388085193f5487e1599f45aa62648Mark Andrews 'b': ( "DBUS_TYPE_BOOLEAN", "dbus_bool_t", "bool" ),
19ff7edc1a6388085193f5487e1599f45aa62648Mark Andrews 'n': ( "DBUS_TYPE_INT16", "int16_t", "int16_t" ),
19ff7edc1a6388085193f5487e1599f45aa62648Mark Andrews 'q': ( "DBUS_TYPE_UINT16", "uint16_t", "uint16_t" ),
8a0ff6c15cb20c903f9e16a3d5c2cab603478bc3Mark Andrews 'i': ( "DBUS_TYPE_INT32", "int32_t", "int32_t" ),
8a0ff6c15cb20c903f9e16a3d5c2cab603478bc3Mark Andrews 'u': ( "DBUS_TYPE_UINT32", "uint32_t", "uint32_t" ),
8a0ff6c15cb20c903f9e16a3d5c2cab603478bc3Mark Andrews 'x': ( "DBUS_TYPE_INT64", "int64_t", "int64_t" ),
8a0ff6c15cb20c903f9e16a3d5c2cab603478bc3Mark Andrews 't': ( "DBUS_TYPE_UINT64", "uint64_t", "uint64_t" ),
a6dbd6b6604e27ae3c7190de20dbcaaa6e5a1fd8Andreas Gustafsson 'd': ( "DBUS_TYPE_DOUBLE", "double", "double" ),
42928d936e79dbda7ea00bbcab6e5d8034a95bf8Andreas Gustafsson 's': ( "DBUS_TYPE_STRING", "const char *", "const char *" ),
0c0619cc1983ff58e855c5159d8892e46dddac5eBrian Wellington 'o': ( "DBUS_TYPE_OBJECT_PATH", "const char *", "const char *" ),
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley type = type[1:]
383665e42ad838046472e847b16c4e0d3f1aaf76Bob Halley (self.dbus_constant, self.dbus_type, self.sssd_type) = BASIC_TYPES[type]
6b5a6fbe1cc0ceb7e2b516aaada596b79360a5b8Bob Halley # If types are not identical, we can't do array (yet)
6b5a6fbe1cc0ceb7e2b516aaada596b79360a5b8Bob Halley self.is_basic = (self.dbus_type == self.sssd_type)
d3a86da2e8f09e2c3f55721aae537b9cacc7e537Andreas Gustafsson if not self.only_basic_args() and not self.use_raw_handler():
850d70818503ca1b0f98c9c70b16b51e789fd705Andreas Gustafsson raise DBusXmlException("Method has complex arguments and requires " +
850d70818503ca1b0f98c9c70b16b51e789fd705Andreas Gustafsson "the 'org.freedesktop.sssd.RawHandler' annotation")
3c82f274bd880a33fdaf211af4fe8f6b3d6ca556David Lawrence return "%s_%s" % (self.iface.c_name(), self.c_name())
3c82f274bd880a33fdaf211af4fe8f6b3d6ca556David Lawrence return self.annotations.get(anno, self.iface.annotations.get(anno)) == 'true'
3c82f274bd880a33fdaf211af4fe8f6b3d6ca556David Lawrence return "".join([arg.type for arg in self.in_args])
5afc10d6d8278c9ab34b9f6c82ef7bb3bfefd0efAndreas Gustafsson return "%s_%s" % (self.iface.c_name(), self.c_name())
5afc10d6d8278c9ab34b9f6c82ef7bb3bfefd0efAndreas Gustafsson def __init__(self, iface, name, type, access):
ebfcb6cf66283096ebda1503b6cc042ce86b6bedBrian Wellington raise DBusXmlException('Invalid access type %s'%self.access)
c379c1bddb2d84c9219ab6c394b33aa866b9f3bfAndreas Gustafsson return "%s_%s" % (self.iface.c_name(), self.c_name())
c379c1bddb2d84c9219ab6c394b33aa866b9f3bfAndreas Gustafsson return "%s_get_%s" % (self.iface.c_name(), self.c_name())
17442ccc2b2e9c3b3bfc337f0fdfad6186fbb123Mark Andrews sig = "void (*%s)(struct sbus_request *, void *data, %s *" % (name, self.sssd_type)
a3e41e3c03a32b00fc243fce538a39ddc7237885Andreas Gustafsson return self.annotations.get("org.freedesktop.DBus.GLib.CSymbol",
fa3cbea8bfba19d1c11f9a6ad20f40a2c15377f0Brian Wellington# -----------------------------------------------------------------------------
fa3cbea8bfba19d1c11f9a6ad20f40a2c15377f0Brian Wellington# Code Generation
c03298d879554fc5dc197c28fd4b686e0d880ee3Mark Andrews # NOTE: Would like to use the following syntax for this function
c03298d879554fc5dc197c28fd4b686e0d880ee3Mark Andrews # but need to wait until python3 until it is supported:
04c22ceaf2d3812eaab69d79958d0e0d62048cd2Mark Andrews assert not kwargs, "unknown keyword argument(s): %s" % str(kwargs)
389c749a5ee18f1c0d6278ae49f2aae5d5f0d2dcMark Andrewsdef method_function_pointer(meth, name, with_names=False):
72fa265baa3d138b43427bcb5c0838740f807045Mark Andrews return "int (*%s)(struct sbus_request *%s, void *%s%s)" % \
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews return prop.getter_signature(prop.getter_name())
b1cde6bf3a8e3a77eb77caf97df0d7ec5c8450dfBrian Wellingtondef forward_method_invoker(signature, args):
f8abaa0fae7f75d9601c10b6a4af8dd907494d45Mark Andrews out("/* invokes a handler with a '%s' DBus signature */", signature)
f8abaa0fae7f75d9601c10b6a4af8dd907494d45Mark Andrews out("static int invoke_%s_method(struct sbus_request *dbus_req, void *function_ptr);", signature)
37d1c8ee546ae89720c3e17e57ee3a05e9cdc7b9Brian Wellington out("/* invokes a handler with a '%s' DBus signature */", signature)
37d1c8ee546ae89720c3e17e57ee3a05e9cdc7b9Brian Wellington out("static int invoke_%s_method(struct sbus_request *dbus_req, void *function_ptr)", signature)
78db9e8f4b686fde6dfa0ec85a68c06cc9d4bf28Brian Wellington out(" int (*handler)(struct sbus_request *, void *%s) = function_ptr;", method_arg_types(args))
78db9e8f4b686fde6dfa0ec85a68c06cc9d4bf28Brian Wellington out(" if (!sbus_request_parse_or_finish(dbus_req,")
450995b90c8cb66d82c2377d4f9bd9812a132c30Andreas Gustafsson out(" %s, &arg_%d,", arg.dbus_constant, i)
190fbe9738bd0c1b9b13732bb8bd56b2b7c71640David Lawrence out(" return (handler)(dbus_req, dbus_req->intf->instance_data", new_line=False)
c40085afa75a5eae732ec1198384dd5cb24400b6Bob Halley out("/* invokes a getter with an array of '%s' DBus type */", prop.dbus_type)
7b438bdb9b821f9f1c96443762072e137716048dBrian Wellington out("/* invokes a getter with a '%s' DBus type */", prop.dbus_type)
c40085afa75a5eae732ec1198384dd5cb24400b6Bob Halley out("static int %s(struct sbus_request *dbus_req, void *function_ptr)",
588b63e1a86fb707172830e14897da624ed380edMark Andrews out(" %s", prop.getter_signature("handler"), new_line=False)
bb17aa91c14de959b191a200df61afb6a68f110fBrian Wellington out(" (handler)(dbus_req, dbus_req->intf->instance_data, &prop_val", new_line=False)
6850cdd4497424c9d42ade487edfde9fb9a47de9Brian Wellington out(" out_val = prop_val == NULL ? \"\" : prop_val;")
2a37aa188c2297e0c0856c3e5740c43dd426a432Mark 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)
6c87cf19970a9eef43c1e38227cd23b3a2f6151aMark Andrews out(" return sbus_request_return_as_variant(dbus_req, %s, &out_val);", prop.dbus_constant)
fb04db11ee6aad3ac3e023ab89b5f9d8a4d5674dMichael Sawyer forward_method_invoker(signature, meth.in_args)
fb04db11ee6aad3ac3e023ab89b5f9d8a4d5674dMichael Sawyer source_method_invoker(signature, meth.in_args)
fb04db11ee6aad3ac3e023ab89b5f9d8a4d5674dMichael Sawyer out("static int %s(struct sbus_request *dbus_req, void *function_ptr);",
ff7e6f2791cc5ad7c5f401a184b88343fde5ec3cAndreas Gustafsson out("int %s_finish(struct sbus_request *req%s)",
693ddf84daa745a0ea8ca311a8154dfa03eabc43Andreas Gustafsson meth.fq_c_name(), method_arg_types(meth.out_args, with_names=True))
ff7e6f2791cc5ad7c5f401a184b88343fde5ec3cAndreas Gustafsson out(" %s cast_%s = arg_%s;", arg.dbus_type, arg.c_name(), arg.c_name())
ff7e6f2791cc5ad7c5f401a184b88343fde5ec3cAndreas Gustafsson out(" return sbus_request_return_and_finish(req,")
4da10bce4bf64b574b59aa4fb5be0f237d0d41edBrian Wellington out("DBUS_TYPE_ARRAY, %s, &arg_%s, len_%s,",
3f123dcc2fe5d2cd08ca91b732741d86a4036906Brian Wellington arg.dbus_constant, arg.c_name(), arg.c_name())
16ea60d0dbbaf1206f4800cb16744ef568fd7be8Michael Sawyer out("%s, &cast_%s,", arg.dbus_constant, arg.c_name())
16ea60d0dbbaf1206f4800cb16744ef568fd7be8Michael Sawyer out("%s, &arg_%s,", arg.dbus_constant, arg.c_name())
d15f51c600ed29b2dc379c433fb226c3a13ac0bbAndreas Gustafsson out(" %s *%s", arg.dbus_type, arg.c_name())
d15f51c600ed29b2dc379c433fb226c3a13ac0bbAndreas Gustafsson out(" %s %s;", arg.dbus_type, arg.c_name())
cef18335b7f37bf02bc9e9f2c8750a3a9dcd718aAndreas Gustafsson types = [arg.sssd_type for arg in meth.in_args]
e412ae947df6de858883564b8676a9650df70d9aMark Andrews out("/* arguments for %s.%s */", parent.iface.name, parent.name)
e412ae947df6de858883564b8676a9650df70d9aMark Andrews out("const struct sbus_arg_meta %s%s[] = {", parent.fq_c_name(), suffix)
07a926724c0a91d85b85a94441938d0094e88cffMark Andrews out(" { \"%s\", \"%s\" },", arg.name, arg.type)
922e6a3c2ac4ef900dd9dc99f0cc137f18372583Andreas Gustafsson source_args(meth, meth.out_args, "__out")
337ca1838428c52bca3c72288342ce3dee550a04Andreas Gustafsson out("const struct sbus_method_meta %s__methods[] = {", iface.c_name())
27d725f2b0f8d176d4625dc8b2ed71269b25c9a7Andreas Gustafsson out(" offsetof(struct %s, %s),", iface.c_name(), meth.c_name())
27d725f2b0f8d176d4625dc8b2ed71269b25c9a7Andreas Gustafsson if meth.use_raw_handler() or not meth.in_args:
c89ac488df58cf6a37918cd00236eedf015830f8Andreas Gustafsson out(" invoke_%s_method,", meth.in_signature())
c50a002bd1e36d13e95d74b43ed4a2b5d6fdcec3Mark Andrews out("const struct sbus_signal_meta %s__signals[] = {", iface.c_name())
07a46d6dca37ef96b6e9c1fc0c2789983d91819cAndreas Gustafsson out("/* property info for %s */", iface.name)
6d85ebc2d2ccbb8ef01c3ac1659686d3c2be0377Brian Wellington out("const struct sbus_property_meta %s__properties[] = {", iface.c_name())
98b8d49c0c0bbace27966eed5811bc81255ce297Brian Wellington out(" SBUS_PROPERTY_READABLE | SBUS_PROPERTY_WRITABLE,")
a94948ad5b3b258ce9503b7322bdf82c0baabcabAndreas Gustafsson out(" offsetof(struct %s, %s),", iface.c_name(), prop.getter_name())
be1d71fd17c92b0acee36ba43ebe4daa498e8014Mark Andrews out("extern const struct sbus_interface_meta %s_meta;", iface.c_name())
afd2f40b3cff8c3c307155bdc27e5b60e9115545Andreas Gustafsson out("/* interface info for %s */", iface.name)
afd2f40b3cff8c3c307155bdc27e5b60e9115545Andreas Gustafsson out("const struct sbus_interface_meta %s_meta = {", iface.c_name())
91ac60fe11b3ebd095c5fed0db343b2c9a97e646Mark Andrewsdef generate_source(ifaces, filename, include_header=None):
83d2840b6f1a5ec898e441be148ddd3211f11583Bob Halley out("/* The following definitions are auto-generated from %s */", basename)
42e31e6ef7689e0c0569a1f9a5c250d73870b073Michael Graff out("#include \"%s\"", os.path.basename(include_header))
a405a53d536521e6c93f47485aacd7c1a1ffb29eAndreas Gustafsson meth_invokers = forward_method_invokers(ifaces)
a405a53d536521e6c93f47485aacd7c1a1ffb29eAndreas Gustafsson prop_invokers = forward_prop_invokers(ifaces)
b7e031d5173476224027407d8e23eaa7557fc396Andreas Gustafsson out("/* finish function for %s */", meth.name)
b7e031d5173476224027407d8e23eaa7557fc396Andreas Gustafsson out("int %s_finish(struct sbus_request *req%s);",
b7e031d5173476224027407d8e23eaa7557fc396Andreas Gustafsson meth.fq_c_name(), method_arg_types(meth.out_args, with_names=True))
cef18335b7f37bf02bc9e9f2c8750a3a9dcd718aAndreas Gustafsson out(" struct sbus_vtable vtable; /* derive from sbus_vtable */")
94361d586755d4de09b717782f7002e9dd282c89Andreas Gustafsson out(" %s;", method_function_pointer(meth, meth.c_name(), with_names=True))
4440f995911810aaa98d8985ac1a8192095879f2Michael Graff out("#define %s \"%s\"", iface.c_name().upper(), iface.name)
abaec24086f0cc3d7c0994ca9d2247b40eb6aaedBrian Wellington out("#define %s \"%s\"", meth.fq_c_name().upper(), meth.name)
abaec24086f0cc3d7c0994ca9d2247b40eb6aaedBrian Wellington out("#define %s \"%s\"", sig.fq_c_name().upper(), sig.name)
cef18335b7f37bf02bc9e9f2c8750a3a9dcd718aAndreas Gustafsson out("#define %s \"%s\"", prop.fq_c_name().upper(), prop.name)
3ad16d4c3a5029662d4ec804f7644739d011d03dBob Halley guard = "__%s__" % re.sub(r'([^_A-Z0-9])', "_", basename.upper())
32b2cdf212de957e3f9b0efca59f098ed4fb42deBrian Wellington out("/* The following declarations are auto-generated from %s */", basename)
3113e4dac81fa7b9f0ee5d663d54fbb8ed92738dBob Halley out("/* ------------------------------------------------------------------------")
8cf8a04209c3b6c8d4f0936f1dce06b629605c81Michael Graff out(" * Various constants of interface and method names mostly for use by clients")
1fc26319b5d69d19a7a31c8d0ab1afc2beef0c41Andreas Gustafsson out("/* ------------------------------------------------------------------------")
cef18335b7f37bf02bc9e9f2c8750a3a9dcd718aAndreas Gustafsson out(" * These structures are filled in by implementors of the different")
7da0286b540515c82ea83163d6cba59a64fa3eddMichael Graff out(" * dbus interfaces to handle method calls.")
7da0286b540515c82ea83163d6cba59a64fa3eddMichael Graff out(" * Handler functions of type sbus_msg_handler_fn accept raw messages,")
c4ec2c3190175705df255aa3d5e842a96137a5a1Andreas Gustafsson out(" * other handlers are typed appropriately. If a handler that is")
c4ec2c3190175705df255aa3d5e842a96137a5a1Andreas Gustafsson out(" * set to NULL is invoked it will result in a")
8529c3cdc6abdf3514cb0127313a976bbc3b3936Andreas Gustafsson out(" * org.freedesktop.DBus.Error.NotSupported error for the caller.")
87ecd67dae468cf5c9bae213c6fa321449b2ebc2Andreas Gustafsson out(" * Handlers have a matching xxx_finish() function (unless the method has")
87ecd67dae468cf5c9bae213c6fa321449b2ebc2Andreas Gustafsson out(" * accepts raw messages). These finish functions the")
f38a84ce830efefe48838425ab281e0ae2a91d0eAndreas Gustafsson out(" * sbus_request_return_and_finish() with the appropriate arguments to")
f38a84ce830efefe48838425ab281e0ae2a91d0eAndreas Gustafsson out(" * construct a valid reply. Once a finish function has been called, the")
f38a84ce830efefe48838425ab281e0ae2a91d0eAndreas Gustafsson out(" * @dbus_req it was called with is freed and no longer valid.")
4b809ba3464c9fb6bb08e9153b9286a8f8a37b01Brian Wellington out("/* ------------------------------------------------------------------------")
a69cebac84ec223b908e056678fa7c1181785b20Andreas Gustafsson out(" * These structure definitions are filled in with the information about")
a69cebac84ec223b908e056678fa7c1181785b20Andreas Gustafsson out(" * the interfaces, methods, properties and so on.")
d9ec31a329a14588127b0a15618dec53ca41c73eAndreas Gustafsson out(" * The actual definitions are found in the accompanying C file next")
7d8d82cee0910a0252e1c37bace732e996789772Andreas Gustafsson# -----------------------------------------------------------------------------
7d8d82cee0910a0252e1c37bace732e996789772Andreas Gustafsson# XML Interface Parsing
1aae88078f409b39c24e2313ffdd767ed29ac787Brian Wellington raise DBusXmlException("Missing attribute '%s'" % name)
17a28c1f02c5093b207a3b64201aa9e71df78ebaAndreas Gustafsson raise DBusXmlException("Empty attribute '%s'" % name)
b5232b135db580a2c16666e74a82f11130e0731fAndreas Gustafsson parser = xml.parsers.expat.ParserCreate()
cea88d887559f209ae9d993e0a8fb58d03f60e77Brian Wellington parser.CommentHandler = self.handle_comment
cea88d887559f209ae9d993e0a8fb58d03f60e77Brian Wellington parser.CharacterDataHandler = self.handle_char_data
cea88d887559f209ae9d993e0a8fb58d03f60e77Brian Wellington parser.StartElementHandler = self.handle_start_element
a7705f38e91cc6afaba0426f6b452c9ae5a4efeaAndreas Gustafsson parser.EndElementHandler = self.handle_end_element
405ffb1f0d2c12d199f85f03973d1a02ac12e000Andreas Gustafsson elif self.cur_object and name == STATE_ANNOTATION:
405ffb1f0d2c12d199f85f03973d1a02ac12e000Andreas Gustafsson self.cur_object.annotations[expect_attr(attrs, 'name')] = val
b0f941a50f24656b3523609f86cead41b0269c7aBrian Wellington iface = Interface(expect_attr(attrs, 'name'))
8af0b86ade4c15a7db207bd7643f8a9f6cb5a648David Lawrence method = Method(self.cur_object, expect_attr(attrs, 'name'))
69d17bea6be937b92f3375e6249b5677c90f4fe2Andreas Gustafsson signal = Signal(self.cur_object, expect_attr(attrs, 'name'))
a4c55a3d0813e00e3d7846cc9736110c61d0a2baAndreas Gustafsson raise DBusXmlException('Invalid direction "%s"' % direction)
e5f5ec73a710d21067d4721a9e82f2399f2f6c25David Lawrence assert False, 'Unhandled state "%s" while entering element with name "%s"' % (self.state, name)
9594482ba300a4d694162fa62ba636c7dd00d3b6Brian Wellington self.cur_object_stack.append(old_cur_object)
c5944292e9ebee4a39fe939b9a16fe5596808556David Lawrence self.cur_object = self.cur_object_stack.pop()
c5944292e9ebee4a39fe939b9a16fe5596808556David Lawrence parser = optparse.OptionParser("usage: %prog [options] introspect.xml ...")
c5944292e9ebee4a39fe939b9a16fe5596808556David Lawrence parser.set_description("sbus_codegen generates sbus interface structures \
c5944292e9ebee4a39fe939b9a16fe5596808556David Lawrence help="'header' or 'source' (default: header)",
529a6b5224d751504027293a766a4c8b81241869Brian Wellington help="Set output file name (default: stdout)",
febf5f8b55abb2e6e840488a29a5ef4e20654f67David Lawrence print >> sys.stderr, "sbus_codegen: no input file specified"
c34bdef6bd197a04990e52469ad68481532dd35aAndreas Gustafsson if options.mode not in ["header", "source"]:
c34bdef6bd197a04990e52469ad68481532dd35aAndreas Gustafsson print >> sys.stderr, "sbus_codegen: specify --mode=header or --mode=source"
ffea7c2e73a0771c80b32df93cf4547fcea64eaeAndreas Gustafsson generate_header(parser.parsed_interfaces, filename)