Struct IpcClient

Source
pub struct IpcClient<Crypto, Com, Ses>
where Crypto: CryptoProvider<Com, Ses>, Com: CommunicationBackend, Ses: SessionRepository<Crypto::Session>,
{ crypto: Crypto, communication: Com, sessions: Ses, handlers: RpcHandlerRegistry, incoming: RwLock<Option<Receiver<IncomingMessage>>>, cancellation_token: RwLock<Option<CancellationToken>>, }
Expand description

An IPC client that handles communication between different components and clients. It uses a crypto provider to encrypt and decrypt messages, a communication backend to send and receive messages, and a session repository to persist sessions.

Fields§

§crypto: Crypto§communication: Com§sessions: Ses§handlers: RpcHandlerRegistry§incoming: RwLock<Option<Receiver<IncomingMessage>>>§cancellation_token: RwLock<Option<CancellationToken>>

Implementations§

Source§

impl<Crypto, Com, Ses> IpcClient<Crypto, Com, Ses>
where Crypto: CryptoProvider<Com, Ses>, Com: CommunicationBackend, Ses: SessionRepository<Crypto::Session>,

Source

pub fn new(crypto: Crypto, communication: Com, sessions: Ses) -> Arc<Self>

Create a new IPC client with the provided crypto provider, communication backend, and session repository.

Source

pub async fn start(self: &Arc<Self>)

Start the IPC client, which will begin listening for incoming messages and processing them. This will be done in a separate task, allowing the client to receive messages asynchronously. The client will stop automatically if an error occurs during message processing or if the cancellation token is triggered.

Note: The client can and will send messages in the background while it is running, even if no active subscriptions are present.

Source

pub async fn is_running(self: &Arc<Self>) -> bool

Check if the IPC client task is currently running.

Source

pub async fn stop(self: &Arc<Self>)

Stop the IPC client task. This will stop listening for incoming messages.

Source

pub async fn register_rpc_handler<H>(self: &Arc<Self>, handler: H)
where H: RpcHandler + Send + Sync + 'static,

Register a new RPC handler for processing incoming RPC requests. The handler will be executed by the IPC client when an RPC request is received and the response will be sent back over IPC.

Source

pub async fn send( self: &Arc<Self>, message: OutgoingMessage, ) -> Result<(), Crypto::SendError>

Send a message

Source

pub async fn subscribe( self: &Arc<Self>, topic: Option<String>, ) -> Result<IpcClientSubscription, SubscribeError>

Create a subscription to receive messages, optionally filtered by topic. Setting the topic to None will receive all messages.

Source

pub async fn subscribe_typed<Payload>( self: &Arc<Self>, ) -> Result<IpcClientTypedSubscription<Payload>, SubscribeError>

Create a subscription to receive messages that can be deserialized into the provided payload type.

Source

pub async fn request<Request>( self: &Arc<Self>, request: Request, destination: Endpoint, cancellation_token: Option<CancellationToken>, ) -> Result<Request::Response, RequestError>
where Request: RpcRequest,

Send a request to the specified destination and wait for a response. The destination must have a registered RPC handler for the request type, otherwise an error will be returned by the remote endpoint.

Source

fn handle_rpc_request(self: &Arc<Self>, incoming_message: IncomingMessage)

Auto Trait Implementations§

§

impl<Crypto, Com, Ses> !Freeze for IpcClient<Crypto, Com, Ses>

§

impl<Crypto, Com, Ses> !RefUnwindSafe for IpcClient<Crypto, Com, Ses>

§

impl<Crypto, Com, Ses> Send for IpcClient<Crypto, Com, Ses>

§

impl<Crypto, Com, Ses> Sync for IpcClient<Crypto, Com, Ses>

§

impl<Crypto, Com, Ses> Unpin for IpcClient<Crypto, Com, Ses>
where Crypto: Unpin, Com: Unpin, Ses: Unpin,

§

impl<Crypto, Com, Ses> !UnwindSafe for IpcClient<Crypto, Com, Ses>

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.