Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Homie framework fails with exception when compiled with sloeber #696

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Homie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ using namespace HomieInternals;
HomieClass::HomieClass()
: _setupCalled(false)
, _firmwareSet(false)
, _boot(nullptr)
, _flaggedForReboot(false)
, __HOMIE_SIGNATURE("\x25\x48\x4f\x4d\x49\x45\x5f\x45\x53\x50\x38\x32\x36\x36\x5f\x46\x57\x25") {
strlcpy(Interface::get().brand, DEFAULT_BRAND, MAX_BRAND_LENGTH);
Interface::get().bootMode = HomieBootMode::UNDEFINED;
Expand Down Expand Up @@ -400,5 +402,8 @@ void HomieClass::doDeepSleep(uint64_t time_us, RFMode mode) {
}
#endif // ESP32

//HomieClass Homie;
HomieClass& getHomie() {
return *(HomieClass::getInstance().get());
}

HomieClass Homie;
22 changes: 17 additions & 5 deletions src/Homie.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,21 @@
#define Homie_setBrand(brand) const char* __FLAGGED_BRAND = "\xfb\x2a\xf5\x68\xc0" brand "\x6e\x2f\x0f\xeb\x2d"; Homie.__setBrand(__FLAGGED_BRAND);

namespace HomieInternals {
class HomieClass {
friend class ::HomieNode;
friend SendingPromise;
class HomieClass;
using HomieClassPtr = std::shared_ptr<HomieClass>;

class HomieClass: public std::enable_shared_from_this<HomieClass> {
friend class ::HomieNode;
friend SendingPromise;

public:
HomieClass();
static HomieClassPtr getInstance() {
static HomieClassPtr m_inst = HomieClassPtr(new HomieClass());
return m_inst;
}
HomieClass(const HomieClass&) = delete;
HomieClass& operator=(const HomieClass&) = delete;

~HomieClass();
void setup();
void loop();
Expand Down Expand Up @@ -74,6 +83,7 @@ class HomieClass {
#endif // ESP32

private:
HomieClass();
bool _setupCalled;
bool _firmwareSet;
Boot* _boot;
Expand All @@ -95,4 +105,6 @@ class HomieClass {
};
} // namespace HomieInternals

extern HomieInternals::HomieClass Homie;
//extern HomieInternals::HomieClass Homie;
#define Homie (getHomie())
extern HomieInternals::HomieClass& getHomie();
2 changes: 1 addition & 1 deletion src/Homie/Boot/BootNormal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace HomieInternals {
class BootNormal : public Boot {
public:
BootNormal();
~BootNormal();
virtual ~BootNormal();
void setup();
void loop();

Expand Down
10 changes: 6 additions & 4 deletions src/Homie/Datatypes/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

using namespace HomieInternals;

InterfaceData Interface::_interface; // need to define the static variable

InterfaceData::InterfaceData()
: brand{ '\0' }
, bootMode{ HomieBootMode::UNDEFINED }
Expand All @@ -22,6 +20,10 @@ InterfaceData::InterfaceData()
, _sendingPromise{ nullptr } {
}

InterfaceData& Interface::get() {
return _interface;
namespace HomieInternals {
namespace Interface {
InterfaceData& get() {
return *( InterfaceData::getInstance().get());
}
}
}
24 changes: 14 additions & 10 deletions src/Homie/Datatypes/Interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,19 @@ class Config;
class SendingPromise;
class HomieClass;

class InterfaceData {
class InterfaceData;
using InterfaceDataPtr = std::shared_ptr<InterfaceData>;

class InterfaceData : public std::enable_shared_from_this<InterfaceData> {
friend HomieClass;

public:
InterfaceData();
static InterfaceDataPtr getInstance() {
static InterfaceDataPtr m_inst = InterfaceDataPtr(new InterfaceData());
return m_inst;
}
InterfaceData(const InterfaceData&) = delete;
InterfaceData& operator=(const InterfaceData&) = delete;

/***** User configurable data *****/
char brand[MAX_BRAND_LENGTH];
Expand Down Expand Up @@ -74,18 +82,14 @@ class InterfaceData {
SendingPromise& getSendingPromise() { return *_sendingPromise; }

private:
InterfaceData();
Logger* _logger;
Blinker* _blinker;
Config* _config;
AsyncMqttClient* _mqttClient;
SendingPromise* _sendingPromise;
};

class Interface {
public:
static InterfaceData& get();

private:
static InterfaceData _interface;
};
namespace Interface {
extern InterfaceData& get();
}
} // namespace HomieInternals