tail_core 0.1.1

Core library for the Tail operating system
Documentation
// Copyright 2025, TAIL OS. All Rights Reserved.
//
// You must obtain a written license from and pay applicable license fees to TAIL OS
// before you may reproduce, modify, or distribute this software, or any work that
// includes all or part of this software.
//
// Free development licenses are available for evaluation, research, and non-commercial
// purposes, which may include access to the source code under these terms. Redistribution
// or commercial use without a license is strictly prohibited.
//
// This file may contain contributions from others. Please review this entire file for
// other proprietary rights or license notices, as well as the TAIL OS License Guide at
// https://tail-os.com/license-guide/ for more information.
//
// For licensing inquiries, visit https://tail-os.com or email license@tail-os.com.


use crate::tail::TOPIC_NAME_MAX_LENGTH;
use crate::syscall;
use core::ptr;

/// Represents a subscriber for receiving messages from topics.
///
/// # Deprecated
///
/// This type is obsolete and will be removed in a future version.
/// The topic-based IPC mechanism is being phased out.
#[deprecated(note = "Subscriber is obsolete. Use alternative IPC mechanisms.")]
pub struct Subscriber<T: ?Sized> {
    topic_name: [u8; TOPIC_NAME_MAX_LENGTH],    //TODO: change it to String
    phantom: core::marker::PhantomData<T>,
}

impl<T: ?Sized> Subscriber<T> {
    /// Creates a new subscriber for the given topic name.
    ///
    /// # Deprecated
    ///
    /// This method is obsolete and will be removed in a future version.
    #[deprecated(note = "Subscriber::new is obsolete. Use alternative IPC mechanisms.")]
    pub fn new(topic_name: &str) -> Self
    {
        let mut subscriber = Subscriber {
            topic_name: [0; TOPIC_NAME_MAX_LENGTH],
            phantom: core::marker::PhantomData,
        };
        unsafe { ptr::copy_nonoverlapping(topic_name.as_ptr(), subscriber.topic_name.as_mut_ptr(), topic_name.len()) };

        subscriber
    }

    /// Subscribes to the topic and receives a message.
    ///
    /// # Deprecated
    ///
    /// This method is obsolete and will be removed in a future version.
    #[deprecated(note = "Subscriber::subscribe is obsolete. Use alternative IPC mechanisms.")]
    pub fn subscribe(&self) -> (*const u8, usize)
    {
        syscall::syscall_subscribe_topic(core::str::from_utf8(&self.topic_name).unwrap_or(""))
        // Cast the *const u8 to *const T
        //let message_ptr: *const T = message_ptr as *const T;
        // Ensure the raw pointer is converted to a reference safely

    }
}