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> 39 struct AvahiEntryGroup;
40 struct AvahiSimplePoll;
41 struct AvahiServiceBrowser;
42 struct AvahiServiceResolver;
43 struct AvahiHostNameResolver;
44 struct AvahiAddressResolver;
48 class ServiceBrowseHandler;
51 class AvahiResolverHandler;
56 AvahiThread(
bool enable_ipv4 =
true,
bool enable_ipv6 =
true);
85 static void client_callback(AvahiClient *c, AvahiClientState state,
void *instance);
87 static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state,
void *instance);
89 static void browse_callback(AvahiServiceBrowser * b,
90 AvahiIfIndex interface,
91 AvahiProtocol protocol,
92 AvahiBrowserEvent event,
96 AvahiLookupResultFlags flags,
99 static void resolve_callback(AvahiServiceResolver *r,
100 AVAHI_GCC_UNUSED AvahiIfIndex interface,
101 AVAHI_GCC_UNUSED AvahiProtocol protocol,
102 AvahiResolverEvent event,
106 const char * host_name,
107 const AvahiAddress * address,
109 AvahiStringList * txt,
110 AvahiLookupResultFlags flags,
113 static void host_name_resolver_callback(AvahiHostNameResolver *r,
114 AvahiIfIndex interface,
115 AvahiProtocol protocol,
116 AvahiResolverEvent event,
118 const AvahiAddress * a,
119 AvahiLookupResultFlags flags,
122 static void address_resolver_callback(AvahiAddressResolver * r,
123 AvahiIfIndex interface,
124 AvahiProtocol protocol,
125 AvahiResolverEvent event,
126 const AvahiAddress * a,
128 AvahiLookupResultFlags flags,
131 void call_handler_service_removed(
const char *
name,
const char *type,
const char *domain);
132 void call_handler_service_added(
const char *
name,
135 const char * host_name,
136 const AvahiIfIndex interface,
137 const AvahiAddress * address,
139 std::list<std::string> &txt,
140 AvahiLookupResultFlags flags);
141 void call_handler_failed(
const char *
name,
const char *type,
const char *domain);
143 void call_handler_all_for_now(
const char *type);
144 void call_handler_cache_exhausted(
const char *type);
146 void create_browser(
const char *service_type);
147 void create_browsers();
148 void erase_browsers();
149 void recreate_browsers();
150 void create_pending_browsers();
151 void remove_pending_browsers();
159 AvahiEntryGroup *create_service(
const NetworkService &service, AvahiEntryGroup *exgroup);
160 void group_reset(AvahiEntryGroup *g);
161 void group_erase(AvahiEntryGroup *g);
162 void name_collision(AvahiEntryGroup *g);
165 void create_pending_services();
166 void remove_pending_services();
167 void recreate_services();
171 typedef std::pair<AvahiThread *, AvahiResolverHandler *> AvahiResolverCallbackData;
173 void remove_hostname_resolver(AvahiHostNameResolver *r);
174 void remove_address_resolver(AvahiAddressResolver *r);
175 void start_address_resolvers();
176 void start_hostname_resolvers();
177 void start_hostname_resolver(
const char *
name, AvahiResolverCallbackData *data);
178 void start_address_resolver(
const struct sockaddr_storage *in_addr,
179 AvahiResolverCallbackData * data);
185 bool do_erase_browsers;
186 bool do_reset_groups;
188 AvahiSimplePoll *simple_poll;
189 AvahiClient * client;
190 AvahiClientState client_state;
191 AvahiProtocol service_protocol;
Service publisher interface.
Wait until a given condition holds.
~AvahiThread()
Destructor.
virtual void loop()
Avahi thread loop.
Fawkes library namespace.
virtual void run()
Code to execute in the thread.
Thread class encapsulation of pthreads.
Interface for class that process browse results.
Avahi resolver handler interface.
void publish_service(NetworkService *service)
Publish service.
void resolve_address(struct sockaddr *addr, socklen_t addrlen, AvahiResolverHandler *handler)
Order address resolution.
void resolve_name(const char *name, AvahiResolverHandler *handler)
Order name resolution.
virtual void run()
Stub to see name in backtrace for easier debugging.
void watch_service(const char *service_type, ServiceBrowseHandler *h)
Add a result handler.
const char * name() const
Get name of thread.
Representation of a service announced or found via service discovery (i.e.
AvahiThread(bool enable_ipv4=true, bool enable_ipv6=true)
Constructor.
void unpublish_service(NetworkService *service)
Revoke service publication.
void wait_initialized()
Waits for the AvahiThread to be initialized.
void unwatch_service(const char *service_type, ServiceBrowseHandler *h)
Remove a handler.