From ece7919f4933aff0c5d10de6aec4a3e437b62655 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Tue, 12 Oct 2010 10:58:31 +0000 Subject: [PATCH] added removed()-method for mote objects --- tools/cooja/java/se/sics/cooja/Mote.java | 6 +++++- tools/cooja/java/se/sics/cooja/Simulation.java | 9 +++++++-- .../java/se/sics/cooja/motes/AbstractWakeupMote.java | 4 +++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/Mote.java b/tools/cooja/java/se/sics/cooja/Mote.java index f29f40edb..80bad9ab1 100644 --- a/tools/cooja/java/se/sics/cooja/Mote.java +++ b/tools/cooja/java/se/sics/cooja/Mote.java @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: Mote.java,v 1.8 2010/02/03 16:05:49 fros4943 Exp $ + * $Id: Mote.java,v 1.9 2010/10/12 10:58:31 fros4943 Exp $ */ package se.sics.cooja; @@ -144,4 +144,8 @@ public interface Mote { public abstract boolean setConfigXML(Simulation simulation, Collection configXML, boolean visAvailable); + /** + * Called when mote is removed from simulation + */ + public void removed(); } diff --git a/tools/cooja/java/se/sics/cooja/Simulation.java b/tools/cooja/java/se/sics/cooja/Simulation.java index 0f52fe781..0fabe7b66 100644 --- a/tools/cooja/java/se/sics/cooja/Simulation.java +++ b/tools/cooja/java/se/sics/cooja/Simulation.java @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: Simulation.java,v 1.66 2010/10/04 10:11:56 nifi Exp $ + * $Id: Simulation.java,v 1.67 2010/10/12 10:58:31 fros4943 Exp $ */ package se.sics.cooja; @@ -662,7 +662,11 @@ public class Simulation extends Observable implements Runnable { /* Create mote using mote type */ Mote mote = moteType.generateMote(this); if (mote.setConfigXML(this, element.getChildren(), visAvailable)) { - addMote(mote); + if (getMoteWithID(mote.getID()) != null) { + logger.warn("Ignoring duplicate mote ID: " + mote.getID()); + } else { + addMote(mote); + } } else { logger.fatal("Mote was not created: " + element.getText().trim()); throw new Exception("All motes were not recreated"); @@ -690,6 +694,7 @@ public class Simulation extends Observable implements Runnable { currentRadioMedium.unregisterMote(mote, Simulation.this); /* Dispose mote interface resources */ + mote.removed(); for (MoteInterface i: mote.getInterfaces().getInterfaces()) { i.removed(); } diff --git a/tools/cooja/java/se/sics/cooja/motes/AbstractWakeupMote.java b/tools/cooja/java/se/sics/cooja/motes/AbstractWakeupMote.java index 7e306e1b7..f5113f524 100644 --- a/tools/cooja/java/se/sics/cooja/motes/AbstractWakeupMote.java +++ b/tools/cooja/java/se/sics/cooja/motes/AbstractWakeupMote.java @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: AbstractWakeupMote.java,v 1.2 2010/10/04 12:54:01 joxe Exp $ + * $Id: AbstractWakeupMote.java,v 1.3 2010/10/12 10:58:31 fros4943 Exp $ */ package se.sics.cooja.motes; @@ -128,4 +128,6 @@ public abstract class AbstractWakeupMote implements Mote { return true; } + public void removed() { + } }