use crate::syscall;
use crate::tail::TOPIC_NAME_MAX_LENGTH;
#[deprecated(note = "Publisher is obsolete. Use alternative IPC mechanisms.")]
pub struct Publisher<T: ?Sized> {
topic_name: [u8; TOPIC_NAME_MAX_LENGTH],
topic_name_len: usize,
phantom: core::marker::PhantomData<T>,
}
impl<T: ?Sized> Publisher<T> {
#[deprecated(note = "Publisher::new is obsolete. Use alternative IPC mechanisms.")]
pub fn new(topic_name: &str) -> Publisher<T> {
if topic_name.len() > TOPIC_NAME_MAX_LENGTH {
panic!("Topic name length {} exceeds maximum length {}", topic_name.len(), TOPIC_NAME_MAX_LENGTH);
}
let mut publisher = Publisher {
topic_name: [0; TOPIC_NAME_MAX_LENGTH],
topic_name_len: topic_name.len(),
phantom: core::marker::PhantomData,
};
publisher.topic_name[..topic_name.len()].copy_from_slice(topic_name.as_bytes());
syscall::syscall_create_topic_old::<T>(topic_name);
publisher
}
pub fn topic_name(&self) -> &str {
core::str::from_utf8(&self.topic_name[..self.topic_name_len])
.expect("Topic name should always be valid UTF-8")
}
#[deprecated(note = "Publisher::publish is obsolete. Use alternative IPC mechanisms.")]
pub fn publish(&self, message: &T, message_size: usize) {
syscall::syscall_publish_to_topic(self.topic_name(), message, message_size);
}
}
impl<T> Publisher<T> {
#[deprecated(note = "Publisher::publish_sized is obsolete. Use alternative IPC mechanisms.")]
pub fn publish_sized(&self, message: &T) {
let message_size = core::mem::size_of::<T>();
syscall::syscall_publish_to_topic(self.topic_name(), message, message_size);
}
}