Skip to main content

ServiceWatcher

Struct ServiceWatcher 

pub struct ServiceWatcher {
    socket: AsyncFd<Socket>,
}
Expand description

Watches the IPC router for QMI servers that are added or removed.

Services start at different times during boot. Use ServiceWatcher::wait_for to wait until a service is available before connecting to it.

§Example

use ql_qmi::{RawClient, ServiceWatcher};

let server = ServiceWatcher::new()?.wait_for(0x401, 1).await?;
let (client, connection) = RawClient::builder(0x401, 1).connect_to(server)?;
tokio::spawn(connection.run());

The router queues a message for every change, including every client on the modem that goes away. Keep reading the watcher with ServiceWatcher::recv or drop it. Unread messages take up kernel memory, and on some kernels they keep the device from suspending.

Fields§

§socket: AsyncFd<Socket>

Implementations§

§

impl ServiceWatcher

pub fn new() -> Result<Self, Error>

Starts watching.

Only changes after this call are reported.

§Errors

Returns an error if the socket can’t be set up.

§Panics

Panics if called outside of a tokio runtime.

pub async fn recv(&mut self) -> Result<ServiceEvent, Error>

Waits for the next change.

§Errors

Returns an error if receiving fails.

pub async fn wait_for( &mut self, service: u32, version: u8, ) -> Result<Server, Error>

Waits until a server provides the service and returns it.

Returns immediately if one already does. Drops the changes that were queued before the call, so they can’t report a server that is gone. Repeats the lookup every 30 s, because the router can lose a change when it runs out of memory.

Connecting to the returned server can still fail. The router can list a server for a short time after it has reported its removal.

§Errors

Returns an error if the lookup or receiving fails.

pub async fn wait_for_service<S: Service>(&mut self) -> Result<Server, Error>

Waits until a server provides service S and returns it.

Behaves like ServiceWatcher::wait_for otherwise.

§Errors

Returns an error if the lookup or receiving fails.

pub async fn wait_for_instance( &mut self, service: u32, version: u8, instance_id: u32, ) -> Result<Server, Error>

Waits until a server provides this instance of the service and returns it.

Behaves like ServiceWatcher::wait_for otherwise.

§Errors

Returns Error::InstanceNotFound if instance_id doesn’t fit into 24 bits, or an error if the lookup or receiving fails.

pub async fn wait_removed(&mut self, server: Server) -> Result<(), Error>

Waits until server goes away.

Returns immediately if it is already gone. Wait for this next to Connection::run, because the Connection doesn’t see every server that goes away. The router reports a hang up to it when the server’s port closes or the modem restarts, except on EVA for a modem server that was removed before its port closed. No kernel reports a server that unregisters but keeps its port. Requests to that server time out.

Repeats the lookup every 30 s, like Self::wait_for.

§Errors

Returns an error if the lookup or receiving fails.

fn is_listed(&self, server: Server) -> Result<bool, Error>

Returns whether a lookup lists server.

async fn wait(&mut self, service: u32, filter: Filter) -> Result<Server, Error>

fn drain(&self) -> Result<(), Error>

Drops the queued changes.

Trait Implementations§

§

impl Debug for ServiceWatcher

§

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = !

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more