diff --git a/jack-sys/build.rs b/jack-sys/build.rs index 835d2f0c4..1d50bbe46 100644 --- a/jack-sys/build.rs +++ b/jack-sys/build.rs @@ -128,12 +128,17 @@ fn write_dynamic_loading_src(out: &mut W) -> Result<(), std:: f.type_name() )?; } else { + let mut f_name = f.name; + if f_name == "jack_client_open_with_server_name" { + f_name = "jack_client_open"; + } + writeln!(out, " let {}_impl = library.get:: {}>(b\"{}\").unwrap();", f.name, f.args_full(false), f.ret, - f.name, + f_name, )?; writeln!( out, @@ -362,6 +367,17 @@ const FUNCTIONS: &[Function] = &[ ret: "*mut jack_client_t", flags: FunctionFlags::NONE, }, + Function { + name: "jack_client_open_with_server_name", + args: &[ + ("client_name", "*const ::libc::c_char"), + ("options", "jack_options_t"), + ("status", "*mut jack_status_t"), + ("server_name", "*const ::libc::c_char"), + ], + ret: "*mut jack_client_t", + flags: FunctionFlags::NONE, + }, Function { name: "jack_client_new", args: &[("client_name", "*const ::libc::c_char")], diff --git a/src/client/client_impl.rs b/src/client/client_impl.rs index 4490ea3aa..a74c14800 100644 --- a/src/client/client_impl.rs +++ b/src/client/client_impl.rs @@ -51,8 +51,15 @@ impl Client { /// Although the client may be successful in opening, there still may be some errors minor /// errors when attempting to opening. To access these, check the returned `ClientStatus`. pub fn new(client_name: &str, options: ClientOptions) -> Result<(Self, ClientStatus), Error> { - let _m = CREATE_OR_DESTROY_CLIENT_MUTEX.lock().ok(); + Self::new_with_server_name(client_name, options, None) + } + pub fn new_with_server_name( + client_name: &str, + options: ClientOptions, + server_name: Option<&str>, + ) -> Result<(Self, ClientStatus), Error> { + let _m = CREATE_OR_DESTROY_CLIENT_MUTEX.lock().ok(); // All of the jack_sys functions below assume the client library is loaded and will panic if // it is not #[cfg(feature = "dynamic_loading")] @@ -61,18 +68,31 @@ impl Client { } crate::logging::maybe_init_logging(); - sleep_on_test(); let mut status_bits = 0; - let client = unsafe { + let client = { let client_name = ffi::CString::new(client_name).unwrap(); - j::jack_client_open(client_name.as_ptr(), options.bits(), &mut status_bits) + if let Some(server_name) = server_name { + let server_name = ffi::CString::new(server_name).unwrap(); + let options = options | ClientOptions::SERVER_NAME; + unsafe { + j::jack_client_open_with_server_name( + client_name.as_ptr(), + options.bits(), + &mut status_bits, + server_name.as_ptr(), + ) + } + } else { + unsafe { + j::jack_client_open(client_name.as_ptr(), options.bits(), &mut status_bits) + } + } }; - sleep_on_test(); + let status = ClientStatus::from_bits(status_bits).unwrap_or_else(ClientStatus::empty); if client.is_null() { Err(Error::ClientError(status)) } else { - sleep_on_test(); Ok((Client(client, Arc::default(), None), status)) } } diff --git a/src/client/client_options.rs b/src/client/client_options.rs index 84659e176..ef84465e7 100644 --- a/src/client/client_options.rs +++ b/src/client/client_options.rs @@ -14,8 +14,7 @@ bitflags! { const USE_EXACT_NAME = j::JackUseExactName; /// Open with optional `server_name` parameter. - /// - /// TODO: implement + /// Use Client::new_with_server_name const SERVER_NAME = j::JackServerName; /// Load internal client from optional `load_name`, otherwise use the `client_name`.