Crossroads

Struct Crossroads 

Source
pub struct Crossroads { /* private fields */ }
Expand description

Crossroads is the “main” object, containing object paths, a registry of interfaces, and a crossreference of which object paths implement which interfaces.

You can store some arbitrary data with every object path if you like. This data can then be accessed from within the method callbacks. If you do not want this, just pass () as your data.

Crossroads can contain callbacks and data which is Send, but Sync is not required. Hence Crossroads itself is Send but not Sync.

Implementations§

Source§

impl Crossroads

Source

pub fn new() -> Crossroads

Create a new Crossroads instance.

Source

pub fn set_add_standard_ifaces(&mut self, enable: bool)

If set to true (the default), will make paths implement the standard “Introspectable” and, if the path has interfaces with properties, the “Properties” interfaces.

Source

pub fn register<T, N, F>(&mut self, name: N, f: F) -> IfaceToken<T>
where T: Send + 'static, N: Into<Interface<'static>>, F: FnOnce(&mut IfaceBuilder<T>),

Registers a new interface into the interface registry. The closure receives an IfaceBuilder that you can add methods, signals and properties to.

Source

pub fn data_mut<D: Any + Send + 'static>( &mut self, name: &Path<'static>, ) -> Option<&mut D>

Access the data of a certain path.

Will return none both if the path was not found, and if the found data was of another type.

Source

pub fn insert<'z, D, I, N>(&mut self, name: N, ifaces: I, data: D)
where D: Any + Send + 'static, N: Into<Path<'static>>, I: IntoIterator<Item = &'z IfaceToken<D>>,

Inserts a new path.

If the path already exists, it is overwritten.

Source

pub fn add_interface<'z, D, N>(&mut self, name: N, iface: IfaceToken<D>) -> bool
where D: Any + Send + 'static, N: Into<Path<'static>>,

Adds an interface to an existing object path.

Returns true if interface can be added to the object or already exists in the object. Returns false if the object does not exist or the interface cannot be added due to data type mismatch.

Source

pub fn remove_interface<'z, D, N>(&mut self, name: N, iface: IfaceToken<D>)
where D: Any + Send + 'static, N: Into<Path<'static>>,

Removes an interface from an object path.

Source

pub fn has_interface<D: Send>( &self, name: &Path<'static>, token: IfaceToken<D>, ) -> bool

Returns true if the path exists and implements the interface

Source

pub fn remove<D>(&mut self, name: &Path<'static>) -> Option<D>
where D: Any + Send + 'static,

Removes an existing path.

Returns None if the path was not found. In case of a type mismatch, the path will be removed, but None will be returned.

Source

pub fn handle_message<S: Sender>( &mut self, message: Message, conn: &S, ) -> Result<(), ()>

Handles an incoming message call.

Returns Err if the message is not a method call.

Source

pub fn introspectable<T: Send + 'static>(&self) -> IfaceToken<T>

The token representing the built-in implementation of “org.freedesktop.DBus.Introspectable”.

Source

pub fn properties<T: Send + 'static>(&self) -> IfaceToken<T>

The token representing the built-in implementation of “org.freedesktop.DBus.Properties”.

Source

pub fn object_manager<T: Send + 'static>(&self) -> IfaceToken<T>

The token representing the built-in implementation of “org.freedesktop.DBus.ObjectManager”.

You can add this to a path without enabling “set_object_manager_support”, but no signals will be sent.

Source

pub fn set_async_support( &mut self, x: Option<(Arc<dyn Sender + Send + Sync + 'static>, Box<dyn Fn(Pin<Box<dyn Future<Output = ()> + Send + 'static>>) + Send + 'static>)>, ) -> Option<(Arc<dyn Sender + Send + Sync + 'static>, Box<dyn Fn(Pin<Box<dyn Future<Output = ()> + Send + 'static>>) + Send + 'static>)>

Enables this crossroads instance to run asynchronous methods (and setting properties).

Incoming method calls are spawned as separate tasks if necessary. This provides the necessary abstractions needed to spawn a new tasks, and to send the reply when the task has finished.

Source

pub fn set_object_manager_support( &mut self, x: Option<Arc<dyn Sender + Send + Sync + 'static>>, ) -> Option<Arc<dyn Sender + Send + Sync + 'static>>

Enables this crossroads instance to send signals when paths are added and removed.

The added/removed path is a subpath of a path which implements an object manager instance.

Source

pub fn serve(self, connection: &Connection) -> Result<(), Error>

Serve clients forever on a blocking Connection.

This is a quick one-liner for the simplest case. In more advanced scenarios, you probably have to write similar code yourself.

Trait Implementations§

Source§

impl Debug for Crossroads

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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>,

Source§

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>,

Source§

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.