Struct libmapper_rs::graph::Graph
source · pub struct Graph { /* private fields */ }
Expand description
A graph is a lightweight connection to libmapper’s distributed graph. You can use a graph to create maps and query the state of the graph.
Implementations§
source§impl Graph
impl Graph
sourcepub fn create() -> Graph
pub fn create() -> Graph
Examples found in repository?
examples/segfault.rs (line 7)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
fn main() {
let graph = Arc::new(Graph::create());
let counter: Arc<AtomicU64> = Arc::new(AtomicU64::new(0));
let mut threads = Vec::<JoinHandle<()>>::new();
{
// spawn a thread to poll the graph
let graph = Arc::clone(&graph);
let thread = std::thread::spawn(move || {
loop {
graph.poll();
}
});
threads.push(thread);
}
let mut num_workers = 10;
let arg = env::args().skip(1).next();
if arg.is_some() {
num_workers = arg.unwrap().parse::<i32>().unwrap_or(10);
}
// spawn n threads creating then deleting devices at random
for _ in 0..num_workers {
let graph = graph.clone();
let id_counter = counter.clone();
let thread = std::thread::spawn(move || {
let name = format!("rust_{:?}", thread::current().id());
loop {
let _dev = libmapper_rs::device::Device::create_from_graph(&name, &graph);
loop {
_dev.poll();
if _dev.is_ready() {
break;
}
}
let signal = _dev.create_signal::<f32>("test_sig", libmapper_rs::constants::mpr_dir::MPR_DIR_OUT);
thread::sleep(std::time::Duration::from_millis(id_counter.fetch_add(1, Ordering::SeqCst) as u64));
drop(signal);
drop(_dev);
}
});
threads.push(thread);
}
for thread in threads {
thread.join().unwrap();
}
}
source§impl Graph
impl Graph
sourcepub fn poll(&self)
pub fn poll(&self)
Poll the graph without blocking
Examples found in repository?
examples/segfault.rs (line 17)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
fn main() {
let graph = Arc::new(Graph::create());
let counter: Arc<AtomicU64> = Arc::new(AtomicU64::new(0));
let mut threads = Vec::<JoinHandle<()>>::new();
{
// spawn a thread to poll the graph
let graph = Arc::clone(&graph);
let thread = std::thread::spawn(move || {
loop {
graph.poll();
}
});
threads.push(thread);
}
let mut num_workers = 10;
let arg = env::args().skip(1).next();
if arg.is_some() {
num_workers = arg.unwrap().parse::<i32>().unwrap_or(10);
}
// spawn n threads creating then deleting devices at random
for _ in 0..num_workers {
let graph = graph.clone();
let id_counter = counter.clone();
let thread = std::thread::spawn(move || {
let name = format!("rust_{:?}", thread::current().id());
loop {
let _dev = libmapper_rs::device::Device::create_from_graph(&name, &graph);
loop {
_dev.poll();
if _dev.is_ready() {
break;
}
}
let signal = _dev.create_signal::<f32>("test_sig", libmapper_rs::constants::mpr_dir::MPR_DIR_OUT);
thread::sleep(std::time::Duration::from_millis(id_counter.fetch_add(1, Ordering::SeqCst) as u64));
drop(signal);
drop(_dev);
}
});
threads.push(thread);
}
for thread in threads {
thread.join().unwrap();
}
}
pub fn poll_and_block(&self, time: i32)
Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more