24 #ifndef __NETCOMM_DNSSD_AVAHI_THREAD_H_ 25 #define __NETCOMM_DNSSD_AVAHI_THREAD_H_ 27 #include <core/threading/thread.h> 28 #include <netcomm/service_discovery/service_publisher.h> 29 #include <netcomm/service_discovery/service_browser.h> 31 #include <core/utils/lock_map.h> 32 #include <core/utils/lock_list.h> 33 #include <core/utils/lock_queue.h> 35 #include <avahi-client/client.h> 38 #include <netinet/in.h> 40 struct AvahiEntryGroup;
41 struct AvahiSimplePoll;
42 struct AvahiServiceBrowser;
43 struct AvahiServiceResolver;
44 struct AvahiHostNameResolver;
45 struct AvahiAddressResolver;
49 class ServiceBrowseHandler;
52 class AvahiResolverHandler;
60 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,
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,
133 void call_handler_service_removed(
const char *name,
136 void call_handler_service_added(
const char *name,
139 const char *host_name,
140 const AvahiIfIndex interface,
141 const AvahiAddress *address,
143 std::list<std::string> &txt,
144 AvahiLookupResultFlags flags);
145 void call_handler_failed(
const char *name,
149 void call_handler_all_for_now(
const char *type);
150 void call_handler_cache_exhausted(
const char *type);
153 void create_browser(
const char *service_type);
154 void create_browsers();
155 void erase_browsers();
156 void recreate_browsers();
157 void create_pending_browsers();
158 void remove_pending_browsers();
167 AvahiEntryGroup *exgroup);
168 void group_reset(AvahiEntryGroup *g);
169 void group_erase(AvahiEntryGroup *g);
170 void name_collision(AvahiEntryGroup *g);
173 void create_pending_services();
174 void remove_pending_services();
175 void recreate_services();
179 typedef std::pair<AvahiThread *, AvahiResolverHandler *> AvahiResolverCallbackData;
181 void remove_hostname_resolver(AvahiHostNameResolver *r);
182 void remove_address_resolver(AvahiAddressResolver *r);
183 void start_address_resolvers();
184 void start_hostname_resolvers();
185 void start_hostname_resolver(
const char *name, AvahiResolverCallbackData *data);
186 void start_address_resolver(
const struct sockaddr_storage *in_addr, AvahiResolverCallbackData *data);
192 bool do_erase_browsers;
193 bool do_reset_groups;
195 AvahiSimplePoll *simple_poll;
197 AvahiClientState client_state;
198 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.