Skip to content

Commit 150b3f9

Browse files
committed
ComSpec refactoring
Moved ComSpec logic from component to port module Reimplement default ComSpec creation logic
1 parent d062918 commit 150b3f9

9 files changed

+187
-152
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016-2017 Conny Gustafsson
3+
Copyright (c) 2016-2021 Conny Gustafsson
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

autosar/component.py

Lines changed: 10 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ def createProvidePort(self, name, portInterfaceRef, **kwargs):
9090
if portInterface is None:
9191
raise autosar.base.InvalidPortInterfaceRef(portInterfaceRef)
9292
if comspecList is None:
93-
comspecList = self._autoCreateComSpecListFromArgs(ws, portInterface, kwargs)
94-
port = autosar.port.ProvidePort(name, portInterface.ref, comspecList, parent=self)
93+
comspecDict = kwargs if len(kwargs) > 0 else None
94+
port = autosar.port.ProvidePort(name, portInterface.ref, comspecDict, parent=self)
95+
else:
96+
port = autosar.port.ProvidePort(name, portInterface.ref, comspecList, parent=self)
97+
assert(isinstance(port, autosar.port.Port))
9598
self.providePorts.append(port)
9699
return port
97100

@@ -135,8 +138,11 @@ def createRequirePort(self, name, portInterfaceRef, **kwargs):
135138
if portInterface is None:
136139
raise autosar.base.InvalidPortInterfaceRef(portInterfaceRef)
137140
if comspecList is None:
138-
comspecList = self._autoCreateComSpecListFromArgs(ws, portInterface, kwargs)
139-
port = autosar.port.RequirePort(name,portInterface.ref, comspecList, parent=self)
141+
comspecDict = kwargs if len(kwargs) > 0 else None
142+
port = autosar.port.RequirePort(name, portInterface.ref, comspecDict, parent=self)
143+
else:
144+
port = autosar.port.RequirePort(name, portInterface.ref, comspecList, parent=self)
145+
assert(isinstance(port, autosar.port.Port))
140146
self.requirePorts.append(port)
141147
return port
142148

@@ -163,116 +169,6 @@ def mirrorPort(self, otherPort):
163169
"""
164170
self.append(otherPort.mirror())
165171

166-
def _autoCreateComSpecListFromArgs(self, ws, portInterface, kwargs):
167-
"""
168-
Attempts to prepare comspec arguments before calling the Port.createComSpecFromDict method
169-
"""
170-
comspecList = []
171-
if isinstance(portInterface, autosar.portinterface.SenderReceiverInterface):
172-
if len(portInterface.dataElements)==1:
173-
comspec={'dataElement': portInterface.dataElements[0].name}
174-
initValue = kwargs.get('initValue', None)
175-
initValueRef = kwargs.get('initValueRef', None)
176-
queueLength = kwargs.get('queueLength', None)
177-
178-
if initValue is not None:
179-
if initValueRef is not None:
180-
raise ValueError('A port cannot have both initValue and initValueRef set at the same time')
181-
comspec['initValue'] = initValue
182-
if initValueRef is not None:
183-
if initValue is not None:
184-
raise ValueError('A port cannot have both initValue and initValueRef set at the same time')
185-
comspec['initValueRef'] = initValueRef
186-
if queueLength is not None:
187-
comspec['queueLength'] = queueLength
188-
if ws.version >= 4.0:
189-
usesEndToEndProtection = kwargs.get('usesEndToEndProtection', None)
190-
if usesEndToEndProtection is not None:
191-
comspec['usesEndToEndProtection'] = bool(usesEndToEndProtection)
192-
comspecList.append(comspec)
193-
else:
194-
raise RuntimeError("This feature only works when there is exactly one data element in the port interface")
195-
196-
elif isinstance(portInterface,autosar.portinterface.ClientServerInterface):
197-
for operation in portInterface.operations:
198-
comspecList.append({'operation': operation.name})
199-
200-
elif isinstance(portInterface,autosar.portinterface.ParameterInterface):
201-
if len(portInterface.parameters)==1:
202-
initValue = kwargs.get('initValue', None)
203-
comspec={'parameter': portInterface.parameters[0].name}
204-
if initValue is not None:
205-
comspec['initValue'] = initValue
206-
comspecList.append(comspec)
207-
else:
208-
raise RuntimeError("This feature only works when there is exactly one data element in the port interface")
209-
210-
elif isinstance(portInterface,autosar.portinterface.ModeSwitchInterface):
211-
comspec = {}
212-
enhancedMode = kwargs.get('enhancedMode', None)
213-
supportAsync = kwargs.get('supportAsync', None)
214-
queueLength = kwargs.get('queueLength', None)
215-
modeSwitchAckTimeout = kwargs.get('modeSwitchAckTimeout', None)
216-
modeGroup = kwargs.get('modeGroup', None)
217-
if enhancedMode is not None:
218-
comspec['enhancedMode']=enhancedMode
219-
if supportAsync is not None:
220-
comspec['supportAsync']=supportAsync
221-
if queueLength is not None:
222-
comspec['queueLength']=queueLength
223-
if modeSwitchAckTimeout is not None:
224-
comspec['modeSwitchAckTimeout']=modeSwitchAckTimeout
225-
if modeGroup is not None:
226-
comspec['modeGroup']=modeGroup
227-
comspecList.append(comspec)
228-
elif isinstance(portInterface,autosar.portinterface.NvDataInterface):
229-
if len(portInterface.nvDatas)==1:
230-
comspec={'nvData': portInterface.nvDatas[0].name}
231-
initValue = kwargs.get('initValue', None)
232-
initValueRef = kwargs.get('initValueRef', None)
233-
ramBlockInitValue = kwargs.get('ramBlockInitValue', None)
234-
ramBlockInitValueRef = kwargs.get('ramBlockInitValueRef', None)
235-
romBlockInitValue = kwargs.get('romBlockInitValue', None)
236-
romBlockInitValueRef = kwargs.get('romBlockInitValueRef', None)
237-
queueLength = kwargs.get('queueLength', None)
238-
239-
if initValue is not None:
240-
if initValueRef is not None:
241-
raise ValueError('A port cannot have both initValue and initValueRef set at the same time')
242-
comspec['initValue'] = initValue
243-
if initValueRef is not None:
244-
if initValue is not None:
245-
raise ValueError('A port cannot have both initValue and initValueRef set at the same time')
246-
comspec['initValueRef'] = initValueRef
247-
248-
if ramBlockInitValue is not None:
249-
if ramBlockInitValueRef is not None:
250-
raise ValueError('A port cannot have both ramBlockInitValue and ramBlockInitValueRef set at the same time')
251-
comspec['ramBlockInitValue'] = ramBlockInitValue
252-
253-
if ramBlockInitValueRef is not None:
254-
if ramBlockInitValue is not None:
255-
raise ValueError('A port cannot have both ramBlockInitValue and ramBlockInitValueRef set at the same time')
256-
comspec['ramBlockInitValueRef'] = ramBlockInitValueRef
257-
258-
if romBlockInitValue is not None:
259-
if romBlockInitValueRef is not None:
260-
raise ValueError('A port cannot have both romBlockInitValue and romBlockInitValueRef set at the same time')
261-
comspec['romBlockInitValue'] = romBlockInitValue
262-
263-
if romBlockInitValueRef is not None:
264-
if romBlockInitValue is not None:
265-
raise ValueError('A port cannot have both romBlockInitValue and romBlockInitValueRef set at the same time')
266-
comspec['romBlockInitValueRef'] = romBlockInitValueRef
267-
comspecList.append(comspec)
268-
else:
269-
raise RuntimeError("This feature only works when there is exactly one data element in the port interface")
270-
else:
271-
raise NotImplementedError(type(portInterface))
272-
273-
return comspecList if len(comspecList) > 0 else None
274-
275-
276172
class AtomicSoftwareComponent(ComponentType):
277173
"""
278174
base class for ApplicationSoftwareComponent and ComplexDeviceDriverComponent

autosar/parser/component_parser.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ def parseSoftwareComponent(self, xmlRoot, parent=None):
123123
for descriptorXml in xmlElem.findall('./NV-BLOCK-DESCRIPTOR'):
124124
descriptor = self.behavior_parser.parseNvBlockSWCnvBlockDescriptor(descriptorXml, componentType)
125125
componentType.nvBlockDescriptors.append(descriptor)
126+
elif xmlElem.tag == 'CATEGORY':
127+
componentType.category = self.parseTextNode(xmlElem)
126128
else:
127129
print('Unhandled tag: '+xmlElem.tag, file=sys.stderr)
128130
return componentType
@@ -134,7 +136,7 @@ def parseComponentPorts(self, componentType, xmlRoot):
134136
if(xmlPort.tag == "R-PORT-PROTOTYPE"):
135137
portName = xmlPort.find('SHORT-NAME').text
136138
portInterfaceRef = self.parseTextNode(xmlPort.find('REQUIRED-INTERFACE-TREF'))
137-
port = autosar.port.RequirePort(portName,portInterfaceRef,parent=componentType)
139+
port = autosar.port.RequirePort(portName, portInterfaceRef, autoCreateComSpec = False, parent=componentType)
138140
if hasAdminData(xmlPort):
139141
port.adminData=parseAdminDataNode(xmlPort.find('ADMIN-DATA'))
140142
if xmlPort.findall('./REQUIRED-COM-SPECS') is not None:
@@ -178,7 +180,7 @@ def parseComponentPorts(self, componentType, xmlRoot):
178180
elif(xmlPort.tag == 'P-PORT-PROTOTYPE'):
179181
portName = xmlPort.find('SHORT-NAME').text
180182
portInterfaceRef = self.parseTextNode(xmlPort.find('PROVIDED-INTERFACE-TREF'))
181-
port = autosar.port.ProvidePort(portName,portInterfaceRef,parent=componentType)
183+
port = autosar.port.ProvidePort(portName, portInterfaceRef, autoCreateComSpec = False, parent = componentType)
182184
if hasAdminData(xmlPort):
183185
port.adminData=parseAdminDataNode(xmlPort.find('ADMIN-DATA'))
184186
if xmlPort.findall('./PROVIDED-COM-SPECS') is not None:

0 commit comments

Comments
 (0)