mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
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.
This commit is contained in:
parent
f61bb3aef5
commit
04e65a86a1
2 changed files with 9 additions and 17 deletions
|
|
@ -10,13 +10,11 @@
|
||||||
static int roundtrip(struct pw_core *core, struct pw_main_loop *loop)
|
static int roundtrip(struct pw_core *core, struct pw_main_loop *loop)
|
||||||
{
|
{
|
||||||
struct spa_hook core_listener;
|
struct spa_hook core_listener;
|
||||||
int pending, done = 0;
|
int pending;
|
||||||
void core_event_done(void *object, uint32_t id, int seq) {
|
void core_event_done(void *object, uint32_t id, int seq) {
|
||||||
if (id == PW_ID_CORE && seq == pending) {
|
if (id == PW_ID_CORE && seq == pending)
|
||||||
done = 1;
|
|
||||||
pw_main_loop_quit(loop);
|
pw_main_loop_quit(loop);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
const struct pw_core_events core_events = {
|
const struct pw_core_events core_events = {
|
||||||
PW_VERSION_CORE_EVENTS,
|
PW_VERSION_CORE_EVENTS,
|
||||||
.done = core_event_done,
|
.done = core_event_done,
|
||||||
|
|
@ -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);
|
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);
|
spa_hook_remove(&core_listener);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,23 +26,20 @@ object. We are only interested in the `done` event in this
|
||||||
tutorial. This is the event handler:
|
tutorial. This is the event handler:
|
||||||
|
|
||||||
\code{.c}
|
\code{.c}
|
||||||
int pending, done = 0;
|
int pending;
|
||||||
|
|
||||||
void core_event_done(void *data, uint32_t id, int seq) {
|
void core_event_done(void *data, uint32_t id, int seq) {
|
||||||
if (id == PW_ID_CORE && seq == pending) {
|
if (id == PW_ID_CORE && seq == pending)
|
||||||
done = 1;
|
|
||||||
pw_main_loop_quit(loop);
|
pw_main_loop_quit(loop);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
const struct pw_core_events core_events = {
|
const struct pw_core_events core_events = {
|
||||||
PW_VERSION_CORE_EVENTS,
|
PW_VERSION_CORE_EVENTS,
|
||||||
.done = core_event_done,
|
.done = core_event_done,
|
||||||
};
|
};
|
||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
When the done event is received for an object with id `PW_ID_CORE`
|
When the done event is received for an object with id `PW_ID_CORE` and
|
||||||
and a certain sequence number `seq`, this function will set the done
|
a certain sequence number `seq`, this function will call `pw_main_loop_quit()`.
|
||||||
variable to 1 and call `pw_main_loop_quit()`.
|
|
||||||
|
|
||||||
Next we do:
|
Next we do:
|
||||||
|
|
||||||
|
|
@ -68,9 +65,7 @@ We then run the mainloop to send the messages to the server and
|
||||||
receive the events:
|
receive the events:
|
||||||
|
|
||||||
\code{.c}
|
\code{.c}
|
||||||
while (!done) {
|
|
||||||
pw_main_loop_run(loop);
|
pw_main_loop_run(loop);
|
||||||
}
|
|
||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
When we get the done event, we can compare it to the sync method
|
When we get the done event, we can compare it to the sync method
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue