sbus_codegen revision 66277b21179d95f6e96abed01a20ccbccf27ce99
4364N/A# Stef Walter <stefw@redhat.com> 4820N/A# Copyright (C) 2014 Red Hat 1426N/A# This program is free software; you can redistribute it and/or modify 1426N/A# it under the terms of the GNU General Public License as published by 797N/A# the Free Software Foundation; either version 3 of the License, or 797N/A# (at your option) any later version. 797N/A# This program is distributed in the hope that it will be useful, 797N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of 797N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 797N/A# GNU General Public License for more details. 797N/A# You should have received a copy of the GNU General Public License 1426N/A# Some parser code from GLib 1426N/A# Copyright (C) 2008-2011 Red Hat, Inc. 797N/A# This library is free software; you can redistribute it and/or 797N/A# modify it under the terms of the GNU Lesser General Public 797N/A# License as published by the Free Software Foundation; either 797N/A# version 2 of the License, or (at your option) any later version. 797N/A# This library is distributed in the hope that it will be useful, 797N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of 797N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1426N/A# Lesser General Public License for more details. 4364N/A# You should have received a copy of the GNU Lesser General 4364N/A# Public License along with this library; if not, write to the 2505N/A# Free Software Foundation, Inc., 59 Temple Place, Suite 330, 2505N/A# Boston, MA 02111-1307, USA. 4364N/A# Portions by: David Zeuthen <davidz@redhat.com> 4364N/A# DBus interfaces are defined here: 4002N/A# The introspection data format has become the standard way to represent a 4364N/A# A word about annotations. These are extra flags or values that can be 4364N/A# assigned to anything. So far, the codegen supports this annotation: 4364N/A# - An annotation specified in the specification that tells us what C symbol 4364N/A# to generate for a given interface or method. By default the codegen will 4820N/A# build up a symbol name from the DBus name. 4820N/A# ----------------------------------------------------------------------------- 4364N/A # Lets us print problems like a compiler would 4820N/A# The basic types that we support marshalling right now. These 4364N/A# are the ones we can pass as basic arguments to libdbus directly. 2505N/A# If the dbus and sssd types are identical we pass things directly. 4364N/A# otherwise some copying is necessary. 4364N/A 'y': ( "DBUS_TYPE_BYTE", "uint8_t", "uint8_t" ), 4364N/A 'b': ( "DBUS_TYPE_BOOLEAN", "dbus_bool_t", "bool" ), 4364N/A 'n': ( "DBUS_TYPE_INT16", "int16_t", "int16_t" ), 4364N/A 'q': ( "DBUS_TYPE_UINT16", "uint16_t", "uint16_t" ), 4364N/A 'i': ( "DBUS_TYPE_INT32", "int32_t", "int32_t" ), 4364N/A 'u': ( "DBUS_TYPE_UINT32", "uint32_t", "uint32_t" ), 4364N/A 'x': ( "DBUS_TYPE_INT64", "int64_t", "int64_t" ), 4364N/A 't': ( "DBUS_TYPE_UINT64", "uint64_t", "uint64_t" ), 4820N/A 'd': ( "DBUS_TYPE_DOUBLE", "double", "double" ), 4364N/A 's': ( "DBUS_TYPE_STRING", "const char *", "const char *" ), 4364N/A 'o': ( "DBUS_TYPE_OBJECT_PATH", "const char *", "const char *" ), 4002N/A # If types are not identical, we can't do array (yet) 797N/A# ----------------------------------------------------------------------------- 4002N/A # NOTE: Would like to use the following syntax for this function 4002N/A # but need to wait until python3 until it is supported: 4002N/A # def out(format, *args, new_line=True) 4002N/A return "int (*%s)(struct sbus_request *%s, void *%s%s)" % \ 4002N/A out("static int invoke_%s_method(struct sbus_request *dbus_req, void *function_ptr);", signature) 4002N/A out("static int invoke_%s_method(struct sbus_request *dbus_req, void *function_ptr)", signature) 797N/A out(" if (!sbus_request_parse_or_finish(dbus_req,") 4364N/A out(" DBUS_TYPE_ARRAY, %s, &arg_%d, &len_%d,", 797N/A out("static int %s(struct sbus_request *dbus_req, void *function_ptr)", 4002N/A out(" out_val = prop_val == NULL ? \"\" : prop_val;") 4002N/A out(" out_val = prop_val == NULL ? \"/\" : prop_val;") 4002N/A out("static int invoke_%s_get_all(struct sbus_request *dbus_req, void *function_ptr)", 4820N/A out(" struct sbus_interface *intf = dbus_req->intf;") 4002N/A out(" const struct sbus_property_meta *property;") 4364N/A out(" reply = dbus_message_new_method_return(dbus_req->message);") 4002N/A out(" dbus_message_iter_init_append(reply, &iter);") 4002N/A out(" dbret = dbus_message_iter_open_container(") 4364N/A out(" DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING") 797N/A out(" DBUS_DICT_ENTRY_END_CHAR_AS_STRING,") 4002N/A out(" if (property != NULL && property->flags & SBUS_PROPERTY_READABLE) {") 4002N/A out(" %s_handler = VTABLE_FUNC(intf->vtable, property->vtable_offset_get);", prop.type) 4820N/A out(" %s_out_val = %s_prop_val == NULL ? \"\" : %s_prop_val;", 4820N/A out(" %s_out_val = %s_prop_val == NULL ? \"/\" : %s_prop_val;", 797N/A out(" ret = sbus_add_array_as_variant_to_dict(&iter_dict, \"%s\", %s, (uint8_t*)%s_out_val, %s_prop_len, sizeof(%s));", prop.c_name(), prop.dbus_constant, prop.type, prop.type, prop.sssd_type) 797N/A out(" dbret = dbus_message_iter_close_container(&iter, &iter_dict);") 4820N/A out(" return sbus_request_finish(dbus_req, reply);") 4820N/A out("static int %s(struct sbus_request *dbus_req, void *function_ptr);", 797N/A out("int %s_finish(struct sbus_request *req%s)", 1426N/A out(" return sbus_request_return_and_finish(req,") 2377N/A out("DBUS_TYPE_ARRAY, %s, &arg_%s, len_%s,", 4820N/A out(" SBUS_PROPERTY_READABLE | SBUS_PROPERTY_WRITABLE,") 4820N/A # always generate getall, for interfaces without properties 4820N/A # let's return an empty array 4820N/A # The sbus_interface structure 4820N/A out("int %s_finish(struct sbus_request *req%s);", 4820N/A out(" struct sbus_vtable vtable; /* derive from sbus_vtable */") 4820N/A out("/* ------------------------------------------------------------------------") 4820N/A out(" * Various constants of interface and method names mostly for use by clients") 4820N/A out("/* ------------------------------------------------------------------------") 4820N/A out(" * These structures are filled in by implementors of the different") 4820N/A out(" * dbus interfaces to handle method calls.") 4820N/A out(" * Handler functions of type sbus_msg_handler_fn accept raw messages,") 4820N/A out(" * other handlers are typed appropriately. If a handler that is") 4820N/A out(" * set to NULL is invoked it will result in a") 4820N/A out(" * Handlers have a matching xxx_finish() function (unless the method has") 4820N/A out(" * accepts raw messages). These finish functions the") 4820N/A out(" * sbus_request_return_and_finish() with the appropriate arguments to") 4820N/A out(" * construct a valid reply. Once a finish function has been called, the") 4820N/A out(" * @dbus_req it was called with is freed and no longer valid.") 4820N/A out("/* ------------------------------------------------------------------------") 4820N/A out(" * These structure definitions are filled in with the information about") 4820N/A out(" * the interfaces, methods, properties and so on.") 4820N/A out(" * The actual definitions are found in the accompanying C file next") 4820N/A# ----------------------------------------------------------------------------- 4820N/A from standard XML Introspect data.") 4820N/A # Write output at end to be nice to 'make'