autocommit 2022-01-02 15:13:33 CET
This commit is contained in:
commit
d6172b273f
50 changed files with 5807 additions and 0 deletions
91
src/ifs/wl_registry/mod.rs
Normal file
91
src/ifs/wl_registry/mod.rs
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
mod types;
|
||||
|
||||
use crate::globals::{Global, GlobalName};
|
||||
use crate::objects::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::WlParser;
|
||||
use crate::wl_client::{DynEventFormatter, WlClientData};
|
||||
use std::rc::Rc;
|
||||
pub use types::*;
|
||||
|
||||
const BIND: u32 = 0;
|
||||
|
||||
const GLOBAL: u32 = 0;
|
||||
const GLOBAL_REMOVE: u32 = 1;
|
||||
|
||||
pub struct WlRegistry {
|
||||
id: ObjectId,
|
||||
client: Rc<WlClientData>,
|
||||
}
|
||||
|
||||
impl WlRegistry {
|
||||
pub fn new(id: ObjectId, client: &Rc<WlClientData>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
client: client.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn global(self: &Rc<Self>, global: &Rc<dyn Global>) -> DynEventFormatter {
|
||||
Box::new(GlobalE {
|
||||
obj: self.clone(),
|
||||
global: global.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn global_remove(self: &Rc<Self>, name: GlobalName) -> DynEventFormatter {
|
||||
Box::new(GlobalRemove {
|
||||
obj: self.clone(),
|
||||
name,
|
||||
})
|
||||
}
|
||||
|
||||
async fn bind(&self, parser: WlParser<'_, '_>) -> Result<(), BindError> {
|
||||
let bind: Bind = self.client.parse(self, parser)?;
|
||||
let global = self.client.state.globals.get(bind.name)?;
|
||||
if global.interface().name() != bind.interface {
|
||||
return Err(BindError::InvalidInterface(InterfaceError {
|
||||
name: global.name(),
|
||||
interface: global.interface(),
|
||||
actual: bind.interface.to_string(),
|
||||
}));
|
||||
}
|
||||
if bind.version > global.version() {
|
||||
return Err(BindError::InvalidVersion(VersionError {
|
||||
name: global.name(),
|
||||
interface: global.interface(),
|
||||
version: global.version(),
|
||||
actual: bind.version,
|
||||
}));
|
||||
}
|
||||
global.bind(&self.client, bind.id, bind.version).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_request_(
|
||||
&self,
|
||||
request: u32,
|
||||
parser: WlParser<'_, '_>,
|
||||
) -> Result<(), WlRegistryError> {
|
||||
match request {
|
||||
BIND => self.bind(parser).await?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
handle_request!(WlRegistry);
|
||||
|
||||
impl Object for WlRegistry {
|
||||
fn id(&self) -> ObjectId {
|
||||
self.id
|
||||
}
|
||||
|
||||
fn interface(&self) -> Interface {
|
||||
Interface::WlRegistry
|
||||
}
|
||||
|
||||
fn num_requests(&self) -> u32 {
|
||||
BIND + 1
|
||||
}
|
||||
}
|
||||
117
src/ifs/wl_registry/types.rs
Normal file
117
src/ifs/wl_registry/types.rs
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
use crate::globals::{Global, GlobalError, GlobalName};
|
||||
use crate::ifs::wl_registry::{WlRegistry, GLOBAL, GLOBAL_REMOVE};
|
||||
use crate::objects::{Interface, Object, ObjectId};
|
||||
use crate::utils::buffd::{WlFormatter, WlParser, WlParserError};
|
||||
use crate::wl_client::{EventFormatter, RequestParser};
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::rc::Rc;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum WlRegistryError {
|
||||
#[error("Could not process bind request")]
|
||||
BindError(#[source] Box<BindError>),
|
||||
}
|
||||
|
||||
efrom!(WlRegistryError, BindError, BindError);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum BindError {
|
||||
#[error("Parsing failed")]
|
||||
ParseError(#[source] Box<WlParserError>),
|
||||
#[error(transparent)]
|
||||
GlobalError(Box<GlobalError>),
|
||||
#[error("Tried to bind to global {} of type {} using interface {}", .0.name, .0.interface.name(), .0.actual)]
|
||||
InvalidInterface(InterfaceError),
|
||||
#[error("Tried to bind to global {} of type {} and version {} using version {}", .0.name, .0.interface.name(), .0.version, .0.actual)]
|
||||
InvalidVersion(VersionError),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct InterfaceError {
|
||||
pub name: GlobalName,
|
||||
pub interface: Interface,
|
||||
pub actual: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct VersionError {
|
||||
pub name: GlobalName,
|
||||
pub interface: Interface,
|
||||
pub version: u32,
|
||||
pub actual: u32,
|
||||
}
|
||||
|
||||
efrom!(BindError, ParseError, WlParserError);
|
||||
efrom!(BindError, GlobalError, GlobalError);
|
||||
|
||||
pub(super) struct GlobalE {
|
||||
pub obj: Rc<WlRegistry>,
|
||||
pub global: Rc<dyn Global>,
|
||||
}
|
||||
impl EventFormatter for GlobalE {
|
||||
fn format(self: Box<Self>, fmt: &mut WlFormatter<'_>) {
|
||||
fmt.header(self.obj.id, GLOBAL)
|
||||
.uint(self.global.name().raw())
|
||||
.string(self.global.interface().name())
|
||||
.uint(self.global.version());
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
&*self.obj
|
||||
}
|
||||
}
|
||||
impl Debug for GlobalE {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"global(name: {}, interface: {:?}, version: {})",
|
||||
self.global.name(),
|
||||
self.global.interface().name(),
|
||||
self.global.version()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct GlobalRemove {
|
||||
pub obj: Rc<WlRegistry>,
|
||||
pub name: GlobalName,
|
||||
}
|
||||
impl EventFormatter for GlobalRemove {
|
||||
fn format(self: Box<Self>, fmt: &mut WlFormatter<'_>) {
|
||||
fmt.header(self.obj.id, GLOBAL_REMOVE).uint(self.name.raw());
|
||||
}
|
||||
fn obj(&self) -> &dyn Object {
|
||||
&*self.obj
|
||||
}
|
||||
}
|
||||
impl Debug for GlobalRemove {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "global_remove(name: {})", self.name)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct Bind<'a> {
|
||||
pub name: GlobalName,
|
||||
pub id: ObjectId,
|
||||
pub interface: &'a str,
|
||||
pub version: u32,
|
||||
}
|
||||
impl<'a> RequestParser<'a> for Bind<'a> {
|
||||
fn parse(parser: &mut WlParser<'_, 'a>) -> Result<Self, WlParserError> {
|
||||
Ok(Self {
|
||||
name: parser.global()?,
|
||||
interface: parser.string()?,
|
||||
version: parser.uint()?,
|
||||
id: parser.object()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Debug for Bind<'_> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"bind(name: {}, interface: {:?}, version: {}, id: {})",
|
||||
self.name, self.interface, self.version, self.id
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue