Communication Library for Autonomous Systems v1.0
Reliable and secure communication library for autonomous vehicle systems
Loading...
Searching...
No Matches
Clock Class Reference

Thread-safe singleton for PTP clock synchronization. More...

#include <clock.h>

Public Types

enum class  State { UNSYNCHRONIZED , AWAITING_SECOND_MSG , SYNCHRONIZED }
 

Public Member Functions

 Clock (const Clock &)=delete
 
Clockoperator= (const Clock &)=delete
 
void setSelfId (LeaderIdType id)
 Set the self ID for this clock instance (node's own PTP-relevant ID)
 
void activate (const PtpRelevantData *new_msg_data)
 Activate the state machine with new PTP data.
 
TimestampType getSynchronizedTime (bool *is_synchronized)
 Get the current synchronized time.
 
bool isFullySynchronized () const
 Check if clock is fully synchronized.
 
State getState ()
 Get current synchronization state.
 
LeaderIdType getCurrentLeader () const
 Get the current PTP leader ID.
 
TimestampType getLocalSteadyHardwareTime () const
 
TimestampType getLocalSystemTime ()
 
DurationType getMaxLeaderSilenceInterval () const
 
void reset ()
 Reset the Clock singleton to its initial state (for testing only)
 

Static Public Member Functions

static ClockgetInstance ()
 Get the singleton instance.
 

Detailed Description

Thread-safe singleton for PTP clock synchronization.

This class is thread-safe and can be accessed from multiple threads. All state access is protected by mutex locks. The singleton instance is initialized in a thread-safe manner using C++11's static initialization guarantees.

Member Enumeration Documentation

◆ State

Enumerator
UNSYNCHRONIZED 
AWAITING_SECOND_MSG 
SYNCHRONIZED 

Constructor & Destructor Documentation

◆ Clock()

Clock::Clock ( const Clock )
delete

Member Function Documentation

◆ activate()

void Clock::activate ( const PtpRelevantData new_msg_data)
inline

Activate the state machine with new PTP data.

Parameters
new_msg_dataPTP data from incoming message or nullptr for timeout checks

Thread-safe: Protected by mutex

◆ getCurrentLeader()

LeaderIdType Clock::getCurrentLeader ( ) const
inline

Get the current PTP leader ID.

Returns
Current leader ID

Thread-safe: Protected by mutex

◆ getInstance()

Clock & Clock::getInstance ( )
inlinestatic

Get the singleton instance.

Returns
Reference to the singleton instance

Thread-safe: Uses C++11's static initialization guarantees

◆ getLocalSteadyHardwareTime()

TimestampType Clock::getLocalSteadyHardwareTime ( ) const
inline

◆ getLocalSystemTime()

TimestampType Clock::getLocalSystemTime ( )
inline

◆ getMaxLeaderSilenceInterval()

DurationType Clock::getMaxLeaderSilenceInterval ( ) const
inline

◆ getState()

Clock::State Clock::getState ( )
inline

Get current synchronization state.

Returns
Current state

Thread-safe: Protected by mutex

◆ getSynchronizedTime()

TimestampType Clock::getSynchronizedTime ( bool is_synchronized)
inline

Get the current synchronized time.

Returns
Current PTP-synchronized timestamp

Thread-safe: Protected by mutex

◆ isFullySynchronized()

bool Clock::isFullySynchronized ( ) const
inline

Check if clock is fully synchronized.

Returns
true if in SYNCHRONIZED state

Thread-safe: Protected by mutex

◆ operator=()

Clock & Clock::operator= ( const Clock )
delete

◆ reset()

void Clock::reset ( )
inline

Reset the Clock singleton to its initial state (for testing only)

This method is NOT thread-safe and should only be used in test setup/teardown.

◆ setSelfId()

void Clock::setSelfId ( LeaderIdType  id)
inline

Set the self ID for this clock instance (node's own PTP-relevant ID)

Parameters
idThe LeaderIdType of this node

Thread-safe: Protected by mutex


The documentation for this class was generated from the following file: