| Home | Trees | Indices | Help |
|---|
|
|
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2012, Fraunhofer FKIE/US, Alexander Tiderko
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 # * Neither the name of Fraunhofer nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32
33 import time
34 import socket
35 import threading
36 import xmlrpclib
37 import random
38 from python_qt_binding import QtCore
39
40 #import roslib; roslib.load_manifest('node_manager_fkie')
41 import rospy
42
43 from master_discovery_fkie.master_info import MasterInfo
44
46 '''
47 A thread to retrieve the state about ROS master from remote discovery node and
48 publish it be sending a QT signal.
49 '''
50 update_signal = QtCore.Signal(MasterInfo)
51 '''
52 @ivar: update_signal is a signal, which is emitted, if a new
53 L{aster_discovery_fkie.MasterInfo} is retrieved.
54 '''
55
56 master_errors_signal = QtCore.Signal(str, list)
57 '''
58 @ivar: master_errors_signal is a signal (masteruri, list of errors),
59 which is emitted, if we get a list with errors from remote master_discovery.
60 '''
61
62 error_signal = QtCore.Signal(str, str)
63 '''
64 @ivar: error_signal is a signal (masteruri, error message), which is emitted,
65 if an error while retrieving a master info was occurred.
66 '''
67
69 '''
70 @param masteruri: the URI of the remote ROS master
71 @type masteruri: C{str}
72 @param monitoruri: the URI of the monitor RPC interface of the master_discovery node
73 @type monitoruri: C{str}
74 @param delayed_exec: Delay the execution of the request for given seconds.
75 @type delayed_exec: C{float}
76 '''
77 QtCore.QObject.__init__(self)
78 threading.Thread.__init__(self)
79 self._monitoruri = monitoruri
80 self._masteruri = masteruri
81 self._delayed_exec = delayed_exec
82 self.setDaemon(True)
83
85 '''
86 '''
87 try:
88 delay = self._delayed_exec+0.5+random.random()
89 #'print "wait request update", self._monitoruri, delay
90 time.sleep(delay)
91 #'print "request update", self._monitoruri
92 socket.setdefaulttimeout(25)
93 remote_monitor = xmlrpclib.ServerProxy(self._monitoruri)
94 # get first master errors
95 try:
96 muri, errors = remote_monitor.masterErrors()
97 self.master_errors_signal.emit(muri, errors)
98 except xmlrpclib.Fault as err:
99 rospy.logwarn("Older master_discovery on %s detected. It does not support master error reports!"%self._masteruri)
100 # now get master info from master discovery
101 remote_info = remote_monitor.masterInfo()
102 master_info = MasterInfo.from_list(remote_info)
103 master_info.check_ts = time.time()
104 #'print "request success", self._monitoruri
105 self.update_signal.emit(master_info)
106 except:
107 import traceback
108 # print traceback.print_exc()
109 formatted_lines = traceback.format_exc(1).splitlines()
110 rospy.logwarn("Connection to %s failed:\n\t%s", str(self._monitoruri), formatted_lines[-1])
111 #'print "request failed", self._monitoruri
112 self.error_signal.emit(self._masteruri, formatted_lines[-1])
113 finally:
114 if not socket is None:
115 socket.setdefaulttimeout(None)
116
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Fri Aug 28 11:39:31 2015 | http://epydoc.sourceforge.net |