24#ifndef _NETCOMM_DNSSD_AVAHI_THREAD_H_
25#define _NETCOMM_DNSSD_AVAHI_THREAD_H_
27#include <avahi-client/client.h>
28#include <core/threading/thread.h>
29#include <core/utils/lock_list.h>
30#include <core/utils/lock_map.h>
31#include <core/utils/lock_queue.h>
32#include <netcomm/service_discovery/service_browser.h>
33#include <netcomm/service_discovery/service_publisher.h>
34#include <netinet/in.h>
40struct AvahiEntryGroup;
41struct AvahiSimplePoll;
42struct AvahiServiceBrowser;
43struct AvahiServiceResolver;
44struct AvahiHostNameResolver;
45struct AvahiAddressResolver;
49class ServiceBrowseHandler;
52class AvahiResolverHandler;
57 AvahiThread(
bool enable_ipv4 =
true,
bool enable_ipv6 =
true);
86 static void client_callback(AvahiClient *c, AvahiClientState state,
void *instance);
88 static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state,
void *instance);
90 static void browse_callback(AvahiServiceBrowser * b,
91 AvahiIfIndex interface,
92 AvahiProtocol protocol,
93 AvahiBrowserEvent event,
97 AvahiLookupResultFlags flags,
100 static void resolve_callback(AvahiServiceResolver * r,
101 AVAHI_GCC_UNUSED AvahiIfIndex interface,
102 AVAHI_GCC_UNUSED AvahiProtocol protocol,
103 AvahiResolverEvent event,
107 const char * host_name,
108 const AvahiAddress * address,
110 AvahiStringList * txt,
111 AvahiLookupResultFlags flags,
114 static void host_name_resolver_callback(AvahiHostNameResolver *r,
115 AvahiIfIndex interface,
116 AvahiProtocol protocol,
117 AvahiResolverEvent event,
119 const AvahiAddress * a,
120 AvahiLookupResultFlags flags,
123 static void address_resolver_callback(AvahiAddressResolver * r,
124 AvahiIfIndex interface,
125 AvahiProtocol protocol,
126 AvahiResolverEvent event,
127 const AvahiAddress * a,
129 AvahiLookupResultFlags flags,
132 void call_handler_service_removed(
const char *
name,
const char *type,
const char *domain);
133 void call_handler_service_added(
const char *
name,
136 const char * host_name,
137 const AvahiIfIndex interface,
138 const AvahiAddress * address,
140 std::list<std::string> &txt,
141 AvahiLookupResultFlags flags);
142 void call_handler_failed(
const char *
name,
const char *type,
const char *domain);
144 void call_handler_all_for_now(
const char *type);
145 void call_handler_cache_exhausted(
const char *type);
147 void create_browser(
const char *service_type);
148 void create_browsers();
149 void erase_browsers();
150 void recreate_browsers();
151 void create_pending_browsers();
152 void remove_pending_browsers();
160 AvahiEntryGroup *create_service(
const NetworkService &service, AvahiEntryGroup *exgroup);
161 void group_reset(AvahiEntryGroup *g);
162 void group_erase(AvahiEntryGroup *g);
163 void name_collision(AvahiEntryGroup *g);
166 void create_pending_services();
167 void remove_pending_services();
168 void recreate_services();
172 typedef std::pair<AvahiThread *, AvahiResolverHandler *> AvahiResolverCallbackData;
174 void remove_hostname_resolver(AvahiHostNameResolver *r);
175 void remove_address_resolver(AvahiAddressResolver *r);
176 void start_address_resolvers();
177 void start_hostname_resolvers();
178 void start_hostname_resolver(
const char *
name, AvahiResolverCallbackData *data);
179 void start_address_resolver(
const struct sockaddr_storage *in_addr,
180 AvahiResolverCallbackData * data);
186 bool do_erase_browsers;
187 bool do_reset_groups;
189 AvahiSimplePoll * simple_poll;
190 AvahiClient * client;
191 AvahiClientState client_state;
192 AvahiProtocol service_protocol;
193 const static std::chrono::seconds wait_on_init_failure;
Avahi resolver handler interface.
void resolve_name(const char *name, AvahiResolverHandler *handler)
Order name resolution.
void watch_service(const char *service_type, ServiceBrowseHandler *h)
Add a result handler.
~AvahiThread()
Destructor.
void publish_service(NetworkService *service)
Publish service.
void unwatch_service(const char *service_type, ServiceBrowseHandler *h)
Remove a handler.
void unpublish_service(NetworkService *service)
Revoke service publication.
AvahiThread(bool enable_ipv4=true, bool enable_ipv6=true)
Constructor.
void wait_initialized()
Waits for the AvahiThread to be initialized.
virtual void run()
Stub to see name in backtrace for easier debugging.
virtual void loop()
Avahi thread loop.
void resolve_address(struct sockaddr *addr, socklen_t addrlen, AvahiResolverHandler *handler)
Order address resolution.
Representation of a service announced or found via service discovery (i.e.
Interface for class that process browse results.
Service publisher interface.
Thread class encapsulation of pthreads.
const char * name() const
Get name of thread.
virtual void run()
Code to execute in the thread.
Wait until a given condition holds.
Fawkes library namespace.