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

This state flow is responsible for reserving node ID aliases. More...

#include <AliasAllocator.hxx>

Inheritance diagram for openlcb::AliasAllocator:
StateFlow< Buffer< AliasInfo >, QList< 1 > > TypedStateFlow< MessageType, Base > FlowInterface< MessageType >

Classes

class  ConflictHandler
 Listens to incoming CAN frames and handles alias conflicts. More...
 

Public Member Functions

 AliasAllocator (NodeID if_id, IfCan *if_can)
 Constructs a new AliasAllocator flow.
 
virtual ~AliasAllocator ()
 Destructor.
 
NodeID if_node_id ()
 
void reinit_seed ()
 Resets the alias allocator to the state it was at construction.
 
NodeAlias get_new_seed ()
 Returns a new alias to check from the random sequence.
 
NodeAlias get_allocated_alias (NodeID destination_id, Executable *done)
 Allocates an alias from the reserved but unused aliases list.
 
unsigned num_reserved_aliases ()
 
void clear_reserved_aliases ()
 Removes all aliases that are reserved but not yet used.
 
void return_alias (NodeID id, NodeAlias alias)
 Releases a given alias.
 
void add_allocated_alias (NodeAlias alias)
 Call from an alternate alias allocator.
 
- Public Member Functions inherited from StateFlow< Buffer< AliasInfo >, QList< 1 > >
 StateFlow (Service *service)
 Constructor.
 
- Public Member Functions inherited from TypedStateFlow< MessageType, Base >
 TypedStateFlow (Service *service)
 Constructor.
 
virtual ~TypedStateFlow ()
 Destructor.
 
void send (MessageType *msg, unsigned priority=UINT_MAX) OVERRIDE
 Sends a message to the state flow for processing.
 
- Public Member Functions inherited from FlowInterface< MessageType >
virtual Poolpool ()
 
virtual MessageType * type_helper ()
 This function is never user in the code, but GDB can use it to infer the correct message types.
 
MessageType * alloc ()
 Synchronously allocates a message buffer from the pool of this flow.
 
void alloc_async (Executable *target)
 Asynchronously allocates a message buffer from the pool of this flow.
 

Private Member Functions

AliasInfopending_alias ()
 
Action entry () override
 Entry into the StateFlow activity.
 
Action handle_allocate_for_cid_frame ()
 
Action send_cid_frame ()
 
Action wait_done ()
 
Action send_rid_frame ()
 
Action handle_alias_conflict ()
 
void next_seed ()
 Generates the next alias to check in the seed_ variable.
 
IfCanif_can ()
 Physical interface for sending packets and assigning handlers to received packets.
 

Private Attributes

openlcb::AliasAllocator::ConflictHandler conflictHandler_
 
StateFlowTimer timer_
 
Q waitingClients_
 Set of client flows that are waiting for allocating an alias.
 
NodeID if_id_
 48-bit nodeID that we will use for alias reservations.
 
unsigned cid_frame_sequence_: 3
 Which CID frame are we trying to send out. Valid values: 7..4.
 
unsigned conflict_detected_: 1
 Set to 1 if an incoming frame signals an alias conflict.
 
unsigned seed_: 12
 Seed for generating random-looking alias numbers.
 
unsigned reserveUnusedAliases_: 8
 How many unused aliases we should reserve.
 
BarrierNotifiable n_
 Notifiable used for tracking outgoing frames.
 

Friends

class ConflictHandler
 
class AsyncAliasAllocatorTest
 
class AsyncIfTest
 

Additional Inherited Members

- Public Types inherited from TypedStateFlow< MessageType, Base >
typedef Base::Action Action
 Allows using Action without having StateFlowBase:: prefix in front of it.
 
- Public Types inherited from FlowInterface< MessageType >
typedef MessageType message_type
 Stores the message template type for external reference.
 
- Static Public Member Functions inherited from FlowInterface< MessageType >
static MessageType * cast_alloc (QMember *entry)
 Down casts and initializes an asynchronous allocation result to the appropriate flow's buffer type.
 
- Protected Member Functions inherited from TypedStateFlow< MessageType, Base >
void release () OVERRIDE
 Unrefs the current buffer.
 
void return_buffer ()
 For state flows that are operated using invoke_subflow_and_wait this is a way to hand back the buffer to the caller.
 
MessageType * message ()
 
MessageType * transfer_message ()
 Releases ownership of the current message.
 

Detailed Description

This state flow is responsible for reserving node ID aliases.

For every incoming Buffer<AliasInfo> it will run through the standard-compliant flow of reserving an alias, and then push the alias into the queue of reserved aliases.

Users who need an allocated alias should get it from the queue in reserved_aliases().

Definition at line 95 of file AliasAllocator.hxx.

Constructor & Destructor Documentation

◆ AliasAllocator()

openlcb::AliasAllocator::AliasAllocator ( NodeID  if_id,
IfCan if_can 
)

Constructs a new AliasAllocator flow.

Parameters
if_idis a 48-bit NMRAnet NodeID. This node id will be used for reserving all aliases. This NodeID must be unique to the hardware on the bus; it will typically be the same as the NodeID of some virtual node that the current application will be creating.
if_canis the interface to which this alias allocator should talk to.

Definition at line 44 of file AliasAllocator.cxx.

◆ ~AliasAllocator()

openlcb::AliasAllocator::~AliasAllocator ( )
virtual

Destructor.

Definition at line 202 of file AliasAllocator.cxx.

Member Function Documentation

◆ add_allocated_alias()

void openlcb::AliasAllocator::add_allocated_alias ( NodeAlias  alias)

Call from an alternate alias allocator.

Marks that alias is reserved for the local interface (RID frame is just sent out). Adds the alias to the local alias cache and wakes up a flow that might be waiting for an alias.

Parameters
aliasa reserved node alias.

Definition at line 141 of file AliasAllocator.cxx.

◆ clear_reserved_aliases()

void openlcb::AliasAllocator::clear_reserved_aliases ( )

Removes all aliases that are reserved but not yet used.

Definition at line 106 of file AliasAllocator.cxx.

◆ entry()

StateFlowBase::Action openlcb::AliasAllocator::entry ( )
overrideprivatevirtual

Entry into the StateFlow activity.

Pure virtual which must be defined by derived class.

Returns
function pointer to next state

Implements TypedStateFlow< MessageType, Base >.

Definition at line 206 of file AliasAllocator.cxx.

◆ get_allocated_alias()

NodeAlias openlcb::AliasAllocator::get_allocated_alias ( NodeID  destination_id,
Executable done 
)

Allocates an alias from the reserved but unused aliases list.

If there is a free alias there, that alias will be reassigned to destination_id in the local alias cache, and done will never be notified. If there is no free alias, then a new alias will be allocated, and done will be notified when the allocation is complete. Then the call has to be re-tried by the destination flow.

Parameters
destination_idif there is a free alias right now, it will be assigned to this Node ID in the local alias cache.
doneif an async allocation is necessary, this will be notified after a new alias has been received.
Returns
the alias if the it was allocated inline, or 0 if there will be an asynchronous notification coming later.

Definition at line 159 of file AliasAllocator.cxx.

◆ get_new_seed()

NodeAlias openlcb::AliasAllocator::get_new_seed ( )

Returns a new alias to check from the random sequence.

Checks that it is not in the alias cache yet.

Definition at line 224 of file AliasAllocator.cxx.

◆ handle_alias_conflict()

StateFlowBase::Action openlcb::AliasAllocator::handle_alias_conflict ( )
private

Definition at line 301 of file AliasAllocator.cxx.

◆ handle_allocate_for_cid_frame()

StateFlowBase::Action openlcb::AliasAllocator::handle_allocate_for_cid_frame ( )
private

Definition at line 267 of file AliasAllocator.cxx.

◆ if_can()

IfCan * openlcb::AliasAllocator::if_can ( )
inlineprivate

Physical interface for sending packets and assigning handlers to received packets.

Definition at line 223 of file AliasAllocator.hxx.

◆ if_node_id()

NodeID openlcb::AliasAllocator::if_node_id ( )
inline
Returns
the Node ID for the interface.

Definition at line 115 of file AliasAllocator.hxx.

◆ next_seed()

void openlcb::AliasAllocator::next_seed ( )
private

Generates the next alias to check in the seed_ variable.

Definition at line 249 of file AliasAllocator.cxx.

◆ num_reserved_aliases()

unsigned openlcb::AliasAllocator::num_reserved_aliases ( )
Returns
the number of aliases that are reserved and available for new virtual nodes to use.

Definition at line 84 of file AliasAllocator.cxx.

◆ pending_alias()

AliasInfo * openlcb::AliasAllocator::pending_alias ( )
inlineprivate

Definition at line 194 of file AliasAllocator.hxx.

◆ reinit_seed()

void openlcb::AliasAllocator::reinit_seed ( )

Resets the alias allocator to the state it was at construction.

useful after connection restart in order to ensure it will try to allocate the same alias.

Definition at line 58 of file AliasAllocator.cxx.

◆ return_alias()

void openlcb::AliasAllocator::return_alias ( NodeID  id,
NodeAlias  alias 
)

Releases a given alias.

Sends out an AMR frame and puts the alias into the reserved aliases queue.

Definition at line 126 of file AliasAllocator.cxx.

◆ send_cid_frame()

StateFlowBase::Action openlcb::AliasAllocator::send_cid_frame ( )
private

Definition at line 281 of file AliasAllocator.cxx.

◆ send_rid_frame()

StateFlowBase::Action openlcb::AliasAllocator::send_rid_frame ( )
private

Definition at line 325 of file AliasAllocator.cxx.

◆ wait_done()

StateFlowBase::Action openlcb::AliasAllocator::wait_done ( )
private

Definition at line 314 of file AliasAllocator.cxx.

Friends And Related Symbol Documentation

◆ AsyncAliasAllocatorTest

friend class AsyncAliasAllocatorTest
friend

Definition at line 210 of file AliasAllocator.hxx.

◆ AsyncIfTest

friend class AsyncIfTest
friend

Definition at line 211 of file AliasAllocator.hxx.

◆ ConflictHandler

friend class ConflictHandler
friend

Definition at line 192 of file AliasAllocator.hxx.

Member Data Documentation

◆ cid_frame_sequence_

unsigned openlcb::AliasAllocator::cid_frame_sequence_
private

Which CID frame are we trying to send out. Valid values: 7..4.

Definition at line 229 of file AliasAllocator.hxx.

◆ conflict_detected_

unsigned openlcb::AliasAllocator::conflict_detected_
private

Set to 1 if an incoming frame signals an alias conflict.

Definition at line 231 of file AliasAllocator.hxx.

◆ if_id_

NodeID openlcb::AliasAllocator::if_id_
private

48-bit nodeID that we will use for alias reservations.

Definition at line 219 of file AliasAllocator.hxx.

◆ n_

BarrierNotifiable openlcb::AliasAllocator::n_
private

Notifiable used for tracking outgoing frames.

Definition at line 241 of file AliasAllocator.hxx.

◆ reserveUnusedAliases_

unsigned openlcb::AliasAllocator::reserveUnusedAliases_
private

How many unused aliases we should reserve.

Currently we only support 0 or 1 as value.

Definition at line 238 of file AliasAllocator.hxx.

◆ seed_

unsigned openlcb::AliasAllocator::seed_
private

Seed for generating random-looking alias numbers.

Definition at line 234 of file AliasAllocator.hxx.

◆ timer_

StateFlowTimer openlcb::AliasAllocator::timer_
private

Definition at line 213 of file AliasAllocator.hxx.

◆ waitingClients_

Q openlcb::AliasAllocator::waitingClients_
private

Set of client flows that are waiting for allocating an alias.

Definition at line 216 of file AliasAllocator.hxx.


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