method for accessing event central + include mote when notifying simulation observers that a mote was added/removed

This commit is contained in:
fros4943 2009-07-02 12:04:28 +00:00
parent f13a313a7d
commit 9b164adc35
1 changed files with 20 additions and 10 deletions

View File

@ -24,17 +24,22 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: Simulation.java,v 1.48 2009/06/24 07:56:15 fros4943 Exp $ * $Id: Simulation.java,v 1.49 2009/07/02 12:04:28 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
import java.util.*; import java.util.ArrayList;
import org.apache.log4j.Logger; import java.util.Collection;
import org.jdom.*; import java.util.Observable;
import java.util.Observer;
import java.util.Random;
import java.util.Vector;
import se.sics.cooja.contikimote.ContikiMote; import org.apache.log4j.Logger;
import se.sics.cooja.dialogs.*; import org.jdom.Element;
import se.sics.cooja.dialogs.CreateSimDialog;
/** /**
* A simulation consists of a number of motes and mote types. * A simulation consists of a number of motes and mote types.
@ -396,6 +401,11 @@ public class Simulation extends Observable implements Runnable {
this.maxMoteStartupDelay = Math.max(0, maxMoteStartupDelay); this.maxMoteStartupDelay = Math.max(0, maxMoteStartupDelay);
} }
private SimEventCentral eventCentral = new SimEventCentral(this);
public SimEventCentral getEventCentral() {
return eventCentral;
}
/** /**
* Returns the current simulation config represented by XML elements. This * Returns the current simulation config represented by XML elements. This
* config also includes the current radio medium, all mote types and motes. * config also includes the current radio medium, all mote types and motes.
@ -608,6 +618,8 @@ public class Simulation extends Observable implements Runnable {
public void execute(long t) { public void execute(long t) {
motes.remove(mote); motes.remove(mote);
currentRadioMedium.unregisterMote(mote, Simulation.this); currentRadioMedium.unregisterMote(mote, Simulation.this);
setChanged();
notifyObservers(mote);
/* Loop through all scheduled events. /* Loop through all scheduled events.
* Delete all events associated with deleted mote. */ * Delete all events associated with deleted mote. */
@ -623,8 +635,6 @@ public class Simulation extends Observable implements Runnable {
} }
recreateMoteLists(); recreateMoteLists();
Simulation.this.setChanged();
Simulation.this.notifyObservers(this);
} }
}; };
@ -656,7 +666,7 @@ public class Simulation extends Observable implements Runnable {
motes.add(mote); motes.add(mote);
currentRadioMedium.registerMote(mote, this); currentRadioMedium.registerMote(mote, this);
this.setChanged(); this.setChanged();
this.notifyObservers(this); this.notifyObservers(mote);
return; return;
} }
@ -667,7 +677,7 @@ public class Simulation extends Observable implements Runnable {
currentRadioMedium.registerMote(mote, Simulation.this); currentRadioMedium.registerMote(mote, Simulation.this);
recreateMoteLists(); recreateMoteLists();
Simulation.this.setChanged(); Simulation.this.setChanged();
Simulation.this.notifyObservers(this); Simulation.this.notifyObservers(mote);
} }
public String toString() { public String toString() {
return "ADD MOTE"; return "ADD MOTE";