Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
af3
AF3
Commits
45882248
Commit
45882248
authored
Jan 26, 2018
by
Simon Barner
Browse files
- Adjust TaskArchitecture transformIntoTaskArchitecture(Component) to updated Task metamodel.
refs 3067
parent
8709250f
Changes
3
Hide whitespace changes
Inline
Side-by-side
org.fortiss.af3.task/trunk/src/org/fortiss/af3/task/util/.ratings
View file @
45882248
TaskAllocationUtils.java a656e4c8082afce931f3e10b2a2afe4c887c893f YELLOW
TaskArchitectureUtils.java
5
a1e
a75ff7dac29a26237ff85d9d6eddfc8b8de2 RED
TaskArchitectureUtils.java a1e
124025794234ee09e3e91829432731a6afc77 YELLOW
TaskModelElementFactory.java 918d64692e3c29550d5b4d67bbd8b8f620e72296 RED
org.fortiss.af3.task/trunk/src/org/fortiss/af3/task/util/TaskArchitectureUtils.java
View file @
45882248
...
...
@@ -15,25 +15,42 @@
+--------------------------------------------------------------------------*/
package
org.fortiss.af3.task.util
;
import
static
org
.
fortiss
.
af3
.
allocation
.
utils
.
AllocationUtils
.
addAllocationEntry
;
import
static
org
.
fortiss
.
af3
.
allocation
.
utils
.
AllocationUtils
.
getOrCreateAllocationTable
;
import
static
org
.
fortiss
.
af3
.
component
.
utils
.
ComponentArchitectureUtils
.
isAtomicComponent
;
import
static
org
.
fortiss
.
af3
.
component
.
utils
.
ComponentUtils
.
getAllSubComponentsRecursively
;
import
static
org
.
fortiss
.
af3
.
task
.
util
.
TaskAllocationUtils
.
getAllocatedComponentsTo
;
import
static
org
.
fortiss
.
af3
.
task
.
util
.
TaskModelElementFactory
.
createSignal
;
import
static
org
.
fortiss
.
af3
.
task
.
util
.
TaskModelElementFactory
.
createTask
;
import
static
org
.
fortiss
.
af3
.
task
.
util
.
TaskModelElementFactory
.
createTaskArchitecture
;
import
static
org
.
fortiss
.
af3
.
task
.
util
.
TaskModelElementFactory
.
createTaskSamplingInputPort
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
KernelModelElementUtils
.
computeFullyQualifiedName
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
KernelModelElementUtils
.
getParentElement
;
import
static
org
.
fortiss
.
tooling
.
kernel
.
utils
.
UniqueIDUtils
.
fixMissingIDs
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.
Optional
;
import
java.util.
stream.Collectors
;
import
org.eclipse.emf.common.util.EList
;
import
org.fortiss.af3.component.model.Channel
;
import
org.fortiss.af3.component.model.Component
;
import
org.fortiss.af3.component.model.ComponentArchitecture
;
import
org.fortiss.af3.component.model.InputPort
;
import
org.fortiss.af3.component.model.OutputPort
;
import
org.fortiss.af3.component.model.Port
;
import
org.fortiss.af3.task.model.InputSignalPort
;
import
org.fortiss.af3.task.model.OutputSignalPort
;
import
org.fortiss.af3.task.model.TaskPort
;
import
org.fortiss.af3.task.model.Signal
;
import
org.fortiss.af3.task.model.Task
;
import
org.fortiss.af3.task.model.TaskAllocation
;
import
org.fortiss.af3.task.model.TaskArchitecture
;
import
org.fortiss.tooling.base.model.element.IConnector
;
import
org.fortiss.af3.task.model.TaskInputPort
;
import
org.fortiss.af3.task.model.TaskOutputPort
;
import
org.fortiss.af3.task.model.TaskSamplingInputPort
;
import
org.fortiss.af3.task.model.TaskSamplingOutputPort
;
import
org.fortiss.af3.task.model.allocation.ComponentToTaskAllocationEntry
;
import
org.fortiss.af3.task.model.allocation.ComponentToTaskAllocationTable
;
import
org.fortiss.af3.task.model.allocation.InputPortToTaskInputPortAllocationEntry
;
import
org.fortiss.af3.task.model.allocation.OutputPortToTaskOutputPortAllocationEntry
;
/**
* Utility methods for handling {@link TaskArchitecture}s and its sub elements.
...
...
@@ -84,134 +101,95 @@ public class TaskArchitectureUtils {
return
result
;
}
/** Unicode left arrow. */
private
static
final
String
LEFT_ARROW
=
"\u2192"
;
/** Transforms the atomic children of the given component into a task graph. */
public
static
TaskArchitecture
transformIntoTaskArchitecture
(
Component
topLevelComponent
)
{
// // take all atomic subcomponents
// TaskArchitecture taskArchitecture =
// TaskModelElementFactory.createTaskArchitecture("TA_" + topLevelComponent.getName());
// List<Component> components =
// (ComponentUtils.getAllSubComponentsRecursively(topLevelComponent)).stream()
// .filter(c -> isAtomicComponent(c)).collect(Collectors.toList());
// List<Task> tasks = new ArrayList<>();
// List<TaskAllocation> taskAllocations = new ArrayList<>();
// for(Component c : components) {
// Task task = TaskModelElementFactory.createTask("Task_" + c.getName());
// for(InputPort in : c.getInputPorts()) {
// InputSignalPort inSignal =
// TaskModelElementFactory.createInputSignalPort(in.getName());
// inSignal.setInputPortReference(in);
// task.getConnectors().add(inSignal);
// }
// for(OutputPort out : c.getOutputPorts()) {
// OutputSignalPort outSignal =
// TaskModelElementFactory.createOutputSignalPort(out.getName());
// outSignal.setOutputPortReference(out);
// task.getConnectors().add(outSignal);
// }
// taskAllocations.add(TaskModelElementFactory.createTaskAllocation(taskArchitecture,
// task, c));
// tasks.add(task);
// taskArchitecture.getContainedElements().add(task);
// }
// for(Component sink : components) {
// for(InputPort in : sink.getInputPorts()) {
// if(in.getIncomingChannels().isEmpty()) {
// continue;
// }
//
// List<Channel> channels = new ArrayList<>();
// // an input port can only have one incoming channel
// Channel channel = in.getIncomingChannels().get(0);
// Component src = channel.getSource().getComponent();
// channels.add(channel);
// while(!isAtomicComponent(src)) {
// final EList<Channel> incomingChannels =
// channel.getSource().getIncomingChannels();
// if(incomingChannels.isEmpty()) {
// // ignore. there is no signal in the task architecture to be created
// src = null;
// break;
// }
// // an input port can only have one incoming channel
// channel = incomingChannels.get(0);
// src = channel.getSource().getComponent();
// channels.add(channel);
// }
// if(src != null && components.contains(src)) {
// Task srcTask = getTask(taskAllocations, src);
// SignalPort srcPort = getSignalPort(srcTask, channel.getSource());
// Task sinkTask = getTask(taskAllocations, sink);
// SignalPort sinkPort = getSignalPort(sinkTask, in);
// Signal signal =
// TaskModelElementFactory.createSignal((OutputSignalPort)srcPort,
// (InputSignalPort)sinkPort);
// signal.setName("Signal_" + srcTask.getName() + "->" + sinkTask.getName());
// taskArchitecture.getConnections().add(signal);
// Collections.reverse(channels);
// TransmissionUnitBandwidth annotation;
// try {
// annotation =
// AnnotationUtils.getAnnotation(channel.getSource(),
// TransmissionUnitBandwidth.class);
// } catch(NullPointerException e) {
// // catch nullpointer due to modelContext which is null; happens in the case
// // of test execution
// annotation = null;
// }
// if(annotation != null) {
// // Take the bandwidth of the last channel and use it for the signal. If the
// // connection goes through hierarchies, the bandwidth should always be the
// // same for every channel.
// TransmissionUnitBandwidth bandwidth =
// AF3TimingAnnotationFactory.eINSTANCE
// .createTransmissionUnitBandwidth();
// bandwidth.setBandwidth_MBytesPerSecond(annotation
// .getBandwidth_MBytesPerSecond());
// signal.getSpecifications().add(bandwidth);
// }
//
// TaskModelElementFactory.createSignalAllocation(taskArchitecture, signal,
// channels);
// }
// }
// }
//
// ComponentArchitecture ca =
// EcoreUtils.getFirstParentWithType(topLevelComponent, ComponentArchitecture.class);
// taskArchitecture.setComponentArchitectureReference(ca);
// UniqueIDUtils.prepareUniqueID(taskArchitecture, ca);
// TreeIterator<EObject> eAllContents = taskArchitecture.eAllContents();
// while(eAllContents.hasNext()) {
// EObject next = eAllContents.next();
// if(next instanceof IIdLabeled) {
// UniqueIDUtils.prepareUniqueID(next, ca);
// }
// }
// return taskArchitecture;
return
null
;
}
TaskArchitecture
taskArchitecture
=
createTaskArchitecture
(
"Task Architecture (generated for: "
+
topLevelComponent
.
getName
()
+
")"
);
/** Returns the {@link TaskPort} for the given (Component) {@link Port} reference. */
public
static
TaskPort
getSignalPort
(
Task
task
,
Port
port
)
{
for
(
IConnector
p
:
task
.
getConnectors
())
{
if
(
p
instanceof
InputSignalPort
)
{
if
(((
InputSignalPort
)
p
).
getInputPortReference
().
equals
(
port
))
{
return
(
TaskPort
)
p
;
}
// All atomic subcomponents
List
<
Component
>
components
=
(
getAllSubComponentsRecursively
(
topLevelComponent
)).
stream
()
.
filter
(
c
->
isAtomicComponent
(
c
)).
collect
(
Collectors
.
toList
());
ComponentArchitecture
ca
=
getParentElement
(
topLevelComponent
,
ComponentArchitecture
.
class
,
false
);
ComponentToTaskAllocationTable
ca2ta
=
getOrCreateAllocationTable
(
ComponentToTaskAllocationTable
.
class
,
ca
,
null
,
ca
.
getTopComponent
().
getName
()
+
LEFT_ARROW
+
taskArchitecture
.
getName
());
// Create Tasks (including ports)
for
(
Component
comp
:
components
)
{
Task
task
=
createTask
(
"Task_"
+
comp
.
getName
());
addAllocationEntry
(
ca2ta
,
ComponentToTaskAllocationEntry
.
class
,
comp
,
task
);
for
(
InputPort
inputPort
:
comp
.
getInputPorts
())
{
TaskSamplingInputPort
taskInputPort
=
createTaskSamplingInputPort
(
inputPort
.
getName
());
addAllocationEntry
(
ca2ta
,
InputPortToTaskInputPortAllocationEntry
.
class
,
inputPort
,
taskInputPort
);
task
.
getConnectors
().
add
(
taskInputPort
);
}
for
(
OutputPort
outputPort
:
comp
.
getOutputPorts
())
{
TaskSamplingOutputPort
taskOutputPort
=
TaskModelElementFactory
.
createTaskSamplingOutputPort
(
outputPort
.
getName
());
addAllocationEntry
(
ca2ta
,
OutputPortToTaskOutputPortAllocationEntry
.
class
,
outputPort
,
taskOutputPort
);
task
.
getConnectors
().
add
(
taskOutputPort
);
}
if
(
p
instanceof
OutputSignalPort
)
{
if
(((
OutputSignalPort
)
p
).
getOutputPortReference
().
equals
(
port
))
{
return
(
TaskPort
)
p
;
taskArchitecture
.
getContainedElements
().
add
(
task
);
}
for
(
Component
targetComp
:
components
)
{
for
(
InputPort
inputPort
:
targetComp
.
getInputPorts
())
{
if
(
inputPort
.
getIncomingChannels
().
isEmpty
())
{
continue
;
}
// An input port can only have one incoming channel
Channel
channel
=
inputPort
.
getIncomingChannels
().
get
(
0
);
Component
sourceComp
=
channel
.
getSource
().
getComponent
();
while
(!
isAtomicComponent
(
sourceComp
))
{
EList
<
Channel
>
incomingChannels
=
channel
.
getSource
().
getIncomingChannels
();
if
(
incomingChannels
.
isEmpty
())
{
// Ignore: there is no signal in the task architecture to be created.
sourceComp
=
null
;
break
;
}
// an input port can only have one incoming channel
channel
=
incomingChannels
.
get
(
0
);
sourceComp
=
channel
.
getSource
().
getComponent
();
}
if
(
sourceComp
!=
null
&&
components
.
contains
(
sourceComp
))
{
Task
sourceTask
=
getTask
(
ca2ta
,
sourceComp
);
TaskOutputPort
taskOutputPort
=
ca2ta
.
getTaskOutputPort
((
OutputPort
)
channel
.
getSource
());
Task
targetTask
=
getTask
(
ca2ta
,
targetComp
);
TaskInputPort
taskInputPort
=
ca2ta
.
getTaskInputPort
(
inputPort
);
String
signalName
=
"Signal "
+
sourceTask
.
getName
()
+
LEFT_ARROW
+
targetTask
.
getName
();
Signal
signal
=
createSignal
(
taskOutputPort
,
taskInputPort
,
signalName
);
taskArchitecture
.
getConnections
().
add
(
signal
);
}
}
}
return
null
;
fixMissingIDs
(
taskArchitecture
,
topLevelComponent
);
return
taskArchitecture
;
}
/** Returns the task allocated to the given component. */
public
static
Task
getTask
(
List
<
TaskAllocation
>
taskAllocations
,
Component
src
)
{
Optional
<
TaskAllocation
>
first
=
taskAllocations
.
stream
().
filter
(
ta
->
ta
.
getComponents
().
contains
(
src
)).
findFirst
();
return
first
.
get
().
getTask
();
/** Determines the {@link Task} to which the given {@link Component} is allocated. . */
private
static
Task
getTask
(
ComponentToTaskAllocationTable
ca2ta
,
Component
component
)
{
EList
<
Task
>
tasks
=
ca2ta
.
getTasks
(
component
);
if
(
tasks
.
size
()
!=
1
)
{
throw
new
RuntimeException
(
computeFullyQualifiedName
(
component
)
+
" is not mapped to exactly one Task."
);
}
// There is exactly one task
return
tasks
.
get
(
0
);
}
}
org.fortiss.af3.task/trunk/src/org/fortiss/af3/task/util/TaskModelElementFactory.java
View file @
45882248
...
...
@@ -16,20 +16,21 @@
package
org.fortiss.af3.task.util
;
import
static
org
.
fortiss
.
af3
.
task
.
util
.
TaskAllocationUtils
.
getAllocationOf
;
import
static
org
.
fortiss
.
tooling
.
base
.
utils
.
LayoutModelElementFactory
.
createConnectionLayout
;
import
static
org
.
fortiss
.
tooling
.
base
.
utils
.
LayoutModelElementFactory
.
createConnectorLayout
;
import
java.util.List
;
import
org.fortiss.af3.component.model.Channel
;
import
org.fortiss.af3.component.model.Component
;
import
org.fortiss.af3.task.model.InputSignalPort
;
import
org.fortiss.af3.task.model.OutputSignalPort
;
import
org.fortiss.af3.task.model.Signal
;
import
org.fortiss.af3.task.model.SignalAllocation
;
import
org.fortiss.af3.task.model.Task
;
import
org.fortiss.af3.task.model.TaskAllocation
;
import
org.fortiss.af3.task.model.TaskArchitecture
;
import
org.fortiss.af3.task.model.TaskInputPort
;
import
org.fortiss.af3.task.model.TaskModelFactory
;
import
org.fortiss.af3.task.model.TaskOutputPort
;
import
org.fortiss.af3.task.model.TaskQueuingInputPort
;
import
org.fortiss.af3.task.model.TaskQueuingOutputPort
;
import
org.fortiss.af3.task.model.TaskSamplingInputPort
;
...
...
@@ -62,11 +63,14 @@ public class TaskModelElementFactory {
}
/** Returns a {@link Signal}. */
public
static
Signal
createSignal
(
OutputSignalPort
output
,
InputSignalPort
input
)
{
public
static
Signal
createSignal
(
TaskOutputPort
taskOutputPort
,
TaskInputPort
taskInputPort
,
String
name
)
{
Signal
signal
=
TaskModelFactory
.
eINSTANCE
.
createSignal
();
signal
.
setSource
(
output
);
signal
.
setTarget
(
input
);
LayoutModelElementFactory
.
createConnectionLayout
(
signal
);
signal
.
setSource
(
taskOutputPort
);
signal
.
setTarget
(
taskInputPort
);
createConnectionLayout
(
signal
);
signal
.
setName
(
name
);
return
signal
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment