sbus_codegen revision b699c4d7f85a5404be1d1ee9450331aea869b886
0b062f4990db5cc6db2fe3398926f71b92a67407Brian Wellington# Stef Walter <stefw@redhat.com>
0b062f4990db5cc6db2fe3398926f71b92a67407Brian Wellington# Copyright (C) 2014 Red Hat
9016767f4e15191b7c763b8a4ad36a57dc2705a2Mark Andrews# This program is free software; you can redistribute it and/or modify
9016767f4e15191b7c763b8a4ad36a57dc2705a2Mark Andrews# it under the terms of the GNU General Public License as published by
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# the Free Software Foundation; either version 3 of the License, or
9016767f4e15191b7c763b8a4ad36a57dc2705a2Mark Andrews# (at your option) any later version.
9016767f4e15191b7c763b8a4ad36a57dc2705a2Mark Andrews# This program is distributed in the hope that it will be useful,
9016767f4e15191b7c763b8a4ad36a57dc2705a2Mark Andrews# but WITHOUT ANY WARRANTY; without even the implied warranty of
0b062f4990db5cc6db2fe3398926f71b92a67407Brian Wellington# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75c0816e8295e180f4bc7f10db3d0d880383bc1cMark Andrews# GNU General Public License for more details.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# You should have received a copy of the GNU General Public License
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# along with this program. If not, see <http://www.gnu.org/licenses/>.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Some parser code from GLib
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Copyright (C) 2008-2011 Red Hat, Inc.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# This library is free software; you can redistribute it and/or
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# modify it under the terms of the GNU Lesser General Public
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# License as published by the Free Software Foundation; either
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# version 2 of the License, or (at your option) any later version.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# This library is distributed in the hope that it will be useful,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# but WITHOUT ANY WARRANTY; without even the implied warranty of
75c0816e8295e180f4bc7f10db3d0d880383bc1cMark Andrews# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Lesser General Public License for more details.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# You should have received a copy of the GNU Lesser General
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Public License along with this library; if not, write to the
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Boston, MA 02111-1307, USA.
75c0816e8295e180f4bc7f10db3d0d880383bc1cMark Andrews# Portions by: David Zeuthen <davidz@redhat.com>
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# DBus interfaces are defined here:
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# The introspection data format has become the standard way to represent a
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# DBus interface. For many examples see /usr/share/dbus-1/interfaces/ on a
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# typical linux machine.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# A word about annotations. These are extra flags or values that can be
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# assigned to anything. So far, the codegen supports this annotation:
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# - An annotation specified in the specification that tells us what C symbol
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# to generate for a given interface or method. By default the codegen will
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# build up a symbol name from the DBus name.
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# -----------------------------------------------------------------------------
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein # Lets us print problems like a compiler would
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein return "%s:%d: %s" % (self.file, self.line, message)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein return self.annotations.get("org.freedesktop.DBus.GLib.CSymbol", self.name)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein return "%s_%s" % (self.iface.c_name(), self.c_name())
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein return "%s_%s" % (self.iface.c_name(), self.c_name())
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein def __init__(self, iface, name, signature, access):
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein raise DBusXmlException('Invalid access type %s'%self.access)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein return "%s_%s" % (self.iface.c_name(), self.c_name())
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein return self.annotations.get("org.freedesktop.DBus.GLib.CSymbol",
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# -----------------------------------------------------------------------------
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein# Code Generation
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein out("/* arguments for %s.%s */", parent.iface.name, parent.name)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein out("const struct sbus_arg_meta %s%s[] = {", parent.fq_c_name(), suffix)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein out(" { \"%s\", \"%s\" },", arg.name, arg.signature)
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein out("const struct sbus_method_meta %s__methods[] = {", iface.c_name())
75c0816e8295e180f4bc7f10db3d0d880383bc1cMark Andrews out("const struct sbus_signal_meta %s__signals[] = {", iface.c_name())
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein out("const struct sbus_property_meta %s__properties[] = {", iface.c_name())
75c0816e8295e180f4bc7f10db3d0d880383bc1cMark Andrews out(" SBUS_PROPERTY_READABLE | SBUS_PROPERTY_WRITABLE,")
60e5e10f8d2e2b0c41e8abad38cacd867caa6ab2Rob Austein out("extern const struct sbus_interface_meta %s_meta;", iface.c_name())
if iface.methods:
if iface.signals:
if iface.properties:
if iface.methods:
if iface.signals:
if iface.properties:
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: