Compare commits

...

4 Commits

Author SHA1 Message Date
Nolan Darilek 0efdccc9aa Merge branch '32bit' into 'master'
Fix msg_id and client_id being size_t in C

Closes #5

See merge request ndarilek/speech-dispatcher-rs!5
2022-09-07 14:53:43 +00:00
Nolan Darilek e770c73e67 Merge branch 'voice_type' into 'master'
Fix voice_type signedness change

Closes #4

See merge request ndarilek/speech-dispatcher-rs!6
2022-09-07 14:48:56 +00:00
Samuel Thibault 8ff6902148 Fix voice_type signedness change
The signedness changed happened in speech-dispatcher 0.11, not in
speech-dispatcher 0.10.2.

Closes #4
2022-09-07 15:54:53 +02:00
Samuel Thibault 29f990e19b Fix msg_id and client_id being size_t in C
instead of u64 which is only valid on 64bit architectures.

Fixes #5
2022-09-07 15:31:10 +02:00
3 changed files with 30 additions and 30 deletions

View File

@ -11,7 +11,7 @@ before_script:
test:
stage: test
script:
- cargo test
- cargo test --no-default-features --features 0_10
publish:
stage: publish

View File

@ -8,9 +8,9 @@ license = "LGPL-2.1 OR MIT OR Apache-2.0"
edition = "2021"
[features]
0_10_2 = ["0_10"]
0_11 = ["0_10"]
0_10 = []
default = ["0_10_2"]
default = ["0_11"]
[dependencies]
lazy_static = "1"

View File

@ -122,12 +122,12 @@ fn c_int_to_result(r: c_int) -> Result<(), Error> {
#[derive(Default)]
struct Callbacks {
begin: Option<Box<dyn FnMut(u64, u64)>>,
end: Option<Box<dyn FnMut(u64, u64)>>,
index_mark: Option<Box<dyn FnMut(u64, u64, String)>>,
cancel: Option<Box<dyn FnMut(u64, u64)>>,
pause: Option<Box<dyn FnMut(u64, u64)>>,
resume: Option<Box<dyn FnMut(u64, u64)>>,
begin: Option<Box<dyn FnMut(size_t, size_t)>>,
end: Option<Box<dyn FnMut(size_t, size_t)>>,
index_mark: Option<Box<dyn FnMut(size_t, size_t, String)>>,
cancel: Option<Box<dyn FnMut(size_t, size_t)>>,
pause: Option<Box<dyn FnMut(size_t, size_t)>>,
resume: Option<Box<dyn FnMut(size_t, size_t)>>,
}
unsafe impl Send for Callbacks {}
@ -135,13 +135,13 @@ unsafe impl Send for Callbacks {}
unsafe impl Sync for Callbacks {}
lazy_static! {
static ref callbacks: Mutex<HashMap<u64, Callbacks>> = {
static ref callbacks: Mutex<HashMap<size_t, Callbacks>> = {
let m = HashMap::new();
Mutex::new(m)
};
}
unsafe extern "C" fn cb(msg_id: u64, client_id: u64, state: u32) {
unsafe extern "C" fn cb(msg_id: size_t, client_id: size_t, state: u32) {
let state = match state {
SPDNotificationType_SPD_EVENT_BEGIN => Notification::Begin,
SPDNotificationType_SPD_EVENT_END => Notification::End,
@ -165,7 +165,7 @@ unsafe extern "C" fn cb(msg_id: u64, client_id: u64, state: u32) {
}
}
unsafe extern "C" fn cb_im(msg_id: u64, client_id: u64, state: u32, index_mark: *mut c_char) {
unsafe extern "C" fn cb_im(msg_id: size_t, client_id: size_t, state: u32, index_mark: *mut c_char) {
let index_mark = CStr::from_ptr(index_mark);
let index_mark = index_mark.to_string_lossy().to_string();
let state = match state {
@ -205,7 +205,7 @@ impl fmt::Display for Error {
}
#[derive(Clone, Debug)]
pub struct Connection(pub Arc<*mut SPDConnection>, u64);
pub struct Connection(pub Arc<*mut SPDConnection>, size_t);
impl Connection {
pub fn open<S: Into<String>>(
@ -287,7 +287,7 @@ impl Connection {
if let Some(client_id) = client_id {
let client_id: Vec<&str> = client_id.split("-").collect();
if let Some(client_id) = client_id.get(1) {
if let Ok(client_id) = client_id.parse::<u64>() {
if let Ok(client_id) = client_id.parse::<size_t>() {
self.1 = client_id;
}
}
@ -413,26 +413,26 @@ impl Connection {
}
pub fn set_voice_type(&self, voice_type: VoiceType) -> Result<(), Error> {
#[cfg(all(feature = "0_10", not(feature = "0_10_2")))]
let v = unsafe { spd_set_voice_type(*self.0, voice_type as i32) };
#[cfg(any(feature = "0_10_2", not(feature = "0_10")))]
#[cfg(all(feature = "0_10", not(feature = "0_11")))]
let v = unsafe { spd_set_voice_type(*self.0, voice_type as u32) };
#[cfg(any(feature = "0_11", not(feature = "0_10")))]
let v = unsafe { spd_set_voice_type(*self.0, voice_type as i32) };
c_int_to_result(v)
}
pub fn set_voice_type_all(&self, voice_type: VoiceType) -> Result<(), Error> {
#[cfg(all(feature = "0_10", not(feature = "0_10_2")))]
let v = unsafe { spd_set_voice_type_all(*self.0, voice_type as i32) };
#[cfg(any(feature = "0_10_2", not(feature = "0_10")))]
#[cfg(all(feature = "0_10", not(feature = "0_11")))]
let v = unsafe { spd_set_voice_type_all(*self.0, voice_type as u32) };
#[cfg(any(feature = "0_11", not(feature = "0_10")))]
let v = unsafe { spd_set_voice_type_all(*self.0, voice_type as i32) };
c_int_to_result(v)
}
pub fn set_voice_type_uid(&self, voice_type: VoiceType, target_uid: u32) -> Result<(), Error> {
#[cfg(all(feature = "0_10", not(feature = "0_10_2")))]
let v = unsafe { spd_set_voice_type_uid(*self.0, voice_type as i32, target_uid) };
#[cfg(any(feature = "0_10_2", not(feature = "0_10")))]
#[cfg(all(feature = "0_10", not(feature = "0_11")))]
let v = unsafe { spd_set_voice_type_uid(*self.0, voice_type as u32, target_uid) };
#[cfg(any(feature = "0_11", not(feature = "0_10")))]
let v = unsafe { spd_set_voice_type_uid(*self.0, voice_type as i32, target_uid) };
c_int_to_result(v)
}
@ -693,7 +693,7 @@ impl Connection {
}
}
pub fn on_begin(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
pub fn on_begin(&self, f: Option<Box<dyn FnMut(size_t, size_t)>>) {
if let Ok(mut cbs) = callbacks.lock() {
let cb = cbs.get_mut(&self.1);
if let Some(cb) = cb {
@ -702,7 +702,7 @@ impl Connection {
}
}
pub fn on_end(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
pub fn on_end(&self, f: Option<Box<dyn FnMut(size_t, size_t)>>) {
if let Ok(mut cbs) = callbacks.lock() {
let cb = cbs.get_mut(&self.1);
if let Some(cb) = cb {
@ -711,7 +711,7 @@ impl Connection {
}
}
pub fn on_cancel(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
pub fn on_cancel(&self, f: Option<Box<dyn FnMut(size_t, size_t)>>) {
if let Ok(mut cbs) = callbacks.lock() {
let cb = cbs.get_mut(&self.1);
if let Some(cb) = cb {
@ -720,7 +720,7 @@ impl Connection {
}
}
pub fn on_pause(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
pub fn on_pause(&self, f: Option<Box<dyn FnMut(size_t, size_t)>>) {
if let Ok(mut cbs) = callbacks.lock() {
let cb = cbs.get_mut(&self.1);
if let Some(cb) = cb {
@ -729,7 +729,7 @@ impl Connection {
}
}
pub fn on_resume(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
pub fn on_resume(&self, f: Option<Box<dyn FnMut(size_t, size_t)>>) {
if let Ok(mut cbs) = callbacks.lock() {
let cb = cbs.get_mut(&self.1);
if let Some(cb) = cb {
@ -738,7 +738,7 @@ impl Connection {
}
}
pub fn on_index_mark(&self, f: Option<Box<dyn FnMut(u64, u64, String)>>) {
pub fn on_index_mark(&self, f: Option<Box<dyn FnMut(size_t, size_t, String)>>) {
if let Ok(mut cbs) = callbacks.lock() {
let cb = cbs.get_mut(&self.1);
if let Some(cb) = cb {
@ -784,7 +784,7 @@ impl Connection {
Ok(modules)
}
pub fn client_id(&self) -> u64 {
pub fn client_id(&self) -> size_t {
self.1
}
}