lib/avahi/Service: add field visible

Now individual services can be hidden or shown at any time.
This commit is contained in:
Max Kellermann 2024-01-18 16:04:40 +01:00 committed by Max Kellermann
parent 8d02986b0e
commit aef2c5dc14
3 changed files with 24 additions and 7 deletions

View File

@ -55,22 +55,25 @@ Publisher::~Publisher() noexcept
client.RemoveListener(*this);
}
void
Publisher::UpdateServices() noexcept
{
if (visible && client.IsConnected())
defer_register_services.Schedule();
}
void
Publisher::AddService(Service &service) noexcept
{
services.push_back(service);
if (visible && client.IsConnected())
defer_register_services.Schedule();
UpdateServices();
}
void
Publisher::RemoveService(Service &service) noexcept
{
services.erase(services.iterator_to(service));
if (visible && client.IsConnected())
defer_register_services.Schedule();
UpdateServices();
}
inline void
@ -141,7 +144,8 @@ AddServices(AvahiEntryGroup &group,
const IntrusiveList<Service> &services, const char *name)
{
for (const auto &i : services)
AddService(group, i, name);
if (i.visible)
AddService(group, i, name);
}
void

View File

@ -59,6 +59,12 @@ public:
Publisher(const Publisher &) = delete;
Publisher &operator=(const Publisher &) = delete;
/**
* Call this after a #Service field was modified to publish
* the changes.
*/
void UpdateServices() noexcept;
/**
* Publish another service.
*

View File

@ -22,6 +22,13 @@ struct Service : IntrusiveListHook<> {
std::string type;
uint16_t port;
/**
* If this is false, then the service is not published. You
* can change this field at any time and then call
* Publisher::UpdateServices() to publish the change.
*/
bool visible = true;
Service(AvahiIfIndex _interface, AvahiProtocol _protocol,
const char *_type, uint16_t _port) noexcept
:interface(_interface), protocol(_protocol),