16 #include <avahi-client/publish.h> 17 #include <avahi-client/client.h> 18 #include <avahi-client/lookup.h> 19 #include <avahi-common/malloc.h> 20 #include <avahi-common/error.h> 21 #include <avahi-common/thread-watch.h> 23 #include <boost/thread/mutex.hpp> 24 #include <boost/bimap/bimap.hpp> 25 #include <boost/function.hpp> 26 #include <boost/shared_ptr.hpp> 28 #include <zeroconf_msgs/PublishedService.h> 29 #include <zeroconf_msgs/DiscoveredService.h> 52 bool operator()(
const zeroconf_msgs::PublishedService &a,
const zeroconf_msgs::PublishedService &b)
const 56 return a.name < b.name;
58 else if (a.type != b.type)
60 return a.type < b.type;
64 return a.port < b.port;
86 int protocol,
int hardware_interface) :
87 service(discovered_service), protocol(protocol), hardware_interface(hardware_interface), resolver(new_resolver)
95 avahi_service_resolver_free(resolver);
115 const zeroconf_msgs::DiscoveredService &a = avahi_service_a->service;
116 const zeroconf_msgs::DiscoveredService &b = avahi_service_b->service;
117 if (a.name != b.name)
119 return a.name < b.name;
121 else if (a.type != b.type)
123 return a.type < b.type;
125 else if (a.domain != b.domain)
127 return a.domain < b.domain;
129 else if (avahi_service_a->hardware_interface != avahi_service_b->hardware_interface)
131 return avahi_service_a->hardware_interface < avahi_service_b->hardware_interface;
135 return avahi_service_a->protocol < avahi_service_b->protocol;
166 typedef boost::bimaps::bimap<AvahiEntryGroup*, boost::bimaps::set_of<PublishedService, PublishedServiceCompare> >
service_bimap;
167 typedef boost::bimaps::bimap<AvahiServiceBrowser*, boost::bimaps::set_of<std::string> >
discovery_bimap;
175 bool add_service(PublishedService &service);
176 bool remove_service(
const PublishedService &service);
181 bool add_listener(std::string &service_type);
182 bool remove_listener(
const std::string &service_type);
184 void list_discovered_services(
const std::string &service_type, std::vector<zeroconf_msgs::DiscoveredService> &list);
185 void list_published_services(
const std::string &service_type, std::vector<zeroconf_msgs::PublishedService> &list);
189 new_connection_signal = new_connections;
190 lost_connection_signal = lost_connections;
211 int ros_to_avahi_protocol(
const int &protocol);
212 std::string ros_to_txt_protocol(
const int &protocol);
213 int avahi_to_ros_protocol(
const int &protocol);
214 std::string avahi_to_txt_protocol(
const int &protocol);
215 discovered_service_set::iterator find_discovered_service(zeroconf_msgs::DiscoveredService &service);
220 bool add_service_non_threaded(PublishedService &service);
223 avahi_threaded_poll_quit(threaded_poll);
224 invalid_object =
true;
230 static void entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state,
void *userdata);
231 static void client_callback(AvahiClient *c, AvahiClientState state,
void * userdata);
232 static void discovery_callback(AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol,
233 AvahiBrowserEvent event,
const char *name,
const char *type,
const char *domain,
234 AvahiLookupResultFlags flags,
void* userdata);
235 static void resolve_callback(AvahiServiceResolver *r, AvahiIfIndex interface, AvahiProtocol protocol,
236 AvahiResolverEvent event,
const char *name,
const char *type,
const char *domain,
237 const char *host_name,
const AvahiAddress *address, uint16_t port, AvahiStringList *txt,
238 AvahiLookupResultFlags flags,
void* userdata);
239 static void modify_callback(AVAHI_GCC_UNUSED AvahiTimeout *e,
void *userdata);
std::set< boost::shared_ptr< DiscoveredAvahiService >, DiscoveredAvahiServiceCompare > discovered_service_set
Internal storage for linking discovered service info with active avahi resolvers. ...
bool operator()(const zeroconf_msgs::PublishedService &a, const zeroconf_msgs::PublishedService &b) const
boost::mutex service_mutex
boost::bimaps::bimap< AvahiEntryGroup *, boost::bimaps::set_of< PublishedService, PublishedServiceCompare > > service_bimap
~DiscoveredAvahiService()
Internal comparison function for use with ordered sets.
AvahiThreadedPoll * threaded_poll
bool operator()(const boost::shared_ptr< DiscoveredAvahiService > avahi_service_a, const boost::shared_ptr< DiscoveredAvahiService > avahi_service_b) const
connection_signal_cb new_connection_signal
discovery_bimap discovery_service_types
const int permitted_protocols
service_bimap committed_services
zeroconf_msgs::DiscoveredService service
Ros interface to linux's avahi daemon.
zeroconf_msgs::PublishedService PublishedService
std::pair< AvahiEntryGroup *, PublishedService > service_map_pair
void connect_signal_callbacks(connection_signal_cb new_connections, connection_signal_cb lost_connections)
AvahiServiceResolver * resolver
DiscoveredAvahiService(zeroconf_msgs::DiscoveredService &discovered_service, AvahiServiceResolver *new_resolver, int protocol, int hardware_interface)
boost::bimaps::bimap< AvahiServiceBrowser *, boost::bimaps::set_of< std::string > > discovery_bimap
boost::function< void(zeroconf_msgs::DiscoveredService)> connection_signal_cb
service_bimap established_services
discovered_service_set discovered_services
Comparison functor for the discovered services set.