From dff909d473f43a6bd0f0286fa2d279c0ebe945c6 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Tue, 25 Feb 2014 10:29:23 +0100 Subject: sbus: Add type-safe DBus method handlers and finish functions Type safe method handlers allow methods not to have to do tedious unwrapping and wrapping of DBus method call messages or replies. Arguments of the following DBus types are supported in type-safe method handlers. In addition arrays of these are supported. y: uint8_t b: bool (but no arrays, yet) n: int16_t q: uint16_t i: int32_t u: uint32_t x: int64_t t: uint64_t d: double s: char * (utf8 string) o: char * (object path) As an exception, arrays of booleans are not supported, but could be added later. Other more complex types could be added later if desired. If a method has other argument types, then it must be marked as having a raw handler (see below). Internally each method can have a type specific invoker function which unpacks the incoming arguments and invokes the method handler with the correct arguments. Each method also has a finish which accepts the type-safe out arguments (ie: return values) and builds the reply message. Like other request 'finish' functions, these free the request talloc context, and are to be used in place of sbus_request_finish() or friends. Raw method handlers parse their own method arguments, and prepare their own reply (ideally using sbus_request_finish() helpers). They can also do strange things like have variable arguments. To mark a DBus method as having a raw method handler use the following annotation: Raw methods do not have invokers or finish functions. I've left all of the internal peer to peer communication using raw method handlers. No code changes here. --- src/tests/sbus_codegen_tests.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'src/tests/sbus_codegen_tests.c') diff --git a/src/tests/sbus_codegen_tests.c b/src/tests/sbus_codegen_tests.c index 8055cf206..798d394df 100644 --- a/src/tests/sbus_codegen_tests.c +++ b/src/tests/sbus_codegen_tests.c @@ -53,7 +53,7 @@ START_TEST(test_interfaces) /* Explicit C Symbol */ ck_assert_str_eq(test_pilot_meta.name, "com.planetexpress.Pilot"); - ck_assert(test_pilot_meta.methods == NULL); /* no methods */ + ck_assert(test_pilot_meta.methods != NULL); ck_assert(test_pilot_meta.signals == NULL); /* no signals */ ck_assert(test_pilot_meta.properties != NULL); @@ -113,16 +113,42 @@ START_TEST(test_signals) END_TEST static int -mock_move_universe(struct sbus_request *dbus_req, void *data) +mock_move_universe(struct sbus_request *dbus_req, void *data, + bool arg_smoothly, uint32_t arg_speed_factor) { - /* not called */ - return 0; + /* + * The above arguments should match the handler signature, + * and the below finish function should have the right signature. + * + * Not called, just testing compilation + */ + ck_assert(FALSE); + return com_planetexpress_Ship_MoveUniverse_finish(dbus_req, "here"); } static int -mock_crash_now(struct sbus_request *dbus_req, void *data) +mock_crash_now(struct sbus_request *dbus_req, void *data, + const char *where) { - /* not called */ + /* + * One argument, no return value, yet a finish function should + * have been generated. + * + * Not called, just testing compilation + */ + ck_assert(FALSE); + return com_planetexpress_Ship_crash_now_finish(dbus_req); +} + +static int +mock_land(struct sbus_request *req, void *data) +{ + /* + * Raw handler, no finish function, no special arguments. + * + * Not called, just testing compilation + */ + ck_assert(FALSE); return 0; } @@ -132,6 +158,7 @@ START_TEST(test_vtable) { &com_planetexpress_Ship_meta, 0 }, mock_move_universe, mock_crash_now, + mock_land, }; /* @@ -141,6 +168,7 @@ START_TEST(test_vtable) */ ck_assert(vtable.crash_now == mock_crash_now); ck_assert(vtable.MoveUniverse == mock_move_universe); + ck_assert(vtable.Land == mock_land); } END_TEST -- cgit