mirror of
https://github.com/esphome/esphome.git
synced 2025-10-23 12:13:49 +01:00
Merge branch 'esp32_mdns_fixed_vector' into integration
This commit is contained in:
@@ -31,19 +31,17 @@ void MDNSComponent::setup() {
|
|||||||
mdns_instance_name_set(this->hostname_.c_str());
|
mdns_instance_name_set(this->hostname_.c_str());
|
||||||
|
|
||||||
for (const auto &service : services) {
|
for (const auto &service : services) {
|
||||||
FixedVector<mdns_txt_item_t> txt_records;
|
auto txt_records = std::make_unique<mdns_txt_item_t[]>(service.txt_records.size());
|
||||||
txt_records.init(service.txt_records.size());
|
for (size_t i = 0; i < service.txt_records.size(); i++) {
|
||||||
for (const auto &record : service.txt_records) {
|
const auto &record = service.txt_records[i];
|
||||||
mdns_txt_item_t it{};
|
|
||||||
// key and value are either compile-time string literals in flash or pointers to dynamic_txt_values_
|
// key and value are either compile-time string literals in flash or pointers to dynamic_txt_values_
|
||||||
// Both remain valid for the lifetime of this function, and ESP-IDF makes internal copies
|
// Both remain valid for the lifetime of this function, and ESP-IDF makes internal copies
|
||||||
it.key = MDNS_STR_ARG(record.key);
|
txt_records[i].key = MDNS_STR_ARG(record.key);
|
||||||
it.value = MDNS_STR_ARG(record.value);
|
txt_records[i].value = MDNS_STR_ARG(record.value);
|
||||||
txt_records.push_back(it);
|
|
||||||
}
|
}
|
||||||
uint16_t port = const_cast<TemplatableValue<uint16_t> &>(service.port).value();
|
uint16_t port = const_cast<TemplatableValue<uint16_t> &>(service.port).value();
|
||||||
err = mdns_service_add(nullptr, MDNS_STR_ARG(service.service_type), MDNS_STR_ARG(service.proto), port,
|
err = mdns_service_add(nullptr, MDNS_STR_ARG(service.service_type), MDNS_STR_ARG(service.proto), port,
|
||||||
txt_records.begin(), txt_records.size());
|
txt_records.get(), service.txt_records.size());
|
||||||
|
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGW(TAG, "Failed to register service %s: %s", MDNS_STR_ARG(service.service_type), esp_err_to_name(err));
|
ESP_LOGW(TAG, "Failed to register service %s: %s", MDNS_STR_ARG(service.service_type), esp_err_to_name(err));
|
||||||
|
Reference in New Issue
Block a user