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 from python_qt_binding.QtCore import QObject, Signal
34 import threading
35
36 from master_discovery_fkie.master_info import MasterInfo
37 from update_thread import UpdateThread
38
39
41 '''
42 A class to retrieve the state about ROS master from remote discovery node and
43 publish it be sending a QT signal. To retrieve the state a new thread will be
44 created.
45 '''
46 master_info_signal = Signal(MasterInfo)
47 '''
48 @ivar: master_info_signal is a signal, which is emitted, if a new
49 U{master_discovery_fkie.MasterInfo<http://docs.ros.org/api/master_discovery_fkie/html/modules.html#module-master_discovery_fkie.master_info>} is retrieved.
50 '''
51 master_errors_signal = Signal(str, list)
52 '''
53 @ivar: master_errors_signal is a signal (masteruri, error list) with errors which
54 are occured on remote master_discovery.
55 '''
56
57 error_signal = Signal(str, str)
58 '''
59 @ivar: error_signal is a signal (masteruri, error message), which is emitted,
60 if an error while retrieving a master info was occurred.
61 '''
62
63 timediff_signal = Signal(str, float)
64 '''
65 @ivar: timediff_signal is a signal (masteruri, time difference), which is emitted
66 after the difference of time to the remote host is determined.
67 '''
68
70 QObject.__init__(self)
71 self.__updateThreads = {}
72 self.__requestedUpdates = {}
73 self._lock = threading.RLock()
74
76 if len(self.__updateThreads) > 0:
77 print " Shutdown update threads..."
78 self.__requestedUpdates.clear()
79 for _, thread in self.__updateThreads.iteritems():
80 thread.join(3)
81 print " Update threads are off!"
82
84 '''
85 This method starts a thread to get the informations about the ROS master by
86 the given RCP uri of the master_discovery node. If all informations are
87 retrieved, a C{master_info_signal} of this class will be emitted. If for given
88 masteruri a thread is already running, it will be inserted to the requested
89 updates. For the same masteruri only one requested update can be stored.
90 On update error the requested update will be ignored.
91 This method is thread safe.
92
93 @param masteruri: the URI of the remote ROS master
94 @type masteruri: C{str}
95 @param monitoruri: the URI of the monitor RPC interface of the master_discovery node
96 @type monitoruri: C{str}
97 @param delayed_exec: Delay the execution of the request for given seconds.
98 @type delayed_exec: C{float}
99 '''
100 with self._lock:
101 try:
102 if masteruri in self.__updateThreads:
103 self.__requestedUpdates[masteruri] = (monitoruri, delayed_exec)
104 else:
105 self.__create_update_thread(monitoruri, masteruri, delayed_exec)
106 except:
107 pass
108
112
115
118
122
124 with self._lock:
125 try:
126 thread = self.__updateThreads.pop(masteruri)
127 del thread
128 monitoruri, delayed_exec = self.__requestedUpdates.pop(masteruri)
129 self.__create_update_thread(monitoruri, masteruri, delayed_exec)
130 except KeyError:
131 pass
132 except:
133 import traceback
134 print traceback.format_exc(1)
135
144