diff --git a/Cargo.lock b/Cargo.lock index 5d7b04091..656cbc994 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,13 @@ dependencies = [ "memchr", ] +[[package]] +name = "alive_rs" +version = "0.0.1" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "1.0.0" @@ -163,9 +170,9 @@ dependencies = [ name = "health_monitoring_lib" version = "0.0.1" dependencies = [ + "alive_rs", "containers", "loom", - "monitor_rs", "score_log", "score_testing_macros", "stdout_logger", @@ -245,13 +252,6 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" -[[package]] -name = "monitor_rs" -version = "0.0.1" -dependencies = [ - "libc", -] - [[package]] name = "nu-ansi-term" version = "0.50.3" @@ -328,11 +328,11 @@ checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" name = "rust_supervised_app" version = "0.0.1" dependencies = [ + "alive_rs", "clap", "health_monitoring_lib", "libc", "lifecycle_client_rs", - "monitor_rs", "score_log", "signal-hook", "stdout_logger", diff --git a/Cargo.toml b/Cargo.toml index c923ee5f4..dfa1add75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ resolver = "2" members = [ "score/launch_manager/src/lifecycle_client/src/rust", - "score/launch_manager/src/daemon/src/alive_monitor/rust", + "score/launch_manager/src/alive/src/rust", "score/health_monitor/src", "examples/rust_supervised_app", ] @@ -19,7 +19,7 @@ libc = "0.2.177" clap = { version = "4.5.49", features = ["derive"] } signal-hook = "0.3.18" -monitor_rs = { path = "score/launch_manager/src/daemon/src/alive_monitor/rust" } # Temporary API +alive_rs = { path = "score/launch_manager/src/alive/src/rust" } # Temporary API health_monitoring_lib = { path = "score/health_monitor/src" } score_log = { git = "https://github.com/eclipse-score/baselibs_rust.git", tag = "v0.1.1" } score_testing_macros = { git = "https://github.com/eclipse-score/baselibs_rust.git", tag = "v0.1.1" } diff --git a/examples/cpp_supervised_app/BUILD b/examples/cpp_supervised_app/BUILD index 0c09a7276..379938ed7 100644 --- a/examples/cpp_supervised_app/BUILD +++ b/examples/cpp_supervised_app/BUILD @@ -33,7 +33,6 @@ cc_binary( visibility = ["//visibility:public"], deps = [ "//score/health_monitor:health_monitoring_cc", - "//score/launch_manager:alive_cc", "//score/launch_manager:lifecycle_cc", "@score_baselibs_rust//src/log/stdout_logger_cpp_init", ], diff --git a/examples/rust_supervised_app/Cargo.toml b/examples/rust_supervised_app/Cargo.toml index b4c7eb376..c2c7bb20c 100644 --- a/examples/rust_supervised_app/Cargo.toml +++ b/examples/rust_supervised_app/Cargo.toml @@ -12,7 +12,7 @@ clap = { workspace = true } libc = { workspace = true } signal-hook = { workspace = true } lifecycle_client_rs = { path = "../../score/launch_manager/src/lifecycle_client/src/rust" } -monitor_rs = { path = "../../score/launch_manager/src/daemon/src/alive_monitor/rust" } +alive_rs = { path = "../../score/launch_manager/src/alive/src/rust" } health_monitoring_lib.workspace = true score_log.workspace = true stdout_logger.workspace = true diff --git a/score/health_monitor/src/Cargo.toml b/score/health_monitor/src/Cargo.toml index 0c3ad00dd..afa397a9a 100644 --- a/score/health_monitor/src/Cargo.toml +++ b/score/health_monitor/src/Cargo.toml @@ -18,7 +18,7 @@ thread.workspace = true score_log.workspace = true score_testing_macros.workspace = true containers.workspace = true -monitor_rs = { workspace = true, optional = true } +alive_rs = { workspace = true, optional = true } [dev-dependencies] stdout_logger.workspace = true @@ -27,5 +27,5 @@ stdout_logger.workspace = true loom = { version = "0.7.2", features = ["checkpoint"] } [features] -default = ["monitor_rs"] +default = ["alive_rs"] stub_supervisor_api_client = [] diff --git a/score/health_monitor/src/rust/supervisor_api_client/score_supervisor_api_client.rs b/score/health_monitor/src/rust/supervisor_api_client/score_supervisor_api_client.rs index a198f9ada..5b9b3f701 100644 --- a/score/health_monitor/src/rust/supervisor_api_client/score_supervisor_api_client.rs +++ b/score/health_monitor/src/rust/supervisor_api_client/score_supervisor_api_client.rs @@ -15,10 +15,9 @@ use crate::log::debug; use crate::supervisor_api_client::SupervisorAPIClient; -use crate::worker::Checks; pub struct ScoreSupervisorAPIClient { - supervisor_link: monitor_rs::Monitor, + supervisor_link: alive_rs::Alive, } 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 { let value = std::env::var("IDENTIFIER").expect("IDENTIFIER env not set"); debug!("ScoreSupervisorAPIClient: Creating with IDENTIFIER={}", value); // This is only temporary usage so unwrap is fine here. - let supervisor_link = monitor_rs::Monitor::::new(&value).expect("Failed to create supervisor_link"); + let supervisor_link = alive_rs::Alive::new(&value).expect("Failed to create supervisor_link"); Self { supervisor_link } } } impl SupervisorAPIClient for ScoreSupervisorAPIClient { fn notify_alive(&self) { - self.supervisor_link.report_checkpoint(Checks::WorkerCheckpoint); + self.supervisor_link.report_alive(); } } diff --git a/score/launch_manager/BUILD b/score/launch_manager/BUILD index 4f331aeb4..d6eda34ae 100644 --- a/score/launch_manager/BUILD +++ b/score/launch_manager/BUILD @@ -21,12 +21,12 @@ alias( alias( name = "alive_cc", - actual = "//score/launch_manager/src/daemon/src/alive_monitor:am_shared_lib", + actual = "//score/launch_manager/src/alive:alive", ) alias( name = "alive_rust", - actual = "//score/launch_manager/src/daemon/src/alive_monitor/rust:monitor_rs", + actual = "//score/launch_manager/src/alive/src/rust:alive_rs", ) alias( diff --git a/score/launch_manager/src/alive/BUILD b/score/launch_manager/src/alive/BUILD new file mode 100644 index 000000000..6e3c356cb --- /dev/null +++ b/score/launch_manager/src/alive/BUILD @@ -0,0 +1,30 @@ +# ******************************************************************************* +# Copyright (c) 2026 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* +load("@rules_cc//cc:defs.bzl", "cc_library") + +cc_library( + name = "alive", + srcs = [ + "src/alive.cpp", + ], + hdrs = [ + "src/alive.h", + ], + include_prefix = "score/mw/lifecycle", + strip_include_prefix = "/score/launch_manager/src/alive/src", + visibility = ["//score:__subpackages__"], + deps = [ + "//score/launch_manager/src/alive/src/details:alive_impl", + "@score_baselibs//score/language/futurecpp", + ], +) diff --git a/score/launch_manager/src/alive/src/alive.cpp b/score/launch_manager/src/alive/src/alive.cpp new file mode 100644 index 000000000..53eec5903 --- /dev/null +++ b/score/launch_manager/src/alive/src/alive.cpp @@ -0,0 +1,89 @@ +/******************************************************************************** + * Copyright (c) 2026 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +#include "score/mw/lifecycle/alive.h" +#include "score/mw/launch_manager/alive_monitor/details/AliveImpl.h" + +#include +#include + +// The public API is only sending alive notification. No need to support different checkpoints. +static constexpr std::uint32_t kDefaultCheckpointId{1U}; + +namespace score::mw::lifecycle +{ + +Alive::Alive(const std::string_view& instance) noexcept(false) : + aliveImplPtr(std::make_unique(instance)) +{ +} + +Alive::Alive(Alive&& se) noexcept = default; + +Alive& Alive::operator=(Alive&& se) noexcept = default; + +Alive::~Alive() noexcept = default; + +void Alive::ReportAlive() const noexcept +{ + if (aliveImplPtr.get() != nullptr) + { + aliveImplPtr->ReportCheckpoint(kDefaultCheckpointId); + } +} + +void Alive::ReportFailure() const noexcept +{ + SCORE_LANGUAGE_FUTURECPP_PRECONDITION_PRD_MESSAGE(false, "Alive::ReportFailure() is not yet implemented"); +} + +} // namespace score::mw::lifecycle + + +#ifdef __cplusplus +extern "C" { +#endif + +void* score_lcm_alive_initialize(const char* instanceSpecifier) noexcept { + if(instanceSpecifier == nullptr) { + return nullptr; + } + + try { + auto* alivePtr = new score::mw::lifecycle::Alive(instanceSpecifier); + return static_cast(alivePtr); + } catch (...) { + return nullptr; + } +} + +void score_lcm_alive_deinitialize(void* instance) noexcept { + SCORE_LANGUAGE_FUTURECPP_PRECONDITION(instance != nullptr); + auto* alivePtr = static_cast(instance); + delete alivePtr; +} + +void score_lcm_alive_report_alive(void* instance) noexcept { + SCORE_LANGUAGE_FUTURECPP_PRECONDITION(instance != nullptr); + static_cast(instance)->ReportAlive(); +} + +void score_lcm_alive_report_failure(void* instance) noexcept { + SCORE_LANGUAGE_FUTURECPP_PRECONDITION(instance != nullptr); + static_cast(instance)->ReportFailure(); +} + + +#ifdef __cplusplus +} +#endif diff --git a/score/launch_manager/src/alive/src/alive.h b/score/launch_manager/src/alive/src/alive.h new file mode 100644 index 000000000..376cf1bda --- /dev/null +++ b/score/launch_manager/src/alive/src/alive.h @@ -0,0 +1,76 @@ +/******************************************************************************** + * Copyright (c) 2026 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +#ifndef SCORE_LCM_ALIVE_H_ +#define SCORE_LCM_ALIVE_H_ + +#include +#include +#include + +namespace score::mw::lifecycle +{ + +// Forward declaration +class AliveImpl; + +/// @brief Alive API for reporting alive notifications to the launch manager. +/// An alive notification indicates that the component is still active and functioning correctly. +/// The launch manager is configured with an expected alive notification interval, +/// and if it does not receive an alive notification within that interval, +/// it executes the configured recovery action. +/// +/// Each process may only use a single Alive instance. +class Alive +{ +public: + /// @brief Creation of an Alive. + /// @param [in] instance Instance specifier (currently unused) + /// @throws std::runtime_error if the configured IPC channel to connect to launch manager is not existing + /// @throws std::bad_alloc in case of insufficient memory + explicit Alive(const std::string_view& instance) noexcept(false); + + /// @brief The copy constructor for Alive shall not be used. + Alive(const Alive& se) = delete; + + /// @brief Move constructor for Alive + /// @param [in,out] se The Alive object to be moved + Alive(Alive&& se) noexcept; + + /// @brief The copy assignment operator for Alive shall not be used. + Alive& operator=(const Alive& se) = delete; + + /// @brief Move assignment operator for Alive + /// @param [in,out] se The Alive object to be moved + /// @return The moved Alive object + Alive& operator=(Alive&& se) noexcept; + + /// @brief Destructor of an Alive + virtual ~Alive() noexcept; + + /// @brief Reports an alive notification + /// @remark Thread safety: This method is NOT thread safe. + void ReportAlive() const noexcept; + + /// @brief Report a direct failure + /// @remark Thread safety: This method is NOT thread safe. + /// @note Not Implemented. This method currently does nothing. + void ReportFailure() const noexcept; + +private: + /// @brief Unique pointer to implementation class of Alive + std::unique_ptr aliveImplPtr; +}; + +} // namespace score::mw::lifecycle +#endif // SCORE_LCM_ALIVE_H_ diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/MonitorImpl.cpp b/score/launch_manager/src/alive/src/details/AliveImpl.cpp similarity index 80% rename from score/launch_manager/src/daemon/src/alive_monitor/details/MonitorImpl.cpp rename to score/launch_manager/src/alive/src/details/AliveImpl.cpp index 5c666964b..2cdc18768 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/MonitorImpl.cpp +++ b/score/launch_manager/src/alive/src/details/AliveImpl.cpp @@ -11,7 +11,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#include "score/mw/launch_manager/alive_monitor/details/MonitorImpl.h" +#include "score/mw/launch_manager/alive_monitor/details/AliveImpl.h" #include @@ -22,7 +22,7 @@ namespace score::mw::lifecycle { -MonitorImpl::MonitorImpl(const std::string_view& f_instanceSpecifier_r, +AliveImpl::AliveImpl(const std::string_view& f_instanceSpecifier_r, std::unique_ptr f_ipcClient) noexcept(false) : k_instanceSpecifierPath(f_instanceSpecifier_r), ipcClient(std::move(f_ipcClient)), @@ -33,17 +33,17 @@ MonitorImpl::MonitorImpl(const std::string_view& f_instanceSpecifier_r, connectToPhmDaemon(); } -void MonitorImpl::ReportCheckpoint(Checkpoint f_checkpointId) const noexcept(true) +void AliveImpl::ReportCheckpoint(std::uint32_t f_checkpointId) const noexcept(true) { (void)ipcClient->sendEmplace(score::lcm::saf::timers::OsClock::getMonotonicSystemClock(), f_checkpointId); } -void MonitorImpl::connectToPhmDaemon(void) noexcept(false) +void AliveImpl::connectToPhmDaemon(void) noexcept(false) { const auto ipc_path_res = readInterfacePath(); if (ipc_path_res == std::nullopt) { - logger_r.LogError() << "Failed to load interface path for Monitor (" << k_instanceSpecifierPath << ")"; + logger_r.LogError() << "Failed to load interface path for Alive instance (" << k_instanceSpecifierPath << ")"; throw std::runtime_error("Failed to get interface path"); } CheckpointIpcClient::EIpcInitResult initResult{ipcClient->init(ipc_path_res.value())}; @@ -55,13 +55,13 @@ void MonitorImpl::connectToPhmDaemon(void) noexcept(false) { const uid_t uid{geteuid()}; logger_r.LogError() << "Connection to PHM daemon failed (permission denied for effective uid" << uid - << "), for the Monitor (" << k_instanceSpecifierPath << ")"; + << "), for the Alive instance (" << k_instanceSpecifierPath << ")"; return; } - logger_r.LogError() << "Connection to PHM daemon failed, for the Monitor (" << k_instanceSpecifierPath << ")"; + logger_r.LogError() << "Connection to PHM daemon failed, for the Alive instance (" << k_instanceSpecifierPath << ")"; } -std::optional MonitorImpl::readInterfacePath() noexcept +std::optional AliveImpl::readInterfacePath() noexcept { const char* if_path{getenv("LCM_ALIVE_INTERFACE_PATH")}; if (if_path == nullptr || if_path[0] == '\0') diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/MonitorImpl.h b/score/launch_manager/src/alive/src/details/AliveImpl.h similarity index 70% rename from score/launch_manager/src/daemon/src/alive_monitor/details/MonitorImpl.h rename to score/launch_manager/src/alive/src/details/AliveImpl.h index 4f1f0ea84..af23360f3 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/MonitorImpl.h +++ b/score/launch_manager/src/alive/src/details/AliveImpl.h @@ -11,15 +11,13 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SCORE_LCM_MonitorImpl_H_ -#define SCORE_LCM_MonitorImpl_H_ +#ifndef SCORE_LCM_ALIVEIMPL_H_ +#define SCORE_LCM_ALIVEIMPL_H_ #include #include #include -#include "score/mw/launch_manager/alive_monitor/MonitorImplWrapper.h" -#include "score/mw/launch_manager/alive_monitor/Monitor.h" #include "score/mw/launch_manager/alive_monitor/details/ifappl/DataStructures.hpp" #include "score/mw/launch_manager/alive_monitor/details/ipc/IpcClient.hpp" #include "score/mw/launch_manager/alive_monitor/details/logging/PhmLogger.hpp" @@ -27,11 +25,11 @@ namespace score::mw::lifecycle { -/// @brief Implementation class for score::mw::lifecycle::Monitor class +/// @brief Implementation class for score::mw::lifecycle::Alive class /// This class is responsible for establishing the connection between the application and PHM daemon /// by invoking the calls to PHM class methods and to forward the reported checkpoints from the application /// to PHM daemon for supervision evaluation -class MonitorImpl +class AliveImpl { public: /// @brief The element that is sent via IPC @@ -41,48 +39,48 @@ class MonitorImpl score::lcm::saf::ifappl::k_maxCheckpointBufferElements>; /// @brief Non-parametric constructor is not supported - MonitorImpl() = delete; + AliveImpl() = delete; - /// @brief Constructor of MonitorImpl class + /// @brief Constructor of AliveImpl class /// @param [in] f_instanceSpecifier_r Instance specifier object with the metamodel path of - /// the Monitor - /// @param [in] f_ipcClient Ipc Connection to PHM daemon + /// the Alive instance + /// @param [in] f_ipcClient Ipc Connection to Launch Manager /// @throws std::runtime_error in case ipc path could not be read from configuration /// @throws std::bad_alloc in case of insufficient memory - explicit MonitorImpl( + explicit AliveImpl( const std::string_view& f_instanceSpecifier_r, std::unique_ptr f_ipcClient = std::make_unique()) noexcept(false); - /// @brief The copy constructor for MonitorImpl is not supported. - MonitorImpl(const MonitorImpl&) = delete; + /// @brief The copy constructor for AliveImpl is not supported. + AliveImpl(const AliveImpl&) = delete; - /// @brief The move constructor for MonitorImpl is not supported. - MonitorImpl(MonitorImpl&&) = delete; + /// @brief The move constructor for AliveImpl is not supported. + AliveImpl(AliveImpl&&) = delete; - /// @brief The copy assignment operator for MonitorImpl is not supported. - MonitorImpl& operator=(const MonitorImpl&) & = delete; + /// @brief The copy assignment operator for AliveImpl is not supported. + AliveImpl& operator=(const AliveImpl&) & = delete; - /// @brief The move assignment operator for MonitorImpl is not supported. - MonitorImpl& operator=(MonitorImpl&&) & noexcept = delete; + /// @brief The move assignment operator for AliveImpl is not supported. + AliveImpl& operator=(AliveImpl&&) & noexcept = delete; /// @brief Destructor of the class - virtual ~MonitorImpl() = default; + virtual ~AliveImpl() = default; /// @brief Reports an occurrence of a Checkpoint /// @param [in] f_checkpointId Checkpoint identifier. - void ReportCheckpoint(Checkpoint f_checkpointId) const noexcept(true); + void ReportCheckpoint(std::uint32_t f_checkpointId) const noexcept(true); private: /// @brief Connect the application process with PHM daemon using IPC /// @throws std::runtime_error in case ipc path could not be read from configuration void connectToPhmDaemon(void) noexcept(false); - /// @brief Read the Monitor Interface Path from an environment variable. + /// @brief Read the Alive Interface Path from an environment variable. /// This is then used to initialise the IPC client /// @return Value of environment variable or nullopt if getenv fails static std::optional readInterfacePath() noexcept; - /// @brief Instance specifier path of the Monitor instance + /// @brief Instance specifier path of the Alive instance const std::string k_instanceSpecifierPath; /// @brief IPC Connection to PHM Daemon diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/MonitorImpl_UT.cpp b/score/launch_manager/src/alive/src/details/AliveImpl_UT.cpp similarity index 66% rename from score/launch_manager/src/daemon/src/alive_monitor/details/MonitorImpl_UT.cpp rename to score/launch_manager/src/alive/src/details/AliveImpl_UT.cpp index 013fa4fe5..7bd86bacb 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/MonitorImpl_UT.cpp +++ b/score/launch_manager/src/alive/src/details/AliveImpl_UT.cpp @@ -14,12 +14,12 @@ #include -#include "score/mw/launch_manager/alive_monitor/details/MonitorImpl.h" +#include "score/mw/launch_manager/alive_monitor/details/AliveImpl.h" namespace score::mw::lifecycle { -class MonitorImplTest : public ::testing::Test +class AliveImplTest : public ::testing::Test { protected: void SetUp() override @@ -30,29 +30,29 @@ class MonitorImplTest : public ::testing::Test } }; -TEST_F(MonitorImplTest, ThrowsWhenInterfacePathEnvVarIsNotSet) +TEST_F(AliveImplTest, ThrowsWhenInterfacePathEnvVarIsNotSet) { - RecordProperty("Description", "MonitorImpl throws when LCM_ALIVE_INTERFACE_PATH is not set."); + RecordProperty("Description", "AliveImpl throws when LCM_ALIVE_INTERFACE_PATH is not set."); - EXPECT_THROW(MonitorImpl("test/instance"), std::runtime_error); + EXPECT_THROW(AliveImpl("test/instance"), std::runtime_error); } -TEST_F(MonitorImplTest, DoesNotThrowWhenInterfacePathEnvVarIsSet) +TEST_F(AliveImplTest, DoesNotThrowWhenInterfacePathEnvVarIsSet) { RecordProperty("Description", - "MonitorImpl construction succeeds when LCM_ALIVE_INTERFACE_PATH is set, " + "AliveImpl construction succeeds when LCM_ALIVE_INTERFACE_PATH is set, " "even if the IPC path does not exist."); setenv("LCM_ALIVE_INTERFACE_PATH", "nonexistent_ipc_path", 1); - EXPECT_NO_THROW({ MonitorImpl impl("test/instance"); }); + EXPECT_NO_THROW({ AliveImpl impl("test/instance"); }); } -TEST_F(MonitorImplTest, ReportCheckpointSafeWhenNotConnected) +TEST_F(AliveImplTest, ReportCheckpointSafeWhenNotConnected) { RecordProperty("Description", "ReportCheckpoint does not crash when the IPC connection was not established."); setenv("LCM_ALIVE_INTERFACE_PATH", "nonexistent_ipc_path", 1); - MonitorImpl impl("test/instance"); + AliveImpl impl("test/instance"); EXPECT_NO_THROW(impl.ReportCheckpoint(42U)); } diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/BUILD b/score/launch_manager/src/alive/src/details/BUILD similarity index 66% rename from score/launch_manager/src/daemon/src/alive_monitor/details/BUILD rename to score/launch_manager/src/alive/src/details/BUILD index ae73fd79a..e608dc4d6 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/BUILD +++ b/score/launch_manager/src/alive/src/details/BUILD @@ -10,27 +10,25 @@ # # SPDX-License-Identifier: Apache-2.0 # ******************************************************************************* -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") +load("@rules_cc//cc:defs.bzl", "cc_library") cc_test( - name = "MonitorImpl_UT", - srcs = ["MonitorImpl_UT.cpp"], + name = "AliveImpl_UT", + srcs = ["AliveImpl_UT.cpp"], deps = [ - ":monitor_impl", + ":alive_impl", "@googletest//:gtest_main", ], ) cc_library( - name = "monitor_impl", - srcs = ["MonitorImpl.cpp"], - hdrs = ["MonitorImpl.h"], + name = "alive_impl", + srcs = ["AliveImpl.cpp"], + hdrs = ["AliveImpl.h"], include_prefix = "score/mw/launch_manager/alive_monitor/details", - strip_include_prefix = "/score/launch_manager/src/daemon/src/alive_monitor/details", - visibility = ["//score/launch_manager/src/daemon/src/alive_monitor:__subpackages__"], + strip_include_prefix = "/score/launch_manager/src/alive/src/details", + visibility = ["//score/launch_manager/src/alive:__pkg__"], deps = [ - "//score/launch_manager/src/daemon/src/alive_monitor:alive_monitor_h", - "//score/launch_manager/src/daemon/src/alive_monitor:config", "//score/launch_manager/src/daemon/src/alive_monitor/details/ifappl:data_structures", "//score/launch_manager/src/daemon/src/alive_monitor/details/ipc:ipc_if", "//score/launch_manager/src/daemon/src/alive_monitor/details/logging:phm_logging", diff --git a/score/launch_manager/src/daemon/src/alive_monitor/rust/BUILD b/score/launch_manager/src/alive/src/rust/BUILD similarity index 94% rename from score/launch_manager/src/daemon/src/alive_monitor/rust/BUILD rename to score/launch_manager/src/alive/src/rust/BUILD index 4a8780703..b2b733cd7 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/rust/BUILD +++ b/score/launch_manager/src/alive/src/rust/BUILD @@ -13,11 +13,11 @@ load("@rules_rust//rust:defs.bzl", "rust_library") rust_library( - name = "monitor_rs", + name = "alive_rs", srcs = [ + "src/alive.rs", "src/errors.rs", "src/lib.rs", - "src/monitor.rs", ], visibility = ["//score:__subpackages__"], deps = [ diff --git a/score/launch_manager/src/daemon/src/alive_monitor/rust/Cargo.lock b/score/launch_manager/src/alive/src/rust/Cargo.lock similarity index 94% rename from score/launch_manager/src/daemon/src/alive_monitor/rust/Cargo.lock rename to score/launch_manager/src/alive/src/rust/Cargo.lock index f55059e7c..1d78b7626 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/rust/Cargo.lock +++ b/score/launch_manager/src/alive/src/rust/Cargo.lock @@ -9,7 +9,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" [[package]] -name = "monitor_rs" +name = "alive_rs" version = "0.0.1" dependencies = [ "libc", diff --git a/score/launch_manager/src/daemon/src/alive_monitor/rust/Cargo.toml b/score/launch_manager/src/alive/src/rust/Cargo.toml similarity index 76% rename from score/launch_manager/src/daemon/src/alive_monitor/rust/Cargo.toml rename to score/launch_manager/src/alive/src/rust/Cargo.toml index d6bfb444a..5a222760c 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/rust/Cargo.toml +++ b/score/launch_manager/src/alive/src/rust/Cargo.toml @@ -1,10 +1,10 @@ [package] -name = "monitor_rs" +name = "alive_rs" version = "0.0.1" edition = "2021" [lib] -name = "monitor_rs" +name = "alive_rs" crate-type = ["cdylib", "rlib"] [dependencies] diff --git a/score/launch_manager/src/daemon/src/alive_monitor/rust/src/monitor.rs b/score/launch_manager/src/alive/src/rust/src/alive.rs similarity index 59% rename from score/launch_manager/src/daemon/src/alive_monitor/rust/src/monitor.rs rename to score/launch_manager/src/alive/src/rust/src/alive.rs index 030b94032..709167499 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/rust/src/monitor.rs +++ b/score/launch_manager/src/alive/src/rust/src/alive.rs @@ -11,35 +11,33 @@ // SPDX-License-Identifier: Apache-2.0 // ******************************************************************************* use crate::errors; -use libc::{c_char, c_uint, c_void}; +use libc::{c_char, c_void}; use std::ffi::CString; -use std::marker::PhantomData; -#[link(name = "am-lib")] +#[link(name = "alive")] unsafe extern "C" { - fn score_lcm_monitor_initialize(instanceSpecifier: *const c_char) -> *mut c_void; - fn score_lcm_monitor_deinitialize(instance: *mut c_void); - fn score_lcm_monitor_report_checkpoint(instance: *mut c_void, checkpoint_id: c_uint); + fn score_lcm_alive_initialize(instanceSpecifier: *const c_char) -> *mut c_void; + fn score_lcm_alive_deinitialize(instance: *mut c_void); + fn score_lcm_alive_report_alive(instance: *mut c_void); + unsafe fn score_lcm_alive_report_failure(instance: *mut c_void); } -pub struct Monitor { +pub struct Alive { instance_ptr: *mut c_void, name: CString, - phantom: PhantomData, } -impl Monitor { +impl Alive { pub fn new(instance: &str) -> Result> { let tmp_str = CString::new(instance)?; let mut tmp_inst = Self { instance_ptr: std::ptr::null_mut(), name: tmp_str, - phantom: PhantomData, }; let ptr: *mut c_void; unsafe { - ptr = score_lcm_monitor_initialize(tmp_inst.name.as_ptr()); + ptr = score_lcm_alive_initialize(tmp_inst.name.as_ptr()); } if ptr.is_null() { @@ -50,21 +48,23 @@ impl Monitor { Ok(tmp_inst) } - pub fn report_checkpoint(&self, checkpoint_id: EnumT) - where - EnumT: Into + Copy, - { - let id: u32 = checkpoint_id.into(); + pub fn report_alive(&self) { unsafe { - score_lcm_monitor_report_checkpoint(self.instance_ptr, id); + score_lcm_alive_report_alive(self.instance_ptr); + } + } + + pub fn report_failure(&self) { + unsafe { + score_lcm_alive_report_failure(self.instance_ptr); } } } -impl Drop for Monitor { +impl Drop for Alive { fn drop(&mut self) { unsafe { - score_lcm_monitor_deinitialize(self.instance_ptr); + score_lcm_alive_deinitialize(self.instance_ptr); } } } diff --git a/score/launch_manager/src/daemon/src/alive_monitor/rust/src/errors.rs b/score/launch_manager/src/alive/src/rust/src/errors.rs similarity index 93% rename from score/launch_manager/src/daemon/src/alive_monitor/rust/src/errors.rs rename to score/launch_manager/src/alive/src/rust/src/errors.rs index 6b08025ca..934c6f774 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/rust/src/errors.rs +++ b/score/launch_manager/src/alive/src/rust/src/errors.rs @@ -17,7 +17,7 @@ pub struct ConstructorError; impl fmt::Display for ConstructorError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "failed to construct Monitor instance") + write!(f, "failed to construct Alive instance") } } diff --git a/score/launch_manager/src/daemon/src/alive_monitor/rust/src/lib.rs b/score/launch_manager/src/alive/src/rust/src/lib.rs similarity index 93% rename from score/launch_manager/src/daemon/src/alive_monitor/rust/src/lib.rs rename to score/launch_manager/src/alive/src/rust/src/lib.rs index fe010c738..bbfd220c6 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/rust/src/lib.rs +++ b/score/launch_manager/src/alive/src/rust/src/lib.rs @@ -10,8 +10,8 @@ // // SPDX-License-Identifier: Apache-2.0 // ******************************************************************************* +pub mod alive; pub mod errors; -pub mod monitor; +pub use alive::Alive; pub use errors::ConstructorError; -pub use monitor::Monitor; diff --git a/score/launch_manager/src/daemon/src/alive_monitor/BUILD b/score/launch_manager/src/daemon/src/alive_monitor/BUILD index b899c4bdc..5afd71e39 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/BUILD +++ b/score/launch_manager/src/daemon/src/alive_monitor/BUILD @@ -37,39 +37,6 @@ cc_library( visibility = ["//score/launch_manager/src/daemon/src/alive_monitor:__subpackages__"], ) -cc_library( - name = "alive_monitor_h", - hdrs = [ - "Monitor.h", - "MonitorImplWrapper.h", - ], - include_prefix = "score/mw/launch_manager/alive_monitor", - strip_include_prefix = "/score/launch_manager/src/daemon/src/alive_monitor", - visibility = ["//score/launch_manager/src/daemon/src/alive_monitor:__subpackages__"], -) - -cc_library( - name = "am-lib", - srcs = [ - "Monitor.cpp", - "MonitorImplWrapper.cpp", - ], - hdrs = [ - "Monitor.h", - "MonitorImplWrapper.h", - ], - include_prefix = "score/mw/launch_manager/alive_monitor", - strip_include_prefix = "/score/launch_manager/src/daemon/src/alive_monitor", - visibility = ["//score:__subpackages__"], - deps = [ - ":alive_monitor_h", - "//score/launch_manager/src/daemon/src/alive_monitor/details:monitor_impl", - ] + select({ - "@platforms//os:qnx": [], - "@platforms//os:linux": ["//externals/acl"], - }), -) - cc_library( name = "alive_monitor", visibility = ["//score:__subpackages__"], @@ -77,21 +44,3 @@ cc_library( "//score/launch_manager/src/daemon/src/alive_monitor/details/daemon:health_monitor_impl", ], ) - -cc_library( - name = "am_shared_lib", - hdrs = [ - "Monitor.h", - "MonitorImplWrapper.h", - ], - include_prefix = "score/mw/launch_manager/alive_monitor", - strip_include_prefix = "/score/launch_manager/src/daemon/src/alive_monitor", - visibility = ["//score:__subpackages__"], - deps = [ - ":am-lib", - "//score/launch_manager/src/daemon/src/alive_monitor/details/ipc:ipc_if", - "//score/launch_manager/src/daemon/src/alive_monitor/details/logging:phm_logging", - "//score/launch_manager/src/daemon/src/alive_monitor/details/timers:timers_os_clock", - ], - alwayslink = True, -) diff --git a/score/launch_manager/src/daemon/src/alive_monitor/Monitor.cpp b/score/launch_manager/src/daemon/src/alive_monitor/Monitor.cpp deleted file mode 100644 index f5d9b5836..000000000 --- a/score/launch_manager/src/daemon/src/alive_monitor/Monitor.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2025 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -#include "score/mw/launch_manager/alive_monitor/Monitor.h" - -enum class Dummy : std::uint32_t {}; - -#ifdef __cplusplus -extern "C" { -#endif - -void* score_lcm_monitor_initialize(const char* instanceSpecifier) noexcept { - try { - auto* monitorPtr = new score::mw::lifecycle::Monitor(instanceSpecifier); - return static_cast(monitorPtr); - } catch (...) { - return nullptr; - } -} - -void score_lcm_monitor_deinitialize(void* instance) noexcept { - auto* monitorPtr = static_cast*>(instance); - delete monitorPtr; -} - -void score_lcm_monitor_report_checkpoint(void* instance, std::uint32_t checkpointId) noexcept { - static_cast*>(instance)->ReportCheckpoint(static_cast(checkpointId)); -} - -#ifdef __cplusplus -} -#endif diff --git a/score/launch_manager/src/daemon/src/alive_monitor/Monitor.h b/score/launch_manager/src/daemon/src/alive_monitor/Monitor.h deleted file mode 100644 index a007ad784..000000000 --- a/score/launch_manager/src/daemon/src/alive_monitor/Monitor.h +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2025 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -#ifndef SCORE_LCM_MONITOR_H_ -#define SCORE_LCM_MONITOR_H_ - -#include -#include -#include -#include - -#include "score/mw/launch_manager/alive_monitor/MonitorImplWrapper.h" - -namespace score::mw::lifecycle -{ - -/// @brief Monitor Class -template -class Monitor -{ -public: - /// @brief Creation of a Monitor. - /// @param [in] instance Instance specifier of the Monitor - /// @throws std::runtime_error in case of an error loading the process-specific configuration - /// @throws std::bad_alloc in case of insufficient memory - /* RULECHECKER_comment(0, 11, check_unique_ptr_construction, "monitorImplWrapperPtr uses unique pointer\ - as type-casting to void pointer from make_unique is not possible", true_no_defect) */ - explicit Monitor(const std::string_view& instance) noexcept(false) : - monitorImplWrapperPtr(std::make_unique(instance)) - { - } - - /// @brief The copy constructor for Monitor shall not be used. - Monitor(const Monitor& se) = delete; - - /// @brief Move constructor for Monitor - /// @param [in,out] se The Monitor object to be moved - Monitor(Monitor&& se) noexcept : - monitorImplWrapperPtr(std::move(se.monitorImplWrapperPtr)) - { - } - - /// @brief The copy assignment operator for Monitor shall not be used. - Monitor& operator=(const Monitor& se) = delete; - - /// @brief Move assignment operator for Monitor - /// @param [in,out] se The Monitor object to be moved - /// @return The moved Monitor object - Monitor& operator=(Monitor&& se) noexcept - { - if (this != &se) - { - monitorImplWrapperPtr.reset(nullptr); - monitorImplWrapperPtr = std::move(se.monitorImplWrapperPtr); - } - - return *this; - } - - /// @brief Destructor of a Monitor - virtual ~Monitor() noexcept - { - } - - /// @brief Reports an occurrence of a Checkpoint - /// @param [in] checkpointId Checkpoint identifier. - /// @remark Thread safety: - /// Report Checkpoint is NOT thread safe. - /// In case a Monitor is shared between threads or in case two Monitor's are constructed - /// with the same instance specifier in different threads a common lock before calling ReportCheckpoint is required. - void ReportCheckpoint(EnumT checkpointId) const noexcept - { - if (monitorImplWrapperPtr.get() != nullptr) - { - monitorImplWrapperPtr->ReportCheckpoint(static_cast(checkpointId)); - } - } - -private: - /// @brief Unique pointer to the wrapper of implementation class of Monitor - std::unique_ptr monitorImplWrapperPtr; - - /// @brief Assert if Monitor class is constructed with an enumeration type - static_assert(std::is_enum::value, - "Monitor class must be constructed with template type " - "which is an enumeration class!"); - - /// @brief Underlying data type of the used template argument - using underlyingCheckpointIdType = typename std::underlying_type::type; - - /// @brief Assert if enumeration used during the construction of Monitor class - /// is of the type std::uint32_t - static_assert(std::is_same::value, - "The enumeration class used during the construction of Monitor class must be of " - "type 'std::uint32_t'!"); -}; - -#ifdef __cplusplus -extern "C" -{ -#endif - void* score_lcm_monitor_initialize(const char* instanceSpecifier) noexcept; - void score_lcm_monitor_deinitialize(void* instance) noexcept; - void score_lcm_monitor_report_checkpoint(void* instance, std::uint32_t checkpointId) noexcept; -#ifdef __cplusplus -} -#endif - -} // namespace score::mw::lifecycle -#endif diff --git a/score/launch_manager/src/daemon/src/alive_monitor/MonitorImplWrapper.cpp b/score/launch_manager/src/daemon/src/alive_monitor/MonitorImplWrapper.cpp deleted file mode 100644 index 59b4ba769..000000000 --- a/score/launch_manager/src/daemon/src/alive_monitor/MonitorImplWrapper.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2025 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -#include "score/mw/launch_manager/alive_monitor/MonitorImplWrapper.h" - -#include "score/mw/launch_manager/alive_monitor/details/MonitorImpl.h" -#include "score/mw/launch_manager/alive_monitor/Monitor.h" - -namespace score::mw::lifecycle -{ - -MonitorImplWrapper::MonitorImplWrapper( - const std::string_view& f_instanceSpecifier_r) noexcept(false) : - // coverity[autosar_cpp14_a15_5_2_violation] This warning comes from pipc-sa(external library) - monitorImplPtr(std::make_unique(f_instanceSpecifier_r)) -{ -} - -MonitorImplWrapper::~MonitorImplWrapper() noexcept(true) -{ - monitorImplPtr.reset(); -} - -void MonitorImplWrapper::ReportCheckpoint(Checkpoint f_checkpointId) const noexcept(true) -{ - if (monitorImplPtr.get() != nullptr) - { - monitorImplPtr->ReportCheckpoint(f_checkpointId); - } -} - -} // namespace score::mw::lifecycle diff --git a/score/launch_manager/src/daemon/src/alive_monitor/MonitorImplWrapper.h b/score/launch_manager/src/daemon/src/alive_monitor/MonitorImplWrapper.h deleted file mode 100644 index 95c92422d..000000000 --- a/score/launch_manager/src/daemon/src/alive_monitor/MonitorImplWrapper.h +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2025 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0 - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - -#ifndef SCORE_LCM_MonitorImplWrapper_H_ -#define SCORE_LCM_MonitorImplWrapper_H_ - -#include -#include -#include - -namespace score::mw::lifecycle -{ - -/// @brief Represents a Checkpoint -using Checkpoint = std::uint32_t; - -/// @brief Forward Declaration for them Implementation class for Monitor -class MonitorImpl; - -/// @brief Wrapper of implementation class for score::mw::lifecycle::Monitor class -/// This class is just a wrapper and forwards the calls from score::mw::lifecycle::Monitor class -/// to the actual implementation class, i.e., score::mw::lifecycle::MonitorImpl -class MonitorImplWrapper -{ -public: - /// @brief Non-parametric constructor is not supported - MonitorImplWrapper() = delete; - - /// @brief Constructor of MonitorImplWrapper class - /// @param [in] f_instanceSpecifier_r Instance specifier object with the metamodel path of - /// the Monitor - /// @throws std::runtime_error in case of an error loading the process-specific configuration - /// @throws std::bad_alloc in case of insufficient memory - explicit MonitorImplWrapper(const std::string_view& f_instanceSpecifier_r) noexcept(false); - - /// @brief The copy constructor for MonitorImplWrapper is not supported. - MonitorImplWrapper(const MonitorImplWrapper&) = delete; - - /* RULECHECKER_comment(0, 6, check_incomplete_data_member_construction, "Default constructor is not provided\ - the member initializer", false) */ - /// @brief Default move constructor for MonitorImplWrapper - /// @param [in,out] MonitorImplWrapper&& rvalue reference of the MonitorImplWrapper object - /// which shall be moved - MonitorImplWrapper(MonitorImplWrapper&&) noexcept = default; - - /// @brief The copy assignment operator for MonitorImplWrapper is not supported. - MonitorImplWrapper& operator=(const MonitorImplWrapper&) & = delete; - - /// @brief Default move assignment operator for MonitorImplWrapper - /// @param [in,out] MonitorImplWrapper&& rvalue reference of the MonitorImplWrapper object - /// which shall be moved - /// @return Reference of the moved MonitorImplWrapper object - MonitorImplWrapper& operator=(MonitorImplWrapper&&) & noexcept = default; - - /// @brief Destructor of the class - virtual ~MonitorImplWrapper() noexcept(true); - - /// @brief Reports an occurrence of a Checkpoint - /// @param [in] f_checkpointId Checkpoint identifier. - void ReportCheckpoint(score::mw::lifecycle::Checkpoint f_checkpointId) const noexcept(true); - -private: - /// @brief Unique pointer to the implementation class of Monitor - std::unique_ptr monitorImplPtr; -}; - -} // namespace score::mw::lifecycle - -#endif diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/AliveMonitorImpl.cpp b/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/AliveMonitorImpl.cpp index 79964286f..4035cb259 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/AliveMonitorImpl.cpp +++ b/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/AliveMonitorImpl.cpp @@ -37,15 +37,15 @@ EInitCode AliveMonitorImpl::init() noexcept { if (initResult == score::lcm::saf::daemon::EInitCode::kNoError) { const long ms{m_osClock.endMeasurement()}; - m_logger.LogDebug() << "HealthMonitor: Initialization took " << ms << " ms"; + m_logger.LogDebug() << "AliveMonitor: Initialization took " << ms << " ms"; } else { - m_logger.LogError() << "HealthMonitor: Initialization failed with error code:" << static_cast(initResult); + m_logger.LogError() << "AliveMonitor: Initialization failed with error code:" << static_cast(initResult); } } catch (const std::exception& e) { - std::cerr << "HealthMonitor: Initialization failed due to standard exception: " << e.what() << ".\n"; + std::cerr << "AliveMonitor: Initialization failed due to standard exception: " << e.what() << ".\n"; initResult = EInitCode::kGeneralError; } catch (...) { - std::cerr << "HealthMonitor: Initialization failed due to exception!\n"; + std::cerr << "AliveMonitor: Initialization failed due to exception!\n"; initResult = EInitCode::kGeneralError; } diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/AliveMonitorImpl.hpp b/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/AliveMonitorImpl.hpp index 3f8a83603..cf40feaa2 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/AliveMonitorImpl.hpp +++ b/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/AliveMonitorImpl.hpp @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SAF_DAEMON_HEALTH_MONITOR_IMPL_HPP_INCLUDED -#define SAF_DAEMON_HEALTH_MONITOR_IMPL_HPP_INCLUDED +#ifndef SAF_DAEMON_ALIVE_MONITOR_IMPL_HPP_INCLUDED +#define SAF_DAEMON_ALIVE_MONITOR_IMPL_HPP_INCLUDED #include #include diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/IAliveMonitor.hpp b/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/IAliveMonitor.hpp index 624d88a6c..655e8740b 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/IAliveMonitor.hpp +++ b/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/IAliveMonitor.hpp @@ -10,8 +10,8 @@ * * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef SAF_DAEMON_HEALTH_MONITOR_HPP_INCLUDED -#define SAF_DAEMON_HEALTH_MONITOR_HPP_INCLUDED +#ifndef SAF_DAEMON_ALIVE_MONITOR_HPP_INCLUDED +#define SAF_DAEMON_ALIVE_MONITOR_HPP_INCLUDED #include @@ -31,11 +31,11 @@ class IAliveMonitor { public: virtual ~IAliveMonitor() = default; - /// @brief Initialize the HealthMonitor functionality + /// @brief Initialize the AliveMonitor functionality /// @return kNoError if initialization was successful, otherwise an appropriate error code. virtual EInitCode init() noexcept = 0; - /// @brief Run the HealthMonitor functionality in a cyclic manner until cancellation is requested. + /// @brief Run the AliveMonitor functionality in a cyclic manner until cancellation is requested. /// @param cancel_thread Atomic boolean flag to signal thread cancellation. virtual bool run(std::atomic_bool& cancel_thread) noexcept = 0; }; diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/SwClusterHandler.cpp b/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/SwClusterHandler.cpp index 5a5643465..574b0e53c 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/SwClusterHandler.cpp +++ b/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/SwClusterHandler.cpp @@ -31,8 +31,8 @@ SwClusterHandler::SwClusterHandler(const std::string& f_swClusterName_r) : logger_r(logging::PhmLogger::getLogger(logging::PhmLogger::EContext::factory)), f_swClusterName(f_swClusterName_r), processStates{}, - monitorIfIpcs{}, - monitorInterfaces{}, + aliveIfIpcs{}, + aliveInterfaces{}, checkpoints{}, aliveSupervisions{} { @@ -63,15 +63,15 @@ bool SwClusterHandler::constructWorkers( } if (isSuccess) { - isSuccess = flatCfgFactory.createMonitorIfIpcs(monitorIfIpcs); + isSuccess = flatCfgFactory.createAliveIfIpcs(aliveIfIpcs); } if (isSuccess) { - isSuccess = flatCfgFactory.createMonitorIf(monitorInterfaces, monitorIfIpcs, processStates); + isSuccess = flatCfgFactory.createAliveIf(aliveInterfaces, aliveIfIpcs, processStates); } if (isSuccess) { - isSuccess = flatCfgFactory.createSupervisionCheckpoints(checkpoints, monitorInterfaces, processStates); + isSuccess = flatCfgFactory.createSupervisionCheckpoints(checkpoints, aliveInterfaces, processStates); } if (isSuccess) { @@ -87,9 +87,9 @@ bool SwClusterHandler::constructWorkers( void SwClusterHandler::checkInterfaceForNewData(const timers::NanoSecondType f_syncTimestamp) { - for (auto& monitorInterface : monitorInterfaces) + for (auto& aliveInterface : aliveInterfaces) { - monitorInterface.checkForNewData(f_syncTimestamp); + aliveInterface.checkForNewData(f_syncTimestamp); } } diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/SwClusterHandler.hpp b/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/SwClusterHandler.hpp index dec198d70..7512d6ee9 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/SwClusterHandler.hpp +++ b/score/launch_manager/src/daemon/src/alive_monitor/details/daemon/SwClusterHandler.hpp @@ -125,11 +125,11 @@ class SwClusterHandler /// Vector of Process states std::vector processStates; - /// Vector of Monitor Interface IPCs - std::vector monitorIfIpcs; + /// Vector of Alive Interface IPCs + std::vector aliveIfIpcs; - /// Vector of Monitor Interfaces - std::vector monitorInterfaces; + /// Vector of Alive Interfaces + std::vector aliveInterfaces; /// Vector of Supervision checkpoints std::vector checkpoints; diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/factory/FlatCfgFactory.cpp b/score/launch_manager/src/daemon/src/alive_monitor/details/factory/FlatCfgFactory.cpp index 49975481e..0f4a8479c 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/factory/FlatCfgFactory.cpp +++ b/score/launch_manager/src/daemon/src/alive_monitor/details/factory/FlatCfgFactory.cpp @@ -196,13 +196,13 @@ bool FlatCfgFactory::initIpcServerWithUidBasedAccess(ifappl::CheckpointIpcServer if (!f_ipcServer_r.setAccessRights(uid)) { logger_r.LogError() << kLogPrefix << "Could not set ACL permissions (r/w for uid" << uid - << ") for Monitor interface IPC with path:" << f_ipcPath_r; + << ") for Alive interface IPC with path:" << f_ipcPath_r; return false; } return true; } -bool FlatCfgFactory::createMonitorIfIpcs(std::vector& f_interfaceIpcs_r) +bool FlatCfgFactory::createAliveIfIpcs(std::vector& f_interfaceIpcs_r) { bool isSuccess{true}; if (flatBuffer_p->hmMonitorInterface() != nullptr) @@ -223,12 +223,12 @@ bool FlatCfgFactory::createMonitorIfIpcs(std::vector(f_interfaceIpcs_r.size()); } else { f_interfaceIpcs_r.clear(); - logger_r.LogError() << kLogPrefix << "Could not create all necessary Monitor interface IPCs."; + logger_r.LogError() << kLogPrefix << "Could not create all necessary Alive interface IPCs."; } return isSuccess; } -bool FlatCfgFactory::createMonitorIf(std::vector& f_interfaces_r, +bool FlatCfgFactory::createAliveIf(std::vector& f_interfaces_r, std::vector& f_interfaceIpcs_r, std::vector& f_processStates_r) { @@ -282,19 +282,19 @@ bool FlatCfgFactory::createMonitorIf(std::vector& f_int f_processStates_r.at(static_cast(refProcessIndex)).attachObserver(f_interfaces_r.back()); logger_r.LogDebug() << kLogPrefix - << "Successfully created MonitorInterface:" << f_interfaces_r.back().getInterfaceName(); + << "Successfully created Alive Interface:" << f_interfaces_r.back().getInterfaceName(); // coverity[autosar_cpp14_a4_7_1_violation] Value limited by amount of interfaces, which is smaller. index++; } - logger_r.LogDebug() << kLogPrefix << "Number of constructed Monitor interfaces:" + logger_r.LogDebug() << kLogPrefix << "Number of constructed Alive interfaces:" << static_cast(f_interfaces_r.size()); } catch (const std::exception& f_exception_r) { isSuccess = false; f_interfaces_r.clear(); - logger_r.LogError() << kLogPrefix << "Could not create all necessary Monitor interfaces due to exception:" + logger_r.LogError() << kLogPrefix << "Could not create all necessary Alive interfaces due to exception:" << std::string_view{f_exception_r.what()}; } diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/factory/FlatCfgFactory.hpp b/score/launch_manager/src/daemon/src/alive_monitor/details/factory/FlatCfgFactory.hpp index f0aee86af..d9ddd870a 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/factory/FlatCfgFactory.hpp +++ b/score/launch_manager/src/daemon/src/alive_monitor/details/factory/FlatCfgFactory.hpp @@ -83,10 +83,10 @@ class FlatCfgFactory : public IPhmFactory ifexm::ProcessStateReader& f_processStateReader_r) override; /// Refer to the description of the base class (IPhmFactory) - bool createMonitorIfIpcs(std::vector& f_interfaceIpcs_r) override; + bool createAliveIfIpcs(std::vector& f_interfaceIpcs_r) override; /// Refer to the description of the base class (IPhmFactory) - bool createMonitorIf(std::vector& f_interfaces_r, + bool createAliveIf(std::vector& f_interfaces_r, std::vector& f_interfaceIpcs_r, std::vector& f_processStates_r) override; diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/factory/IPhmFactory.hpp b/score/launch_manager/src/daemon/src/alive_monitor/details/factory/IPhmFactory.hpp index d5e494732..5acad6689 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/factory/IPhmFactory.hpp +++ b/score/launch_manager/src/daemon/src/alive_monitor/details/factory/IPhmFactory.hpp @@ -81,23 +81,23 @@ class IPhmFactory virtual bool createProcessStates(std::vector& f_processStates_r, ifexm::ProcessStateReader& f_processStateReader_r) = 0; - /// @brief Create IPCs for Monitor Interfaces - /// @param [out] f_interfaceIpcs_r Vector of created Monitor Interface IPCs + /// @brief Create IPCs for Alive Interfaces + /// @param [out] f_interfaceIpcs_r Vector of created Alive Interface IPCs /// @return Object creation successful (true), otherwise failed (false) - virtual bool createMonitorIfIpcs(std::vector& f_interfaceIpcs_r) = 0; + virtual bool createAliveIfIpcs(std::vector& f_interfaceIpcs_r) = 0; - /// @brief Create Monitor Interfaces - /// @param [out] f_interfaces_r Vector of created Monitor Interfaces - /// @param [in] f_interfaceIpcs_r Vector of Monitor Interface IPCs required for interface creation. + /// @brief Create Alive Interfaces + /// @param [out] f_interfaces_r Vector of created Alive Interfaces + /// @param [in] f_interfaceIpcs_r Vector of Alive Interface IPCs required for interface creation. /// @param [in,out] f_processStates_r Vector of Process States /// @return Object creation successful (true), otherwise failed (false) - virtual bool createMonitorIf(std::vector& f_interfaces_r, + virtual bool createAliveIf(std::vector& f_interfaces_r, std::vector& f_interfaceIpcs_r, std::vector& f_processStates_r) = 0; /// @brief Create Supervision Checkpoints /// @param [out] f_checkpoints_r Vector of created Supervision Checkpoints - /// @param [in,out] f_interfaces_r Vector of Monitor Interfaces required for attaching the checkpoints. + /// @param [in,out] f_interfaces_r Vector of Alive Interfaces required for attaching the checkpoints. /// @param [in] f_processStates_r Vector of ProcessStates required for constructing the Checkpoint /// instances. /// @return Object creation successful (true), otherwise failed (false) diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/ifappl/BUILD b/score/launch_manager/src/daemon/src/alive_monitor/details/ifappl/BUILD index 7f8f8cf57..32c531645 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/ifappl/BUILD +++ b/score/launch_manager/src/daemon/src/alive_monitor/details/ifappl/BUILD @@ -17,7 +17,10 @@ cc_library( hdrs = ["DataStructures.hpp"], include_prefix = "score/mw/launch_manager/alive_monitor/details/ifappl", strip_include_prefix = "/score/launch_manager/src/daemon/src/alive_monitor/details/ifappl", - visibility = ["//score/launch_manager/src/daemon/src/alive_monitor:__subpackages__"], + visibility = [ + "//score/launch_manager/src/alive:__subpackages__", + "//score/launch_manager/src/daemon/src/alive_monitor:__subpackages__", + ], deps = [ "//score/launch_manager/src/daemon/src/alive_monitor/details/ipc:ipc_if", "//score/launch_manager/src/daemon/src/alive_monitor/details/timers:timers_os_clock", diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/ifappl/DataStructures.hpp b/score/launch_manager/src/daemon/src/alive_monitor/details/ifappl/DataStructures.hpp index 57c1a8ca9..64ab0adb5 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/ifappl/DataStructures.hpp +++ b/score/launch_manager/src/daemon/src/alive_monitor/details/ifappl/DataStructures.hpp @@ -30,8 +30,8 @@ namespace ifappl /// Maximum number of Checkpoints to be stored in IPC channel /// @todo Implement logic to determine the number of checkpoint entries -/// that a Monitor instance can report between two cycles -/// of PHM daemon. +/// that an Alive instance can report between two cycles +/// of AliveMonitor. // coverity[autosar_cpp14_a0_1_1_violation] value is referenced in multiple files, but depending on build package. constexpr uint16_t k_maxCheckpointBufferElements{512U}; diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/ifappl/MonitorIfDaemon.hpp b/score/launch_manager/src/daemon/src/alive_monitor/details/ifappl/MonitorIfDaemon.hpp index 8c88eaeba..ec2d7205a 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/ifappl/MonitorIfDaemon.hpp +++ b/score/launch_manager/src/daemon/src/alive_monitor/details/ifappl/MonitorIfDaemon.hpp @@ -40,7 +40,7 @@ class Global; namespace ifappl { -/// @brief Monitor Interface for PHM Deamon +/// @brief Alive Interface for PHM Deamon /// @details The MonitorIfDaemon class provides methods to write/read information to the /// data exchange between PHM daemon and Application, which are only required on PHM Daemon side. class MonitorIfDaemon : public common::Observer @@ -84,7 +84,7 @@ class MonitorIfDaemon : public common::Observer const std::string& getInterfaceName(void) const noexcept(true); /// @brief Attach checkpoint - /// @details Attaches a checkpoint observer to the Monitor interface + /// @details Attaches a checkpoint observer to the Alive interface /// Note: Attached observers will receive updates in case there is new information /// @param [in] f_checkpoint_r Checkpoint which is added to the observer array /// @throws std::bad_alloc in case of insufficient memory for vector allocation @@ -95,7 +95,7 @@ class MonitorIfDaemon : public common::Observer void updateData(const ifexm::ProcessState& f_observable_r) noexcept(true) override; /// @brief Check for new data - /// @details Check Monitor interface for new data from application side + /// @details Check Alive interface for new data from application side /// @param [in] f_syncTimestamp Timestamp till data shall be read, newer data will not be considered void checkForNewData(const score::lcm::saf::timers::NanoSecondType f_syncTimestamp) noexcept(true); @@ -110,7 +110,7 @@ class MonitorIfDaemon : public common::Observer /// @brief Push overflow event information to all checkpoint observer /// @details Every attached checkpoint observer will be informed that a data loss event in the - /// Monitor has occurred + /// Alive interface has occurred void pushOverflowInfoToCheckpointObservers(void) const; /// @brief Move to kInactiveOverflow state and push overflow event to observers @@ -149,7 +149,7 @@ class MonitorIfDaemon : public common::Observer /// Interface name const std::string k_interfaceName; - /// Array of checkpoint observers attached to the Monitor interface + /// Array of checkpoint observers attached to the Alive interface std::vector checkpointObservers{}; /// @brief IPC connection to application diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/ipc/BUILD b/score/launch_manager/src/daemon/src/alive_monitor/details/ipc/BUILD index 23ef688f7..083fee615 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/ipc/BUILD +++ b/score/launch_manager/src/daemon/src/alive_monitor/details/ipc/BUILD @@ -21,7 +21,10 @@ cc_library( ], include_prefix = "score/mw/launch_manager/alive_monitor/details/ipc", strip_include_prefix = "/score/launch_manager/src/daemon/src/alive_monitor/details/ipc", - visibility = ["//score/launch_manager/src/daemon/src/alive_monitor:__subpackages__"], + visibility = [ + "//score/launch_manager/src/alive:__subpackages__", + "//score/launch_manager/src/daemon/src/alive_monitor:__subpackages__", + ], deps = ["//externals/ipc_dropin"] + select({ "@platforms//os:qnx": [], "@platforms//os:linux": ["//externals/acl"], diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/logging/BUILD b/score/launch_manager/src/daemon/src/alive_monitor/details/logging/BUILD index a78f3cf3d..0a0547059 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/logging/BUILD +++ b/score/launch_manager/src/daemon/src/alive_monitor/details/logging/BUILD @@ -22,6 +22,9 @@ cc_library( }), include_prefix = "score/mw/launch_manager/alive_monitor/details/logging", strip_include_prefix = "/score/launch_manager/src/daemon/src/alive_monitor/details/logging", - visibility = ["//score/launch_manager/src/daemon/src/alive_monitor:__subpackages__"], + visibility = [ + "//score/launch_manager/src/alive:__subpackages__", + "//score/launch_manager/src/daemon/src/alive_monitor:__subpackages__", + ], deps = ["@score_baselibs//score/mw/log"], ) diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/supervision/Alive.hpp b/score/launch_manager/src/daemon/src/alive_monitor/details/supervision/Alive.hpp index c46607da6..61ca5b82d 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/supervision/Alive.hpp +++ b/score/launch_manager/src/daemon/src/alive_monitor/details/supervision/Alive.hpp @@ -17,7 +17,6 @@ #include #include -#include "score/mw/launch_manager/alive_monitor/Monitor.h" #include "score/mw/launch_manager/alive_monitor/details/common/Observer.hpp" #include "score/mw/launch_manager/alive_monitor/details/common/TimeSortingBuffer.hpp" #include "score/mw/launch_manager/alive_monitor/details/ifappl/Checkpoint.hpp" diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/supervision/BUILD b/score/launch_manager/src/daemon/src/alive_monitor/details/supervision/BUILD index 2fad2d869..1e3d00e33 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/supervision/BUILD +++ b/score/launch_manager/src/daemon/src/alive_monitor/details/supervision/BUILD @@ -47,7 +47,6 @@ cc_library( deps = [ ":i_supervision", ":supervision_cfg", - "//score/launch_manager/src/daemon/src/alive_monitor:alive_monitor_h", "//score/launch_manager/src/daemon/src/alive_monitor/details/common:time_sorting_buffer", "//score/launch_manager/src/daemon/src/alive_monitor/details/ifappl:checkpoint", "//score/launch_manager/src/daemon/src/alive_monitor/details/ifexm:process_state", diff --git a/score/launch_manager/src/daemon/src/alive_monitor/details/timers/BUILD b/score/launch_manager/src/daemon/src/alive_monitor/details/timers/BUILD index 05cd4e4e4..4e5733631 100644 --- a/score/launch_manager/src/daemon/src/alive_monitor/details/timers/BUILD +++ b/score/launch_manager/src/daemon/src/alive_monitor/details/timers/BUILD @@ -32,7 +32,10 @@ cc_library( ], include_prefix = "score/mw/launch_manager/alive_monitor/details/timers", strip_include_prefix = "/score/launch_manager/src/daemon/src/alive_monitor/details/timers", - visibility = ["//score/launch_manager/src/daemon/src/alive_monitor:__subpackages__"], + visibility = [ + "//score/launch_manager/src/alive:__subpackages__", + "//score/launch_manager/src/daemon/src/alive_monitor:__subpackages__", + ], ) alias(