config: remove bincode command bridge
This commit is contained in:
parent
d8920ed7a0
commit
87de5fcca3
6 changed files with 64 additions and 119 deletions
|
|
@ -15,10 +15,9 @@ use {
|
|||
ptr_ext::PtrExt,
|
||||
},
|
||||
},
|
||||
bincode::Options,
|
||||
jay_config::{
|
||||
_private::{
|
||||
ConfigEntry, VERSION, bincode_ops,
|
||||
ConfigEntry, VERSION,
|
||||
ipc::{InitMessage, ServerFeature, ServerMessage, V1InitMessage},
|
||||
},
|
||||
input::{InputDevice, Seat, SwitchEvent},
|
||||
|
|
@ -167,18 +166,17 @@ impl Drop for ConfigProxy {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe extern "C" fn default_client_init(
|
||||
unsafe fn default_client_init(
|
||||
srv_data: *const u8,
|
||||
srv_unref: unsafe extern "C" fn(data: *const u8),
|
||||
srv_handler: unsafe extern "C" fn(data: *const u8, msg: *const u8, size: usize),
|
||||
msg: *const u8,
|
||||
size: usize,
|
||||
srv_unref: jay_config::_private::Unref,
|
||||
srv_handler: jay_config::_private::ServerHandler,
|
||||
msg: InitMessage,
|
||||
) -> *const u8 {
|
||||
extern "C" fn configure() {
|
||||
fn configure() {
|
||||
jay_toml_config::configure();
|
||||
}
|
||||
unsafe {
|
||||
jay_config::_private::client::init(srv_data, srv_unref, srv_handler, msg, size, configure)
|
||||
jay_config::_private::client::init(srv_data, srv_unref, srv_handler, msg, configure)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +192,6 @@ impl ConfigProxy {
|
|||
state: state.clone(),
|
||||
next_id: NumCell::new(1),
|
||||
keymaps: Default::default(),
|
||||
bufs: Default::default(),
|
||||
workspace_ids: NumCell::new(1),
|
||||
workspaces_by_name: Default::default(),
|
||||
workspaces_by_id: Default::default(),
|
||||
|
|
@ -218,16 +215,13 @@ impl ConfigProxy {
|
|||
window_matcher_no_auto_focus: Default::default(),
|
||||
window_matcher_initial_tile_state: Default::default(),
|
||||
});
|
||||
let init_msg = bincode_ops()
|
||||
.serialize(&InitMessage::V1(V1InitMessage {}))
|
||||
.unwrap();
|
||||
let init_msg = InitMessage::V1(V1InitMessage {});
|
||||
unsafe {
|
||||
let client_data = (entry.init)(
|
||||
Rc::into_raw(data.clone()) as _,
|
||||
unref,
|
||||
handle_msg,
|
||||
init_msg.as_ptr(),
|
||||
init_msg.len(),
|
||||
init_msg,
|
||||
);
|
||||
data.client_data.set(client_data);
|
||||
}
|
||||
|
|
@ -259,21 +253,20 @@ impl ConfigProxy {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe extern "C" fn unref(data: *const u8) {
|
||||
unsafe fn unref(data: *const u8) {
|
||||
let server = data as *const ConfigProxyHandler;
|
||||
unsafe {
|
||||
drop(Rc::from_raw(server));
|
||||
}
|
||||
}
|
||||
|
||||
unsafe extern "C" fn handle_msg(data: *const u8, msg: *const u8, size: usize) {
|
||||
unsafe fn handle_msg(data: *const u8, msg: &jay_config::_private::ipc::ClientMessage<'_>) {
|
||||
unsafe {
|
||||
let server = (data as *const ConfigProxyHandler).deref();
|
||||
if server.dropped.get() {
|
||||
return;
|
||||
}
|
||||
let rc = Rc::from_raw(server);
|
||||
let msg = std::slice::from_raw_parts(msg, size);
|
||||
rc.handle_request(msg);
|
||||
mem::forget(rc);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,15 +37,13 @@ use {
|
|||
errorfmt::ErrorFmt,
|
||||
numcell::NumCell,
|
||||
oserror::OsErrorExt,
|
||||
stack::Stack,
|
||||
timer::{TimerError, TimerFd},
|
||||
},
|
||||
},
|
||||
bincode::Options,
|
||||
jay_config::{
|
||||
_private::{
|
||||
ClientCriterionIpc, ClientCriterionStringField, GenericCriterionIpc, PollableId,
|
||||
WindowCriterionIpc, WindowCriterionStringField, WireMode, bincode_ops,
|
||||
ConfigHandler, Unref, WindowCriterionIpc, WindowCriterionStringField, WireMode,
|
||||
ipc::{ClientMessage, Response, ServerMessage, WorkspaceSource},
|
||||
},
|
||||
Axis, Direction, Workspace,
|
||||
|
|
@ -93,12 +91,11 @@ pub(super) struct ConfigProxyHandler {
|
|||
pub client_data: Cell<*const u8>,
|
||||
pub dropped: Cell<bool>,
|
||||
pub _version: u32,
|
||||
pub unref: unsafe extern "C" fn(data: *const u8),
|
||||
pub handle_msg: unsafe extern "C" fn(data: *const u8, msg: *const u8, size: usize),
|
||||
pub unref: Unref,
|
||||
pub handle_msg: ConfigHandler,
|
||||
pub state: Rc<State>,
|
||||
pub next_id: NumCell<u64>,
|
||||
pub keymaps: CopyHashMap<Keymap, Rc<KbvmMap>>,
|
||||
pub bufs: Stack<Vec<u8>>,
|
||||
|
||||
pub workspace_ids: NumCell<u64>,
|
||||
pub workspaces_by_name: CopyHashMap<Rc<String>, u64>,
|
||||
|
|
@ -202,13 +199,9 @@ impl ConfigProxyHandler {
|
|||
}
|
||||
|
||||
pub fn send(&self, msg: &ServerMessage) {
|
||||
let mut buf = self.bufs.pop().unwrap_or_default();
|
||||
buf.clear();
|
||||
bincode_ops().serialize_into(&mut buf, msg).unwrap();
|
||||
unsafe {
|
||||
(self.handle_msg)(self.client_data.get(), buf.as_ptr(), buf.len());
|
||||
(self.handle_msg)(self.client_data.get(), msg);
|
||||
}
|
||||
self.bufs.push(buf);
|
||||
}
|
||||
|
||||
pub fn respond(&self, msg: Response) {
|
||||
|
|
@ -2813,17 +2806,14 @@ impl ConfigProxyHandler {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn handle_request(self: &Rc<Self>, msg: &[u8]) {
|
||||
pub fn handle_request(self: &Rc<Self>, msg: &ClientMessage<'_>) {
|
||||
if let Err(e) = self.handle_request_(msg) {
|
||||
log::error!("Could not handle client request: {}", ErrorFmt(e));
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_request_(self: &Rc<Self>, msg: &[u8]) -> Result<(), CphError> {
|
||||
let request = match bincode_ops().deserialize::<ClientMessage>(msg) {
|
||||
Ok(msg) => msg,
|
||||
Err(e) => return Err(CphError::ParsingFailed(e)),
|
||||
};
|
||||
fn handle_request_(self: &Rc<Self>, request: &ClientMessage<'_>) -> Result<(), CphError> {
|
||||
let request = request.clone();
|
||||
match request {
|
||||
ClientMessage::Log {
|
||||
level,
|
||||
|
|
@ -3599,8 +3589,6 @@ enum CphError {
|
|||
UnknownColor(u32),
|
||||
#[error("Sized element {0} is not known")]
|
||||
UnknownSized(u32),
|
||||
#[error("Could not parse the message")]
|
||||
ParsingFailed(#[source] bincode::Error),
|
||||
#[error("Could not process a `{0}` request")]
|
||||
FailedRequest(&'static str, #[source] Box<Self>),
|
||||
#[error(transparent)]
|
||||
|
|
|
|||
|
|
@ -6,11 +6,10 @@ use {
|
|||
tree::OutputNode,
|
||||
utils::{copyhashmap::CopyHashMap, stack::Stack},
|
||||
},
|
||||
bincode::Options,
|
||||
isnt::std_1::primitive::IsntConstPtrExt,
|
||||
jay_config::{
|
||||
_private::{
|
||||
ConfigEntry, VERSION, bincode_ops,
|
||||
ConfigEntry, VERSION,
|
||||
ipc::{ClientMessage, Response, ServerMessage},
|
||||
},
|
||||
Axis, Direction,
|
||||
|
|
@ -53,12 +52,11 @@ where
|
|||
res
|
||||
}
|
||||
|
||||
unsafe extern "C" fn init(
|
||||
unsafe fn init(
|
||||
srv_data: *const u8,
|
||||
srv_unref: unsafe extern "C" fn(data: *const u8),
|
||||
srv_handler: unsafe extern "C" fn(data: *const u8, msg: *const u8, size: usize),
|
||||
_msg: *const u8,
|
||||
_size: usize,
|
||||
srv_unref: jay_config::_private::Unref,
|
||||
srv_handler: jay_config::_private::ServerHandler,
|
||||
_msg: jay_config::_private::ipc::InitMessage,
|
||||
) -> *const u8 {
|
||||
let tc = CONFIG.get();
|
||||
assert!(tc.is_not_null());
|
||||
|
|
@ -76,23 +74,15 @@ unsafe extern "C" fn init(
|
|||
}
|
||||
}
|
||||
|
||||
unsafe extern "C" fn unref(data: *const u8) {
|
||||
unsafe fn unref(data: *const u8) {
|
||||
unsafe {
|
||||
Rc::decrement_strong_count(data.cast::<TestConfig>());
|
||||
}
|
||||
}
|
||||
|
||||
unsafe extern "C" fn handle_msg(data: *const u8, msg: *const u8, size: usize) {
|
||||
unsafe fn handle_msg(data: *const u8, msg: &ServerMessage) {
|
||||
let tc = unsafe { &*data.cast::<TestConfig>() };
|
||||
let msg = unsafe { std::slice::from_raw_parts(msg, size) };
|
||||
let res = bincode_ops().deserialize::<ServerMessage>(msg);
|
||||
let msg = match res {
|
||||
Ok(msg) => msg,
|
||||
Err(e) => {
|
||||
log::error!("could not deserialize message: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
let msg = msg.clone();
|
||||
match msg {
|
||||
ServerMessage::Configure { .. } => {}
|
||||
ServerMessage::Response { response } => {
|
||||
|
|
@ -138,8 +128,8 @@ unsafe extern "C" fn handle_msg(data: *const u8, msg: *const u8, size: usize) {
|
|||
#[derive(Copy, Clone)]
|
||||
struct ServerData {
|
||||
srv_data: *const u8,
|
||||
srv_unref: unsafe extern "C" fn(data: *const u8),
|
||||
srv_handler: unsafe extern "C" fn(data: *const u8, msg: *const u8, size: usize),
|
||||
srv_unref: jay_config::_private::Unref,
|
||||
srv_handler: jay_config::_private::ServerHandler,
|
||||
}
|
||||
|
||||
pub struct TestConfig {
|
||||
|
|
@ -170,10 +160,8 @@ impl TestConfig {
|
|||
Some(srv) => srv,
|
||||
_ => bail!("srv not set"),
|
||||
};
|
||||
let mut buf = vec![];
|
||||
bincode_ops().serialize_into(&mut buf, msg).unwrap();
|
||||
unsafe {
|
||||
(srv.srv_handler)(srv.srv_data, buf.as_ptr(), buf.len());
|
||||
(srv.srv_handler)(srv.srv_data, msg);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue