From 04e65a86a13b339da1780bb9d4a7640d1c5423cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Thu, 21 Jul 2022 00:24:46 +0200 Subject: [PATCH] doc: tutorial3: remove `done` variable Use `pw_main_loop_quit()` alone, which should be enough to cause `pw_main_loop_run()` to return. `pw_main_loop_run()` only returns prematurely when there is an error, but since there is no error handling in this example, that scenario is ignored. --- doc/tutorial3.c | 11 ++++------- doc/tutorial3.dox | 15 +++++---------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/doc/tutorial3.c b/doc/tutorial3.c index 2c6cab2fa..130357755 100644 --- a/doc/tutorial3.c +++ b/doc/tutorial3.c @@ -10,12 +10,10 @@ static int roundtrip(struct pw_core *core, struct pw_main_loop *loop) { struct spa_hook core_listener; - int pending, done = 0; + int pending; void core_event_done(void *object, uint32_t id, int seq) { - if (id == PW_ID_CORE && seq == pending) { - done = 1; + if (id == PW_ID_CORE && seq == pending) pw_main_loop_quit(loop); - } } const struct pw_core_events core_events = { PW_VERSION_CORE_EVENTS, @@ -27,9 +25,8 @@ static int roundtrip(struct pw_core *core, struct pw_main_loop *loop) pending = pw_core_sync(core, PW_ID_CORE, 0); - while (!done) { - pw_main_loop_run(loop); - } + pw_main_loop_run(loop); + spa_hook_remove(&core_listener); return 0; } diff --git a/doc/tutorial3.dox b/doc/tutorial3.dox index 8882f68da..90b447716 100644 --- a/doc/tutorial3.dox +++ b/doc/tutorial3.dox @@ -26,13 +26,11 @@ object. We are only interested in the `done` event in this tutorial. This is the event handler: \code{.c} - int pending, done = 0; + int pending; void core_event_done(void *data, uint32_t id, int seq) { - if (id == PW_ID_CORE && seq == pending) { - done = 1; + if (id == PW_ID_CORE && seq == pending) pw_main_loop_quit(loop); - } } const struct pw_core_events core_events = { PW_VERSION_CORE_EVENTS, @@ -40,9 +38,8 @@ tutorial. This is the event handler: }; \endcode -When the done event is received for an object with id `PW_ID_CORE` -and a certain sequence number `seq`, this function will set the done -variable to 1 and call `pw_main_loop_quit()`. +When the done event is received for an object with id `PW_ID_CORE` and +a certain sequence number `seq`, this function will call `pw_main_loop_quit()`. Next we do: @@ -68,9 +65,7 @@ We then run the mainloop to send the messages to the server and receive the events: \code{.c} - while (!done) { - pw_main_loop_run(loop); - } + pw_main_loop_run(loop); \endcode When we get the done event, we can compare it to the sync method