in crates/libs/core/src/client/mod.rs [64:129]
fn create_local_client_internal<T: Interface>(
connection_strings: Option<&Vec<crate::WString>>,
service_notification_handler: Option<&IFabricServiceNotificationEventHandler>,
client_connection_handler: Option<&IFabricClientConnectionEventHandler>,
client_role: Option<ClientRole>,
client_settings: Option<FabricClientSettings>,
client_credentials: Option<FabricSecurityCredentials>,
) -> Result<T, FabricClientCreationError> {
let role = client_role.unwrap_or(ClientRole::Unknown);
// create raw conn str ptrs.
let connection_strings_ptrs = connection_strings.map(|addrs| {
addrs
.iter()
.map(|s| crate::PCWSTR(s.as_ptr()))
.collect::<Vec<_>>()
});
let client = match connection_strings_ptrs {
Some(addrs) => {
assert!(
role == ClientRole::Unknown,
"ClientRole is for local client only and cannot be used for connecting to remote cluster."
);
crate::API_TABLE.fabric_create_client3::<T>(
&addrs,
service_notification_handler,
client_connection_handler,
)
},
None => {
if role == ClientRole::Unknown {
// unknown role should use the SF function without role param.
crate::API_TABLE.fabric_create_local_client3::<T>(
service_notification_handler,
client_connection_handler,
)
} else {
crate::API_TABLE.fabric_create_local_client4::<T>(
service_notification_handler,
client_connection_handler,
role.into(),
)
}
}
}
// if params are right, client should be created. There is no network call involved during obj creation.
.expect("failed to create fabric client");
if client_settings.is_some() || client_credentials.is_some() {
let setting_interface = client
.clone()
.cast::<IFabricClientSettings2>()
.expect("failed to cast fabric client to IFabricClientSettings2");
if let Some(desired_settings) = client_settings {
desired_settings
.apply(&setting_interface)
.map_err(FabricClientCreationError::InvalidFabricClientSettings)?;
}
if let Some(desired_credentials) = client_credentials {
desired_credentials
.apply(setting_interface)
.map_err(FabricClientCreationError::InvalidFabricSecurityCredentials)?;
}
};
Ok(client)
}