36#ifndef _OPENLCB_PIPCLIENT_HXX_
37#define _OPENLCB_PIPCLIENT_HXX_
83 errorCode_ = OPERATION_PENDING;
105 OPERATION_SUCCESS = 0x10000,
106 OPERATION_PENDING = 0x20000,
118 MASK_1 = ~(MTI_1a ^ MTI_1b),
125 Action request_buffer()
128 iface()->addressed_message_write_flow(),
STATE(write_request));
131 Action write_request()
139 &responseHandler_, MTI_1, MASK_1);
141 &responseHandler_, MTI_2, MASK_2);
153 if (src_ != message->
data()->dstNode ||
154 !iface()->matching_node(dst_, message->
data()->src))
175 errorCode_ = OPERATION_SUCCESS;
180 LOG(
INFO,
"Unexpected MTI for PIP response handler: %04x",
181 message->
data()->mti);
186 errorCode_ &= ~OPERATION_PENDING;
190 Action response_came()
192 if (errorCode_ & OPERATION_PENDING)
194 errorCode_ = TIMEOUT;
214 parent_->handle_response(message);
226 StateFlowTimer timer_{
this};
230 uint64_t pipResponse_{0};
231 uint32_t errorCode_{IDLE};
232 PIPResponseHandler responseHandler_{
this};
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.
Base class for all QMember types that hold data in an expandable format.
T * data()
get a pointer to the start of the data.
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.
An object that can schedule itself on an executor to run.
virtual void notify()=0
Generic callback.
Base class for state machines.
Service * service()
Return a pointer to the service I am bound to.
Action allocate_and_call(FlowInterface< Buffer< T > > *target_flow, Callback c, Pool *pool=nullptr)
Allocates a buffer from a pool and proceed to the next state when allocation is successful.
StateFlowBase()
Default constructor.
Action exit()
Terminate current StateFlow activity.
void start_flow(Callback c)
Resets the flow to the specified state and starts it.
Buffer< T > * get_allocation_result(FlowInterface< Buffer< T > > *target_flow)
Takes the result of the asynchronous allocation.
Action sleep_and_call(::Timer *timer, long long timeout_nsec, Callback c)
Suspends execution of this control flow for a specified time.
void trigger()
This will wakeup the timer prematurely, immediately.
Abstract class representing an OpenLCB Interface.
MessageDispatchFlow * dispatcher()
MessageHandler * addressed_message_write_flow()
Base class for NMRAnet nodes conforming to the asynchronous interface.
Message handler for incoming PIP responses.
State flow to request PIP information from a remote node on the OpenLCB network.
uint64_t response()
Returns the response of the last request out, or unspecified if the last request has not succeeded.
void request(NodeHandle dst, Node *src, Notifiable *done)
Sends a PIP request to the specified node.
#define LOG(level, message...)
Conditionally write a message to the logging output.
static const int INFO
Loglevel that is printed by default, reporting some status information.
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
long long PIP_CLIENT_TIMEOUT_NSEC
Specifies how long to wait for a PIP request to get a response.
string EMPTY_PAYLOAD
A global class / variable for empty or not-yet-initialized payloads.
NodeID buffer_to_node_id(const string &buf)
Converts a 6-byte-long buffer to a node ID.
void buffer_to_error(const Payload &payload, uint16_t *error_code, uint16_t *mti, string *error_message)
Parses the payload of an Optional Interaction Rejected or Terminate Due To Error message.
@ MTI_EXACT
match mask for a single MTI
@ MTI_PROTOCOL_SUPPORT_INQUIRY
inquire on supported protocols
@ MTI_OPTIONAL_INTERACTION_REJECTED
rejected request
@ MTI_PROTOCOL_SUPPORT_REPLY
reply with supported protocols
@ MTI_TERMINATE_DUE_TO_ERROR
terminate due to some error
Container of both a NodeID and NodeAlias.