concertmaster_discovery.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_app_manager/concert_client/LICENSE
00005 #
00006 
00007 import rospy
00008 import redis
00009 import threading
00010 # It polls redis server to discover currently connected concertmaster
00011 # and notifies concert client
00012 
00013 
00014 class ConcertMasterDiscovery(threading.Thread):
00015     params = {}
00016 
00017     def __init__(self, hub_client, key, processNewMaster):
00018         threading.Thread.__init__(self)
00019         self.hub_client = hub_client
00020         self.concertmasterlist_key = key
00021         self.processNewMaster = processNewMaster
00022         self._stop = False
00023         self.masterlist = []
00024 
00025     def run(self):
00026         rospy.loginfo("Concert Client : concert discovery has started")
00027 
00028         while not rospy.is_shutdown() and not self._stop:
00029             try:
00030                 discovered_masterlist = self.getMasterList()
00031                 self.processNewMaster(discovered_masterlist)
00032                 rospy.sleep(3)
00033             except redis.ConnectionError as e:
00034                 # This just drops out - we probably need failure recovery somewhere
00035                 rospy.logwarn("Concert Client : lost connection to the hub [%s]" % str(e))
00036                 break
00037         rospy.loginfo("Concert Client : concert discovery has stopped")
00038 
00039     def getMasterList(self):
00040         return self.hub_client.getValues(self.concertmasterlist_key)
00041 
00042     def set_stop(self):
00043         self._stop = True
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends


concert_client
Author(s): Jihoon
autogenerated on Tue Jan 22 2013 12:59:50