lib/avahi/Service: add field visible
Now individual services can be hidden or shown at any time.
This commit is contained in:
parent
8d02986b0e
commit
aef2c5dc14
@ -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
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user