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

Rename hstring to wstring #108

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crates/libs/core/src/client/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use mssf_com::FabricClient::{
IFabricGatewayInformationResult,
};

use crate::{strings::HSTRINGWrap, types::NodeId};
use crate::{strings::WStringWrap, types::NodeId};

/// Internal trait that rust code implements that can be bridged into IFabricClientConnectionEventHandler.
/// Not exposed to user.
Expand All @@ -21,20 +21,20 @@ pub trait ClientConnectionEventHandler: 'static {
/// Traslated from IFabricGatewayInformationResult
#[derive(Debug, Clone)]
pub struct GatewayInformationResult {
pub node_address: crate::HSTRING,
pub node_address: crate::WString,
pub node_id: NodeId,
pub node_instance_id: u64,
pub node_name: crate::HSTRING,
pub node_name: crate::WString,
}

impl GatewayInformationResult {
fn from_com(com: &IFabricGatewayInformationResult) -> Self {
let info = unsafe { com.get_GatewayInformation().as_ref().unwrap() };
Self {
node_address: HSTRINGWrap::from(info.NodeAddress).into(),
node_address: WStringWrap::from(info.NodeAddress).into(),
node_id: info.NodeId.into(),
node_instance_id: info.NodeInstanceId,
node_name: HSTRINGWrap::from(info.NodeName).into(),
node_name: WStringWrap::from(info.NodeName).into(),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/libs/core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mod tests;

/// Creates FabricClient com object using SF com API.
fn create_local_client_internal<T: Interface>(
connection_strings: Option<&Vec<crate::HSTRING>>,
connection_strings: Option<&Vec<crate::WString>>,
service_notification_handler: Option<&IFabricServiceNotificationEventHandler>,
client_connection_handler: Option<&IFabricClientConnectionEventHandler>,
client_role: Option<ClientRole>,
Expand Down Expand Up @@ -94,7 +94,7 @@ pub struct FabricClientBuilder {
sn_handler: Option<IFabricServiceNotificationEventHandler>,
cc_handler: Option<LambdaClientConnectionNotificationHandler>,
client_role: ClientRole,
connection_strings: Option<Vec<crate::HSTRING>>,
connection_strings: Option<Vec<crate::WString>>,
}

impl Default for FabricClientBuilder {
Expand Down Expand Up @@ -175,7 +175,7 @@ impl FabricClientBuilder {

/// Sets the client connection strings.
/// Example value: localhost:19000
pub fn with_connection_strings(mut self, addrs: Vec<crate::HSTRING>) -> Self {
pub fn with_connection_strings(mut self, addrs: Vec<crate::WString>) -> Self {
self.connection_strings = Some(addrs);
self
}
Expand Down
6 changes: 3 additions & 3 deletions crates/libs/core/src/client/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use mssf_com::{

use crate::{
iter::{FabricIter, FabricListAccessor},
strings::HSTRINGWrap,
strings::WStringWrap,
types::ServicePartitionInformation,
};

Expand All @@ -30,7 +30,7 @@ pub trait ServiceNotificationEventHandler: 'static {
/// If endpoint list is empty, the service is removed.
#[derive(Debug, Clone)]
pub struct ServiceNotification {
pub service_name: crate::HSTRING,
pub service_name: crate::WString,
pub partition_info: Option<ServicePartitionInformation>,
pub partition_id: crate::GUID,
pub endpoints: ServiceEndpointList,
Expand All @@ -42,7 +42,7 @@ impl ServiceNotification {
// SF guarantees this is not null.
let raw = unsafe { com.get_Notification().as_ref().unwrap() };
Self {
service_name: HSTRINGWrap::from(crate::PCWSTR(raw.ServiceName.0)).into(),
service_name: WStringWrap::from(crate::PCWSTR(raw.ServiceName.0)).into(),
partition_info: unsafe {
// It is possible for partition info to be null,
// that is why we make the field as an option.
Expand Down
24 changes: 12 additions & 12 deletions crates/libs/core/src/client/svc_mgmt_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ use mssf_com::{
FABRIC_SERVICE_ROLE_STATELESS, FABRIC_URI,
},
};
use windows_core::{HSTRING, PCWSTR};
use windows_core::{WString, PCWSTR};

use crate::{
iter::{FabricIter, FabricListAccessor},
strings::HSTRINGWrap,
strings::WStringWrap,
sync::{fabric_begin_end_proxy2, CancellationToken, FabricReceiver2},
types::{
RemoveReplicaDescription, RestartReplicaDescription, ServiceNotificationFilterDescription,
Expand Down Expand Up @@ -148,7 +148,7 @@ impl ServiceManagementClient {
// Resolve service partition
pub async fn resolve_service_partition(
&self,
name: &HSTRING,
name: &WString,
key_type: &PartitionKeyType,
prev: Option<&ResolvedServicePartition>,
timeout: Duration,
Expand Down Expand Up @@ -271,7 +271,7 @@ pub enum PartitionKeyType {
Int64(i64),
Invalid,
None,
String(HSTRING),
String(WString),
}

impl PartitionKeyType {
Expand All @@ -287,7 +287,7 @@ impl PartitionKeyType {
ServicePartitionKind::Named => {
let x = data as *mut u16;
assert!(!x.is_null());
let s = HSTRINGWrap::from(PCWSTR::from_raw(x)).into();
let s = WStringWrap::from(PCWSTR::from_raw(x)).into();
PartitionKeyType::String(s)
}
}
Expand Down Expand Up @@ -370,7 +370,7 @@ impl ResolvedServicePartition {

#[derive(Debug)]
pub struct ResolvedServicePartitionInfo {
pub service_name: HSTRING,
pub service_name: WString,
pub service_partition_kind: ServicePartitionKind,
pub partition_key_type: PartitionKeyType,
}
Expand All @@ -379,7 +379,7 @@ impl ResolvedServicePartition {
// Get the service partition info/metadata
pub fn get_info(&self) -> ResolvedServicePartitionInfo {
let raw = unsafe { self.com.get_Partition().as_ref().unwrap() };
let service_name = HSTRINGWrap::from(PCWSTR::from_raw(raw.ServiceName.0)).into();
let service_name = WStringWrap::from(PCWSTR::from_raw(raw.ServiceName.0)).into();
let kind_raw = raw.Info.Kind;
let val = raw.Info.Value;
let service_partition_kind: ServicePartitionKind = kind_raw.into();
Expand Down Expand Up @@ -481,7 +481,7 @@ impl FabricListAccessor<FABRIC_RESOLVED_SERVICE_ENDPOINT> for ResolvedServiceEnd

#[derive(Debug, Clone)]
pub struct ResolvedServiceEndpoint {
pub address: HSTRING,
pub address: WString,
pub role: ServiceEndpointRole,
}

Expand All @@ -496,15 +496,15 @@ impl From<&FABRIC_RESOLVED_SERVICE_ENDPOINT> for ResolvedServiceEndpoint {
fn from(value: &FABRIC_RESOLVED_SERVICE_ENDPOINT) -> Self {
let raw = value;
Self {
address: HSTRINGWrap::from(raw.Address).into(),
address: WStringWrap::from(raw.Address).into(),
role: raw.Role.into(),
}
}
}

#[cfg(test)]
mod tests {
use windows_core::{HSTRING, PCWSTR};
use windows_core::{WString, PCWSTR};

use super::{PartitionKeyType, ServicePartitionKind};

Expand All @@ -524,12 +524,12 @@ mod tests {

#[test]
fn test_conversion_string() {
let src = HSTRING::from("mystr");
let src = WString::from("mystr");
let k = PartitionKeyType::String(src.clone());
// check the raw ptr is ok
let raw = k.get_raw_opt();
let s =
HSTRING::from_wide(unsafe { PCWSTR::from_raw(raw.unwrap() as *const u16).as_wide() });
WString::from_wide(unsafe { PCWSTR::from_raw(raw.unwrap() as *const u16).as_wide() });
assert_eq!(s, src);

let service_type = ServicePartitionKind::Named;
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/core/src/client/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::time::Duration;

use mssf_com::FabricTypes::FABRIC_E_SERVICE_DOES_NOT_EXIST;
use tokio_util::sync::CancellationToken;
use windows_core::HSTRING;
use windows_core::WString;

use crate::{
client::{svc_mgmt_client::PartitionKeyType, FabricClient},
Expand Down Expand Up @@ -81,7 +81,7 @@ async fn test_fabric_client() {
{
let res = smgr
.resolve_service_partition(
&HSTRING::from("fabric:/EchoApp/EchoAppService"),
&WString::from("fabric:/EchoApp/EchoAppService"),
&PartitionKeyType::None,
None,
timeout,
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub mod sync;
pub mod types;

// re-export some windows types
pub use windows_core::{Error, Interface, Result, GUID, HRESULT, HSTRING, PCWSTR};
pub use windows_core::{Error, Interface, Result, WString, GUID, HRESULT, PCWSTR};
// Note cannot re-export windows_core::implement because the macro using it has hard coded mod name.

pub use windows_core::Win32::Foundation::BOOLEAN;
48 changes: 24 additions & 24 deletions crates/libs/core/src/runtime/activation_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use mssf_com::{
};

use crate::{
strings::HSTRINGWrap,
strings::WStringWrap,
types::{EndpointResourceDescription, HealthInformation, HealthReportSendOption},
Error, HSTRING, PCWSTR,
Error, WString, PCWSTR,
};

use super::config::ConfigurationPackage;
Expand All @@ -27,16 +27,16 @@ pub struct CodePackageActivationContext {
/// about the code package and the local runtime environment.
#[derive(Debug, Clone)]
pub struct CodePackageInfo {
pub context_id: HSTRING,
pub code_package_name: HSTRING,
pub code_package_version: HSTRING,
pub work_directory: HSTRING,
pub log_directory: HSTRING,
pub temp_directory: HSTRING,
pub application_name: HSTRING,
pub application_type_name: HSTRING,
pub service_listen_address: HSTRING,
pub service_publish_address: HSTRING,
pub context_id: WString,
pub code_package_name: WString,
pub code_package_version: WString,
pub work_directory: WString,
pub log_directory: WString,
pub temp_directory: WString,
pub application_name: WString,
pub application_type_name: WString,
pub service_listen_address: WString,
pub service_publish_address: WString,
}

impl CodePackageActivationContext {
Expand All @@ -47,7 +47,7 @@ impl CodePackageActivationContext {

pub fn get_endpoint_resource(
&self,
serviceendpointresourcename: &HSTRING,
serviceendpointresourcename: &WString,
) -> crate::Result<EndpointResourceDescription> {
let rs = unsafe {
self.com_impl.GetServiceEndpointResource(PCWSTR::from_raw(
Expand All @@ -61,7 +61,7 @@ impl CodePackageActivationContext {

pub fn get_configuration_package(
&self,
configpackagename: &HSTRING,
configpackagename: &WString,
) -> crate::Result<ConfigurationPackage> {
let c = unsafe {
self.com_impl
Expand All @@ -72,29 +72,29 @@ impl CodePackageActivationContext {

pub fn get_code_package_info(&self) -> CodePackageInfo {
CodePackageInfo {
context_id: HSTRINGWrap::from(unsafe { self.com_impl.get_ContextId() }).into(),
code_package_name: HSTRINGWrap::from(unsafe { self.com_impl.get_CodePackageName() })
context_id: WStringWrap::from(unsafe { self.com_impl.get_ContextId() }).into(),
code_package_name: WStringWrap::from(unsafe { self.com_impl.get_CodePackageName() })
.into(),
code_package_version: HSTRINGWrap::from(unsafe {
code_package_version: WStringWrap::from(unsafe {
self.com_impl.get_CodePackageVersion()
})
.into(),
work_directory: HSTRINGWrap::from(unsafe { self.com_impl.get_WorkDirectory() }).into(),
log_directory: HSTRINGWrap::from(unsafe { self.com_impl.get_LogDirectory() }).into(),
temp_directory: HSTRINGWrap::from(unsafe { self.com_impl.get_TempDirectory() }).into(),
application_name: HSTRINGWrap::from(PCWSTR(unsafe {
work_directory: WStringWrap::from(unsafe { self.com_impl.get_WorkDirectory() }).into(),
log_directory: WStringWrap::from(unsafe { self.com_impl.get_LogDirectory() }).into(),
temp_directory: WStringWrap::from(unsafe { self.com_impl.get_TempDirectory() }).into(),
application_name: WStringWrap::from(PCWSTR(unsafe {
self.com_impl.get_ApplicationName().0
}))
.into(),
application_type_name: HSTRINGWrap::from(unsafe {
application_type_name: WStringWrap::from(unsafe {
self.com_impl.get_ApplicationTypeName()
})
.into(),
service_listen_address: HSTRINGWrap::from(unsafe {
service_listen_address: WStringWrap::from(unsafe {
self.com_impl.get_ServiceListenAddress()
})
.into(),
service_publish_address: HSTRINGWrap::from(unsafe {
service_publish_address: WStringWrap::from(unsafe {
self.com_impl.get_ServicePublishAddress()
})
.into(),
Expand Down
Loading
Loading