use crate::ei::EiContext;
use crate::ei::ei_client::EiClient;
use crate::ei::ei_client::EiClientError;
use crate::utils::buffd::EiMsgParser;
use crate::wire_ei::EiHandshakeId;
use jay_proc::jay_hash;
use std::cmp::Ordering;
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::LowerHex;
use std::rc::Rc;
pub const EI_HANDSHAKE_ID: EiHandshakeId = EiHandshakeId::from_raw(0);
#[jay_hash]
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq)]
pub struct EiObjectId(u64);
impl EiObjectId {
#[expect(unused)]
pub const NONE: Self = EiObjectId(0);
pub fn from_raw(raw: u64) -> Self {
Self(raw)
}
pub fn raw(self) -> u64 {
self.0
}
}
impl Display for EiObjectId {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Display::fmt(&self.0, f)
}
}
impl LowerHex for EiObjectId {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
LowerHex::fmt(&self.0, f)
}
}
pub trait EiObjectBase {
fn id(&self) -> EiObjectId;
fn version(&self) -> EiVersion;
fn client(&self) -> &EiClient;
fn handle_request(
self: Rc<Self>,
client: &EiClient,
request: u32,
parser: EiMsgParser<'_, '_>,
) -> Result<(), EiClientError>;
fn interface(&self) -> EiInterface;
}
pub trait EiObject: EiObjectBase + 'static {
fn break_loops(&self) {}
fn context(&self) -> EiContext {
self.client().context.get()
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct EiInterface(pub &'static str);
impl EiInterface {
pub fn name(self) -> &'static str {
self.0
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub struct EiVersion(pub u32);
impl EiVersion {
}
impl PartialEq<u32> for EiVersion {
fn eq(&self, other: &u32) -> bool {
self.0 == *other
}
}
impl PartialOrd<u32> for EiVersion {
fn partial_cmp(&self, other: &u32) -> Option<Ordering> {
self.0.partial_cmp(other)
}
}