pub struct Replier<TReq, TRep>where
TReq: RequestReply,
TRep: RequestReply,{ /* private fields */ }Expand description
A DDS Replier that receives requests and sends replies.
Creates two topics internally:
{service_name}Request— for subscribing to requests{service_name}Reply— for publishing replies
§Example
use cyclonedds::*;
use std::time::Duration;
#[derive(DdsTypeDerive, Clone)]
struct AddRequest { correlation_id: u64, a: i32, b: i32 }
#[derive(DdsTypeDerive, Clone)]
struct AddReply { correlation_id: u64, result: i32 }
impl RequestReply for AddRequest {
fn correlation_id(&self) -> u64 { self.correlation_id }
fn set_correlation_id(&mut self, id: u64) { self.correlation_id = id; }
}
impl RequestReply for AddReply {
fn correlation_id(&self) -> u64 { self.correlation_id }
fn set_correlation_id(&mut self, id: u64) { self.correlation_id = id; }
}
let participant = DomainParticipant::new(0).unwrap();
let replier = Replier::<AddRequest, AddReply>::new(
&participant, "CalcService", None, None,
).unwrap();
loop {
if let Some(req) = replier.receive_request(Duration::from_secs(1)).unwrap() {
let reply = AddReply {
correlation_id: req.correlation_id(),
result: req.a + req.b,
};
replier.send_reply(reply).unwrap();
}
}Implementations§
Source§impl<TReq, TRep> Replier<TReq, TRep>where
TReq: RequestReply,
TRep: RequestReply,
impl<TReq, TRep> Replier<TReq, TRep>where
TReq: RequestReply,
TRep: RequestReply,
pub fn new( participant: &DomainParticipant, service_name: &str, request_qos: Option<&Qos>, reply_qos: Option<&Qos>, ) -> DdsResult<Self>
Sourcepub fn receive_request(&self, timeout: Duration) -> DdsResult<Option<TReq>>
pub fn receive_request(&self, timeout: Duration) -> DdsResult<Option<TReq>>
Block until a request arrives or timeout.
Sourcepub fn send_reply(&self, data: TRep) -> DdsResult<()>
pub fn send_reply(&self, data: TRep) -> DdsResult<()>
Send a reply with the matching correlation_id.
Auto Trait Implementations§
impl<TReq, TRep> Freeze for Replier<TReq, TRep>
impl<TReq, TRep> RefUnwindSafe for Replier<TReq, TRep>where
TRep: RefUnwindSafe,
TReq: RefUnwindSafe,
impl<TReq, TRep> Send for Replier<TReq, TRep>
impl<TReq, TRep> Sync for Replier<TReq, TRep>
impl<TReq, TRep> Unpin for Replier<TReq, TRep>
impl<TReq, TRep> UnsafeUnpin for Replier<TReq, TRep>
impl<TReq, TRep> UnwindSafe for Replier<TReq, TRep>where
TRep: UnwindSafe,
TReq: UnwindSafe,
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request