Skip to content
Open
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
2 changes: 0 additions & 2 deletions score/launch_manager/src/daemon/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ cc_binary(
"//score/launch_manager/src/daemon/src/configuration:flatbuffer_config_loader",
"//score/launch_manager/src/daemon/src/osal:ipc_comms",
"//score/launch_manager/src/daemon/src/process_group_manager",
"//score/launch_manager/src/daemon/src/process_group_manager:alive_monitor_thread",
"//score/launch_manager/src/daemon/src/recovery_client",
"//score/launch_manager/src/daemon/src/supervision_control_client:supervision_control_notifier",
"//score/launch_manager/src/daemon/src/watchdog:watchdog_factory",
"@score_baselibs//score/language/futurecpp",
],
Expand Down
24 changes: 24 additions & 0 deletions score/launch_manager/src/daemon/src/alive_monitor/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,27 @@ cc_library(
"//score/launch_manager/src/daemon/src/alive_monitor/details/daemon:health_monitor_impl",
],
)

cc_library(
name = "i_alive_monitor",
hdrs = ["IAliveMonitor.hpp"],
include_prefix = "score/mw/launch_manager/alive_monitor",
strip_include_prefix = "/score/launch_manager/src/daemon/src/alive_monitor",
visibility = ["//score:__subpackages__"],
deps = [
"//score/launch_manager/src/daemon/src/supervision_control_client:isupervision_factory",
],
)

cc_library(
name = "mock_alive_monitor",
testonly = True,
hdrs = ["mock_alive_monitor.hpp"],
include_prefix = "score/mw/launch_manager/alive_monitor",
strip_include_prefix = "/score/launch_manager/src/daemon/src/alive_monitor",
visibility = ["//score:__subpackages__"],
deps = [
":i_alive_monitor",
"@googletest//:gtest_main",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
#ifndef SAF_DAEMON_ALIVE_MONITOR_HPP_INCLUDED
#define SAF_DAEMON_ALIVE_MONITOR_HPP_INCLUDED

#include <atomic>

#include "score/mw/launch_manager/alive_monitor/details/daemon/PhmDaemon.hpp"
#include "score/mw/launch_manager/supervision_control_client/isupervision_factory.hpp"

namespace score::mw::lifecycle::internal::saf::daemon
{
Expand All @@ -26,13 +24,21 @@ class IAliveMonitor
public:
virtual ~IAliveMonitor() = default;

/// @brief Initialize the AliveMonitor functionality
/// @return kNoError if initialization was successful, otherwise an appropriate error code.
virtual EInitCode init() noexcept = 0;
/// @brief Start the monitor thread
/// @warning Not valid if @c init() failed
virtual bool start() = 0;

/// @brief Stop the monitor thread
/// @warning Not valid if @c init() failed
virtual void stop() = 0;

/// @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;
/// @brief Returns an interface for components to register their alive supervision
/// @warning Not valid if @c init() failed
virtual ISupervisionFactory& getSupervisionFactory() const = 0;

/// @brief Initialize the AliveMonitor functionality
/// @return True if initialization was successful, false otherwise.
virtual bool init() noexcept = 0;
};

} // namespace score::mw::lifecycle::internal::saf::daemon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ cc_library(
visibility = ["//score/launch_manager/src/daemon/src/alive_monitor:__subpackages__"],
)

cc_library(
name = "einitcode",
hdrs = ["EInitCode.hpp"],
include_prefix = "score/mw/launch_manager/alive_monitor/details/common",
strip_include_prefix = "/score/launch_manager/src/daemon/src/alive_monitor/details/common",
visibility = ["//score/launch_manager/src/daemon/src/alive_monitor:__subpackages__"],
)

cc_library(
name = "locked_vector",
hdrs = ["LockedVector.hpp"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/********************************************************************************
* 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 E_INIT_CODE_HPP_INCLUDED
#define E_INIT_CODE_HPP_INCLUDED

#include <cstdint>

namespace score::mw::lifecycle::internal::saf::daemon
{

/// @brief Return codes for PhmDaemon Initialization
enum class EInitCode : std::int8_t
{
kNoError, ///< Init Successful (no error occurred)
kNotInitialized, ///< Init was not performed
kCycleTimeInitFailed, ///< Cyclic Timer initialization failed
kConstructFlatCfgFactoryFailed, ///< FlatCfgFactory failed loading SWCL configurations
kGeneralError ///< General error
};

} // namespace score::mw::lifecycle::internal::saf::daemon

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,38 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
#include <sys/types.h>

#include <iostream>

#include <score/assert.hpp>

#include "score/mw/launch_manager/alive_monitor/details/daemon/AliveMonitorImpl.hpp"
#include "score/mw/launch_manager/alive_monitor/details/daemon/PhmDaemon.hpp"

namespace score::mw::lifecycle::internal::saf::daemon
{

AliveMonitorImpl::AliveMonitorImpl(
SptrIRecoveryClient recovery_client,
UptrISupervisionControlReceiver observable_event_receiver,
const Config& config)
: m_recovery_client(recovery_client),
m_observable_event_receiver(std::move(observable_event_receiver)),
m_config(config)
AliveSupervisionConfig config,
const std::size_t supervised_components)
: m_recovery_client(recovery_client), config_(config), supervised_components_(supervised_components)
{
}

EInitCode AliveMonitorImpl::init() noexcept
bool AliveMonitorImpl::init() noexcept
{
EInitCode initResult{EInitCode::kGeneralError};
try
{
m_osClock.startMeasurement();

m_daemon = std::make_unique<PhmDaemon>(m_osClock, std::move(m_observable_event_receiver));
initResult = m_daemon->init(m_recovery_client, m_config);
m_daemon = std::make_unique<PhmDaemon>(m_osClock, supervised_components_);
EInitCode initResult = m_daemon->init(m_recovery_client, config_);

if (initResult == EInitCode::kNoError)
{
const long ms{m_osClock.endMeasurement()};
LM_LOG_DEBUG() << "AliveMonitor: Initialization took " << ms << " ms";
return true;
}
else
{
Expand All @@ -54,22 +52,43 @@ EInitCode AliveMonitorImpl::init() noexcept
catch (const std::exception& e)
{
std::cerr << "AliveMonitor: Initialization failed due to standard exception: " << e.what() << ".\n";
initResult = EInitCode::kGeneralError;
}
catch (...)
{
std::cerr << "AliveMonitor: Initialization failed due to exception!\n";
initResult = EInitCode::kGeneralError;
}

return initResult;
return false;
}

bool AliveMonitorImpl::run(std::atomic_bool& cancel_thread) noexcept
bool AliveMonitorImpl::start() noexcept
{
alive_monitor_thread_ = std::thread([this]() {
threadFn(stop_thread_);
});

return true;
}

void AliveMonitorImpl::stop() noexcept
{
stop_thread_.store(true);
if (alive_monitor_thread_.joinable())
{
alive_monitor_thread_.join();
}
}

bool AliveMonitorImpl::threadFn(std::atomic_bool& cancel_thread) noexcept
{
SCORE_LANGUAGE_FUTURECPP_PRECONDITION_PRD_MESSAGE(
m_daemon != nullptr, "HealthMonitor: Instance is not initialized!");
return m_daemon->startCyclicExec(cancel_thread);
}

ISupervisionFactory& AliveMonitorImpl::getSupervisionFactory() const noexcept
{
return *m_daemon;
Comment thread
WilliamRoebuck marked this conversation as resolved.
}

} // namespace score::mw::lifecycle::internal::saf::daemon
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@

#include <atomic>
#include <memory>
#include <thread>

#include "score/mw/launch_manager/alive_monitor/details/daemon/IAliveMonitor.hpp"
#include "score/mw/launch_manager/alive_monitor/IAliveMonitor.hpp"
#include "score/mw/launch_manager/alive_monitor/details/daemon/PhmDaemon.hpp"
#include "score/mw/launch_manager/configuration/config.hpp"

namespace score::mw::lifecycle
Expand All @@ -28,30 +30,47 @@ namespace internal::saf::daemon
{

using SptrIRecoveryClient = std::shared_ptr<score::mw::lifecycle::IRecoveryClient>;
using UptrISupervisionControlReceiver = std::unique_ptr<score::mw::lifecycle::ISupervisionControlReceiver>;
using UptrPhmDaemon = std::unique_ptr<score::mw::lifecycle::internal::saf::daemon::PhmDaemon>;
using OsClock = score::mw::lifecycle::internal::saf::timers::OsClockInterface;
using Config = score::mw::lifecycle::internal::configuration::Config;
using score::mw::lifecycle::internal::configuration::AliveSupervisionConfig;
using configuration::AliveSupervisionConfig;

class AliveMonitorImpl : public IAliveMonitor
{
static_assert(
std::is_trivially_copyable_v<AliveSupervisionConfig>,
"AliveSupervisionConfig is copied to this object since it is trivially copyable. If this changes, it should be "
"passed by move instead");

public:
AliveMonitorImpl(
SptrIRecoveryClient recovery_client,
UptrISupervisionControlReceiver observable_event_receiver,
const Config& config);
AliveSupervisionConfig config,
const std::size_t supervised_components);

/// @brief @see IAliveMonitor definition
bool start() noexcept override;
Comment thread
WilliamRoebuck marked this conversation as resolved.

EInitCode init() noexcept override;
/// @brief @see IAliveMonitor definition
void stop() noexcept override;

bool run(std::atomic_bool& cancel_thread) noexcept override;
/// @brief @see IAliveMonitor definition
ISupervisionFactory& getSupervisionFactory() const noexcept override;
Comment thread
WilliamRoebuck marked this conversation as resolved.

/// @brief @see IAliveMonitor definition
bool init() noexcept override;

private:
/// @brief Run the AliveMonitor functionality in a cyclic manner until cancellation is requested.
/// @param cancel_thread Atomic boolean flag to signal thread cancellation.
bool threadFn(std::atomic_bool& cancel_thread) noexcept;

SptrIRecoveryClient m_recovery_client{nullptr};
UptrPhmDaemon m_daemon{nullptr};
OsClock m_osClock{};
UptrISupervisionControlReceiver m_observable_event_receiver;
const Config& m_config;
AliveSupervisionConfig config_;
std::thread alive_monitor_thread_{};
std::atomic_bool stop_thread_{false};
std::size_t supervised_components_;
};

} // namespace internal::saf::daemon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ cc_library(
deps = [
":phm_daemon_config",
":sw_cluster_handler",
"//score/launch_manager/src/daemon/src/alive_monitor/details/common:einitcode",
"//score/launch_manager/src/daemon/src/alive_monitor/details/factory:flat_cfg_factory",
"//score/launch_manager/src/daemon/src/alive_monitor/details/ifappl:monitor_if_daemon",
"//score/launch_manager/src/daemon/src/alive_monitor/details/ifexm:observable_event_reader",
Expand All @@ -59,18 +60,10 @@ cc_library(
"//score/launch_manager/src/daemon/src/alive_monitor/details/timers:cycle_timer",
"//score/launch_manager/src/daemon/src/alive_monitor/details/timers:timers_os_clock",
"//score/launch_manager/src/daemon/src/common:log",
"//score/launch_manager/src/daemon/src/supervision_control_client:isupervision_factory",
],
)

cc_library(
name = "i_health_monitor",
hdrs = ["IAliveMonitor.hpp"],
include_prefix = "score/mw/launch_manager/alive_monitor/details/daemon",
strip_include_prefix = "/score/launch_manager/src/daemon/src/alive_monitor/details/daemon",
visibility = ["//score/launch_manager/src/daemon:__subpackages__"],
deps = [":phm_daemon"],
)

cc_library(
name = "health_monitor_impl",
srcs = ["AliveMonitorImpl.cpp"],
Expand All @@ -79,7 +72,8 @@ cc_library(
strip_include_prefix = "/score/launch_manager/src/daemon/src/alive_monitor/details/daemon",
visibility = ["//score/launch_manager/src/daemon:__subpackages__"],
deps = [
":i_health_monitor",
":phm_daemon",
"//score/launch_manager/src/daemon/src/alive_monitor:i_alive_monitor",
"//score/launch_manager/src/daemon/src/configuration:config",
"@score_baselibs//score/language/futurecpp",
],
Expand Down
Loading
Loading