5 Copyright (C) 2009-2010 7 RT-Synthesis Research Group 8 Intelligent Systems Research Institute, 9 National Institute of Advanced Industrial Science and Technology (AIST), 12 Licensed under the Eclipse Public License -v 1.0 (EPL) 13 http://www.opensource.org/licenses/eclipse-1.0.txt 15 File: data_port_connector.py 17 Objects representing connections between data and service ports. 21 __version__ =
'$Revision: $' 25 from rtsprofile
import RTS_NS, RTS_NS_S, RTS_EXT_NS, RTS_EXT_NS_S, \
28 InvalidServicePortConnectorNodeError
31 indent_string, parse_properties_xml, \
32 properties_to_xml, validate_attribute
39 '''Represents a connection between data ports.''' 41 def __init__(self, connector_id='', name='', data_type='',
42 interface_type=
'', data_flow_type=
'', subscription_type=
'',
43 push_interval=0.0, source_data_port=
TargetPort(),
44 target_data_port=
TargetPort(), comment=
'', visible=
True):
47 @param connector_id ID of the connector. 48 @type connector_id str 49 @param name Name of the connector. 51 @param data_type Data type that this connector transports. 53 @param interface_type Interface type of the connected ports. 54 @type interface_type str 55 @param data_flow_type Type of data flow between the ports. 56 @type data_flow_type str 57 @param subscription_type Type of subscription between the ports. 58 @type subscription_type str 59 @param push_interval Rate at which data is sent between the ports. 60 @type push_interval float 61 @param source_data_port The source port in the connection. 62 @type source_data_port TargetPort 63 @param target_data_port The target port in the connection. 64 @type target_data_port TargetPort 65 @param comment A comment about the port connector. 67 @param visible If this connector is visible in graphical displays. 72 expected_type=[str, unicode], required=
False)
75 expected_type=[str, unicode], required=
False)
78 expected_type=[str, unicode], required=
False)
81 expected_type=[str, unicode], required=
False)
84 expected_type=[str, unicode], required=
False)
87 'dataport_connector.subscriptionType',
88 expected_type=[str, unicode], required=
False)
91 expected_type=[int, float], required=
False)
94 'dataport_connector.sourceDataPort',
95 expected_type=TargetPort, required=
False)
98 'dataport_connector.targetDataPort',
99 expected_type=TargetPort, required=
False)
102 expected_type=[str, unicode], required=
False)
105 expected_type=bool, required=
False)
110 result =
'Name: {1}\n Connector ID: {0}\n Data type: {2}\n \ 111 Interface type: {3}\n Data flow type: {4}\n Subscription type: {5}\n Push \ 112 interval: {6}\n Source data port:\n{7}\n Target data port:\n{8}\n'.format(\
118 result +=
'Comment: {0}\n'.format(self.
comment)
119 result +=
'Visible: {0}\n'.format(self.
visible)
121 result +=
'Properties:\n' 123 result +=
' {0}: {1}\n'.format(p, self.
properties[p])
128 '''The ID of the connector used to distinguish it in the RT system.''' 134 expected_type=[str, unicode], required=
True)
139 '''The name of the connector.''' 145 expected_type=[str, unicode], required=
True)
150 '''Data type that this connector transports.''' 156 expected_type=[str, unicode], required=
True)
161 '''Interface type of the connection. 163 As specified when the RT system is created. Dependent on what the RT 164 Middleware used to execute the RT system supports. 169 @interface_type.setter
172 expected_type=[str, unicode], required=
True)
177 '''Type of data flow between the ports. 179 As specified when the RT system is created. Dependent on what the RT 180 Middleware used to execute the RT system supports. 185 @data_flow_type.setter
188 expected_type=[str, unicode], required=
True)
193 '''Type of the subscription between the ports. 195 As specified when the RT system is created. Only used when @ref 196 data_flow_type is set to PUSH. Dependent on what the RT Middleware used 197 to execute the RT system supports. 202 @subscription_type.setter
205 'dataport_connector.subscriptionType',
206 expected_type=[str, unicode], required=
False)
211 '''Rate at which data is sent between ports. 213 As specified when the RT system is created. 218 @push_interval.setter
221 expected_type=[int, float], required=
False)
226 '''The source port in the connection.''' 229 @source_data_port.setter
232 'dataport_connector.sourceDataPort',
233 expected_type=TargetPort, required=
True)
238 '''The target port in the connection.''' 241 @target_data_port.setter
244 'dataport_connector.targetDataPort',
245 expected_type=TargetPort, required=
True)
250 '''Comment about the connector. 252 A brief comment about the connector. May or may not be displayed in 253 other tools. May be empty. 255 Part of the extended profile. 263 expected_type=[str, unicode], required=
False)
268 '''Display the connector in graphical tools. 270 This value controls whether graphical tools will display this connector 273 Part of the extended profile. 281 expected_type=bool, required=
False)
286 '''Miscellaneous properties. 288 Stores key/value pair properties. 290 Part of the extended profile. 298 expected_type=dict, required=
False)
302 '''Parse an xml.dom Node object representing a data connector into this 307 self.
name = node.getAttributeNS(RTS_NS,
'name')
308 self.
data_type = node.getAttributeNS(RTS_NS,
'dataType')
311 if node.hasAttributeNS(RTS_NS,
'subscriptionType'):
316 if node.hasAttributeNS(RTS_NS,
'pushInterval'):
321 self.
comment = node.getAttributeNS(RTS_EXT_NS,
'comment')
322 if node.hasAttributeNS(RTS_EXT_NS,
'visible'):
323 visible = node.getAttributeNS(RTS_EXT_NS,
'visible')
324 if visible ==
'true' or visible ==
'1':
329 if node.getElementsByTagNameNS(RTS_NS,
'sourceDataPort').length != 1:
330 raise InvalidDataPortConnectorNodeError
332 node.getElementsByTagNameNS(RTS_NS,
'sourceDataPort')[0])
333 if node.getElementsByTagNameNS(RTS_NS,
'targetDataPort').length != 1:
334 raise InvalidDataPortConnectorNodeError
336 node.getElementsByTagNameNS(RTS_NS,
'targetDataPort')[0])
338 local_name=
'Properties'):
344 '''Parse a YAML specification of a data port connector into this 349 self.
name = y[
'name']
353 if 'subscriptionType' in y:
357 if 'pushInterval' in y:
361 if RTS_EXT_NS_YAML +
'comment' in y:
362 self.
comment = y[RTS_EXT_NS_YAML +
'comment']
366 if RTS_EXT_NS_YAML +
'visible' in y:
367 visible = y[RTS_EXT_NS_YAML +
'visible']
368 if visible ==
'true' or visible ==
'1':
370 if not 'sourceDataPort' in y:
371 raise InvalidDataPortConnectorNodeError
374 if not 'targetDataPort' in y:
375 raise InvalidDataPortConnectorNodeError
378 if RTS_EXT_NS_YAML +
'properties' in y:
379 for p
in y[RTS_EXT_NS_YAML +
'properties']:
388 '''Save this data port into an xml.dom.Element object.''' 389 element.setAttributeNS(RTS_NS, RTS_NS_S +
'connectorId',
391 element.setAttributeNS(RTS_NS, RTS_NS_S +
'name', self.
name)
392 element.setAttributeNS(RTS_NS, RTS_NS_S +
'dataType', self.
data_type)
393 element.setAttributeNS(RTS_NS, RTS_NS_S +
'interfaceType',
395 element.setAttributeNS(RTS_NS, RTS_NS_S +
'dataflowType',
398 element.setAttributeNS(RTS_NS, RTS_NS_S +
'subscriptionType',
400 element.setAttributeNS(RTS_NS, RTS_NS_S +
'pushInterval',
403 element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S +
'comment',
405 element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S +
'visible',
407 new_element = doc.createElementNS(RTS_NS, RTS_NS_S +
'sourceDataPort')
408 self.source_data_port.save_xml(doc, new_element)
409 element.appendChild(new_element)
410 new_element = doc.createElementNS(RTS_NS, RTS_NS_S +
'targetDataPort')
411 self.target_data_port.save_xml(doc, new_element)
412 element.appendChild(new_element)
414 new_prop_element = doc.createElementNS(RTS_EXT_NS,
415 RTS_EXT_NS +
'Properties')
417 element.appendChild(new_prop_element)
420 '''Save this data port connector into a dictionary.''' 426 RTS_EXT_NS_YAML +
'visible': str(self.
visible).lower(),
427 'sourceDataPort': self.source_data_port.to_dict(),
428 'targetDataPort': self.target_data_port.to_dict()}
434 d[RTS_EXT_NS_YAML +
'comment'] = self.
comment 442 d[RTS_EXT_NS_YAML +
'properties'] = props
450 '''Represents a connection between service ports.''' 452 def __init__(self, connector_id='', name='', trans_method='',
457 @param connector_id ID of the connector. 458 @type connector_id str 459 @param name Name of the connector. 461 @param trans_method Transport method used by the ports. 462 @type trans_method str 463 @param source_service_port The source port in the connection. 464 @type source_service_port TargetPort 465 @param target_service_port The target port in the connection. 466 @type target_service_port TargetPort 467 @param comment A comment about the port connector. 469 @param visible If this connector is visible in graphical displays. 474 expected_type=[str, unicode], required=
False)
477 expected_type=[str, unicode], required=
False)
480 expected_type=[str, unicode], required=
False)
483 'serviceport_connector.sourceServicePort',
484 expected_type=TargetPort, required=
True)
487 'serviceport_connector.targetServicePort',
488 expected_type=TargetPort, required=
True)
491 expected_type=[str, unicode], required=
False)
494 expected_type=bool, required=
False)
500 result =
'Name: {1}\n Connector ID: {0}\n Trans method: {2}\n \ 501 Source data port:\n{3}\n Target data port:\n{4}'.format(self.
connector_id,
506 result +=
'Comment: {0}\n'.format(self.
comment)
507 result +=
'Visible: {0}\n'.format(self.
visible)
509 result +=
'Properties:\n' 511 result +=
' {0}: {1}\n'.format(p, self.
properties[p])
516 '''The ID of the connector used to distinguish it in the RT system.''' 522 expected_type=[str, unicode], required=
True)
527 '''The name of the connector.''' 533 expected_type=[str, unicode], required=
True)
538 '''Transport method used by the ports. 540 As specified when the RT system is created. Dependent on what the RT 541 Middleware used to execute the RT system supports. 549 expected_type=[str, unicode], required=
False)
554 '''The source port in the connection.''' 557 @source_service_port.setter
560 'serviceport_connector.sourceServicePort',
561 expected_type=TargetPort, required=
True)
566 '''The target port in the connection.''' 569 @target_service_port.setter
572 'serviceport_connector.targetServicePort',
573 expected_type=TargetPort, required=
True)
578 '''Comment about the connector. 580 A brief comment about the connector. May or may not be displayed in 581 other tools. May be empty. 583 Part of the extended profile. 591 expected_type=[str, unicode], required=
False)
596 '''Display the connector in graphical tools. 598 This value controls whether graphical tools will display this connector 601 Part of the extended profile. 609 expected_type=bool, required=
False)
614 '''Miscellaneous properties. 616 Stores key/value pair properties. 618 Part of the extended profile. 626 expected_type=dict, required=
False)
630 '''Parse an xml.dom Node object representing a service port connector into 635 self.
name = node.getAttributeNS(RTS_NS,
'name')
636 if node.hasAttributeNS(RTS_NS,
'transMethod'):
641 self.
comment = node.getAttributeNS(RTS_EXT_NS,
'comment')
642 if node.hasAttributeNS(RTS_EXT_NS,
'visible'):
643 visible = node.getAttributeNS(RTS_EXT_NS,
'visible')
644 if visible ==
'true' or visible ==
'1':
649 if node.getElementsByTagNameNS(RTS_NS,
'sourceServicePort').length != 1:
650 raise InvalidServicePortConnectorNodeError
652 node.getElementsByTagNameNS(RTS_NS,
'sourceServicePort')[0])
653 if node.getElementsByTagNameNS(RTS_NS,
'targetServicePort').length != 1:
654 raise InvalidServicePortConnectorNodeError
656 node.getElementsByTagNameNS(RTS_NS,
'targetServicePort')[0])
658 local_name=
'Properties'):
664 '''Parse a YAML specification of a service port connector into this 669 self.
name = y[
'name']
670 if 'transMethod' in y:
674 if RTS_EXT_NS_YAML +
'comment' in y:
675 self.
comment = y[RTS_EXT_NS_YAML +
'comment']
679 if RTS_EXT_NS_YAML +
'visible' in y:
680 visible = y[RTS_EXT_NS_YAML +
'visible']
681 if visible ==
'true' or visible ==
'1':
683 if 'sourceServicePort' not in y:
684 raise InvalidServicePortConnectorNodeError
687 if 'targetServicePort' not in y:
688 raise InvalidServicePortConnectorNodeError
691 if RTS_EXT_NS_YAML +
'properties' in y:
692 for p
in y[RTS_EXT_NS_YAML +
'properties']:
701 '''Save this service port into an xml.dom.Element object.''' 702 element.setAttributeNS(RTS_NS, RTS_NS_S +
'connectorId',
704 element.setAttributeNS(RTS_NS, RTS_NS_S +
'name', self.
name)
706 element.setAttributeNS(RTS_NS, RTS_NS_S +
'transMethod',
709 element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S +
'comment',
711 element.setAttributeNS(RTS_EXT_NS, RTS_EXT_NS_S +
'visible',
713 new_element = doc.createElementNS(RTS_NS,
714 RTS_NS_S +
'sourceServicePort')
715 self.source_service_port.save_xml(doc, new_element)
716 element.appendChild(new_element)
717 new_element = doc.createElementNS(RTS_NS,
718 RTS_NS_S +
'targetServicePort')
719 self.target_service_port.save_xml(doc, new_element)
720 element.appendChild(new_element)
722 new_prop_element = doc.createElementNS(RTS_EXT_NS,
723 RTS_EXT_NS_S +
'Properties')
725 element.appendChild(new_prop_element)
728 '''Save this service port connector into a dictionary.''' 731 RTS_EXT_NS_YAML +
'visible': str(self.
visible).lower(),
732 'sourceServicePort': self.source_service_port.to_dict(),
733 'targetServicePort': self.target_service_port.to_dict()}
737 d[RTS_EXT_NS_YAML +
'comment'] = self.
comment 745 d[RTS_EXT_NS_YAML +
'properties'] = props
def save_xml(self, doc, element)
def __init__(self, connector_id='', name='', data_type='', interface_type='', data_flow_type='', subscription_type='', push_interval=0.0, source_data_port=TargetPort(), target_data_port=TargetPort(), comment='', visible=True)
def parse_xml_node(self, node)
def parse_xml_node(self, node)
def __init__(self, connector_id='', name='', trans_method='', source_service_port=TargetPort(), target_service_port=TargetPort(), comment='', visible=True)
DataPortConnector object.
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)
ServicePortConnector object.
def indent_string(string, num_spaces=2)
def save_xml(self, doc, element)