Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use super::*; | ||
use bindings::*; | ||
use core::marker::PhantomData; | ||
|
||
/// A type representing an agile reference to a COM/WinRT object. | ||
#[repr(transparent)] | ||
#[derive(Clone, PartialEq, Eq)] | ||
pub struct AgileReference<T>(IAgileReference, PhantomData<T>); | ||
|
||
impl<T: Interface> AgileReference<T> { | ||
/// Creates an agile reference to the object. | ||
pub fn new<'a>(object: &'a T) -> Result<Self> | ||
where | ||
&'a T: IntoParam<'a, IUnknown>, | ||
{ | ||
unsafe { RoGetAgileReference(AGILEREFERENCE_DEFAULT, &T::IID, object).map(|reference| Self(reference, Default::default())) } | ||
} | ||
|
||
/// Retrieves a proxy to the target of the `AgileReference` object that may safely be used within any thread context in which get is called. | ||
pub fn resolve(&self) -> Result<T> { | ||
unsafe { self.0.Resolve() } | ||
} | ||
} | ||
|
||
unsafe impl<T: Interface> Send for AgileReference<T> {} | ||
unsafe impl<T: Interface> Sync for AgileReference<T> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "test_agile_reference" | ||
version = "0.0.0" | ||
authors = ["Microsoft"] | ||
edition = "2018" | ||
|
||
[dependencies.windows] | ||
path = "../../libs/windows" | ||
features = [ | ||
"Foundation", | ||
"Media_Control", | ||
"Foundation_Collections" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use windows::core::{AgileReference, Result}; | ||
use windows::Media::Control::GlobalSystemMediaTransportControlsSessionManager; | ||
|
||
#[test] | ||
fn test() -> Result<()> { | ||
let manager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync()?.get()?; | ||
let reference = AgileReference::new(&manager)?; | ||
|
||
let handle = std::thread::spawn(move || { | ||
let manager = reference.resolve()?; | ||
|
||
manager.GetSessions()?; | ||
Ok(()) | ||
}); | ||
handle.join().unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters