use crate::behavior::reader_locator::ReaderLocator;
use crate::behavior::writer::{Writer, WriterAttributes};
use crate::structure::cache_change::CacheChange;
use crate::structure::change_kind::ChangeKind_t;
use crate::structure::data::Data;
use crate::structure::endpoint::{Endpoint, EndpointAttributes};
use crate::structure::entity::{Entity, EntityAttributes};
use crate::structure::instance_handle::InstanceHandle_t;
use crate::structure::sequence_number::SequenceNumber_t;
use crate::structure::time::Time_t;
struct StatelessWriter {
resend_data_period: Time_t,
reader_locators: Vec<ReaderLocator>,
entity_attributes: EntityAttributes,
endpoint_attributes: EndpointAttributes,
writer_attributes: WriterAttributes,
}
impl Entity for StatelessWriter {
fn as_entity(&self) -> &EntityAttributes {
&self.entity_attributes
}
}
impl Endpoint for StatelessWriter {
fn as_endpoint(&self) -> &EndpointAttributes {
&self.endpoint_attributes
}
}
impl Writer for StatelessWriter {
fn as_writer(&self) -> &WriterAttributes {
&self.writer_attributes
}
fn new_change(
&mut self,
kind: ChangeKind_t,
data: Data,
handle: InstanceHandle_t,
) -> CacheChange {
self.writer_attributes.last_change_sequence_number =
self.writer_attributes.last_change_sequence_number + SequenceNumber_t::from(1);
CacheChange {
kind: kind,
writer_guid: self.entity_attributes.guid,
data_value: data,
instance_handle: handle,
sequence_number: self.writer_attributes.last_change_sequence_number,
}
}
}
impl StatelessWriter {
pub fn new(
entity_attributes: EntityAttributes,
endpoint_attributes: EndpointAttributes,
writer_attributes: WriterAttributes,
resend_data_period: Time_t,
) -> Self {
StatelessWriter {
entity_attributes: entity_attributes,
endpoint_attributes: endpoint_attributes,
writer_attributes: writer_attributes,
resend_data_period: resend_data_period,
reader_locators: vec![],
}
}
pub fn reader_locator_add(&mut self, a_locator: ReaderLocator) {
self.reader_locators.push(a_locator)
}
pub fn reader_locator_remove(&mut self, a_locator: ReaderLocator) {
self.reader_locators.retain(|x| x != &a_locator)
}
pub fn unsent_changes_reset(&mut self) {
unimplemented!();
}
}
#[cfg(test)]
mod tests {}