mirror of
https://gitlab.freedesktop.org/pipewire/pipewire
synced 2024-10-15 12:22:47 +00:00
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.
This commit is contained in:
parent
04e65a86a1
commit
473809190b
|
@ -7,23 +7,32 @@
|
|||
#include <pipewire/pipewire.h>
|
||||
|
||||
/* [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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
if (id == PW_ID_CORE && seq == d->pending)
|
||||
pw_main_loop_quit(d->loop);
|
||||
}
|
||||
const struct pw_core_events core_events = {
|
||||
PW_VERSION_CORE_EVENTS,
|
||||
.done = core_event_done,
|
||||
};
|
||||
\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
|
||||
|
|
Loading…
Reference in a new issue