From 3d71cc46e5c66df67900cafee9ce6e4220708c94 Mon Sep 17 00:00:00 2001 From: srperens Date: Tue, 5 Dec 2023 08:36:37 +0100 Subject: [PATCH 1/2] add server_name support --- jack-sys/build.rs | 18 +++++++++++++++++- src/client/client_impl.rs | 20 ++++++++++++++++++-- src/client/client_options.rs | 3 +-- 3 files changed, 36 insertions(+), 5 deletions(-) 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 28663ff92..696bf1da8 100644 --- a/src/client/client_impl.rs +++ b/src/client/client_impl.rs @@ -49,6 +49,10 @@ 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> { + 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().unwrap(); // All of the jack_sys functions below assume the client library is loaded and will panic if @@ -64,10 +68,22 @@ impl Client { } 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() { diff --git a/src/client/client_options.rs b/src/client/client_options.rs index d7d66b510..8f11823f8 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`. From bf97a2e48cfff82908237aa9e461c9530869108f Mon Sep 17 00:00:00 2001 From: Will Date: Sat, 14 Sep 2024 16:30:54 -0700 Subject: [PATCH 2/2] Run rustfmt --- src/client/client_impl.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/client/client_impl.rs b/src/client/client_impl.rs index b3398ef64..a74c14800 100644 --- a/src/client/client_impl.rs +++ b/src/client/client_impl.rs @@ -53,8 +53,12 @@ impl Client { pub fn new(client_name: &str, options: ClientOptions) -> Result<(Self, ClientStatus), Error> { 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> { + + 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 @@ -71,8 +75,13 @@ impl Client { 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()) - } + 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)