Package concert_orchestra :: Module node
[frames] | no frames]

Source Code for Module concert_orchestra.node

 1  #!/usr/bin/env python 
 2  # 
 3  # License: BSD 
 4  #   https://raw.github.com/robotics-in-concert/rocon_concert/hydro-devel/concert_orchestra/LICENSE 
 5  # 
 6  ############################################################################## 
 7  # Imports 
 8  ############################################################################## 
 9   
10  import re 
11  import concert_msgs.msg as concert_msgs 
12   
13  ############################################################################## 
14  # Classes 
15  ############################################################################## 
16   
17   
18 -class Node(object):
19 ''' 20 This represents an implementation rule node currently derived from 21 a ros parameterisation. 22 ''' 23 __slots__ = ['id', 'tuple', 'min', 'max', 'force_name_matching'] 24
25 - def __init__(self, param):
26 # Compulsory parameters - should do some exception checking here 27 self.id = param['id'] 28 self.tuple = param['tuple'] 29 # Optional parameters 30 if not 'min' in param and not 'max' in param: 31 self.min = 1 32 self.max = 1 33 elif not 'min' in param: 34 self.min = 1 35 self.max = param['max'] 36 elif not 'max' in param: 37 self.min = param['min'] 38 self.max = concert_msgs.LinkNode.UNLIMITED_RESOURCE 39 else: 40 self.min = param['min'] 41 self.max = param['max'] 42 self.force_name_matching = True if 'force_name_matching' in param else False
43
44 - def __str__(self):
45 return "%s-%s-%s-%s-%s" % (self.id, self.tuple, str(self.min), str(self.max), self.force_name_matching)
46
47 - def is_singleton(self):
48 return self.min == self.max
49
50 - def is_compatible(self, concert_client):
51 ''' 52 Checks to see if a client is compatible for the implementation's node rule. 53 ''' 54 #print "****** _match ******" 55 #print "%s-%s-%s-%s-%s" % (self.id, self.tuple, str(self.min), str(self.max), self.force_name_matching) 56 #print concert_client.name + "-" + concert_client.platform + "." + concert_client.system + "." + concert_client.robot 57 parts = self.tuple.split('.') 58 platform = parts[0] 59 system = parts[1] 60 robot = parts[2] 61 app_name = parts[3] 62 if platform != '*' and platform != concert_client.platform: 63 return False 64 if system != '*' and system != concert_client.system: 65 return False 66 if robot != '*' and robot != concert_client.robot: 67 return False 68 # Check if we should match name prefixes (i.e. ignore trailing numericals) 69 if self.force_name_matching and not re.match(self.id, re.sub('[0-9]*$', '', concert_client.name)): 70 return False 71 for client_app in concert_client.apps: 72 if app_name == client_app.name: 73 return True 74 return False
75