1#![allow(unused_variables)]
5#![allow(clippy::useless_conversion, clippy::unit_arg)]
6
7use arci::{BaseVelocity, Error, Isometry2, Isometry3, WaitFuture};
8use super::*;
9#[derive(Debug, Clone)]
10pub struct RemoteGamepadSender {
11 pub(crate) client: pb::gamepad_client::GamepadClient<tonic::transport::Channel>,
12}
13impl RemoteGamepadSender {
14 pub async fn connect<D>(dst: D) -> Result<Self, arci::Error>
16 where
17 D: TryInto<tonic::transport::Endpoint>,
18 D::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
19 {
20 let client = pb::gamepad_client::GamepadClient::connect(dst)
21 .await
22 .map_err(|e| arci::Error::Connection {
23 message: e.to_string(),
24 })?;
25 Ok(Self { client })
26 }
27 pub fn new(channel: tonic::transport::Channel) -> Self {
29 Self {
30 client: pb::gamepad_client::GamepadClient::new(channel),
31 }
32 }
33}
34#[derive(Debug)]
35pub struct RemoteGamepadReceiver<T> {
36 pub(crate) inner: T,
37}
38impl<T> RemoteGamepadReceiver<T>
39where
40 T: arci::Gamepad + 'static,
41{
42 pub fn new(inner: T) -> Self {
44 Self { inner }
45 }
46 pub fn into_service(self) -> pb::gamepad_server::GamepadServer<Self> {
48 pb::gamepad_server::GamepadServer::new(self)
49 }
50 pub async fn serve(self, addr: SocketAddr) -> Result<(), arci::Error> {
51 tonic::transport::Server::builder()
52 .add_service(self.into_service())
53 .serve(addr)
54 .await
55 .map_err(|e| arci::Error::Connection {
56 message: e.to_string(),
57 })?;
58 Ok(())
59 }
60}
61#[derive(Debug, Clone)]
62pub struct RemoteJointTrajectoryClientSender {
63 pub(crate) client: pb::joint_trajectory_client_client::JointTrajectoryClientClient<
64 tonic::transport::Channel,
65 >,
66}
67impl RemoteJointTrajectoryClientSender {
68 pub async fn connect<D>(dst: D) -> Result<Self, arci::Error>
70 where
71 D: TryInto<tonic::transport::Endpoint>,
72 D::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
73 {
74 let client = pb::joint_trajectory_client_client::JointTrajectoryClientClient::connect(
75 dst,
76 )
77 .await
78 .map_err(|e| arci::Error::Connection {
79 message: e.to_string(),
80 })?;
81 Ok(Self { client })
82 }
83 pub fn new(channel: tonic::transport::Channel) -> Self {
85 Self {
86 client: pb::joint_trajectory_client_client::JointTrajectoryClientClient::new(
87 channel,
88 ),
89 }
90 }
91}
92#[derive(Debug)]
93pub struct RemoteJointTrajectoryClientReceiver<T> {
94 pub(crate) inner: T,
95}
96impl<T> RemoteJointTrajectoryClientReceiver<T>
97where
98 T: arci::JointTrajectoryClient + 'static,
99{
100 pub fn new(inner: T) -> Self {
102 Self { inner }
103 }
104 pub fn into_service(
106 self,
107 ) -> pb::joint_trajectory_client_server::JointTrajectoryClientServer<Self> {
108 pb::joint_trajectory_client_server::JointTrajectoryClientServer::new(self)
109 }
110 pub async fn serve(self, addr: SocketAddr) -> Result<(), arci::Error> {
111 tonic::transport::Server::builder()
112 .add_service(self.into_service())
113 .serve(addr)
114 .await
115 .map_err(|e| arci::Error::Connection {
116 message: e.to_string(),
117 })?;
118 Ok(())
119 }
120}
121#[derive(Debug, Clone)]
122pub struct RemoteLocalizationSender {
123 pub(crate) client: pb::localization_client::LocalizationClient<
124 tonic::transport::Channel,
125 >,
126}
127impl RemoteLocalizationSender {
128 pub async fn connect<D>(dst: D) -> Result<Self, arci::Error>
130 where
131 D: TryInto<tonic::transport::Endpoint>,
132 D::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
133 {
134 let client = pb::localization_client::LocalizationClient::connect(dst)
135 .await
136 .map_err(|e| arci::Error::Connection {
137 message: e.to_string(),
138 })?;
139 Ok(Self { client })
140 }
141 pub fn new(channel: tonic::transport::Channel) -> Self {
143 Self {
144 client: pb::localization_client::LocalizationClient::new(channel),
145 }
146 }
147}
148#[derive(Debug)]
149pub struct RemoteLocalizationReceiver<T> {
150 pub(crate) inner: T,
151}
152impl<T> RemoteLocalizationReceiver<T>
153where
154 T: arci::Localization + 'static,
155{
156 pub fn new(inner: T) -> Self {
158 Self { inner }
159 }
160 pub fn into_service(self) -> pb::localization_server::LocalizationServer<Self> {
162 pb::localization_server::LocalizationServer::new(self)
163 }
164 pub async fn serve(self, addr: SocketAddr) -> Result<(), arci::Error> {
165 tonic::transport::Server::builder()
166 .add_service(self.into_service())
167 .serve(addr)
168 .await
169 .map_err(|e| arci::Error::Connection {
170 message: e.to_string(),
171 })?;
172 Ok(())
173 }
174}
175impl arci::Localization for RemoteLocalizationSender {
176 fn current_pose(&self, frame_id: &str) -> Result<Isometry2<f64>, Error> {
177 let mut client = self.client.clone();
178 let args = tonic::Request::new(frame_id.into());
179 Ok(
180 block_in_place(client.current_pose(args))
181 .map_err(|e| arci::Error::Other(e.into()))?
182 .into_inner()
183 .into(),
184 )
185 }
186}
187#[tonic::async_trait]
188impl<T> pb::localization_server::Localization for RemoteLocalizationReceiver<T>
189where
190 T: arci::Localization + 'static,
191{
192 async fn current_pose(
193 &self,
194 request: tonic::Request<::prost::alloc::string::String>,
195 ) -> Result<tonic::Response<pb::Isometry2>, tonic::Status> {
196 let request = request.into_inner();
197 let res = arci::Localization::current_pose(&self.inner, &request)
198 .map_err(|e| tonic::Status::unknown(e.to_string()))?
199 .into();
200 Ok(tonic::Response::new(res))
201 }
202}
203#[derive(Debug, Clone)]
204pub struct RemoteMotorDrivePositionSender {
205 pub(crate) client: pb::motor_drive_position_client::MotorDrivePositionClient<
206 tonic::transport::Channel,
207 >,
208}
209impl RemoteMotorDrivePositionSender {
210 pub async fn connect<D>(dst: D) -> Result<Self, arci::Error>
212 where
213 D: TryInto<tonic::transport::Endpoint>,
214 D::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
215 {
216 let client = pb::motor_drive_position_client::MotorDrivePositionClient::connect(
217 dst,
218 )
219 .await
220 .map_err(|e| arci::Error::Connection {
221 message: e.to_string(),
222 })?;
223 Ok(Self { client })
224 }
225 pub fn new(channel: tonic::transport::Channel) -> Self {
227 Self {
228 client: pb::motor_drive_position_client::MotorDrivePositionClient::new(
229 channel,
230 ),
231 }
232 }
233}
234#[derive(Debug)]
235pub struct RemoteMotorDrivePositionReceiver<T> {
236 pub(crate) inner: T,
237}
238impl<T> RemoteMotorDrivePositionReceiver<T>
239where
240 T: arci::MotorDrivePosition + 'static,
241{
242 pub fn new(inner: T) -> Self {
244 Self { inner }
245 }
246 pub fn into_service(
248 self,
249 ) -> pb::motor_drive_position_server::MotorDrivePositionServer<Self> {
250 pb::motor_drive_position_server::MotorDrivePositionServer::new(self)
251 }
252 pub async fn serve(self, addr: SocketAddr) -> Result<(), arci::Error> {
253 tonic::transport::Server::builder()
254 .add_service(self.into_service())
255 .serve(addr)
256 .await
257 .map_err(|e| arci::Error::Connection {
258 message: e.to_string(),
259 })?;
260 Ok(())
261 }
262}
263impl arci::MotorDrivePosition for RemoteMotorDrivePositionSender {
264 fn set_motor_position(&self, position: f64) -> Result<(), Error> {
265 let mut client = self.client.clone();
266 let args = tonic::Request::new(position.into());
267 Ok(
268 block_in_place(client.set_motor_position(args))
269 .map_err(|e| arci::Error::Other(e.into()))?
270 .into_inner()
271 .into(),
272 )
273 }
274 fn get_motor_position(&self) -> Result<f64, Error> {
275 let mut client = self.client.clone();
276 let args = tonic::Request::new(());
277 Ok(
278 block_in_place(client.get_motor_position(args))
279 .map_err(|e| arci::Error::Other(e.into()))?
280 .into_inner()
281 .into(),
282 )
283 }
284}
285#[tonic::async_trait]
286impl<T> pb::motor_drive_position_server::MotorDrivePosition
287for RemoteMotorDrivePositionReceiver<T>
288where
289 T: arci::MotorDrivePosition + 'static,
290{
291 async fn set_motor_position(
292 &self,
293 request: tonic::Request<f64>,
294 ) -> Result<tonic::Response<()>, tonic::Status> {
295 let request = request.into_inner();
296 let res = arci::MotorDrivePosition::set_motor_position(
297 &self.inner,
298 request.into(),
299 )
300 .map_err(|e| tonic::Status::unknown(e.to_string()))?
301 .into();
302 Ok(tonic::Response::new(res))
303 }
304 async fn get_motor_position(
305 &self,
306 request: tonic::Request<()>,
307 ) -> Result<tonic::Response<f64>, tonic::Status> {
308 let request = request.into_inner();
309 let res = arci::MotorDrivePosition::get_motor_position(&self.inner)
310 .map_err(|e| tonic::Status::unknown(e.to_string()))?
311 .into();
312 Ok(tonic::Response::new(res))
313 }
314}
315#[derive(Debug, Clone)]
316pub struct RemoteMotorDriveVelocitySender {
317 pub(crate) client: pb::motor_drive_velocity_client::MotorDriveVelocityClient<
318 tonic::transport::Channel,
319 >,
320}
321impl RemoteMotorDriveVelocitySender {
322 pub async fn connect<D>(dst: D) -> Result<Self, arci::Error>
324 where
325 D: TryInto<tonic::transport::Endpoint>,
326 D::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
327 {
328 let client = pb::motor_drive_velocity_client::MotorDriveVelocityClient::connect(
329 dst,
330 )
331 .await
332 .map_err(|e| arci::Error::Connection {
333 message: e.to_string(),
334 })?;
335 Ok(Self { client })
336 }
337 pub fn new(channel: tonic::transport::Channel) -> Self {
339 Self {
340 client: pb::motor_drive_velocity_client::MotorDriveVelocityClient::new(
341 channel,
342 ),
343 }
344 }
345}
346#[derive(Debug)]
347pub struct RemoteMotorDriveVelocityReceiver<T> {
348 pub(crate) inner: T,
349}
350impl<T> RemoteMotorDriveVelocityReceiver<T>
351where
352 T: arci::MotorDriveVelocity + 'static,
353{
354 pub fn new(inner: T) -> Self {
356 Self { inner }
357 }
358 pub fn into_service(
360 self,
361 ) -> pb::motor_drive_velocity_server::MotorDriveVelocityServer<Self> {
362 pb::motor_drive_velocity_server::MotorDriveVelocityServer::new(self)
363 }
364 pub async fn serve(self, addr: SocketAddr) -> Result<(), arci::Error> {
365 tonic::transport::Server::builder()
366 .add_service(self.into_service())
367 .serve(addr)
368 .await
369 .map_err(|e| arci::Error::Connection {
370 message: e.to_string(),
371 })?;
372 Ok(())
373 }
374}
375impl arci::MotorDriveVelocity for RemoteMotorDriveVelocitySender {
376 fn set_motor_velocity(&self, velocity: f64) -> Result<(), Error> {
377 let mut client = self.client.clone();
378 let args = tonic::Request::new(velocity.into());
379 Ok(
380 block_in_place(client.set_motor_velocity(args))
381 .map_err(|e| arci::Error::Other(e.into()))?
382 .into_inner()
383 .into(),
384 )
385 }
386 fn get_motor_velocity(&self) -> Result<f64, Error> {
387 let mut client = self.client.clone();
388 let args = tonic::Request::new(());
389 Ok(
390 block_in_place(client.get_motor_velocity(args))
391 .map_err(|e| arci::Error::Other(e.into()))?
392 .into_inner()
393 .into(),
394 )
395 }
396}
397#[tonic::async_trait]
398impl<T> pb::motor_drive_velocity_server::MotorDriveVelocity
399for RemoteMotorDriveVelocityReceiver<T>
400where
401 T: arci::MotorDriveVelocity + 'static,
402{
403 async fn set_motor_velocity(
404 &self,
405 request: tonic::Request<f64>,
406 ) -> Result<tonic::Response<()>, tonic::Status> {
407 let request = request.into_inner();
408 let res = arci::MotorDriveVelocity::set_motor_velocity(
409 &self.inner,
410 request.into(),
411 )
412 .map_err(|e| tonic::Status::unknown(e.to_string()))?
413 .into();
414 Ok(tonic::Response::new(res))
415 }
416 async fn get_motor_velocity(
417 &self,
418 request: tonic::Request<()>,
419 ) -> Result<tonic::Response<f64>, tonic::Status> {
420 let request = request.into_inner();
421 let res = arci::MotorDriveVelocity::get_motor_velocity(&self.inner)
422 .map_err(|e| tonic::Status::unknown(e.to_string()))?
423 .into();
424 Ok(tonic::Response::new(res))
425 }
426}
427#[derive(Debug, Clone)]
428pub struct RemoteMotorDriveEffortSender {
429 pub(crate) client: pb::motor_drive_effort_client::MotorDriveEffortClient<
430 tonic::transport::Channel,
431 >,
432}
433impl RemoteMotorDriveEffortSender {
434 pub async fn connect<D>(dst: D) -> Result<Self, arci::Error>
436 where
437 D: TryInto<tonic::transport::Endpoint>,
438 D::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
439 {
440 let client = pb::motor_drive_effort_client::MotorDriveEffortClient::connect(dst)
441 .await
442 .map_err(|e| arci::Error::Connection {
443 message: e.to_string(),
444 })?;
445 Ok(Self { client })
446 }
447 pub fn new(channel: tonic::transport::Channel) -> Self {
449 Self {
450 client: pb::motor_drive_effort_client::MotorDriveEffortClient::new(channel),
451 }
452 }
453}
454#[derive(Debug)]
455pub struct RemoteMotorDriveEffortReceiver<T> {
456 pub(crate) inner: T,
457}
458impl<T> RemoteMotorDriveEffortReceiver<T>
459where
460 T: arci::MotorDriveEffort + 'static,
461{
462 pub fn new(inner: T) -> Self {
464 Self { inner }
465 }
466 pub fn into_service(
468 self,
469 ) -> pb::motor_drive_effort_server::MotorDriveEffortServer<Self> {
470 pb::motor_drive_effort_server::MotorDriveEffortServer::new(self)
471 }
472 pub async fn serve(self, addr: SocketAddr) -> Result<(), arci::Error> {
473 tonic::transport::Server::builder()
474 .add_service(self.into_service())
475 .serve(addr)
476 .await
477 .map_err(|e| arci::Error::Connection {
478 message: e.to_string(),
479 })?;
480 Ok(())
481 }
482}
483impl arci::MotorDriveEffort for RemoteMotorDriveEffortSender {
484 fn set_motor_effort(&self, effort: f64) -> Result<(), Error> {
485 let mut client = self.client.clone();
486 let args = tonic::Request::new(effort.into());
487 Ok(
488 block_in_place(client.set_motor_effort(args))
489 .map_err(|e| arci::Error::Other(e.into()))?
490 .into_inner()
491 .into(),
492 )
493 }
494 fn get_motor_effort(&self) -> Result<f64, Error> {
495 let mut client = self.client.clone();
496 let args = tonic::Request::new(());
497 Ok(
498 block_in_place(client.get_motor_effort(args))
499 .map_err(|e| arci::Error::Other(e.into()))?
500 .into_inner()
501 .into(),
502 )
503 }
504}
505#[tonic::async_trait]
506impl<T> pb::motor_drive_effort_server::MotorDriveEffort
507for RemoteMotorDriveEffortReceiver<T>
508where
509 T: arci::MotorDriveEffort + 'static,
510{
511 async fn set_motor_effort(
512 &self,
513 request: tonic::Request<f64>,
514 ) -> Result<tonic::Response<()>, tonic::Status> {
515 let request = request.into_inner();
516 let res = arci::MotorDriveEffort::set_motor_effort(&self.inner, request.into())
517 .map_err(|e| tonic::Status::unknown(e.to_string()))?
518 .into();
519 Ok(tonic::Response::new(res))
520 }
521 async fn get_motor_effort(
522 &self,
523 request: tonic::Request<()>,
524 ) -> Result<tonic::Response<f64>, tonic::Status> {
525 let request = request.into_inner();
526 let res = arci::MotorDriveEffort::get_motor_effort(&self.inner)
527 .map_err(|e| tonic::Status::unknown(e.to_string()))?
528 .into();
529 Ok(tonic::Response::new(res))
530 }
531}
532#[derive(Debug, Clone)]
533pub struct RemoteMoveBaseSender {
534 pub(crate) client: pb::move_base_client::MoveBaseClient<tonic::transport::Channel>,
535}
536impl RemoteMoveBaseSender {
537 pub async fn connect<D>(dst: D) -> Result<Self, arci::Error>
539 where
540 D: TryInto<tonic::transport::Endpoint>,
541 D::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
542 {
543 let client = pb::move_base_client::MoveBaseClient::connect(dst)
544 .await
545 .map_err(|e| arci::Error::Connection {
546 message: e.to_string(),
547 })?;
548 Ok(Self { client })
549 }
550 pub fn new(channel: tonic::transport::Channel) -> Self {
552 Self {
553 client: pb::move_base_client::MoveBaseClient::new(channel),
554 }
555 }
556}
557#[derive(Debug)]
558pub struct RemoteMoveBaseReceiver<T> {
559 pub(crate) inner: T,
560}
561impl<T> RemoteMoveBaseReceiver<T>
562where
563 T: arci::MoveBase + 'static,
564{
565 pub fn new(inner: T) -> Self {
567 Self { inner }
568 }
569 pub fn into_service(self) -> pb::move_base_server::MoveBaseServer<Self> {
571 pb::move_base_server::MoveBaseServer::new(self)
572 }
573 pub async fn serve(self, addr: SocketAddr) -> Result<(), arci::Error> {
574 tonic::transport::Server::builder()
575 .add_service(self.into_service())
576 .serve(addr)
577 .await
578 .map_err(|e| arci::Error::Connection {
579 message: e.to_string(),
580 })?;
581 Ok(())
582 }
583}
584impl arci::MoveBase for RemoteMoveBaseSender {
585 fn send_velocity(&self, velocity: &BaseVelocity) -> Result<(), Error> {
586 let mut client = self.client.clone();
587 let args = tonic::Request::new((*velocity).into());
588 Ok(
589 block_in_place(client.send_velocity(args))
590 .map_err(|e| arci::Error::Other(e.into()))?
591 .into_inner()
592 .into(),
593 )
594 }
595 fn current_velocity(&self) -> Result<BaseVelocity, Error> {
596 let mut client = self.client.clone();
597 let args = tonic::Request::new(());
598 Ok(
599 block_in_place(client.current_velocity(args))
600 .map_err(|e| arci::Error::Other(e.into()))?
601 .into_inner()
602 .into(),
603 )
604 }
605}
606#[tonic::async_trait]
607impl<T> pb::move_base_server::MoveBase for RemoteMoveBaseReceiver<T>
608where
609 T: arci::MoveBase + 'static,
610{
611 async fn send_velocity(
612 &self,
613 request: tonic::Request<pb::BaseVelocity>,
614 ) -> Result<tonic::Response<()>, tonic::Status> {
615 let request = request.into_inner();
616 let res = arci::MoveBase::send_velocity(&self.inner, &request.into())
617 .map_err(|e| tonic::Status::unknown(e.to_string()))?
618 .into();
619 Ok(tonic::Response::new(res))
620 }
621 async fn current_velocity(
622 &self,
623 request: tonic::Request<()>,
624 ) -> Result<tonic::Response<pb::BaseVelocity>, tonic::Status> {
625 let request = request.into_inner();
626 let res = arci::MoveBase::current_velocity(&self.inner)
627 .map_err(|e| tonic::Status::unknown(e.to_string()))?
628 .into();
629 Ok(tonic::Response::new(res))
630 }
631}
632#[derive(Debug, Clone)]
633pub struct RemoteNavigationSender {
634 pub(crate) client: pb::navigation_client::NavigationClient<
635 tonic::transport::Channel,
636 >,
637}
638impl RemoteNavigationSender {
639 pub async fn connect<D>(dst: D) -> Result<Self, arci::Error>
641 where
642 D: TryInto<tonic::transport::Endpoint>,
643 D::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
644 {
645 let client = pb::navigation_client::NavigationClient::connect(dst)
646 .await
647 .map_err(|e| arci::Error::Connection {
648 message: e.to_string(),
649 })?;
650 Ok(Self { client })
651 }
652 pub fn new(channel: tonic::transport::Channel) -> Self {
654 Self {
655 client: pb::navigation_client::NavigationClient::new(channel),
656 }
657 }
658}
659#[derive(Debug)]
660pub struct RemoteNavigationReceiver<T> {
661 pub(crate) inner: T,
662}
663impl<T> RemoteNavigationReceiver<T>
664where
665 T: arci::Navigation + 'static,
666{
667 pub fn new(inner: T) -> Self {
669 Self { inner }
670 }
671 pub fn into_service(self) -> pb::navigation_server::NavigationServer<Self> {
673 pb::navigation_server::NavigationServer::new(self)
674 }
675 pub async fn serve(self, addr: SocketAddr) -> Result<(), arci::Error> {
676 tonic::transport::Server::builder()
677 .add_service(self.into_service())
678 .serve(addr)
679 .await
680 .map_err(|e| arci::Error::Connection {
681 message: e.to_string(),
682 })?;
683 Ok(())
684 }
685}
686impl arci::Navigation for RemoteNavigationSender {
687 fn send_goal_pose(
688 &self,
689 goal: Isometry2<f64>,
690 frame_id: &str,
691 timeout: std::time::Duration,
692 ) -> Result<WaitFuture, Error> {
693 let mut client = self.client.clone();
694 let args = tonic::Request::new((goal, frame_id, timeout).into());
695 Ok(
696 wait_from_handle(
697 tokio::spawn(async move { client.send_goal_pose(args).await }),
698 ),
699 )
700 }
701 fn cancel(&self) -> Result<(), Error> {
702 let mut client = self.client.clone();
703 let args = tonic::Request::new(());
704 Ok(
705 block_in_place(client.cancel(args))
706 .map_err(|e| arci::Error::Other(e.into()))?
707 .into_inner()
708 .into(),
709 )
710 }
711}
712#[tonic::async_trait]
713impl<T> pb::navigation_server::Navigation for RemoteNavigationReceiver<T>
714where
715 T: arci::Navigation + 'static,
716{
717 async fn send_goal_pose(
718 &self,
719 request: tonic::Request<pb::GoalPoseRequest>,
720 ) -> Result<tonic::Response<()>, tonic::Status> {
721 let request = request.into_inner();
722 let res = arci::Navigation::send_goal_pose(
723 &self.inner,
724 request.goal.unwrap().into(),
725 &request.frame_id,
726 request.timeout.unwrap().try_into().unwrap(),
727 )
728 .map_err(|e| tonic::Status::unknown(e.to_string()))?
729 .await
730 .map_err(|e| tonic::Status::unknown(e.to_string()))?
731 .into();
732 Ok(tonic::Response::new(res))
733 }
734 async fn cancel(
735 &self,
736 request: tonic::Request<()>,
737 ) -> Result<tonic::Response<()>, tonic::Status> {
738 let request = request.into_inner();
739 let res = arci::Navigation::cancel(&self.inner)
740 .map_err(|e| tonic::Status::unknown(e.to_string()))?
741 .into();
742 Ok(tonic::Response::new(res))
743 }
744}
745#[derive(Debug, Clone)]
746pub struct RemoteSpeakerSender {
747 pub(crate) client: pb::speaker_client::SpeakerClient<tonic::transport::Channel>,
748}
749impl RemoteSpeakerSender {
750 pub async fn connect<D>(dst: D) -> Result<Self, arci::Error>
752 where
753 D: TryInto<tonic::transport::Endpoint>,
754 D::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
755 {
756 let client = pb::speaker_client::SpeakerClient::connect(dst)
757 .await
758 .map_err(|e| arci::Error::Connection {
759 message: e.to_string(),
760 })?;
761 Ok(Self { client })
762 }
763 pub fn new(channel: tonic::transport::Channel) -> Self {
765 Self {
766 client: pb::speaker_client::SpeakerClient::new(channel),
767 }
768 }
769}
770#[derive(Debug)]
771pub struct RemoteSpeakerReceiver<T> {
772 pub(crate) inner: T,
773}
774impl<T> RemoteSpeakerReceiver<T>
775where
776 T: arci::Speaker + 'static,
777{
778 pub fn new(inner: T) -> Self {
780 Self { inner }
781 }
782 pub fn into_service(self) -> pb::speaker_server::SpeakerServer<Self> {
784 pb::speaker_server::SpeakerServer::new(self)
785 }
786 pub async fn serve(self, addr: SocketAddr) -> Result<(), arci::Error> {
787 tonic::transport::Server::builder()
788 .add_service(self.into_service())
789 .serve(addr)
790 .await
791 .map_err(|e| arci::Error::Connection {
792 message: e.to_string(),
793 })?;
794 Ok(())
795 }
796}
797impl arci::Speaker for RemoteSpeakerSender {
798 fn speak(&self, message: &str) -> Result<WaitFuture, Error> {
799 let mut client = self.client.clone();
800 let args = tonic::Request::new(message.into());
801 Ok(wait_from_handle(tokio::spawn(async move { client.speak(args).await })))
802 }
803}
804#[tonic::async_trait]
805impl<T> pb::speaker_server::Speaker for RemoteSpeakerReceiver<T>
806where
807 T: arci::Speaker + 'static,
808{
809 async fn speak(
810 &self,
811 request: tonic::Request<::prost::alloc::string::String>,
812 ) -> Result<tonic::Response<()>, tonic::Status> {
813 let request = request.into_inner();
814 let res = arci::Speaker::speak(&self.inner, &request)
815 .map_err(|e| tonic::Status::unknown(e.to_string()))?
816 .await
817 .map_err(|e| tonic::Status::unknown(e.to_string()))?
818 .into();
819 Ok(tonic::Response::new(res))
820 }
821}
822#[derive(Debug, Clone)]
823pub struct RemoteTransformResolverSender {
824 pub(crate) client: pb::transform_resolver_client::TransformResolverClient<
825 tonic::transport::Channel,
826 >,
827}
828impl RemoteTransformResolverSender {
829 pub async fn connect<D>(dst: D) -> Result<Self, arci::Error>
831 where
832 D: TryInto<tonic::transport::Endpoint>,
833 D::Error: Into<Box<dyn std::error::Error + Send + Sync>>,
834 {
835 let client = pb::transform_resolver_client::TransformResolverClient::connect(dst)
836 .await
837 .map_err(|e| arci::Error::Connection {
838 message: e.to_string(),
839 })?;
840 Ok(Self { client })
841 }
842 pub fn new(channel: tonic::transport::Channel) -> Self {
844 Self {
845 client: pb::transform_resolver_client::TransformResolverClient::new(channel),
846 }
847 }
848}
849#[derive(Debug)]
850pub struct RemoteTransformResolverReceiver<T> {
851 pub(crate) inner: T,
852}
853impl<T> RemoteTransformResolverReceiver<T>
854where
855 T: arci::TransformResolver + 'static,
856{
857 pub fn new(inner: T) -> Self {
859 Self { inner }
860 }
861 pub fn into_service(
863 self,
864 ) -> pb::transform_resolver_server::TransformResolverServer<Self> {
865 pb::transform_resolver_server::TransformResolverServer::new(self)
866 }
867 pub async fn serve(self, addr: SocketAddr) -> Result<(), arci::Error> {
868 tonic::transport::Server::builder()
869 .add_service(self.into_service())
870 .serve(addr)
871 .await
872 .map_err(|e| arci::Error::Connection {
873 message: e.to_string(),
874 })?;
875 Ok(())
876 }
877}
878impl arci::TransformResolver for RemoteTransformResolverSender {
879 fn resolve_transformation(
880 &self,
881 from: &str,
882 to: &str,
883 time: std::time::SystemTime,
884 ) -> Result<Isometry3<f64>, Error> {
885 let mut client = self.client.clone();
886 let args = tonic::Request::new((from, to, time).into());
887 Ok(
888 block_in_place(client.resolve_transformation(args))
889 .map_err(|e| arci::Error::Other(e.into()))?
890 .into_inner()
891 .into(),
892 )
893 }
894}
895#[tonic::async_trait]
896impl<T> pb::transform_resolver_server::TransformResolver
897for RemoteTransformResolverReceiver<T>
898where
899 T: arci::TransformResolver + 'static,
900{
901 async fn resolve_transformation(
902 &self,
903 request: tonic::Request<pb::ResolveTransformationRequest>,
904 ) -> Result<tonic::Response<pb::Isometry3>, tonic::Status> {
905 let request = request.into_inner();
906 let res = arci::TransformResolver::resolve_transformation(
907 &self.inner,
908 &request.from,
909 &request.to,
910 request.time.unwrap().try_into().unwrap(),
911 )
912 .map_err(|e| tonic::Status::unknown(e.to_string()))?
913 .into();
914 Ok(tonic::Response::new(res))
915 }
916}