zeroconf.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # License: BSD
00004 #   https://raw.github.com/robotics-in-concert/rocon_multimaster/master/multimaster_server/rocon_hub/LICENSE
00005 #
00006 ##############################################################################
00007 # Imports
00008 ##############################################################################
00009 
00010 import subprocess
00011 import sys
00012 
00013 # Ros imports
00014 import roslib
00015 roslib.load_manifest('rocon_hub')
00016 import rospy
00017 
00018 # Local imports
00019 from . import utils
00020 ##############################################################################
00021 # Functions
00022 ##############################################################################
00023 
00024 
00025 def advertise_port_to_avahi(port, hub_name):
00026     '''
00027       Check if avahi-daemon is around and publish the redis server ip:port.
00028     '''
00029     # Check - assuming ubuntu here, robustify later
00030     proc = subprocess.Popen(["pidof", "avahi-daemon"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
00031     if proc.stdout.read() == "":
00032         sys.exit(utils.logfatal("Hub : could not find the avahi-daemon - is it running?"))
00033         sys.exit(utils.logfatal("    : if your isp is misbehaving and avahi not autostarting"))
00034         sys.exit(utils.logfatal("    : you may need to set AVAHI_DAEMON_DETECT_LOCAL=0"))
00035         sys.exit(utils.logfatal("    : in /etc/default/avahi-daemon"))
00036 
00037     # if you don't specify  stdout/stderr streams, then it will automatically go to the background
00038     # avahi-publish is a blocking call - it has to go to the background
00039     # also note, we don't worrry about cleaning it up as it will be killed with the parent process
00040     subprocess.Popen(["avahi-publish", "-s", hub_name, "_ros-multimaster-hub._tcp", str(port)])
00041     rospy.loginfo("Hub : advertising '" + hub_name + "' on zeroconf [_ros-multimaster-hub._tcp, port " + str(port) + "]")
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


rocon_hub
Author(s): Daniel Stonier, Jihoon Lee
autogenerated on Tue Jan 15 2013 17:43:33