bug fix. only registering when interface exists

This commit is contained in:
fros4943 2007-01-26 15:12:00 +00:00
parent 2604c891e1
commit f4ff1061c5

View file

@ -24,7 +24,7 @@
* (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: EventListener.java,v 1.3 2007/01/26 14:39:54 fros4943 Exp $ * $Id: EventListener.java,v 1.4 2007/01/26 15:12:00 fros4943 Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
@ -251,7 +251,9 @@ public class EventListener extends VisPlugin {
if (!shouldObserve) { if (!shouldObserve) {
// Remove existing observers // Remove existing observers
for (EventObserver obs : allObservers.toArray(new EventObserver[0])) { for (EventObserver obs : allObservers.toArray(new EventObserver[0])) {
if (obs.getObservable().getClass() == interfaceClass) { Class<? extends Observable> objClass = obs.getObservable().getClass();
if (objClass == interfaceClass ||
interfaceClass.isAssignableFrom(objClass)) {
obs.detachFromObject(); obs.detachFromObject();
allObservers.remove(obs); allObservers.remove(obs);
} }
@ -261,8 +263,10 @@ public class EventListener extends VisPlugin {
for (int i = 0; i < mySimulation.getMotesCount(); i++) { for (int i = 0; i < mySimulation.getMotesCount(); i++) {
MoteInterface moteInterface = mySimulation.getMote(i).getInterfaces() MoteInterface moteInterface = mySimulation.getMote(i).getInterfaces()
.getInterfaceOfType(interfaceClass); .getInterfaceOfType(interfaceClass);
allObservers.add(new InterfaceEventObserver(myPlugin, mySimulation if (moteInterface != null) {
.getMote(i), moteInterface)); allObservers.add(new InterfaceEventObserver(myPlugin, mySimulation
.getMote(i), moteInterface));
}
} }
} }
} }