SpaIot Library
Loading...
Searching...
No Matches
spaclient.h
1/*
2 SpaIot Library (c) by epsilonrt - epsilonrt@epsilonrt.fr
3 This file is part of SpaIot library <https://github.com/epsilonrt/spaiot-lib>
4
5 SpaIot library is licensed under a
6 Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
7
8 You should have received a copy of the license along with this
9 work. If not, see <http://creativecommons.org/licenses/by-nc-sa/4.0/>.
10
11 SpaIot library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY;
13*/
14#pragma once
15
16#include <set>
17#include <initializer_list>
18#include "event.h"
19
20namespace SpaIot {
21
48 class SpaClient {
49 public:
50
57
61 virtual ~SpaClient();
62
68 SpaClient (std::initializer_list<Event::Type> subscribedEvents);
69
75 SpaClient (const std::set<Event::Type> &subscribedEvents);
76
80 SpaClient (const SpaClient &other);
81
87
92
98
103 virtual void clear();
104
108 bool isNull() const;
109
113 virtual bool isEmpty() const;
114
123 virtual bool operator== (const SpaClient &other) const;
124
133 virtual bool operator!= (const SpaClient &other) const;
134
140 void subscribe (std::initializer_list<Event::Type> subscribedEvents);
141
147 void subscribe (std::set<Event::Type> subscribedEvents);
148
154 void subscribe (Event::Type event);
155
161 const std::set<Event::Type> &subscribedEvents() const;
162
169 bool isSubscribed (const Event::Type &event) const;
170
176 bool write (const Event &event);
177
184
192
196 int available() const;
197
207 bool begin();
208
214 virtual bool isOpen() const;
215
223 virtual void end();
224
235 virtual bool handle();
236
242 virtual const String &className() const;
243
244 protected:
254 SpaClient (const char *className);
255
261 void pushToSpa (const Event &event);
262
269 bool pullFromSpa (Event &event);
270
279 virtual bool pollSpaEvents ();
280
289 uint16_t spaValue (Event::Type type) const;
292 protected:
293 class Private;
294 SpaClient (Private &dd);
295 std::unique_ptr<Private> d_ptr;
296 private:
297 PIMPL_DECLARE_PRIVATE (SpaClient)
298 };
299}
Spa Events.
Definition event.h:25
Type
Type of event.
Definition event.h:31
SpaClient class.
Definition spaclient.h:48
bool pullFromSpa(Event &event)
This client pull an event from the spa.
virtual void end()
Stop the client.
Event read(Event::Type type)
Reads the next event of the specified type from the client.
SpaClient(std::initializer_list< Event::Type > subscribedEvents)
Construct a new SpaClient object with the specified subscribed events.
virtual bool isEmpty() const
Checks if all attributes are set to their default values (same as the default constructor)
virtual bool pollSpaEvents()
This client poll events from the spa.
const std::set< Event::Type > & subscribedEvents() const
Get the subscribed events.
virtual bool operator!=(const SpaClient &other) const
bool write(const Event &event)
Write an event to the client.
bool begin()
Start the client.
SpaClient()
Construct a new default SpaClient object.
void subscribe(std::initializer_list< Event::Type > subscribedEvents)
Add subscribed events.
virtual bool handle()
Process the client.
int available() const
Returns the number of events to be read.
bool isSubscribed(const Event::Type &event) const
Check if the client is subscribed to the event.
SpaClient(const std::set< Event::Type > &subscribedEvents)
Construct a new SpaClient object with the specified subscribed events.
void subscribe(Event::Type event)
Add subscribed event.
virtual ~SpaClient()
Destructor.
void subscribe(std::set< Event::Type > subscribedEvents)
Add subscribed events.
virtual void clear()
Clears the SpaClient object After the call to this function, the SpaClient object is the same as one ...
SpaClient(const SpaClient &other)
Copy Constructor.
bool isNull() const
Returns true if the object is null (i.e. it has not been initialized, d_ptr is null)
SpaClient(const char *className)
Construct a new SpaClient object with the specified class name.
SpaClient & operator=(const SpaClient &other)
Sets the SpaClient object to be equal to other.
SpaClient(SpaClient &&other)
Move Constructor after the move, other is null, other.clear() must be called if it is to be used agai...
virtual bool operator==(const SpaClient &other) const
void pushToSpa(const Event &event)
This client push an event to the spa.
uint16_t spaValue(Event::Type type) const
Get a spa value from the internal variables of the client object.
virtual bool isOpen() const
Check if the client is open.
virtual const String & className() const
Returns the class name This allows to know the class name of the object at runtime when only a pointe...
Event read()
Reads the next event from the client.
SpaIot name space.
Definition bussettings.h:15