1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 import threading
34 from python_qt_binding import QtCore
35
36 from master_discovery_fkie.master_info import MasterInfo
37 from update_thread import UpdateThread
38
40 '''
41 A class to retrieve the state about ROS master from remote discovery node and
42 publish it be sending a QT signal. To retrieve the state a new thread will be
43 created.
44 '''
45 master_info_signal = QtCore.Signal(MasterInfo)
46 '''
47 @ivar: master_info_signal is a signal, which is emitted, if a new
48 L{aster_discovery_fkie.MasterInfo} is retrieved.
49 '''
50 master_errors_signal = QtCore.Signal(str, list)
51 '''
52 @ivar: master_errors_signal is a signal (masteruri, error list) with errors which
53 are occured on remote master_discovery.
54 '''
55
56 error_signal = QtCore.Signal(str, str)
57 '''
58 @ivar: error_signal is a signal (masteruri, error message), which is emitted,
59 if an error while retrieving a master info was occurred.
60 '''
61
63 QtCore.QObject.__init__(self)
64 self.__updateThreads = {}
65 self.__requestedUpdates = {}
66 self._lock = threading.RLock()
67
69 print " Shutdown update threads..."
70 self.__requestedUpdates.clear()
71 for _, thread in self.__updateThreads.iteritems():
72 thread.join(3)
73 print " Update threads are off!"
74
76 '''
77 This method starts a thread to get the informations about the ROS master by
78 the given RCP uri of the master_discovery node. If all informations are
79 retrieved, a C{master_info_signal} of this class will be emitted. If for given
80 masteruri a thread is already running, it will be inserted to the requested
81 updates. For the same masteruri only one requested update can be stored.
82 On update error the requested update will be ignored.
83 This method is thread safe.
84
85 @param masteruri: the URI of the remote ROS master
86 @type masteruri: C{str}
87 @param monitoruri: the URI of the monitor RPC interface of the master_discovery node
88 @type monitoruri: C{str}
89 @param delayed_exec: Delay the execution of the request for given seconds.
90 @type delayed_exec: C{float}
91 '''
92 with self._lock:
93 try:
94 if (self.__updateThreads.has_key(masteruri)):
95 self.__requestedUpdates[masteruri] = (monitoruri, delayed_exec)
96 else:
97 self.__create_update_thread(monitoruri, masteruri, delayed_exec)
98
99
100 except:
101 pass
102
106
109
113
115 with self._lock:
116 try:
117 thread = self.__updateThreads.pop(masteruri)
118 del thread
119 monitoruri, delayed_exec = self.__requestedUpdates.pop(masteruri)
120 self.__create_update_thread(monitoruri, masteruri, delayed_exec)
121 except KeyError:
122
123
124 pass
125 except:
126 import traceback
127 print traceback.format_exc(1)
128
136