89 lines
2.4 KiB
C++
89 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include <chrono>
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "manager/safety_manager/include/safety_types.h"
|
|
|
|
namespace cmvr::safety {
|
|
|
|
class DeviceSafetyEndpoint;
|
|
|
|
enum class ParticipantPhase {
|
|
Ingress,
|
|
Scheduler,
|
|
ControlSession,
|
|
Actuator,
|
|
PeripheralActivity,
|
|
Verification,
|
|
};
|
|
|
|
struct ParticipantDescriptor {
|
|
std::string participant_id;
|
|
ParticipantPhase phase{ParticipantPhase::Actuator};
|
|
bool required{true};
|
|
std::chrono::milliseconds timeout{5000};
|
|
};
|
|
|
|
struct SafetyOperationContext {
|
|
std::string operation_id;
|
|
std::uint64_t safety_epoch{0};
|
|
SafetyClock::time_point deadline{SafetyClock::time_point::max()};
|
|
};
|
|
|
|
struct BarrierToken {
|
|
std::string participant_id;
|
|
std::string operation_id;
|
|
std::uint64_t safety_epoch{0};
|
|
std::uint64_t generation{0};
|
|
|
|
bool valid() const noexcept
|
|
{
|
|
return !participant_id.empty() && !operation_id.empty() &&
|
|
safety_epoch != 0 && generation != 0;
|
|
}
|
|
};
|
|
|
|
struct ParticipantResult {
|
|
bool success{false};
|
|
SafetyReason reason{SafetyReason::StopUnconfirmed};
|
|
std::string detail;
|
|
};
|
|
|
|
class SafetyParticipant {
|
|
public:
|
|
virtual ~SafetyParticipant() = default;
|
|
virtual ParticipantDescriptor descriptor() const = 0;
|
|
virtual BarrierToken beginBarrier(
|
|
const SafetyOperationContext& context) = 0;
|
|
virtual ParticipantResult requestQuiesce(
|
|
const BarrierToken& token,
|
|
const SafetyOperationContext& context) = 0;
|
|
virtual ParticipantResult verifyQuiescent(
|
|
const BarrierToken& token,
|
|
const SafetyOperationContext& context) = 0;
|
|
virtual RecoveryCheckResult recoverAdmission(
|
|
const BarrierToken& token,
|
|
const RecoveryContext& context) = 0;
|
|
// Commits the participant's admission reopening. A failed commit must
|
|
// leave that participant fail-closed and be retryable through recovery.
|
|
virtual ParticipantResult releaseBarrier(
|
|
const BarrierToken& token) noexcept = 0;
|
|
};
|
|
|
|
class SafetyParticipantProvider {
|
|
public:
|
|
virtual ~SafetyParticipantProvider() = default;
|
|
virtual std::shared_ptr<SafetyParticipant> safetyParticipant() = 0;
|
|
};
|
|
|
|
struct DeviceSafetyRegistration {
|
|
DeviceSafetyDescriptor descriptor;
|
|
std::shared_ptr<DeviceSafetyEndpoint> endpoint;
|
|
std::shared_ptr<SafetyParticipant> participant;
|
|
};
|
|
|
|
} // namespace cmvr::safety
|