-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Tokio and config-rs features (#37)
As discussed offline, I have some oddball integration scenarios where much of the SF runtime interaction is already handled by existing application logic written in other languages, but we'd like to move parts of the system into Rust. At least for now, my project is not making use of any of the functionality in mssf-core that actually necessitates use of Tokio, nor are we currently using the config_rs crate. At the same time, mssf_com is a bit too low level to be ideal for us - we have no desire to duplicate / rewrite existing Rust wrappers such as: * mssf_core::runtime::config types * mssf_core::runtime::ActivationContext To enable minimizing dependencies and compile times for those of use who don't need the entire runtime at present, this PR adds two default-on features (naming suggestions of course welcome) - one for config-rs, one for tokio (tokio feature also requires ctrlc as that's small and part of the Executor, and I'm assuming most native-Rust applications that are ok with tokio will want that too). It also moves some of the code form runtimes/mod.rs to its own file to make the conditional complication a bit less messy, though it could be cleaner. Additionally, one of the echomain (echomain-stateful) examples is adjusted to demonstrate that config_rs feature is optional. The example already did not need any of the APIs that are now gated behind that feature, demonstrating that a thinner version of mssf_core could have utility to pure Rust SF applications as well. I think it's just the hostname function that even needs the tokio_async feature, but haven't tried to create a "neither feature" example yet.
- Loading branch information
1 parent
1a6e8ab
commit 32fde93
Showing
5 changed files
with
110 additions
and
65 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
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,59 @@ | ||
use crate::HSTRING; | ||
/// safe wrapping for runtime | ||
use mssf_com::FabricCommon::FabricRuntime::{ | ||
IFabricRuntime, IFabricStatefulServiceFactory, IFabricStatelessServiceFactory, | ||
}; | ||
|
||
use super::{ | ||
create_com_runtime, executor::Executor, stateful::StatefulServiceFactory, | ||
stateful_bridge::StatefulServiceFactoryBridge, stateless::StatelessServiceFactory, | ||
stateless_bridge::StatelessServiceFactoryBridge, | ||
}; | ||
pub struct Runtime<E> | ||
where | ||
E: Executor, | ||
{ | ||
com_impl: IFabricRuntime, | ||
rt: E, | ||
} | ||
|
||
impl<E> Runtime<E> | ||
where | ||
E: Executor, | ||
{ | ||
pub fn create(rt: E) -> ::windows_core::Result<Runtime<E>> { | ||
let com = create_com_runtime()?; | ||
Ok(Runtime { com_impl: com, rt }) | ||
} | ||
|
||
pub fn register_stateless_service_factory<F>( | ||
&self, | ||
servicetypename: &HSTRING, | ||
factory: F, | ||
) -> windows_core::Result<()> | ||
where | ||
F: StatelessServiceFactory, | ||
{ | ||
let rt_cp = self.rt.clone(); | ||
let bridge: IFabricStatelessServiceFactory = | ||
StatelessServiceFactoryBridge::create(factory, rt_cp).into(); | ||
unsafe { | ||
self.com_impl | ||
.RegisterStatelessServiceFactory(servicetypename, &bridge) | ||
} | ||
} | ||
|
||
pub fn register_stateful_service_factory( | ||
&self, | ||
servicetypename: &HSTRING, | ||
factory: impl StatefulServiceFactory, | ||
) -> windows_core::Result<()> { | ||
let rt_cp = self.rt.clone(); | ||
let bridge: IFabricStatefulServiceFactory = | ||
StatefulServiceFactoryBridge::create(factory, rt_cp).into(); | ||
unsafe { | ||
self.com_impl | ||
.RegisterStatefulServiceFactory(servicetypename, &bridge) | ||
} | ||
} | ||
} |
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