6 Copyright (C) 2009-2010 8 RT-Synthesis Research Group 9 Intelligent Systems Research Institute, 10 National Institute of Advanced Industrial Science and Technology (AIST), 13 Licensed under the Eclipse Public License -v 1.0 (EPL) 14 http://www.opensource.org/licenses/eclipse-1.0.txt 18 Object representing a component's execution context. 22 __version__ =
'$Revision: $' 26 from rtsprofile
import RTS_NS, RTS_NS_S, RTS_EXT_NS, RTS_EXT_NS_S, \
30 indent_string, parse_properties_xml, \
31 properties_to_xml, validate_attribute
38 '''Represents an execution context being used in the RT system.''' 43 @param id The ID of this execution context. 45 @param kind The action execution type used by this context. 47 @param rate The execution rate of this context, if it is periodic. 52 expected_type=[str, unicode], required=
False)
55 expected_type=[str, unicode], required=
False)
58 expected_type=[int, float], required=
False)
64 result =
'ID: {0}\nKind: {1}\nRate: {2}\n'.format(self.
id, self.
kind,
67 result +=
'Participants:\n' 69 result +=
'{0}\n'.format(indent_str(str(p)))
71 result +=
'Properties:\n' 73 result +=
' {0}: {1}\n'.format(p, self.
properties[p])
78 '''The ID used to identify this execution context.''' 84 expected_type=[str, unicode], required=
True)
89 '''The action execution type used by this context. 91 Valid values are supposed to be in the specification appendix, but they 92 aren't. The best way to find them is to create a system with 93 RTSystemEditor and look at the XML. A common valid value is 94 PeriodicExecutionContext. 102 expected_type=[str, unicode], required=
True)
107 '''The components participating in this execution context. 109 An ordered list. May be an empty list if no components are 110 participating in this context. 118 expected_type = list)
123 '''The execution rate of this context, if it has one, in Hertz. 125 This value is only used if the execution context is periodic for a data 134 expected_type=[int, float], required=
False)
139 '''Miscellaneous properties. 141 Stores key/value pair properties. 143 Part of the extended profile. 151 expected_type=dict, required=
False)
155 '''Parse an xml.dom Node object representing an execution context into 159 self.
id = node.getAttributeNS(RTS_NS,
'id')
160 self.
kind = node.getAttributeNS(RTS_NS,
'kind')
161 if node.hasAttributeNS(RTS_NS,
'rate'):
162 self.
rate = float(node.getAttributeNS(RTS_NS,
'rate'))
166 for c
in node.getElementsByTagNameNS(RTS_NS,
'Participants'):
169 local_name=
'Properties'):
175 '''Parse a YAML spefication of an execution context into this 180 self.
kind = y[
'kind']
182 self.
rate = float(y[
'rate'])
186 if 'participants' in y:
187 for p
in y.get(
'participants'):
188 self._participants.append(TargetComponent().
parse_yaml(p))
189 if RTS_EXT_NS_YAML +
'properties' in y:
190 for p
in y.get(RTS_EXT_NS_YAML +
'properties'):
199 '''Save this execution context into an xml.dom.Element object.''' 200 element.setAttributeNS(RTS_NS, RTS_NS_S +
'id', self.
id)
201 element.setAttributeNS(RTS_NS, RTS_NS_S +
'kind', self.
kind)
202 element.setAttributeNS(RTS_NS, RTS_NS_S +
'rate', str(self.
rate))
204 new_element = doc.createElementNS(RTS_NS,
205 RTS_NS_S +
'Participants')
206 p.save_xml(doc, new_element)
207 element.appendChild(new_element)
209 new_prop_element = doc.createElementNS(RTS_EXT_NS,
210 RTS_EXT_NS_S +
'Properties')
212 element.appendChild(new_prop_element)
215 '''Save this execution context into a dictionary.''' 219 d[
'rate'] = self.
rate 222 participants.append(p.to_dict())
224 d[
'participants'] = participants
232 d[RTS_EXT_NS_YAML +
'properties'] = props
def parse_xml_node(self, node)
def save_xml(self, doc, element)
def properties_to_xml(element, name, value=None)
def parse_properties_xml(node)
def validate_attribute(attr, name, expected_type=None, required=False)
def get_direct_child_elements_xml(node, prefix=None, local_name=None)
def __init__(self, id='', kind='', rate=0.0)