forked from xiaozhi/xiaozhi-esp32
do not allocate memory if old IoT protocol is not used
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user