35#ifndef _OPENLCB_SIMPLEINFOPROTOCOL_HXX_
36#define _OPENLCB_SIMPLEINFOPROTOCOL_HXX_
48struct SimpleInfoDescriptor;
97 FILE_LITERAL_BYTE = 5,
145 bool use_continue_bits =
true)
148 max_bytes_per_message > 255 ? 255 : max_bytes_per_message)
182 return (current_descriptor().cmd == SimpleInfoDescriptor::END_OF_DATA);
190 const char* new_file_name =
reinterpret_cast<const char*
>(d.
data);
201 int ret = lseek(
fd_, d.arg2, SEEK_SET);
210 case SimpleInfoDescriptor::C_STRING:
221#if OPENMRN_HAVE_POSIX_FD
222 case SimpleInfoDescriptor::FILE_CHAR_ARRAY:
226 case SimpleInfoDescriptor::CHAR_ARRAY:
231#if OPENMRN_HAVE_POSIX_FD
232 case SimpleInfoDescriptor::FILE_LITERAL_BYTE:
237 case SimpleInfoDescriptor::FILE_C_STRING:
255 int result = ::read(
fd_, &ret, 1);
257 if (result == 0) ret = 0;
267 case SimpleInfoDescriptor::END_OF_DATA:
269 case SimpleInfoDescriptor::LITERAL_BYTE: {
275 case SimpleInfoDescriptor::C_STRING:
284 case SimpleInfoDescriptor::CHAR_ARRAY:
293 case SimpleInfoDescriptor::FILE_C_STRING:
305 case SimpleInfoDescriptor::FILE_LITERAL_BYTE:
311 case SimpleInfoDescriptor::FILE_CHAR_ARRAY:
316 DIE(
"Unexpected descriptor type.");
326 case SimpleInfoDescriptor::END_OF_DATA:
328 case SimpleInfoDescriptor::LITERAL_BYTE:
329 case SimpleInfoDescriptor::FILE_LITERAL_BYTE:
331 case SimpleInfoDescriptor::C_STRING:
332 case SimpleInfoDescriptor::FILE_C_STRING:
333 case SimpleInfoDescriptor::CHAR_ARRAY:
334 case SimpleInfoDescriptor::FILE_CHAR_ARRAY:
344 DIE(
"Unexpected descriptor type.");
350 Action continue_send()
357 message()->data()->src->iface()->addressed_message_write_flow(),
366 ->addressed_message_write_flow());
367 const SimpleInfoResponse &r = *
message()->data();
368 b->data()->reset(r.mti, r.src->node_id(), r.dst,
EMPTY_PAYLOAD);
379 b->data()->set_flag_dst(
389 b->data()->set_flag_dst(
393 b->set_done(n_.
reset(
this));
394 message()->data()->src->iface()->addressed_message_write_flow()->send(
#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.
BarrierNotifiable * reset(Notifiable *done)
Resets the barrier. Returns &*this. Asserts that is_done().
Collection of related state machines that pend on incoming messages.
Return type for a state flow callback.
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 wait_and_call(Callback c)
Wait for resource to become available before proceeding to next state.
Action release_and_exit()
Terminates the processing of the current message.
State flow with a given typed input queue.
Base::Action Action
Allows using Action without having StateFlowBase:: prefix in front of it.
Action call_immediately(Callback c)
Imediately call the next state upon return.
Base class for NMRAnet nodes conforming to the asynchronous interface.
StateFlow for sending out medium-sized data payloads like the Simple Node Ident Info protocol.
const char * fileName_
Last file name we opened.
Action entry() OVERRIDE
Entry into the StateFlow activity.
uint8_t file_read_current_byte()
Returns the next byte from the file data, advancing the file offset.
uint8_t byteOffset_
Byte offset within a descriptor entry.
uint8_t isFirstMessage_
Whether this is the first reply message we are sending out.
uint8_t entryOffset_
Tells which descriptor entry we are processing.
uint8_t maxBytesPerMessage_
Configuration option.
void update_for_next_entry()
Call this function after updating entryOffset_.
void open_and_seek_next_file()
Assumes that the current descriptor is a file argument.
uint8_t useContinueBits_
Configuration option.
int fd_
fd of the last file we opened.
SimpleInfoFlow(Service *s, unsigned max_bytes_per_message=255, bool use_continue_bits=true)
Creates a simple ident flow handler.
uint8_t current_byte()
Returns the current byte in the stream of data.
void step_byte()
Increments to the next byte in the stream of data.
uint8_t currentLength_
Total / max length of the current block.
#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...
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
#define DIE(MSG)
Unconditionally terminates the current process with a message.
string EMPTY_PAYLOAD
A global class / variable for empty or not-yet-initialized payloads.
StateFlow< Buffer< SimpleInfoResponse >, QList< 1 > > SimpleInfoFlowBase
Base class for the SimpleInfoFlow.
MTI
Known Message type indicators.
This class is used in the dispatching of incoming or outgoing NMRAnet messages to the message handler...
@ DSTFLAG_NOT_FIRST_MESSAGE
Signals to the stack that we need to set the continuation bits in the outgoing message to indicate th...
@ WAIT_FOR_LOCAL_LOOPBACK
Specifies that the stack should wait for the local loopback processing before invoking the done notif...
@ DSTFLAG_NOT_LAST_MESSAGE
Signals to the stack that we need to set the continuation bits in the outgoing message to indicate th...
Node * dstNode
If the destination node is local, this value is non-NULL.
NodeHandle src
Source node.
Container of both a NodeID and NodeAlias.
This structure defines how to piece together a reply to a Simple Info request, sich as SNIP.
const char * data
Points to a string if the command requires so.
Use a Buffer<SimpleInfoResponse> to send a SNIP response to a particular destination host.
Defs::MTI mti
MTI of the response to be sent.
Node * src
Source node to send the response from.
NodeHandle dst
Destination node to send the response to.
void reset(const GenMessage *msg_to_respond, const SimpleInfoDescriptor *desc, Defs::MTI response_mti)
Initializes the fields of this message to be a response to an NMRAnetMessage (i.e....
const SimpleInfoDescriptor * descriptor
Descriptor of payload to send.