use { crate::{ ei::{ EiContext, ei_client::{EiClient, EiClientError}, }, utils::buffd::EiMsgParser, wire_ei::EiHandshakeId, }, std::{ cmp::Ordering, rc::Rc, }, }; pub use jay_wire_types::EiObjectId; pub const EI_HANDSHAKE_ID: EiHandshakeId = EiHandshakeId::from_raw(0); pub trait EiObjectBase { fn id(&self) -> EiObjectId; fn version(&self) -> EiVersion; fn client(&self) -> &EiClient; fn handle_request( self: Rc, 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 { // pub const ALL: EiVersion = EiVersion(0); } impl PartialEq for EiVersion { fn eq(&self, other: &u32) -> bool { self.0 == *other } } impl PartialOrd for EiVersion { fn partial_cmp(&self, other: &u32) -> Option { self.0.partial_cmp(other) } }