Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
CallableFlow.hxx
Go to the documentation of this file.
1
36#ifndef _EXECUTOR_CALLABLEFLOW_HXX_
37#define _EXECUTOR_CALLABLEFLOW_HXX_
38
40
55
56
57template<class RequestType> class CallableFlow : public StateFlow<Buffer<RequestType>, QList<1> > {
58public:
61 CallableFlow(Service* s) : StateFlow<Buffer<RequestType>, QList<1> >(s) {}
62
63protected:
64 using Action = StateFlowBase::Action;
65
69 RequestType *request()
70 {
71 if (!this->message())
72 {
73 // This is not an assert macro, because this function gets inlined
74 // into a lot of places, and we want the shortest possible code
75 // size. However, letting this pass into a hard fault due to the
76 // nullptr dereference is extremely hard to debug.
77 abort();
78 }
79 return this->message()->data();
80 }
81
85 {
86 return this->message() != nullptr;
87 }
88
92 {
93 return return_with_error(0);
94 }
95
98 {
99 return this->wait_and_call(STATE(wait_done));
100 }
101
105 {
106 return return_ok();
107 }
108
112 {
113 request()->resultCode = error;
114 this->return_buffer();
115 return this->exit();
116 }
117};
118
120template<class T, typename... Args>
123 BufferPtr<T> b(flow->alloc());
124 b->data()->reset(std::forward<Args>(args)...);
125 b->data()->done.reset(&n);
126 flow->send(b->ref());
128 return b;
129}
130
131#endif // _EXECUTOR_CALLABLEFLOW_HXX_
AutoReleaseBuffer< T > BufferPtr
Smart pointer for buffers.
Definition Buffer.hxx:259
BufferPtr< T > invoke_flow(FlowInterface< Buffer< T > > *flow, Args &&... args)
Helper function for testing flow invocations.
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
Definition StateFlow.hxx:61
A BarrierNotifiable allows to create a number of child Notifiable and wait for all of them to finish.
Base class for all QMember types that hold data in an expandable format.
Definition Buffer.hxx:195
Action wait_done()
Terminates the flow and returns the request buffer to the caller with an error code of OK (zero).
CallableFlow(Service *s)
Creates a callable flow.
Action return_ok()
Terminates the flow and returns the request buffer to the caller with an error code of OK (zero).
Action wait_and_return_ok()
Waits to be notified before moving onto the next state for termination.
Action return_with_error(int error)
Terminates the flow and returns the request buffer to the caller with an specific error code.
RequestType * request()
Abstract class for message recipients.
A list of queues.
Definition Queue.hxx:466
Collection of related state machines that pend on incoming messages.
Return type for a state flow callback.
State flow with a given typed input queue.
A Notifiable for synchronously waiting for a notification.
void wait_for_notification()
Blocks the current thread until the notification is delivered.
MessageType * message()
void return_buffer()
For state flows that are operated using invoke_subflow_and_wait this is a way to hand back the buffer...
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.
BarrierNotifiable done
Used internally by the invoke_subflow mechanism of StateFlow to notify the calling flow upon completi...