Debian Codegraph @

tests/common/test-server.h

raw
1 /* WirePlumber
2 *
3 * Copyright © 2019 Collabora Ltd.
4 * @author George Kiagiadakis <[email protected]>
5 *
6 * SPDX-License-Identifier: MIT
7 */
8
9 #include <pipewire/pipewire.h>
10 #include <pipewire/impl.h>
11 #include <glib.h>
12 #include <unistd.h>
13
14 typedef struct {
15 gchar *name;
16 struct pw_thread_loop *thread_loop;
17 struct pw_context *context;
18 } WpTestServer;
19
20 static inline void
21 wp_test_server_setup (WpTestServer *self)
22 {
23 struct pw_properties *properties;
24
25 self->name = g_strdup_printf ("wp-test-server-%d-%d", getpid(),
26 g_random_int ());
27 properties = pw_properties_new(
28 PW_KEY_CORE_DAEMON, "1",
29 PW_KEY_CORE_NAME, self->name,
30 NULL);
31
32 self->thread_loop = pw_thread_loop_new ("wp-test-server", NULL);
33 self->context = pw_context_new (pw_thread_loop_get_loop (self->thread_loop),
34 properties, 0);
35
36 pw_context_load_module (self->context, "libpipewire-module-access", NULL, NULL);
37
38 pw_thread_loop_start (self->thread_loop);
39 }
40
41 static inline void
42 wp_test_server_teardown (WpTestServer *self)
43 {
44 if (self->thread_loop)
45 pw_thread_loop_stop (self->thread_loop);
46 g_clear_pointer (&self->context, pw_context_destroy);
47 g_clear_pointer (&self->thread_loop, pw_thread_loop_destroy);
48 g_clear_pointer (&self->name, g_free);
49 }
50
51 typedef void WpTestServerLocker;
52
53 static inline WpTestServerLocker *
54 wp_test_server_locker_new (WpTestServer * self)
55 {
56 pw_thread_loop_lock (self->thread_loop);
57 return self;
58 }
59
60 static inline void
61 wp_test_server_locker_free (WpTestServerLocker * self)
62 {
63 pw_thread_loop_unlock (((WpTestServer *)self)->thread_loop);
64 }
65
66 G_DEFINE_AUTOPTR_CLEANUP_FUNC (WpTestServerLocker, wp_test_server_locker_free)