|
| | SpaClient () |
| | Construct a new default SpaClient object.
|
| |
|
virtual | ~SpaClient () |
| | Destructor.
|
| |
| | SpaClient (std::initializer_list< Event::Type > subscribedEvents) |
| | Construct a new SpaClient object with the specified subscribed events.
|
| |
| | SpaClient (const std::set< Event::Type > &subscribedEvents) |
| | Construct a new SpaClient object with the specified subscribed events.
|
| |
|
| SpaClient (const SpaClient &other) |
| | Copy Constructor.
|
| |
|
| SpaClient (SpaClient &&other) |
| | Move Constructor after the move, other is null, other.clear() must be called if it is to be used again.
|
| |
|
SpaClient & | operator= (const SpaClient &other) |
| | Sets the SpaClient object to be equal to other.
|
| |
|
SpaClient & | operator= (SpaClient &&other) |
| | Move assignment after the move, other is null, other.clear() must be called if it is to be used again.
|
| |
|
virtual void | clear () |
| | Clears the SpaClient object After the call to this function, the SpaClient object is the same as one that has been default constructed.
|
| |
|
bool | isNull () const |
| | Returns true if the object is null (i.e. it has not been initialized, d_ptr is null)
|
| |
|
virtual bool | isEmpty () const |
| | Checks if all attributes are set to their default values (same as the default constructor)
|
| |
| virtual bool | operator== (const SpaClient &other) const |
| |
| virtual bool | operator!= (const SpaClient &other) const |
| |
| void | subscribe (std::initializer_list< Event::Type > subscribedEvents) |
| | Add subscribed events.
|
| |
| void | subscribe (std::set< Event::Type > subscribedEvents) |
| | Add subscribed events.
|
| |
| void | subscribe (Event::Type event) |
| | Add subscribed event.
|
| |
| const std::set< Event::Type > & | subscribedEvents () const |
| | Get the subscribed events.
|
| |
| bool | isSubscribed (const Event::Type &event) const |
| | Check if the client is subscribed to the event.
|
| |
| bool | write (const Event &event) |
| | Write an event to the client.
|
| |
| Event | read () |
| | Reads the next event from the client.
|
| |
| Event | read (Event::Type type) |
| | Reads the next event of the specified type from the client.
|
| |
|
int | available () const |
| | Returns the number of events to be read.
|
| |
| bool | begin () |
| | Start the client.
|
| |
| virtual bool | isOpen () const |
| | Check if the client is open.
|
| |
| virtual void | end () |
| | Stop the client.
|
| |
| virtual bool | handle () |
| | Process the client.
|
| |
|
virtual const String & | className () const |
| | Returns the class name This allows to know the class name of the object at runtime when only a pointer to the base class is available It should be note that typeid().name() is not available on ESP32/ESP8266 because RTTI is not enabled.
|
| |
SpaClient class.
This class is used to interface the spa with the external world (MQTT, HTTP, Alexa, ...). It's a base class that must be derived to implement the protocol with an external library (PubSubClient, SinricPro...).
- When an event occurs at the spa level, it is sent to all connected clients using
write(), this event is stored in a FIFO queue,
- the client retrieves the event using
pullFromSpa() and transmits it outside the spa (MQTT, HTTP, Alexa, ...).
- When the user sends a command from outside the spa (MQTT, HTTP, Alexa, ...), the client transmits the command to the spa using
pushToSpa(), this event is stored in a FIFO queue,
- the spa retrieves the event using
read() and executes it.
Here is a schematic representation of the communication between the spa and the clients:
+-----------+ FiFo +-----------+
| | write() --> OOOOOOOO --> pullFromSpa() | |
| SpaServer | | Protected | <---> External world (MQTT, HTTP, Alexa, ...)
| (SPA) | read() <-- OOOOOOOO <---- pushToSpa() | API | implements the protocol with an external library
+-----------+ FiFo +-----------+
[ ---------------- SpaClient ---------------- ] [ --- External library (PubSubClient, SinricPro...) ---]
The communication between server and clients is asynchronous, clients can be connected or disconnected at any time. When the spa receives a command from a client, it executes it, then if the command has modified the state of the spa, it sends an event to all connected clients.
- Warning
- Thus a client must not block its process to wait for an event from the spa or the system will be blocked.