wire: move message buffers into workspace crates
This commit is contained in:
parent
d8380b3dce
commit
a1e4641e82
18 changed files with 187 additions and 166 deletions
21
Cargo.lock
generated
21
Cargo.lock
generated
|
|
@ -707,6 +707,8 @@ dependencies = [
|
|||
"jay-tracy",
|
||||
"jay-units",
|
||||
"jay-utils",
|
||||
"jay-wire-buf",
|
||||
"jay-wire-types",
|
||||
"jay-xcon",
|
||||
"kbvm",
|
||||
"libloading",
|
||||
|
|
@ -884,6 +886,25 @@ dependencies = [
|
|||
"uapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jay-wire-buf"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bstr",
|
||||
"jay-io-uring",
|
||||
"jay-time",
|
||||
"jay-units",
|
||||
"jay-utils",
|
||||
"jay-wire-types",
|
||||
"smallvec",
|
||||
"thiserror",
|
||||
"uapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jay-wire-types"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "jay-xcon"
|
||||
version = "0.1.0"
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ members = [
|
|||
"bufio",
|
||||
"dbus-core",
|
||||
"xcon",
|
||||
"wire-types",
|
||||
"wire-buf",
|
||||
"toml-config",
|
||||
"algorithms",
|
||||
"toml-spec",
|
||||
|
|
@ -65,6 +67,8 @@ jay-io-uring = { version = "0.1.0", path = "io-uring" }
|
|||
jay-bufio = { version = "0.1.0", path = "bufio" }
|
||||
jay-dbus-core = { version = "0.1.0", path = "dbus-core" }
|
||||
jay-xcon = { version = "0.1.0", path = "xcon" }
|
||||
jay-wire-types = { version = "0.1.0", path = "wire-types" }
|
||||
jay-wire-buf = { version = "0.1.0", path = "wire-buf" }
|
||||
|
||||
uapi = "0.2.13"
|
||||
thiserror = "2.0.11"
|
||||
|
|
|
|||
|
|
@ -9,41 +9,13 @@ use {
|
|||
},
|
||||
std::{
|
||||
cmp::Ordering,
|
||||
fmt::{Display, Formatter, LowerHex},
|
||||
rc::Rc,
|
||||
},
|
||||
};
|
||||
pub use jay_wire_types::EiObjectId;
|
||||
|
||||
pub const EI_HANDSHAKE_ID: EiHandshakeId = EiHandshakeId::from_raw(0);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub struct EiObjectId(u64);
|
||||
|
||||
impl EiObjectId {
|
||||
#[expect(dead_code)]
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -85,14 +85,10 @@ use {
|
|||
},
|
||||
arrayvec::ArrayVec,
|
||||
linearize::{Linearize, StaticMap},
|
||||
std::{
|
||||
cell::Cell,
|
||||
error::Error,
|
||||
fmt::{Display, Formatter},
|
||||
rc::Rc,
|
||||
},
|
||||
std::{cell::Cell, error::Error, rc::Rc},
|
||||
thiserror::Error,
|
||||
};
|
||||
pub use jay_wire_types::GlobalName;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum GlobalsError {
|
||||
|
|
@ -112,25 +108,6 @@ pub struct GlobalError {
|
|||
pub error: Box<dyn Error>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub struct GlobalName(u32);
|
||||
|
||||
impl GlobalName {
|
||||
pub fn from_raw(id: u32) -> Self {
|
||||
Self(id)
|
||||
}
|
||||
|
||||
pub fn raw(self) -> u32 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for GlobalName {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
Display::fmt(&self.0, f)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait GlobalBase {
|
||||
fn name(&self) -> GlobalName;
|
||||
fn bind<'a>(
|
||||
|
|
@ -275,7 +252,7 @@ impl Globals {
|
|||
removed: CopyHashMap::new(),
|
||||
outputs: Default::default(),
|
||||
seats: Default::default(),
|
||||
singletons: StaticMap::from_fn(|_| GlobalName(0)),
|
||||
singletons: StaticMap::from_fn(|_| GlobalName::from_raw(0)),
|
||||
exposed: Default::default(),
|
||||
};
|
||||
add_singletons(&mut slf);
|
||||
|
|
@ -293,7 +270,7 @@ impl Globals {
|
|||
if id == 0 {
|
||||
panic!("Global names overflowed");
|
||||
}
|
||||
GlobalName(id)
|
||||
GlobalName::from_raw(id)
|
||||
}
|
||||
|
||||
fn insert_no_broadcast<'a>(&'a self, global: Rc<dyn Global>) {
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ macro_rules! id {
|
|||
#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub struct $name(u32);
|
||||
|
||||
#[expect(dead_code)]
|
||||
#[allow(dead_code)]
|
||||
impl $name {
|
||||
pub const NONE: Self = $name(0);
|
||||
|
||||
|
|
@ -639,7 +639,7 @@ macro_rules! ei_id {
|
|||
#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub struct $name(u64);
|
||||
|
||||
#[expect(dead_code)]
|
||||
#[allow(dead_code)]
|
||||
impl $name {
|
||||
pub const NONE: Self = $name(0);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,35 +7,13 @@ use {
|
|||
std::{
|
||||
any::Any,
|
||||
cmp::Ordering,
|
||||
fmt::{Display, Formatter},
|
||||
rc::Rc,
|
||||
},
|
||||
};
|
||||
pub use jay_wire_types::ObjectId;
|
||||
|
||||
pub const WL_DISPLAY_ID: WlDisplayId = WlDisplayId::from_raw(1);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub struct ObjectId(u32);
|
||||
|
||||
impl ObjectId {
|
||||
#[expect(dead_code)]
|
||||
pub const NONE: Self = ObjectId(0);
|
||||
|
||||
pub fn from_raw(raw: u32) -> Self {
|
||||
Self(raw)
|
||||
}
|
||||
|
||||
pub fn raw(self) -> u32 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for ObjectId {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
Display::fmt(&self.0, f)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ObjectBase: Any {
|
||||
fn id(&self) -> ObjectId;
|
||||
fn version(&self) -> Version;
|
||||
|
|
|
|||
|
|
@ -1,43 +1 @@
|
|||
use {crate::io_uring::IoUringError, thiserror::Error};
|
||||
pub use {
|
||||
buf_in::BufFdIn,
|
||||
buf_out::{BufFdOut, OutBuffer, OutBufferSwapchain},
|
||||
ei_formatter::EiMsgFormatter,
|
||||
ei_parser::{EiMsgParser, EiMsgParserError},
|
||||
formatter::MsgFormatter,
|
||||
parser::{MsgParser, MsgParserError},
|
||||
wl_buf_in::{WlBufFdIn, WlMessage},
|
||||
};
|
||||
|
||||
mod buf_in;
|
||||
mod buf_out;
|
||||
mod ei_formatter;
|
||||
mod ei_parser;
|
||||
mod formatter;
|
||||
mod parser;
|
||||
mod wl_buf_in;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum BufFdError {
|
||||
#[error("An IO error occurred")]
|
||||
Io(#[source] IoUringError),
|
||||
#[error("An io-uring error occurred")]
|
||||
Ring(#[from] IoUringError),
|
||||
#[error("The peer did not send a file descriptor")]
|
||||
NoFd,
|
||||
#[error("The peer sent too many file descriptors")]
|
||||
TooManyFds,
|
||||
#[error("The peer closed the connection")]
|
||||
Closed,
|
||||
#[error("The connection timed out")]
|
||||
Timeout,
|
||||
#[error("Message size is not a multiple of 4")]
|
||||
UnalignedMessageSize,
|
||||
#[error("Message size is larger than 4096")]
|
||||
MessageTooLarge,
|
||||
#[error("Message size is smaller than 8")]
|
||||
MessageTooSmall,
|
||||
}
|
||||
|
||||
const BUF_SIZE: usize = 4096;
|
||||
const MAX_IN_FD: usize = 32;
|
||||
pub use jay_wire_buf::*;
|
||||
|
|
|
|||
17
wire-buf/Cargo.toml
Normal file
17
wire-buf/Cargo.toml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
[package]
|
||||
name = "jay-wire-buf"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
license = "GPL-3.0-only"
|
||||
|
||||
[dependencies]
|
||||
jay-io-uring = { version = "0.1.0", path = "../io-uring" }
|
||||
jay-time = { version = "0.1.0", path = "../time" }
|
||||
jay-units = { version = "0.1.0", path = "../units" }
|
||||
jay-utils = { version = "0.1.0", path = "../utils" }
|
||||
jay-wire-types = { version = "0.1.0", path = "../wire-types" }
|
||||
|
||||
bstr = { version = "1.9.0", default-features = false, features = ["std"] }
|
||||
smallvec = { version = "1.11.1", features = ["const_generics", "const_new", "union"] }
|
||||
thiserror = "2.0.11"
|
||||
uapi = "0.2.13"
|
||||
|
|
@ -1,11 +1,7 @@
|
|||
use {
|
||||
crate::{
|
||||
io_uring::IoUring,
|
||||
utils::{
|
||||
buf::Buf,
|
||||
buffd::{BUF_SIZE, BufFdError, MAX_IN_FD},
|
||||
},
|
||||
},
|
||||
crate::{BUF_SIZE, BufFdError, MAX_IN_FD},
|
||||
jay_io_uring::IoUring,
|
||||
jay_utils::buf::Buf,
|
||||
smallvec::SmallVec,
|
||||
std::{collections::VecDeque, mem::MaybeUninit, rc::Rc},
|
||||
uapi::{OwnedFd, Pod},
|
||||
|
|
@ -1,13 +1,8 @@
|
|||
use {
|
||||
crate::{
|
||||
io_uring::{IoUring, IoUringError},
|
||||
time::Time,
|
||||
utils::{
|
||||
buf::Buf,
|
||||
buffd::{BUF_SIZE, BufFdError},
|
||||
oserror::OsError,
|
||||
},
|
||||
},
|
||||
crate::{BUF_SIZE, BufFdError},
|
||||
jay_io_uring::{IoUring, IoUringError},
|
||||
jay_time::Time,
|
||||
jay_utils::{buf::Buf, oserror::OsError},
|
||||
std::{
|
||||
collections::VecDeque,
|
||||
mem::{self},
|
||||
|
|
@ -1,8 +1,6 @@
|
|||
use {
|
||||
crate::{
|
||||
ei::ei_object::EiObjectId,
|
||||
utils::buffd::buf_out::{MsgFds, OUT_BUF_SIZE, OutBuffer, OutBufferMeta},
|
||||
},
|
||||
crate::buf_out::{MsgFds, OUT_BUF_SIZE, OutBuffer, OutBufferMeta},
|
||||
jay_wire_types::EiObjectId,
|
||||
std::{mem, rc::Rc},
|
||||
uapi::OwnedFd,
|
||||
};
|
||||
|
|
@ -42,7 +40,6 @@ impl<'a> EiMsgFormatter<'a> {
|
|||
self
|
||||
}
|
||||
|
||||
#[expect(dead_code)]
|
||||
pub fn long(&mut self, int: i64) -> &mut Self {
|
||||
self.write(uapi::as_bytes(&int));
|
||||
self
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
use {
|
||||
crate::{ei::ei_object::EiObjectId, utils::buffd::BufFdIn},
|
||||
crate::BufFdIn,
|
||||
jay_wire_types::EiObjectId,
|
||||
std::{ptr, rc::Rc},
|
||||
thiserror::Error,
|
||||
uapi::OwnedFd,
|
||||
|
|
@ -1,9 +1,7 @@
|
|||
use {
|
||||
crate::{
|
||||
fixed::Fixed,
|
||||
object::ObjectId,
|
||||
utils::buffd::buf_out::{MsgFds, OUT_BUF_SIZE, OutBuffer, OutBufferMeta},
|
||||
},
|
||||
crate::buf_out::{MsgFds, OUT_BUF_SIZE, OutBuffer, OutBufferMeta},
|
||||
jay_units::Fixed,
|
||||
jay_wire_types::ObjectId,
|
||||
std::{mem, rc::Rc},
|
||||
uapi::{OwnedFd, Packed},
|
||||
};
|
||||
|
|
@ -48,13 +46,11 @@ impl<'a> MsgFormatter<'a> {
|
|||
self
|
||||
}
|
||||
|
||||
#[expect(dead_code)]
|
||||
pub fn u64(&mut self, int: u64) -> &mut Self {
|
||||
self.uint((int >> 32) as u32);
|
||||
self.uint(int as u32)
|
||||
}
|
||||
|
||||
#[expect(dead_code)]
|
||||
pub fn u64_rev(&mut self, int: u64) -> &mut Self {
|
||||
self.uint(int as u32);
|
||||
self.uint((int >> 32) as u32)
|
||||
|
|
@ -96,7 +92,6 @@ impl<'a> MsgFormatter<'a> {
|
|||
self.object(obj).uint(event)
|
||||
}
|
||||
|
||||
#[expect(dead_code)]
|
||||
pub fn array<F: FnOnce(&mut MsgFormatter<'_>)>(&mut self, f: F) -> &mut Self {
|
||||
let pos = self.meta.write_pos;
|
||||
self.uint(0);
|
||||
43
wire-buf/src/lib.rs
Normal file
43
wire-buf/src/lib.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
use {jay_io_uring::IoUringError, thiserror::Error};
|
||||
pub use {
|
||||
buf_in::BufFdIn,
|
||||
buf_out::{BufFdOut, OutBuffer, OutBufferSwapchain},
|
||||
ei_formatter::EiMsgFormatter,
|
||||
ei_parser::{EiMsgParser, EiMsgParserError},
|
||||
formatter::MsgFormatter,
|
||||
parser::{MsgParser, MsgParserError},
|
||||
wl_buf_in::{WlBufFdIn, WlMessage},
|
||||
};
|
||||
|
||||
mod buf_in;
|
||||
mod buf_out;
|
||||
mod ei_formatter;
|
||||
mod ei_parser;
|
||||
mod formatter;
|
||||
mod parser;
|
||||
mod wl_buf_in;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum BufFdError {
|
||||
#[error("An IO error occurred")]
|
||||
Io(#[source] IoUringError),
|
||||
#[error("An io-uring error occurred")]
|
||||
Ring(#[from] IoUringError),
|
||||
#[error("The peer did not send a file descriptor")]
|
||||
NoFd,
|
||||
#[error("The peer sent too many file descriptors")]
|
||||
TooManyFds,
|
||||
#[error("The peer closed the connection")]
|
||||
Closed,
|
||||
#[error("The connection timed out")]
|
||||
Timeout,
|
||||
#[error("Message size is not a multiple of 4")]
|
||||
UnalignedMessageSize,
|
||||
#[error("Message size is larger than 4096")]
|
||||
MessageTooLarge,
|
||||
#[error("Message size is smaller than 8")]
|
||||
MessageTooSmall,
|
||||
}
|
||||
|
||||
const BUF_SIZE: usize = 4096;
|
||||
const MAX_IN_FD: usize = 32;
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
use {
|
||||
crate::{fixed::Fixed, globals::GlobalName, object::ObjectId},
|
||||
bstr::{BStr, ByteSlice},
|
||||
jay_units::Fixed,
|
||||
jay_wire_types::{GlobalName, ObjectId},
|
||||
std::{collections::VecDeque, ptr, rc::Rc},
|
||||
thiserror::Error,
|
||||
uapi::{OwnedFd, Pod},
|
||||
|
|
@ -55,14 +56,12 @@ impl<'a, 'b> MsgParser<'a, 'b> {
|
|||
self.int().map(|i| i as u32)
|
||||
}
|
||||
|
||||
#[expect(dead_code)]
|
||||
pub fn u64(&mut self) -> Result<u64, MsgParserError> {
|
||||
let hi = self.uint()?;
|
||||
let lo = self.uint()?;
|
||||
Ok(((hi as u64) << 32) | lo as u64)
|
||||
}
|
||||
|
||||
#[expect(dead_code)]
|
||||
pub fn u64_rev(&mut self) -> Result<u64, MsgParserError> {
|
||||
let lo = self.uint()?;
|
||||
let hi = self.uint()?;
|
||||
|
|
@ -76,7 +75,6 @@ impl<'a, 'b> MsgParser<'a, 'b> {
|
|||
self.int().map(|i| ObjectId::from_raw(i as u32).into())
|
||||
}
|
||||
|
||||
#[expect(dead_code)]
|
||||
pub fn global(&mut self) -> Result<GlobalName, MsgParserError> {
|
||||
self.int().map(|i| GlobalName::from_raw(i as u32))
|
||||
}
|
||||
|
|
@ -1,12 +1,8 @@
|
|||
use {
|
||||
crate::{
|
||||
io_uring::IoUring,
|
||||
object::ObjectId,
|
||||
utils::{
|
||||
buf::Buf,
|
||||
buffd::{BufFdError, MAX_IN_FD},
|
||||
},
|
||||
},
|
||||
crate::{BufFdError, MAX_IN_FD},
|
||||
jay_io_uring::IoUring,
|
||||
jay_utils::buf::Buf,
|
||||
jay_wire_types::ObjectId,
|
||||
std::{collections::VecDeque, ptr, rc::Rc, slice},
|
||||
uapi::OwnedFd,
|
||||
};
|
||||
5
wire-types/Cargo.toml
Normal file
5
wire-types/Cargo.toml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
[package]
|
||||
name = "jay-wire-types"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
license = "GPL-3.0-only"
|
||||
68
wire-types/src/lib.rs
Normal file
68
wire-types/src/lib.rs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
use std::fmt::{Display, Formatter, LowerHex};
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub struct ObjectId(u32);
|
||||
|
||||
impl ObjectId {
|
||||
pub const NONE: Self = ObjectId(0);
|
||||
|
||||
pub fn from_raw(raw: u32) -> Self {
|
||||
Self(raw)
|
||||
}
|
||||
|
||||
pub fn raw(self) -> u32 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for ObjectId {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
Display::fmt(&self.0, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub struct GlobalName(u32);
|
||||
|
||||
impl GlobalName {
|
||||
pub fn from_raw(id: u32) -> Self {
|
||||
Self(id)
|
||||
}
|
||||
|
||||
pub fn raw(self) -> u32 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for GlobalName {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
Display::fmt(&self.0, f)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
|
||||
pub struct EiObjectId(u64);
|
||||
|
||||
impl EiObjectId {
|
||||
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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue