use crate::ErrorCode;
use crate::types::{
FaultType, HealthInformation, LoadMetric, LoadMetricListRef, MoveCost,
SelfReconfiguringConfigurationReport, ServicePartitionInformation,
};
use mssf_com::FabricRuntime::IFabricSelfReconfiguringServicePartition;
#[derive(Debug, Clone)]
pub struct SelfReconfiguringServicePartition {
com_impl: IFabricSelfReconfiguringServicePartition,
}
impl SelfReconfiguringServicePartition {
pub fn new(
com_impl: IFabricSelfReconfiguringServicePartition,
) -> SelfReconfiguringServicePartition {
SelfReconfiguringServicePartition { com_impl }
}
pub fn get_com(&self) -> &IFabricSelfReconfiguringServicePartition {
&self.com_impl
}
}
impl crate::runtime::ISelfReconfiguringServicePartition for SelfReconfiguringServicePartition {
fn get_partition_info(&self) -> crate::Result<ServicePartitionInformation> {
unsafe { self.com_impl.GetPartitionInfo()?.as_ref() }
.ok_or(ErrorCode::E_POINTER.into())
.map(ServicePartitionInformation::from)
}
fn report_load(&self, metrics: &[LoadMetric]) -> crate::Result<()> {
let metrics_ref = LoadMetricListRef::from_slice(metrics);
let raw = metrics_ref.as_raw_slice();
unsafe { self.com_impl.ReportLoad(raw) }.map_err(crate::Error::from)
}
fn report_fault(&self, fault_type: FaultType) -> crate::Result<()> {
unsafe { self.com_impl.ReportFault(fault_type.into()) }.map_err(crate::Error::from)
}
fn report_move_cost(&self, move_cost: MoveCost) -> crate::Result<()> {
unsafe { self.com_impl.ReportMoveCost(move_cost.into()) }.map_err(crate::Error::from)
}
fn report_instance_health(&self, healthinfo: &HealthInformation) -> crate::Result<()> {
let healthinfo_ref = &healthinfo.into();
unsafe {
self.com_impl
.ReportInstanceHealth(healthinfo_ref, std::ptr::null())
}
.map_err(crate::Error::from)
}
fn report_partition_health(&self, healthinfo: &HealthInformation) -> crate::Result<()> {
let healthinfo_ref = &healthinfo.into();
unsafe {
self.com_impl
.ReportPartitionHealth(healthinfo_ref, std::ptr::null())
}
.map_err(crate::Error::from)
}
fn report_configuration(
&self,
report: &SelfReconfiguringConfigurationReport,
) -> crate::Result<()> {
let view = report.get_view();
unsafe { self.com_impl.ReportConfiguration(view.get_raw()) }.map_err(crate::Error::from)
}
}