Skip to content
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
17 changes: 12 additions & 5 deletions examples/cpp_supervised_app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,17 @@ int main(int argc, char** argv)
MonitorTag ident("monitor");

{
auto hm = HealthMonitorBuilder()
.add_deadline_monitor(ident, std::move(builder_mon))
.with_internal_processing_cycle(std::chrono::milliseconds(50))
.with_supervisor_api_cycle(std::chrono::milliseconds(50))
.build();
auto hm_res = HealthMonitorBuilder()
.add_deadline_monitor(ident, std::move(builder_mon))
.with_internal_processing_cycle(std::chrono::milliseconds(50))
.with_supervisor_api_cycle(std::chrono::milliseconds(50))
.build();
if (!hm_res.has_value())
{
std::cerr << "Failed to build health monitor" << std::endl;
return EXIT_FAILURE;
}
auto hm = std::move(*hm_res);

auto deadline_monitor_res = hm.get_deadline_monitor(ident);
if (!deadline_monitor_res.has_value())
Expand All @@ -142,6 +148,7 @@ int main(int argc, char** argv)
}

hm.start();

score::lcm::LifecycleClient{}.ReportExecutionState(score::lcm::ExecutionState::kRunning);

auto deadline_mon = std::move(*deadline_monitor_res);
Expand Down
2 changes: 1 addition & 1 deletion examples/rust_supervised_app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn main_logic(args: &Args, stop: Arc<AtomicBool>) -> Result<(), Box<dyn std::err
.get_deadline_monitor(MonitorTag::from("mon1"))
.expect("Failed to get monitor");

hm.start().expect("Failed to start health monitor");
hm.start();

if !lifecycle_client_rs::report_execution_state_running() {
error!("Rust app FAILED to report execution state!");
Expand Down
9 changes: 6 additions & 3 deletions src/health_monitoring_lib/cpp/health_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ HealthMonitorBuilder HealthMonitorBuilder::with_supervisor_api_cycle(std::chrono
return std::move(*this);
}

HealthMonitor HealthMonitorBuilder::build() &&
score::cpp::expected<HealthMonitor, Error> HealthMonitorBuilder::build() &&
{
auto health_monitor_builder_handle = health_monitor_builder_handle_.drop_by_rust();
SCORE_LANGUAGE_FUTURECPP_PRECONDITION(health_monitor_builder_handle.has_value());
Expand All @@ -136,9 +136,12 @@ HealthMonitor HealthMonitorBuilder::build() &&
FFIHandle health_monitor_handle{nullptr};
auto result{health_monitor_builder_build(
health_monitor_builder_handle.value(), supervisor_duration_ms, internal_duration_ms, &health_monitor_handle)};
SCORE_LANGUAGE_FUTURECPP_ASSERT(result == kSuccess);
if (result != kSuccess)
{
return score::cpp::unexpected(static_cast<Error>(result));
}

return HealthMonitor{health_monitor_handle};
return score::cpp::expected<HealthMonitor, Error>(HealthMonitor{health_monitor_handle});
}

HealthMonitor::HealthMonitor(FFIHandle handle) : health_monitor_(handle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class HealthMonitorBuilder final
HealthMonitorBuilder with_internal_processing_cycle(std::chrono::milliseconds cycle_duration) &&;

/// Build a new `HealthMonitor` instance based on provided parameters.
HealthMonitor build() &&;
score::cpp::expected<HealthMonitor, Error> build() &&;

private:
internal::DroppableFFIHandle health_monitor_builder_handle_;
Expand Down
16 changes: 9 additions & 7 deletions src/health_monitoring_lib/cpp/tests/health_monitor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ TEST_F(HealthMonitorTest, TestName)
auto logic_monitor_builder =
logic::LogicMonitorBuilder{from_state}.add_state(from_state, std::vector{to_state}).add_state(to_state, {});

auto hm = HealthMonitorBuilder()
.add_deadline_monitor(deadline_monitor_tag, std::move(deadline_monitor_builder))
.add_heartbeat_monitor(heartbeat_monitor_tag, std::move(heartbeat_monitor_builder))
.add_logic_monitor(logic_monitor_tag, std::move(logic_monitor_builder))
.with_internal_processing_cycle(std::chrono::milliseconds(50))
.with_supervisor_api_cycle(std::chrono::milliseconds(50))
.build();
auto hmon_result{HealthMonitorBuilder()
.add_deadline_monitor(deadline_monitor_tag, std::move(deadline_monitor_builder))
.add_heartbeat_monitor(heartbeat_monitor_tag, std::move(heartbeat_monitor_builder))
.add_logic_monitor(logic_monitor_tag, std::move(logic_monitor_builder))
.with_internal_processing_cycle(std::chrono::milliseconds(50))
.with_supervisor_api_cycle(std::chrono::milliseconds(50))
.build()};
EXPECT_TRUE(hmon_result.has_value());
auto hm{std::move(hmon_result.value())};

// Obtain deadline monitor from HMON.
auto deadline_monitor_res = hm.get_deadline_monitor(deadline_monitor_tag);
Expand Down
17 changes: 7 additions & 10 deletions src/health_monitoring_lib/rust/deadline/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@
//
// SPDX-License-Identifier: Apache-2.0
// *******************************************************************************
use core::{
ops::Deref,
sync::atomic::{AtomicBool, Ordering},
};

use crate::TimeRange;
use crate::common::TimeRange;
use core::ops::Deref;
use core::sync::atomic::{AtomicBool, Ordering};

/// Index type for identifying states associated with deadlines.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -73,11 +70,11 @@ impl DeadlineTemplate {

#[cfg(all(test, not(loom)))]
mod tests {
use super::*;
use std::sync::Arc;

use crate::TimeRange;
use crate::common::TimeRange;
use crate::deadline::common::{DeadlineTemplate, StateIndex};
use core::sync::atomic::Ordering;
use core::time::Duration;
use std::sync::Arc;

#[test]
fn new_and_fields() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ mod tests {
);
});
}

#[test]
fn deadline_outside_time_range_is_error_when_dropped_after_evaluate() {
let monitor = create_monitor_with_deadlines();
Expand Down
2 changes: 1 addition & 1 deletion src/health_monitoring_lib/rust/deadline/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
//
// SPDX-License-Identifier: Apache-2.0
// *******************************************************************************
use crate::common::TimeRange;
use crate::deadline::deadline_monitor::Deadline;
use crate::deadline::{DeadlineMonitor, DeadlineMonitorBuilder, DeadlineMonitorError};
use crate::ffi::{FFIBorrowed, FFICode, FFIHandle};
use crate::tag::DeadlineTag;
use crate::TimeRange;
use core::time::Duration;

pub(crate) struct DeadlineMonitorCpp {
Expand Down
4 changes: 2 additions & 2 deletions src/health_monitoring_lib/rust/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// *******************************************************************************
use crate::deadline::ffi::DeadlineMonitorCpp;
use crate::deadline::DeadlineMonitorBuilder;
use crate::health_monitor::{HealthMonitor, HealthMonitorBuilder, HealthMonitorError};
use crate::heartbeat::HeartbeatMonitorBuilder;
use crate::logic::LogicMonitorBuilder;
use crate::tag::MonitorTag;
use crate::{HealthMonitor, HealthMonitorBuilder, HealthMonitorError};
use core::mem::ManuallyDrop;
use core::ops::{Deref, DerefMut};
use core::time::Duration;
Expand Down Expand Up @@ -346,7 +346,7 @@ pub extern "C" fn health_monitor_start(health_monitor_handle: FFIHandle) -> FFIC
let mut health_monitor = FFIBorrowed::new(unsafe { Box::from_raw(health_monitor_handle as *mut HealthMonitor) });

// Start monitoring logic.
match health_monitor.start() {
match health_monitor.start_internal() {
Ok(_) => FFICode::Success,
Err(error) => error.into(),
}
Expand Down
Loading
Loading