pub struct WshRpc {
input_ch: Sender<Vec<u8>>,
output_ch: Sender<Vec<u8>>,
rpc_context: Arc<Mutex<Option<RpcContext>>>,
auth_token: Arc<Mutex<String>>,
rpc_map: Arc<Mutex<HashMap<String, RpcData>>>,
event_listener: Arc<EventListener>,
debug: AtomicBool,
debug_name: String,
server_done: AtomicBool,
}Expand description
Main WshRpc client.
Provides bidirectional RPC over message channels:
- Send requests and wait for responses
- Handle incoming requests with registered handlers
- Support streaming responses
- Auth token management
Fields§
§input_ch: Sender<Vec<u8>>§output_ch: Sender<Vec<u8>>§rpc_context: Arc<Mutex<Option<RpcContext>>>§auth_token: Arc<Mutex<String>>§rpc_map: Arc<Mutex<HashMap<String, RpcData>>>§event_listener: Arc<EventListener>§debug: AtomicBool§debug_name: String§server_done: AtomicBoolImplementations§
Source§impl WshRpc
impl WshRpc
Sourcepub fn new(debug_name: &str) -> (Self, Receiver<Vec<u8>>, Sender<Vec<u8>>)
pub fn new(debug_name: &str) -> (Self, Receiver<Vec<u8>>, Sender<Vec<u8>>)
Create a new WshRpc client with input/output channels.
Sourcepub fn set_rpc_context(&self, ctx: RpcContext)
pub fn set_rpc_context(&self, ctx: RpcContext)
Set the RPC context.
Sourcepub fn get_rpc_context(&self) -> Option<RpcContext>
pub fn get_rpc_context(&self) -> Option<RpcContext>
Get the current RPC context.
Sourcepub fn set_auth_token(&self, token: &str)
pub fn set_auth_token(&self, token: &str)
Set the auth token.
Sourcepub fn get_auth_token(&self) -> String
pub fn get_auth_token(&self) -> String
Get the auth token.
Sourcepub fn get_event_listener(&self) -> &EventListener
pub fn get_event_listener(&self) -> &EventListener
Get the event listener.
Sourcepub async fn send_rpc_request(
&self,
command: &str,
data: Option<Value>,
timeout_ms: Option<u64>,
) -> Result<Option<Value>, String>
pub async fn send_rpc_request( &self, command: &str, data: Option<Value>, timeout_ms: Option<u64>, ) -> Result<Option<Value>, String>
Send an RPC request and wait for a single response.
Sourcepub async fn send_message(
&self,
command: &str,
data: Option<Value>,
) -> Result<(), String>
pub async fn send_message( &self, command: &str, data: Option<Value>, ) -> Result<(), String>
Send a fire-and-forget message (no response expected).
Sourcepub fn process_incoming_message(&self, raw_msg: &[u8]) -> Result<(), String>
pub fn process_incoming_message(&self, raw_msg: &[u8]) -> Result<(), String>
Process an incoming message (response or request).
Sourcefn handle_response(&self, msg: RpcMessage) -> Result<(), String>
fn handle_response(&self, msg: RpcMessage) -> Result<(), String>
Handle an incoming response message.
Sourcepub fn is_server_done(&self) -> bool
pub fn is_server_done(&self) -> bool
Check if the server is done.
Sourcepub fn set_server_done(&self)
pub fn set_server_done(&self)
Mark the server as done.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Get the count of pending RPC requests.
Auto Trait Implementations§
impl !Freeze for WshRpc
impl RefUnwindSafe for WshRpc
impl Send for WshRpc
impl Sync for WshRpc
impl Unpin for WshRpc
impl UnwindSafe for WshRpc
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.