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
163 virtual bool isStateStorageMigrationNeeded() const;
164
170 virtual void onRegistered(Supla::Protocol::SuplaSrpc *suplaSrpc = nullptr);
171
178 virtual void iterateAlways();
179
188 virtual bool iterateConnected();
190 virtual bool iterateConnected(void *ptr);
191
199 virtual void onTimer();
200
208 virtual void onFastTimer();
209
213 virtual void onSoftReset();
214
220 virtual void onDeviceConfigChange(uint64_t fieldBit);
221
231 virtual int32_t handleNewValueFromServer(TSD_SuplaChannelNewValue *newValue);
232
239
240 // Handles "get channel state" request from server
241 // channelState is prefilled with network and device status informations
248 virtual void handleGetChannelState(TDSC_ChannelState *channelState);
249
258
259 // Returns SUPLA_RESULTCODE_
269 virtual uint8_t handleChannelConfig(TSD_ChannelConfig *newChannelConfig,
270 bool local = false);
271
284 virtual uint8_t handleWeeklySchedule(TSD_ChannelConfig *newWeeklySchedule,
285 bool altSchedule = false,
286 bool local = false);
287
288 // handleSetChannelConfigResult should handle both standard channel config
289 // and weekly schedule config
298 virtual void handleSetChannelConfigResult(
300
307 virtual void handleChannelConfigFinished();
308
315 int getChannelNumber() const;
316
323 int getSecondaryChannelNumber() const;
324
332 virtual bool isOwnerOfSubDeviceId(int subDeviceId) const;
333
339 virtual const Channel *getChannel() const;
340 virtual Channel *getChannel();
341
348 virtual const Channel *getSecondaryChannel() const;
349 virtual Channel *getSecondaryChannel();
350
360 virtual void generateKey(char *output, const char *key) const;
361
367 Element &disableChannelState();
368
374 bool isChannelStateEnabled() const;
375
381 virtual bool isAnyUpdatePending() const;
382
393 void setInitialCaption(const char *caption, bool secondaryChannel = false);
394
403 bool setDefaultFunction(uint32_t defaultFunction);
404
413 bool setFunction(uint32_t newFunction);
414
421 virtual void onFunctionChange(uint32_t currentFunction, uint32_t newFunction);
422
423 protected:
424 static Element *firstPtr;
425 static bool invalidatePtr;
426 Element *nextPtr = nullptr;
427};
428
429}; // namespace Supla
430
431#endif // SRC_SUPLA_ELEMENT_H_
Definition SuplaDevice.h:153
Definition channel.h:33
virtual void onFunctionChange(uint32_t currentFunction, uint32_t newFunction)
Called when channel function changes.
Definition element.cpp:353
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:267
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:298
virtual void onTimer()
Method called on timer interupt.
Definition element.cpp:164
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:259
bool setFunction(uint32_t newFunction)
Sets channel's function.
Definition element.cpp:349
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:358
virtual int handleCalcfgFromServer(TSD_DeviceCalCfgRequest *request)
Handles CALCFG requests from server.
Definition element.cpp:247
void setInitialCaption(const char *caption, bool secondaryChannel=false)
Sets initial caption.
Definition element.cpp:323
static bool IsInvalidPtrSet()
When "invalid pointer" is set, previously obtained Element pointer may be invalid.
Definition element.cpp:311
virtual const Channel * getSecondaryChannel() const
Returns pointer to secondary channel.
Definition element.cpp:199
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:315
int getChannelNumber() const
Returns channel number.
Definition element.cpp:177
virtual void onSoftReset()
Method called when device soft restart is triggered.
Definition element.cpp:295
int getSecondaryChannelNumber() const
Returns secondary channel number.
Definition element.cpp:186
virtual bool isStateStorageMigrationNeeded() const
Method called after onInit() to check if state storage migration is needed.
Definition element.cpp:362
virtual void generateKey(char *output, const char *key) const
Generates key used for Config.
Definition element.cpp:291
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:168
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:252
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 bool isAnyUpdatePending() const
Returns true if any update is pending.
Definition element.cpp:319
virtual void handleChannelConfigFinished()
Handles "channel config finished" message from server.
Definition element.cpp:285
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:166
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:278
virtual const Channel * getChannel() const
Returns pointer to main channel.
Definition element.cpp:195
static void NotifyElementsAboutConfigChange(uint64_t fieldBit)
Notifies all elements about device config change.
Definition element.cpp:302
bool setDefaultFunction(uint32_t defaultFunction)
Sets default channel's function.
Definition element.cpp:336
virtual void handleGetChannelState(TDSC_ChannelState *channelState)
Handles "get channel state (i)" request from server.
Definition element.cpp:211
virtual void fillSuplaChannelNewValue(TSD_SuplaChannelNewValue *value)
Fills TSD_SuplaChannelNewValue based on current state.
Definition element.cpp:173
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
Definition supla_srpc.h:55
Definition proto.h:2647
Definition proto.h:3091
Definition proto.h:3075
Definition proto.h:2287
Definition proto.h:1200