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::syscall;
use crate::service::service_request::ServiceRequestData;
use crate::service::service_reply::ServiceReplyData;
use crate::error_kind::ErrorKind;

pub fn create_server(server_name: &str) {
    syscall::syscall_create_server(server_name);
}

pub fn receive_service_request<T>(server_name: &str) -> Result<(u64, u64, ServiceRequestData<T>), ErrorKind> {
    match syscall::syscall_receive_service_request(server_name) {
        Ok((request_client_thread_id, request_message_type, request_message_ptr, request_message_size)) => {
            Ok((request_client_thread_id, request_message_type, ServiceRequestData::new(request_message_ptr as *const T, request_message_size)))
        },
        Err(e) => Err(e.into()),
    }
}


pub fn reply_to_service_request<T>(server_name: &str, request_client_thread_id: u64, reply_data: &ServiceReplyData<T>) -> Result<(), ErrorKind> {
    let reply_message_ptr = reply_data.get_reply_message_ptr();
    let reply_message_size = reply_data.get_reply_message_size();
    let reply_message_error = reply_data.get_reply_message_error().unwrap_or(0);    // 0 is assigned to NONE

    match syscall::syscall_reply_to_service_request(server_name, request_client_thread_id, reply_message_ptr as *const u8, reply_message_size, reply_message_error) {
        Ok(_) => Ok(()),
        Err(_) => Err(ErrorKind::Other.into()),
    }
}