Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
ProtocolIdentification.hxx
Go to the documentation of this file.
1
35#ifndef _OPENLCB_PROTOCOLIDENTIFICATION_HXX_
36#define _OPENLCB_PROTOCOLIDENTIFICATION_HXX_
37
38#include "openlcb/Defs.hxx"
39//#include "openlcb/
40
41namespace openlcb
42{
43
48{
49public:
54 ProtocolIdentificationHandler(Node* node, uint64_t supported)
55 : IncomingMessageStateFlow(node->iface())
56 , node_(node)
57 , payload_()
58 {
59 /* store the supported protocol as a payload */
60 payload_ = node_id_to_buffer(supported);
61
62 /* register our interest in the Protocol Identification Protocol */
65 }
66
70 {
71 /* register our interest in the Protocol Identification Protocol */
74 }
75
76private:
83 {
84 if (nmsg()->dstNode != node_)
85 {
86 /* not for me */
87 return release_and_exit();
88 }
89 /* hanlde messager */
90 //LOG(INFO, "PIP Handle");
91 return allocate_and_call(
94 }
95
100 {
101 /* grab our allocated buffer */
102 auto *b = get_allocation_result(
104 /* fill in response. */
105 b->data()->reset(Defs::MTI_PROTOCOL_SUPPORT_REPLY, node_->node_id(), nmsg()->src, payload_);
106
107 /* pass the response to the addressed message write flow */
109
110 return release_and_exit();
111 }
112
115
118
120};
121
122} /* namespace openlcb */
123
124#endif // _OPENLCB_PROTOCOLIDENTIFICATION_HXX_
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
Definition StateFlow.hxx:61
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.
virtual void send(MessageType *message, unsigned priority=UINT_MAX)=0
Entry point to the flow.
Base::Action Action
Allows using Action without having StateFlowBase:: prefix in front of it.
MessageDispatchFlow * dispatcher()
Definition If.hxx:224
MessageHandler * addressed_message_write_flow()
Definition If.hxx:210
Base class for incoming message handler flows.
Definition If.hxx:400
GenMessage * nmsg()
Returns the NMRAnet message we received.
Definition If.hxx:413
Base class for NMRAnet nodes conforming to the asynchronous interface.
Definition Node.hxx:52
An instance of this class will add Protocol Identification Protocol to an NMRAnet Node.
Action entry() OVERRIDE
Entry point to state flow.
ProtocolIdentificationHandler(Node *node, uint64_t supported)
Constructor.
Action fill_response_buffer()
Respond to incoming request with an outgoing message.
Node * node_
local copy of the node we are binding to
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
Definition macros.h:180
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
Definition macros.h:171
string node_id_to_buffer(NodeID id)
Convenience function to render a 48-bit NMRAnet node ID into a new buffer.
Definition If.cxx:45
string Payload
Container that carries the data bytes in an NMRAnet message.
@ MTI_EXACT
match mask for a single MTI
@ MTI_PROTOCOL_SUPPORT_INQUIRY
inquire on supported protocols
@ MTI_PROTOCOL_SUPPORT_REPLY
reply with supported protocols