Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
NodeBrowser.cxx
Go to the documentation of this file.
1
35
36namespace openlcb
37{
38
40 : node_(node)
41 , callback_(std::move(cb))
42{
44}
45
50
52{
53 auto b = node_->iface()->global_message_write_flow()->alloc();
54 b->data()->reset(
56 node_->iface()->global_message_write_flow()->send(b);
57}
58
66
71
73 : parent_(parent)
74{
75}
76
78{
79 auto d = get_buffer_deleter(b);
80 if (b->data()->payload.size() != 6)
81 {
82 return;
83 }
84 NodeID tgt = buffer_to_node_id(b->data()->payload);
85 parent_->callback_(tgt);
86}
87
88} // namespace openlcb
BufferPtr< T > get_buffer_deleter(Buffer< T > *b)
Helper function to create a BufferPtr of an appropriate type without having to explicitly specify the...
Definition Buffer.hxx:272
Base class for all QMember types that hold data in an expandable format.
Definition Buffer.hxx:195
T * data()
get a pointer to the start of the data.
Definition Buffer.hxx:215
void register_handler(HandlerType *handler, ID id, ID mask)
Adds a new handler to this dispatcher.
void unregister_handler_all(HandlerType *handler)
Removes all instances of a handler from this dispatcher.
virtual void send(MessageType *message, unsigned priority=UINT_MAX)=0
Entry point to the flow.
MessageType * alloc()
Synchronously allocates a message buffer from the pool of this flow.
MessageHandler * global_message_write_flow()
Definition If.hxx:200
MessageDispatchFlow * dispatcher()
Definition If.hxx:224
void send(Buffer< GenMessage > *b, unsigned) override
This class helps establishing a list of all (live) nodes on the network.
void refresh()
Requests a pong from every live node.
std::function< void(NodeID n)> CallbackFunction
Function prototype for the callback.
NodeBrowser(Node *node, CallbackFunction cb)
Constructor.
Node * node_
Me-node.
~NodeBrowser()
Destructor.
VerifiedHandler handler_
Callback registerd in the interface.
void unregister_callbacks()
Remove callbacks from the interface.
void register_callbacks()
Register with the interface for messages we want to listen to.
Base class for NMRAnet nodes conforming to the asynchronous interface.
Definition Node.hxx:52
string EMPTY_PAYLOAD
A global class / variable for empty or not-yet-initialized payloads.
Definition If.cxx:152
uint64_t NodeID
48-bit NMRAnet Node ID type
NodeID buffer_to_node_id(const string &buf)
Converts a 6-byte-long buffer to a node ID.
Definition If.cxx:66
@ MTI_VERIFY_NODE_ID_GLOBAL
verify a Node ID globally
@ MTI_EXACT
match mask for a single MTI
@ MTI_VERIFIED_NODE_ID_NUMBER
respond to a verify Node ID request
@ MTI_INITIALIZATION_COMPLETE
initialization complete