do not allocate memory if old IoT protocol is not used

This commit is contained in:
Terrence
2025-05-23 04:26:47 +08:00
parent 5da66773d5
commit 55a1032779
2 changed files with 9 additions and 1 deletions

View File

@@ -8,22 +8,30 @@
namespace iot {
#if CONFIG_IOT_PROTOCOL_XIAOZHI
static std::map<std::string, std::function<Thing*()>>* thing_creators = nullptr;
#endif
void RegisterThing(const std::string& type, std::function<Thing*()> creator) {
#if CONFIG_IOT_PROTOCOL_XIAOZHI
if (thing_creators == nullptr) {
thing_creators = new std::map<std::string, std::function<Thing*()>>();
}
(*thing_creators)[type] = creator;
#endif
}
Thing* CreateThing(const std::string& type) {
#if CONFIG_IOT_PROTOCOL_XIAOZHI
auto creator = thing_creators->find(type);
if (creator == thing_creators->end()) {
ESP_LOGE(TAG, "Thing type not found: %s", type.c_str());
return nullptr;
}
return creator->second();
#else
return nullptr;
#endif
}
std::string Thing::GetDescriptorJson() {