35#ifndef _OPENLCB_IFCAN_HXX_
36#define _OPENLCB_IFCAN_HXX_
86 int local_alias_cache_size,
int remote_alias_cache_size,
87 int local_nodes_count);
173 return static_cast<IfCan *
>(service());
206 :
public StateFlow<Buffer<NodeCanonicalizeRequest>, QList<1>>
219 if (
input()->handle.id != 0)
223 if (
input()->handle.alias == 0)
238 return allocate_and_call(
247 get_allocation_result(
iface()->addressed_message_write_flow());
250 replyHandler_.set_alias_waiting(
input()->handle.alias);
260 replyHandler_.set_alias_waiting(0);
261 if (!
timer_.is_triggered())
265 if (!
input()->handle.id)
303 if (msg->
src.
id != 0)
307 else if (msg->
payload.size() == 6)
332 } replyHandler_{
this};
334 friend class ReplyHandler;
359 return static_cast<IfCan *
>(service());
std::unique_ptr< Buffer< T >, BufferDelete< T > > AutoReleaseBuffer
This class will automatically unref a Buffer when going out of scope.
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
A BarrierNotifiable allows to create a number of child Notifiable and wait for all of them to finish.
Base class for all QMember types that hold data in an expandable format.
Interface class for the asynchronous frame write flow.
Interface class for CANbus-based protocols.
void register_handler(HandlerType *handler, ID id, ID mask)
Adds a new handler to this dispatcher.
void unregister_handler(HandlerType *handler, ID id, ID mask)
Removes a specific instance of a handler from this dispatcher.
An object that can be scheduled on an executor to run.
This class implements an execution of tasks pulled off an input queue.
void assert_current()
Die if we are not on the current executor.
virtual void send(MessageType *message, unsigned priority=UINT_MAX)=0
Entry point to the flow.
ExecutorBase * executor()
State flow with a given typed input queue.
Base::Action Action
Allows using Action without having StateFlowBase:: prefix in front of it.
void return_buffer()
For state flows that are operated using invoke_subflow_and_wait this is a way to hand back the buffer...
This state flow is responsible for reserving node ID aliases.
Cache of alias to node id mappings.
NodeAlias lookup(NodeID id)
Lookup a node's alias based on its Node ID.
Base class for incoming CAN frame handlers.
Implementation of the OpenLCB interface abstraction for the CAN-bus interface standard.
std::vector< std::unique_ptr< Executable > > ownedFlows_
Various implementation control flows that this interface owns.
void add_addressed_message_support()
Adds support to this interface for addressed NMRAnet messages (both sending and receiving).
Node * lookup_local_node_handle(NodeHandle handle) override
Looks up a node ID in the local nodes' registry.
void send_global_alias_enquiry(Node *source)
Sends a global alias enquiry packet.
void set_alias_allocator(AliasAllocator *a)
Sets the alias allocator for this If. Takes ownership of pointer.
AliasCache localAliases_
Aliases we know are owned by local (virtual or proxied) nodes.
NodeID get_default_node_id() override
bool matching_node(NodeHandle expected, NodeHandle actual) override
std::unique_ptr< AliasAllocator > aliasAllocator_
Owns the alias allocator module.
AliasCache remoteAliases_
Aliases we know are owned by remote nodes on this If.
AliasCache * local_aliases()
void delete_local_node(Node *node) override
Removes a local node from this interface.
AliasAllocator * alias_allocator()
AliasCache * remote_aliases()
void add_owned_flow(Executable *e) override
Transfers ownership of a module to the interface.
void canonicalize_handle(NodeHandle *h) override
Canonicalizes the node handle: fills in id and/or alias from the maps the interface holds internally.
Abstract class representing an OpenLCB Interface.
MessageDispatchFlow * dispatcher()
MessageHandler * addressed_message_write_flow()
Class for listening to the ping response packets.
void send(Buffer< GenMessage > *message, unsigned priority) OVERRIDE
Handler callback for incoming messages.
NodeIdLookupFlow * parent_
Flow owning *this.
ReplyHandler(NodeIdLookupFlow *parent)
Constructor.
void set_alias_waiting(NodeAlias a)
The parent flow calls this function when the handler needs to be activated.
NodeAlias aliasWaiting_
Which node alias we are listening for a reply from.
~ReplyHandler()
Destructor. Unregisters the handler.
Child flow to be used in parents that need translation from node alias to node id.
NodeCanonicalizeRequest * input()
Action send_request()
Send out a ping request to the destination alias.
Action return_ok()
Terminates the current subflow with no error.
Action entry() override
Starts processing an incoming request.
StateFlowTimer timer_
Helper object for timed wait.
Action return_with_error(int error)
Terminates the current subflow with an error code.
Action reply_timeout()
Called when a reply arrives or the timeout expires.
NodeIdLookupFlow(IfCan *iface)
Constructor.
BarrierNotifiable bn_
Helper object for calling subflows.
Base class for NMRAnet nodes conforming to the asynchronous interface.
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
string EMPTY_PAYLOAD
A global class / variable for empty or not-yet-initialized payloads.
NodeID data_to_node_id(const void *d)
Converts 6 bytes of big-endian data to a node ID.
uint64_t NodeID
48-bit NMRAnet Node ID type
size_t g_alias_use_conflicts
Counts the number of alias conflicts that we see for aliases that we already reserved.
uint16_t NodeAlias
Alias to a 48-bit NMRAnet Node ID type.
#define MSEC_TO_NSEC(_msec)
Convert a millisecond value to a nanosecond value.
@ MTI_VERIFY_NODE_ID_ADDRESSED
verify a Node ID
@ MTI_EXACT
match mask for a single MTI
@ MTI_VERIFIED_NODE_ID_NUMBER
respond to a verify Node ID request
This class is used in the dispatching of incoming or outgoing NMRAnet messages to the message handler...
NodeHandle src
Source node.
string payload
Data content in the message body.
Request object for the NodeIdLookupFlow.
NodeHandle handle
Destination node handle to canonicalize.
int resultCode
Set to 0 on success, or an OpenLCB or OpenMRN error code in case of a failure.
Node * srcNode
Caller node (in order to talk to the bus)
void reset(Node *node, NodeHandle handle)
Requests a NodeHandle to be canonicalized, i.e.
BarrierNotifiable done
Needed for receiveing replies by the customer.
Container of both a NodeID and NodeAlias.
NodeID id
48-bit NMRAnet Node ID
NodeAlias alias
alias to NMRAnet Node ID