Skip to content

Commit

Permalink
Implement port prototype elements
Browse files Browse the repository at this point in the history
  • Loading branch information
cogu committed Feb 26, 2024
1 parent 9a15a05 commit 80c566b
Show file tree
Hide file tree
Showing 6 changed files with 696 additions and 90 deletions.
43 changes: 23 additions & 20 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,32 @@ Non-collectable elements are various sub-elements to collectable elements.

#### XML - Software component elements

* ClientComSpec
* ModeSwitchedAckRequest
* ModeSwitchReceiverComSpec
* ModeSwitchSenderComSpec
* NonqueuedReceiverComSpec
* NonqueuedSenderComSpec
* NvProvideComSpec
* NvRequireComSpec
* ParameterProvideComSpec
* ParameterRequireComSpec
* QueuedReceiverComSpec
* QueuedSenderComSpec
* ReceptionComSpecProps
* ServerComSpec
* TransmissionAcknowledgementRequest
* TransmissionComSpecProps
* ClientComSpec | CLIENT-COM-SPEC
* ModeSwitchedAckRequest | MODE-SWITCHED-ACK-REQUEST
* ModeSwitchReceiverComSpec | MODE-SWITCH-RECEIVER-COM-SPEC
* ModeSwitchSenderComSpec | MODE-SWITCH-SENDER-COM-SPEC
* NonqueuedReceiverComSpec | NONQUEUED-RECEIVER-COM-SPEC
* NonqueuedSenderComSpec | NONQUEUED-SENDER-COM-SPEC
* NvProvideComSpec | NV-PROVIDE-COM-SPEC
* NvRequireComSpec | NV-REQUIRE-COM-SPEC
* ParameterProvideComSpec | PARAMETER-PROVIDE-COM-SPEC
* ParameterRequireComSpec | PARAMETER-REQUIRE-COM-SPEC
* QueuedReceiverComSpec | QUEUED-RECEIVER-COM-SPEC
* QueuedSenderComSpec | QUEUED-SENDER-COM-SPEC
* ReceptionComSpecProps | RECEPTION-COM-SPEC-PROPS
* ServerComSpec | SERVER-COM-SPEC
* TransmissionAcknowledgementRequest | TRANSMISSION-ACKNOWLEDGEMENT-REQUEST
* TransmissionComSpecProps | TRANSMISSION-COM-SPEC-PROPS
* ProvidePortPrototype | P-PORT-PROTOTYPE
* RequirePortPrototype | R-PORT-PROTOTYPE
* PRPortPrototype | PR-PORT-PROTOTYPE

#### XML - SWC internal behavior elements

* ArVariableInImplementationDataInstanceRef
* AutosarVariableRef
* VariableAccess
* VariableInAtomicSWCTypeInstanceRef
* ArVariableInImplementationDataInstanceRef | AR-VARIABLE-IN-IMPLEMENTATION-DATA-INSTANCE-REF
* AutosarVariableRef | AUTOSAR-VARIABLE-REF
* VariableAccess | VARIABLE-ACCESS
* VariableInAtomicSWCTypeInstanceRef | VARIABLE-IN-ATOMIC-SWC-TYPE-INSTANCE-REF

#### XML - Reference elements

Expand Down
137 changes: 133 additions & 4 deletions src/autosar/xml/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,24 @@ def _accepted_subtypes(self) -> set[ar_enum.IdentifiableSubTypes]:
ar_enum.IdentifiableSubTypes.VARIABLE_DATA_PROTOTYPE,
}


class PortInterfaceRef(BaseRef):
"""
References to PORT-INTERFACE--SUBTYPES-ENUM
Only a fraction of elements seen in the XML Schema are
actually supported.
"""

def _accepted_subtypes(self) -> set[ar_enum.IdentifiableSubTypes]:
"""Acceptable values for dest"""
return {ar_enum.IdentifiableSubTypes.CLIENT_SERVER_INTERFACE,
ar_enum.IdentifiableSubTypes.MODE_SWITCH_INTERFACE,
ar_enum.IdentifiableSubTypes.NV_DATA_INTERFACE,
ar_enum.IdentifiableSubTypes.PARAMETER_INTERFACE,
ar_enum.IdentifiableSubTypes.SENDER_RECEIVER_INTERFACE,
}

# --- Documentation Elements


Expand Down Expand Up @@ -4429,16 +4447,127 @@ class PortPrototype(Identifiable):
# .VARIATION-POINT not supported


class AbstractProvidedPortPrototype(PortPrototype):
class ProvidePortPrototype(PortPrototype):
"""
Group AR:ABSTRACT-PROVIDED-PORT-PROTOTYPE
Complex type AR:P-PORT-PROTOTYPE
Tag variants: 'P-PORT-PROTOTYPE'
Includes AR:ABSTRACT-PROVIDED-PORT-PROTOTYPE
"""

def __init__(self, name: str,
def __init__(self,
name: str,
port_interface_ref: PortInterfaceRef | None = None,
com_spec: ProvidePortComSpec | list[ProvidePortComSpec] | None = None,
**kwargs) -> None:
super().__init__(name, **kwargs)
# .FIELD-SENDER-COM-SPEC not supported
self.com_spec: list[ProvidePortComSpec] = [] # .PROVIDED-COM-SPECS
self.port_interface_ref: PortInterfaceRef | None = None # .PROVIDED-INTERFACE-TREF
self._assign_optional_strict("port_interface_ref", port_interface_ref, PortInterfaceRef)
if com_spec is not None:
if isinstance(com_spec, ProvidePortComSpec):
self.append_com_spec(com_spec)
elif isinstance(com_spec, (list, tuple)):
for com_spec_elem in com_spec:
self.append_com_spec(com_spec_elem)
else:
raise TypeError("com_spec must be of a type derived from ProvidePortComSpec")

def append_com_spec(self, com_spec: ProvidePortComSpec) -> None:
"""
Adds comspec to internal list of com-specs
"""
if isinstance(com_spec, ProvidePortComSpec):
self.com_spec.append(com_spec)
else:
raise TypeError("com_spec must be of a type derived from ProvidePortComSpec")


class RequirePortPrototype(PortPrototype):
"""
Complex type AR:R-PORT-PROTOTYPE
Tag variants: 'R-PORT-PROTOTYPE'
Includes AR:ABSTRACT-REQUIRED-PORT-PROTOTYPE
"""

def __init__(self,
name: str,
port_interface_ref: PortInterfaceRef | None = None,
com_spec: RequirePortComSpec | list[RequirePortComSpec] | None = None,
allow_unconnected: bool | None = None,
**kwargs) -> None:
super().__init__(name, **kwargs)
self.com_spec: list[RequirePortComSpec] = [] # .REQUIRED-COM-SPECS
self.allow_unconnected: bool | None = None # .MAY-BE-UNCONNECTED
self.port_interface_ref: PortInterfaceRef | None = None # .REQUIRED-INTERFACE-TREF
self._assign_optional_strict("port_interface_ref", port_interface_ref, PortInterfaceRef)
self._assign_optional("allow_unconnected", allow_unconnected, bool)
if com_spec is not None:
if isinstance(com_spec, RequirePortComSpec):
self.append_com_spec(com_spec)
elif isinstance(com_spec, (list, tuple)):
for com_spec_elem in com_spec:
self.append_com_spec(com_spec_elem)
else:
raise TypeError("com_spec must be of a type derived from RequirePortComSpec")

def append_com_spec(self, com_spec: RequirePortComSpec) -> None:
"""
Adds comspec to internal list of com-specs
"""
if isinstance(com_spec, RequirePortComSpec):
self.com_spec.append(com_spec)
else:
raise TypeError("com_spec must be of type RequirePortComSpec")


class PRPortPrototype(PortPrototype):
"""
Complex type AR:PR-PORT-PROTOTYPE
Tag variants: 'PR-PORT-PROTOTYPE'
Includes AR:ABSTRACT-PROVIDED-PORT-PROTOTYPE and AR:ABSTRACT-REQUIRED-PORT-PROTOTYPE
"""

def __init__(self,
name: str,
port_interface_ref: PortInterfaceRef | None = None,
provided_com_spec: ProvidePortComSpec | list[ProvidePortComSpec] | None = None,
required_com_spec: RequirePortComSpec | list[RequirePortComSpec] | None = None,
**kwargs) -> None:
super().__init__(name, **kwargs)
self.port_interface_ref: PortInterfaceRef | None = None
self.provided_com_spec: list[ProvidePortComSpec] = []
self.required_com_spec: list[RequirePortComSpec] = []
self._assign_optional_strict("port_interface_ref", port_interface_ref, PortInterfaceRef)
if provided_com_spec is not None:
if isinstance(provided_com_spec, ProvidePortComSpec):
self.append_com_spec(provided_com_spec)
elif isinstance(required_com_spec, (list, tuple)):
for com_spec_elem in provided_com_spec:
self.append_com_spec(com_spec_elem)
else:
raise TypeError("provided_com_spec must be of a type derived from ProvidePortComSpec")
if required_com_spec is not None:
if isinstance(required_com_spec, RequirePortComSpec):
self.append_com_spec(required_com_spec)
elif isinstance(required_com_spec, (list, tuple)):
for com_spec_elem in required_com_spec:
self.append_com_spec(com_spec_elem)
else:
raise TypeError("required_com_spec must be of a type derived from RequirePortComSpec")

def append_com_spec(self, com_spec: ProvidePortComSpec | RequirePortComSpec) -> None:
"""
Append com-spec to internal list(s) of com-specs
"""
if isinstance(com_spec, ProvidePortComSpec):
self.provided_com_spec.append(com_spec)
elif isinstance(com_spec, RequirePortComSpec):
self.required_com_spec.append(com_spec)
else:
raise TypeError("com_spec must be of either type ProvidePortComSpec, RequirePortComSpec")


class SoftwareComponentType(ARElement):
Expand Down
99 changes: 57 additions & 42 deletions src/autosar/xml/enumeration.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,27 +209,32 @@ class IdentifiableSubTypes(Enum):
AUTOSAR_DATA_PROTOTYPE = 15
AUTOSAR_DATA_TYPE = 16
BSW_MODULE_ENTRY = 17
CLIENT_SERVER_OPERATION = 18
COMPU_METHOD = 19
CONSTANT_SPECIFICATION = 20
DATA_CONSTR = 21
DATA_PROTOTYPE = 22
E2E_PROFILE_COMPATIBILITY_PROPS = 23
IMPLEMENTATION_DATA_TYPE = 24
IMPLEMENTATION_DATA_TYPE_ELEMENT = 25
MODE_DECLARATION = 26
MODE_DECLARATION_GROUP = 27
MODE_DECLARATION_GROUP_PROTOTYPE = 28
P_PORT_PROTOTYPE = 29
PARAMETER_DATA_PROTOTYPE = 30
PHYSICAL_DIMENSION = 31
PORT_PROTOTYPE = 32
PR_PORT_PROTOTYPE = 33
R_PORT_PROTOTYPE = 34
SW_ADDR_METHOD = 35
SW_BASE_TYPE = 36
UNIT = 37
VARIABLE_DATA_PROTOTYPE = 38
CLIENT_SERVER_INTERFACE = 18
CLIENT_SERVER_OPERATION = 19
COMPU_METHOD = 20
CONSTANT_SPECIFICATION = 21
DATA_CONSTR = 22
DATA_PROTOTYPE = 23
E2E_PROFILE_COMPATIBILITY_PROPS = 24
IMPLEMENTATION_DATA_TYPE = 25
IMPLEMENTATION_DATA_TYPE_ELEMENT = 26
MODE_DECLARATION = 27
MODE_DECLARATION_GROUP = 28
MODE_DECLARATION_GROUP_PROTOTYPE = 29
MODE_SWITCH_INTERFACE = 30
NV_DATA_INTERFACE = 31
P_PORT_PROTOTYPE = 32
PARAMETER_INTERFACE = 33
PARAMETER_DATA_PROTOTYPE = 34
PHYSICAL_DIMENSION = 35
PORT_PROTOTYPE = 36
PR_PORT_PROTOTYPE = 37
R_PORT_PROTOTYPE = 38
SENDER_RECEIVER_INTERFACE = 39
SW_ADDR_METHOD = 40
SW_BASE_TYPE = 41
UNIT = 42
VARIABLE_DATA_PROTOTYPE = 43


class IntervalType(Enum):
Expand Down Expand Up @@ -700,6 +705,7 @@ class VersionedTextValue:
"AUTOSAR-DATA-PROTOTYPE": IdentifiableSubTypes.AUTOSAR_DATA_PROTOTYPE,
"AUTOSAR-DATA-TYPE": IdentifiableSubTypes.AUTOSAR_DATA_TYPE,
"BSW-MODULE-ENTRY": IdentifiableSubTypes.BSW_MODULE_ENTRY,
"CLIENT-SERVER-INTERFACE": IdentifiableSubTypes.CLIENT_SERVER_INTERFACE,
"CLIENT-SERVER-OPERATION": IdentifiableSubTypes.CLIENT_SERVER_OPERATION,
"COMPU-METHOD": IdentifiableSubTypes.COMPU_METHOD,
"CONSTANT-SPECIFICATION": IdentifiableSubTypes.CONSTANT_SPECIFICATION,
Expand All @@ -710,12 +716,16 @@ class VersionedTextValue:
"MODE-DECLARATION": IdentifiableSubTypes.MODE_DECLARATION,
"MODE-DECLARATION-GROUP": IdentifiableSubTypes.MODE_DECLARATION_GROUP,
"MODE-DECLARATION-GROUP-PROTOTYPE": IdentifiableSubTypes.MODE_DECLARATION_GROUP_PROTOTYPE,
"MODE-SWITCH-INTERFACE": IdentifiableSubTypes.MODE_SWITCH_INTERFACE,
"NV-DATA-INTERFACE": IdentifiableSubTypes.NV_DATA_INTERFACE,
"P-PORT-PROTOTYPE": IdentifiableSubTypes.P_PORT_PROTOTYPE,
"PARAMETER-DATA-PROTOTYPE": IdentifiableSubTypes.PARAMETER_DATA_PROTOTYPE,
"PARAMETER-INTERFACE": IdentifiableSubTypes.PARAMETER_INTERFACE,
"PHYSICAL-DIMENSION": IdentifiableSubTypes.PHYSICAL_DIMENSION,
"PORT-PROTOTYPE": IdentifiableSubTypes.PORT_PROTOTYPE,
"PR-PORT-PROTOTYPE": IdentifiableSubTypes.PR_PORT_PROTOTYPE,
"R-PORT-PROTOTYPE": IdentifiableSubTypes.R_PORT_PROTOTYPE,
"SENDER-RECEIVER-INTERFACE": IdentifiableSubTypes.SENDER_RECEIVER_INTERFACE,
"SW-ADDR-METHOD": IdentifiableSubTypes.SW_ADDR_METHOD,
"SW-BASE-TYPE": IdentifiableSubTypes.SW_BASE_TYPE,
"UNIT": IdentifiableSubTypes.UNIT,
Expand Down Expand Up @@ -1045,27 +1055,32 @@ def xml_to_enum(enum_type_name: str, xml_text: str, schema_version: int = ar_bas
"AUTOSAR-DATA-PROTOTYPE", # 15
"AUTOSAR-DATA-TYPE", # 16
"BSW-MODULE-ENTRY", # 17
"CLIENT-SERVER-OPERATION", # 18
"COMPU-METHOD", # 19
"CONSTANT-SPECIFICATION", # 20
"DATA-CONSTR", # 21
"DATA-PROTOTYPE", # 22
"E-2-E-PROFILE-COMPATIBILITY-PROPS", # 23
"IMPLEMENTATION-DATA-TYPE", # 24
"IMPLEMENTATION-DATA-TYPE-ELEMENT", # 25
"MODE-DECLARATION", # 26
"MODE-DECLARATION-GROUP", # 27
"MODE-DECLARATION-GROUP-PROTOTYPE", # 28
"P-PORT-PROTOTYPE", # 29
"PARAMETER-DATA-PROTOTYPE", # 30
"PHYSICAL-DIMENSION", # 31
"PORT-PROTOTYPE", # 32
"PR-PORT-PROTOTYPE", # 33
"R-PORT-PROTOTYPE", # 34
"SW-ADDR-METHOD", # 35
"SW-BASE-TYPE", # 36
"UNIT", # 37
"VARIABLE-DATA-PROTOTYPE", # 38
"CLIENT-SERVER-INTERFACE", # 18
"CLIENT-SERVER-OPERATION", # 19
"COMPU-METHOD", # 20
"CONSTANT-SPECIFICATION", # 21
"DATA-CONSTR", # 22
"DATA-PROTOTYPE", # 23
"E-2-E-PROFILE-COMPATIBILITY-PROPS", # 24
"IMPLEMENTATION-DATA-TYPE", # 25
"IMPLEMENTATION-DATA-TYPE-ELEMENT", # 26
"MODE-DECLARATION", # 27
"MODE-DECLARATION-GROUP", # 28
"MODE-DECLARATION-GROUP-PROTOTYPE", # 29
"MODE-SWITCH-INTERFACE", # 30
"NV-DATA-INTERFACE", # 31
"P-PORT-PROTOTYPE", # 32
"PARAMETER-INTERFACE", # 33
"PARAMETER-DATA-PROTOTYPE", # 34
"PHYSICAL-DIMENSION", # 35
"PORT-PROTOTYPE", # 36
"PR-PORT-PROTOTYPE", # 37
"R-PORT-PROTOTYPE", # 38
"SENDER-RECEIVER-INTERFACE", # 39
"SW-ADDR-METHOD", # 40
"SW-BASE-TYPE", # 41
"UNIT", # 42
"VARIABLE-DATA-PROTOTYPE", # 43
],
"IntervalType": [
"CLOSED", # 0
Expand Down
Loading

0 comments on commit 80c566b

Please sign in to comment.