libpulse_sys/
error.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//! Error management.
15
16use std::os::raw::c_char;
17use num_derive::{FromPrimitive, ToPrimitive};
18
19/// Error code.
20///
21/// These represent the i32 error codes returned by many of the underlying PulseAudio C functions.
22/// Beware, these enum values are positive values, whilst PA functions return them in negative form,
23/// i.e. the `Invalid` variant here has a value of `3`, while functions returning this error code
24/// return `-3`. (This is identical to the enum provided in the PA C API).
25#[repr(C)]
26#[derive(Debug, Copy, Clone, PartialEq, Eq)]
27#[derive(FromPrimitive, ToPrimitive)]
28#[allow(non_camel_case_types)]
29pub enum pa_error_code_t {
30    /// No error.
31    Ok = 0,
32    /// Access failure.
33    Access,
34    /// Unknown command.
35    Command,
36    /// Invalid argument.
37    Invalid,
38    /// Entity exists.
39    Exist,
40    /// No such entity.
41    NoEntity,
42    /// Connection refused.
43    ConnectionRefused,
44    /// Protocol error.
45    Protocol,
46    Timeout,
47    /// No authentication key.
48    AuthKey,
49    Internal,
50    ConnectionTerminated,
51    /// Entity killed.
52    Killed,
53    InvalidServer,
54    ModInitFailed,
55    BadState,
56    NoData,
57    /// Incompatible protocol version.
58    Version,
59    /// Data too large.
60    TooLarge,
61    /// Operation not supported.
62    NotSupported,
63    /// The error code was unknown to the client.
64    Unknown,
65    /// Extension does not exist.
66    NoExtension,
67    /// Obsolete functionality.
68    Obsolete,
69    /// Missing implementation.
70    NotImplemented,
71    /// The caller forked without calling execve() and tried to reuse the context.
72    Forked,
73    /// An IO error happened.
74    IO,
75    /// Device or resource busy.
76    Busy,
77}
78
79pub const PA_ERR_MAX: usize = 27;
80
81pub const PA_OK:                       pa_error_code_t = pa_error_code_t::Ok;
82pub const PA_ERR_ACCESS:               pa_error_code_t = pa_error_code_t::Access;
83pub const PA_ERR_COMMAND:              pa_error_code_t = pa_error_code_t::Command;
84pub const PA_ERR_INVALID:              pa_error_code_t = pa_error_code_t::Invalid;
85pub const PA_ERR_EXIST:                pa_error_code_t = pa_error_code_t::Exist;
86pub const PA_ERR_NOENTITY:             pa_error_code_t = pa_error_code_t::NoEntity;
87pub const PA_ERR_CONNECTIONREFUSED:    pa_error_code_t = pa_error_code_t::ConnectionRefused;
88pub const PA_ERR_PROTOCOL:             pa_error_code_t = pa_error_code_t::Protocol;
89pub const PA_ERR_TIMEOUT:              pa_error_code_t = pa_error_code_t::Timeout;
90pub const PA_ERR_AUTHKEY:              pa_error_code_t = pa_error_code_t::AuthKey;
91pub const PA_ERR_INTERNAL:             pa_error_code_t = pa_error_code_t::Internal;
92pub const PA_ERR_CONNECTIONTERMINATED: pa_error_code_t = pa_error_code_t::ConnectionTerminated;
93pub const PA_ERR_KILLED:               pa_error_code_t = pa_error_code_t::Killed;
94pub const PA_ERR_INVALIDSERVER:        pa_error_code_t = pa_error_code_t::InvalidServer;
95pub const PA_ERR_MODINITFAILED:        pa_error_code_t = pa_error_code_t::ModInitFailed;
96pub const PA_ERR_BADSTATE:             pa_error_code_t = pa_error_code_t::BadState;
97pub const PA_ERR_NODATA:               pa_error_code_t = pa_error_code_t::NoData;
98pub const PA_ERR_VERSION:              pa_error_code_t = pa_error_code_t::Version;
99pub const PA_ERR_TOOLARGE:             pa_error_code_t = pa_error_code_t::TooLarge;
100pub const PA_ERR_NOTSUPPORTED:         pa_error_code_t = pa_error_code_t::NotSupported;
101pub const PA_ERR_UNKNOWN:              pa_error_code_t = pa_error_code_t::Unknown;
102pub const PA_ERR_NOEXTENSION:          pa_error_code_t = pa_error_code_t::NoExtension;
103pub const PA_ERR_OBSOLETE:             pa_error_code_t = pa_error_code_t::Obsolete;
104pub const PA_ERR_NOTIMPLEMENTED:       pa_error_code_t = pa_error_code_t::NotImplemented;
105pub const PA_ERR_FORKED:               pa_error_code_t = pa_error_code_t::Forked;
106pub const PA_ERR_IO:                   pa_error_code_t = pa_error_code_t::IO;
107pub const PA_ERR_BUSY:                 pa_error_code_t = pa_error_code_t::Busy;
108
109#[link(name = "pulse")]
110extern "C" {
111    pub fn pa_strerror(error: i32) -> *const c_char;
112}