sbus_codegen revision dff909d473f43a6bd0f0286fa2d279c0ebe945c6
943N/A# Stef Walter <stefw@redhat.com> 571N/A# Copyright (C) 2014 Red Hat 919N/A# This program is free software; you can redistribute it and/or modify 919N/A# it under the terms of the GNU General Public License as published by 919N/A# the Free Software Foundation; either version 3 of the License, or 919N/A# (at your option) any later version. 919N/A# This program is distributed in the hope that it will be useful, 919N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of 919N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 919N/A# GNU General Public License for more details. 919N/A# You should have received a copy of the GNU General Public License 919N/A# Some parser code from GLib 571N/A# Copyright (C) 2008-2011 Red Hat, Inc. 571N/A# This library is free software; you can redistribute it and/or 571N/A# modify it under the terms of the GNU Lesser General Public 970N/A# License as published by the Free Software Foundation; either 970N/A# version 2 of the License, or (at your option) any later version. 970N/A# This library is distributed in the hope that it will be useful, 970N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of 571N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 571N/A# Lesser General Public License for more details. 911N/A# You should have received a copy of the GNU Lesser General 911N/A# Public License along with this library; if not, write to the 911N/A# Free Software Foundation, Inc., 59 Temple Place, Suite 330, 911N/A# Boston, MA 02111-1307, USA. 571N/A# Portions by: David Zeuthen <davidz@redhat.com> 571N/A# DBus interfaces are defined here: 571N/A# The introspection data format has become the standard way to represent a 571N/A# typical linux machine. 571N/A# A word about annotations. These are extra flags or values that can be 970N/A# assigned to anything. So far, the codegen supports this annotation: 970N/A# - An annotation specified in the specification that tells us what C symbol 970N/A# to generate for a given interface or method. By default the codegen will 970N/A# build up a symbol name from the DBus name. 571N/A# ----------------------------------------------------------------------------- # Lets us print problems like a compiler would # 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. '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 *" ), # If types are not identical, we can't do array (yet) # ----------------------------------------------------------------------------- # 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) return "sbus_msg_handler_fn " + name return "int (*%s)(struct sbus_request *%s, void *%s%s)" % \ out("/* invokes a handler with a '%s' DBus signature */", signature) out("static int invoke_%s_method(struct sbus_request *dbus_req, void *function_ptr);", signature) out("/* invokes a handler with a '%s' DBus signature */", signature) out("static int invoke_%s_method(struct sbus_request *dbus_req, void *function_ptr)", signature) out(" if (!sbus_request_parse_or_finish(dbus_req,") out(" DBUS_TYPE_ARRAY, %s, &arg_%d, &len_%d,", out(" DBUS_TYPE_INVALID)) {") out(" return EOK; /* request handled */") out(" return (handler)(dbus_req, dbus_req->intf->instance_data", new_line=False) out("int %s_finish(struct sbus_request *req%s)", out(" return sbus_request_return_and_finish(req,") out("DBUS_TYPE_ARRAY, %s, &arg_%s, len_%s,", out(" DBUS_TYPE_INVALID);") out(" NULL, /* no in_args */") out(" NULL, /* no out_args */") out(" NULL, /* no invoker */") out(" NULL, /* no args */") out("const struct sbus_property_meta %s__properties[] = {", iface.c_name()) out(" SBUS_PROPERTY_READABLE | SBUS_PROPERTY_WRITABLE,") out(" SBUS_PROPERTY_READABLE,") out(" SBUS_PROPERTY_WRITABLE,") out(" NULL, /* no methods */") out(" NULL, /* no signals */") out(" NULL, /* no propetries */") out("/* The following definitions are auto-generated from %s */", basename) # The sbus_interface structure out("int %s_finish(struct sbus_request *req%s);", out(" struct sbus_vtable vtable; /* derive from sbus_vtable */") # TODO: Property getters and setters will go here out("/* The following declarations are auto-generated from %s */", basename) out("/* ------------------------------------------------------------------------") out(" * Various constants of interface and method names mostly for use by clients") out("/* ------------------------------------------------------------------------") out(" * These structures are filled in by implementors of the different") out(" * dbus interfaces to handle method calls.") out(" * Handler functions of type sbus_msg_handler_fn accept raw messages,") out(" * other handlers are typed appropriately. If a handler that is") out(" * set to NULL is invoked it will result in a") out(" * Handlers have a matching xxx_finish() function (unless the method has") out(" * accepts raw messages). These finish functions the") out(" * sbus_request_return_and_finish() with the appropriate arguments to") out(" * construct a valid reply. Once a finish function has been called, the") out(" * @dbus_req it was called with is freed and no longer valid.") out("/* ------------------------------------------------------------------------") out(" * DBus Interface Metadata") out(" * These structure definitions are filled in with the information about") out(" * the interfaces, methods, properties and so on.") out(" * The actual definitions are found in the accompanying C file next") out(" * to this header.") # ----------------------------------------------------------------------------- from standard XML Introspect data.") help="'header' or 'source' (default: header)", help="Set output file name (default: stdout)", help="name of a header to #include", print >> sys.stderr, "sbus_codegen: no input file specified" print >> sys.stderr, "sbus_codegen: specify --mode=header or --mode=source" # Write output at end to be nice to 'make'