-
Notifications
You must be signed in to change notification settings - Fork 6
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
Fix DBus conversions #185
Comments
Thanks for writing this down. Good starting point for what might be a description of our architecture, something I have wanted to guide choices. I don't want to muddy the water, the above is complicated enough, however in my mind's eye we offer two API's:
|
Not sure I understand the first part. I don't think there is a The second part is true though. |
No, there is no Rust |
New idea, we add This will construct the event without checking the interface/method combo. This allows us to write: impl TryFrom<Message> for Event {
match ... {
("interface", "member") => MyUEFT::from_parts_unchecked(obj_ref, body)?,
// ...
}
} It can still fail, and it will still return a Not sure if you can see my edits, but I re-invented |
DBus/zbus Problems
Ok, so I keep getting bugged by having two functions that appear to do similar things on the surface.
Namely, converting from a
zbus::Message
to a specific event type.Current Situation
Right now, in the
main
branch, this occurs in two steps:TryFrom<&zbus::Message>
Message
reference, and extracts the three required parts to be processed by step two:path()
and application as asender()
, collectively refered to as anObjectRef
.BusProperties
trait:from_message_parts
from_message_parts
implementaiton based on if the message matches the correctmember()
,interface()
, and body signature.ObjectRef
and do not even need a deserialized body of any kind.Luuk's PR
Luuk has an approach which simplifies the public API.
MessageExt
trait which can find out if it matches the event, before deserializing:matches_event<E: BusProperties>(Message) -> bool
BusProperties
to determine if the message maches the event's DBus interface, member, and body signature.TryFrom<&zbus::Message>
BusProperties
trait:from_message
Message
and converts it to the specific event type; it takes advantage ofTryFrom<&Message>
to fill each field with few expressions.This adds an extra step, but adds a convenient API for checking if an event type is matched by a particular
Message
.The Problem
All of these are extra steps to what in theory is one operation: to fallibly convert a
Message
into a specific event type.The reason we are in this mess is because I have been strongly against writing the boilerplate to do this manually for each event.
So, let's break down the operations that are not unique to one event type and how we may abstract that away.
BusProperties
of an event match that of theMessage
. Luuk's implementaiton, which adds this viaMessageExt::matches_event<E: BusProperties>(&Message) -> bool
is one way to do this.TryFrom<&Message>
.This could be done with the following trait, implemented via a
macro_rules!
macro.Something like
This should allow a blanket implementation for
TryFrom<&Message> for T: NoBodyEvent
.TODO: naming better
TryFrom
; if the individual fields in a given struct are able themselves to beTryFrom<T>
'd, then why not the entire struct?Ideally, we want to be able to do this with certain constraints; we would not want to:
Body
's shape from theMessage
..is_ok()
and dropping the data.atspi-common
crate non-optionally depending onzbus
.zbus::Message
is not re-exported by another crate; it is defined inzbus
itself.zbus
will not currently compile onwasm32-*
architectures.atspi
events are crucal in this mission.Message
will be necessary.This proves somewhat challenging, no matter the order of operation, or what the public API is.
Potential Solution
Please add possible solutions as comments.
The text was updated successfully, but these errors were encountered: