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

Event handler for a single-bit producer, e.g. More...

#include <EventHandlerTemplates.hxx>

Inheritance diagram for openlcb::BitEventProducer:
openlcb::BitEventHandler openlcb::SimpleEventHandler openlcb::EventHandler

Public Member Functions

 BitEventProducer (BitEventInterface *bit)
 
void Update (WriteHelper *writer, Notifiable *done)
 Requests the event associated with the current value of the bit to be produced (unconditionally).
 
void SendQuery (WriteHelper *writer, BarrierNotifiable *done)
 Queries consumers and acquires the current state of the bit.
 
void handle_identify_global (const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
 Called on the need of sending out identification messages.
 
void handle_identify_producer (const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
 Called on another node sending IdentifyProducer.
 
- Public Member Functions inherited from openlcb::BitEventHandler
 BitEventHandler (BitEventInterface *bit)
 
void SendEventReport (WriteHelper *writer, Notifiable *done)
 Requests the event associated with the current value of the bit to be produced (unconditionally): sends an event report packet ot the bus.
 
- 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_event_report (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done)=0
 Called on incoming EventReport messages.
 
virtual void handle_consumer_identified (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done)
 Called on another node sending ConsumerIdentified for this event.
 
virtual void handle_consumer_range_identified (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done)
 Called on another node sending ConsumerRangeIdentified.
 
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.
 
virtual void handle_identify_consumer (const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done)=0
 Called on another node sending IdentifyConsumer.
 

Private Member Functions

 DISALLOW_COPY_AND_ASSIGN (BitEventProducer)
 

Additional Inherited Members

- Public Types inherited from openlcb::EventHandler
using EventReport = openlcb::EventReport
 
using EventRegistryEntry = openlcb::EventRegistryEntry
 
using EventId = openlcb::EventId
 
- Protected Member Functions inherited from openlcb::BitEventHandler
void register_handler (uint64_t event_on, uint64_t event_off)
 Registers this event handler with the global event manager.
 
void unregister_handler ()
 Removes this event handler from the global event manager.
 
void SendProducerIdentified (EventReport *event, BarrierNotifiable *done)
 Sends off two packets using event_write_helper{1,2} of ProducerIdentified for handling a global identify events message.
 
void SendConsumerIdentified (EventReport *event, BarrierNotifiable *done)
 Sends off two packets using event_write_helper{3,4} of ConsumerIdentified for handling a global identify events message.
 
void HandlePCIdentify (Defs::MTI mti_valid, EventReport *event, BarrierNotifiable *done)
 Checks if the event in the report is something we are interested in, and if so, sends off a {Producer|Consumer}Identified{Valid|Invalid} message depending on the current state of the hardware bit.
 
- Protected Attributes inherited from openlcb::BitEventHandler
BitEventInterfacebit_
 

Detailed Description

Event handler for a single-bit producer, e.g.

an individual pin of GPIO input. Exports two event producers on the OpenLCB bus, one for the bit state == ON, and another for the bit state == OFF.

Usage:

Implement the hardware accessor methods in a descendant of BitEventInterface. Instantiate this class by passing the pointer to it in the constructor. When the hardware state changes, call the SendEventReport method.

Definition at line 609 of file EventHandlerTemplates.hxx.

Constructor & Destructor Documentation

◆ BitEventProducer()

openlcb::BitEventProducer::BitEventProducer ( BitEventInterface bit)
inline

@TODO (balazs.racz) this should be more efficient when done from the update configuration callback.

Definition at line 612 of file EventHandlerTemplates.hxx.

◆ ~BitEventProducer()

openlcb::BitEventProducer::~BitEventProducer ( )
inline

Definition at line 618 of file EventHandlerTemplates.hxx.

Member Function Documentation

◆ handle_identify_global()

void openlcb::BitEventProducer::handle_identify_global ( const EventRegistryEntry registry_entry,
EventReport event,
BarrierNotifiable done 
)
overridevirtual

Called on the need of sending out identification messages.

Parameters
eventis NULL. This happens on startup, or when a global or addressed IdentifyGlobal message arrives. Might have destination node id!
registry_entrygives the registry entry for which the current handler is being called.
donemust be notified when the processing is done.

Implements openlcb::EventHandler.

Definition at line 708 of file EventHandlerTemplates.cxx.

◆ handle_identify_producer()

void openlcb::BitEventProducer::handle_identify_producer ( const EventRegistryEntry registry_entry,
EventReport event,
BarrierNotifiable done 
)
overridevirtual

Called on another node sending IdentifyProducer.

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

Implements openlcb::EventHandler.

Definition at line 719 of file EventHandlerTemplates.cxx.

◆ SendQuery()

void openlcb::BitEventProducer::SendQuery ( WriteHelper writer,
BarrierNotifiable done 
)

Queries consumers and acquires the current state of the bit.

Definition at line 701 of file EventHandlerTemplates.cxx.

◆ Update()

void openlcb::BitEventProducer::Update ( WriteHelper writer,
Notifiable done 
)
inline

Requests the event associated with the current value of the bit to be produced (unconditionally).

Parameters
writeris the output flow to be used.
doneis the notification callback. If it is NULL, the writer will be invoked inline and potentially block the calling thread.

@TODO: remove this function and change all callers to use SendEventReport instead.

Definition at line 634 of file EventHandlerTemplates.hxx.


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