[−][src]Struct anachro_client::Client
The Client interface
This is the primary interface used by clients. It is used to track the state of a connection, and process any incoming or outgoing messages
Implementations
impl Client
[src]
pub fn new(
name: &str,
version: Version,
ctr_init: u16,
sub_paths: &'static [&'static str],
pub_short_paths: &'static [&'static str],
timeout_ticks: Option<u8>
) -> Self
[src]
name: &str,
version: Version,
ctr_init: u16,
sub_paths: &'static [&'static str],
pub_short_paths: &'static [&'static str],
timeout_ticks: Option<u8>
) -> Self
Create a new client instance
Parameters
name
The name of this device or client
version
The semantic version number of this client
ctr_init
A value to initialize the control counter.
You may choose to initialize this with a fixed or random value
sub_paths
The subscription paths that the device is interested in
This is typically provided by the Table::sub_paths()
method on
a table type generated using the pubsub_table!()
macro.
pub_paths
The publishing paths that the device is interested in
This is typically provided by the Table::pub_paths()
method on
a table type generated using the pubsub_table!()
macro.
timeout_ticks
The number of ticks used to time-out waiting for certain responses before retrying automatically.
Set to None
to disable automatic retries. This will require the
user to manually call Client::reset_connection()
if a message is
lost.
Ticks are counted by calls to Client::process_one()
, which should be
called at a semi-regular rate. e.g. if you call process_one()
every
10ms, a timeout_ticks: Some(100)
would automatically timeout after
1s of waiting for a response.
pub fn reset_connection(&mut self)
[src]
Reset the client connection
This immediately disconnects the client, at which point it will begin attemption to re-establish a connection to the broker.
pub fn get_id(&self) -> Option<&Uuid>
[src]
Obtain the Uuid
assigned by the broker to this client
If the client is not connected, None
will be returned.
pub fn is_connected(&self) -> bool
[src]
Is the client connected?
pub fn publish<'a, 'b: 'a, C: ClientIo>(
&'b self,
cio: &mut C,
path: &'a str,
payload: &'a [u8]
) -> Result<(), Error>
[src]
&'b self,
cio: &mut C,
path: &'a str,
payload: &'a [u8]
) -> Result<(), Error>
Publish a message
This interface publishes a message from the client to the broker.
Parameters
cio
This is the ClientIo
instance used by the client
path
This is the path to publish to. This is typically created by using
the Table::serialize()
method, which returns a path and the serialized
payload
payload
The serialized payload to publish. This is typically created by using
the Table::serialize()
method, which returns a path and the serialized
payload
pub fn process_one<C: ClientIo, T: Table>(
&mut self,
cio: &mut C
) -> Result<Option<RecvMsg<T>>, Error>
[src]
&mut self,
cio: &mut C
) -> Result<Option<RecvMsg<T>>, Error>
Process a single incoming message
This function must be called regularly to process messages
that have been received by the broker. It is suggested to call
it at regular intervals if you are using the timeout_ticks
option
when creating the Client.
If a subscription message has been received, it will be returned with the path that was published to. If the Client has subscribed using a wildcard, it may not exactly match the subscription topic
The anachro-icd::matches
function can be used to compare if a topic
matches a given fixed or wildcard path, if necessary.
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,