use crate::{
dcps::{
actor::ActorAddress,
channels::{mpsc::MpscReceiver, oneshot::oneshot},
status_condition::DcpsStatusCondition,
status_condition_mail::DcpsStatusConditionMail,
},
infrastructure::{error::DdsResult, status::StatusKind},
};
use alloc::vec::Vec;
pub struct StatusConditionAsync {
address: ActorAddress<DcpsStatusCondition>,
}
impl Clone for StatusConditionAsync {
fn clone(&self) -> Self {
Self {
address: self.address.clone(),
}
}
}
impl StatusConditionAsync {
pub(crate) fn new(address: ActorAddress<DcpsStatusCondition>) -> Self {
Self { address }
}
pub(crate) async fn register_notification(&self) -> DdsResult<MpscReceiver<()>> {
let (reply_sender, reply_receiver) = oneshot();
self.address
.send_actor_mail(DcpsStatusConditionMail::RegisterNotification { reply_sender })
.await?;
reply_receiver.await
}
}
impl StatusConditionAsync {
#[tracing::instrument(skip(self))]
pub async fn get_enabled_statuses(&self) -> DdsResult<Vec<StatusKind>> {
let (reply_sender, reply_receiver) = oneshot();
self.address
.send_actor_mail(DcpsStatusConditionMail::GetStatusConditionEnabledStatuses {
reply_sender,
})
.await?;
reply_receiver.await
}
#[tracing::instrument(skip(self))]
pub async fn set_enabled_statuses(&self, mask: &[StatusKind]) -> DdsResult<()> {
self.address
.send_actor_mail(DcpsStatusConditionMail::SetStatusConditionEnabledStatuses {
status_mask: mask.to_vec(),
})
.await?;
Ok(())
}
#[tracing::instrument(skip(self))]
pub async fn get_entity(&self) {
todo!()
}
}
impl StatusConditionAsync {
#[tracing::instrument(skip(self))]
pub async fn get_trigger_value(&self) -> DdsResult<bool> {
let (reply_sender, reply_receiver) = oneshot();
self.address
.send_actor_mail(DcpsStatusConditionMail::GetStatusConditionTriggerValue {
reply_sender,
})
.await?;
reply_receiver.await
}
}