demo_zeroconf_api.cpp
Go to the documentation of this file.
1 
13 /*****************************************************************************
14 ** Includes
15 *****************************************************************************/
16 
18 #include <zeroconf_msgs/PublishedService.h>
19 #include <ros/ros.h>
20 
21 /*****************************************************************************
22 ** Main
23 *****************************************************************************/
24 
25 int main(int argc, char **argv) {
26 
27  zeroconf_avahi::Zeroconf zeroconf;
28  zeroconf_msgs::PublishedService service_dudette, service_dude, service_colliding_dude, service_not_advertised;
29  service_dudette.name = "Dudette";
30  service_dudette.type = "_ros-master._tcp";
31  service_dudette.port = 8888;
32  service_dudette.domain = "local";
33  ROS_INFO("===== Adding a service =====");
34  zeroconf.add_service(service_dudette);
35  sleep(2);
36  ROS_INFO("===== Adding a listener =====");
37  zeroconf.add_listener(service_dudette.type);
38  sleep(2);
39  service_dude = service_dudette;
40  service_dude.name = "Dude";
41  service_dude.port = 8889;
42  ROS_INFO("===== Adding another service =====");
43  zeroconf.add_service(service_dude);
44  sleep(2);
45  ROS_INFO("===== Accidentally adding the service again =====");
46  zeroconf.add_service(service_dude);
47  sleep(2);
48  service_colliding_dude = service_dude;
49  // collision
50  ROS_INFO("===== Local Collision =====");
51  service_colliding_dude.port = 8890;
52  zeroconf.add_service(service_colliding_dude);
53  sleep(3);
54  ROS_INFO("===== Removing some services =====");
55  zeroconf.remove_service(service_dudette);
56  zeroconf.remove_service(service_colliding_dude);
57  service_not_advertised = service_dude;
58  service_not_advertised.name = "OtherDude";
59  ROS_INFO("===== Remove a non-advertised service =====");
60  zeroconf.remove_service(service_not_advertised);
61  ROS_INFO("===== Waiting for listener to detect removals =====");
62  sleep(2); // chance for the removals to show up
63  ROS_INFO("===== Remove a listener =====");
64  zeroconf.remove_listener(service_dudette.type);
65  return 0;
66 }
bool add_listener(std::string &service_type)
bool add_service(PublishedService &service)
bool remove_service(const PublishedService &service)
#define ROS_INFO(...)
int main(int argc, char **argv)
bool remove_listener(const std::string &service_type)


zeroconf_avahi_demos
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 15:49:05