decoupled sectionmemory and addressmemory.

This commit is contained in:
fros4943 2007-02-02 11:02:14 +00:00
parent 291545bd15
commit 3eef58750c
3 changed files with 127 additions and 60 deletions

View file

@ -0,0 +1,115 @@
/*
* Copyright (c) 2006, Swedish Institute of Computer Science. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of the
* Institute nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (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: AddressMemory.java,v 1.1 2007/02/02 11:02:14 fros4943 Exp $
*/
package se.sics.cooja;
public interface AddressMemory {
/**
* @return All variable names known and residing in this memory
*/
public String[] getVariableNames();
/**
* Checks if given variable exists in memory.
*
* @param varName Variable name
* @return True if variable exists, false otherwise
*/
public boolean variableExists(String varName);
/**
* Returns address of variable with given name.
*
* @param varName
* Variable name
* @return Address of given variable, or -1
*/
public int getVariableAddress(String varName);
/**
* Returns a value of the byte variable with the given name.
*
* @param varName
* Name of byte variable
* @return Value of byte variable
*/
public byte getByteValueOf(String varName);
/**
* Set byte value of variable with given name.
*
* @param varName
* Name of byte variable
* @param newVal
* New value to set
*/
public void setByteValueOf(String varName, byte newVal);
/**
* Returns byte array of given length and with the given name.
*
* @param varName
* Name of array
* @param length
* Length of array
* @return Data of array
*/
public byte[] getByteArray(String varName, int length);
/**
* Set byte array of the variable with the given name.
*
* @param varName
* Name of array
* @param data
* New data of array
*/
public void setByteArray(String varName, byte[] data);
/**
* Returns a value of the integer variable with the given name.
*
* @param varName
* Name of integer variable
* @return Value of integer variable
*/
public int getIntValueOf(String varName);
/**
* Set integer value of variable with given name.
*
* @param varName
* Name of integer variable
* @param newVal
* New value to set
*/
public void setIntValueOf(String varName, int newVal);
}

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: SectionMoteMemory.java,v 1.4 2007/01/10 14:57:42 fros4943 Exp $ * $Id: SectionMoteMemory.java,v 1.5 2007/02/02 11:02:15 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -46,7 +46,7 @@ import se.sics.cooja.MoteMemory;
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
public class SectionMoteMemory implements MoteMemory { public class SectionMoteMemory implements MoteMemory, AddressMemory {
private static Logger logger = Logger.getLogger(SectionMoteMemory.class); private static Logger logger = Logger.getLogger(SectionMoteMemory.class);
private Vector<MoteMemorySection> sections = new Vector<MoteMemorySection>(); private Vector<MoteMemorySection> sections = new Vector<MoteMemorySection>();
@ -64,9 +64,6 @@ public class SectionMoteMemory implements MoteMemory {
this.variableAddresses = variableAddresses; this.variableAddresses = variableAddresses;
} }
/**
* @return All variable names known and residing in this memory
*/
public String[] getVariableNames() { public String[] getVariableNames() {
String[] names = new String[variableAddresses.size()]; String[] names = new String[variableAddresses.size()];
Enumeration nameEnum = variableAddresses.keys(); Enumeration nameEnum = variableAddresses.keys();
@ -76,11 +73,6 @@ public class SectionMoteMemory implements MoteMemory {
return names; return names;
} }
/**
* @param varName
* Variable name
* @return Address of given variable, or -1
*/
public int getVariableAddress(String varName) { public int getVariableAddress(String varName) {
if (!variableAddresses.containsKey(varName)) if (!variableAddresses.containsKey(varName))
return -1; return -1;
@ -207,13 +199,10 @@ public class SectionMoteMemory implements MoteMemory {
return sections.elementAt(sectionNr).getData(); return sections.elementAt(sectionNr).getData();
} }
/** public boolean variableExists(String varName) {
* Returns a value of the integer variable with the given name. return variableAddresses.containsKey(varName);
* }
* @param varName
* Name of integer variable
* @return Value of integer variable
*/
public int getIntValueOf(String varName) { public int getIntValueOf(String varName) {
// Get start address of variable // Get start address of variable
if (!variableAddresses.containsKey(varName)) if (!variableAddresses.containsKey(varName))
@ -235,14 +224,6 @@ public class SectionMoteMemory implements MoteMemory {
return retVal; return retVal;
} }
/**
* Set integer value of variable with given name.
*
* @param varName
* Name of integer variable
* @param newVal
* New value to set
*/
public void setIntValueOf(String varName, int newVal) { public void setIntValueOf(String varName, int newVal) {
// Get start address of variable // Get start address of variable
if (!variableAddresses.containsKey(varName)) if (!variableAddresses.containsKey(varName))
@ -264,13 +245,6 @@ public class SectionMoteMemory implements MoteMemory {
setMemorySegment(varAddr, varData); setMemorySegment(varAddr, varData);
} }
/**
* Returns a value of the byte variable with the given name.
*
* @param varName
* Name of byte variable
* @return Value of byte variable
*/
public byte getByteValueOf(String varName) { public byte getByteValueOf(String varName) {
// Get start address of variable // Get start address of variable
if (!variableAddresses.containsKey(varName)) if (!variableAddresses.containsKey(varName))
@ -282,14 +256,6 @@ public class SectionMoteMemory implements MoteMemory {
return varData[0]; return varData[0];
} }
/**
* Set byte value of variable with given name.
*
* @param varName
* Name of byte variable
* @param newVal
* New value to set
*/
public void setByteValueOf(String varName, byte newVal) { public void setByteValueOf(String varName, byte newVal) {
// Get start address of variable // Get start address of variable
if (!variableAddresses.containsKey(varName)) if (!variableAddresses.containsKey(varName))
@ -303,15 +269,6 @@ public class SectionMoteMemory implements MoteMemory {
setMemorySegment(varAddr, varData); setMemorySegment(varAddr, varData);
} }
/**
* Returns byte array of given length and with the given name.
*
* @param varName
* Name of array
* @param length
* Length of array
* @return Data of array
*/
public byte[] getByteArray(String varName, int length) { public byte[] getByteArray(String varName, int length) {
// Get start address of variable // Get start address of variable
if (!variableAddresses.containsKey(varName)) if (!variableAddresses.containsKey(varName))
@ -322,14 +279,6 @@ public class SectionMoteMemory implements MoteMemory {
return getMemorySegment(varAddr, length); return getMemorySegment(varAddr, length);
} }
/**
* Set byte array of the variable with the given name.
*
* @param varName
* Name of array
* @param data
* New data of array
*/
public void setByteArray(String varName, byte[] data) { public void setByteArray(String varName, byte[] data) {
// Get start address of variable // Get start address of variable
if (!variableAddresses.containsKey(varName)) if (!variableAddresses.containsKey(varName))

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: VariableWatcher.java,v 1.3 2007/01/09 09:49:24 fros4943 Exp $ * $Id: VariableWatcher.java,v 1.4 2007/02/02 11:02:16 fros4943 Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
@ -55,7 +55,7 @@ import se.sics.cooja.*;
public class VariableWatcher extends VisPlugin { public class VariableWatcher extends VisPlugin {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private SectionMoteMemory moteMemory; private AddressMemory moteMemory;
private final static int LABEL_WIDTH = 170; private final static int LABEL_WIDTH = 170;
private final static int LABEL_HEIGHT = 15; private final static int LABEL_HEIGHT = 15;
@ -82,7 +82,10 @@ public class VariableWatcher extends VisPlugin {
public VariableWatcher(Mote moteToView, Simulation simulation, GUI gui) { public VariableWatcher(Mote moteToView, Simulation simulation, GUI gui) {
super("Variable Watcher (" + moteToView + ")", gui); super("Variable Watcher (" + moteToView + ")", gui);
moteMemory = (SectionMoteMemory) moteToView.getMemory(); System.out.println("?!!");
moteMemory = (AddressMemory) moteToView.getMemory();
System.out.println("?!!");
JLabel label; JLabel label;
integerFormat = NumberFormat.getIntegerInstance(); integerFormat = NumberFormat.getIntegerInstance();