From 473809190b98104c2b52ed2a0e930f92fad7fc48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Thu, 21 Jul 2022 00:30:10 +0200 Subject: [PATCH] doc: tutorial3: do not use nested functions Nested functions are a GNU C extension, they are not supported by clang, and by GCC in C++ mode. --- doc/tutorial3.c | 25 +++++++++++++++++-------- doc/tutorial3.dox | 19 ++++++++----------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/doc/tutorial3.c b/doc/tutorial3.c index 130357755..3e0cd9c42 100644 --- a/doc/tutorial3.c +++ b/doc/tutorial3.c @@ -7,23 +7,32 @@ #include /* [roundtrip] */ +struct roundtrip_data { + int pending; + struct pw_main_loop *loop; +}; + +static void on_core_done(void *data, uint32_t id, int seq) +{ + struct roundtrip_data *d = data; + + if (id == PW_ID_CORE && seq == d->pending) + pw_main_loop_quit(d->loop); +} + static int roundtrip(struct pw_core *core, struct pw_main_loop *loop) { + struct roundtrip_data d = { .loop = loop }; struct spa_hook core_listener; - int pending; - void core_event_done(void *object, uint32_t id, int seq) { - if (id == PW_ID_CORE && seq == pending) - pw_main_loop_quit(loop); - } const struct pw_core_events core_events = { PW_VERSION_CORE_EVENTS, - .done = core_event_done, + .done = on_core_done, }; pw_core_add_listener(core, &core_listener, - &core_events, NULL); + &core_events, &d); - pending = pw_core_sync(core, PW_ID_CORE, 0); + d.pending = pw_core_sync(core, PW_ID_CORE, 0); pw_main_loop_run(loop); diff --git a/doc/tutorial3.dox b/doc/tutorial3.dox index 90b447716..159c2d059 100644 --- a/doc/tutorial3.dox +++ b/doc/tutorial3.dox @@ -18,7 +18,7 @@ Let's take a look at what this method does. struct spa_hook core_listener; pw_core_add_listener(core, &core_listener, - &core_events, NULL); + &core_events, &d); \endcode First of all we add a listener for the events of the core @@ -26,16 +26,13 @@ object. We are only interested in the `done` event in this tutorial. This is the event handler: \code{.c} - int pending; +static void on_core_done(void *data, uint32_t id, int seq) +{ + struct roundtrip_data *d = data; - void core_event_done(void *data, uint32_t id, int seq) { - if (id == PW_ID_CORE && seq == pending) - pw_main_loop_quit(loop); - } - const struct pw_core_events core_events = { - PW_VERSION_CORE_EVENTS, - .done = core_event_done, - }; + if (id == PW_ID_CORE && seq == d->pending) + pw_main_loop_quit(d->loop); +} \endcode When the done event is received for an object with id `PW_ID_CORE` and @@ -44,7 +41,7 @@ a certain sequence number `seq`, this function will call `pw_main_loop_quit()`. Next we do: \code{.c} - pending = pw_core_sync(core, PW_ID_CORE, 0); + d.pending = pw_core_sync(core, PW_ID_CORE, 0); \endcode This triggers the `sync` method on the core object with id