From 8f7fd72af3f8fe66cf677ce6d7faba0b246ef85a Mon Sep 17 00:00:00 2001 From: Ludovic Apvrille <ludovic.apvrille@telecom-paristech.fr> Date: Mon, 24 Jan 2011 19:51:48 +0000 Subject: [PATCH] AVATAR simulator :update on main engine + partial management of time --- .../AvatarActionOnSignal.java | 8 + src/avatartranslator/AvatarExpireTimer.java | 4 + src/avatartranslator/AvatarRandom.java | 4 + src/avatartranslator/AvatarResetTimer.java | 4 + src/avatartranslator/AvatarSetTimer.java | 4 + src/avatartranslator/AvatarSpecification.java | 4 + src/avatartranslator/AvatarStartState.java | 4 + src/avatartranslator/AvatarState.java | 4 + .../AvatarStateMachineElement.java | 2 + src/avatartranslator/AvatarStopState.java | 4 + src/avatartranslator/AvatarTransition.java | 43 +++ ...atarSimulationAsynchronousTransaction.java | 80 +++++ .../AvatarSimulationBlock.java | 42 ++- .../AvatarSimulationPendingTransaction.java | 25 +- .../AvatarSimulationTransaction.java | 2 +- .../AvatarSpecificationSimulation.java | 294 +++++++++++++++--- src/ui/MainGUI.java | 22 +- src/ui/TGComponent.java | 15 +- .../JFrameAvatarInteractiveSimulation.java | 128 +++++--- 19 files changed, 586 insertions(+), 107 deletions(-) create mode 100644 src/avatartranslator/directsimulation/AvatarSimulationAsynchronousTransaction.java diff --git a/src/avatartranslator/AvatarActionOnSignal.java b/src/avatartranslator/AvatarActionOnSignal.java index 53a13f4b55..0bb23a5c9e 100644 --- a/src/avatartranslator/AvatarActionOnSignal.java +++ b/src/avatartranslator/AvatarActionOnSignal.java @@ -103,5 +103,13 @@ public class AvatarActionOnSignal extends AvatarStateMachineElement { public String getExtendedName() { return getName() + ":" + getSignal().getName(); } + + public String getNiceName() { + if (signal.isIn()) { + return "Receiving signal " + signal.getName(); + } else { + return "Sending signal " + signal.getName(); + } + } } \ No newline at end of file diff --git a/src/avatartranslator/AvatarExpireTimer.java b/src/avatartranslator/AvatarExpireTimer.java index 7b72977ea0..b9912d314a 100644 --- a/src/avatartranslator/AvatarExpireTimer.java +++ b/src/avatartranslator/AvatarExpireTimer.java @@ -60,4 +60,8 @@ public class AvatarExpireTimer extends AvatarTimerOperator { return aet; } + public String getNiceName() { + return "Expiration of timer " + getName(); + } + } \ No newline at end of file diff --git a/src/avatartranslator/AvatarRandom.java b/src/avatartranslator/AvatarRandom.java index 3ecf00b0d7..a9a73e5af7 100644 --- a/src/avatartranslator/AvatarRandom.java +++ b/src/avatartranslator/AvatarRandom.java @@ -92,4 +92,8 @@ public class AvatarRandom extends AvatarStateMachineElement { return ar; } + public String getNiceName() { + return "Random between " + minValue + " and " + maxValue + " stored in " + variable; + } + } \ No newline at end of file diff --git a/src/avatartranslator/AvatarResetTimer.java b/src/avatartranslator/AvatarResetTimer.java index c0f9aeddf5..4a7421d302 100644 --- a/src/avatartranslator/AvatarResetTimer.java +++ b/src/avatartranslator/AvatarResetTimer.java @@ -60,4 +60,8 @@ public class AvatarResetTimer extends AvatarTimerOperator { return art; } + public String getNiceName() { + return "Reseting of timer " + getName(); + } + } \ No newline at end of file diff --git a/src/avatartranslator/AvatarSetTimer.java b/src/avatartranslator/AvatarSetTimer.java index c783d64937..98dc109554 100644 --- a/src/avatartranslator/AvatarSetTimer.java +++ b/src/avatartranslator/AvatarSetTimer.java @@ -70,4 +70,8 @@ public class AvatarSetTimer extends AvatarTimerOperator { return ast; } + public String getNiceName() { + return "Setting of timer " + getName(); + } + } \ No newline at end of file diff --git a/src/avatartranslator/AvatarSpecification.java b/src/avatartranslator/AvatarSpecification.java index 2f4e983c29..454db5b306 100644 --- a/src/avatartranslator/AvatarSpecification.java +++ b/src/avatartranslator/AvatarSpecification.java @@ -134,6 +134,10 @@ public class AvatarSpecification extends AvatarElement { return Conversion.putVariableValueInString(ops, _source, _at.getName(), _at.getDefaultInitialValue()); } + public String putRealAttributeValueInString(String _source, AvatarAttribute _at) { + return Conversion.putVariableValueInString(ops, _source, _at.getName(), _at.getInitialValue()); + } + public void removeCompositeStates() { for(AvatarBlock block: blocks) { diff --git a/src/avatartranslator/AvatarStartState.java b/src/avatartranslator/AvatarStartState.java index df11e2995c..dcb8a263a4 100644 --- a/src/avatartranslator/AvatarStartState.java +++ b/src/avatartranslator/AvatarStartState.java @@ -58,5 +58,9 @@ public class AvatarStartState extends AvatarStateMachineElement { public AvatarStateMachineElement basicCloneMe() { return new AvatarStartState(getName(), getReferenceObject()); } + + public String getNiceName() { + return "Start state"; + } } \ No newline at end of file diff --git a/src/avatartranslator/AvatarState.java b/src/avatartranslator/AvatarState.java index 121609f8e5..0ebe403f34 100644 --- a/src/avatartranslator/AvatarState.java +++ b/src/avatartranslator/AvatarState.java @@ -62,4 +62,8 @@ public class AvatarState extends AvatarStateMachineElement { AvatarState as = new AvatarState(getName(), getReferenceObject(), isCheckable()); return as; } + + public String getNiceName() { + return "State " + getName(); + } } \ No newline at end of file diff --git a/src/avatartranslator/AvatarStateMachineElement.java b/src/avatartranslator/AvatarStateMachineElement.java index 1d88787329..f15b5e847b 100644 --- a/src/avatartranslator/AvatarStateMachineElement.java +++ b/src/avatartranslator/AvatarStateMachineElement.java @@ -263,5 +263,7 @@ public abstract class AvatarStateMachineElement extends AvatarElement { return true; } + public abstract String getNiceName(); + } \ No newline at end of file diff --git a/src/avatartranslator/AvatarStopState.java b/src/avatartranslator/AvatarStopState.java index 6af8ea1274..e2f23055f5 100644 --- a/src/avatartranslator/AvatarStopState.java +++ b/src/avatartranslator/AvatarStopState.java @@ -58,5 +58,9 @@ public class AvatarStopState extends AvatarStateMachineElement { public AvatarStateMachineElement basicCloneMe() { return new AvatarStartState(getName(), getReferenceObject()); } + + public String getNiceName() { + return "Stop state"; + } } \ No newline at end of file diff --git a/src/avatartranslator/AvatarTransition.java b/src/avatartranslator/AvatarTransition.java index 64ed2e5801..b64658272f 100644 --- a/src/avatartranslator/AvatarTransition.java +++ b/src/avatartranslator/AvatarTransition.java @@ -239,6 +239,49 @@ public class AvatarTransition extends AvatarStateMachineElement { } + // Assumes actions are correctly formatted + public boolean hasMethodCall() { + int index; + + for(String action: actions) { + index = action.indexOf("="); + + // Method of the form f(...) + if (index == -1) { + return true; + } + + // Method of the form x = f(...) + action = action.substring(index+1, action.length()).trim(); + index = action.indexOf("("); + if (index != -1) { + action = action.substring(0, index).trim(); + boolean b1 = (action.substring(0,1)).matches("[a-zA-Z]"); + boolean b2 = action.matches("\\w*"); + if (b1 && b2) { + return true; + } + } + } + return false; + + } + + public String getNiceName() { + if (isGuarded()) + return "Transition (guard=" + guard + ", ...)"; + + if (hasDelay()) + return "Transition (delay=(" + minDelay + ", " + maxDelay + "), ...)"; + + if (actions.size() > 0) { + return "Transition (" + actions.get(0) + ", ...)"; + } + + return "Empty transition"; + } + + diff --git a/src/avatartranslator/directsimulation/AvatarSimulationAsynchronousTransaction.java b/src/avatartranslator/directsimulation/AvatarSimulationAsynchronousTransaction.java new file mode 100644 index 0000000000..06afa36592 --- /dev/null +++ b/src/avatartranslator/directsimulation/AvatarSimulationAsynchronousTransaction.java @@ -0,0 +1,80 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + +ludovic.apvrille AT enst.fr + +This software is a computer program whose purpose is to allow the +edition of TURTLE analysis, design and deployment diagrams, to +allow the generation of RT-LOTOS or Java code from this diagram, +and at last to allow the analysis of formal validation traces +obtained from external tools, e.g. RTL from LAAS-CNRS and CADP +from INRIA Rhone-Alpes. + +This software is governed by the CeCILL license under French law and +abiding by the rules of distribution of free software. You can use, +modify and/ or redistribute the software under the terms of the CeCILL +license as circulated by CEA, CNRS and INRIA at the following URL +"http://www.cecill.info". + +As a counterpart to the access to the source code and rights to copy, +modify and redistribute granted by the license, users are provided only +with a limited warranty and the software's author, the holder of the +economic rights, and the successive licensors have only limited +liability. + +In this respect, the user's attention is drawn to the risks associated +with loading, using, modifying and/or developing or reproducing the +software by the user in light of its specific status of free software, +that may mean that it is complicated to manipulate, and that also +therefore means that it is reserved for developers and experienced +professionals having in-depth computer knowledge. Users are therefore +encouraged to load and test the software's suitability as regards their +requirements in conditions enabling the security of their systems and/or +data to be ensured and, more generally, to use and operate it in the +same conditions as regards security. + +The fact that you are presently reading this means that you have had +knowledge of the CeCILL license and that you accept its terms. + +/** + * Class AvatarSimulationAsynchronousTransaction + * Avatar: notion of asynchronous transaction in simulation + * Creation: 24/01/2011 + * @version 1.0 24/01/2011 + * @author Ludovic APVRILLE + * @see + */ + + +package avatartranslator.directsimulation; + +import java.util.*; + +import avatartranslator.*; +import myutil.*; + +public class AvatarSimulationAsynchronousTransaction { + + private Vector<String> parameters; + private AvatarRelation relation; + + public AvatarSimulationAsynchronousTransaction(AvatarRelation _ar) { + relation = _ar; + parameters = new Vector<String>(); + } + + public AvatarRelation getRelation() { + return relation; + } + + public void addParameter(String _s) { + parameters.add(_s); + } + + public int getNbOfParameters() { + return parameters.size(); + } + + public Vector<String> getParameters() { + return parameters; + } +} \ No newline at end of file diff --git a/src/avatartranslator/directsimulation/AvatarSimulationBlock.java b/src/avatartranslator/directsimulation/AvatarSimulationBlock.java index 071338ff7c..17e3e9c244 100644 --- a/src/avatartranslator/directsimulation/AvatarSimulationBlock.java +++ b/src/avatartranslator/directsimulation/AvatarSimulationBlock.java @@ -61,15 +61,19 @@ public class AvatarSimulationBlock { private AvatarBlock block; private AvatarSimulationTransaction lastTransaction; - private LinkedList<AvatarSimulationTransaction> transactions; + private Vector <AvatarSimulationTransaction> transactions; private boolean completed; public AvatarSimulationBlock(AvatarBlock _block) { block = _block; - transactions = new LinkedList<AvatarSimulationTransaction>(); + transactions = new Vector<AvatarSimulationTransaction>(); completed = false; } + public AvatarBlock getBlock() { + return block; + } + public String getName() { if (block != null) { return block.getName(); @@ -96,19 +100,27 @@ public class AvatarSimulationBlock { return STARTED; } - public LinkedList<AvatarSimulationTransaction> getTransactions() { + public Vector<AvatarSimulationTransaction> getTransactions() { return transactions; } - public LinkedList<AvatarSimulationPendingTransaction> getPendingTransactions(LinkedList<AvatarSimulationTransaction> _allTransactions, long _clockValue, int _maxTransationsInARow) { - LinkedList<AvatarSimulationPendingTransaction> ll = new LinkedList<AvatarSimulationPendingTransaction>(); + public Vector<AvatarSimulationPendingTransaction> getPendingTransactions(Vector<AvatarSimulationTransaction> _allTransactions, long _clockValue, int _maxTransationsInARow) { + Vector<AvatarSimulationPendingTransaction> ll = new Vector<AvatarSimulationPendingTransaction>(); if (completed) { return ll; } if (lastTransaction == null) { - runToNextBlockingElement(_allTransactions, _clockValue, _maxTransationsInARow); + //runToNextBlockingElement(_allTransactions, _clockValue, _maxTransationsInARow); + // First transaction + AvatarStartState ass = block.getStateMachine().getStartState(); + if (ass == null) { + completed = true; + return ll; + } + makeExecutedTransaction(_allTransactions, ass, _clockValue); + } if ((lastTransaction == null) || completed) { @@ -142,7 +154,7 @@ public class AvatarSimulationBlock { return ll; } - public void runToNextBlockingElement(LinkedList<AvatarSimulationTransaction> _allTransactions, long _clockValue, int _maxTransationsInARow) { + /*public void runToNextBlockingElement(Vector<AvatarSimulationTransaction> _allTransactions, long _clockValue, int _maxTransationsInARow) { // No previous transaction if (lastTransaction == null) { @@ -193,14 +205,16 @@ public class AvatarSimulationBlock { TraceManager.addDev("Too many transactions in a row: aborting block"); completed = true; } - } + }*/ - public void runSoloPendingTransaction(AvatarSimulationPendingTransaction _aspt, LinkedList<AvatarSimulationTransaction> _allTransactions, long _clockValue, int _maxTransationsInARow) { + public void runSoloPendingTransaction(AvatarSimulationPendingTransaction _aspt, Vector<AvatarSimulationTransaction> _allTransactions, long _clockValue, int _maxTransationsInARow) { if (_aspt.involvedElement != null) { executeElement(_allTransactions, _aspt.involvedElement, _clockValue); } executeElement(_allTransactions, _aspt.elementToExecute, _clockValue); - runToNextBlockingElement(_allTransactions, _clockValue, _maxTransationsInARow); + + + //runToNextBlockingElement(_allTransactions, _clockValue, _maxTransationsInARow); } @@ -232,7 +246,7 @@ public class AvatarSimulationBlock { return true; } - public void executeElement(LinkedList<AvatarSimulationTransaction>_allTransactions, AvatarStateMachineElement _elt, long _clockValue) { + public void executeElement(Vector<AvatarSimulationTransaction>_allTransactions, AvatarStateMachineElement _elt, long _clockValue) { // Stop state if (_elt instanceof AvatarStopState) { makeExecutedTransaction(_allTransactions, _elt, _clockValue); @@ -255,7 +269,7 @@ public class AvatarSimulationBlock { } } - public void makeExecutedTransaction(LinkedList<AvatarSimulationTransaction> _allTransactions, AvatarStateMachineElement _elt, long _clockValue) { + public void makeExecutedTransaction(Vector<AvatarSimulationTransaction> _allTransactions, AvatarStateMachineElement _elt, long _clockValue) { AvatarSimulationTransaction ast = new AvatarSimulationTransaction(_elt); ast.block = block; ast.asb = this; @@ -265,7 +279,7 @@ public class AvatarSimulationBlock { ast.id = ast.setID(); // Attributes - LinkedList<String> attributeValues = new LinkedList<String>(); + Vector<String> attributeValues = new Vector<String>(); String s; if (lastTransaction == null) { for(AvatarAttribute aa: block.getAttributes()) { @@ -282,7 +296,7 @@ public class AvatarSimulationBlock { addExecutedTransaction(_allTransactions, ast); } - public void addExecutedTransaction(LinkedList<AvatarSimulationTransaction> _allTransactions, AvatarSimulationTransaction _ast) { + public void addExecutedTransaction(Vector<AvatarSimulationTransaction> _allTransactions, AvatarSimulationTransaction _ast) { transactions.add(_ast); lastTransaction = _ast; _allTransactions.add(_ast); diff --git a/src/avatartranslator/directsimulation/AvatarSimulationPendingTransaction.java b/src/avatartranslator/directsimulation/AvatarSimulationPendingTransaction.java index bc7971c8e8..67b4a5f190 100644 --- a/src/avatartranslator/directsimulation/AvatarSimulationPendingTransaction.java +++ b/src/avatartranslator/directsimulation/AvatarSimulationPendingTransaction.java @@ -57,15 +57,38 @@ public class AvatarSimulationPendingTransaction { public AvatarSimulationBlock asb; public AvatarStateMachineElement elementToExecute; public AvatarStateMachineElement involvedElement; //(transition) + public AvatarSimulationPendingTransaction linkedTransaction; + public AvatarSimulationAsynchronousTransaction linkedAsynchronousMessage; public long clockValue; + public long nextMinClockValue; + public long nextMaxClockValue; public AvatarSimulationPendingTransaction() { } + public AvatarSimulationPendingTransaction cloneMe() { + + AvatarSimulationPendingTransaction aspt = new AvatarSimulationPendingTransaction(); + aspt.asb = this.asb; + aspt.elementToExecute = this.elementToExecute; + aspt.involvedElement = this.involvedElement; + aspt.linkedTransaction = this.linkedTransaction; + aspt.linkedAsynchronousMessage = this.linkedAsynchronousMessage; + aspt.clockValue = this.clockValue; + + return aspt; + } + public String toString() { - String res = " @" + clockValue + " " + elementToExecute + " in block " + asb.getName(); + String res = "in Block " + asb.getName() + ": "; + if (linkedTransaction == null) { + res = res + elementToExecute.getNiceName() + "/ID=" + elementToExecute.getID(); + } else { + res += "[SYNCHRO]" + elementToExecute.getNiceName() + "/ID=" + elementToExecute.getID(); + res += " | " + linkedTransaction.toString(); + } return res; } } \ No newline at end of file diff --git a/src/avatartranslator/directsimulation/AvatarSimulationTransaction.java b/src/avatartranslator/directsimulation/AvatarSimulationTransaction.java index 83d0c6099a..3f6a182db9 100644 --- a/src/avatartranslator/directsimulation/AvatarSimulationTransaction.java +++ b/src/avatartranslator/directsimulation/AvatarSimulationTransaction.java @@ -64,7 +64,7 @@ public class AvatarSimulationTransaction { public long initialClockValue; public long clockValueWhenPerformed; public long id; - public LinkedList<String> attributeValues; + public Vector<String> attributeValues; public AvatarSimulationTransaction(AvatarStateMachineElement _executeElement) { executedElement = _executeElement; diff --git a/src/avatartranslator/directsimulation/AvatarSpecificationSimulation.java b/src/avatartranslator/directsimulation/AvatarSpecificationSimulation.java index a8da07ba94..e342c0cc3d 100644 --- a/src/avatartranslator/directsimulation/AvatarSpecificationSimulation.java +++ b/src/avatartranslator/directsimulation/AvatarSpecificationSimulation.java @@ -66,26 +66,31 @@ public class AvatarSpecificationSimulation { private AvatarSpecification avspec; private AvatarSimulationInteraction asi; private long clockValue; - private LinkedList<AvatarSimulationBlock> blocks; - private LinkedList<AvatarActionOnSignal> asynchronousMessages; - private LinkedList<AvatarSimulationPendingTransaction> pendingTransactions; - private LinkedList<AvatarSimulationTransaction> allTransactions; + private Vector<AvatarSimulationBlock> blocks; + private AvatarSimulationBlock previousBlock; + private Vector<AvatarSimulationAsynchronousTransaction> asynchronousMessages; + private Vector<AvatarSimulationPendingTransaction> pendingTransactions; + private Vector<AvatarSimulationTransaction> allTransactions; private boolean stopped = false; private boolean killed = false; private int nbOfCommands = -1; // means: until it blocks + private int indexSelectedTransaction = -1; + + private IntExpressionEvaluator iee; public AvatarSpecificationSimulation(AvatarSpecification _avspec, AvatarSimulationInteraction _asi) { avspec = _avspec; asi = _asi; + iee = new IntExpressionEvaluator(); } - public LinkedList<AvatarSimulationBlock> getSimulationBlocks() { + public Vector<AvatarSimulationBlock> getSimulationBlocks() { return blocks; } - public LinkedList<AvatarSimulationTransaction> getAllTransactions() { + public Vector<AvatarSimulationTransaction> getAllTransactions() { return allTransactions; } @@ -115,18 +120,18 @@ public class AvatarSpecificationSimulation { AvatarSimulationTransaction.reinit(); // Create all simulation blocks - blocks = new LinkedList<AvatarSimulationBlock>(); + blocks = new Vector<AvatarSimulationBlock>(); for(AvatarBlock block: avspec.getListOfBlocks()) { AvatarSimulationBlock asb = new AvatarSimulationBlock(block); blocks.add(asb); } // Create all simulation asynchronous channels - asynchronousMessages = new LinkedList<AvatarActionOnSignal>(); + asynchronousMessages = new Vector<AvatarSimulationAsynchronousTransaction>(); // Create the structure for pending and executed transactions - pendingTransactions = new LinkedList<AvatarSimulationPendingTransaction>(); - allTransactions = new LinkedList<AvatarSimulationTransaction>(); + pendingTransactions = new Vector<AvatarSimulationPendingTransaction>(); + allTransactions = new Vector<AvatarSimulationTransaction>(); } public boolean isInDeadlock() { @@ -136,30 +141,34 @@ public class AvatarSpecificationSimulation { public void runSimulation() { setMode(RUNNING); int index[]; - LinkedList<AvatarSimulationPendingTransaction> selectedTransactions; + Vector<AvatarSimulationPendingTransaction> selectedTransactions; boolean go = true; stopped = true; - if (stopped && go) { - setMode(STOPPED); - TraceManager.addDev("Simulation waiting for run"); - waitForUnstopped(); - if (go) { - setMode(RUNNING); - } - } - TraceManager.addDev("Simulation started at time: " + clockValue); while((go == true) && !killed) { - while((go == true) && !stopped && !killed) { + while((go == true) && !killed) { gatherPendingTransactions(); if (pendingTransactions.size() == 0) { go = false; TraceManager.addDev("No more pending transactions"); } else { + + if (stopped && go) { + setMode(STOPPED); + TraceManager.addDev("Simulation waiting for run"); + waitForUnstopped(); + if (go) { + setMode(RUNNING); + } + } else if (nbOfCommands == 0) { + stopSimulation(); + stopSimulation(go); + } + selectedTransactions = selectTransactions(pendingTransactions); if (selectedTransactions.size() == 0) { @@ -170,18 +179,10 @@ public class AvatarSpecificationSimulation { go = performSelectedTransactions(selectedTransactions); TraceManager.addDev("NbOfcommands=" + nbOfCommands); nbOfCommands --; - if (nbOfCommands == 0) { - stopSimulation(); - stopSimulation(go); - } } } } - if (stopped && go && !killed) { - stopSimulation(go); - - } } setMode(TERMINATED); TraceManager.addDev("Simulation finished at time: " + clockValue + "\n--------------------------------------"); @@ -190,25 +191,190 @@ public class AvatarSpecificationSimulation { } public void gatherPendingTransactions() { + AvatarTransition tr; + pendingTransactions.clear(); // Gather all pending transactions from blocks for(AvatarSimulationBlock asb: blocks) { pendingTransactions.addAll(asb.getPendingTransactions(allTransactions, clockValue, MAX_TRANSACTION_IN_A_ROW)); } + + TraceManager.addDev("# of pending transactions before selection: " + pendingTransactions.size()); + + Vector<AvatarSimulationPendingTransaction> ll = new Vector<AvatarSimulationPendingTransaction>(); + + for(AvatarSimulationPendingTransaction aspt: pendingTransactions) { + if (aspt.elementToExecute instanceof AvatarTransition) { + tr = (AvatarTransition)(aspt.elementToExecute); + if (!tr.hasDelay()) { + ll.add(aspt); + } + } else if (aspt.elementToExecute instanceof AvatarState) { + ll.add(aspt); + } else if (aspt.elementToExecute instanceof AvatarStopState) { + ll.add(aspt); + } else if (aspt.elementToExecute instanceof AvatarActionOnSignal) { + workOnAvatarActionOnSignalTransaction(ll, aspt, (AvatarActionOnSignal)(aspt.elementToExecute)); + } + } + + if (ll.size() == 0) { + // Randomly select a time for transitions + int min, max; + String res; + AvatarBlock ab; + int i; + + for(AvatarSimulationPendingTransaction aspt: pendingTransactions) { + if (aspt.elementToExecute instanceof AvatarTransition) { + tr = (AvatarTransition)(aspt.elementToExecute); + if (tr.hasDelay()) { + ab = aspt.asb.getBlock(); + res = tr.getMinDelay(); + for(i=0; i<ab.attributeNb(); i++) { + res = avspec.putRealAttributeValueInString(res, ab.getAttribute(i)); + } + min = (int)(iee.getResultOf(res)); + res = tr.getMaxDelay(); + for(i=0; i<ab.attributeNb(); i++) { + TraceManager.addDev("res =" + res + "atrribute " + ab.getAttribute(i)); + res = avspec.putRealAttributeValueInString(res, ab.getAttribute(i)); + } + TraceManager.addDev("res =" + res); + max = (int)(iee.getResultOf(res)); + aspt.nextMinClockValue = min; + aspt.nextMaxClockValue = max; + TraceManager.addDev("Setting clock value to " + aspt.nextMinClockValue + "," + aspt.nextMaxClockValue); + } + } + } + } + + pendingTransactions = ll; + + + + } + + public void workOnAvatarActionOnSignalTransaction(Vector<AvatarSimulationPendingTransaction> transactions, AvatarSimulationPendingTransaction _aspt, AvatarActionOnSignal _aaos) { + AvatarSignal as = _aaos.getSignal(); + if (as.isIn()) { + AvatarRelation ar = avspec.getAvatarRelationWithSignal(as); + // If synchronous, not taken into account -> taken into account at sending side + if (ar.isAsynchronous()) { + // Must check whether there is at least one element to read in the channel + AvatarSimulationAsynchronousTransaction asat = getAsynchronousMessage(ar); + if (asat != null) { + _aspt.linkedAsynchronousMessage = asat; + transactions.add(_aspt); + + } + } + } else { + AvatarRelation ar = avspec.getAvatarRelationWithSignal(as); + if (ar.isAsynchronous()) { + // Mus see whether the channel is full or not + if (ar.isBlocking()) { + // Must see whether te channel is full or not + int nb = getNbOfAsynchronousMessages(ar); + if (nb < ar.getSizeOfFIFO()) { + transactions.add(_aspt); + } + } else { + // The transaction can be performed + transactions.add(_aspt); + } + } else { + // Synchronous -> must find a corresponding synchronous one + // Each time one is found, a new pending transaction is added, linked with the receiving action + TraceManager.addDev("Found a synchronous signal"); + for(AvatarSimulationPendingTransaction otherTransaction: pendingTransactions) { + if (otherTransaction != _aspt) { + if (otherTransaction.elementToExecute instanceof AvatarActionOnSignal) { + TraceManager.addDev("step 2"); + AvatarSignal sig = ((AvatarActionOnSignal)(otherTransaction.elementToExecute)).getSignal(); + AvatarRelation rel = avspec.getAvatarRelationWithSignal(sig); + if (rel == ar) { + TraceManager.addDev("step 3"); + if (sig.isIn()) { + // Found one! + TraceManager.addDev("step 4"); + AvatarSimulationPendingTransaction newone = _aspt.cloneMe(); + newone.linkedTransaction = otherTransaction; + transactions.add(newone); + } + } + } + } + } + + } + } + } + + public AvatarSimulationAsynchronousTransaction getAsynchronousMessage(AvatarRelation _ar) { + for(AvatarSimulationAsynchronousTransaction asat: asynchronousMessages) { + if (asat.getRelation() == _ar) { + return asat; + } + } + return null; + } + + public int getNbOfAsynchronousMessages(AvatarRelation _ar) { + int cpt = 0; + for(AvatarSimulationAsynchronousTransaction asat: asynchronousMessages) { + if (asat.getRelation() == _ar) { + cpt ++; + } + } + return cpt; } - public LinkedList<AvatarSimulationPendingTransaction> selectTransactions(LinkedList<AvatarSimulationPendingTransaction> _pendingTransactions) { - LinkedList<AvatarSimulationPendingTransaction> ll = new LinkedList<AvatarSimulationPendingTransaction>(); + public Vector<AvatarSimulationPendingTransaction> selectTransactions(Vector<AvatarSimulationPendingTransaction> _pendingTransactions) { + Vector<AvatarSimulationPendingTransaction> ll = new Vector<AvatarSimulationPendingTransaction>(); // Put in ll the first possible logical transaction which is met - // andom select the first index - int decIndex = (int)(Math.floor(Math.random()*_pendingTransactions.size())); + // Random select the first index if none has been selected + + if (indexSelectedTransaction == -1) { + TraceManager.addDev("No transition selected"); + indexSelectedTransaction = (int)(Math.floor(Math.random()*_pendingTransactions.size())); + } - AvatarSimulationPendingTransaction currentTransaction; + AvatarSimulationPendingTransaction currentTransaction = _pendingTransactions.get(indexSelectedTransaction); + ll.add(currentTransaction); + indexSelectedTransaction = -1; + return ll; + + // First consider logical transactions of the previous block + /*if (previousBlock != null) { + for(i=0; i<_pendingTransactions.size(); i++) { + currentTransaction = _pendingTransactions.get((i+decIndex)%_pendingTransactions.size()); + if (currentTransaction.asb == previousBlock) { + if (currentTransaction.elementToExecute instanceof AvatarTransition) { + AvatarTransition tr = (AvatarTransition)(currentTransaction.elementToExecute); + if (!tr.hasDelay() && !tr.hasMethodCall()) { + ll.add(currentTransaction); + } + break; + } else if (currentTransaction.elementToExecute instanceof AvatarState) { + ll.add(currentTransaction); + break; + } else if (currentTransaction.elementToExecute instanceof AvatarStopState) { + ll.add(currentTransaction); + break; + } + } + } + } + if (ll.size() > 0) { + return ll; + }*/ // First consider logical transactions only - for(int i=0; i<_pendingTransactions.size(); i++) { + /*for(i=0; i<_pendingTransactions.size(); i++) { currentTransaction = _pendingTransactions.get((i+decIndex)%_pendingTransactions.size()); if (currentTransaction.elementToExecute instanceof AvatarTransition) { @@ -217,17 +383,37 @@ public class AvatarSpecificationSimulation { ll.add(currentTransaction); } break; + } else if (currentTransaction.elementToExecute instanceof AvatarState) { + ll.add(currentTransaction); + break; + } else if (currentTransaction.elementToExecute instanceof AvatarStopState) { + ll.add(currentTransaction); + break; } } + if (ll.size() > 0) { + return ll; + }*/ + // Then consider timed transactions - return ll; + //return ll; } - public boolean performSelectedTransactions(LinkedList<AvatarSimulationPendingTransaction> _pendingTransactions) { + public boolean performSelectedTransactions(Vector<AvatarSimulationPendingTransaction> _pendingTransactions) { if (_pendingTransactions.size() == 1) { + preExecutedTransaction(_pendingTransactions.get(0)); _pendingTransactions.get(0).asb.runSoloPendingTransaction(_pendingTransactions.get(0), allTransactions, clockValue, MAX_TRANSACTION_IN_A_ROW); + postExecutedTransaction(_pendingTransactions.get(0)); + previousBlock = _pendingTransactions.get(0).asb; + if (_pendingTransactions.get(0).linkedTransaction != null) { + preExecutedTransaction(_pendingTransactions.get(0).linkedTransaction); + _pendingTransactions.get(0).linkedTransaction.asb.runSoloPendingTransaction(_pendingTransactions.get(0).linkedTransaction, allTransactions, clockValue, MAX_TRANSACTION_IN_A_ROW); + postExecutedTransaction(_pendingTransactions.get(0).linkedTransaction); + } + + return true; } else if (_pendingTransactions.size() == 1) { // synchro //Not yet handled @@ -238,6 +424,29 @@ public class AvatarSpecificationSimulation { } } + public void preExecutedTransaction(AvatarSimulationPendingTransaction _aspt) { + if (_aspt.elementToExecute instanceof AvatarActionOnSignal) { + AvatarSignal sig = ((AvatarActionOnSignal)(_aspt.elementToExecute)).getSignal(); + AvatarRelation rel = avspec.getAvatarRelationWithSignal(sig); + if (rel.isAsynchronous()) { + if (sig.isOut()) { + // Create the stucture to put elements + AvatarSimulationAsynchronousTransaction asat = new AvatarSimulationAsynchronousTransaction(rel); + _aspt.linkedAsynchronousMessage = asat; + asynchronousMessages.add(asat); + } else { + // Must remove the asynchronous operation, and give the parameters + AvatarSimulationAsynchronousTransaction asat = getAsynchronousMessage(rel); + asynchronousMessages.remove(asat); + _aspt.linkedAsynchronousMessage = asat; + } + } + } + } + + public void postExecutedTransaction(AvatarSimulationPendingTransaction _aspt) { + } + public void printExecutedTransactions() { for(AvatarSimulationTransaction ast: allTransactions) { TraceManager.addDev(ast.toString() + "\n"); @@ -302,6 +511,17 @@ public class AvatarSpecificationSimulation { } } + public AvatarSimulationBlock getPreviousBlock() { + return previousBlock; + } + public Vector<AvatarSimulationPendingTransaction> getPendingTransitions() { + return pendingTransactions; + } + + public void setIndexSelectedTransaction(int _index) { + TraceManager.addDev("Selected transition: " + _index); + indexSelectedTransaction = _index; + } } \ No newline at end of file diff --git a/src/ui/MainGUI.java b/src/ui/MainGUI.java index ed252ed6ba..60aa8941ff 100755 --- a/src/ui/MainGUI.java +++ b/src/ui/MainGUI.java @@ -3246,7 +3246,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener { dtree.toBeUpdated();*/ jfais = new JFrameAvatarInteractiveSimulation(frame, this, "Interactive simulation", gtm.getAvatarSpecification()); jfais.setIconImage(IconManager.img9); - jfais.setSize(1024, 900); + jfais.setSize(1024, 600); GraphicLib.centerOnParent(jfais); jfais.setVisible(true); } else if ((tp instanceof TMLDesignPanel) || (tp instanceof TMLComponentDesignPanel) || (tp instanceof TMLArchiPanel)) { @@ -5536,6 +5536,15 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener { selectTab(getCurrentTURTLEPanel(), tab); } + public void openAVATARSMD(String tab) { + TDiagramPanel cur = getCurrentTDiagramPanel(); + selectTab(getCurrentTURTLEPanel(), tab); + TDiagramPanel tdp = getCurrentTDiagramPanel(); + if (tdp == cur) { + tdp.repaint(); + } + } + public boolean selectHighLevelTab(String s) { TURTLEPanel tp = getTURTLEPanel(s); if (s != null) { @@ -5665,11 +5674,16 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener { setDiploAnimate(!TDiagramPanel.DIPLO_ANIMATE_ON); } - public boolean isRunningAvatarComponent(TGComponent _tgc) { + public int isRunningAvatarComponent(TGComponent _tgc) { if(jfais.isVisible()) { - return jfais.isRunningComponent(_tgc); + if (jfais.isRunningComponent(_tgc)) { + return 1; + } + if (jfais.isSelectedComponentFromTransaction(_tgc)) { + return 2; + } } - return false; + return 0; } public void setDiploAnimate(boolean b) { diff --git a/src/ui/TGComponent.java b/src/ui/TGComponent.java index 0cebf53c2d..36341507f8 100755 --- a/src/ui/TGComponent.java +++ b/src/ui/TGComponent.java @@ -507,7 +507,9 @@ public abstract class TGComponent implements CDElement, GenericTree { } - public void drawAVATARComp(Graphics g) { + // _mode: 1 : running + // 2 : slected for execution + public void drawAVATARComp(Graphics g, int _mode) { int wb = 30; int hb = 10; int wh = 15; @@ -550,7 +552,11 @@ public abstract class TGComponent implements CDElement, GenericTree { xp[6] = myx - sep - wb -wh; yp[6] = myy + ((myheight+hb) / 2); - g.setColor(ColorManager.CURRENT_COMMAND_RUNNING); + if (_mode == 1) { + g.setColor(ColorManager.CURRENT_COMMAND_RUNNING); + } else { + g.setColor(ColorManager.CURRENT_COMMAND_SUSPENDED); + } g.fillPolygon(xp, yp, 7); } @@ -774,9 +780,10 @@ public abstract class TGComponent implements CDElement, GenericTree { if (AVATAR_met) { drawAVATARMet(g); } - if (tdp.getMGUI().isRunningAvatarComponent(this)) { + int ret = tdp.getMGUI().isRunningAvatarComponent(this); + if (ret > 0) { //TraceManager.addDev("Avatar animate!"); - drawAVATARComp(g); + drawAVATARComp(g, ret); } } diff --git a/src/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java b/src/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java index 3cc865aa67..59a4718d19 100755 --- a/src/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java +++ b/src/ui/avatarinteractivesimulation/JFrameAvatarInteractiveSimulation.java @@ -47,7 +47,7 @@ package ui.avatarinteractivesimulation; //import java.io.*; import javax.swing.*; -//import javax.swing.event.*; +import javax.swing.event.*; import javax.swing.table.*; import java.awt.*; import java.awt.event.*; @@ -63,7 +63,7 @@ import avatartranslator.*; import avatartranslator.directsimulation.*; -public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarSimulationInteraction, ActionListener, Runnable, MouseListener, ItemListener/*, StoppableGUIElement, SteppedAlgorithm, ExternalCall*/ { +public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarSimulationInteraction, ActionListener, Runnable, MouseListener, ItemListener, ListSelectionListener/*, StoppableGUIElement, SteppedAlgorithm, ExternalCall*/ { private static String buttonStartS = "Start simulator"; @@ -100,7 +100,12 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS protected JTextField saveFileName; protected JTextField stateFileName; protected JTextField benchmarkFileName; - protected JComboBox cpus, busses, mems, tasks, chans; + //protected JComboBox cpus, busses, mems, tasks, chans; + + //List of transactions + private JList listPendingTransactions; + private TGComponent selectedComponentForTransaction; + private AvatarSimulationBlock previousBlock; //private String[] cpuIDs, busIDs, memIDs, taskIDs, chanIDs; @@ -325,18 +330,18 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS mainTop.add(commands, c02); commandTab = new JTabbedPane(); + commands.add(commandTab); //commandTab.setBackground(ColorManager.InteractiveSimulationBackground); + // Control commands jp01 = new JPanel(new BorderLayout()); + commandTab.addTab("Control", null, jp01, "Main control commands"); //jp01.setMinimumSize(new Dimension(375, 400)); //gridbag01 = new GridBagLayout(); //c01 = new GridBagConstraints(); //jp01.setLayout(gridbag01); - commandTab.addTab("Control", null, jp01, "Main control commands"); - - mctb = new AvatarMainCommandsToolBar(this); jp01.add(mctb, BorderLayout.NORTH); @@ -357,6 +362,22 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS c01.gridwidth = GridBagConstraints.REMAINDER; //end row paramMainCommand = new JTextField("1", 30); jp02.add(paramMainCommand, c01); + // list of pending transactions + JPanel panellpt = new JPanel(); + panellpt.setLayout(new BorderLayout()); + panellpt.setBorder(new javax.swing.border.TitledBorder("Pending transactions")); + + listPendingTransactions = new JList(); + //listPendingTransactions.setPreferredSize(new Dimension(150, 150)); + listPendingTransactions.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION ); + listPendingTransactions.addListSelectionListener(this); + JScrollPane scrollPane1 = new JScrollPane(listPendingTransactions); + scrollPane1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + panellpt.add(scrollPane1); + jp02.add(panellpt, c01); + jp01.add(jp02, BorderLayout.CENTER); + + /*c01.gridwidth = 1; jp02.add(new JLabel("CPUs: "), c01); @@ -408,49 +429,10 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS } jp02.add(chans, c01);*/ - jp01.add(jp02, BorderLayout.CENTER); - - - // Text commands - /*jp01 = new JPanel(); - //jp01.setPreferredSize(new Dimension(375, 400)); - gridbag01 = new GridBagLayout(); - c01 = new GridBagConstraints(); - jp01.setLayout(gridbag01); - commandTab.addTab("Text commands", null, jp01, "Sending text commands to simulator"); - c01.gridheight = 1; - c01.weighty = 1.0; - c01.weightx = 1.0; - c01.gridwidth = GridBagConstraints.REMAINDER; //end row - c01.fill = GridBagConstraints.BOTH; - c01.gridheight = 1; - c01.gridheight = 2; - jp01.add(new JLabel("Enter a text command:"), c01); - textCommand = new JTextField(30); - jp01.add(textCommand, c01); - c01.gridheight = 1; - jp01.add(new JLabel(" "), c01); - c01.gridheight = 2; - sendTextCommand = new JButton("Send Command", IconManager.imgic71); - sendTextCommand.addMouseListener(this); - jp01.add(sendTextCommand, c01); - c01.gridheight = 1; - jp01.add(new JLabel(" "), c01); - c01.gridheight = 2; - printHelpTextCommands = new JButton("Help on a text command", IconManager.imgic33); - printHelpTextCommands.addMouseListener(this); - jp01.add(printHelpTextCommands, c01); - c01.gridheight = 1; - jp01.add(new JLabel(" "), c01); - c01.gridheight = 2; - listTextCommands = new JButton("List all text commands", IconManager.imgic29); - listTextCommands.addMouseListener(this); - jp01.add(listTextCommands, c01);*/ - commands.add(commandTab); // Set variables /*jpsv = new JPanelSetVariables(this, valueTable); @@ -761,6 +743,7 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS public void setMode(int _mode) { busyMode = _mode; TraceManager.addDev("****************** mode set to " + busyMode); + TraceManager.addDev("# of Pending transactions: " + ass.getPendingTransitions().size()); setAll(); @@ -808,6 +791,7 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS //actions[AvatarInteractiveSimulationActions.ACT_RESTORE_STATE].setEnabled(b); setLabelColors(); + setcontentOfListOfPendingTransactions(); } public void setLabelColors() { @@ -837,6 +821,19 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS } } + public void setcontentOfListOfPendingTransactions() { + Vector<AvatarSimulationPendingTransaction> ll = ass.getPendingTransitions(); + try { + listPendingTransactions.clearSelection(); + selectedComponentForTransaction = null; + if (ll != null) { + listPendingTransactions.setListData(ll); + } else { + listPendingTransactions.setListData(new Vector<AvatarSimulationPendingTransaction>()); + } + } catch (Exception e) {} + } + public void resetMetElements() { if (avspec.getReferenceObject() instanceof AvatarDesignPanel) { ((AvatarDesignPanel)(avspec.getReferenceObject())).resetMetElements(); @@ -876,11 +873,16 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS // Search for corresponding element in avatar spec tgc = (TGComponent)(asme.getReferenceObject()); if (tgc != null) { - TraceManager.addDev("Found an object:" + tgc); + //TraceManager.addDev("Found an object:" + tgc); runningTGComponents.add(tgc); } } } + if (openDiagram.isSelected()) { + if (ass.getPreviousBlock() != null) { + mgui.openAVATARSMD(ass.getPreviousBlock().getName()); + } + } } mgui.setAvatarAnimate(animate.isSelected()); } @@ -890,6 +892,10 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS return runningTGComponents.contains(_tgc); } + public boolean isSelectedComponentFromTransaction(TGComponent _tgc) { + return _tgc == selectedComponentForTransaction; + } + // Mouse management public void mouseReleased(MouseEvent e) {} @@ -955,6 +961,36 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS jta.append("error: " + error + "\n"); } + public void valueChanged(ListSelectionEvent e) { + int index = listPendingTransactions.getSelectedIndex(); + if (index > -1) { + try { + AvatarSimulationPendingTransaction aspt = (AvatarSimulationPendingTransaction)(listPendingTransactions.getSelectedValue()); + selectedComponentForTransaction = (TGComponent)(aspt.elementToExecute.getReferenceObject()); + if (!(busyMode == AvatarSpecificationSimulation.RUNNING)) { + ass.setIndexSelectedTransaction(listPendingTransactions.getSelectedIndex()); + } + if (animate.isSelected() && (openDiagram.isSelected())) { + if (aspt.asb != null) { + previousBlock = aspt.asb; + mgui.openAVATARSMD(previousBlock.getName()); + } + } + } catch (Exception ex){ + selectedComponentForTransaction = null; + if (previousBlock != null) { + mgui.openAVATARSMD(previousBlock.getName()); + } + } + } else { + selectedComponentForTransaction = null; + if (previousBlock != null) { + mgui.openAVATARSMD(previousBlock.getName()); + } + } + + } + public void itemStateChanged(ItemEvent e) { if (e.getSource() == animate) { -- GitLab