libpulse_sys/mainloop/
api.rs

1// Copyright 2017 Lyndon Brown
2//
3// This file is part of the PulseAudio Rust language linking library.
4//
5// Licensed under the MIT license or the Apache license (version 2.0), at your option. You may not
6// copy, modify, or distribute this file except in compliance with said license. You can find copies
7// of these licenses either in the LICENSE-MIT and LICENSE-APACHE files, or alternatively at
8// <http://opensource.org/licenses/MIT> and <http://www.apache.org/licenses/LICENSE-2.0>
9// respectively.
10//
11// Portions of documentation are copied from the LGPL 2.1+ licensed PulseAudio C headers on a
12// fair-use basis, as discussed in the overall project readme (available in the git repository).
13
14//! Main loop abstraction layer API.
15
16use std::os::raw::c_void;
17use crate::timeval::timeval;
18
19pub type pa_io_event_flags_t = u32;
20
21pub use self::io_event_flags::*;
22
23pub mod io_event_flags {
24    use super::pa_io_event_flags_t;
25
26    pub const PA_IO_EVENT_NULL:   pa_io_event_flags_t = 0;
27    pub const PA_IO_EVENT_INPUT:  pa_io_event_flags_t = 1;
28    pub const PA_IO_EVENT_OUTPUT: pa_io_event_flags_t = 2;
29    pub const PA_IO_EVENT_HANGUP: pa_io_event_flags_t = 4;
30    pub const PA_IO_EVENT_ERROR:  pa_io_event_flags_t = 8;
31}
32
33/// An opaque IO event source object.
34#[repr(C)] pub struct pa_io_event { _private: [u8; 0] }
35#[rustfmt::skip]
36pub type pa_io_event_cb_t = Option<extern "C" fn(a: *const pa_mainloop_api, e: *mut pa_io_event, fd: i32, events: pa_io_event_flags_t, userdata: *mut c_void)>;
37#[rustfmt::skip]
38pub type pa_io_event_destroy_cb_t = Option<extern "C" fn(a: *const pa_mainloop_api, e: *mut pa_io_event, userdata: *mut c_void)>;
39
40/// An opaque timer event source object.
41#[repr(C)] pub struct pa_time_event { _private: [u8; 0] }
42#[rustfmt::skip]
43pub type pa_time_event_cb_t = Option<extern "C" fn(a: *const pa_mainloop_api, e: *mut pa_time_event, tv: *const timeval, userdata: *mut c_void)>;
44#[rustfmt::skip]
45pub type pa_time_event_destroy_cb_t = Option<extern "C" fn(a: *const pa_mainloop_api, e: *mut pa_time_event, userdata: *mut c_void)>;
46
47/// An opaque deferred event source object.
48///
49/// Events of this type are triggered once in every main loop iteration.
50#[repr(C)] pub struct pa_defer_event { _private: [u8; 0] }
51#[rustfmt::skip]
52pub type pa_defer_event_cb_t = Option<extern "C" fn(a: *const pa_mainloop_api, e: *mut pa_defer_event, userdata: *mut c_void)>;
53#[rustfmt::skip]
54pub type pa_defer_event_destroy_cb_t = Option<extern "C" fn(a: *const pa_mainloop_api, e: *mut pa_defer_event, userdata: *mut c_void)>;
55
56#[rustfmt::skip]
57#[repr(C)]
58pub struct pa_mainloop_api {
59    pub userdata: *mut c_void,
60
61    pub io_new: Option<extern "C" fn(a: *const pa_mainloop_api, fd: i32, events: pa_io_event_flags_t, cb: pa_io_event_cb_t, userdata: *mut c_void) -> *mut pa_io_event>,
62    pub io_enable: Option<extern "C" fn(e: *mut pa_io_event, events: pa_io_event_flags_t)>,
63    pub io_free: Option<extern "C" fn(e: *mut pa_io_event)>,
64    pub io_set_destroy: Option<extern "C" fn(e: *mut pa_io_event, cb: pa_io_event_destroy_cb_t)>,
65
66    pub time_new: Option<extern "C" fn(a: *const pa_mainloop_api, tv: *const timeval, cb: pa_time_event_cb_t, userdata: *mut c_void) -> *mut pa_time_event>,
67    pub time_restart: Option<extern "C" fn(e: *mut pa_time_event, tv: *const timeval)>,
68    pub time_free: Option<extern "C" fn(e: *mut pa_time_event)>,
69    pub time_set_destroy: Option<extern "C" fn(e: *mut pa_time_event, cb: pa_time_event_destroy_cb_t)>,
70
71    pub defer_new: Option<extern "C" fn(a: *const pa_mainloop_api, cb: pa_defer_event_cb_t, userdata: *mut c_void) -> *mut pa_defer_event>,
72    pub defer_enable: Option<extern "C" fn(e: *mut pa_defer_event, b: i32)>,
73    pub defer_free: Option<extern "C" fn(e: *mut pa_defer_event)>,
74    pub defer_set_destroy: Option<extern "C" fn(e: *mut pa_defer_event, cb: pa_defer_event_destroy_cb_t)>,
75
76    pub quit: Option<extern "C" fn(a: *const pa_mainloop_api, retval: i32)>,
77}
78
79#[rustfmt::skip]
80pub type pa_mainloop_api_once_cb = Option<extern "C" fn(m: *const pa_mainloop_api, userdata: *mut c_void)>;
81
82#[rustfmt::skip]
83#[link(name = "pulse")]
84extern "C" {
85    pub fn pa_mainloop_api_once(m: *const pa_mainloop_api, callback: pa_mainloop_api_once_cb, userdata: *mut c_void);
86}