Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openlcb::BroadcastTimeServer Class Reference

Implementation of a Broadcast Time Protocol server. More...

#include <BroadcastTimeServer.hxx>

Inheritance diagram for openlcb::BroadcastTimeServer:
openlcb::BroadcastTime openlcb::SimpleEventHandler StateFlowBase TimeBase openlcb::EventHandler Executable Atomic Notifiable QMember Destructable

Public Member Functions

 BroadcastTimeServer (Node *node, NodeID clock_id)
 Constructor.
 
 ~BroadcastTimeServer ()
 Destructor.
 
bool is_server_detected () override
 Has a time server been detected?
 
bool is_server_self () override
 Test if this is a server.
 
- Public Member Functions inherited from openlcb::BroadcastTime
virtual ~BroadcastTime ()
 Destructor.
 
void set_time (int hours, int minutes)
 Set the time in seconds since the system Epoch.
 
void set_date (int month, int day)
 Set the time in seconds since the system Epoch.
 
void set_year (int year)
 Set the time in seconds since the system Epoch.
 
void set_date_year_str (const char *date_year)
 Set the date and year from a C string.
 
void set_rate_quarters (int16_t rate)
 Set Rate.
 
void start ()
 Start clock.
 
void stop ()
 Stop clock.
 
void query ()
 Query the current time.
 
UpdateSubscribeHandle update_subscribe_add (TimeUpdateCallback callback)
 Register a callback for when the time synchronization is updated.
 
void update_subscribe_remove (UpdateSubscribeHandle handle)
 Unregister a callback for when the time synchronization is updated.
 
Nodenode ()
 Accessor method to get the Node reference.
 
NodeID clock_id ()
 Accessor method to get the (48-bit) Clock ID.
 
EventId event_base ()
 Access method to get the (64-bit) Event ID base.
 
const struct tm * gmtime_recalculate ()
 Recalculate the struct tm representation of time.
 
const struct tm * gmtime_get ()
 Get the last calculated reprentation of time.
 
- Public Member Functions inherited from openlcb::SimpleEventHandler
 IGNOREFN (handle_event_report)
 
 IGNOREFN (handle_consumer_identified)
 
 IGNOREFN (handle_consumer_range_identified)
 
 IGNOREFN (handle_producer_identified)
 
 IGNOREFN (handle_producer_range_identified)
 
 IGNOREFN (handle_identify_consumer)
 
 IGNOREFN (handle_identify_producer)
 
- Public Member Functions inherited from openlcb::EventHandler
virtual void handle_producer_identified (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done)
 Called on another node sending ProducerIdentified for this event.
 
virtual void handle_producer_range_identified (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done)
 Called on another node sending ProducerRangeIdentified for this event.
 
- Public Member Functions inherited from StateFlowBase
void run () override
 Callback from the executor.
 
void notify () override
 Wakeup call arrived.
 
Serviceservice ()
 Return a pointer to the service I am bound to.
 
- Public Member Functions inherited from Executable
void test_deletion ()
 
- Public Member Functions inherited from QMember
void init ()
 Initiailize a QMember, in place of a public placement construction.
 
- Public Member Functions inherited from TimeBase
void sync (const TimeBase &other)
 Synchronizes this time with a different clock.
 
std::pair< time_t, int16_t > time_and_rate_quarters ()
 Get the time as a value of seconds relative to the system epoch.
 
time_t compare_realtime (time_t t1, time_t t2)
 Get the difference in time scaled to real time.
 
time_t time ()
 Get the time as a value of seconds relative to the system epoch.
 
struct tm * gmtime_r (struct tm *result)
 Get the time as a standard struct tm.
 
int date (int *month, int *day)
 Get the date (month/day).
 
int day_of_week ()
 Get the day of the week.
 
int day_of_year ()
 Get the day of the year.
 
int year ()
 Get the year.
 
int16_t get_rate_quarters ()
 Report the clock rate as a 12-bit fixed point number (-512.00 to 511.75).
 
bool is_running ()
 Test of the clock is running.
 
bool is_started ()
 Test of the clock is started (rate could still be 0).
 
bool fast_sec_to_real_nsec_period (int16_t rate, time_t fast_sec, long long *real_nsec)
 Convert fast clock period to a period in real nsec.
 
bool real_nsec_to_fast_sec_period (int16_t rate, long long real_nsec, time_t *fast_sec)
 Convert period in real nsec to a fast clock period.
 
bool real_nsec_until_fast_time_abs (time_t fast_sec, long long *real_nsec)
 Convert a fast time to absolute nsec until it will occur.
 
bool fast_sec_to_real_nsec_period_abs (time_t fast_sec, long long *real_nsec)
 Convert fast clock absolute (negative or positive) period to a positive (absolute) period in real nsec.
 

Private Member Functions

void handle_identify_global (const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
 Handle requested identification message.
 
void handle_identify_consumer (const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
 Handle requested identification message.
 
void handle_identify_producer (const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
 Handle requested identification message.
 
void handle_consumer_identified (const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
 Handle an incoming consumer identified.
 
void handle_consumer_range_identified (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done) override
 Called on another node sending ConsumerRangeIdentified.
 
void handle_event_report (const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
 Handle an incoming event report.
 
virtual void set_shortcut (uint64_t event) override
 Try the possible set event shortcut.
 
Action entry ()
 Entry to state machine.
 
Action query_response ()
 Respond to a query by scheduling a sync.
 
 DISALLOW_COPY_AND_ASSIGN (BroadcastTimeServer)
 

Private Attributes

time_t secondsRequested_
 pending clock time in seconds
 
uint16_t updateRequested_: 1
 clock settings have change
 
BroadcastTimeServerTimetime_
 
BroadcastTimeServerSyncsync_
 
BroadcastTimeServerSetset_
 
BroadcastTimeServerAlarmalarm_
 

Friends

class BroadcastTimeServerTime
 
class BroadcastTimeServerSync
 
class BroadcastTimeServerSet
 
class BroadcastTimeServerAlarm
 

Additional Inherited Members

- Public Types inherited from openlcb::BroadcastTime
typedef size_t UpdateSubscribeHandle
 An opaque data element that is returned from update subscriber registration, and allows unregistering a subscriber.
 
typedef std::function< void(time_t old, time_t current)> TimeUpdateCallback
 Callback type used for time update subscribers.
 
- Public Types inherited from openlcb::EventHandler
using EventReport = openlcb::EventReport
 
using EventRegistryEntry = openlcb::EventRegistryEntry
 
using EventId = openlcb::EventId
 
- Static Public Member Functions inherited from StateFlowBase
template<class T , typename... Args>
static void invoke_subflow_and_ignore_result (FlowInterface< Buffer< T > > *target_flow, Args &&... args)
 Calls a helper flow to perform some actions.
 
- Protected Types inherited from StateFlowBase
typedef Action(StateFlowBase::* Callback) ()
 State Flow callback prototype.
 
- Protected Member Functions inherited from openlcb::BroadcastTime
 BroadcastTime (Node *node, NodeID clock_id)
 Constructor.
 
void service_callbacks (time_t old, time_t current)
 Service all of the attached update subscribers.
 
- Protected Member Functions inherited from StateFlowBase
 StateFlowBase (Service *service)
 Constructor.
 
 ~StateFlowBase ()
 Destructor.
 
void reset_flow (Callback c)
 Resets the flow to the specified state.
 
bool is_state (Callback c)
 
bool is_terminated ()
 
void start_flow (Callback c)
 Resets the flow to the specified state and starts it.
 
Action again ()
 Call the current state again via call_immediately.
 
Action exit ()
 Terminate current StateFlow activity.
 
Action delete_this ()
 Terminates the flow and deletes *this.
 
Action set_terminated ()
 Sets the flow to terminated state.
 
Action call_immediately (Callback c)
 Imediately call the next state upon return.
 
Action wait ()
 Wait for an asynchronous call.
 
Action wait_and_call (Callback c)
 Wait for resource to become available before proceeding to next state.
 
template<class T >
Action allocate_and_call (FlowInterface< Buffer< T > > *target_flow, Callback c, Pool *pool=nullptr)
 Allocates a buffer from a pool and proceed to the next state when allocation is successful.
 
Action allocate_and_call (Callback c, QAsync *queue)
 Allocates an entry from an asynchronous queue, and transitions to a state once the allocation is complete.
 
template<class T >
Buffer< T > * full_allocation_result (FlowInterface< Buffer< T > > *target_flow)
 Takes the result of the asynchronous allocation without resetting the object.
 
template<class T >
T * full_allocation_result (TypedQAsync< T > *queue)
 Takes the result of the asynchronous allocation without resetting the object.
 
template<class T >
void cast_allocation_result (T **member)
 Takes the result of the asynchronous allocation without resetting the object.
 
template<class T >
Buffer< T > * get_allocation_result (FlowInterface< Buffer< T > > *target_flow)
 Takes the result of the asynchronous allocation.
 
Action yield_and_call (Callback c)
 Place the current flow to the back of the executor, and transition to a new state after we get the CPU again.
 
Action yield ()
 Place the current flow to the back of the executor, and re-try the current state after we get the CPU again.
 
Action sleep_and_call (::Timer *timer, long long timeout_nsec, Callback c)
 Suspends execution of this control flow for a specified time.
 
template<class T , typename... Args>
Action invoke_subflow_and_wait (FlowInterface< Buffer< T > > *target_flow, Callback c, Args &&... args)
 Calls a helper flow to perform some actions.
 
Action read_repeated (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Blocks until size bytes are read and then invokes the next state.
 
Action read_single (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Attempts to read at most size_t bytes, and blocks the caller until at least one byte is read.
 
Action read_nonblocking (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Attempts to read at most size bytes, and then invokes the next state, even if only zero bytes are available right now.
 
Action read_repeated_with_timeout (StateFlowTimedSelectHelper *helper, long long timeout_nsec, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Blocks until size bytes are read, or a timeout expires.
 
Action internal_try_read ()
 Implementation state that gets repeatedly called upon every wakeup and tries to make progress on reading.
 
Action write_repeated (StateFlowSelectHelper *helper, int fd, const void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Writes some data into a file descriptor, repeating the operation as necessary until all bytes are written.
 
Action internal_try_write ()
 Implementation state that gets repeatedly called upon every wakeup and tries to make progress on writing.
 
- Protected Member Functions inherited from QMember
 QMember ()
 Constructor.
 
 ~QMember ()
 Destructor.
 
- Protected Member Functions inherited from Atomic
void lock ()
 
void unlock ()
 
- Protected Attributes inherited from openlcb::BroadcastTime
struct tm tm_
 the time we are last set to as a struct tm
 
Nodenode_
 OpenLCB node to export the consumer on.
 
EventId eventBase_
 48-bit unique identifier for the clock instance
 
WriteHelper writer_
 helper for sending event messages
 
StateFlowTimer timer_
 timer helper
 
std::vector< TimeUpdateCallbackcallbacks_
 update subscribers
 
int16_t rateRequested_
 pending clock rate
 
- Protected Attributes inherited from QMember
QMembernext
 pointer to the next member in the queue
 
- Protected Attributes inherited from TimeBase
long long timestamp_ {OSTime::get_monotonic()}
 OS time at the last time update.
 
time_t seconds_ {0}
 Clock time at the last time update.
 
int16_t rate_ {0}
 effective clock rate
 
uint16_t started_: 1
 true if clock is started
 

Detailed Description

Implementation of a Broadcast Time Protocol server.

Note: A Broadcast Time server must produce all the individual time events for which there is an identified consumer. In order to guarantee that the server can identify all of the consumers, it is important to have an Event Identify Global message sent after the creation of the server object. In order to prevent unnecessary duplication of Event Identify Global messages, it is left to the application to send the Event Identify Global message. An application can use the openlcb::EventIdentifyGlobal object for production of an Event Identify Global message.

Definition at line 58 of file BroadcastTimeServer.hxx.

Constructor & Destructor Documentation

◆ BroadcastTimeServer()

openlcb::BroadcastTimeServer::BroadcastTimeServer ( Node node,
NodeID  clock_id 
)

Constructor.

Parameters
nodethe virtual node that will be listening for events and responding to Identify messages.
clock_id48-bit unique identifier for the clock instance

Definition at line 803 of file BroadcastTimeServer.cxx.

◆ ~BroadcastTimeServer()

openlcb::BroadcastTimeServer::~BroadcastTimeServer ( )

Destructor.

Definition at line 822 of file BroadcastTimeServer.cxx.

Member Function Documentation

◆ entry()

Action openlcb::BroadcastTimeServer::entry ( )
inlineprivate

Entry to state machine.

Returns
query_response after timeout

Definition at line 191 of file BroadcastTimeServer.hxx.

◆ handle_consumer_identified()

void openlcb::BroadcastTimeServer::handle_consumer_identified ( const EventRegistryEntry entry,
EventReport event,
BarrierNotifiable done 
)
overrideprivatevirtual

Handle an incoming consumer identified.

Parameters
entryregistry entry for the event range
eventinformation about the incoming message
doneused to notify we are finished

Reimplemented from openlcb::EventHandler.

Definition at line 848 of file BroadcastTimeServer.cxx.

◆ handle_consumer_range_identified()

void openlcb::BroadcastTimeServer::handle_consumer_range_identified ( const EventRegistryEntry registry_entry,
EventReport event,
BarrierNotifiable done 
)
overrideprivatevirtual

Called on another node sending ConsumerRangeIdentified.

Parameters
eventstores information about the incoming message. Filled: event id, mask (!= 1), src_node. Not filled: state.
registry_entrygives the registry entry for which the current handler is being called.
donemust be notified when the processing is done.

Reimplemented from openlcb::EventHandler.

Definition at line 871 of file BroadcastTimeServer.cxx.

◆ handle_event_report()

void openlcb::BroadcastTimeServer::handle_event_report ( const EventRegistryEntry entry,
EventReport event,
BarrierNotifiable done 
)
overrideprivatevirtual

Handle an incoming event report.

Parameters
entryregistry entry for the event range
eventinformation about the incoming message
doneused to notify we are finished

Implements openlcb::EventHandler.

Definition at line 886 of file BroadcastTimeServer.cxx.

◆ handle_identify_consumer()

void openlcb::BroadcastTimeServer::handle_identify_consumer ( const EventRegistryEntry entry,
EventReport event,
BarrierNotifiable done 
)
inlineoverrideprivatevirtual

Handle requested identification message.

Parameters
entryregistry entry for the event range
eventinformation about the incoming message
doneused to notify we are finished

Implements openlcb::EventHandler.

Definition at line 127 of file BroadcastTimeServer.hxx.

◆ handle_identify_global()

void openlcb::BroadcastTimeServer::handle_identify_global ( const EventRegistryEntry entry,
EventReport event,
BarrierNotifiable done 
)
inlineoverrideprivatevirtual

Handle requested identification message.

Parameters
entryregistry entry for the event range
eventinformation about the incoming message
doneused to notify we are finished

Implements openlcb::EventHandler.

Definition at line 95 of file BroadcastTimeServer.hxx.

◆ handle_identify_producer()

void openlcb::BroadcastTimeServer::handle_identify_producer ( const EventRegistryEntry entry,
EventReport event,
BarrierNotifiable done 
)
inlineoverrideprivatevirtual

Handle requested identification message.

Parameters
entryregistry entry for the event range
eventinformation about the incoming message
doneused to notify we are finished

Implements openlcb::EventHandler.

Definition at line 148 of file BroadcastTimeServer.hxx.

◆ is_server_detected()

bool openlcb::BroadcastTimeServer::is_server_detected ( )
inlineoverridevirtual

Has a time server been detected?

Returns
true if a time server has been detected, else false

Implements openlcb::BroadcastTime.

Definition at line 72 of file BroadcastTimeServer.hxx.

◆ is_server_self()

bool openlcb::BroadcastTimeServer::is_server_self ( )
inlineoverridevirtual

Test if this is a server.

Returns
true if a BroadcastTimeServer, else false

Implements openlcb::BroadcastTime.

Definition at line 79 of file BroadcastTimeServer.hxx.

◆ query_response()

StateFlowBase::Action openlcb::BroadcastTimeServer::query_response ( )
private

Respond to a query by scheduling a sync.

Returns
exit()

Definition at line 924 of file BroadcastTimeServer.cxx.

◆ set_shortcut()

void openlcb::BroadcastTimeServer::set_shortcut ( uint64_t  event)
overrideprivatevirtual

Try the possible set event shortcut.

Parameters
eventevent that we would be "setting"

Reimplemented from openlcb::BroadcastTime.

Definition at line 898 of file BroadcastTimeServer.cxx.

Friends And Related Symbol Documentation

◆ BroadcastTimeServerAlarm

friend class BroadcastTimeServerAlarm
friend

Definition at line 216 of file BroadcastTimeServer.hxx.

◆ BroadcastTimeServerSet

friend class BroadcastTimeServerSet
friend

Definition at line 215 of file BroadcastTimeServer.hxx.

◆ BroadcastTimeServerSync

friend class BroadcastTimeServerSync
friend

Definition at line 214 of file BroadcastTimeServer.hxx.

◆ BroadcastTimeServerTime

friend class BroadcastTimeServerTime
friend

Definition at line 213 of file BroadcastTimeServer.hxx.

Member Data Documentation

◆ alarm_

BroadcastTimeServerAlarm* openlcb::BroadcastTimeServer::alarm_
private

Definition at line 211 of file BroadcastTimeServer.hxx.

◆ secondsRequested_

time_t openlcb::BroadcastTimeServer::secondsRequested_
private

pending clock time in seconds

Definition at line 202 of file BroadcastTimeServer.hxx.

◆ set_

BroadcastTimeServerSet* openlcb::BroadcastTimeServer::set_
private

Definition at line 210 of file BroadcastTimeServer.hxx.

◆ sync_

BroadcastTimeServerSync* openlcb::BroadcastTimeServer::sync_
private

Definition at line 209 of file BroadcastTimeServer.hxx.

◆ time_

BroadcastTimeServerTime* openlcb::BroadcastTimeServer::time_
private

Definition at line 208 of file BroadcastTimeServer.hxx.

◆ updateRequested_

uint16_t openlcb::BroadcastTimeServer::updateRequested_
private

clock settings have change

Definition at line 203 of file BroadcastTimeServer.hxx.


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