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 from threading import RLock3611438 self.masteruri = masteruri 39 self._masternames = [mastername] if mastername else [] 40 self._hostnames = [hostname] if hostname else [] 41 self._addresses = [address] if address else []4244 return ''.join([str(self.masteruri), ':\n', 45 ' masternames: ', str(self._masternames), '\n', 46 ' hostnames: ', str(self._hostnames), '\n', 47 ' addresses: ', str(self._addresses), '\n'])48 53 58 63 67 71 75 80 83 88 9395 if len(self._masternames) > 1: 96 try: 97 self._masternames.remove(mastername) 98 except: 99 pass100 107117 ''' 118 This class stores the association between master URI, master name and 119 host name or IP. Both the setter and the getter methods are thread safe. 120 ''' 121300123 self.mutex = RLock() 124 self._masters = [] #sets with masters 125 self._hosts = [] #sets with hosts 126 self._address = [] # avoid the mixing of ip and name as address127129 with self.mutex: 130 for m in self._masters: 131 if masteruri and m.masteruri == masteruri: 132 self._masters.remove(m) 133 return134136 with self.mutex: 137 for m in self._masters: 138 if m.hasMastername(mastername) and (m.hasHostname(hostname) or m.hasAddress(hostname)): 139 m.removeExtMastername(mastername) 140 m.removeExtHostname(hostname) 141 m.removeExtAddress(hostname) 142 return143 144 # def remove(self, name=None, masteruri=None, host=None): 145 # ''' 146 # Remove an association. If one of the given parameter found in the association, 147 # the association will be removed from the name resolution list. 148 # @param name: the name of the ROS master. 149 # @type name: C{str} (Default: C{None}) 150 # @param masteruri: the URI of the ROS master. 151 # @type masteruri: C{str} (Default: C{None}) 152 # @param host: the host name or IP 153 # @type host: C{str} (Default: C{None}) 154 # ''' 155 # try: 156 # self.mutex.acquire() 157 # for s in list(self._masters): 158 # if (name, 'name') in s or (masteruri, 'uri') in s or (host, 'host') in s: 159 # try: 160 # s.remove((name, 'name')) 161 # except: 162 # pass 163 # try: 164 # s.remove((masteruri, 'uri')) 165 # except: 166 # pass 167 # try: 168 # s.remove((host, 'host')) 169 # self._address.remove(host) 170 # except: 171 # pass 172 # if len(s) < 2: 173 # self._masters.remove(s) 174 # finally: 175 # self.mutex.release() 176178 with self.mutex: 179 mastername = self._validateMastername(mastername, masteruri) 180 for m in self._masters: 181 if m.masteruri and m.masteruri == masteruri: 182 m.addMastername(mastername) 183 m.addHostname(hostname) 184 m.addAddress(address) 185 return 186 elif m.masteruri is None and m.hasMastername(mastername): 187 m.masteruri = masteruri 188 m.addMastername(mastername) 189 m.addHostname(hostname) 190 m.addAddress(address) 191 return 192 self._masters.append(MasterEntry(masteruri, mastername, address, hostname))193195 with self.mutex: 196 # mastername = self._validateMastername(mastername) 197 for m in self._masters: 198 if m.hasMastername(mastername): 199 m.addMastername(mastername) 200 m.addHostname(hostname) 201 m.addAddress(address) 202 return 203 elif mastername is None: 204 if m.hasHostname(hostname) or m.hasAddress(address): 205 m.addHostname(hostname) 206 m.addAddress(address) 207 if not mastername is None: 208 self._masters.append(MasterEntry(None, mastername, address, hostname))209211 ''' 212 Not thead safe 213 ''' 214 # with self.mutex: 215 mm = self.masteruri(mastername) 216 if mm and mm != masteruri: 217 print "EROROR name", mastername, "bereits fuer", mm, "vergeben!" 218 nr = 2 219 while mm and mm != masteruri: 220 mm = self.masteruri('_'.join([mastername, str(nr)])) 221 nr = nr + 1 222 return '_'.join([mastername, str(nr)]) 223 return mastername224226 with self.mutex: 227 for m in self._masters: 228 if m.masteruri == masteruri: 229 return True 230 return False231233 with self.mutex: 234 for m in self._masters: 235 if m.masteruri == masteruri: 236 if not address is None: 237 if m.hasAddress(address): 238 return m.getMastername() 239 else: 240 return m.getMastername() 241 return None242244 with self.mutex: 245 for m in self._masters: 246 if m.masteruri == masteruri: 247 return m.getMasternames() 248 return list()249251 with self.mutex: 252 for m in self._masters: 253 if m.hasAddress(address): 254 return m.getMastername() 255 return None256258 with self.mutex: 259 for m in self._masters: 260 if m.hasMastername(mastername): 261 return m.masteruri 262 return None263265 with self.mutex: 266 result = [] 267 for m in self._masters: 268 if m.hasHostname(hostname) and m.masteruri and not m.masteruri in result: 269 result.append(m.masteruri) 270 return result271273 with self.mutex: 274 for m in self._masters: 275 if m.masteruri == masteruri or m.hasHostname(masteruri) or m.hasMastername(masteruri): 276 return m.getAddress() 277 return None278280 with self.mutex: 281 for m in self._masters: 282 if m.hasAddress(address) or m.hasMastername(address): 283 result = m.getHostname() 284 return result if result else address 285 return address286 287 @classmethod289 ''' 290 Returns the host name used in a url 291 292 @return: host or None if url is invalid 293 @rtype: C{str} 294 ''' 295 if url is None: 296 return None 297 from urlparse import urlparse 298 o = urlparse(url) 299 return o.hostname
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Mon Oct 6 11:14:58 2014 | http://epydoc.sourceforge.net |