pipewire/main_loop/
mod.rs

1// Copyright The pipewire-rs Contributors.
2// SPDX-License-Identifier: MIT
3
4use crate::loop_::Loop;
5
6mod box_;
7pub use box_::*;
8mod rc;
9pub use rc::*;
10
11#[repr(transparent)]
12pub struct MainLoop(pw_sys::pw_main_loop);
13
14impl MainLoop {
15    pub fn as_raw(&self) -> &pw_sys::pw_main_loop {
16        &self.0
17    }
18
19    pub fn as_raw_ptr(&self) -> *mut pw_sys::pw_main_loop {
20        std::ptr::addr_of!(self.0).cast_mut()
21    }
22
23    pub fn loop_(&self) -> &Loop {
24        unsafe {
25            let pw_loop = pw_sys::pw_main_loop_get_loop(self.as_raw_ptr());
26            // FIXME: Make sure pw_loop is not null
27            &*(pw_loop.cast::<Loop>())
28        }
29    }
30
31    pub fn run(&self) {
32        unsafe {
33            pw_sys::pw_main_loop_run(self.as_raw_ptr());
34        }
35    }
36
37    pub fn quit(&self) {
38        unsafe {
39            pw_sys::pw_main_loop_quit(self.as_raw_ptr());
40        }
41    }
42}
43
44impl std::convert::AsRef<Loop> for MainLoop {
45    fn as_ref(&self) -> &Loop {
46        self.loop_()
47    }
48}