From d3a679600a9bb7cbda1cf3fc9123b962ec040aa0 Mon Sep 17 00:00:00 2001 From: Ludovic Apvrille <ludovic.apvrille@telecom-paristech.fr> Date: Wed, 20 Jan 2010 13:49:02 +0000 Subject: [PATCH] Updates on multichannel write Add priority on channels, at mapping --- src/tmltranslator/TMLChannel.java | 10 +++++++ src/tmltranslator/TMLMapping.java | 8 ++++++ .../TMLMappingTextSpecification.java | 21 +++++++++++--- src/tmltranslator/touppaal/TML2UPPAAL.java | 28 ++++++++++++++++--- src/ui/GTMLModeling.java | 6 ++++ .../tmldd/TMLArchiCommunicationArtifact.java | 23 +++++++++++++-- .../window/JDialogCommunicationArtifact.java | 14 +++++++++- 7 files changed, 99 insertions(+), 11 deletions(-) diff --git a/src/tmltranslator/TMLChannel.java b/src/tmltranslator/TMLChannel.java index 357cf1440b..af6a3f00e0 100755 --- a/src/tmltranslator/TMLChannel.java +++ b/src/tmltranslator/TMLChannel.java @@ -58,6 +58,8 @@ public class TMLChannel extends TMLCommunicationElement { private int max; protected TMLTask origin, destination; + + private int priority; public TMLChannel(String name, Object reference) { @@ -76,6 +78,14 @@ public class TMLChannel extends TMLCommunicationElement { public TMLTask getDestinationTask() { return destination; } + + public void setPriority(int _priority) { + priority = _priority; + } + + public int getPriority() { + return priority; + } public void setSize(int _size) { size = _size; diff --git a/src/tmltranslator/TMLMapping.java b/src/tmltranslator/TMLMapping.java index 162df26cc3..ff74180e95 100755 --- a/src/tmltranslator/TMLMapping.java +++ b/src/tmltranslator/TMLMapping.java @@ -340,6 +340,14 @@ public class TMLMapping { return tmlm.getTMLTaskByName(_name); } + public TMLChannel getChannelByName(String _name) { + TMLElement tmle = tmlm.getCommunicationElementByName(_name); + if (tmle instanceof TMLChannel) { + return (TMLChannel)tmle; + } + return null; + } + public HwExecutionNode getHwExecutionNodeByName(String _name) { HwNode node = tmla.getHwNodeByName(_name); if (node instanceof HwExecutionNode) { diff --git a/src/tmltranslator/TMLMappingTextSpecification.java b/src/tmltranslator/TMLMappingTextSpecification.java index 235cc05928..3853ff8490 100755 --- a/src/tmltranslator/TMLMappingTextSpecification.java +++ b/src/tmltranslator/TMLMappingTextSpecification.java @@ -219,6 +219,9 @@ public class TMLMappingTextSpecification { if ((node != null) && (elt != null)) { tmp += "MAP " + prepareString(node.getName()) + " " + prepareString(elt.getName()) + CR; + if (elt instanceof TMLChannel) { + tmp += "SET " + prepareString(elt.getName()) + " priority " + ((TMLChannel)(elt)).getPriority() + CR; + } //tmp += "SET " + prepareString(task.getName()) + " priority " + task.getPriority() + CR; } } @@ -569,6 +572,7 @@ public class TMLMappingTextSpecification { HwExecutionNode hwnode; TMLTask task; + TMLChannel channel; HwCommunicationNode hwcommnode; TMLElement elt; @@ -640,16 +644,25 @@ public class TMLMappingTextSpecification { return -1; } - task = tmlmap.getTaskByName(_split[1]); + task = null; + channel = null; - if (task == null) { - error = "Unknown task: " + _split[1] ; + task = tmlmap.getTaskByName(_split[1]); + channel = tmlmap.getChannelByName(_split[1]); + if ((task == null) && (channel == null)) { + error = "Unknown task / channel: " + _split[1] ; addError(0, _lineNb, 0, error, _line); return -1; } if (_split[2].toUpperCase().equals("PRIORITY")) { - task.setPriority(Integer.decode(_split[3]).intValue()); + if (task != null) { + task.setPriority(Integer.decode(_split[3]).intValue()); + } else { + if (channel != null) { + channel.setPriority(Integer.decode(_split[3]).intValue()); + } + } } } // SET diff --git a/src/tmltranslator/touppaal/TML2UPPAAL.java b/src/tmltranslator/touppaal/TML2UPPAAL.java index bab5d5e6cb..08fbab6096 100755 --- a/src/tmltranslator/touppaal/TML2UPPAAL.java +++ b/src/tmltranslator/touppaal/TML2UPPAAL.java @@ -354,10 +354,30 @@ public class TML2UPPAAL { setAssignment(tr, "nb__wr = " + wc.getNbOfSamples()); // no support for multiwrite - tr1 = addTransition(template, loc, loc); - setGuard(tr1, "nb__wr>0"); - setSynchronization(tr1, "wr__" +wc.getChannel(0).getName() + "!"); - setAssignment(tr1, "nb__wr = nb__wr - 1"); + if (wc.getNbOfChannels() == 1) { + tr1 = addTransition(template, loc, loc); + setGuard(tr1, "nb__wr>0"); + setSynchronization(tr1, "wr__" +wc.getChannel(0).getName() + "!"); + setAssignment(tr1, "nb__wr = nb__wr - 1"); + } else { + loc2 = loc; + loc1 = null; + for(int k=0; k<wc.getNbOfChannels(); k++) { + if (k == (wc.getNbOfChannels()-1)) { + tr1 = addTransition(template, loc2, loc); + setAssignment(tr1, "nb__wr = nb__wr - 1"); + } else { + loc1 = addLocation(template); + tr1 = addTransition(template, loc2, loc1); + } + if (loc2 == loc) { + setGuard(tr1, "nb__wr>0"); + } + loc2 = loc1; + setGuard(tr1, "nb__wr>0"); + setSynchronization(tr1, "wr__" +wc.getChannel(k).getName() + "!"); + } + } loc1 = addLocation(template); tr2 = addTransition(template, loc, loc1); diff --git a/src/ui/GTMLModeling.java b/src/ui/GTMLModeling.java index 9ab1e9c163..0b52252a71 100755 --- a/src/ui/GTMLModeling.java +++ b/src/ui/GTMLModeling.java @@ -1841,6 +1841,12 @@ public class GTMLModeling { s = s.replaceAll("\\s", ""); s = s + "__" + artifact.getCommunicationName(); elt = tmlm.getCommunicationElementByName(s); + + if (elt instanceof TMLChannel) { + //System.out.println("Setting priority"); + ((TMLChannel)(elt)).setPriority(artifact.getPriority()); + } + if (elt != null) { map.addCommToHwCommNode(elt, (HwCommunicationNode)node); } else { diff --git a/src/ui/tmldd/TMLArchiCommunicationArtifact.java b/src/ui/tmldd/TMLArchiCommunicationArtifact.java index 73ecda3abc..47dbbb31df 100755 --- a/src/ui/tmldd/TMLArchiCommunicationArtifact.java +++ b/src/ui/tmldd/TMLArchiCommunicationArtifact.java @@ -56,7 +56,7 @@ import myutil.*; import ui.*; import ui.window.*; -public class TMLArchiCommunicationArtifact extends TGCWithoutInternalComponent implements SwallowedTGComponent { +public class TMLArchiCommunicationArtifact extends TGCWithoutInternalComponent implements SwallowedTGComponent, WithAttributes { protected int lineLength = 5; protected int textX = 5; protected int textY = 15; @@ -70,6 +70,7 @@ public class TMLArchiCommunicationArtifact extends TGCWithoutInternalComponent i protected String referenceCommunicationName = "TMLCommunication"; protected String communicationName = "name"; protected String typeName = "channel"; + protected int priority = 0; // Between 0 and 10 public TMLArchiCommunicationArtifact(int _x, int _y, int _minX, int _maxX, int _minY, int _maxY, boolean _pos, TGComponent _father, TDiagramPanel _tdp) { super(_x, _y, _minX, _maxX, _minY, _maxY, _pos, _father, _tdp); @@ -94,6 +95,10 @@ public class TMLArchiCommunicationArtifact extends TGCWithoutInternalComponent i myImageIcon = IconManager.imgic702; } + public int getPriority() { + return priority; + } + public void internalDrawing(Graphics g) { @@ -182,6 +187,8 @@ public class TMLArchiCommunicationArtifact extends TGCWithoutInternalComponent i if (dialog.getTypeName().length() != 0) { typeName = dialog.getTypeName(); } + + priority = dialog.getPriority(); if (error) { JOptionPane.showMessageDialog(frame, @@ -215,6 +222,8 @@ public class TMLArchiCommunicationArtifact extends TGCWithoutInternalComponent i StringBuffer sb = new StringBuffer("<extraparam>\n"); sb.append("<info value=\"" + value + "\" communicationName=\"" + communicationName + "\" referenceCommunicationName=\""); sb.append(referenceCommunicationName); + sb.append("\" priority=\""); + sb.append(priority); sb.append("\" typeName=\"" + typeName); sb.append("\" />\n"); sb.append("</extraparam>\n"); @@ -230,7 +239,7 @@ public class TMLArchiCommunicationArtifact extends TGCWithoutInternalComponent i Element elt; int t1id; String svalue = null, sname = null, sreferenceCommunication = null, stype = null; - String prio; + String prio = null; for(int i=0; i<nl.getLength(); i++) { n1 = nl.item(i); @@ -247,6 +256,7 @@ public class TMLArchiCommunicationArtifact extends TGCWithoutInternalComponent i sname = elt.getAttribute("communicationName"); sreferenceCommunication = elt.getAttribute("referenceCommunicationName"); stype = elt.getAttribute("typeName"); + prio = elt.getAttribute("priority"); } if (svalue != null) { value = svalue; @@ -260,12 +270,17 @@ public class TMLArchiCommunicationArtifact extends TGCWithoutInternalComponent i if (stype != null){ typeName = stype; } + + if ((prio != null) && (prio.trim().length() > 0)) { + priority = Integer.decode(prio).intValue(); + } } } } } } catch (Exception e) { + System.out.println("Channel artifact"); throw new MalformedModelingException(); } makeFullValue(); @@ -292,6 +307,10 @@ public class TMLArchiCommunicationArtifact extends TGCWithoutInternalComponent i return typeName; } + public String getAttributes() { + return "Priority = " + priority; + } + } diff --git a/src/ui/window/JDialogCommunicationArtifact.java b/src/ui/window/JDialogCommunicationArtifact.java index 38b38f4be5..806ecdc63b 100755 --- a/src/ui/window/JDialogCommunicationArtifact.java +++ b/src/ui/window/JDialogCommunicationArtifact.java @@ -66,7 +66,7 @@ public class JDialogCommunicationArtifact extends javax.swing.JDialog implements private Frame frame; private TMLArchiCommunicationArtifact artifact; - protected JComboBox referenceCommunicationName; + protected JComboBox referenceCommunicationName, priority; // Main Panel private JButton closeButton; @@ -127,6 +127,14 @@ public class JDialogCommunicationArtifact extends javax.swing.JDialog implements //referenceTaskName.setFont(new Font("times", Font.PLAIN, 12)); panel2.add(referenceCommunicationName, c1); + list = new Vector<String>(); + for(int i=0; i<11; i++) { + list.add(""+i); + } + priority = new JComboBox(list); + priority.setSelectedIndex(artifact.getPriority()); + panel2.add(priority, c1); + /*c1.gridwidth = 1; c1.gridheight = 1; c1.weighty = 1.0; @@ -239,5 +247,9 @@ public class JDialogCommunicationArtifact extends javax.swing.JDialog implements } return 0; } + + public int getPriority() { + return priority.getSelectedIndex(); + } } -- GitLab