Skip to content
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

feat: handle device event in service handler #132

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vthib
Copy link
Contributor

@vthib vthib commented Sep 9, 2024

I have recently needed to receive device events as a windows service, and found out that I couldn't with the current version of windows-service. This PR is here to make this possible.

To receive those events, a call to RegisterDeviceNotification must be done. This is of course not done in this crate and let instead to the user.

Then, instead of parsing the event data for every subtype of device events, I've chosen to keep the event data in raw form, and let the user of the crate do this parsing. This does not seem to be quite how the rest of the service event handler is written, but this is by far the simplest:

  • The event data for device events can be quite complex (with first a HDR type, then different type of objects depending on the subtype stored in the header), and which type of events is received also depends on which parameters was provided to RegistryDeviceNotification
  • There are several type of device events (arrival, remove, custom, etc), and the user may only be interested in a subset of those

So all in all, it's imho much simpler and also efficient to let the user handle the conversion of this event data into rust. For example in my case, I only need to handle device arrival, and only some subset of those events.

Let me know what you think, or if you would prefer parsing those events to provide a nicer experience to the user. Also, thanks for your work on this crate :)


This change is Reviewable

Add device event in service control to allow the user to receive and
handle device events.
The data of those events is for the moment not parsed. Converting those
events to Rust is not trivial, and we can let the user do it rather than
doing it in his place, when he does not necessarily care for all the
different type of device events.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant