sbus_codegen revision c2cc119de8eac712c040b3993f41c967ff2278de
#
# Authors:
# Stef Walter <stefw@redhat.com>
#
# Copyright (C) 2014 Red Hat
#
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# Some parser code from GLib
#
# Copyright (C) 2008-2011 Red Hat, Inc.
#
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA 02111-1307, USA.
#
# Portions by: David Zeuthen <davidz@redhat.com>
#
#
# DBus interfaces are defined here:
#
# http://dbus.freedesktop.org/doc/dbus-specification.html#introspection-format
#
# The introspection data format has become the standard way to represent a
# DBus interface. For many examples see /usr/share/dbus-1/interfaces/ on a
# typical linux machine.
#
# A word about annotations. These are extra flags or values that can be
# assigned to anything. So far, the codegen supports this annotation:
#
# - An annotation specified in the specification that tells us what C symbol
# to generate for a given interface or method. By default the codegen will
# build up a symbol name from the DBus name.
#
# -----------------------------------------------------------------------------
# Objects
line = 0
# Lets us print problems like a compiler would
elif self.file:
else:
return message
self.annotations = { }
self.args = []
else:
self.methods = []
self.signals = []
self.properties = []
# -----------------------------------------------------------------------------
# Code Generation
else:
else:
for sig in iface.signals:
if sig.args:
if sig.args:
else:
for prop in properties:
elif prop.readable:
elif prop.writable:
else:
if iface.methods:
else:
if iface.signals:
else:
if iface.properties:
else:
if include_header:
# The methods
if iface.methods:
# The signals array
if iface.signals:
# The properties array
if iface.properties:
# The sbus_interface structure
# All methods
for meth in iface.methods:
# TODO: Property getters and setters will go here
for meth in iface.methods:
for sig in iface.signals:
for prop in iface.properties:
if iface.methods:
# -----------------------------------------------------------------------------
# XML Interface Parsing
STATE_TOP = 'top'
STATE_NODE = 'node'
STATE_INTERFACE = 'interface'
STATE_METHOD = 'method'
STATE_SIGNAL = 'signal'
STATE_PROPERTY = 'property'
STATE_ARG = 'arg'
STATE_ANNOTATION = 'annotation'
STATE_IGNORED = 'ignored'
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:
else:
elif self.state == STATE_NODE:
if name == STATE_INTERFACE:
else:
elif self.state == STATE_INTERFACE:
if name == STATE_METHOD:
elif name == STATE_SIGNAL:
elif name == STATE_PROPERTY:
else:
elif self.state == STATE_METHOD:
else:
else:
elif self.state == STATE_SIGNAL:
else:
elif self.state == STATE_PROPERTY:
elif self.state == STATE_ARG:
else:
from standard XML Introspect data.")
print >> sys.stderr, "sbus_codegen: no input file specified"
sys.exit(2)
print >> sys.stderr, "sbus_codegen: specify --mode=header or --mode=source"
options, args = parse_options()
if options.output:
sys.stdout = buf = StringIO.StringIO()
else:
# Write output at end to be nice to 'make'
if options.output:
try:
main()
print >> sys.stderr, str(ex)
sys.exit(1)