libpulse_sys/
operation.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//! Asynchronous operations.
15
16use std::os::raw::c_void;
17use num_derive::{FromPrimitive, ToPrimitive};
18
19/// An asynchronous operation object.
20#[repr(C)] pub struct pa_operation { _private: [u8; 0] }
21
22/// Operation state.
23#[repr(C)]
24#[derive(Debug, Copy, Clone, PartialEq, Eq)]
25#[derive(FromPrimitive, ToPrimitive)]
26pub enum pa_operation_state_t {
27    /// The operation is still running.
28    Running,
29    /// The operation has completed.
30    Done,
31    /// The operation has been cancelled. Operations may get cancelled by the application, or as a
32    /// result of the context getting disconnected while the operation is pending.
33    Cancelled,
34}
35
36pub const PA_OPERATION_RUNNING:   pa_operation_state_t = pa_operation_state_t::Running;
37pub const PA_OPERATION_DONE:      pa_operation_state_t = pa_operation_state_t::Done;
38pub const PA_OPERATION_CANCELED:  pa_operation_state_t = pa_operation_state_t::Cancelled;
39pub const PA_OPERATION_CANCELLED: pa_operation_state_t = pa_operation_state_t::Cancelled;
40
41/// A callback for operation state changes.
42#[rustfmt::skip]
43pub type pa_operation_notify_cb_t = Option<extern "C" fn(o: *mut pa_operation, userdata: *mut c_void)>;
44
45#[rustfmt::skip]
46#[link(name = "pulse")]
47extern "C" {
48    pub fn pa_operation_ref(o: *mut pa_operation) -> *mut pa_operation;
49    pub fn pa_operation_unref(o: *mut pa_operation);
50    pub fn pa_operation_cancel(o: *mut pa_operation);
51    pub fn pa_operation_get_state(o: *const pa_operation) -> pa_operation_state_t;
52    pub fn pa_operation_set_state_callback(o: *mut pa_operation, cb: pa_operation_notify_cb_t, userdata: *mut c_void);
53}