Struct rustbus::connection::rpc_conn::RpcConn
source · pub struct RpcConn { /* private fields */ }
Expand description
Convenience wrapper around the lowlevel connection
use rustbus::{connection::{Timeout, ll_conn::force_finish_on_error}, standard_messages, MessageBuilder, MessageType, RpcConn};
// Connect to the session bus. This also takes care of the mandatory hello messages
let mut rpc_con = RpcConn::session_conn(Timeout::Infinite).unwrap();
let mut call = MessageBuilder::new()
.call("evaluateScript")
.with_interface("org.kde.PlasmaShell")
.on("/PlasmaShell")
.at("org.kde.plasmashell")
.build();
let id = rpc_con
.send_message(&mut call)
.expect("Wanna send message :(")
.write_all()
.map_err(force_finish_on_error)
.expect("Wanna send message :(");
let message = rpc_con
.wait_response(id, Timeout::Infinite)
.expect("Get failed");
Implementations§
source§impl RpcConn
impl RpcConn
pub fn new(conn: DuplexConn) -> Self
pub fn conn(&self) -> &DuplexConn
pub fn conn_mut(&mut self) -> &mut DuplexConn
sourcepub fn alloc_serial(&mut self) -> u32
pub fn alloc_serial(&mut self) -> u32
get the next new serial
pub fn session_conn(timeout: Timeout) -> Result<Self, Error>
pub fn system_conn(timeout: Timeout) -> Result<Self, Error>
pub fn connect_to_path(path: UnixAddr, timeout: Timeout) -> Result<Self, Error>
pub fn set_filter(&mut self, filter: MessageFilter)
sourcepub fn try_get_response(&mut self, serial: u32) -> Option<MarshalledMessage>
pub fn try_get_response(&mut self, serial: u32) -> Option<MarshalledMessage>
Return a response if one is there but dont block
sourcepub fn wait_response(
&mut self,
serial: u32,
timeout: Timeout
) -> Result<MarshalledMessage, Error>
pub fn wait_response( &mut self, serial: u32, timeout: Timeout ) -> Result<MarshalledMessage, Error>
Return a response if one is there or block until it arrives
sourcepub fn try_get_signal(&mut self) -> Option<MarshalledMessage>
pub fn try_get_signal(&mut self) -> Option<MarshalledMessage>
Return a signal if one is there but dont block
sourcepub fn wait_signal(
&mut self,
timeout: Timeout
) -> Result<MarshalledMessage, Error>
pub fn wait_signal( &mut self, timeout: Timeout ) -> Result<MarshalledMessage, Error>
Return a sginal if one is there or block until it arrives
sourcepub fn try_get_call(&mut self) -> Option<MarshalledMessage>
pub fn try_get_call(&mut self) -> Option<MarshalledMessage>
Return a call if one is there but dont block
sourcepub fn wait_call(
&mut self,
timeout: Timeout
) -> Result<MarshalledMessage, Error>
pub fn wait_call( &mut self, timeout: Timeout ) -> Result<MarshalledMessage, Error>
Return a call if one is there or block until it arrives
sourcepub fn send_message<'a>(
&'a mut self,
msg: &'a mut MarshalledMessage
) -> Result<SendMessageContext<'a>, Error>
pub fn send_message<'a>( &'a mut self, msg: &'a mut MarshalledMessage ) -> Result<SendMessageContext<'a>, Error>
Send a message to the bus
sourcepub fn try_refill_once(
&mut self,
timeout: Timeout
) -> Result<Option<MessageType>, Error>
pub fn try_refill_once( &mut self, timeout: Timeout ) -> Result<Option<MessageType>, Error>
This processes ONE message. This might be an ignored message. The result will tell you which if any message type was received. The message will be placed into the appropriate queue in the RpcConn.
If a call is received that should be filtered out an error message is sent automatically
sourcepub fn refill_once(&mut self, timeout: Timeout) -> Result<MessageType, Error>
pub fn refill_once(&mut self, timeout: Timeout) -> Result<MessageType, Error>
This blocks until a new message (that should not be ignored) arrives. The message gets placed into the correct list. The Result will tell you which kind of message has been received.
If calls are received that should be filtered out an error message is sent automatically
sourcepub fn refill_all(&mut self) -> Result<Vec<MarshalledMessage>, Error>
pub fn refill_all(&mut self) -> Result<Vec<MarshalledMessage>, Error>
This will drain all outstanding IO on the socket, this will never block. If there is a partially received message pending it will be collected by the next call to any of the io-performing functions. For the callers convenience the Error::Timedout resulting of the EAGAIN/EWOULDBLOCK errors are converted to Ok(()) before returning, since these are expected to happen to normally exit this function.
This will not send automatic error messages for calls to unknown methods because it does never block, but error replies should always be sent. For this reason replies to all filtered calls are collected and returned. The original messages are dropped immediatly, so it should keep memory usage relatively low. The caller is responsible to send these error replies over the RpcConn, at a convenient time.