From fcd8093c58638dc7c4f9cddfc97f273b94ce2ead Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Fri, 10 Jan 2014 08:54:41 +0100 Subject: sbus: Add sbus_vtable and update codegen to support it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each interface is a vtable structure derived from sbus_vtable, in the sense that it has an sbus_vtable struct as its first argument. This lets us upcast the interface vtable structure to an sbus_vtable and dispatch to it dynamically and cleanly. The interface metadata contains information about which vtable offset in the interface metadata should be dispatched to for a given function. This is a common scheme, not only among dbus implementations, but also compiled languages. Currently all the vtable functions are of type sbus_msg_handler_fn. These are the handlers we are familiar with and perform raw processing of the message. Later commits will introduce type safe handlers that levelage compile checking and automatic argument packing/unpacking. Although this may seem contrived now, the remainder of the dbus infrastructure work will build on this, including ofd.Properties, ofd.ObjectManager, ofd.Introspect, compiler checked type safe unpacking/packing, etc. The codegen now generates vtable structures for each interface along-side the metadata, and fills in vtable offsets appropriately. It is obviously still possible to hand-craft such vtables and metadata if needed for a special case. Once again examples output can be found at: src/tests/sbus_codegen_tests_generated.h Reviewed-by: Jakub Hrozek Reviewed-by: Sumit Bose Reviewed-by: Lukáš Slebodník Reviewed-by: Simo Sorce --- src/tests/sbus_codegen_tests_generated.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/tests/sbus_codegen_tests_generated.h') diff --git a/src/tests/sbus_codegen_tests_generated.h b/src/tests/sbus_codegen_tests_generated.h index c3a23c870..3f7621588 100644 --- a/src/tests/sbus_codegen_tests_generated.h +++ b/src/tests/sbus_codegen_tests_generated.h @@ -5,6 +5,25 @@ #include "sbus/sssd_dbus.h" +/* ------------------------------------------------------------------------ + * DBus Vtable handler structures + * + * These structures are filled in by implementors of the different + * dbus interfaces to handle method calls. + * + * Handler functions of type sbus_msg_handler_fn accept raw messages, + * other handlers will be typed appropriately. If a handler that is + * set to NULL is invoked it will result in a + * org.freedesktop.DBus.Error.NotSupported error for the caller. + */ + +/* vtable for com.planetexpress.Ship */ +struct com_planetexpress_Ship { + struct sbus_vtable vtable; /* derive from sbus_vtable */ + sbus_msg_handler_fn MoveUniverse; + sbus_msg_handler_fn crash_now; +}; + /* ------------------------------------------------------------------------ * DBus Interface Metadata * -- cgit