diff --git a/src/main/java/avatartranslator/AvatarBlockTemplate.java b/src/main/java/avatartranslator/AvatarBlockTemplate.java index 8453a61001703c50593907491104fd689a74ad63..054d02d7774f48de0f01f74f1bc7e0a4b0575e13 100644 --- a/src/main/java/avatartranslator/AvatarBlockTemplate.java +++ b/src/main/java/avatartranslator/AvatarBlockTemplate.java @@ -151,6 +151,7 @@ public class AvatarBlockTemplate { AvatarBlock ab = new AvatarBlock(_name, _avspec, _referenceRelation); ab.setName(_name); + // Create the read and write signals AvatarSignal write = new AvatarSignal("write", AvatarSignal.IN, _referenceRelation); AvatarSignal read = new AvatarSignal("read", AvatarSignal.OUT, _referenceRelation); @@ -160,51 +161,6 @@ public class AvatarBlockTemplate { ab.addSignal(read); // corresponds to sig2 ab.addSignal(queryS); - - // Creating the attributes of the signals - // Same attributes for all signals - for (AvatarAttribute aa : _sig1.getListOfAttributes()) { - write.addParameter(aa.advancedClone(null)); - } - for (AvatarAttribute aa : _sig2.getListOfAttributes()) { - read.addParameter(aa.advancedClone(null)); - } - - AvatarAttribute queryA = new AvatarAttribute("queryA", AvatarType.INTEGER, ab, _referenceRelation); - ab.addAttribute(queryA); - queryS.addParameter(queryA.advancedClone(null)); - - - - // Creating the attributes to support the FIFO - // For each parameter, we create an attribute that is similar to the one of e.g. sig1 - // We duplicate this for the size of the fifo - for (AvatarAttribute aa : _sig1.getListOfAttributes()) { - for (int i = 0; i < _sizeOfFifo; i++) { - AvatarAttribute newA = aa.advancedClone(null); - newA.setName("arg_" + aa.getName() + "_" + i); - ab.addAttribute(newA); - } - } - - // If lossy, add corresponding lossy attributes - if (_ar.isLossy()) { - for (AvatarAttribute aa : _sig1.getListOfAttributes()) { - AvatarAttribute newL = aa.advancedClone(null); - newL.setName("loss_" + aa.getName()); - ab.addAttribute(newL); - } - } - - // If non blocking, then, we need extra attributes - if (!(_ar.isBlocking())) { - for (AvatarAttribute aa : _sig1.getListOfAttributes()) { - AvatarAttribute newL = aa.advancedClone(null); - newL.setName("bucket_" + aa.getName()); - ab.addAttribute(newL); - } - } - // We create the attribute to manage the FIFO AvatarAttribute size = new AvatarAttribute("size", AvatarType.INTEGER, ab, _referenceRelation); size.setInitialValue("0"); @@ -215,23 +171,17 @@ public class AvatarBlockTemplate { maxSize.setInitialValue("" + _sizeOfFifo); ab.addAttribute(maxSize); - // Where we write: the head - AvatarAttribute head = new AvatarAttribute("head", AvatarType.INTEGER, ab, _referenceRelation); - head.setInitialValue("0"); - ab.addAttribute(head); - - // Where we read: the tail - AvatarAttribute tail = new AvatarAttribute("tail", AvatarType.INTEGER, ab, _referenceRelation); - tail.setInitialValue("0"); - ab.addAttribute(tail); - + // Atrribute for query signal + AvatarAttribute queryA = new AvatarAttribute("queryA", AvatarType.INTEGER, ab, _referenceRelation); + ab.addAttribute(queryA); + queryS.addParameter(queryA.advancedClone(null)); - // Creating the state machine - // Don't forget the isLossy AvatarTransition at; AvatarStateMachine asm = ab.getStateMachine(); + + // Start state AvatarStartState ass = new AvatarStartState("start", _referenceRelation); asm.setStartState(ass); @@ -242,73 +192,179 @@ public class AvatarBlockTemplate { asm.addElement(main); at = makeAvatarEmptyTransitionBetween(ab, asm, ass, main, _referenceRelation); + // Two cases: signals have paremeters or not + // In the first case : simply model + // In the second case: complex handling - // Can write only if fifo is not full only if transition - AvatarState testHead = new AvatarState("testHead", _referenceRelation); - asm.addElement(testHead); - at = makeAvatarEmptyTransitionBetween(ab, asm, testHead, main, _referenceRelation); - at.setGuard("[head<maxSize]"); - at = makeAvatarEmptyTransitionBetween(ab, asm, testHead, main, _referenceRelation); - at.setGuard("[head==maxSize]"); - at.addAction("head=0"); - for (int i = 0; i < _sizeOfFifo; i++) { - AvatarActionOnSignal aaos_write = new AvatarActionOnSignal("write_" + i, write, _referenceRelation); - for (AvatarAttribute aa : _sig1.getListOfAttributes()) { - aaos_write.addValue("arg_" + aa.getName() + "_" + i); - } + + + if ( (_sig1.getListOfAttributes().size() == 0) ) { + + // Write + AvatarActionOnSignal aaos_write = new AvatarActionOnSignal("write_elt", write, _referenceRelation); asm.addElement(aaos_write); at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaos_write, _referenceRelation); - at.setGuard("[(size < maxSize) && (head==" + i + ")]"); - at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_write, testHead, _referenceRelation); - at.addAction("head = head + 1"); + at.setGuard("[(size < maxSize)]"); + at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_write, main, _referenceRelation); at.addAction("size = size + 1"); - } - // if is lossy, can write, and does not store this nor increase the fifo size - if (_ar.isLossy()) { - AvatarActionOnSignal aaos_write_loss = new AvatarActionOnSignal("writeloss_", write, _referenceRelation); - for (AvatarAttribute aa : _sig1.getListOfAttributes()) { - aaos_write_loss.addValue("loss_" + aa.getName()); + if (!_ar.isBlocking()) { + AvatarActionOnSignal aaos_write_bucket = new AvatarActionOnSignal("write_elt_bucket", write, _referenceRelation); + asm.addElement(aaos_write_bucket); + at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaos_write_bucket, _referenceRelation); + at.setGuard("[(size == maxSize)]"); + at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_write_bucket, main, _referenceRelation); } - asm.addElement(aaos_write_loss); - at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaos_write_loss, _referenceRelation); - at.setGuard("[(size < maxSize)]"); - at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_write_loss, main, _referenceRelation); - } - /// If maxSize has been reached - // If it is blocking, then, the new message is written but not added - if (!(_ar.isBlocking())) { - AvatarActionOnSignal aaos_write_bucket = new AvatarActionOnSignal("writebucket_", write, _referenceRelation); + if (_ar.isLossy()) { + AvatarActionOnSignal aaos_write_loss = new AvatarActionOnSignal("write_elt_loss", write, _referenceRelation); + asm.addElement(aaos_write_loss); + at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaos_write_loss, _referenceRelation); + at.setGuard("[(size < maxSize)]"); + at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_write_loss, main, _referenceRelation); + } + + // read + AvatarActionOnSignal aaos_read = new AvatarActionOnSignal("read_elt", read, _referenceRelation); + asm.addElement(aaos_read); + at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaos_read, _referenceRelation); + at.setGuard("[(size > 0)]"); + at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_read, main, _referenceRelation); + at.addAction("size = size - 1"); + + } else { + + // Creating the attributes of the signals + // Same attributes for all signals for (AvatarAttribute aa : _sig1.getListOfAttributes()) { - aaos_write_bucket.addValue("bucket_" + aa.getName()); + write.addParameter(aa.advancedClone(null)); + } + for (AvatarAttribute aa : _sig2.getListOfAttributes()) { + read.addParameter(aa.advancedClone(null)); } - asm.addElement(aaos_write_bucket); - at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaos_write_bucket, _referenceRelation); - at.setGuard("[(size == maxSize)]"); - at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_write_bucket, main, _referenceRelation); - } - // Read - AvatarState testTail = new AvatarState("testTail", _referenceRelation); - asm.addElement(testTail); - at = makeAvatarEmptyTransitionBetween(ab, asm, testTail, main, _referenceRelation); - at.setGuard("[tail<maxSize]"); - at = makeAvatarEmptyTransitionBetween(ab, asm, testTail, main, _referenceRelation); - at.setGuard("[tail==maxSize]"); - at.addAction("tail=0"); - for (int i = 0; i < _sizeOfFifo; i++) { - AvatarActionOnSignal aaos_read = new AvatarActionOnSignal("read_" + i, read, _referenceRelation); + // Creating the attributes to support the FIFO + // For each parameter, we create an attribute that is similar to the one of e.g. sig1 + // We duplicate this for the size of the fifo for (AvatarAttribute aa : _sig1.getListOfAttributes()) { - aaos_read.addValue("arg_" + aa.getName() + "_" + i); + for (int i = 0; i < _sizeOfFifo; i++) { + AvatarAttribute newA = aa.advancedClone(null); + newA.setName("arg_" + aa.getName() + "_" + i); + ab.addAttribute(newA); + } } - asm.addElement(aaos_read); - at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaos_read, _referenceRelation); - at.setGuard("[(size > 0) && (tail==" + i + ")]"); - at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_read, testTail, _referenceRelation); + + // If lossy, add corresponding lossy attributes + if (_ar.isLossy()) { + for (AvatarAttribute aa : _sig1.getListOfAttributes()) { + AvatarAttribute newL = aa.advancedClone(null); + newL.setName("loss_" + aa.getName()); + ab.addAttribute(newL); + } + } + + // If non blocking, then, we need extra attributes + if (!(_ar.isBlocking())) { + for (AvatarAttribute aa : _sig1.getListOfAttributes()) { + AvatarAttribute newL = aa.advancedClone(null); + newL.setName("bucket_" + aa.getName()); + ab.addAttribute(newL); + } + } + + // Where we write: the head + AvatarAttribute head = new AvatarAttribute("head", AvatarType.INTEGER, ab, _referenceRelation); + head.setInitialValue("0"); + ab.addAttribute(head); + + // Where we read: the tail + AvatarAttribute tail = new AvatarAttribute("tail", AvatarType.INTEGER, ab, _referenceRelation); + tail.setInitialValue("0"); + ab.addAttribute(tail); + + + // Creating the state machine + // Don't forget the isLossy + + + // Can write only if fifo is not full only if transition + AvatarState testHead = new AvatarState("testHead", _referenceRelation); + asm.addElement(testHead); + at = makeAvatarEmptyTransitionBetween(ab, asm, testHead, main, _referenceRelation); + at.addAction("head = head + 1"); + at.addAction("size = size + 1"); + at.setGuard("[head<(maxSize-1)]"); + at = makeAvatarEmptyTransitionBetween(ab, asm, testHead, main, _referenceRelation); + at.setGuard("[head==(maxSize-1)]"); + at.addAction("head=0"); + at.addAction("size = size + 1"); + + for (int i = 0; i < _sizeOfFifo; i++) { + AvatarActionOnSignal aaos_write = new AvatarActionOnSignal("write_" + i, write, _referenceRelation); + for (AvatarAttribute aa : _sig1.getListOfAttributes()) { + aaos_write.addValue("arg_" + aa.getName() + "_" + i); + } + asm.addElement(aaos_write); + at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaos_write, _referenceRelation); + at.setGuard("[(size < maxSize) && (head==" + i + ")]"); + at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_write, testHead, _referenceRelation); + //at.addAction("head = head + 1"); + //at.addAction("size = size + 1"); + + } + // if is lossy, can write, and does not store this nor increase the fifo size + if (_ar.isLossy()) { + AvatarActionOnSignal aaos_write_loss = new AvatarActionOnSignal("writeloss_", write, _referenceRelation); + for (AvatarAttribute aa : _sig1.getListOfAttributes()) { + aaos_write_loss.addValue("loss_" + aa.getName()); + } + asm.addElement(aaos_write_loss); + at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaos_write_loss, _referenceRelation); + at.setGuard("[(size < maxSize)]"); + at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_write_loss, main, _referenceRelation); + } + + /// If maxSize has been reached + // If it is blocking, then, the new message is written but not added + if (!(_ar.isBlocking())) { + AvatarActionOnSignal aaos_write_bucket = new AvatarActionOnSignal("writebucket_", write, _referenceRelation); + for (AvatarAttribute aa : _sig1.getListOfAttributes()) { + aaos_write_bucket.addValue("bucket_" + aa.getName()); + } + asm.addElement(aaos_write_bucket); + at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaos_write_bucket, _referenceRelation); + at.setGuard("[(size == maxSize)]"); + at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_write_bucket, main, _referenceRelation); + } + + // Read + AvatarState testTail = new AvatarState("testTail", _referenceRelation); + asm.addElement(testTail); + at = makeAvatarEmptyTransitionBetween(ab, asm, testTail, main, _referenceRelation); + at.setGuard("[tail<(maxSize-1)]"); at.addAction("tail = tail + 1"); at.addAction("size = size - 1"); + at = makeAvatarEmptyTransitionBetween(ab, asm, testTail, main, _referenceRelation); + at.setGuard("[tail==(maxSize-1)]"); + at.addAction("tail=0"); + at.addAction("size = size - 1"); + for (int i = 0; i < _sizeOfFifo; i++) { + AvatarActionOnSignal aaos_read = new AvatarActionOnSignal("read_" + i, read, _referenceRelation); + for (AvatarAttribute aa : _sig1.getListOfAttributes()) { + aaos_read.addValue("arg_" + aa.getName() + "_" + i); + } + asm.addElement(aaos_read); + at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaos_read, _referenceRelation); + at.setGuard("[(size > 0) && (tail==" + i + ")]"); + at = makeAvatarEmptyTransitionBetween(ab, asm, aaos_read, testTail, _referenceRelation); + //at.addAction("tail = tail + 1"); + //at.addAction("size = size - 1"); + } + + + + // Complex block is finished! } // Query @@ -318,7 +374,6 @@ public class AvatarBlockTemplate { at = makeAvatarEmptyTransitionBetween(ab, asm, main, aaosQuery, _referenceRelation); at = makeAvatarEmptyTransitionBetween(ab, asm, aaosQuery, main, _referenceRelation); - // Block is finished! return ab; } diff --git a/src/main/java/tmltranslator/toavatar/FullTML2Avatar.java b/src/main/java/tmltranslator/toavatar/FullTML2Avatar.java index ae4b3b64cbab2a5851645838abad9bdca588ad40..03734756e280a753b870c0aa5b2db4ba55f1af65 100644 --- a/src/main/java/tmltranslator/toavatar/FullTML2Avatar.java +++ b/src/main/java/tmltranslator/toavatar/FullTML2Avatar.java @@ -564,14 +564,14 @@ public class FullTML2Avatar { ar = new AvatarRelation(channel.getName(), taskBlockMap.get(channel.getOriginTask()), taskBlockMap.get(channel .getDestinationTask()), channel.getReferenceObject()); ar.setAsynchronous(true); - ar.setSizeOfFIFO(channel.getSize()); + ar.setSizeOfFIFO(channel.getMax()); ar.setBlocking(true); ar.setPrivate(true); } else if (channel.getType() == TMLChannel.BRNBW) { ar = new AvatarRelation(channel.getName(), taskBlockMap.get(channel.getOriginTask()), taskBlockMap.get(channel .getDestinationTask()), channel.getReferenceObject()); ar.setAsynchronous(true); - ar.setSizeOfFIFO(channel.getSize()); + ar.setSizeOfFIFO(channel.getMax()); ar.setBlocking(false); ar.setPrivate(true); } else { diff --git a/src/main/java/ui/TGUIAction.java b/src/main/java/ui/TGUIAction.java index 23f56162b33baaab56b27d927d4c125f8f0d0bff..0de491cadf6d2755bb090b2dcd8fb4406a994545 100644 --- a/src/main/java/ui/TGUIAction.java +++ b/src/main/java/ui/TGUIAction.java @@ -1090,7 +1090,7 @@ public class TGUIAction extends AbstractAction { "Add a dependency matrix to the currently opened TTool diagram", 0); actions[PRAGMA] = new TAction("pragma", "Security pragmas", IconManager.imgic6000, IconManager.imgic6001, "Security pragmas", "Add security pragmas to the currently opened TTool diagram", 0); - actions[SAFETY_PRAGMA] = new TAction("safety_pragma", "Add a safety (UPPAAL) property to a diagram", IconManager.imgic6002, IconManager.imgic6003, "Safety property (UPPAAL)", "Add a safety (UPPAAL) property to the currently opened TTool diagram", 0); + actions[SAFETY_PRAGMA] = new TAction("safety_pragma", "Add a safety property to a diagram", IconManager.imgic6002, IconManager.imgic6003, "Safety property", "Add a safety property to the currently opened TTool diagram", 0); actions[TML_PRAGMA] = new TAction("tml_pragma", "Add a TML pragma", IconManager.imgic6006, IconManager.imgic6007,"TML pragma", "Add a TML pragma to the currently opened TTool diagram", 0); actions[PERFORMANCE_PRAGMA] = new TAction("performance_pragma", "Add a performance property to a diagram", IconManager.imgic6004, IconManager.imgic6005, "Performance property", "Add a performance property to the currently opened TTool diagram", 0); actions[AVATAR_FIREWALL] = new TAction("avatar_firewall", "Add an avatar firewall to a diagram", IconManager.imgic7001, IconManager.imgic7001, "Add an avatar firewall", "Add an avatar firewall to the currently opened TTool diagram", 0); diff --git a/src/main/java/ui/graphd/GraphDPanel.java b/src/main/java/ui/graphd/GraphDPanel.java index f882ffc21b309acadac316fa17aad62d2efed2b5..4e27c8c1664a13c556430a81501e2902ee62abef 100644 --- a/src/main/java/ui/graphd/GraphDPanel.java +++ b/src/main/java/ui/graphd/GraphDPanel.java @@ -289,14 +289,15 @@ public class GraphDPanel extends TDiagramPanel implements TDPWithAttributes, Run } // Blue for comm states - if (info.contains("Sending ")) { - dv.setCurrentColor(ColorManager.TML_COMPOSITE_COMPONENT); - } else if (info.contains("Receiving ")) { - dv.setCurrentColor(ColorManager.BUS_BOX); + if (info != null) { + if (info.contains("Sending ") || info.contains("!")) { + dv.setCurrentColor(ColorManager.TML_COMPOSITE_COMPONENT); + } else if (info.contains("Receiving ") || info.contains("?")) { + dv.setCurrentColor(ColorManager.BUS_BOX); + } } - - + return dv; }