Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add server name support #189

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion jack-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,17 @@ fn write_dynamic_loading_src<W: std::io::Write>(out: &mut W) -> Result<(), std::
f.type_name()
)?;
} else {
let mut f_name = f.name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably needs to be locked behind the dynamic loading feature as dynamic linking (write_dynamic_linking_src function) doesn't work due to having the same symbol name ("jack_client_open") and Rust not supporting varargs (rust-lang/rust#44930)

if f_name == "jack_client_open_with_server_name" {
f_name = "jack_client_open";
}

writeln!(out,
" let {}_impl = library.get::<unsafe extern \"C\" fn({}) -> {}>(b\"{}\").unwrap();",
f.name,
f.args_full(false),
f.ret,
f.name,
f_name,
)?;
writeln!(
out,
Expand Down Expand Up @@ -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")],
Expand Down
32 changes: 26 additions & 6 deletions src/client/client_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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))
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/client/client_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
Loading