36#ifndef _OPENLCB_SNIPCLIENT_HXX_
37#define _OPENLCB_SNIPCLIENT_HXX_
63 OPERATION_PENDING = 0x20000,
64 ERROR_REJECTED = 0x200000,
65 OPENMRN_TIMEOUT = 0x80000,
76#if !defined(GTEST) || !defined(SNIP_CLIENT_TIMEOUT_NSEC)
105 request()->resultCode = SNIPClientRequest::OPERATION_PENDING;
115 MASK_1 = ~(MTI_1a ^ MTI_1b),
156 uint16_t mti, error_code;
158 message->data()->payload, &error_code, &mti,
nullptr);
159 LOG(
INFO,
"rejection err %04x mti %04x", error_code, mti);
166 error_code | SNIPClientRequest::ERROR_REJECTED;
176 LOG(
INFO,
"Unexpected MTI for SNIP response handler: %04x",
185 Action response_came()
188 if (
request()->resultCode & SNIPClientRequest::OPERATION_PENDING)
198 return request()->src_->iface();
BufferPtr< T > get_buffer_deleter(Buffer< T > *b)
Helper function to create a BufferPtr of an appropriate type without having to explicitly specify the...
#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.
Action return_with_error(int error)
Terminates the flow and returns the request buffer to the caller with an specific error code.
SNIPClientRequest * request()
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.
void sync_run(std::function< void()> fn)
Synchronously runs a closure on this executor.
virtual void send(MessageType *message, unsigned priority=UINT_MAX)=0
Entry point to the flow.
Collection of related state machines that pend on incoming messages.
ExecutorBase * executor()
Return type for a state flow callback.
Use this timer class to deliver the timeout notification to a stateflow.
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.
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.
void ensure_triggered()
Triggers the timer if it is not expired yet.
Abstract class representing an OpenLCB Interface.
MessageDispatchFlow * dispatcher()
MessageHandler * addressed_message_write_flow()
Base class for NMRAnet nodes conforming to the asynchronous interface.
Action write_request()
Called once the allocation is complete.
StateFlowTimer timer_
Handles the timeout feature.
void handle_response(Buffer< GenMessage > *message)
Callback from the response handler.
Action entry() override
Entry into the StateFlow activity.
void shutdown()
Flushes the pending timed operations.
SNIPClient(Service *s)
Constructor.
IncomingMessageStateFlow::GenericHandler responseHandler_
Registered handler for response messages.
#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.
string EMPTY_PAYLOAD
A global class / variable for empty or not-yet-initialized payloads.
string Payload
Container that carries the data bytes in an NMRAnet message.
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.
static constexpr long long SNIP_CLIENT_TIMEOUT_NSEC
Specifies how long to wait for a SNIP request to get a response.
#define MSEC_TO_NSEC(_msec)
Convert a millisecond value to a nanosecond value.
static void microsleep(uint32_t microseconds)
Sleep a given number of microseconds.
All callable flow request objects have to derive from this struct.
void reset_base()
Call this from all instances of reset(...).
int resultCode
If high bits are zero, this is a 16-bit OpenLCB result code.
@ MTI_IDENT_INFO_REPLY
node identity reply
@ MTI_IDENT_INFO_REQUEST
request node identity
@ MTI_EXACT
match mask for a single MTI
@ MTI_OPTIONAL_INTERACTION_REJECTED
rejected request
@ MTI_TERMINATE_DUE_TO_ERROR
terminate due to some error
Container of both a NodeID and NodeAlias.
Buffer contents for invoking the SNIP client.
NodeHandle dst_
Destination node to query.
Payload response
Response payload if successful.
void reset(Node *src, NodeHandle dst)
Helper function for invoke_subflow.
Node * src_
Source node where to send the request from.