libpulse_sys/context/
subscribe.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//! Daemon introspection event subscription subsystem.
15
16use std::os::raw::c_void;
17use crate::operation::pa_operation;
18
19/// The base integer type passed to the callback, from which the facility and operation components
20/// can be extracted.
21pub type pa_subscription_event_type_t = u32;
22
23/// Used to express what facilities you are interested in when subscribing.
24pub type pa_subscription_mask_t = u32;
25
26/// Mask to extract facility value from the event type passed to the user callback.
27pub const PA_SUBSCRIPTION_EVENT_FACILITY_MASK: pa_subscription_event_type_t = 0xf;
28/// Mask to extract operation value from the event type passed to the user callback.
29pub const PA_SUBSCRIPTION_EVENT_TYPE_MASK:     pa_subscription_event_type_t = 0x30;
30
31pub use self::subscription_masks::*;
32
33/// A set of masks used for expressing which facilities you are interested in when subscribing.
34pub mod subscription_masks {
35    use super::pa_subscription_mask_t;
36
37    pub const PA_SUBSCRIPTION_MASK_NULL:          pa_subscription_mask_t = 0;
38    pub const PA_SUBSCRIPTION_MASK_SINK:          pa_subscription_mask_t = 1 << 0;
39    pub const PA_SUBSCRIPTION_MASK_SOURCE:        pa_subscription_mask_t = 1 << 1;
40    pub const PA_SUBSCRIPTION_MASK_SINK_INPUT:    pa_subscription_mask_t = 1 << 2;
41    pub const PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT: pa_subscription_mask_t = 1 << 3;
42    pub const PA_SUBSCRIPTION_MASK_MODULE:        pa_subscription_mask_t = 1 << 4;
43    pub const PA_SUBSCRIPTION_MASK_CLIENT:        pa_subscription_mask_t = 1 << 5;
44    pub const PA_SUBSCRIPTION_MASK_SAMPLE_CACHE:  pa_subscription_mask_t = 1 << 6;
45    pub const PA_SUBSCRIPTION_MASK_SERVER:        pa_subscription_mask_t = 1 << 7;
46    /* NOTE: value `0x100` previously assigned, obsoleted */
47    pub const PA_SUBSCRIPTION_MASK_CARD:          pa_subscription_mask_t = 1 << 9;
48    pub const PA_SUBSCRIPTION_MASK_ALL:           pa_subscription_mask_t = 0x2ff;
49}
50
51pub use self::event_facilities::*;
52
53/// Possible facility variants that could be extracted from an event type.
54pub mod event_facilities {
55    use super::pa_subscription_event_type_t;
56
57    pub const PA_SUBSCRIPTION_EVENT_SINK:          pa_subscription_event_type_t = 0;
58    pub const PA_SUBSCRIPTION_EVENT_SOURCE:        pa_subscription_event_type_t = 1;
59    pub const PA_SUBSCRIPTION_EVENT_SINK_INPUT:    pa_subscription_event_type_t = 2;
60    pub const PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT: pa_subscription_event_type_t = 3;
61    pub const PA_SUBSCRIPTION_EVENT_MODULE:        pa_subscription_event_type_t = 4;
62    pub const PA_SUBSCRIPTION_EVENT_CLIENT:        pa_subscription_event_type_t = 5;
63    pub const PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE:  pa_subscription_event_type_t = 6;
64    /// Global server change, only occurring with a change operation.
65    pub const PA_SUBSCRIPTION_EVENT_SERVER:        pa_subscription_event_type_t = 7;
66    /* NOTE: value `8` previously assigned, obsoleted */
67    pub const PA_SUBSCRIPTION_EVENT_CARD:          pa_subscription_event_type_t = 9;
68}
69
70pub use self::event_operations::*;
71
72/// Possible operation variants that could be extracted from an event type.
73pub mod event_operations {
74    use super::pa_subscription_event_type_t;
75
76    pub const PA_SUBSCRIPTION_EVENT_NEW:    pa_subscription_event_type_t = 0;
77    pub const PA_SUBSCRIPTION_EVENT_CHANGE: pa_subscription_event_type_t = 0x10;
78    pub const PA_SUBSCRIPTION_EVENT_REMOVE: pa_subscription_event_type_t = 0x20;
79}
80
81/// Checks if event type `t` matches an event mask bitfield (returns `true` if so).
82pub const fn pa_subscription_match_flags(m: pa_subscription_mask_t, t: pa_subscription_event_type_t)
83    -> bool
84{
85    (m & (1 << (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK))) != 0
86}
87
88#[rustfmt::skip]
89pub type pa_context_subscribe_cb_t = Option<extern "C" fn(c: *mut super::pa_context, t: pa_subscription_event_type_t, idx: u32, userdata: *mut c_void)>;
90
91#[rustfmt::skip]
92#[link(name = "pulse")]
93extern "C" {
94    pub fn pa_context_subscribe(c: *mut super::pa_context, m: pa_subscription_mask_t, cb: super::pa_context_success_cb_t, userdata: *mut c_void) -> *mut pa_operation;
95    pub fn pa_context_set_subscribe_callback(c: *mut super::pa_context, cb: pa_context_subscribe_cb_t, userdata: *mut c_void);
96}