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 16 File: message_sending.py 18 Objects for the message sending interface. 22 __version__ =
'$Revision: $' 26 from rtsprofile
import RTS_NS, RTS_NS_S, RTS_EXT_NS, RTS_EXT_NS_S, \
31 indent_string, validate_attribute
38 '''Defines the orderings and conditions components in the RT system for 44 '''@param targets Orderings and conditions.''' 46 expected_type=list, required=
False)
50 result = self.__class__.__name__ +
'\n' 52 result +=
'Targets:\n' 59 '''Orderings and conditions.''' 65 expected_type=list, required=
False)
69 '''Parse an xml.dom Node object representing a message sending object 74 for c
in node.getElementsByTagNameNS(RTS_NS,
'targets'):
75 if c.getElementsByTagNameNS(RTS_NS,
'WaitTime'):
77 elif c.getElementsByTagNameNS(RTS_NS,
'Preceding'):
81 new_target.parse_xml_node(c)
82 self._targets.append(new_target)
86 '''Parse a YAML speficication of a message sending object into this 92 for t
in y[
'targets']:
93 if 'waitTime' in t[
'condition']:
95 elif 'preceding' in t[
'condition']:
99 new_target.parse_yaml(t)
100 self._targets.append(new_target)
104 '''Save this message_sending object into an xml.dom.Element object.''' 106 new_element = doc.createElementNS(RTS_NS, RTS_NS_S +
'targets')
107 cond.save_xml(doc, new_element)
108 element.appendChild(new_element)
111 '''Save this message sending object into a dictionary.''' 114 targets.append(cond.to_dict())
116 return {
'targets': targets}
125 '''Specifies the start order and conditions of components when the RT 135 class ShutDown(MessageSending):
136 '''Specifies the stop order and conditions of components when the RT system 147 '''Specifies the activation order and conditions of components when the RT 158 '''Specifies the deactivation order and conditions of components when the RT 159 system is deactivated. 169 '''Specifies the reset order and conditions of components when the RT 180 '''Specifies the initialisation order and conditions of components when the 181 RT system is initialised. 191 '''Specifies the finalisation order and conditions of components when the 192 RT system is finalised. 202 '''Specifies execution orderings and conditions for RT components in the RT 205 Execution conditions can include the time to wait before executing and 206 order of precedence for components. The involved RT component is specified 207 using @ref TargetExecutionContext. 211 def __init__(self, sequence=0, target_component=TargetExecutionContext()):
214 @param sequence Execution order of the target component. 216 @param target_component The target of the condition. 217 @type target_component TargetComponent 220 expected_type=int, required=
False)
223 expected_type=TargetExecutionContext,
229 result =
'Sequence: {0}\nTargetEC:\n{1}\n'.format(self.
sequence,
232 result +=
'Properties:\n' 234 result +=
' {0}: {1}\n'.format(p, self.
properties[p])
239 '''The execution order of the target components for the various 248 expected_type=int, required=
False)
253 '''Target component of the condition.''' 256 @target_component.setter
259 expected_type=TargetExecutionContext,
265 '''Miscellaneous properties. 267 Stores key/value pair properties. 269 Part of the extended profile. 277 expected_type=dict, required=
False)
281 '''Parse an xml.dom Node object representing a condition into this 285 self.
sequence = int(node.getAttributeNS(RTS_NS,
'sequence'))
286 c = node.getElementsByTagNameNS(RTS_NS,
'TargetComponent')
288 raise InvalidParticipantNodeError
291 local_name=
'Properties'):
297 '''Parse a YAML specification of a condition into this object.''' 301 if RTS_EXT_NS_YAML +
'properties' in y:
302 for p
in y.get(RTS_EXT_NS_YAML +
'properties'):
311 '''Save this condition into an xml.dom.Element object.''' 312 element.setAttributeNS(RTS_NS, RTS_NS_S +
'sequence',
314 new_element = doc.createElementNS(RTS_NS, RTS_NS_S +
'TargetComponent')
315 self.target_component.save_xml(doc, new_element)
316 element.appendChild(new_element)
318 new_prop_element = doc.createElementNS(RTS_EXT_NS,
319 RTS_EXT_NS_S +
'Properties')
321 element.appendChild(new_prop_element)
324 '''Save this condition into a dictionary.''' 326 'targetComponent': self.target_component.to_dict()}
334 d[RTS_EXT_NS_YAML +
'properties'] = props
342 '''Specifies that the target RT component should precede other RT 343 components that are part of the same action (e.g. activation) when that 348 def __init__(self, sequence=0, target_component=TargetExecutionContext(),
349 timeout=0, sending_timing=
'', preceding_components=[]):
352 @param sequence Execution order of the target component. 354 @param target_component The target of the condition. 355 @type target_component TargetComponent 356 @param timeout Status check timeout. 358 @param sending_timing Timing for executing actions. 359 @type sending_timing str 360 @param preceding_components Preceding components of the condition. 361 @type preceding components list(TargetExecutionContext) 364 super(Preceding, self).
__init__(sequence, target_component)
366 expected_type=int, required=
False)
369 expected_type=[str, unicode], required=
False)
372 'preceding.PrecedingComponents',
373 expected_type=list, required=
False)
377 result =
'Timeout: {0}\nSending timing: {1}\n{2}'.format(self.
timeout,
381 result +=
'\nPreceding component:\n{0}'.format(\
387 '''Time out for checking if the target component has executed the 390 Can be zero. Specified in milliseconds. 398 expected_type=int, required=
False)
403 '''Timing for executing actions. 405 Either wait for the preceding RT component to finish executing the 406 action (specified by "SYNC"), or execute the action without waiting for 407 the preceding RT component to finish (specified by "ASYNC"). When not 408 specified, the first option will be assumed. 413 @sending_timing.setter
416 expected_type=[str, unicode], required=
False)
421 '''Preceding components of this condition.''' 424 @preceding_components.setter
427 expected_type=list, required=
False)
431 '''Parse an xml.dom Node object representing a preceding condition into 436 p_nodes = node.getElementsByTagNameNS(RTS_NS,
'Preceding')
437 if p_nodes.length != 1:
438 raise InvalidParticipantNodeError
440 if p_node.hasAttributeNS(RTS_NS,
'timeout'):
441 self.
timeout = int(p_node.getAttributeNS(RTS_NS,
'timeout'))
444 if p_node.hasAttributeNS(RTS_NS,
'sendingTiming'):
449 for c
in p_node.getElementsByTagNameNS(RTS_NS,
'PrecedingComponents'):
454 '''Parse a YAML specification of a preceding condition into this 459 c = y[
'condition'][
'preceding']
461 self.
timeout = int(c[
'timeout'])
464 if 'sendingTiming' in c:
469 if 'precedingComponents' in c:
470 for p
in c.get(
'precedingComponents'):
475 '''Save this preceding condition into an xml.dom.Element object.''' 476 super(Preceding, self).
save_xml(doc, element)
477 pre_element = doc.createElementNS(RTS_NS, RTS_NS_S +
'Preceding')
479 pre_element.setAttributeNS(RTS_NS, RTS_NS_S +
'timeout',
482 pre_element.setAttributeNS(RTS_NS, RTS_NS_S +
'sendingTiming',
485 new_element = doc.createElementNS(RTS_NS,
486 RTS_NS_S +
'PrecedingComponents')
487 pc.save_xml(doc, new_element)
488 pre_element.appendChild(new_element)
489 element.appendChild(pre_element)
492 '''Save this preceding condition into a dictionary.''' 493 d = super(Preceding, self).
to_dict()
501 pcs.append(pc.to_dict())
503 e[
'precedingComponents'] = pcs
504 d[
'condition'] = {
'preceding': e}
512 '''Specifies the time to wait before executing the specified action on the 513 target RT component. After the action command is received by the RT 514 component, it will wait the specified length of time before executing it. 518 def __init__(self, wait_time=0, sequence=0,
522 @param sequence Execution order of the target component. 524 @param target_component The target of the condition. 525 @type target_component TargetComponent 526 @param wait_time The length of time to wait, in milliseconds. 530 super(WaitTime, self).
__init__(sequence, target_component)
532 expected_type=int, required=
False)
536 return 'Wait time: {0}\n{1}'.format(self.
wait_time,
537 Condition.__str__(self))
541 '''The length of time to wait before executing the specified action. 551 expected_type=int, required=
False)
555 '''Parse an xml.dom Node object representing a wait_time condition into 560 wait_time_nodes = node.getElementsByTagNameNS(RTS_NS,
'WaitTime')
561 if wait_time_nodes.length != 1:
562 raise InvalidParticipantNodeError
563 self.
wait_time = int(wait_time_nodes[0].getAttributeNS(RTS_NS,
568 '''Parse a YAML specification of a wait_time condition into this 573 self.
wait_time = int(y[
'condition'][
'waitTime'][
'waitTime'])
577 '''Save this wait_time condition into an xml.dom.Element object.''' 578 super(WaitTime, self).
save_xml(doc, element)
579 new_element = doc.createElementNS(RTS_NS, RTS_NS_S +
'WaitTime')
580 new_element.setAttributeNS(RTS_NS, RTS_NS_S +
'waitTime',
582 element.appendChild(new_element)
585 '''Save this wait_time condition into a dictionary.''' 586 d = super(WaitTime, self).
to_dict()
587 d[
'condition'] = {
'waitTime': {
'waitTime': self.
wait_time}}
def save_xml(self, doc, element)
def __init__(self, targets=[])
def preceding_components(self)
MessageSending base object.
def properties_to_xml(element, name, value=None)
def parse_properties_xml(node)
def __init__(self, wait_time=0, sequence=0, target_component=TargetExecutionContext())
def validate_attribute(attr, name, expected_type=None, required=False)
def get_direct_child_elements_xml(node, prefix=None, local_name=None)
def parse_xml_node(self, node)
def save_xml(self, doc, element)
def __init__(self, sequence=0, target_component=TargetExecutionContext(), timeout=0, sending_timing='', preceding_components=[])
def parse_xml_node(self, node)
def save_xml(self, doc, element)
TargetExecutionContext object.
def indent_string(string, num_spaces=2)
def __init__(self, sequence=0, target_component=TargetExecutionContext())
def save_xml(self, doc, element)
def parse_xml_node(self, node)
def parse_xml_node(self, node)