demo_zeroconf_api.cpp
Go to the documentation of this file.
00001 
00013 /*****************************************************************************
00014 ** Includes
00015 *****************************************************************************/
00016 
00017 #include <zeroconf_avahi/zeroconf.hpp>
00018 #include <zeroconf_msgs/PublishedService.h>
00019 #include <ros/ros.h>
00020 
00021 /*****************************************************************************
00022 ** Main
00023 *****************************************************************************/
00024 
00025 int main(int argc, char **argv) {
00026 
00027         zeroconf_avahi::Zeroconf zeroconf;
00028         zeroconf_msgs::PublishedService service_dudette, service_dude, service_colliding_dude, service_not_advertised;
00029         service_dudette.name = "Dudette";
00030         service_dudette.type = "_ros-master._tcp";
00031         service_dudette.port = 8888;
00032         service_dudette.domain = "local";
00033         ROS_INFO("===== Adding a service =====");
00034         zeroconf.add_service(service_dudette);
00035         sleep(2);
00036         ROS_INFO("===== Adding a listener =====");
00037         zeroconf.add_listener(service_dudette.type);
00038         sleep(2);
00039         service_dude = service_dudette;
00040         service_dude.name = "Dude";
00041         service_dude.port = 8889;
00042         ROS_INFO("===== Adding another service =====");
00043         zeroconf.add_service(service_dude);
00044         sleep(2);
00045         ROS_INFO("===== Accidentally adding the service again =====");
00046         zeroconf.add_service(service_dude);
00047         sleep(2);
00048         service_colliding_dude = service_dude;
00049         // collision
00050         ROS_INFO("===== Local Collision =====");
00051         service_colliding_dude.port = 8890;
00052         zeroconf.add_service(service_colliding_dude);
00053         sleep(3);
00054         ROS_INFO("===== Removing some services =====");
00055         zeroconf.remove_service(service_dudette);
00056         zeroconf.remove_service(service_colliding_dude);
00057         service_not_advertised = service_dude;
00058         service_not_advertised.name = "OtherDude";
00059         ROS_INFO("===== Remove a non-advertised service =====");
00060         zeroconf.remove_service(service_not_advertised);
00061         ROS_INFO("===== Waiting for listener to detect removals =====");
00062         sleep(2); // chance for the removals to show up
00063         ROS_INFO("===== Remove a listener =====");
00064         zeroconf.remove_listener(service_dudette.type);
00065         return 0;
00066 }


zeroconf_avahi_demos
Author(s): Daniel Stonier
autogenerated on Mon Oct 6 2014 09:12:39