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/license/LICENSE
00005 #
00006 ##############################################################################
00007 # Imports
00008 ##############################################################################
00009 
00010 import subprocess
00011 import sys
00012 
00013 # Delete this once we upgrade (hopefully anything after precise)
00014 # Refer to https://github.com/robotics-in-concert/rocon_multimaster/issues/248
00015 import threading
00016 threading._DummyThread._Thread__stop = lambda x: 42
00017 
00018 # Ros imports
00019 import rospy
00020 
00021 # Local imports
00022 from . import utils
00023 ##############################################################################
00024 # Functions
00025 ##############################################################################
00026 
00027 
00028 def advertise_port_to_avahi(port, hub_name):
00029     '''
00030       Check if avahi-daemon is around and publish the redis server ip:port.
00031     '''
00032     # Check - assuming ubuntu here, robustify later
00033     proc = subprocess.Popen(["pidof", "avahi-daemon"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
00034     if proc.stdout.read() == "":
00035         sys.exit(utils.logfatal("Hub : could not find the avahi-daemon - is it running?"))
00036         sys.exit(utils.logfatal("    : if your isp is misbehaving and avahi not autostarting"))
00037         sys.exit(utils.logfatal("    : you may need to set AVAHI_DAEMON_DETECT_LOCAL=0"))
00038         sys.exit(utils.logfatal("    : in /etc/default/avahi-daemon"))
00039 
00040     # if you don't specify  stdout/stderr streams, then it will automatically go to the background
00041     # avahi-publish is a blocking call - it has to go to the background
00042     # also note, we don't worry about cleaning it up as it will be killed with the parent process
00043     subprocess.Popen(["avahi-publish", "-s", hub_name, "_ros-multimaster-hub._tcp", str(port)])
00044     rospy.loginfo("Hub : advertising '" + hub_name + "' on zeroconf [_ros-multimaster-hub._tcp, port " + str(port) + "]")


rocon_hub
Author(s): Daniel Stonier , Jihoon Lee , Piyush Khandelwal
autogenerated on Sat Jun 8 2019 18:48:46