use dbus::blocking::{Connection, Proxy};
use std::error::Error;
use std::thread::sleep;
use shmem_ipc::sharedring::Sender;
use std::time::Duration;
use std::fs::File;
fn main() -> Result<(), Box<dyn Error>> {
let c = Connection::new_session()?;
let proxy = Proxy::new("com.example.shmemtest", "/shmemtest", Duration::from_millis(3000), &c);
let (capacity, memfd, empty_signal, full_signal): (u64, File, File, File) =
proxy.method_call("com.example.shmemtest", "Setup", ())?;
let mut r = Sender::open(capacity as usize, memfd, empty_signal, full_signal)?;
let mut items = 100000;
loop {
let item = 1.0f64 / (items as f64);
r.send_raw(|p: *mut f64, mut count| unsafe {
if items < count { count = items };
for i in 0..count {
*p.offset(i as isize) = item;
}
println!("Sending {} items of {}, in total {}", count, item, (count as f64) * item);
count
}).unwrap();
items += 100000;
sleep(Duration::from_millis(1000));
}
}