Make client ID easier to get at.

* Pass `client_id` into all callbacks.
* Expose via `client_id()` method.
* Bump version.
This commit is contained in:
Nolan Darilek 2020-08-19 20:59:48 -05:00
parent e022973c8e
commit bf348af84f
3 changed files with 30 additions and 18 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "speech-dispatcher"
version = "0.5.0"
version = "0.6.0"
authors = ["Nolan Darilek <nolan@thewordnerd.info>"]
repository = "https://gitlab.com/ndarilek/speech-dispatcher-rs"
description = "Rusty interface to the speech-dispatcher speech synthesis library"

View File

@ -10,11 +10,19 @@ fn main() {
"hello_world",
Mode::Threaded,
);
connection.on_begin(Some(|id| println!("Beginning {}", id)));
connection.on_end(Some(|id| println!("Ending {}", id)));
connection.on_begin(Some(|msg_id, client_id| {
println!("Beginning {} from {}", msg_id, client_id)
}));
connection.on_end(Some(|msg_id, client_id| {
println!("Ending {} from {}", msg_id, client_id)
}));
connection.say(
Priority::Important,
format!("Hello, world at rate {}.", connection.get_voice_rate()),
format!(
"Hello, world at rate {} from client {}.",
connection.get_voice_rate(),
connection.client_id()
),
);
connection.set_voice_rate(100);
connection.say(Priority::Important, "This is faster.");

View File

@ -84,12 +84,12 @@ fn i32_to_bool(v: i32) -> bool {
#[derive(Clone, Copy)]
struct Callbacks {
begin: Option<fn(u64)>,
end: Option<fn(u64)>,
index_mark: Option<fn(u64, String)>,
cancel: Option<fn(u64)>,
pause: Option<fn(u64)>,
resume: Option<fn(u64)>,
begin: Option<fn(u64, u64)>,
end: Option<fn(u64, u64)>,
index_mark: Option<fn(u64, u64, String)>,
cancel: Option<fn(u64, u64)>,
pause: Option<fn(u64, u64)>,
resume: Option<fn(u64, u64)>,
}
impl Default for Callbacks {
@ -131,7 +131,7 @@ unsafe extern "C" fn cb(msg_id: u64, client_id: u64, state: u32) {
_ => panic!("Unknown notification type"),
};
if let Some(f) = f {
f(msg_id);
f(msg_id, client_id);
}
}
}
@ -149,7 +149,7 @@ unsafe extern "C" fn cb_im(msg_id: u64, client_id: u64, state: u32, index_mark:
_ => panic!("Unknown notification type"),
};
if let Some(f) = f {
f(msg_id, index_mark);
f(msg_id, client_id, index_mark);
}
}
}
@ -596,7 +596,7 @@ impl Connection {
}
}
pub fn on_begin(&self, f: Option<fn(u64)>) {
pub fn on_begin(&self, f: Option<fn(u64, u64)>) {
if let Ok(mut cbs) = callbacks.lock() {
let cb = cbs.get_mut(&self.1);
if let Some(cb) = cb {
@ -605,7 +605,7 @@ impl Connection {
}
}
pub fn on_end(&self, f: Option<fn(u64)>) {
pub fn on_end(&self, f: Option<fn(u64, u64)>) {
if let Ok(mut cbs) = callbacks.lock() {
let cb = cbs.get_mut(&self.1);
if let Some(cb) = cb {
@ -614,7 +614,7 @@ impl Connection {
}
}
pub fn on_cancel(&self, f: Option<fn(u64)>) {
pub fn on_cancel(&self, f: Option<fn(u64, u64)>) {
if let Ok(mut cbs) = callbacks.lock() {
let cb = cbs.get_mut(&self.1);
if let Some(cb) = cb {
@ -623,7 +623,7 @@ impl Connection {
}
}
pub fn on_pause(&self, f: Option<fn(u64)>) {
pub fn on_pause(&self, f: Option<fn(u64, u64)>) {
if let Ok(mut cbs) = callbacks.lock() {
let cb = cbs.get_mut(&self.1);
if let Some(cb) = cb {
@ -632,7 +632,7 @@ impl Connection {
}
}
pub fn on_resume(&self, f: Option<fn(u64)>) {
pub fn on_resume(&self, f: Option<fn(u64, u64)>) {
if let Ok(mut cbs) = callbacks.lock() {
let cb = cbs.get_mut(&self.1);
if let Some(cb) = cb {
@ -641,7 +641,7 @@ impl Connection {
}
}
pub fn on_index_mark(&self, f: Option<fn(u64, String)>) {
pub fn on_index_mark(&self, f: Option<fn(u64, u64, String)>) {
if let Ok(mut cbs) = callbacks.lock() {
let cb = cbs.get_mut(&self.1);
if let Some(cb) = cb {
@ -649,6 +649,10 @@ impl Connection {
}
}
}
pub fn client_id(&self) -> u64 {
self.1
}
}
unsafe impl Send for Connection {}