[cooja] memory: Removed MoteMemory class including all references

This commit is contained in:
Enrico Joerns 2014-07-23 10:12:19 +02:00
parent 9dd29d56c9
commit 482dab5d16
10 changed files with 127 additions and 257 deletions

View file

@ -1,90 +0,0 @@
/*
* 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.
*
*/
package org.contikios.cooja;
/**
* This interface represents a mote memory.
*
* Mote memory is represented by byte arrays and this
* interface provides a few of basic operations.
*
* Note that this memory internally may consist of several
* different memory sections, not covering the entire range
* between the start address and the end address of this memory.
*
* @see org.contikios.cooja.SectionMoteMemory
* @author Fredrik Osterlind
*/
public interface MoteMemory extends AddressMemory {
/**
* Clears the entire memory.
*/
public void clearMemory();
/**
* Returns a memory segment.
*
* @param address Start address of memory segment
* @param size Size of memory segment
* @return Memory segment or null if segment not available
*/
public byte[] getMemorySegment(int address, int size);
/**
* Sets a memory segment.
*
* @param address Start address of memory segment
* @param data Data
*/
public void setMemorySegment(int address, byte[] data);
/**
* Returns the sum of all byte array sizes in this memory.
* This is not neccessarily the the same as the total memory range,
* since the entire memory range may not be handled by this memory.
*
* @return Total size
*/
public int getTotalSize();
public abstract int parseInt(byte[] memorySegment);
public enum MemoryEventType { READ, WRITE };
public interface MemoryMonitor {
public void memoryChanged(MoteMemory memory, MemoryEventType type, int address);
}
public boolean addMemoryMonitor(int address, int size, MemoryMonitor mm);
public void removeMemoryMonitor(int address, int size, MemoryMonitor mm);
}

View file

@ -46,7 +46,7 @@ import org.contikios.cooja.mote.memory.MemoryLayout;
*
* @author Fredrik Osterlind
*/
public class SectionMoteMemory implements MemoryInterface, MoteMemory, AddressMemory {
public class SectionMoteMemory implements MemoryInterface, AddressMemory {
private static Logger logger = Logger.getLogger(SectionMoteMemory.class);
private ArrayList<MoteMemorySection> sections = new ArrayList<MoteMemorySection>();
@ -94,48 +94,48 @@ public class SectionMoteMemory implements MemoryInterface, MoteMemory, AddressMe
sections.clear();
}
@Override
public byte[] getMemorySegment(int address, int size) {
/* Cooja address space */
address -= offset;
for (MoteMemorySection section : sections) {
if (section.includesAddr(address)
&& section.includesAddr(address + size - 1)) {
return section.getMemorySegment(address, size);
}
}
/* Check if in readonly section */
for (MoteMemorySection section : readonlySections) {
if (section.includesAddr(address)
&& section.includesAddr(address + size - 1)) {
return section.getMemorySegment(address, size);
}
}
return null;
}
// @Override
// public byte[] getMemorySegment(int address, int size) {
// /* Cooja address space */
// address -= offset;
//
// for (MoteMemorySection section : sections) {
// if (section.includesAddr(address)
// && section.includesAddr(address + size - 1)) {
// return section.getMemorySegment(address, size);
// }
// }
//
// /* Check if in readonly section */
// for (MoteMemorySection section : readonlySections) {
// if (section.includesAddr(address)
// && section.includesAddr(address + size - 1)) {
// return section.getMemorySegment(address, size);
// }
// }
//
// return null;
// }
public void setMemorySegmentNative(int address, byte[] data) {
setMemorySegment(address+offset, data);
}
@Override
public void setMemorySegment(int address, byte[] data) {
/* Cooja address space */
address -= offset;
/* TODO XXX Sections may overlap */
for (MoteMemorySection section : sections) {
if (section.includesAddr(address)
&& section.includesAddr(address + data.length - 1)) {
section.setMemorySegment(address, data);
return;
}
}
sections.add(new MoteMemorySection(address, data));
}
// @Override
// public void setMemorySegment(int address, byte[] data) {
// /* Cooja address space */
// address -= offset;
//
// /* TODO XXX Sections may overlap */
// for (MoteMemorySection section : sections) {
// if (section.includesAddr(address)
// && section.includesAddr(address + data.length - 1)) {
// section.setMemorySegment(address, data);
// return;
// }
// }
// sections.add(new MoteMemorySection(address, data));
// }
public void setReadonlyMemorySegment(int address, byte[] data) {
/* Cooja address space */
@ -271,6 +271,11 @@ public class SectionMoteMemory implements MemoryInterface, MoteMemory, AddressMe
setMemorySegment(varAddr, data);
}
@Override
public byte[] getMemory() throws MoteMemoryException {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public byte[] getMemorySegment(long addr, int size) throws MoteMemoryException {
throw new UnsupportedOperationException("Not supported yet.");
@ -430,12 +435,12 @@ public class SectionMoteMemory implements MemoryInterface, MoteMemory, AddressMe
}
private class PolledMemorySegments {
public final MemoryMonitor mm;
public final SegmentMonitor mm;
public final int address;
public final int size;
private byte[] oldMem;
public PolledMemorySegments(MemoryMonitor mm, int address, int size) {
public PolledMemorySegments(SegmentMonitor mm, int address, int size) {
this.mm = mm;
this.address = address;
this.size = size;
@ -449,20 +454,20 @@ public class SectionMoteMemory implements MemoryInterface, MoteMemory, AddressMe
return;
}
mm.memoryChanged(SectionMoteMemory.this, MemoryEventType.WRITE, address);
mm.memoryChanged(SectionMoteMemory.this, SegmentMonitor.EventType.WRITE, address);
oldMem = newMem;
}
}
@Override
public boolean addMemoryMonitor(int address, int size, MemoryMonitor mm) {
// @Override
public boolean addMemoryMonitor(int address, int size, SegmentMonitor mm) {
PolledMemorySegments t = new PolledMemorySegments(mm, address, size);
polledMemories.add(t);
return true;
}
@Override
public void removeMemoryMonitor(int address, int size, MemoryMonitor mm) {
// @Override
public void removeMemoryMonitor(int address, int size, SegmentMonitor mm) {
for (PolledMemorySegments mcm: polledMemories) {
if (mcm.mm != mm || mcm.address != address || mcm.size != size) {
continue;
@ -472,7 +477,7 @@ public class SectionMoteMemory implements MemoryInterface, MoteMemory, AddressMe
}
}
@Override
// @Override
public int parseInt(byte[] memorySegment) {
int retVal = 0;
int pos = 0;

View file

@ -38,7 +38,6 @@ import org.jdom.Element;
import org.contikios.cooja.Mote;
import org.contikios.cooja.MoteInterface;
import org.contikios.cooja.MoteInterfaceHandler;
import org.contikios.cooja.MoteMemory;
import org.contikios.cooja.MoteType;
import org.contikios.cooja.SectionMoteMemory;
import org.contikios.cooja.Simulation;
@ -103,8 +102,8 @@ public class ContikiMote extends AbstractWakeupMote implements Mote {
return myMemory;
}
public void setMemory(MoteMemory memory) {
myMemory = (SectionMoteMemory) memory;
public void setMemory(SectionMoteMemory memory) {
myMemory = memory;
}
@Override

View file

@ -0,0 +1,41 @@
/*
* Copyright (c) 2013, Enrico Joerns
* 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.
*/
package org.contikios.cooja.mote.memory;
/**
* Unknown variable name exception.
*/
public class UnknownVariableException extends RuntimeException {
public UnknownVariableException(String varName) {
super("Unknown variable name: " + varName);
}
}

View file

@ -39,7 +39,6 @@ import org.jdom.Element;
import org.contikios.cooja.Mote;
import org.contikios.cooja.MoteInterface;
import org.contikios.cooja.MoteInterfaceHandler;
import org.contikios.cooja.MoteMemory;
import org.contikios.cooja.MoteType;
import org.contikios.cooja.RadioPacket;
import org.contikios.cooja.SectionMoteMemory;
@ -116,7 +115,7 @@ public abstract class AbstractApplicationMote extends AbstractWakeupMote impleme
return memory;
}
public void setMemory(MoteMemory memory) {
public void setMemory(SectionMoteMemory memory) {
this.memory = (SectionMoteMemory) memory;
}

View file

@ -89,8 +89,6 @@ import org.jdom.Element;
import org.contikios.cooja.ClassDescription;
import org.contikios.cooja.Cooja;
import org.contikios.cooja.Mote;
import org.contikios.cooja.MoteMemory;
import org.contikios.cooja.MoteMemory.MemoryEventType;
import org.contikios.cooja.Plugin;
import org.contikios.cooja.PluginType;
import org.contikios.cooja.SimEventCentral.MoteCountListener;