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

source

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

source

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();
  }
}
source

pub fn poll_and_block(&self, time: i32)

Trait Implementations§

source§

impl Drop for Graph

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Send for Graph

source§

impl Sync for Graph

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.