SpaIot Library
|
Public Member Functions | |
SpaClient () | |
Construct a new default SpaClient object. More... | |
virtual | ~SpaClient () |
Destructor. | |
SpaClient (std::initializer_list< Event::Type > subscribedEvents) | |
Construct a new SpaClient object with the specified subscribed events. More... | |
SpaClient (const std::set< Event::Type > &subscribedEvents) | |
Construct a new SpaClient object with the specified subscribed events. More... | |
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. More... | |
void | subscribe (std::set< Event::Type > subscribedEvents) |
Add subscribed events. More... | |
void | subscribe (Event::Type event) |
Add subscribed event. More... | |
const std::set< Event::Type > & | subscribedEvents () const |
Get the subscribed events. More... | |
bool | isSubscribed (const Event::Type &event) const |
Check if the client is subscribed to the event. More... | |
bool | write (const Event &event) |
Write an event to the client. More... | |
Event | read () |
Reads the next event from the client. More... | |
Event | read (Event::Type type) |
Reads the next event of the specified type from the client. More... | |
int | available () const |
Returns the number of events to be read. | |
bool | begin () |
Start the client. More... | |
virtual bool | isOpen () const |
Check if the client is open. More... | |
virtual void | end () |
Stop the client. More... | |
virtual bool | handle () |
Process the client. More... | |
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. | |
Protected Member Functions | |
SpaClient Protected API | |
Used by client-derived classes to communicate the outside world to the spa | |
SpaClient (const char *className) | |
Construct a new SpaClient object with the specified class name. | |
void | pushToSpa (const Event &event) |
This client push an event to the spa. More... | |
bool | pullFromSpa (Event &event) |
This client pull an event from the spa. More... | |
virtual bool | pollSpaEvents () |
This client poll events from the spa. More... | |
uint16_t | spaValue (Event::Type type) const |
Get a spa value from the internal variables of the client object. More... | |
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...).
write()
, this event is stored in a FIFO queue,pullFromSpa()
and transmits it outside the spa (MQTT, HTTP, Alexa, ...).pushToSpa()
, this event is stored in a FIFO queue,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.
SpaIot::SpaClient::SpaClient | ( | ) |
Construct a new default SpaClient object.
The subscribed events list is empty, all events may be sent to the client or the spa
SpaIot::SpaClient::SpaClient | ( | std::initializer_list< Event::Type > | subscribedEvents | ) |
Construct a new SpaClient object with the specified subscribed events.
subscribedEvents | The events subscribed by the client, only the events in the list will be sent to the client or the spa |
SpaIot::SpaClient::SpaClient | ( | const std::set< Event::Type > & | subscribedEvents | ) |
Construct a new SpaClient object with the specified subscribed events.
subscribedEvents | The events subscribed by the client, only the events in the list will be sent to the client or the spa |
bool SpaIot::SpaClient::begin | ( | ) |
Start the client.
This method must be called in the setup() function before begin(). It will be call by SpaServer::begin()
to start the client services. The default implementation sets isOpen() to true and returns true. It must be reimplemented in derived classes to start the client services, and called by the derived class begin() method.
|
virtual |
|
virtual |
Process the client.
This method must be called periodically in the main loop. It will be call by SpaServer::handle()
to process the client tasks. The default implementation call pollSpaEvents()
and returns true if events have been polled. It should be reimplemented in derived classes to process the client tasks.
|
virtual |
Check if the client is open.
bool SpaIot::SpaClient::isSubscribed | ( | const Event::Type & | event | ) | const |
Check if the client is subscribed to the event.
event | The event |
|
virtual |
The function returns true if the two objects are not equal
other | the other SpaClient object to compare to |
|
virtual |
The function returns true if the two objects are equal
other | the other SpaClient object to compare to |
|
protectedvirtual |
This client poll events from the spa.
Poll events from the spa using pullFromSpa()
and update the internal variables of the client object. These variables are accessible by the spaValue()
method.
|
protected |
This client pull an event from the spa.
event | The event to be filled |
|
protected |
This client push an event to the spa.
event | The event to be pushed |
Event SpaIot::SpaClient::read | ( | ) |
Reads the next event from the client.
Event SpaIot::SpaClient::read | ( | Event::Type | type | ) |
Reads the next event of the specified type from the client.
type | The event type that is expected |
|
protected |
Get a spa value from the internal variables of the client object.
These variables are updated by the pollSpaEvents()
method.
type | The event type |
void SpaIot::SpaClient::subscribe | ( | Event::Type | event | ) |
Add subscribed event.
event | The event subscribed by the client |
void SpaIot::SpaClient::subscribe | ( | std::initializer_list< Event::Type > | subscribedEvents | ) |
Add subscribed events.
subscribedEvents | The events subscribed by the client |
void SpaIot::SpaClient::subscribe | ( | std::set< Event::Type > | subscribedEvents | ) |
Add subscribed events.
subscribedEvents | The events subscribed by the client |
const std::set<Event::Type>& SpaIot::SpaClient::subscribedEvents | ( | ) | const |
Get the subscribed events.
bool SpaIot::SpaClient::write | ( | const Event & | event | ) |
Write an event to the client.
event | The event to be sent |