sbus_codegen revision df4e1db5d41c903ae57fd880acc76a0ad84aa7b2
#
# 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 = { }
# The basic types that we support marshalling right now. These
# are the ones we can pass as basic arguments to libdbus directly.
# If the dbus and sssd types are identical we pass things directly.
# otherwise some copying is necessary.
BASIC_TYPES = {
'y': ( "DBUS_TYPE_BYTE", "uint8_t", "uint8_t" ),
'b': ( "DBUS_TYPE_BOOLEAN", "dbus_bool_t", "bool" ),
'n': ( "DBUS_TYPE_INT16", "int16_t", "int16_t" ),
'q': ( "DBUS_TYPE_UINT16", "uint16_t", "uint16_t" ),
'i': ( "DBUS_TYPE_INT32", "int32_t", "int32_t" ),
'u': ( "DBUS_TYPE_UINT32", "uint32_t", "uint32_t" ),
'x': ( "DBUS_TYPE_INT64", "int64_t", "int64_t" ),
't': ( "DBUS_TYPE_UINT64", "uint64_t", "uint64_t" ),
'd': ( "DBUS_TYPE_DOUBLE", "double", "double" ),
's': ( "DBUS_TYPE_STRING", "const char *", "const char *" ),
'o': ( "DBUS_TYPE_OBJECT_PATH", "const char *", "const char *" ),
}
self.type = type
if type[0] == 'a':
type = type[1:]
if type in BASIC_TYPES:
# If types are not identical, we can't do array (yet)
else:
return False
return True
self.args = []
else:
sig += " *, int *"
sig += ")"
return sig
self.methods = []
self.signals = []
self.properties = []
# -----------------------------------------------------------------------------
# Code Generation
# NOTE: Would like to use the following syntax for this function
# but need to wait until python3 until it is supported:
# def out(format, *args, new_line=True)
str = ""
str += ", "
if with_names:
str += " "
str += "arg_"
str += "[], int"
if with_names:
str += " len_"
return str
else:
return "int (*%s)(struct sbus_request *%s, void *%s%s)" % \
else:
else:
else:
invokers = { }
for meth in iface.methods:
continue
continue
return invokers
else:
else:
else:
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 prop.readable:
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
return
# All methods
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:
# -----------------------------------------------------------------------------
# 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)