Skip to content

Commit 3c65e9f

Browse files
Refactor Monitor API to public Alive API (#229)
* Rename Monitor to Alive API * Make MonitorImplWrapper private * Remove instanceSpecifier from Alive API * Remove obsolete MonitorImplWrapper class * Rename rust binding for Alive API * Further renaming * Move Alive API to launch_manager/alive * Remove checkpoint ids from public API * Cleanup doxygen * Fix bazel formatting * Correct cargo files * Add doxygen documentation * Update copyright header * Add ReportFailure method * Correct name in log message * Fixes for Alive API * Introduce nullptr asserts * For non-implement method ReportFailure(), use assert rather than deprecation warning. * Remove C functions from header file. Seems enough to have them in the cpp file * Default move ctor and assignment * More renaming Monitor -> Alive
1 parent 81dcc1d commit 3c65e9f

41 files changed

Lines changed: 355 additions & 490 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
resolver = "2"
33
members = [
44
"score/launch_manager/src/lifecycle_client/src/rust",
5-
"score/launch_manager/src/daemon/src/alive_monitor/rust",
5+
"score/launch_manager/src/alive/src/rust",
66
"score/health_monitor/src",
77
"examples/rust_supervised_app",
88
]
@@ -19,7 +19,7 @@ libc = "0.2.177"
1919
clap = { version = "4.5.49", features = ["derive"] }
2020
signal-hook = "0.3.18"
2121

22-
monitor_rs = { path = "score/launch_manager/src/daemon/src/alive_monitor/rust" } # Temporary API
22+
alive_rs = { path = "score/launch_manager/src/alive/src/rust" } # Temporary API
2323
health_monitoring_lib = { path = "score/health_monitor/src" }
2424
score_log = { git = "https://github.com/eclipse-score/baselibs_rust.git", tag = "v0.1.1" }
2525
score_testing_macros = { git = "https://github.com/eclipse-score/baselibs_rust.git", tag = "v0.1.1" }

examples/cpp_supervised_app/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ cc_binary(
3333
visibility = ["//visibility:public"],
3434
deps = [
3535
"//score/health_monitor:health_monitoring_cc",
36-
"//score/launch_manager:alive_cc",
3736
"//score/launch_manager:lifecycle_cc",
3837
"@score_baselibs_rust//src/log/stdout_logger_cpp_init",
3938
],

examples/rust_supervised_app/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ clap = { workspace = true }
1212
libc = { workspace = true }
1313
signal-hook = { workspace = true }
1414
lifecycle_client_rs = { path = "../../score/launch_manager/src/lifecycle_client/src/rust" }
15-
monitor_rs = { path = "../../score/launch_manager/src/daemon/src/alive_monitor/rust" }
15+
alive_rs = { path = "../../score/launch_manager/src/alive/src/rust" }
1616
health_monitoring_lib.workspace = true
1717
score_log.workspace = true
1818
stdout_logger.workspace = true

score/health_monitor/src/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ thread.workspace = true
1818
score_log.workspace = true
1919
score_testing_macros.workspace = true
2020
containers.workspace = true
21-
monitor_rs = { workspace = true, optional = true }
21+
alive_rs = { workspace = true, optional = true }
2222

2323
[dev-dependencies]
2424
stdout_logger.workspace = true
@@ -27,5 +27,5 @@ stdout_logger.workspace = true
2727
loom = { version = "0.7.2", features = ["checkpoint"] }
2828

2929
[features]
30-
default = ["monitor_rs"]
30+
default = ["alive_rs"]
3131
stub_supervisor_api_client = []

score/health_monitor/src/rust/supervisor_api_client/score_supervisor_api_client.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515

1616
use crate::log::debug;
1717
use crate::supervisor_api_client::SupervisorAPIClient;
18-
use crate::worker::Checks;
1918

2019
pub struct ScoreSupervisorAPIClient {
21-
supervisor_link: monitor_rs::Monitor<Checks>,
20+
supervisor_link: alive_rs::Alive,
2221
}
2322

2423
unsafe impl Send for ScoreSupervisorAPIClient {} // Just assuming it's safe to send across threads, this is a temporary solution
@@ -28,13 +27,13 @@ impl ScoreSupervisorAPIClient {
2827
let value = std::env::var("IDENTIFIER").expect("IDENTIFIER env not set");
2928
debug!("ScoreSupervisorAPIClient: Creating with IDENTIFIER={}", value);
3029
// This is only temporary usage so unwrap is fine here.
31-
let supervisor_link = monitor_rs::Monitor::<Checks>::new(&value).expect("Failed to create supervisor_link");
30+
let supervisor_link = alive_rs::Alive::new(&value).expect("Failed to create supervisor_link");
3231
Self { supervisor_link }
3332
}
3433
}
3534

3635
impl SupervisorAPIClient for ScoreSupervisorAPIClient {
3736
fn notify_alive(&self) {
38-
self.supervisor_link.report_checkpoint(Checks::WorkerCheckpoint);
37+
self.supervisor_link.report_alive();
3938
}
4039
}

score/launch_manager/BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ alias(
2121

2222
alias(
2323
name = "alive_cc",
24-
actual = "//score/launch_manager/src/daemon/src/alive_monitor:am_shared_lib",
24+
actual = "//score/launch_manager/src/alive:alive",
2525
)
2626

2727
alias(
2828
name = "alive_rust",
29-
actual = "//score/launch_manager/src/daemon/src/alive_monitor/rust:monitor_rs",
29+
actual = "//score/launch_manager/src/alive/src/rust:alive_rs",
3030
)
3131

3232
alias(
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
load("@rules_cc//cc:defs.bzl", "cc_library")
14+
15+
cc_library(
16+
name = "alive",
17+
srcs = [
18+
"src/alive.cpp",
19+
],
20+
hdrs = [
21+
"src/alive.h",
22+
],
23+
include_prefix = "score/mw/lifecycle",
24+
strip_include_prefix = "/score/launch_manager/src/alive/src",
25+
visibility = ["//score:__subpackages__"],
26+
deps = [
27+
"//score/launch_manager/src/alive/src/details:alive_impl",
28+
"@score_baselibs//score/language/futurecpp",
29+
],
30+
)
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/********************************************************************************
2+
* Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Apache License Version 2.0 which is available at
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* SPDX-License-Identifier: Apache-2.0
12+
********************************************************************************/
13+
14+
#include "score/mw/lifecycle/alive.h"
15+
#include "score/mw/launch_manager/alive_monitor/details/AliveImpl.h"
16+
17+
#include <utility>
18+
#include <cassert>
19+
20+
// The public API is only sending alive notification. No need to support different checkpoints.
21+
static constexpr std::uint32_t kDefaultCheckpointId{1U};
22+
23+
namespace score::mw::lifecycle
24+
{
25+
26+
Alive::Alive(const std::string_view& instance) noexcept(false) :
27+
aliveImplPtr(std::make_unique<AliveImpl>(instance))
28+
{
29+
}
30+
31+
Alive::Alive(Alive&& se) noexcept = default;
32+
33+
Alive& Alive::operator=(Alive&& se) noexcept = default;
34+
35+
Alive::~Alive() noexcept = default;
36+
37+
void Alive::ReportAlive() const noexcept
38+
{
39+
if (aliveImplPtr.get() != nullptr)
40+
{
41+
aliveImplPtr->ReportCheckpoint(kDefaultCheckpointId);
42+
}
43+
}
44+
45+
void Alive::ReportFailure() const noexcept
46+
{
47+
SCORE_LANGUAGE_FUTURECPP_PRECONDITION_PRD_MESSAGE(false, "Alive::ReportFailure() is not yet implemented");
48+
}
49+
50+
} // namespace score::mw::lifecycle
51+
52+
53+
#ifdef __cplusplus
54+
extern "C" {
55+
#endif
56+
57+
void* score_lcm_alive_initialize(const char* instanceSpecifier) noexcept {
58+
if(instanceSpecifier == nullptr) {
59+
return nullptr;
60+
}
61+
62+
try {
63+
auto* alivePtr = new score::mw::lifecycle::Alive(instanceSpecifier);
64+
return static_cast<void*>(alivePtr);
65+
} catch (...) {
66+
return nullptr;
67+
}
68+
}
69+
70+
void score_lcm_alive_deinitialize(void* instance) noexcept {
71+
SCORE_LANGUAGE_FUTURECPP_PRECONDITION(instance != nullptr);
72+
auto* alivePtr = static_cast<score::mw::lifecycle::Alive*>(instance);
73+
delete alivePtr;
74+
}
75+
76+
void score_lcm_alive_report_alive(void* instance) noexcept {
77+
SCORE_LANGUAGE_FUTURECPP_PRECONDITION(instance != nullptr);
78+
static_cast<score::mw::lifecycle::Alive*>(instance)->ReportAlive();
79+
}
80+
81+
void score_lcm_alive_report_failure(void* instance) noexcept {
82+
SCORE_LANGUAGE_FUTURECPP_PRECONDITION(instance != nullptr);
83+
static_cast<score::mw::lifecycle::Alive*>(instance)->ReportFailure();
84+
}
85+
86+
87+
#ifdef __cplusplus
88+
}
89+
#endif
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/********************************************************************************
2+
* Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Apache License Version 2.0 which is available at
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* SPDX-License-Identifier: Apache-2.0
12+
********************************************************************************/
13+
14+
#ifndef SCORE_LCM_ALIVE_H_
15+
#define SCORE_LCM_ALIVE_H_
16+
17+
#include <cstdint>
18+
#include <memory>
19+
#include <string_view>
20+
21+
namespace score::mw::lifecycle
22+
{
23+
24+
// Forward declaration
25+
class AliveImpl;
26+
27+
/// @brief Alive API for reporting alive notifications to the launch manager.
28+
/// An alive notification indicates that the component is still active and functioning correctly.
29+
/// The launch manager is configured with an expected alive notification interval,
30+
/// and if it does not receive an alive notification within that interval,
31+
/// it executes the configured recovery action.
32+
///
33+
/// Each process may only use a single Alive instance.
34+
class Alive
35+
{
36+
public:
37+
/// @brief Creation of an Alive.
38+
/// @param [in] instance Instance specifier (currently unused)
39+
/// @throws std::runtime_error if the configured IPC channel to connect to launch manager is not existing
40+
/// @throws std::bad_alloc in case of insufficient memory
41+
explicit Alive(const std::string_view& instance) noexcept(false);
42+
43+
/// @brief The copy constructor for Alive shall not be used.
44+
Alive(const Alive& se) = delete;
45+
46+
/// @brief Move constructor for Alive
47+
/// @param [in,out] se The Alive object to be moved
48+
Alive(Alive&& se) noexcept;
49+
50+
/// @brief The copy assignment operator for Alive shall not be used.
51+
Alive& operator=(const Alive& se) = delete;
52+
53+
/// @brief Move assignment operator for Alive
54+
/// @param [in,out] se The Alive object to be moved
55+
/// @return The moved Alive object
56+
Alive& operator=(Alive&& se) noexcept;
57+
58+
/// @brief Destructor of an Alive
59+
virtual ~Alive() noexcept;
60+
61+
/// @brief Reports an alive notification
62+
/// @remark Thread safety: This method is NOT thread safe.
63+
void ReportAlive() const noexcept;
64+
65+
/// @brief Report a direct failure
66+
/// @remark Thread safety: This method is NOT thread safe.
67+
/// @note Not Implemented. This method currently does nothing.
68+
void ReportFailure() const noexcept;
69+
70+
private:
71+
/// @brief Unique pointer to implementation class of Alive
72+
std::unique_ptr<AliveImpl> aliveImplPtr;
73+
};
74+
75+
} // namespace score::mw::lifecycle
76+
#endif // SCORE_LCM_ALIVE_H_

0 commit comments

Comments
 (0)