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;
50 class ServiceBrowseHandler;
53 class AvahiResolverHandler;
86 static void client_callback(AvahiClient *c, AvahiClientState state,
void *instance);
88 static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state,
91 static void browse_callback( AvahiServiceBrowser *b,
92 AvahiIfIndex interface,
93 AvahiProtocol protocol,
94 AvahiBrowserEvent event,
98 AvahiLookupResultFlags flags,
101 static void resolve_callback( AvahiServiceResolver *r,
102 AVAHI_GCC_UNUSED AvahiIfIndex interface,
103 AVAHI_GCC_UNUSED AvahiProtocol protocol,
104 AvahiResolverEvent event,
108 const char *host_name,
109 const AvahiAddress *address,
111 AvahiStringList *txt,
112 AvahiLookupResultFlags flags,
115 static void host_name_resolver_callback(AvahiHostNameResolver *r,
116 AvahiIfIndex interface,
117 AvahiProtocol protocol,
118 AvahiResolverEvent event,
120 const AvahiAddress *a,
121 AvahiLookupResultFlags flags,
124 static void address_resolver_callback(AvahiAddressResolver *r,
125 AvahiIfIndex interface,
126 AvahiProtocol protocol,
127 AvahiResolverEvent event,
128 const AvahiAddress *a,
130 AvahiLookupResultFlags flags,
134 void call_handler_service_removed(
const char *name,
137 void call_handler_service_added(
const char *name,
140 const char *host_name,
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(
struct sockaddr_in *in_addr, AvahiResolverCallbackData *data);
190 bool do_erase_browsers;
191 bool do_reset_groups;
193 AvahiSimplePoll *simple_poll;
195 AvahiClientState client_state;
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()
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.