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 error_signal = QtCore.Signal(str, str)
51 '''
52 @ivar: error_signal is a signal (masteruri, error message), which is emitted,
53 if an error while retrieving a master info was occurred.
54 '''
55
57 QtCore.QObject.__init__(self)
58 self.__updateThreads = {}
59 self.__requestedUpdates = {}
60 self._lock = threading.RLock()
61
63 print " Shutdown update threads..."
64 self.__requestedUpdates.clear()
65 for key, thread in self.__updateThreads.iteritems():
66 thread.join(3)
67 print " Update threads are off!"
68
70 '''
71 This method starts a thread to get the informations about the ROS master by
72 the given RCP uri of the master_discovery node. If all informations are
73 retrieved, a C{master_info_signal} of this class will be emitted. If for given
74 masteruri a thread is already running, it will be inserted to the requested
75 updates. For the same masteruri only one requested update can be stored.
76 On update error the requested update will be ignored.
77 This method is thread safe.
78
79 @param masteruri: the URI of the remote ROS master
80 @type masteruri: C{str}
81 @param monitoruri: the URI of the monitor RPC interface of the master_discovery node
82 @type monitoruri: C{str}
83 @param delayed_exec: Delay the execution of the request for given seconds.
84 @type delayed_exec: C{float}
85 '''
86 with self._lock:
87 try:
88 if (self.__updateThreads.has_key(masteruri)):
89 self.__requestedUpdates[masteruri] = (monitoruri, delayed_exec)
90 else:
91 self.__create_update_thread(monitoruri, masteruri, delayed_exec)
92
93
94 except:
95 pass
96
100
104
106 with self._lock:
107 try:
108 thread = self.__updateThreads.pop(masteruri)
109 del thread
110 monitoruri, delayed_exec = self.__requestedUpdates.pop(masteruri)
111 self.__create_update_thread(monitoruri, masteruri, delayed_exec)
112 except KeyError:
113
114
115 pass
116 except:
117 import traceback
118 print traceback.format_exc()
119
126