diff options
author | Stef Walter <stefw@redhat.com> | 2014-01-10 08:54:41 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2014-02-24 11:14:49 +0100 |
commit | fcd8093c58638dc7c4f9cddfc97f273b94ce2ead (patch) | |
tree | 9f8374be57b0a48f19cd861ae4d38f666ae7af5e /src/tests/sbus_codegen_tests.c | |
parent | b699c4d7f85a5404be1d1ee9450331aea869b886 (diff) | |
download | sssd-fcd8093c58638dc7c4f9cddfc97f273b94ce2ead.tar.gz sssd-fcd8093c58638dc7c4f9cddfc97f273b94ce2ead.tar.xz sssd-fcd8093c58638dc7c4f9cddfc97f273b94ce2ead.zip |
sbus: Add sbus_vtable and update codegen to support it
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 <jhrozek@redhat.com>
Reviewed-by: Sumit Bose <sbose@redhat.com>
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
Reviewed-by: Simo Sorce <simo@redhat.com>
Diffstat (limited to 'src/tests/sbus_codegen_tests.c')
-rw-r--r-- | src/tests/sbus_codegen_tests.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/tests/sbus_codegen_tests.c b/src/tests/sbus_codegen_tests.c index 6b2abf8bc..39856fac7 100644 --- a/src/tests/sbus_codegen_tests.c +++ b/src/tests/sbus_codegen_tests.c @@ -112,6 +112,38 @@ START_TEST(test_signals) } END_TEST +static int +mock_move_universe(DBusMessage *msg, struct sbus_connection *conn) +{ + /* not called */ + return 0; +} + +static int +mock_crash_now(DBusMessage *msg, struct sbus_connection *conn) +{ + /* not called */ + return 0; +} + +START_TEST(test_vtable) +{ + struct com_planetexpress_Ship vtable = { + { &com_planetexpress_Ship_meta, 0 }, + mock_move_universe, + mock_crash_now, + }; + + /* + * These are not silly tests: + * - Will fail compilation if c-symbol name was not respected + * - Will fail if method order was not respected + */ + ck_assert(vtable.crash_now == mock_crash_now); + ck_assert(vtable.MoveUniverse == mock_move_universe); +} +END_TEST + Suite *create_suite(void) { Suite *s = suite_create("sbus_codegen"); @@ -123,6 +155,7 @@ Suite *create_suite(void) tcase_add_test(tc, test_methods); tcase_add_test(tc, test_properties); tcase_add_test(tc, test_signals); + tcase_add_test(tc, test_vtable); /* Add all test cases to the test suite */ suite_add_tcase(s, tc); |