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

async support? #13

Closed
svartalf opened this issue Aug 28, 2019 · 5 comments
Closed

async support? #13

svartalf opened this issue Aug 28, 2019 · 5 comments

Comments

@svartalf
Copy link

@svartalf svartalf commented Aug 28, 2019

For a heim crate I'm looking for a way to fetch the temperature sensors data for Windows and it seems that WMI and MSAcpi_ThermalZoneTemperature class is the only reasonable solution to do that.

Since heim is an async lib, I would prefer the async interface to WMI, but it seems that wmi crate does not has it at the moment. Do you planning to add it, maybe?

@ohadravid
Copy link
Owner

@ohadravid ohadravid commented Aug 28, 2019

Hi!

I don't have any plans to implement that myself (it's quite complex to interact with WMI as it is, and this crate already solves my problem).

Reading the WMI docs, it seems possible and I'll be happy to accept PRs if you think that's something you'd like to implement 😄

Loading

@apennamen
Copy link
Contributor

@apennamen apennamen commented Dec 19, 2020

Hello @ohadravid

I'd like to give it a try, this is what I'm thinking of (i'll put everything here, it's not necessary a must read, it's before creating a PR)

General Idea

Add support for ExecQueryAsync in WMIConnection.
The motivation is to be able to query WMI and obtain a Future object. It could lead in the future to use of wmi crate in heim for windows (if @svartalf agrees of course).

Design [WIP]

The idea would be to add an exec_async_query_native_wrapper and async_raw_query to WMIConnection in query.rs
Implementation would be inpired from this example : https://docs.microsoft.com/fr-fr/windows/win32/wmisdk/example--getting-wmi-data-from-the-local-computer-asynchronously

pub fn exec_async_query_native_wrapper(
        &self,
        query: impl AsRef<str>,
    ) -> Result<QueryResultSink, WMIError> { }

pub fn async_raw_query<T>(&self, query: impl AsRef<str>) -> Future<Result<Vec<T>, WMIError>>
    where
        T: de::DeserializeOwned, {}

I have to dig into https://docs.microsoft.com/en-us/windows/win32/wmisdk/iwbemobjectsink

Impacts

I'll have to use https://docs.rs/winapi/0.3.9/winapi/um/wbemcli/struct.IWbemObjectSink.html
Also import WBEM_FLAG_BIDIRECTIONAL
I'll try to avoid importing new crates, even if the future crates provide a Sink that could be useful...
We'll see ;)

Regards,
AP.

Loading

@ohadravid
Copy link
Owner

@ohadravid ohadravid commented Dec 19, 2020

Hi!
Thanks for looking into this.
It's fine to add new dependencies under a feature flag, so don't worry about it.

The hardest thing IMO will be getting right the lifetimes/pin/unpin semantics of this code, so a crucial part of every change should be a link & quote of the relevant part of the documentation.

Also implementating it in a few separate PRs will be easier to review.

Good luck!

Loading

@apennamen
Copy link
Contributor

@apennamen apennamen commented Dec 23, 2020

Hello!
Thanks for your words of encouragement, I set it as a personnal challenge and... I'm in for a looong dive into unsafe Rust! I set myself a deadline at the begining of March 2021, we'll see then how things have unfold.

First hurdle is to provide an implementation of winapi::um::wbemcli::IWbemObjectSink to the ExecQueryAsync. I can't see yet a safe way to do it, my best idea so far (not tested) is to cast a pointer to a #[repr(C)] Rust struct that provides an implementation.

I have to dig into how the com crates implements its com::class! macro and if I could take something there. As it works in pair with the com::interface! macro, I can't use it on the winapi::um::wbemcli::IWbemObjectSink.

I'll keep you updated of my progress, if I make any 😄

Regards,
AP

Loading

@apennamen apennamen mentioned this issue Dec 23, 2020
10 tasks
@ohadravid
Copy link
Owner

@ohadravid ohadravid commented Feb 23, 2021

Closing now that #30 is merged and published 🎉

Loading

@ohadravid ohadravid closed this Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants