diff --git a/Cargo.lock b/Cargo.lock index a66e1ae..2c18638 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -419,7 +419,6 @@ version = "0.0.1" dependencies = [ "mssf-com", "mssf-core", - "windows", "windows-core", ] @@ -445,7 +444,6 @@ dependencies = [ "tokio", "tracing", "tracing-subscriber", - "windows", "windows-core", ] @@ -453,15 +451,12 @@ dependencies = [ name = "samples_echomain_stateful2" version = "0.1.0" dependencies = [ - "mssf-com", "mssf-core", "tokio", "tokio-util", "tracing", "tracing-subscriber", "trait-variant", - "windows", - "windows-core", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 6f1200e..d0c09cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,4 +9,14 @@ members = [ [workspace.dependencies] tracing = { version = "0.1", features = ["log"] } tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"]} -tokio-util = "0.7" \ No newline at end of file +tokio-util = "0.7" +ctrlc = { version = "3.0", features = ["termination"] } +tokio = { version = "1", features = ["full"] } +windows = {version = "0.57", features = ["implement"]} +windows-core = "0.57" +trait-variant = "0.1" +serde = "*" +serde_derive = "*" +# crates in this repo +mssf-com = { path = "./crates/libs/com" } +mssf-core = { path = "./crates/libs/core", default-features = true} \ No newline at end of file diff --git a/crates/libs/core/src/error/mod.rs b/crates/libs/core/src/error/mod.rs index 2039f06..11eefc0 100644 --- a/crates/libs/core/src/error/mod.rs +++ b/crates/libs/core/src/error/mod.rs @@ -3,7 +3,7 @@ // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. // ------------------------------------------------------------ -use super::HRESULT; +use crate::HRESULT; use mssf_com::FabricTypes::{ FABRIC_ERROR_CODE, FABRIC_E_OPERATION_NOT_COMPLETE, FABRIC_E_OPERATION_NOT_SUPPORTED, }; diff --git a/crates/libs/core/src/lib.rs b/crates/libs/core/src/lib.rs index fd212ad..49c05c4 100644 --- a/crates/libs/core/src/lib.rs +++ b/crates/libs/core/src/lib.rs @@ -33,4 +33,7 @@ pub mod sync; pub mod types; // re-export some windows types -pub use windows_core::{Error, Result, GUID, HRESULT, HSTRING, PCWSTR}; +pub use windows_core::{w, Error, Interface, Result, GUID, HRESULT, HSTRING, PCWSTR}; +// Note cannot re-export windows_core::implement because the macro using it has hard coded mod name. + +pub use windows::Win32::Foundation::BOOLEAN; diff --git a/crates/libs/core/src/runtime/config.rs b/crates/libs/core/src/runtime/config.rs index 4b487ec..1318920 100644 --- a/crates/libs/core/src/runtime/config.rs +++ b/crates/libs/core/src/runtime/config.rs @@ -3,6 +3,8 @@ // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. // ------------------------------------------------------------ +use crate::BOOLEAN; +use crate::{error::FabricErrorCode, HSTRING}; use mssf_com::{ FabricRuntime::IFabricConfigurationPackage, FabricTypes::{ @@ -11,8 +13,6 @@ use mssf_com::{ FABRIC_CONFIGURATION_SECTION_LIST, }, }; -use windows::Win32::Foundation::{BOOLEAN, E_POINTER}; -use windows_core::HSTRING; use crate::{ iter::{FabricIter, FabricListAccessor}, @@ -92,10 +92,7 @@ impl ConfigurationPackage { HSTRINGWrap::from(raw).into() } - pub fn get_section( - &self, - section_name: &HSTRING, - ) -> windows_core::Result { + pub fn get_section(&self, section_name: &HSTRING) -> crate::Result { let raw = unsafe { self.com.GetSection(section_name) }?; let raw_ref = unsafe { raw.as_ref() }; match raw_ref { @@ -104,7 +101,7 @@ impl ConfigurationPackage { res.owner = Some(self.com.clone()); Ok(res) } - None => Err(E_POINTER.into()), + None => Err(FabricErrorCode::ArgumentNull.into()), } } @@ -112,7 +109,7 @@ impl ConfigurationPackage { &self, section_name: &HSTRING, parameter_name: &HSTRING, - ) -> windows_core::Result<(HSTRING, bool)> { + ) -> crate::Result<(HSTRING, bool)> { let mut is_encrypted: BOOLEAN = Default::default(); let raw = unsafe { self.com.GetValue( diff --git a/crates/libs/core/src/runtime/error.rs b/crates/libs/core/src/runtime/error.rs index 1f6e590..9211a55 100644 --- a/crates/libs/core/src/runtime/error.rs +++ b/crates/libs/core/src/runtime/error.rs @@ -3,8 +3,8 @@ // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. // ------------------------------------------------------------ +use crate::{Error, HRESULT, HSTRING}; use mssf_com::FabricCommon::FabricGetLastErrorMessage; -use windows_core::{Error, HRESULT, HSTRING}; // Fills the error info as string for better debugging. // SF has separate last error set and get from windows. @@ -29,14 +29,14 @@ pub fn fill_fabric_error(e: Error) -> Error { #[cfg(test)] #[cfg(windows)] // linux error propagate is not working yet mod test { + use crate::{Error, HSTRING}; use mssf_com::FabricTypes::FABRIC_E_GATEWAY_NOT_REACHABLE; - use windows_core::{Error, HSTRING}; #[test] fn test_win_error() { let s = HSTRING::from("MyError"); let e = Error::new( - windows_core::HRESULT(FABRIC_E_GATEWAY_NOT_REACHABLE.0), + crate::HRESULT(FABRIC_E_GATEWAY_NOT_REACHABLE.0), s.clone().to_string(), ); assert_eq!(e.message(), s); diff --git a/crates/libs/core/src/runtime/mod.rs b/crates/libs/core/src/runtime/mod.rs index da83c09..d827b33 100644 --- a/crates/libs/core/src/runtime/mod.rs +++ b/crates/libs/core/src/runtime/mod.rs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. // ------------------------------------------------------------ +use crate::{Error, Interface, HSTRING, PCWSTR}; use mssf_com::{ FabricRuntime::{ FabricCreateRuntime, FabricGetActivationContext, IFabricCodePackageActivationContext, @@ -10,7 +11,6 @@ use mssf_com::{ }, FabricTypes::FABRIC_ENDPOINT_RESOURCE_DESCRIPTION, }; -use windows_core::{Error, Interface, HSTRING, PCWSTR}; #[cfg(feature = "tokio_async")] use mssf_com::FabricCommon::{IFabricAsyncOperationCallback, IFabricAsyncOperationContext}; @@ -45,13 +45,13 @@ pub mod store_proxy; pub mod store_types; // creates fabric runtime -pub fn create_com_runtime() -> ::windows_core::Result { +pub fn create_com_runtime() -> crate::Result { let rawruntime = unsafe { FabricCreateRuntime(&IFabricRuntime::IID)? }; let runtime = unsafe { IFabricRuntime::from_raw(rawruntime) }; Ok(runtime) } -pub fn get_com_activation_context() -> ::windows_core::Result { +pub fn get_com_activation_context() -> crate::Result { let raw_activation_ctx = unsafe { FabricGetActivationContext(&IFabricCodePackageActivationContext::IID)? }; @@ -62,11 +62,11 @@ pub fn get_com_activation_context() -> ::windows_core::Result Result { + ) -> crate::Result { let rs = unsafe { self.com_impl.GetServiceEndpointResource(PCWSTR::from_raw( serviceendpointresourcename.as_ptr(), @@ -109,7 +109,7 @@ impl ActivationContext { pub fn get_configuration_package( &self, configpackagename: &HSTRING, - ) -> windows_core::Result { + ) -> crate::Result { let c = unsafe { self.com_impl.GetConfigurationPackage(configpackagename) }?; Ok(ConfigurationPackage::from_com(c)) } diff --git a/crates/libs/core/src/runtime/node_context.rs b/crates/libs/core/src/runtime/node_context.rs index 1eb8705..d1c1846 100644 --- a/crates/libs/core/src/runtime/node_context.rs +++ b/crates/libs/core/src/runtime/node_context.rs @@ -1,10 +1,10 @@ use std::time::Duration; +use crate::{Interface, HSTRING}; use mssf_com::FabricRuntime::{ FabricBeginGetNodeContext, FabricEndGetNodeContext, FabricGetNodeContext, IFabricNodeContextResult, IFabricNodeContextResult2, }; -use windows_core::{Interface, HSTRING}; use crate::{ strings::HSTRINGWrap, @@ -43,14 +43,14 @@ impl NodeContext { pub async fn get( timeout: Duration, cancellation_token: Option, - ) -> ::windows_core::Result { + ) -> crate::Result { let com = get_com_node_context(timeout.as_millis().try_into().unwrap(), cancellation_token) .await??; Ok(Self::from(&com)) } // Get the node context synchronously - pub fn get_sync() -> ::windows_core::Result { + pub fn get_sync() -> crate::Result { let raw = unsafe { FabricGetNodeContext() }?; assert!(!raw.is_null()); let com = unsafe { IFabricNodeContextResult::from_raw(raw) }; diff --git a/crates/libs/core/src/runtime/runtime_wrapper.rs b/crates/libs/core/src/runtime/runtime_wrapper.rs index fab59a4..5da8bb4 100644 --- a/crates/libs/core/src/runtime/runtime_wrapper.rs +++ b/crates/libs/core/src/runtime/runtime_wrapper.rs @@ -21,7 +21,7 @@ impl Runtime where E: Executor, { - pub fn create(rt: E) -> ::windows_core::Result> { + pub fn create(rt: E) -> crate::Result> { let com = create_com_runtime()?; Ok(Runtime { com_impl: com, rt }) } @@ -30,7 +30,7 @@ where &self, servicetypename: &HSTRING, factory: F, - ) -> windows_core::Result<()> + ) -> crate::Result<()> where F: StatelessServiceFactory + 'static, { @@ -47,7 +47,7 @@ where &self, servicetypename: &HSTRING, factory: impl StatefulServiceFactory + 'static, - ) -> windows_core::Result<()> { + ) -> crate::Result<()> { let rt_cp = self.rt.clone(); let bridge: IFabricStatefulServiceFactory = StatefulServiceFactoryBridge::create(factory, rt_cp).into(); diff --git a/crates/libs/core/src/runtime/stateful.rs b/crates/libs/core/src/runtime/stateful.rs index 8704df6..28bfa08 100644 --- a/crates/libs/core/src/runtime/stateful.rs +++ b/crates/libs/core/src/runtime/stateful.rs @@ -5,8 +5,8 @@ // stateful contains rs definition of stateful traits that user needs to implement +use crate::{GUID, HSTRING}; use mssf_com::FabricRuntime::IFabricStatefulServicePartition; -use windows_core::{Error, HSTRING}; use crate::sync::CancellationToken; use crate::types::{LoadMetric, LoadMetricListRef, ReplicaRole}; @@ -23,9 +23,9 @@ pub trait StatefulServiceFactory { servicetypename: &HSTRING, servicename: &HSTRING, initializationdata: &[u8], - partitionid: &::windows::core::GUID, + partitionid: &GUID, replicaid: i64, - ) -> Result; + ) -> crate::Result; } /// Defines behavior that governs the lifecycle of a replica, such as startup, initialization, role changes, and shutdown. @@ -41,7 +41,7 @@ pub trait LocalStatefulServiceReplica: Send + Sync + 'static { openmode: OpenMode, partition: &StatefulServicePartition, cancellation_token: CancellationToken, - ) -> windows::core::Result; + ) -> crate::Result; /// Changes the role of the service replica to one of the ReplicaRole. /// Returns the service’s new connection address that is to be associated with the replica via Service Fabric Naming. @@ -54,10 +54,10 @@ pub trait LocalStatefulServiceReplica: Send + Sync + 'static { &self, newrole: ReplicaRole, cancellation_token: CancellationToken, - ) -> ::windows_core::Result; + ) -> crate::Result; /// Closes the service replica gracefully when it is being shut down. - async fn close(&self, cancellation_token: CancellationToken) -> windows::core::Result<()>; + async fn close(&self, cancellation_token: CancellationToken) -> crate::Result<()>; /// Ungracefully terminates the service replica. /// Remarks: Network issues resulting in Service Fabric process shutdown @@ -95,14 +95,14 @@ impl From<&IFabricStatefulServicePartition> for StatefulServicePartition { /// TODO: replicator has no public documentation #[trait_variant::make(Replicator: Send)] pub trait LocalReplicator: Send + Sync + 'static { - async fn open(&self, cancellation_token: CancellationToken) -> ::windows_core::Result; // replicator address - async fn close(&self, cancellation_token: CancellationToken) -> ::windows_core::Result<()>; + async fn open(&self, cancellation_token: CancellationToken) -> crate::Result; // replicator address + async fn close(&self, cancellation_token: CancellationToken) -> crate::Result<()>; async fn change_role( &self, epoch: &Epoch, role: &ReplicaRole, cancellation_token: CancellationToken, - ) -> ::windows_core::Result<()>; + ) -> crate::Result<()>; /// (TODO: This doc is from IStateProvider but not Replicator.) /// Indicates to a replica that the configuration of a replica set has changed due to @@ -116,9 +116,9 @@ pub trait LocalReplicator: Send + Sync + 'static { &self, epoch: &Epoch, cancellation_token: CancellationToken, - ) -> ::windows_core::Result<()>; - fn get_current_progress(&self) -> ::windows_core::Result; - fn get_catch_up_capability(&self) -> ::windows_core::Result; + ) -> crate::Result<()>; + fn get_current_progress(&self) -> crate::Result; + fn get_catch_up_capability(&self) -> crate::Result; fn abort(&self); } @@ -128,28 +128,25 @@ pub trait LocalPrimaryReplicator: Replicator { // SF calls this to indicate that possible data loss has occurred (write quorum loss), // returns is isStateChanged. If true, SF will re-create other secondaries. // The default SF impl might be a pass through to the state provider. - async fn on_data_loss( - &self, - cancellation_token: CancellationToken, - ) -> ::windows_core::Result; + async fn on_data_loss(&self, cancellation_token: CancellationToken) -> crate::Result; fn update_catch_up_replica_set_configuration( &self, currentconfiguration: &ReplicaSetConfig, previousconfiguration: &ReplicaSetConfig, - ) -> ::windows_core::Result<()>; + ) -> crate::Result<()>; async fn wait_for_catch_up_quorum( &self, catchupmode: ReplicaSetQuarumMode, cancellation_token: CancellationToken, - ) -> ::windows_core::Result<()>; + ) -> crate::Result<()>; fn update_current_replica_set_configuration( &self, currentconfiguration: &ReplicaSetConfig, - ) -> ::windows_core::Result<()>; + ) -> crate::Result<()>; async fn build_replica( &self, replica: &ReplicaInfo, cancellation_token: CancellationToken, - ) -> ::windows_core::Result<()>; - fn remove_replica(&self, replicaid: i64) -> ::windows_core::Result<()>; + ) -> crate::Result<()>; + fn remove_replica(&self, replicaid: i64) -> crate::Result<()>; } diff --git a/crates/libs/core/src/runtime/stateful_bridge.rs b/crates/libs/core/src/runtime/stateful_bridge.rs index 2d365b1..edb7a33 100644 --- a/crates/libs/core/src/runtime/stateful_bridge.rs +++ b/crates/libs/core/src/runtime/stateful_bridge.rs @@ -11,7 +11,7 @@ use std::sync::Arc; use tracing::info; -use windows::core::implement; +use windows_core::implement; use windows_core::{Interface, HSTRING}; use mssf_com::{ @@ -71,15 +71,15 @@ where #[allow(clippy::not_unsafe_ptr_arg_deref)] fn CreateReplica( &self, - servicetypename: &::windows_core::PCWSTR, + servicetypename: &crate::PCWSTR, servicename: FABRIC_URI, initializationdatalength: u32, initializationdata: *const u8, - partitionid: &::windows_core::GUID, + partitionid: &crate::GUID, replicaid: i64, - ) -> ::windows_core::Result { + ) -> crate::Result { info!("StatefulServiceFactoryBridge::CreateReplica"); - let p_servicename = ::windows_core::PCWSTR::from_raw(servicename.0); + let p_servicename = crate::PCWSTR::from_raw(servicename.0); let h_servicename = HSTRING::from_wide(unsafe { p_servicename.as_wide() }).unwrap(); let h_servicetypename = HSTRING::from_wide(unsafe { servicetypename.as_wide() }).unwrap(); let data = unsafe { @@ -145,7 +145,7 @@ where fn BeginOpen( &self, callback: ::core::option::Option<&super::IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> crate::Result { info!("IFabricReplicatorBridge::BeginOpen"); let inner = self.inner.clone(); let (ctx, token) = BridgeContext3::make(callback); @@ -160,7 +160,7 @@ where fn EndOpen( &self, context: ::core::option::Option<&super::IFabricAsyncOperationContext>, - ) -> ::windows_core::Result { + ) -> crate::Result { info!("IFabricReplicatorBridge::EndOpen"); BridgeContext3::result(context)? } @@ -171,7 +171,7 @@ where epoch: *const FABRIC_EPOCH, role: FABRIC_REPLICA_ROLE, callback: ::core::option::Option<&super::IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> crate::Result { let inner = self.inner.clone(); let epoch2: Epoch = unsafe { epoch.as_ref().unwrap().into() }; let role2: ReplicaRole = (&role).into(); @@ -189,7 +189,7 @@ where fn EndChangeRole( &self, context: ::core::option::Option<&super::IFabricAsyncOperationContext>, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { info!("IFabricReplicatorBridge::EndChangeRole"); BridgeContext3::result(context)? } @@ -199,7 +199,7 @@ where &self, epoch: *const FABRIC_EPOCH, callback: ::core::option::Option<&super::IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> crate::Result { let inner = self.inner.clone(); let epoch2: Epoch = unsafe { epoch.as_ref().unwrap().into() }; info!( @@ -216,7 +216,7 @@ where fn EndUpdateEpoch( &self, context: ::core::option::Option<&super::IFabricAsyncOperationContext>, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { info!("IFabricReplicatorBridge::BeginUpdateEpoch"); BridgeContext3::result(context)? } @@ -224,7 +224,7 @@ where fn BeginClose( &self, callback: ::core::option::Option<&super::IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> crate::Result { info!("IFabricReplicatorBridge::BeginClose"); let inner = self.inner.clone(); let (ctx, token) = BridgeContext3::make(callback); @@ -234,7 +234,7 @@ where fn EndClose( &self, context: ::core::option::Option<&super::IFabricAsyncOperationContext>, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { info!("IFabricReplicatorBridge::EndClose"); BridgeContext3::result(context)? } @@ -244,13 +244,13 @@ where self.inner.abort(); } - fn GetCurrentProgress(&self) -> ::windows_core::Result { + fn GetCurrentProgress(&self) -> crate::Result { let lsn = self.inner.get_current_progress(); info!("IFabricReplicatorBridge::GetCurrentProgress: {:?}", lsn); lsn } - fn GetCatchUpCapability(&self) -> ::windows_core::Result { + fn GetCatchUpCapability(&self) -> crate::Result { let lsn = self.inner.get_catch_up_capability(); info!("IFabricReplicatorBridge::GetCatchUpCapability: {:?}", lsn); lsn @@ -306,14 +306,14 @@ where fn BeginOpen( &self, callback: ::core::option::Option<&super::IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> crate::Result { self.rplctr.BeginOpen(callback) } fn EndOpen( &self, context: ::core::option::Option<&super::IFabricAsyncOperationContext>, - ) -> ::windows_core::Result { + ) -> crate::Result { self.rplctr.EndOpen(context) } @@ -322,14 +322,14 @@ where epoch: *const FABRIC_EPOCH, role: FABRIC_REPLICA_ROLE, callback: ::core::option::Option<&super::IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> crate::Result { self.rplctr.BeginChangeRole(epoch, role, callback) } fn EndChangeRole( &self, context: ::core::option::Option<&super::IFabricAsyncOperationContext>, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { self.rplctr.EndChangeRole(context) } @@ -337,28 +337,28 @@ where &self, epoch: *const FABRIC_EPOCH, callback: ::core::option::Option<&super::IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> crate::Result { self.rplctr.BeginUpdateEpoch(epoch, callback) } fn EndUpdateEpoch( &self, context: ::core::option::Option<&super::IFabricAsyncOperationContext>, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { self.rplctr.EndUpdateEpoch(context) } fn BeginClose( &self, callback: ::core::option::Option<&super::IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> crate::Result { self.rplctr.BeginClose(callback) } fn EndClose( &self, context: ::core::option::Option<&super::IFabricAsyncOperationContext>, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { self.rplctr.EndClose(context) } @@ -366,11 +366,11 @@ where self.rplctr.Abort() } - fn GetCurrentProgress(&self) -> ::windows_core::Result { + fn GetCurrentProgress(&self) -> crate::Result { self.rplctr.GetCurrentProgress() } - fn GetCatchUpCapability(&self) -> ::windows_core::Result { + fn GetCatchUpCapability(&self) -> crate::Result { self.rplctr.GetCatchUpCapability() } } @@ -383,7 +383,7 @@ where fn BeginOnDataLoss( &self, callback: ::core::option::Option<&super::IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> crate::Result { info!("IFabricPrimaryReplicatorBridge::BeginOnDataLoss"); let inner = self.inner.clone(); @@ -394,7 +394,7 @@ where fn EndOnDataLoss( &self, context: ::core::option::Option<&super::IFabricAsyncOperationContext>, - ) -> ::windows_core::Result { + ) -> crate::Result { info!("IFabricPrimaryReplicatorBridge::EndOnDataLoss"); BridgeContext3::result(context)? } @@ -404,7 +404,7 @@ where &self, currentconfiguration: *const FABRIC_REPLICA_SET_CONFIGURATION, previousconfiguration: *const FABRIC_REPLICA_SET_CONFIGURATION, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { let cc = ReplicaSetConfig::from(unsafe { currentconfiguration.as_ref().unwrap() }); let pc = ReplicaSetConfig::from(unsafe { previousconfiguration.as_ref().unwrap() }); info!("IFabricPrimaryReplicatorBridge::UpdateCatchUpReplicaSetConfiguration: curr {:?}, prev {:?}", cc, pc); @@ -416,7 +416,7 @@ where &self, catchupmode: FABRIC_REPLICA_SET_QUORUM_MODE, callback: ::core::option::Option<&super::IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> crate::Result { info!( "IFabricPrimaryReplicatorBridge::BeginWaitForCatchUpQuorum: mode {:?}", catchupmode @@ -433,7 +433,7 @@ where fn EndWaitForCatchUpQuorum( &self, context: ::core::option::Option<&super::IFabricAsyncOperationContext>, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { info!("IFabricPrimaryReplicatorBridge::BeginWaitForCatchUpQuorum"); BridgeContext3::result(context)? } @@ -442,7 +442,7 @@ where fn UpdateCurrentReplicaSetConfiguration( &self, currentconfiguration: *const FABRIC_REPLICA_SET_CONFIGURATION, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { let c = ReplicaSetConfig::from(unsafe { currentconfiguration.as_ref() }.unwrap()); info!( "IFabricPrimaryReplicatorBridge::UpdateCurrentReplicaSetConfiguration {:?}", @@ -456,7 +456,7 @@ where &self, replica: *const FABRIC_REPLICA_INFORMATION, callback: ::core::option::Option<&super::IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> crate::Result { let inner = self.inner.clone(); let r = ReplicaInfo::from(unsafe { replica.as_ref().unwrap() }); info!("IFabricPrimaryReplicatorBridge::BeginBuildReplica: {:?}", r); @@ -470,12 +470,12 @@ where fn EndBuildReplica( &self, context: ::core::option::Option<&super::IFabricAsyncOperationContext>, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { info!("IFabricPrimaryReplicatorBridge::EndBuildReplica"); BridgeContext3::result(context)? } - fn RemoveReplica(&self, replicaid: i64) -> ::windows_core::Result<()> { + fn RemoveReplica(&self, replicaid: i64) -> crate::Result<()> { info!("IFabricPrimaryReplicatorBridge::RemoveReplica"); self.inner.remove_replica(replicaid) } @@ -517,7 +517,7 @@ where openmode: FABRIC_REPLICA_OPEN_MODE, partition: ::core::option::Option<&IFabricStatefulServicePartition>, callback: ::core::option::Option<&super::IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> crate::Result { let inner = self.inner.clone(); let rt_cp = self.rt.clone(); let openmode2: OpenMode = openmode.into(); @@ -539,7 +539,7 @@ where fn EndOpen( &self, context: ::core::option::Option<&super::IFabricAsyncOperationContext>, - ) -> ::windows_core::Result { + ) -> crate::Result { info!("IFabricStatefulReplicaBridge::EndOpen"); BridgeContext3::result(context)? } @@ -548,7 +548,7 @@ where &self, newrole: FABRIC_REPLICA_ROLE, callback: ::core::option::Option<&super::IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> crate::Result { let inner = self.inner.clone(); let newrole2: ReplicaRole = (&newrole).into(); info!( @@ -567,7 +567,7 @@ where fn EndChangeRole( &self, context: ::core::option::Option<&super::IFabricAsyncOperationContext>, - ) -> ::windows_core::Result { + ) -> crate::Result { info!("IFabricStatefulReplicaBridge::EndChangeRole"); BridgeContext3::result(context)? } @@ -575,7 +575,7 @@ where fn BeginClose( &self, callback: ::core::option::Option<&super::IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> crate::Result { info!("IFabricStatefulReplicaBridge::BeginClose"); let inner = self.inner.clone(); let (ctx, token) = BridgeContext3::make(callback); @@ -585,7 +585,7 @@ where fn EndClose( &self, context: ::core::option::Option<&super::IFabricAsyncOperationContext>, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { info!("IFabricStatefulReplicaBridge::EndClose"); BridgeContext3::result(context)? } diff --git a/crates/libs/core/src/runtime/stateful_proxy.rs b/crates/libs/core/src/runtime/stateful_proxy.rs index cbdd96e..a60d377 100644 --- a/crates/libs/core/src/runtime/stateful_proxy.rs +++ b/crates/libs/core/src/runtime/stateful_proxy.rs @@ -41,7 +41,7 @@ impl StatefulServiceReplica for StatefulServiceReplicaProxy { openmode: OpenMode, partition: &StatefulServicePartition, cancellation_token: CancellationToken, - ) -> windows::core::Result { + ) -> crate::Result { info!("StatefulServiceReplicaProxy::open with mode {:?}", openmode); let com1 = &self.com_impl; let com2 = self.com_impl.clone(); @@ -63,7 +63,7 @@ impl StatefulServiceReplica for StatefulServiceReplicaProxy { &self, newrole: ReplicaRole, cancellation_token: CancellationToken, - ) -> ::windows_core::Result { + ) -> crate::Result { // replica address info!("StatefulServiceReplicaProxy::change_role {:?}", newrole); let com1 = &self.com_impl; @@ -76,7 +76,7 @@ impl StatefulServiceReplica for StatefulServiceReplicaProxy { let addr = rx.await??; Ok(HSTRINGWrap::from(&addr).into()) } - async fn close(&self, cancellation_token: CancellationToken) -> windows::core::Result<()> { + async fn close(&self, cancellation_token: CancellationToken) -> crate::Result<()> { info!("StatefulServiceReplicaProxy::close"); let com1 = &self.com_impl; let com2 = self.com_impl.clone(); @@ -104,7 +104,7 @@ impl ReplicatorProxy { } impl Replicator for ReplicatorProxy { - async fn open(&self, cancellation_token: CancellationToken) -> ::windows_core::Result { + async fn open(&self, cancellation_token: CancellationToken) -> crate::Result { info!("ReplicatorProxy::open"); // replicator address let com1 = &self.com_impl; @@ -117,7 +117,7 @@ impl Replicator for ReplicatorProxy { let addr = rx.await??; Ok(HSTRINGWrap::from(&addr).into()) } - async fn close(&self, cancellation_token: CancellationToken) -> ::windows_core::Result<()> { + async fn close(&self, cancellation_token: CancellationToken) -> crate::Result<()> { info!("ReplicatorProxy::close"); let com1 = &self.com_impl; let com2 = self.com_impl.clone(); @@ -133,7 +133,7 @@ impl Replicator for ReplicatorProxy { epoch: &Epoch, role: &ReplicaRole, cancellation_token: CancellationToken, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { info!("ReplicatorProxy::change_role"); let com1 = &self.com_impl; let com2 = self.com_impl.clone(); @@ -148,7 +148,7 @@ impl Replicator for ReplicatorProxy { &self, epoch: &Epoch, cancellation_token: CancellationToken, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { info!("ReplicatorProxy::update_epoch"); let com1 = &self.com_impl; let com2 = self.com_impl.clone(); @@ -159,11 +159,11 @@ impl Replicator for ReplicatorProxy { ); rx.await? } - fn get_current_progress(&self) -> ::windows_core::Result { + fn get_current_progress(&self) -> crate::Result { info!("ReplicatorProxy::get_current_progress"); unsafe { self.com_impl.GetCurrentProgress() } } - fn get_catch_up_capability(&self) -> ::windows_core::Result { + fn get_catch_up_capability(&self) -> crate::Result { info!("ReplicatorProxy::get_catch_up_capability"); unsafe { self.com_impl.GetCatchUpCapability() } } @@ -186,10 +186,10 @@ impl PrimaryReplicatorProxy { } impl Replicator for PrimaryReplicatorProxy { - async fn open(&self, cancellation_token: CancellationToken) -> ::windows_core::Result { + async fn open(&self, cancellation_token: CancellationToken) -> crate::Result { self.parent.open(cancellation_token).await } - async fn close(&self, cancellation_token: CancellationToken) -> ::windows_core::Result<()> { + async fn close(&self, cancellation_token: CancellationToken) -> crate::Result<()> { self.parent.close(cancellation_token).await } async fn change_role( @@ -197,7 +197,7 @@ impl Replicator for PrimaryReplicatorProxy { epoch: &Epoch, role: &ReplicaRole, cancellation_token: CancellationToken, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { self.parent .change_role(epoch, role, cancellation_token) .await @@ -206,13 +206,13 @@ impl Replicator for PrimaryReplicatorProxy { &self, epoch: &Epoch, cancellation_token: CancellationToken, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { self.parent.update_epoch(epoch, cancellation_token).await } - fn get_current_progress(&self) -> ::windows_core::Result { + fn get_current_progress(&self) -> crate::Result { self.parent.get_current_progress() } - fn get_catch_up_capability(&self) -> ::windows_core::Result { + fn get_catch_up_capability(&self) -> crate::Result { self.parent.get_catch_up_capability() } fn abort(&self) { @@ -221,10 +221,7 @@ impl Replicator for PrimaryReplicatorProxy { } impl PrimaryReplicator for PrimaryReplicatorProxy { - async fn on_data_loss( - &self, - cancellation_token: CancellationToken, - ) -> ::windows_core::Result { + async fn on_data_loss(&self, cancellation_token: CancellationToken) -> crate::Result { info!("PrimaryReplicatorProxy::on_data_loss"); let com1 = &self.com_impl; let com2 = self.com_impl.clone(); @@ -239,7 +236,7 @@ impl PrimaryReplicator for PrimaryReplicatorProxy { &self, currentconfiguration: &ReplicaSetConfig, previousconfiguration: &ReplicaSetConfig, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { info!("PrimaryReplicatorProxy::update_catch_up_replica_set_configuration"); let cc_view = currentconfiguration.get_view(); let pc_view = previousconfiguration.get_view(); @@ -252,7 +249,7 @@ impl PrimaryReplicator for PrimaryReplicatorProxy { &self, catchupmode: ReplicaSetQuarumMode, cancellation_token: CancellationToken, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { info!("PrimaryReplicatorProxy::wait_for_catch_up_quorum"); let com1 = &self.com_impl; let com2 = self.com_impl.clone(); @@ -266,7 +263,7 @@ impl PrimaryReplicator for PrimaryReplicatorProxy { fn update_current_replica_set_configuration( &self, currentconfiguration: &ReplicaSetConfig, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { info!("PrimaryReplicatorProxy::update_current_replica_set_configuration"); unsafe { self.com_impl @@ -277,7 +274,7 @@ impl PrimaryReplicator for PrimaryReplicatorProxy { &self, replica: &ReplicaInfo, cancellation_token: CancellationToken, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { info!("PrimaryReplicatorProxy::build_replica"); let com1 = &self.com_impl; let com2 = self.com_impl.clone(); @@ -292,7 +289,7 @@ impl PrimaryReplicator for PrimaryReplicatorProxy { ); rx.await? } - fn remove_replica(&self, replicaid: i64) -> ::windows_core::Result<()> { + fn remove_replica(&self, replicaid: i64) -> crate::Result<()> { info!("PrimaryReplicatorProxy::remove_replica"); unsafe { self.com_impl.RemoveReplica(replicaid) } } diff --git a/crates/libs/core/src/runtime/stateful_types.rs b/crates/libs/core/src/runtime/stateful_types.rs index 04d7314..34cafad 100644 --- a/crates/libs/core/src/runtime/stateful_types.rs +++ b/crates/libs/core/src/runtime/stateful_types.rs @@ -7,6 +7,7 @@ use std::{ffi::c_void, marker::PhantomData}; +use crate::{HSTRING, PCWSTR}; use mssf_com::FabricTypes::{ FABRIC_EPOCH, FABRIC_REPLICA_INFORMATION, FABRIC_REPLICA_INFORMATION_EX1, FABRIC_REPLICA_OPEN_MODE, FABRIC_REPLICA_OPEN_MODE_EXISTING, FABRIC_REPLICA_OPEN_MODE_INVALID, @@ -15,7 +16,6 @@ use mssf_com::FabricTypes::{ FABRIC_REPLICA_SET_WRITE_QUORUM, FABRIC_REPLICA_STATUS, FABRIC_REPLICA_STATUS_DOWN, FABRIC_REPLICA_STATUS_INVALID, FABRIC_REPLICA_STATUS_UP, }; -use windows_core::PCWSTR; use crate::{strings::HSTRINGWrap, types::ReplicaRole}; @@ -208,7 +208,7 @@ pub struct ReplicaInfo { pub id: i64, pub role: ReplicaRole, pub status: ReplicaStatus, - pub replicator_address: ::windows_core::HSTRING, + pub replicator_address: HSTRING, pub current_progress: i64, pub catch_up_capability: i64, pub must_catch_up: bool, @@ -289,11 +289,11 @@ impl From for FABRIC_REPLICA_SET_QUORUM_MODE { mod test { use std::ffi::c_void; + use crate::HSTRING; use mssf_com::FabricTypes::{ FABRIC_REPLICA_INFORMATION, FABRIC_REPLICA_INFORMATION_EX1, FABRIC_REPLICA_ROLE_PRIMARY, FABRIC_REPLICA_STATUS_UP, }; - use windows_core::HSTRING; use super::{Epoch, ReplicaInfo, ReplicaSetConfig}; diff --git a/crates/libs/core/src/runtime/stateless.rs b/crates/libs/core/src/runtime/stateless.rs index 360e58a..b84db9d 100644 --- a/crates/libs/core/src/runtime/stateless.rs +++ b/crates/libs/core/src/runtime/stateless.rs @@ -5,9 +5,9 @@ #![deny(non_snake_case)] // this file is safe rust +use crate::sync::CancellationToken; +use crate::HSTRING; use mssf_com::FabricRuntime::IFabricStatelessServicePartition; -use tokio_util::sync::CancellationToken; -use windows_core::HSTRING; use crate::types::ServicePartitionInformation; @@ -21,7 +21,7 @@ impl StatelessServicePartition { StatelessServicePartition { com_impl } } - pub fn get_partition_info(&self) -> ::windows_core::Result { + pub fn get_partition_info(&self) -> crate::Result { let raw = unsafe { self.com_impl.GetPartitionInfo() }?; let raw_ref = unsafe { raw.as_ref().unwrap() }; assert!(!raw.is_null()); @@ -41,7 +41,7 @@ pub trait StatelessServiceFactory { initializationdata: &[u8], partitionid: &::windows::core::GUID, instanceid: i64, - ) -> windows_core::Result; + ) -> crate::Result; } /// Defines behavior that governs the lifecycle of a stateless service instance, such as startup, initialization, and shutdown. @@ -57,10 +57,10 @@ pub trait LocalStatelessServiceInstance: Send + Sync + 'static { &self, partition: &StatelessServicePartition, cancellation_token: CancellationToken, - ) -> windows::core::Result; + ) -> crate::Result; /// Closes this service instance gracefully when the service instance is being shut down. - async fn close(&self, cancellation_token: CancellationToken) -> windows::core::Result<()>; + async fn close(&self, cancellation_token: CancellationToken) -> crate::Result<()>; /// Terminates this instance ungracefully with this synchronous method call. /// Remarks: diff --git a/crates/libs/core/src/runtime/stateless_bridge.rs b/crates/libs/core/src/runtime/stateless_bridge.rs index 72439b9..6d3b21a 100644 --- a/crates/libs/core/src/runtime/stateless_bridge.rs +++ b/crates/libs/core/src/runtime/stateless_bridge.rs @@ -8,6 +8,7 @@ use std::sync::Arc; +use crate::HSTRING; use crate::{ runtime::stateless::StatelessServicePartition, strings::HSTRINGWrap, sync::BridgeContext3, }; @@ -22,7 +23,6 @@ use mssf_com::{ }; use tracing::info; use windows::core::implement; -use windows_core::HSTRING; use super::{ executor::Executor, @@ -57,15 +57,15 @@ where #[allow(clippy::not_unsafe_ptr_arg_deref)] fn CreateInstance( &self, - servicetypename: &::windows_core::PCWSTR, + servicetypename: &crate::PCWSTR, servicename: FABRIC_URI, initializationdatalength: u32, initializationdata: *const u8, - partitionid: &::windows_core::GUID, + partitionid: &crate::GUID, instanceid: i64, - ) -> ::windows_core::Result { + ) -> crate::Result { info!("StatelessServiceFactoryBridge::CreateInstance"); - let p_servicename = ::windows_core::PCWSTR::from_raw(servicename.0); + let p_servicename = crate::PCWSTR::from_raw(servicename.0); let h_servicename = HSTRING::from_wide(unsafe { p_servicename.as_wide() }).unwrap(); let h_servicetypename = HSTRING::from_wide(unsafe { servicetypename.as_wide() }).unwrap(); let data = unsafe { @@ -127,7 +127,7 @@ where &self, partition: ::core::option::Option<&IFabricStatelessServicePartition>, callback: ::core::option::Option<&super::IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> crate::Result { info!("IFabricStatelessServiceInstanceBridge::BeginOpen"); let partition_cp = partition.unwrap().clone(); let partition_bridge = StatelessServicePartition::new(partition_cp); @@ -144,7 +144,7 @@ where fn EndOpen( &self, context: ::core::option::Option<&super::IFabricAsyncOperationContext>, - ) -> ::windows_core::Result { + ) -> crate::Result { info!("IFabricStatelessServiceInstanceBridge::EndOpen"); BridgeContext3::result(context)? } @@ -152,7 +152,7 @@ where fn BeginClose( &self, callback: ::core::option::Option<&super::IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> crate::Result { info!("IFabricStatelessServiceInstanceBridge::BeginClose"); let inner = self.inner.clone(); let (ctx, token) = BridgeContext3::make(callback); @@ -162,7 +162,7 @@ where fn EndClose( &self, context: ::core::option::Option<&super::IFabricAsyncOperationContext>, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { info!("IFabricStatelessServiceInstanceBridge::EndClose"); BridgeContext3::result(context)? } diff --git a/crates/libs/core/src/runtime/store.rs b/crates/libs/core/src/runtime/store.rs index e429b71..c94f2a1 100644 --- a/crates/libs/core/src/runtime/store.rs +++ b/crates/libs/core/src/runtime/store.rs @@ -5,6 +5,7 @@ use std::ffi::c_void; +use crate::{Interface, HSTRING, PCWSTR}; use mssf_com::{ FabricRuntime::{ FabricCreateKeyValueStoreReplica, IFabricKeyValueStoreReplica2, IFabricStoreEventHandler, @@ -13,8 +14,7 @@ use mssf_com::{ FabricTypes::{FABRIC_ESE_LOCAL_STORE_SETTINGS, FABRIC_LOCAL_STORE_KIND}, }; use tracing::info; -use windows::core::implement; -use windows_core::{Error, Interface, HSTRING, PCWSTR}; +use windows_core::implement; use super::store_types::{EseLocalStoreSettings, LocalStoreKind, ReplicatorSettings}; @@ -35,7 +35,7 @@ pub fn create_com_key_value_store_replica( localstorekind: LocalStoreKind, localstoresettings: Option<&EseLocalStoreSettings>, storeeventhandler: &IFabricStoreEventHandler, -) -> Result { +) -> crate::Result { let kind: FABRIC_LOCAL_STORE_KIND = localstorekind.into(); let local_settings: Option = localstoresettings.map(|x| x.get_raw()); diff --git a/crates/libs/core/src/runtime/store_proxy.rs b/crates/libs/core/src/runtime/store_proxy.rs index 4bae208..df0c139 100644 --- a/crates/libs/core/src/runtime/store_proxy.rs +++ b/crates/libs/core/src/runtime/store_proxy.rs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. // ------------------------------------------------------------ +use crate::PCWSTR; use mssf_com::{ FabricRuntime::{ IFabricKeyValueStoreItemResult, IFabricKeyValueStoreReplica2, IFabricTransaction, @@ -10,7 +11,6 @@ use mssf_com::{ FabricTypes::{FABRIC_KEY_VALUE_STORE_ITEM, FABRIC_KEY_VALUE_STORE_ITEM_METADATA}, }; use tracing::info; -use windows_core::PCWSTR; use crate::sync::{fabric_begin_end_proxy2, CancellationToken}; @@ -56,28 +56,19 @@ impl KVStoreProxy { KVStoreProxy { com_impl } } - pub fn create_transaction(&self) -> ::windows_core::Result { + pub fn create_transaction(&self) -> crate::Result { let tx = unsafe { self.com_impl.CreateTransaction() }?; Ok(TransactionProxy { com_impl: tx }) } - pub fn add( - &self, - tx: &TransactionProxy, - key: &[u16], - value: &[u8], - ) -> ::windows_core::Result<()> { + pub fn add(&self, tx: &TransactionProxy, key: &[u16], value: &[u8]) -> crate::Result<()> { unsafe { self.com_impl .Add(&tx.com_impl, PCWSTR::from_raw(key.as_ptr()), value) } } - pub fn get( - &self, - tx: &TransactionProxy, - key: &[u16], - ) -> ::windows_core::Result { + pub fn get(&self, tx: &TransactionProxy, key: &[u16]) -> crate::Result { let com = unsafe { self.com_impl .Get(&tx.com_impl, PCWSTR::from_raw(key.as_ptr())) @@ -93,7 +84,7 @@ impl KVStoreProxy { tx: &TransactionProxy, key: &[u16], checksequencenumber: i64, - ) -> ::windows_core::Result<()> { + ) -> crate::Result<()> { unsafe { self.com_impl.Remove( &tx.com_impl, @@ -105,7 +96,7 @@ impl KVStoreProxy { } impl TransactionProxy { - pub fn get_id(&self) -> &::windows_core::GUID { + pub fn get_id(&self) -> &crate::GUID { unsafe { self.com_impl.get_Id().as_ref().unwrap() } } @@ -117,7 +108,7 @@ impl TransactionProxy { &self, timeoutmilliseconds: u32, cancellation_token: Option, - ) -> ::windows_core::Result { + ) -> crate::Result { info!("TransactionProxy::commit"); let com1 = &self.com_impl; let com2 = self.com_impl.clone(); diff --git a/crates/libs/core/src/runtime/store_types.rs b/crates/libs/core/src/runtime/store_types.rs index fa8d494..7271294 100644 --- a/crates/libs/core/src/runtime/store_types.rs +++ b/crates/libs/core/src/runtime/store_types.rs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. // ------------------------------------------------------------ +use crate::PCWSTR; use mssf_com::FabricTypes::{ FABRIC_ESE_LOCAL_STORE_SETTINGS, FABRIC_LOCAL_STORE_KIND, FABRIC_LOCAL_STORE_KIND_ESE, FABRIC_LOCAL_STORE_KIND_INVALID, FABRIC_REPLICATOR_SETTINGS, @@ -12,7 +13,6 @@ use mssf_com::FabricTypes::{ FABRIC_TRANSACTION_ISOLATION_LEVEL_REPEATABLE_READ, FABRIC_TRANSACTION_ISOLATION_LEVEL_SERIALIZABLE, FABRIC_TRANSACTION_ISOLATION_LEVEL_SNAPSHOT, }; -use windows_core::PCWSTR; #[derive(Default)] pub struct ReplicatorSettings { diff --git a/crates/libs/core/src/strings.rs b/crates/libs/core/src/strings.rs index b89fbc8..4d26d84 100644 --- a/crates/libs/core/src/strings.rs +++ b/crates/libs/core/src/strings.rs @@ -3,8 +3,9 @@ // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. // ------------------------------------------------------------ +use crate::{HSTRING, PCWSTR}; use mssf_com::FabricCommon::{IFabricStringResult, IFabricStringResult_Impl}; -use windows_core::{implement, HSTRING, PCWSTR}; +use windows_core::implement; // Basic implementation of fabric string result // usually used as string return value to fabric runtime. @@ -89,8 +90,8 @@ mod test { use crate::strings::HSTRINGWrap; use super::StringResult; + use crate::HSTRING; use mssf_com::FabricCommon::IFabricStringResult; - use windows_core::HSTRING; #[test] fn test_str_addr() { diff --git a/crates/libs/core/src/sync/cancel.rs b/crates/libs/core/src/sync/cancel.rs index 576748a..69d28f8 100644 --- a/crates/libs/core/src/sync/cancel.rs +++ b/crates/libs/core/src/sync/cancel.rs @@ -127,21 +127,21 @@ where } impl IFabricAsyncOperationContext_Impl for BridgeContext3 { - fn IsCompleted(&self) -> ::windows::Win32::Foundation::BOOLEAN { + fn IsCompleted(&self) -> crate::BOOLEAN { self.is_completed.get().into() } // This always returns false because we defer all tasks in the background executuor. - fn CompletedSynchronously(&self) -> ::windows::Win32::Foundation::BOOLEAN { + fn CompletedSynchronously(&self) -> crate::BOOLEAN { self.is_completed_synchronously.into() } - fn Callback(&self) -> ::windows_core::Result { + fn Callback(&self) -> crate::Result { let cp = self.callback.clone(); Ok(cp) } - fn Cancel(&self) -> ::windows_core::Result<()> { + fn Cancel(&self) -> crate::Result<()> { self.token.cancel(); Ok(()) } diff --git a/crates/libs/core/src/sync/mod.rs b/crates/libs/core/src/sync/mod.rs index 1dd7a3d..2d7ee8d 100644 --- a/crates/libs/core/src/sync/mod.rs +++ b/crates/libs/core/src/sync/mod.rs @@ -169,9 +169,9 @@ mod tests { }, }; + use crate::{Interface, HSTRING}; use tokio::sync::oneshot::Sender; - use windows::core::implement; - use windows_core::{Interface, HSTRING}; + use windows_core::implement; use super::{oneshot_channel, FabricReceiver, SBox}; diff --git a/crates/libs/core/src/sync/wait.rs b/crates/libs/core/src/sync/wait.rs index 024682d..b6658e0 100644 --- a/crates/libs/core/src/sync/wait.rs +++ b/crates/libs/core/src/sync/wait.rs @@ -11,7 +11,7 @@ use mssf_com::FabricCommon::{ IFabricAsyncOperationContext, IFabricAsyncOperationContext_Impl, }; use tracing::info; -use windows::core::implement; +use windows_core::implement; #[derive(Debug)] #[implement(IFabricAsyncOperationCallback)] @@ -92,22 +92,22 @@ impl AsyncContext { } impl IFabricAsyncOperationContext_Impl for AsyncContext { - fn IsCompleted(&self) -> windows::Win32::Foundation::BOOLEAN { - windows::Win32::Foundation::BOOLEAN::from(true) + fn IsCompleted(&self) -> crate::BOOLEAN { + crate::BOOLEAN::from(true) } - fn CompletedSynchronously(&self) -> windows::Win32::Foundation::BOOLEAN { - windows::Win32::Foundation::BOOLEAN::from(true) + fn CompletedSynchronously(&self) -> crate::BOOLEAN { + crate::BOOLEAN::from(true) } - fn Callback(&self) -> windows::core::Result { + fn Callback(&self) -> crate::Result { info!("AsyncContext::Callback"); // get a view of the callback let callback_copy: IFabricAsyncOperationCallback = self.callback_.clone(); Ok(callback_copy) } - fn Cancel(&self) -> windows::core::Result<()> { + fn Cancel(&self) -> crate::Result<()> { info!("AsyncContext::Cancel"); Ok(()) } diff --git a/crates/libs/core/src/types/client/mod.rs b/crates/libs/core/src/types/client/mod.rs index 407703a..aa1f6d6 100644 --- a/crates/libs/core/src/types/client/mod.rs +++ b/crates/libs/core/src/types/client/mod.rs @@ -16,8 +16,8 @@ pub use partition::*; mod node; pub use node::*; mod replica; +use crate::HSTRING; pub use replica::*; -use windows_core::HSTRING; // FABRIC_SERVICE_NOTIFICATION_FILTER_FLAGS bitflags::bitflags! { diff --git a/crates/libs/core/src/types/client/node.rs b/crates/libs/core/src/types/client/node.rs index 7907df0..7e8ec69 100644 --- a/crates/libs/core/src/types/client/node.rs +++ b/crates/libs/core/src/types/client/node.rs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. // ------------------------------------------------------------ +use crate::HSTRING; use crate::{ iter::{FabricIter, FabricListAccessor}, strings::HSTRINGWrap, @@ -20,7 +21,6 @@ use mssf_com::{ FABRIC_QUERY_NODE_STATUS_FILTER_UP, }, }; -use windows_core::HSTRING; pub struct PagingStatus { pub continuation_token: HSTRING, diff --git a/crates/libs/core/src/types/client/partition.rs b/crates/libs/core/src/types/client/partition.rs index a54189e..cad035b 100644 --- a/crates/libs/core/src/types/client/partition.rs +++ b/crates/libs/core/src/types/client/partition.rs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. // ------------------------------------------------------------ +use crate::{GUID, HSTRING}; use mssf_com::{ FabricClient::IFabricGetPartitionListResult2, FabricTypes::{ @@ -18,7 +19,6 @@ use mssf_com::{ FABRIC_STATELESS_SERVICE_PARTITION_QUERY_RESULT_ITEM, FABRIC_URI, }, }; -use windows_core::{GUID, HSTRING}; use crate::{ iter::{FabricIter, FabricListAccessor}, diff --git a/crates/libs/core/src/types/client/replica.rs b/crates/libs/core/src/types/client/replica.rs index e8a8419..75a427c 100644 --- a/crates/libs/core/src/types/client/replica.rs +++ b/crates/libs/core/src/types/client/replica.rs @@ -1,3 +1,4 @@ +use crate::{GUID, HSTRING, PCWSTR}; use mssf_com::{ FabricClient::IFabricGetReplicaListResult2, FabricTypes::{ @@ -12,7 +13,6 @@ use mssf_com::{ FABRIC_STATELESS_SERVICE_INSTANCE_QUERY_RESULT_ITEM, }, }; -use windows_core::{GUID, HSTRING, PCWSTR}; use crate::{ iter::{FabricIter, FabricListAccessor}, diff --git a/crates/libs/core/src/types/common/metrics.rs b/crates/libs/core/src/types/common/metrics.rs index 10b574c..b1265d0 100644 --- a/crates/libs/core/src/types/common/metrics.rs +++ b/crates/libs/core/src/types/common/metrics.rs @@ -4,9 +4,9 @@ // ------------------------------------------------------------ // mod for handling fabric metrics +use crate::{HSTRING, PCWSTR}; use mssf_com::FabricTypes::FABRIC_LOAD_METRIC; use std::marker::PhantomData; -use windows_core::{HSTRING, PCWSTR}; // FABRIC_LOAD_METRIC pub struct LoadMetric { diff --git a/crates/libs/core/src/types/common/partition.rs b/crates/libs/core/src/types/common/partition.rs index 8b17e51..5d9dd55 100644 --- a/crates/libs/core/src/types/common/partition.rs +++ b/crates/libs/core/src/types/common/partition.rs @@ -3,13 +3,13 @@ // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. // ------------------------------------------------------------ +use crate::{GUID, HSTRING}; use mssf_com::FabricTypes::{ FABRIC_INT64_RANGE_PARTITION_INFORMATION, FABRIC_NAMED_PARTITION_INFORMATION, FABRIC_SERVICE_PARTITION_INFORMATION, FABRIC_SERVICE_PARTITION_KIND_INT64_RANGE, FABRIC_SERVICE_PARTITION_KIND_INVALID, FABRIC_SERVICE_PARTITION_KIND_NAMED, FABRIC_SERVICE_PARTITION_KIND_SINGLETON, FABRIC_SINGLETON_PARTITION_INFORMATION, }; -use windows_core::GUID; use crate::strings::HSTRINGWrap; @@ -29,15 +29,15 @@ pub struct SingletonPartitionInfomation { #[derive(Debug, Clone)] pub struct Int64PartitionInfomation { - pub id: ::windows_core::GUID, + pub id: GUID, pub low_key: i64, pub high_key: i64, } #[derive(Debug, Clone)] pub struct NamedPartitionInfomation { - pub id: ::windows_core::GUID, - pub name: ::windows_core::HSTRING, + pub id: GUID, + pub name: HSTRING, } impl From<&FABRIC_SINGLETON_PARTITION_INFORMATION> for SingletonPartitionInfomation { diff --git a/crates/samples/client/Cargo.toml b/crates/samples/client/Cargo.toml index 8bd1d04..7f7eaa0 100644 --- a/crates/samples/client/Cargo.toml +++ b/crates/samples/client/Cargo.toml @@ -3,17 +3,7 @@ name = "samples_client" version = "0.0.1" edition = "2018" -[dependencies.windows] -version = "0.57" -features = [ - "implement" -] - -[dependencies.mssf-com] -path = "../../libs/com" - -[dependencies.mssf-core] -path = "../../libs/core" - [dependencies] -windows-core = "0.57" \ No newline at end of file +windows-core.workspace = true +mssf-com.workspace = true +mssf-core.workspace = true \ No newline at end of file diff --git a/crates/samples/client/src/main.rs b/crates/samples/client/src/main.rs index 535ae9b..6700c36 100644 --- a/crates/samples/client/src/main.rs +++ b/crates/samples/client/src/main.rs @@ -9,7 +9,7 @@ use mssf_com::FabricTypes::{FABRIC_NODE_QUERY_DESCRIPTION, FABRIC_NODE_QUERY_RES use mssf_core::sync::wait::WaitableCallback; use windows_core::Interface; -fn main() -> windows::core::Result<()> { +fn main() -> mssf_core::Result<()> { println!("GetNodeCli"); let rawclient = unsafe { diff --git a/crates/samples/echomain-stateful/Cargo.toml b/crates/samples/echomain-stateful/Cargo.toml index fcc2007..5d10f6a 100644 --- a/crates/samples/echomain-stateful/Cargo.toml +++ b/crates/samples/echomain-stateful/Cargo.toml @@ -6,22 +6,9 @@ edition = "2018" [dependencies] tracing.workspace = true tracing-subscriber.workspace = true -ctrlc = { version = "3.0", features = ["termination"] } -tokio = { version = "1", features = ["full"] } -windows-core = "0.57" - -[dependencies.windows] -version = "0.57" -features = [ - "implement" -] - -[dependencies.mssf-com] -path = "../../libs/com" - -[dependencies.mssf-core] -path = "../../libs/core" -# We don't showcase config integration in this particular example -default-features = false -features = ["tokio_async"] +ctrlc.workspace = true +tokio.workspace = true +windows-core.workspace = true +mssf-com.workspace = true +mssf-core = { workspace = true, features = []} # do not use any features diff --git a/crates/samples/echomain-stateful/src/app.rs b/crates/samples/echomain-stateful/src/app.rs index ca17376..c70d457 100644 --- a/crates/samples/echomain-stateful/src/app.rs +++ b/crates/samples/echomain-stateful/src/app.rs @@ -24,12 +24,12 @@ use mssf_com::FabricTypes::{ FABRIC_REPLICA_OPEN_MODE_INVALID, FABRIC_REPLICA_ROLE, FABRIC_REPLICA_SET_CONFIGURATION, FABRIC_REPLICA_SET_QUORUM_MODE, FABRIC_URI, }; +use mssf_core::w; +use mssf_core::HSTRING; use mssf_core::{strings::HSTRINGWrap, sync::wait::AsyncContext}; use tokio::sync::oneshot::{self, Sender}; use tracing::info; -use windows::core::implement; -use windows::core::w; -use windows_core::HSTRING; +use windows_core::implement; mod echo; @@ -62,13 +62,13 @@ impl IFabricStatefulServiceFactory_Impl for StatefulServiceFactory { #[allow(clippy::not_unsafe_ptr_arg_deref)] fn CreateReplica( &self, - servicetypename: &::windows::core::PCWSTR, + servicetypename: &mssf_core::PCWSTR, servicename: FABRIC_URI, initializationdatalength: u32, initializationdata: *const u8, - partitionid: &::windows::core::GUID, + partitionid: &mssf_core::GUID, instanceid: i64, - ) -> ::windows::core::Result { + ) -> mssf_core::Result { let mut init_data: String = "".to_string(); if initializationdata.is_null() && initializationdatalength != 0 { init_data = unsafe { @@ -114,7 +114,7 @@ impl IFabricReplicator_Impl for AppFabricReplicator { fn BeginOpen( &self, callback: ::core::option::Option<&IFabricAsyncOperationCallback>, - ) -> windows::core::Result { + ) -> mssf_core::Result { info!("AppFabricReplicator::BeginOpen"); let ctx: IFabricAsyncOperationContext = AsyncContext::new(callback).into(); // invoke callback right away @@ -125,7 +125,7 @@ impl IFabricReplicator_Impl for AppFabricReplicator { fn EndOpen( &self, _context: ::core::option::Option<&IFabricAsyncOperationContext>, - ) -> windows_core::Result { + ) -> mssf_core::Result { info!("AppFabricReplicator::EndOpen"); let addr = echo::get_addr(self.port_, self.hostname_.clone()); info!("AppFabricReplicator::EndOpen {}", addr); @@ -138,7 +138,7 @@ impl IFabricReplicator_Impl for AppFabricReplicator { _epoch: *const FABRIC_EPOCH, _role: FABRIC_REPLICA_ROLE, callback: ::core::option::Option<&IFabricAsyncOperationCallback>, - ) -> windows_core::Result { + ) -> mssf_core::Result { info!("AppFabricReplicator::BeginChangeRole"); let ctx: IFabricAsyncOperationContext = AsyncContext::new(callback).into(); // invoke callback right away @@ -149,7 +149,7 @@ impl IFabricReplicator_Impl for AppFabricReplicator { fn EndChangeRole( &self, _context: ::core::option::Option<&IFabricAsyncOperationContext>, - ) -> ::windows_core::Result<()> { + ) -> mssf_core::Result<()> { info!("AppFabricReplicator::EndChangeRole"); Ok(()) } @@ -158,7 +158,7 @@ impl IFabricReplicator_Impl for AppFabricReplicator { &self, _epoch: *const FABRIC_EPOCH, callback: ::core::option::Option<&IFabricAsyncOperationCallback>, - ) -> windows_core::Result { + ) -> mssf_core::Result { info!("AppFabricReplicator::BeginUpdateEpoch"); let ctx: IFabricAsyncOperationContext = AsyncContext::new(callback).into(); // invoke callback right away @@ -168,14 +168,14 @@ impl IFabricReplicator_Impl for AppFabricReplicator { fn EndUpdateEpoch( &self, _context: ::core::option::Option<&IFabricAsyncOperationContext>, - ) -> ::windows_core::Result<()> { + ) -> ::mssf_core::Result<()> { info!("AppFabricReplicator::EndUpdateEpoch"); Ok(()) } fn BeginClose( &self, callback: ::core::option::Option<&IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> ::mssf_core::Result { info!("AppFabricReplicator::BeginClose"); let ctx: IFabricAsyncOperationContext = AsyncContext::new(callback).into(); // invoke callback right away @@ -185,19 +185,19 @@ impl IFabricReplicator_Impl for AppFabricReplicator { fn EndClose( &self, _context: ::core::option::Option<&IFabricAsyncOperationContext>, - ) -> ::windows_core::Result<()> { + ) -> ::mssf_core::Result<()> { info!("AppFabricReplicator::EndClose"); Ok(()) } fn Abort(&self) { info!("AppFabricReplicator::Abort"); } - fn GetCurrentProgress(&self) -> ::windows_core::Result { + fn GetCurrentProgress(&self) -> ::mssf_core::Result { info!("AppFabricReplicator::GetCurrentProgress"); let v = 0; Ok(v) } - fn GetCatchUpCapability(&self) -> ::windows_core::Result { + fn GetCatchUpCapability(&self) -> ::mssf_core::Result { info!("AppFabricReplicator::GetCatchUpCapability"); let v = 0; Ok(v) @@ -209,7 +209,7 @@ impl IFabricPrimaryReplicator_Impl for AppFabricReplicator { fn BeginOnDataLoss( &self, callback: ::core::option::Option<&IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> ::mssf_core::Result { info!("AppFabricReplicator::BeginOnDataLoss"); let ctx: IFabricAsyncOperationContext = AsyncContext::new(callback).into(); // invoke callback right away @@ -219,7 +219,7 @@ impl IFabricPrimaryReplicator_Impl for AppFabricReplicator { fn EndOnDataLoss( &self, _context: ::core::option::Option<&IFabricAsyncOperationContext>, - ) -> ::windows_core::Result { + ) -> ::mssf_core::Result { info!("AppFabricReplicator::EndOnDataLoss"); let v = 0; Ok(v) @@ -228,7 +228,7 @@ impl IFabricPrimaryReplicator_Impl for AppFabricReplicator { &self, _currentconfiguration: *const FABRIC_REPLICA_SET_CONFIGURATION, _previousconfiguration: *const FABRIC_REPLICA_SET_CONFIGURATION, - ) -> ::windows_core::Result<()> { + ) -> ::mssf_core::Result<()> { info!("AppFabricReplicator::UpdateCatchUpReplicaSetConfiguration"); Ok(()) } @@ -236,7 +236,7 @@ impl IFabricPrimaryReplicator_Impl for AppFabricReplicator { &self, _catchupmode: FABRIC_REPLICA_SET_QUORUM_MODE, callback: ::core::option::Option<&IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> ::mssf_core::Result { info!("AppFabricReplicator::BeginWaitForCatchUpQuorum"); let ctx: IFabricAsyncOperationContext = AsyncContext::new(callback).into(); // invoke callback right away @@ -246,14 +246,14 @@ impl IFabricPrimaryReplicator_Impl for AppFabricReplicator { fn EndWaitForCatchUpQuorum( &self, _context: ::core::option::Option<&IFabricAsyncOperationContext>, - ) -> ::windows_core::Result<()> { + ) -> ::mssf_core::Result<()> { info!("AppFabricReplicator::EndWaitForCatchUpQuorum"); Ok(()) } fn UpdateCurrentReplicaSetConfiguration( &self, _currentconfiguration: *const FABRIC_REPLICA_SET_CONFIGURATION, - ) -> ::windows_core::Result<()> { + ) -> ::mssf_core::Result<()> { info!("AppFabricReplicator::UpdateCurrentReplicaSetConfiguration"); Ok(()) } @@ -261,7 +261,7 @@ impl IFabricPrimaryReplicator_Impl for AppFabricReplicator { &self, _replica: *const FABRIC_REPLICA_INFORMATION, callback: ::core::option::Option<&IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> ::mssf_core::Result { info!("AppFabricReplicator::BeginBuildReplica"); let ctx: IFabricAsyncOperationContext = AsyncContext::new(callback).into(); // invoke callback right away @@ -271,11 +271,11 @@ impl IFabricPrimaryReplicator_Impl for AppFabricReplicator { fn EndBuildReplica( &self, _context: ::core::option::Option<&IFabricAsyncOperationContext>, - ) -> ::windows_core::Result<()> { + ) -> ::mssf_core::Result<()> { info!("AppFabricReplicator::EndBuildReplica"); Ok(()) } - fn RemoveReplica(&self, replicaid: i64) -> ::windows_core::Result<()> { + fn RemoveReplica(&self, replicaid: i64) -> ::mssf_core::Result<()> { info!( "AppFabricReplicator::UpdateCurrentReplicaSetConfiguration {} ", replicaid @@ -314,7 +314,7 @@ impl IFabricStatefulServiceReplica_Impl for AppInstance { openmode: FABRIC_REPLICA_OPEN_MODE, partition: ::core::option::Option<&IFabricStatefulServicePartition>, callback: ::core::option::Option<&IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> ::mssf_core::Result { info!("echo_replica::BeginOpen"); if openmode == FABRIC_REPLICA_OPEN_MODE_INVALID { @@ -348,7 +348,7 @@ impl IFabricStatefulServiceReplica_Impl for AppInstance { fn EndOpen( &self, context: ::core::option::Option<&IFabricAsyncOperationContext>, - ) -> ::windows_core::Result { + ) -> ::mssf_core::Result { info!("AppInstance::EndOpen"); let completed = unsafe { context @@ -367,7 +367,7 @@ impl IFabricStatefulServiceReplica_Impl for AppInstance { fn BeginClose( &self, callback: ::core::option::Option<&IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> ::mssf_core::Result { info!("AppInstance::BeginClose"); // triggers shutdown to tokio @@ -405,7 +405,7 @@ impl IFabricStatefulServiceReplica_Impl for AppInstance { fn EndClose( &self, context: ::core::option::Option<&IFabricAsyncOperationContext>, - ) -> ::windows_core::Result<()> { + ) -> ::mssf_core::Result<()> { info!("AppInstance::EndClose"); let completed = unsafe { context @@ -428,7 +428,7 @@ impl IFabricStatefulServiceReplica_Impl for AppInstance { &self, _newrole: FABRIC_REPLICA_ROLE, callback: ::core::option::Option<&IFabricAsyncOperationCallback>, - ) -> ::windows_core::Result { + ) -> ::mssf_core::Result { info!("AppInstance::BeginChangeRole"); let ctx: IFabricAsyncOperationContext = AsyncContext::new(callback).into(); // invoke callback right away @@ -439,7 +439,7 @@ impl IFabricStatefulServiceReplica_Impl for AppInstance { fn EndChangeRole( &self, _context: ::core::option::Option<&IFabricAsyncOperationContext>, - ) -> ::windows_core::Result { + ) -> ::mssf_core::Result { info!("AppInstance::EndChangeRole"); let addr = echo::get_addr(self.port_, self.hostname_.clone()); info!("AppInstance::EndChangeRole {}", addr); diff --git a/crates/samples/echomain-stateful/src/app/echo.rs b/crates/samples/echomain-stateful/src/app/echo.rs index 4c95ed7..d822aa7 100644 --- a/crates/samples/echomain-stateful/src/app/echo.rs +++ b/crates/samples/echomain-stateful/src/app/echo.rs @@ -7,11 +7,11 @@ use std::io::Error; +use mssf_core::HSTRING; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio::net::TcpListener; use tokio::sync::oneshot::Receiver; use tracing::info; -use windows::core::HSTRING; pub fn get_addr(port: u32, hostname: HSTRING) -> String { let mut addr = String::new(); diff --git a/crates/samples/echomain-stateful/src/main.rs b/crates/samples/echomain-stateful/src/main.rs index 5827754..a53a0bd 100644 --- a/crates/samples/echomain-stateful/src/main.rs +++ b/crates/samples/echomain-stateful/src/main.rs @@ -10,13 +10,13 @@ use mssf_com::FabricRuntime::{ IFabricRuntime, }; use mssf_core::sync::wait::WaitableCallback; +use mssf_core::w; +use mssf_core::{Interface, HSTRING}; use std::sync::mpsc::channel; use tracing::info; -use windows::core::w; -use windows::core::{Interface, HSTRING}; pub mod app; -fn main() -> windows::core::Result<()> { +fn main() -> mssf_core::Result<()> { tracing_subscriber::fmt().init(); // set ctrc event let (tx, rx) = channel(); diff --git a/crates/samples/echomain-stateful2/Cargo.toml b/crates/samples/echomain-stateful2/Cargo.toml index 82222e5..10f25f9 100644 --- a/crates/samples/echomain-stateful2/Cargo.toml +++ b/crates/samples/echomain-stateful2/Cargo.toml @@ -8,19 +8,7 @@ edition = "2021" [dependencies] tracing.workspace = true tracing-subscriber.workspace = true -tokio = { version = "1", features = ["full"] } +tokio.workspace = true tokio-util.workspace = true -windows-core = "0.57" -trait-variant = "0.1.1" - -[dependencies.windows] -version = "0.57" -features = [ - "implement" -] - -[dependencies.mssf-com] -path = "../../libs/com" - -[dependencies.mssf-core] -path = "../../libs/core" \ No newline at end of file +trait-variant.workspace = true +mssf-core.workspace = true \ No newline at end of file diff --git a/crates/samples/echomain-stateful2/src/echo.rs b/crates/samples/echomain-stateful2/src/echo.rs index 59acab3..a8e1abc 100644 --- a/crates/samples/echomain-stateful2/src/echo.rs +++ b/crates/samples/echomain-stateful2/src/echo.rs @@ -9,12 +9,12 @@ use std::io::Error; use mssf_core::runtime::stateful::StatefulServicePartition; use mssf_core::types::LoadMetric; +use mssf_core::HSTRING; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio::net::TcpListener; use tokio::select; use tokio_util::sync::CancellationToken; use tracing::{error, info}; -use windows::core::HSTRING; pub fn get_addr(port: u32, hostname: HSTRING) -> String { let mut addr = String::new(); diff --git a/crates/samples/echomain-stateful2/src/main.rs b/crates/samples/echomain-stateful2/src/main.rs index 80270b8..4d0ce30 100644 --- a/crates/samples/echomain-stateful2/src/main.rs +++ b/crates/samples/echomain-stateful2/src/main.rs @@ -4,20 +4,12 @@ // ------------------------------------------------------------ use crate::statefulstore::Factory; -use mssf_com::{ - FabricCommon::IFabricAsyncOperationCallback, - FabricRuntime::{FabricBeginGetNodeContext, FabricEndGetNodeContext, IFabricNodeContextResult}, -}; -use mssf_core::{ - runtime::{ - executor::{DefaultExecutor, Executor}, - ActivationContext, - }, - sync::wait::WaitableCallback, +use mssf_core::runtime::{ + executor::{DefaultExecutor, Executor}, + ActivationContext, }; +use mssf_core::HSTRING; use tracing::info; -use windows::core::Interface; -use windows_core::HSTRING; mod echo; mod statefulstore; @@ -26,7 +18,7 @@ mod statefulstore; #[cfg(test)] mod test; -fn main() -> windows::core::Result<()> { +fn main() -> mssf_core::Result<()> { tracing_subscriber::fmt().init(); info!("main start"); @@ -37,7 +29,7 @@ fn main() -> windows::core::Result<()> { let endpoint = actctx .get_endpoint_resource(&HSTRING::from("KvReplicatorEndpoint")) .unwrap(); - let hostname = get_hostname(); + let hostname = get_hostname().expect("cannot get hostname"); let factory = Factory::create(endpoint.port, hostname, e.clone()); runtime @@ -48,21 +40,7 @@ fn main() -> windows::core::Result<()> { Ok(()) } -fn get_hostname() -> HSTRING { - let (token, callback) = WaitableCallback::channel(); - - let callback_arg = callback - .cast::() - .expect("castfailed"); - let ctx = unsafe { FabricBeginGetNodeContext(1000, &callback_arg).expect("getctx failed") }; - - token.wait(); - - let result_raw = unsafe { FabricEndGetNodeContext(&ctx).expect("end failed") }; - let result = unsafe { IFabricNodeContextResult::from_raw(result_raw) }; - let node_ctx = unsafe { result.get_NodeContext() }; - let hostname_raw = unsafe { (*node_ctx).IPAddressOrFQDN }; - let ret = HSTRING::from_wide(unsafe { hostname_raw.as_wide() }).expect("hstring"); - info!("got hostname: {:?}", ret); - ret +fn get_hostname() -> mssf_core::Result { + let node_ctx = mssf_core::runtime::node_context::NodeContext::get_sync()?; + Ok(node_ctx.ip_address_or_fqdn) } diff --git a/crates/samples/echomain-stateful2/src/statefulstore.rs b/crates/samples/echomain-stateful2/src/statefulstore.rs index ebc492a..3761f78 100644 --- a/crates/samples/echomain-stateful2/src/statefulstore.rs +++ b/crates/samples/echomain-stateful2/src/statefulstore.rs @@ -3,7 +3,6 @@ // Licensed under the MIT License (MIT). See License.txt in the repo root for license information. // ------------------------------------------------------------ -use mssf_com::FabricTypes::FABRIC_REPLICATOR_ADDRESS; use mssf_core::{ runtime::{ executor::{DefaultExecutor, Executor}, @@ -12,14 +11,13 @@ use mssf_core::{ StatefulServiceReplica, }, stateful_types::{Epoch, OpenMode, ReplicaInfo, ReplicaSetConfig, ReplicaSetQuarumMode}, - store_types::ReplicatorSettings, }, types::ReplicaRole, }; +use mssf_core::{Error, HSTRING}; use std::{cell::Cell, sync::Mutex}; use tokio_util::sync::CancellationToken; use tracing::info; -use windows_core::{Error, HSTRING}; use crate::echo; @@ -63,14 +61,14 @@ impl AppFabricReplicator { // This is basic implementation of Replicator impl Replicator for AppFabricReplicator { - async fn open(&self, _: CancellationToken) -> windows::core::Result { + async fn open(&self, _: CancellationToken) -> mssf_core::Result { info!("AppFabricReplicator2::Replicator::Open"); let addr = get_addr(self.port_, self.hostname_.clone()); let str_res = HSTRING::from(addr); Ok(str_res) } - async fn close(&self, _: CancellationToken) -> windows::core::Result<()> { + async fn close(&self, _: CancellationToken) -> mssf_core::Result<()> { info!("AppFabricReplicator2::Replicator::close"); Ok(()) } @@ -80,26 +78,22 @@ impl Replicator for AppFabricReplicator { _epoch: &Epoch, _role: &ReplicaRole, _: CancellationToken, - ) -> windows::core::Result<()> { + ) -> mssf_core::Result<()> { info!("AppFabricReplicator2::Replicator::change_role"); Ok(()) } - async fn update_epoch( - &self, - _epoch: &Epoch, - _: CancellationToken, - ) -> windows::core::Result<()> { + async fn update_epoch(&self, _epoch: &Epoch, _: CancellationToken) -> mssf_core::Result<()> { info!("AppFabricReplicator2::Replicator::update_epoch"); Ok(()) } - fn get_current_progress(&self) -> windows::core::Result { + fn get_current_progress(&self) -> mssf_core::Result { info!("AppFabricReplicator2::Replicator::get_current_progress"); Ok(0) } - fn get_catch_up_capability(&self) -> windows::core::Result { + fn get_catch_up_capability(&self) -> mssf_core::Result { info!("AppFabricReplicator2::Replicator::get_catch_up_capability"); Ok(0) } @@ -111,7 +105,7 @@ impl Replicator for AppFabricReplicator { // This is basic implementation of PrimaryReplicator impl PrimaryReplicator for AppFabricReplicator { - async fn on_data_loss(&self, _: CancellationToken) -> windows::core::Result { + async fn on_data_loss(&self, _: CancellationToken) -> mssf_core::Result { info!("AppFabricReplicator2::PrimaryReplicator::on_data_loss"); Ok(0) } @@ -120,7 +114,7 @@ impl PrimaryReplicator for AppFabricReplicator { &self, _currentconfiguration: &ReplicaSetConfig, _previousconfiguration: &ReplicaSetConfig, - ) -> windows::core::Result<()> { + ) -> mssf_core::Result<()> { info!("AppFabricReplicator2::PrimaryReplicator::update_catch_up_replica_set_configuration"); Ok(()) } @@ -129,7 +123,7 @@ impl PrimaryReplicator for AppFabricReplicator { &self, _catchupmode: ReplicaSetQuarumMode, _: CancellationToken, - ) -> windows::core::Result<()> { + ) -> mssf_core::Result<()> { info!("AppFabricReplicator2::PrimaryReplicator::wait_for_catch_up_quorum"); Ok(()) } @@ -137,7 +131,7 @@ impl PrimaryReplicator for AppFabricReplicator { fn update_current_replica_set_configuration( &self, _currentconfiguration: &ReplicaSetConfig, - ) -> windows::core::Result<()> { + ) -> mssf_core::Result<()> { info!("AppFabricReplicator2::PrimaryReplicator::update_current_replica_set_configuration"); Ok(()) } @@ -146,12 +140,12 @@ impl PrimaryReplicator for AppFabricReplicator { &self, _replica: &ReplicaInfo, _: CancellationToken, - ) -> windows::core::Result<()> { + ) -> mssf_core::Result<()> { info!("AppFabricReplicator2::PrimaryReplicator::build_replica"); Ok(()) } - fn remove_replica(&self, _replicaid: i64) -> windows::core::Result<()> { + fn remove_replica(&self, _replicaid: i64) -> mssf_core::Result<()> { info!("AppFabricReplicator2::PrimaryReplicator::remove_replica"); Ok(()) } @@ -160,10 +154,10 @@ impl PrimaryReplicator for AppFabricReplicator { impl StatefulServiceFactory for Factory { fn create_replica( &self, - servicetypename: &windows_core::HSTRING, - servicename: &windows_core::HSTRING, + servicetypename: &mssf_core::HSTRING, + servicename: &mssf_core::HSTRING, initializationdata: &[u8], - partitionid: &windows::core::GUID, + partitionid: &mssf_core::GUID, replicaid: i64, ) -> Result { info!( @@ -174,19 +168,6 @@ impl StatefulServiceFactory for Factory { partitionid, replicaid ); - let settings = ReplicatorSettings { - flags: FABRIC_REPLICATOR_ADDRESS.0 as u32, - replicator_address: HSTRING::from(get_addr( - self.replication_port, - self.hostname.clone(), - )), - ..Default::default() - }; - - info!( - "Factory::create_replica using address {}", - settings.replicator_address - ); let svc = Service::new( self.rt.clone(), @@ -260,7 +241,7 @@ impl StatefulServiceReplica for Replica { openmode: OpenMode, partition: &StatefulServicePartition, _: CancellationToken, - ) -> windows::core::Result { + ) -> mssf_core::Result { // should be primary replicator info!("Replica::open {:?}", openmode); self.svc.start_loop_in_background(partition); @@ -270,7 +251,7 @@ impl StatefulServiceReplica for Replica { &self, newrole: ReplicaRole, _: CancellationToken, - ) -> ::windows_core::Result { + ) -> mssf_core::Result { info!("Replica::change_role {:?}", newrole); if newrole == ReplicaRole::Primary { info!("primary {:?}", self.svc.tcp_port); @@ -280,7 +261,7 @@ impl StatefulServiceReplica for Replica { let str_res = HSTRING::from(addr); Ok(str_res) } - async fn close(&self, _: CancellationToken) -> windows::core::Result<()> { + async fn close(&self, _: CancellationToken) -> mssf_core::Result<()> { info!("Replica::close"); self.svc.stop(); Ok(()) diff --git a/crates/samples/echomain-stateful2/src/test.rs b/crates/samples/echomain-stateful2/src/test.rs index 3d15b5a..cdde932 100644 --- a/crates/samples/echomain-stateful2/src/test.rs +++ b/crates/samples/echomain-stateful2/src/test.rs @@ -167,7 +167,7 @@ impl TestClient { async fn resolve_with_prev( &self, prev: Option<&ResolvedServicePartition>, - ) -> windows_core::Result { + ) -> mssf_core::Result { let mgmt = self.fc.get_service_manager(); mgmt.resolve_service_partition( &self.service_uri, diff --git a/crates/samples/echomain/Cargo.toml b/crates/samples/echomain/Cargo.toml index 3642cb5..9e2290a 100644 --- a/crates/samples/echomain/Cargo.toml +++ b/crates/samples/echomain/Cargo.toml @@ -6,9 +6,7 @@ edition = "2018" [dependencies] tracing.workspace = true tracing-subscriber.workspace = true -tokio = { version = "1", features = ["full"] } -serde = "*" -serde_derive = "*" - -[dependencies.mssf-core] -path = "../../libs/core" +tokio.workspace = true +serde.workspace = true +serde_derive.workspace = true +mssf-core.workspace = true diff --git a/crates/samples/kvstore/Cargo.toml b/crates/samples/kvstore/Cargo.toml index 3e748d9..8e64c8e 100644 --- a/crates/samples/kvstore/Cargo.toml +++ b/crates/samples/kvstore/Cargo.toml @@ -8,11 +8,7 @@ edition = "2021" [dependencies] tracing.workspace = true tracing-subscriber.workspace = true -tokio = { version = "1", features = ["full"] } -windows-core = "0.57" - -[dependencies.mssf-com] -path = "../../libs/com" - -[dependencies.mssf-core] -path = "../../libs/core" \ No newline at end of file +tokio.workspace = true +windows-core.workspace = true +mssf-com.workspace = true +mssf-core.workspace = true \ No newline at end of file diff --git a/crates/samples/no_default_features/Cargo.toml b/crates/samples/no_default_features/Cargo.toml index 32ea76b..4684f7c 100644 --- a/crates/samples/no_default_features/Cargo.toml +++ b/crates/samples/no_default_features/Cargo.toml @@ -7,9 +7,11 @@ edition = "2021" [lib] crate-type = ["cdylib","staticlib"] -[dependencies.mssf-com] -path = "../../libs/com" +[dependencies] +mssf-com.workspace = true +# disable all features [dependencies.mssf-core] path = "../../libs/core" default-features = false +features = []