Request represents a single user request/response over a bus. More...
#include <Request.h>
Public Types | |
using | OwnedList = OwnedLinkedObjectListTemplate< Request > |
using | Callback = Delegate< void(const Request &request)> |
Per-request callback A request goes through the following states: More... | |
![]() | |
using | Iterator = IteratorTemplate< Request, Request *, Request & > |
using | ConstIterator = IteratorTemplate< const Request, const Request *, const Request & > |
Public Member Functions | |
Request (Device &device) | |
Request (const Request &)=delete | |
virtual | ~Request () |
ErrorCode | error () const |
Request error code defaults to 'pending' and is set on completion. More... | |
bool | isPending () const |
String | caption () const |
Get a descriptive caption for this request. More... | |
virtual ErrorCode | parseJson (JsonObjectConst json) |
Fill this request from a JSON description. More... | |
virtual void | submit () |
Submit a request. More... | |
void | complete (ErrorCode err) |
virtual void | getJson (JsonObject json) const |
Get result of a completed request in JSON format. More... | |
void | setID (const String &value) |
Request identifiers are optional, useful for tracking remote requests. More... | |
void | setCommand (Command cmd) |
Set the command code. More... | |
void | onComplete (Callback callback) |
Set the request completion callback. More... | |
bool | nodeQuery (DevNode node) |
bool | nodeOff (DevNode node) |
bool | nodeOn (DevNode node) |
bool | nodeToggle (DevNode node) |
virtual bool | setNode (DevNode node) |
If nodes are supported, implement this method. More... | |
virtual bool | setValue (int value) |
If nodes support values, implement this method. More... | |
virtual DevNode::States | getNodeStates (DevNode node) |
Query node status from response. More... | |
virtual bool | setNodeState (DevNode node, DevNode::State state) |
const CString & | id () const |
Get the request ID, if there is one. More... | |
Command | getCommand () const |
virtual void | handleEvent (Event event) |
Implementations may override this method as required. More... | |
bool | nodeSet (DevNode node, int value) |
For nodes supporting analogue state (e.g. brightness) More... | |
bool | nodeAdjust (DevNode node, int value) |
![]() | |
Request * | getNext () const |
bool | insertAfter (Request *object) |
Iterator | begin () const |
Iterator | end () const |
Iterator | cbegin () const |
Iterator | cend () const |
![]() | |
virtual | ~LinkedObject () |
virtual LinkedObject * | next () const |
bool | insertAfter (LinkedObject *object) |
bool | operator== (const LinkedObject &other) const |
bool | operator!= (const LinkedObject &other) const |
Public Attributes | |
Device & | device |
Detailed Description
Request represents a single user request/response over a bus.
Inherited classes provide additional methods to encapsulate specific commands or functions. Create the appropriate object using new() or the device manager, then configure the request. Finally, call submit(). If submit() is not called then the request object must be deleted. When the request has completed the callback is invoked, after which the request object is destroyed.
Each call to submit() always has a corresponding call to complete(), even if the request is never attempted. This ensures error is reported to the callback and the object released.
In brief, ownership of a request belongs with the user up until submit() is called, which passes ownership to the IO mechanism.
Member Typedef Documentation
◆ Callback
using IO::Request::Callback = Delegate<void(const Request& request)> |
Per-request callback A request goes through the following states:
- submitted request.submit()
- queued Controller places request on internal queue
- executed Controller retrieves request from queue
- completed Request fully handled, status indicates success/failure
A Controller invokes this callback twice, when a request is about to be executed and again when it has completed. Call request.isPending()
to determine which.
◆ OwnedList
Constructor & Destructor Documentation
◆ Request() [1/2]
|
inline |
◆ Request() [2/2]
|
delete |
◆ ~Request()
|
inlinevirtual |
Member Function Documentation
◆ caption()
String IO::Request::caption | ( | ) | const |
Get a descriptive caption for this request.
◆ complete()
void IO::Request::complete | ( | ErrorCode | err | ) |
◆ error()
|
inline |
Request error code defaults to 'pending' and is set on completion.
◆ getCommand()
|
inline |
◆ getJson()
|
virtual |
Get result of a completed request in JSON format.
Reimplemented in IO::Modbus::STS::Fan::Request, IO::RFSwitch::Request, IO::Custom::Request, IO::DMX512::Request, IO::Modbus::R421A::Request, IO::Modbus::RID35::Request, IO::Modbus::STM8Relay::Request, IO::Modbus::NT18B07::Request, and IO::Modbus::GenericRequest.
◆ getNodeStates()
|
inlinevirtual |
Query node status from response.
Reimplemented in IO::Modbus::R421A::Request, and IO::Modbus::STM8Relay::Request.
◆ handleEvent()
|
virtual |
Implementations may override this method as required.
◆ id()
|
inline |
Get the request ID, if there is one.
◆ isPending()
|
inline |
◆ nodeAdjust()
◆ nodeOff()
◆ nodeOn()
◆ nodeQuery()
◆ nodeSet()
For nodes supporting analogue state (e.g. brightness)
◆ nodeToggle()
◆ onComplete()
|
inline |
Set the request completion callback.
◆ parseJson()
|
virtual |
Fill this request from a JSON description.
Reimplemented in IO::RFSwitch::Request, IO::Custom::Request, IO::DMX512::Request, IO::Modbus::R421A::Request, IO::Modbus::STM8Relay::Request, and IO::Modbus::GenericRequest.
◆ setCommand()
|
inline |
Set the command code.
◆ setID()
|
inline |
Request identifiers are optional, useful for tracking remote requests.
◆ setNode()
If nodes are supported, implement this method.
/
/**
Reimplemented in IO::Custom::Request, IO::RFSwitch::Request, IO::DMX512::Request, IO::Modbus::R421A::Request, IO::Modbus::Request, IO::Modbus::STM8Relay::Request, and IO::Modbus::STS::Fan::Request.
◆ setNodeState()
|
inlinevirtual |
Reimplemented in IO::Modbus::R421A::Request, and IO::Modbus::STM8Relay::Request.
◆ setValue()
If nodes support values, implement this method.
Reimplemented in IO::DMX512::Request, IO::Modbus::STS::Fan::Request, and IO::Custom::Request.
◆ submit()
|
virtual |
Submit a request.
The request is added to the controller's queue. If the queue is empty, it starts execution immediately. The result of the request is posted to the callback routine.
Reimplemented in IO::Custom::Request, and IO::DMX512::Request.
Member Data Documentation
◆ device
Device& IO::Request::device |
The documentation for this class was generated from the following file: