supla-device
Loading...
Searching...
No Matches
element.h
1/*
2 Copyright (C) AC SOFTWARE SP. Z O.O.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*/
18
19#ifndef SRC_SUPLA_ELEMENT_H_
20#define SRC_SUPLA_ELEMENT_H_
21
22#include <stdint.h>
23#include <supla-common/proto.h>
24
26
27namespace Supla {
28
29class Channel;
30namespace Protocol {
31class SuplaSrpc;
32} // namespace Protocol
33
37class Element {
38 public:
39 Element();
40 virtual ~Element();
46 static Element *begin();
47
53 static Element *last();
54
62 static Element *getElementByChannelNumber(int channelNumber);
63
71 static Element *getOwnerOfSubDeviceId(int subDeviceId);
72
82 static bool IsAnyUpdatePending();
83
90 static void NotifyElementsAboutConfigChange(uint64_t fieldBit);
91
101 static bool IsInvalidPtrSet();
102
106 static void ClearInvalidPtr();
107
113 Element *next();
114
123 virtual void onLoadConfig(SuplaDeviceClass *sdc);
124
128 virtual void purgeConfig();
129
136 virtual void onLoadState();
137
144 virtual void onInit();
145
151 virtual void onSaveState();
152
158 virtual void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc = nullptr);
159
166 virtual void iterateAlways();
167
176 virtual bool iterateConnected();
178 virtual bool iterateConnected(void *ptr);
179
187 virtual void onTimer();
188
196 virtual void onFastTimer();
197
201 virtual void onSoftReset();
202
208 virtual void onDeviceConfigChange(uint64_t fieldBit);
209
219 virtual int32_t handleNewValueFromServer(TSD_SuplaChannelNewValue *newValue);
220
227
228 // Handles "get channel state" request from server
229 // channelState is prefilled with network and device status informations
236 virtual void handleGetChannelState(TDSC_ChannelState *channelState);
237
246
247 // Returns SUPLA_RESULTCODE_
257 virtual uint8_t handleChannelConfig(TSD_ChannelConfig *newChannelConfig,
258 bool local = false);
259
272 virtual uint8_t handleWeeklySchedule(TSD_ChannelConfig *newWeeklySchedule,
273 bool altSchedule = false,
274 bool local = false);
275
276 // handleSetChannelConfigResult should handle both standard channel config
277 // and weekly schedule config
286 virtual void handleSetChannelConfigResult(
288
295 virtual void handleChannelConfigFinished();
296
303 int getChannelNumber() const;
304
311 int getSecondaryChannelNumber() const;
312
320 virtual bool isOwnerOfSubDeviceId(int subDeviceId) const;
321
327 virtual const Channel *getChannel() const;
328 virtual Channel *getChannel();
329
336 virtual const Channel *getSecondaryChannel() const;
337 virtual Channel *getSecondaryChannel();
338
348 virtual void generateKey(char *output, const char *key) const;
349
355 Element &disableChannelState();
356
362 bool isChannelStateEnabled() const;
363
369 virtual bool isAnyUpdatePending();
370
381 void setInitialCaption(const char *caption, bool secondaryChannel = false);
382
388 void setDefaultFunction(int32_t defaultFunction);
389
390 protected:
391 static Element *firstPtr;
392 static bool invalidatePtr;
393 Element *nextPtr = nullptr;
394};
395
396}; // namespace Supla
397
398#endif // SRC_SUPLA_ELEMENT_H_
Definition SuplaDevice.h:96
Definition channel.h:33
virtual uint8_t handleWeeklySchedule(TSD_ChannelConfig *newWeeklySchedule, bool altSchedule=false, bool local=false)
Handles "set channel config" with "weekly schedule" type request from server.
Definition element.cpp:270
static bool IsAnyUpdatePending()
Checks if any element has pending update for remote server.
Definition element.cpp:95
virtual void onDeviceConfigChange(uint64_t fieldBit)
Method called when device config is changed.
Definition element.cpp:301
void setDefaultFunction(int32_t defaultFunction)
Sets default channel's function.
Definition element.cpp:339
virtual void onTimer()
Method called on timer interupt.
Definition element.cpp:167
static Element * getOwnerOfSubDeviceId(int subDeviceId)
Returns Element which owns given subDeviceId.
Definition element.cpp:82
virtual uint8_t handleChannelConfig(TSD_ChannelConfig *newChannelConfig, bool local=false)
Handles "set channel config" request from server.
Definition element.cpp:262
virtual void onLoadState()
Second method called on element in SuplaDevice.begin().
Definition element.cpp:116
virtual bool isOwnerOfSubDeviceId(int subDeviceId) const
Returns true if element is owner of subDeviceId.
Definition element.cpp:346
virtual int handleCalcfgFromServer(TSD_DeviceCalCfgRequest *request)
Handles CALCFG requests from server.
Definition element.cpp:250
void setInitialCaption(const char *caption, bool secondaryChannel=false)
Sets initial caption.
Definition element.cpp:326
static bool IsInvalidPtrSet()
When "invalid pointer" is set, previously obtained Element pointer may be invalid.
Definition element.cpp:314
virtual const Channel * getSecondaryChannel() const
Returns pointer to secondary channel.
Definition element.cpp:202
virtual bool iterateConnected()
Method called on each SuplaDevice iteration when device is connected and registered to Supla server o...
Definition element.cpp:148
static void ClearInvalidPtr()
Clears "invalid pointer" flag.
Definition element.cpp:318
int getChannelNumber() const
Returns channel number.
Definition element.cpp:180
virtual void onSoftReset()
Method called when device soft restart is triggered.
Definition element.cpp:298
int getSecondaryChannelNumber() const
Returns secondary channel number.
Definition element.cpp:189
virtual void generateKey(char *output, const char *key) const
Generates key used for Config.
Definition element.cpp:294
bool isChannelStateEnabled() const
Returns true if channel state (i) function is enabled.
Definition element.cpp:134
static Element * getElementByChannelNumber(int channelNumber)
Returns Element by channel number.
Definition element.cpp:69
virtual int32_t handleNewValueFromServer(TSD_SuplaChannelNewValue *newValue)
Handles "new value" request from server.
Definition element.cpp:171
virtual void onLoadConfig(SuplaDeviceClass *sdc)
First method called on element in SuplaDevice.begin().
Definition element.cpp:112
Element & disableChannelState()
Disables channel state (i) function.
Definition element.cpp:255
static Element * begin()
Returns first Element (based on creation order)
Definition element.cpp:57
virtual void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc=nullptr)
Method called each time when device successfully registers to Supla server.
Definition element.cpp:120
virtual void handleChannelConfigFinished()
Handles "channel config finished" message from server.
Definition element.cpp:288
static Element * last()
Returns last Element (based on creation order)
Definition element.cpp:61
virtual void onFastTimer()
Method called on fast timer interupt.
Definition element.cpp:169
Element * next()
Returns next Element from the list.
Definition element.cpp:106
virtual void onSaveState()
Method called periodically during SuplaDevice iteration.
Definition element.cpp:118
virtual void onInit()
Third method called on element in SuplaDevice.begin()
Definition element.cpp:110
virtual void handleSetChannelConfigResult(TSDS_SetChannelConfigResult *result)
Handles "set channel config" reply from server.
Definition element.cpp:281
virtual const Channel * getChannel() const
Returns pointer to main channel.
Definition element.cpp:198
static void NotifyElementsAboutConfigChange(uint64_t fieldBit)
Notifies all elements about device config change.
Definition element.cpp:305
virtual void handleGetChannelState(TDSC_ChannelState *channelState)
Handles "get channel state (i)" request from server.
Definition element.cpp:214
virtual void fillSuplaChannelNewValue(TSD_SuplaChannelNewValue *value)
Fills TSD_SuplaChannelNewValue based on current state.
Definition element.cpp:176
virtual void purgeConfig()
Removes all configration data related to the element from Storage::Config.
Definition element.cpp:114
virtual void iterateAlways()
Method called on each SuplaDevice iteration.
Definition element.cpp:141
virtual bool isAnyUpdatePending()
Returns true if any update is pending.
Definition element.cpp:322
Definition supla_srpc.h:55
Definition proto.h:2599
Definition proto.h:3041
Definition proto.h:3025
Definition proto.h:2260
Definition proto.h:1177