-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make generated code reusable for other connection implementations #656
Comments
Since the cookies each have a separate type in these case, I think we does need to have a least 3 traits. If we use the serde machinery and put the extension opcode on the Serializer side, 3 traits would probably be enough. |
True... okay, then, what should those three traits look like? use crate::connection::{BufWithFds, PiecewiseBuf};
/// An X11 request that does not have a reply
pub trait VoidRequest {
/// The protocol name of the extension that this request belongs to, or None for core requests
const EXTENSION_NAME: Option<&'static str>;
/// Serialize this request into its X11 protocol wire representation.
///
/// The argument is the major opcode of the extension that this request belongs to. For core
/// requests, the argument may not have any influence
fn serialize(self, extension_opcode: u8) -> BufWithFds<PiecewiseBuf<'static>>;
}
/// An X11 request that has a reply
pub trait ReplyRequest {
/// The protocol name of the extension that this request belongs to, or None for core requests
const EXTENSION_NAME: Option<&'static str>;
/// Serialize this request into its X11 protocol wire representation.
///
/// The argument is the major opcode of the extension that this request belongs to. For core
/// requests, the argument may not have any influence
fn serialize(self, extension_opcode: u8) -> BufWithFds<PiecewiseBuf<'static>>;
}
/// An X11 request that has a reply containing file descriptors
pub trait ReplyFDsRequest {
/// The protocol name of the extension that this request belongs to, or None for core requests
const EXTENSION_NAME: Option<&'static str>;
/// Serialize this request into its X11 protocol wire representation.
///
/// The argument is the major opcode of the extension that this request belongs to. For core
/// requests, the argument may not have any influence
fn serialize(self, extension_opcode: u8) -> BufWithFds<PiecewiseBuf<'static>>;
} The content of all three traits is again identical, so I am still tempted to introduce a fourth |
I guess we could use marker traits, i.e.
The |
This commit changes the Request trait to have a new EXTENSION_NAME associated constant and a serialize() method. This allows any user of the trait to serialize a Request and send it to an X11 server. This also adds VoidRequest, ReplyRequest, ReplyFDsRequest marker traits that allow to figure out what kind of reply to expect from sending such a request. The code generator is extended to implement these changes. Closes: #656 Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit changes the Request trait to have a new EXTENSION_NAME associated constant and a serialize() method. This allows any user of the trait to serialize a Request and send it to an X11 server. This also adds VoidRequest, ReplyRequest, ReplyFDsRequest marker traits that allow to figure out what kind of reply to expect from sending such a request. The code generator is extended to implement these changes. Closes: #656 Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit changes the Request trait to have a new EXTENSION_NAME associated constant and a serialize() method. This allows any user of the trait to serialize a Request and send it to an X11 server. This also adds VoidRequest, ReplyRequest, ReplyFDsRequest marker traits that allow to figure out what kind of reply to expect from sending such a request. The code generator is extended to implement these changes. Closes: #656 Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit changes the Request trait to have a new EXTENSION_NAME associated constant and a serialize() method. This allows any user of the trait to serialize a Request and send it to an X11 server. This also adds VoidRequest, ReplyRequest, ReplyFDsRequest marker traits that allow to figure out what kind of reply to expect from sending such a request. The code generator is extended to implement these changes. Closes: #656 Signed-off-by: Uli Schlachter <psychon@znc.in>
This is actually the direction I'm taking with For the purposes of ecosystem standardization, I wonder if using the same backing protocol crate would be beneficial. @psychon What are your thoughts on this? |
Sure, somewhere somewhen I might already have written that splitting out the protocol stuff might be a good idea. That still seems like something that could be split out. And that's even before you'd want to re-use this code. I cannot really do much with your link. But do you think the x11rb code would require many changes before it would be usable for you? Or what's your plan? Currently, I still think that one needs generated code even outside the traits that #657 adds. Otherwise the API is just quite unergonomic for crate users. Also, I am already working (as time permits) on a branch that implements an async connection based on these new traits. Last time I worked on this, I managed to get a GetInputFocus request & its reply across. Current WIP state is (now) here: https://github.com/psychon/x11rb/tree/async-experiments/x11rb-async |
Whoops, realized I forgot to commit the protocol files I'd generated there. They should be there now. Definitely not in a finished state, but they should give a good idea of what I'd like to do.
I was trying to design the To answer your question, though: after #657 lands, I could definitely work the current form of the trait RequestTarget<T: Request> {
type Output;
fn send_request(&mut self, req: T) -> Self::Output;
} and implement that on all |
This idea is in the context of #318. There, one needs a way to get the "on the wire bytes" for a request. I do not yet have a good idea on how to do this, but here is a bad one:
Introduce some traits so that the API user can construct e.g. a
GetInputFocusRequest
struct and the generics figure out the rest.A quick sketch is as follows, but this introduces seven new traits, which I do not really like. Three new traits are the bare minimum, because one needs to tell apart "has no reply", "has a reply", "has a reply with FDs". Core requests do not have a "special" major opcode while extensions do. That way I ended up with the below.
I am opening this issue to track this idea. But mainly, I hope that someone has a great idea on how to implement this in a simpler way.
(Follow-up work would then be to split up the x11rb crate into some encode/decode layer and the
x11rb-sync
thingie that provides the blocking behaviour that we already have.)The text was updated successfully, but these errors were encountered: