Skip to main content

jack_sys/
lib.rs

1#![allow(non_camel_case_types, non_upper_case_globals)]
2use lazy_static::lazy_static;
3
4mod consts;
5mod types;
6
7// Contains both static and dynamic dispatched functions.
8mod functions;
9
10pub use consts::*;
11pub use types::*;
12
13#[cfg(not(feature = "dynamic_loading"))]
14pub use functions::dynamic_linking::*;
15#[cfg(feature = "dynamic_loading")]
16pub use functions::dynamic_loading::*;
17
18lazy_static! {
19    static ref LIB_RESULT: Result<libloading::Library, libloading::Error> = unsafe {
20        log::info!("Loading jack from {}.", JACK_LIB);
21        libloading::Library::new(JACK_LIB)
22    };
23}
24
25/// Get the underlying library handle used for dynamic loading. Can be used to extract symbols from
26/// the library.
27///
28/// # Example
29/// ```rust
30/// let symbol = library.get::<unsafe extern "C" fn(client: *mut jack_client_t) -> ::libc::c_int>(b"jack_release_timebase").unwrap();
31/// let raw_symbol = symbol.into_raw();
32/// let func = *raw_symbol.deref() as unsafe extern "C" fn(client: *mut jack_client_t) -> ::libc::c_int;
33/// ```
34pub fn library() -> Result<&'static libloading::Library, impl std::error::Error> {
35    LIB_RESULT.as_ref()
36}