|
Open Model Railroad Network (OpenMRN)
|
This state flow is responsible for reserving node ID aliases. More...
#include <AliasAllocator.hxx>
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 Pool * | pool () |
| 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 | |
| AliasInfo * | pending_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. | |
| IfCan * | if_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. | |
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.
Constructs a new AliasAllocator flow.
| if_id | is 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_can | is the interface to which this alias allocator should talk to. |
Definition at line 44 of file AliasAllocator.cxx.
|
virtual |
Destructor.
Definition at line 202 of file AliasAllocator.cxx.
| 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.
| alias | a reserved node alias. |
Definition at line 141 of file AliasAllocator.cxx.
| void openlcb::AliasAllocator::clear_reserved_aliases | ( | ) |
Removes all aliases that are reserved but not yet used.
Definition at line 106 of file AliasAllocator.cxx.
|
overrideprivatevirtual |
Entry into the StateFlow activity.
Pure virtual which must be defined by derived class.
Implements TypedStateFlow< MessageType, Base >.
Definition at line 206 of file AliasAllocator.cxx.
| 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.
| destination_id | if there is a free alias right now, it will be assigned to this Node ID in the local alias cache. |
| done | if an async allocation is necessary, this will be notified after a new alias has been received. |
Definition at line 159 of file AliasAllocator.cxx.
| 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.
|
private |
Definition at line 301 of file AliasAllocator.cxx.
|
private |
Definition at line 267 of file AliasAllocator.cxx.
|
inlineprivate |
Physical interface for sending packets and assigning handlers to received packets.
Definition at line 223 of file AliasAllocator.hxx.
|
inline |
Definition at line 115 of file AliasAllocator.hxx.
|
private |
Generates the next alias to check in the seed_ variable.
Definition at line 249 of file AliasAllocator.cxx.
| unsigned openlcb::AliasAllocator::num_reserved_aliases | ( | ) |
Definition at line 84 of file AliasAllocator.cxx.
|
inlineprivate |
Definition at line 194 of file AliasAllocator.hxx.
| 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.
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.
|
private |
Definition at line 281 of file AliasAllocator.cxx.
|
private |
Definition at line 325 of file AliasAllocator.cxx.
|
private |
Definition at line 314 of file AliasAllocator.cxx.
|
friend |
Definition at line 210 of file AliasAllocator.hxx.
|
friend |
Definition at line 211 of file AliasAllocator.hxx.
|
friend |
Definition at line 192 of file AliasAllocator.hxx.
|
private |
Which CID frame are we trying to send out. Valid values: 7..4.
Definition at line 229 of file AliasAllocator.hxx.
|
private |
Set to 1 if an incoming frame signals an alias conflict.
Definition at line 231 of file AliasAllocator.hxx.
|
private |
48-bit nodeID that we will use for alias reservations.
Definition at line 219 of file AliasAllocator.hxx.
|
private |
Notifiable used for tracking outgoing frames.
Definition at line 241 of file AliasAllocator.hxx.
|
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.
|
private |
Seed for generating random-looking alias numbers.
Definition at line 234 of file AliasAllocator.hxx.
|
private |
Definition at line 213 of file AliasAllocator.hxx.
|
private |
Set of client flows that are waiting for allocating an alias.
Definition at line 216 of file AliasAllocator.hxx.