an early version of chakana, an automated test framework used with COOJA
This commit is contained in:
parent
9be473e4b9
commit
65533c0c00
29 changed files with 4983 additions and 0 deletions
|
@ -0,0 +1,279 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 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: ChakanaPlugin.java,v 1.1 2007/08/21 14:39:58 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.chakana;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.Collection;
|
||||
import javax.swing.SwingUtilities;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jdom.Element;
|
||||
|
||||
import se.sics.cooja.*;
|
||||
|
||||
/**
|
||||
* Main Chakana plugin.
|
||||
*
|
||||
* Provides remote control functionality to COOJA via socket connections.
|
||||
*
|
||||
* @see #SERVER_PORT
|
||||
* @author Fredrik Osterlind
|
||||
*/
|
||||
@ClassDescription("Chakana COOJA Server")
|
||||
@PluginType(PluginType.COOJA_STANDARD_PLUGIN)
|
||||
public class ChakanaPlugin implements Plugin {
|
||||
public static final String VERSION = "0.1";
|
||||
|
||||
/**
|
||||
* COOJA's Chakana-plugin server port
|
||||
*/
|
||||
public static final int SERVER_PORT = 1234;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static Logger logger = Logger.getLogger(ChakanaPlugin.class);
|
||||
|
||||
private GUI myGUI;
|
||||
|
||||
// Chakana communication
|
||||
private Thread serverThread = null;
|
||||
|
||||
private ServerSocket serverSocket = null;
|
||||
|
||||
private Thread clientThread = null;
|
||||
|
||||
private Socket clientSocket = null;
|
||||
|
||||
private EventpointEvaluator myEvaluator = null;
|
||||
|
||||
private XMLCommandHandler myCommandHandler = null;
|
||||
|
||||
private boolean shutdown = false;
|
||||
|
||||
private Object tag = null;
|
||||
|
||||
/**
|
||||
* Creates new Chakana remote control plugin.
|
||||
*
|
||||
* @param gui COOJA Simulator
|
||||
*/
|
||||
public ChakanaPlugin(GUI gui) {
|
||||
myGUI = gui;
|
||||
|
||||
// Create eventpoint evaluator
|
||||
myEvaluator = new EventpointEvaluator(myGUI);
|
||||
|
||||
// Create remote command handler
|
||||
myCommandHandler = new XMLCommandHandler(myGUI, this, myEvaluator);
|
||||
|
||||
// Open server socket
|
||||
serverThread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
serverSocket = new ServerSocket(SERVER_PORT);
|
||||
logger.info("Chakana server listening on port " + SERVER_PORT + ".");
|
||||
} catch (Exception e) {
|
||||
logger.fatal("Could not start server thread: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle incoming connections
|
||||
while (serverSocket != null) {
|
||||
try {
|
||||
Socket skt = serverSocket.accept();
|
||||
handleNewConnection(skt);
|
||||
} catch (Exception e) {
|
||||
if (!shutdown)
|
||||
logger.fatal("Server thread exception: " + e.getMessage());
|
||||
if (serverThread != null && serverThread.isInterrupted()) {
|
||||
serverThread = null;
|
||||
}
|
||||
serverSocket = null;
|
||||
}
|
||||
}
|
||||
logger.info("Chakana server thread terminating");
|
||||
}
|
||||
}, "chakana listen thread");
|
||||
serverThread.start();
|
||||
}
|
||||
|
||||
public void performCOOJAShutdown() {
|
||||
shutdown = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles incoming connection.
|
||||
*
|
||||
* @param socket Socket
|
||||
*/
|
||||
private void handleNewConnection(Socket socket) {
|
||||
logger.info("Received request from " + socket.getInetAddress() + ":"
|
||||
+ socket.getPort());
|
||||
|
||||
if (clientThread != null) {
|
||||
// Refuse connection
|
||||
logger.warn("A client is already connected, refusing new connection");
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Start thread handling connection
|
||||
clientSocket = socket;
|
||||
clientThread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
// Open stream
|
||||
PrintWriter writer = new PrintWriter(clientSocket.getOutputStream());
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(clientSocket
|
||||
.getInputStream()));
|
||||
|
||||
// Send welcome message
|
||||
writer.print(XMLCommandHandler.createInfoMessage("Chakana COOJA plugin, version " + VERSION) + "\n");
|
||||
writer.flush();
|
||||
|
||||
// Handle incoming data (blocks until connection terminated)
|
||||
String line;
|
||||
String command = "";
|
||||
while ((!shutdown) && ((line = reader.readLine()) != null)) {
|
||||
logger.debug("<-- " + line);
|
||||
command += line;
|
||||
|
||||
if (myCommandHandler.containsEntireCommand(command)) {
|
||||
String reply = myCommandHandler.handleCommand(command);
|
||||
logger.debug("--> " + reply);
|
||||
writer.print(reply + "\n");
|
||||
writer.flush();
|
||||
command = "";
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Terminating Chakana connection");
|
||||
|
||||
// Clean up connection
|
||||
if (writer != null) {
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
if (clientSocket != null && !clientSocket.isClosed())
|
||||
clientSocket.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
logger.fatal("Client connection exception: " + e);
|
||||
}
|
||||
|
||||
clientThread = null;
|
||||
clientSocket = null;
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
myGUI.doQuit(false);
|
||||
}
|
||||
});
|
||||
logger.debug("Chakana client thread terminating");
|
||||
}
|
||||
}, "chakana client thread");
|
||||
clientThread.start();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Shut down any open server socket, and kill server thread.
|
||||
*/
|
||||
protected void closeServer() {
|
||||
// Shut down server
|
||||
if (serverSocket != null && !serverSocket.isClosed()) {
|
||||
logger.info("Closing server socket");
|
||||
try {
|
||||
serverSocket.close();
|
||||
} catch (IOException e) {
|
||||
logger.fatal("Error when closing server socket: " + e);
|
||||
}
|
||||
serverSocket = null;
|
||||
}
|
||||
|
||||
if (serverThread != null && serverThread.isAlive()) {
|
||||
logger.info("Interrupting server thread");
|
||||
serverThread.interrupt();
|
||||
serverThread = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect all connected clients. Currently only one client can be
|
||||
* connected at the same time.
|
||||
*/
|
||||
protected void disconnectClients() {
|
||||
// Disconnect any current accepted client
|
||||
if (clientSocket != null && !clientSocket.isClosed()) {
|
||||
logger.info("Closing client socket");
|
||||
try {
|
||||
clientSocket.close();
|
||||
} catch (IOException e) {
|
||||
logger.fatal("Error when closing client socket: " + e);
|
||||
}
|
||||
clientSocket = null;
|
||||
}
|
||||
|
||||
if (clientThread != null && clientThread.isAlive()) {
|
||||
logger.info("Interrupting client thread");
|
||||
clientThread.interrupt();
|
||||
clientThread = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void closePlugin() {
|
||||
closeServer();
|
||||
disconnectClients();
|
||||
}
|
||||
|
||||
public void tagWithObject(Object tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public Object getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public Collection<Element> getConfigXML() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean setConfigXML(Collection<Element> configXML,
|
||||
boolean visAvailable) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 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: EventpointEvaluator.java,v 1.1 2007/08/21 14:39:58 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.chakana;
|
||||
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import java.util.Vector;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import se.sics.cooja.GUI;
|
||||
import se.sics.cooja.Simulation;
|
||||
import se.sics.chakana.eventpoints.*;
|
||||
|
||||
/**
|
||||
* Keeps track of all active eventpoints. The control method blocks until any of
|
||||
* the active eventpoints trigger.
|
||||
*
|
||||
* @author Fredrik Osterlind
|
||||
*/
|
||||
public class EventpointEvaluator {
|
||||
private static Logger logger = Logger.getLogger(EventpointEvaluator.class);
|
||||
|
||||
private GUI myGUI;
|
||||
private Vector<Eventpoint> allEventpoints;
|
||||
private Eventpoint lastTriggeredEventpoint;
|
||||
private Simulation sim = null;
|
||||
|
||||
private int counterEventpointID = 0;
|
||||
|
||||
private Observer tickObserver = new Observer() {
|
||||
public void update(Observable obs, Object obj) {
|
||||
// Evaluate active eventpoints
|
||||
for (Eventpoint eventpoint: allEventpoints) {
|
||||
if (eventpoint.evaluate()) {
|
||||
lastTriggeredEventpoint = eventpoint;
|
||||
sim.stopSimulation();
|
||||
logger.info("Eventpoint triggered: " + eventpoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new eventpoint evaluator.
|
||||
*
|
||||
* @param gui GUI with simulation
|
||||
*/
|
||||
public EventpointEvaluator(GUI gui) {
|
||||
myGUI = gui;
|
||||
allEventpoints = new Vector<Eventpoint>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Blocks until an active eventpoint triggers.
|
||||
*
|
||||
* @return Triggered eventpoint
|
||||
* @throws EventpointException At evenpoint setup errors
|
||||
*/
|
||||
public Eventpoint resumeSimulation() throws EventpointException {
|
||||
if (myGUI.getSimulation() == null)
|
||||
throw new EventpointException("No simulation to observe");
|
||||
if (allEventpoints == null || allEventpoints.isEmpty())
|
||||
throw new EventpointException("No eventpoints exist");
|
||||
|
||||
// Make sure tick observer is observing the current simulation
|
||||
myGUI.getSimulation().deleteTickObserver(tickObserver);
|
||||
myGUI.getSimulation().addTickObserver(tickObserver);
|
||||
|
||||
// Evaluate active eventpoints before starting simulation
|
||||
for (Eventpoint eventpoint: allEventpoints) {
|
||||
if (eventpoint.evaluate()) {
|
||||
lastTriggeredEventpoint = eventpoint;
|
||||
logger.info("Eventpoint triggered (EARLY): " + eventpoint);
|
||||
return lastTriggeredEventpoint;
|
||||
}
|
||||
}
|
||||
|
||||
// Reset last triggered eventpoint and start simulation
|
||||
lastTriggeredEventpoint = null;
|
||||
sim = myGUI.getSimulation();
|
||||
sim.startSimulation();
|
||||
|
||||
// Block until tickobserver stops simulation
|
||||
while (lastTriggeredEventpoint == null || myGUI.getSimulation().isRunning()) {
|
||||
Thread.yield();
|
||||
}
|
||||
|
||||
if (lastTriggeredEventpoint == null)
|
||||
throw new EventpointException("Simulation was stopped without eventpoint triggering");
|
||||
|
||||
return lastTriggeredEventpoint;
|
||||
}
|
||||
|
||||
public Eventpoint getTriggeredEventpoint() {
|
||||
return lastTriggeredEventpoint;
|
||||
}
|
||||
|
||||
public int getLastTriggeredEventpointID() {
|
||||
return lastTriggeredEventpoint.getID();
|
||||
}
|
||||
|
||||
public Eventpoint getEventpoint(int id) {
|
||||
for (Eventpoint eventpoint: allEventpoints) {
|
||||
if (eventpoint.getID() == id) {
|
||||
return eventpoint;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addEventpoint(Eventpoint eventpoint) {
|
||||
eventpoint.setID(counterEventpointID++);
|
||||
allEventpoints.add(eventpoint);
|
||||
}
|
||||
|
||||
public void clearAllEventpoints() {
|
||||
allEventpoints.clear();
|
||||
}
|
||||
|
||||
public void deleteEventpoint(int id) {
|
||||
Eventpoint eventpointToDelete = null;
|
||||
for (Eventpoint eventpoint: allEventpoints) {
|
||||
if (eventpoint.getID() == id) {
|
||||
eventpointToDelete = eventpoint;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (eventpointToDelete != null)
|
||||
allEventpoints.remove(eventpointToDelete);
|
||||
}
|
||||
|
||||
class EventpointException extends Exception {
|
||||
public EventpointException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 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: Eventpoint.java,v 1.1 2007/08/21 14:39:58 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.chakana.eventpoints;
|
||||
|
||||
public interface Eventpoint {
|
||||
|
||||
/**
|
||||
* Evaluates eventpoint.
|
||||
*
|
||||
* @return True if eventpoint triggered, false otherwise
|
||||
*/
|
||||
public boolean evaluate();
|
||||
|
||||
/**
|
||||
* @return Optional information of triggered eventpoint
|
||||
*/
|
||||
public String getMessage();
|
||||
|
||||
/**
|
||||
* @param id Eventpoint ID
|
||||
*/
|
||||
public void setID(int id);
|
||||
|
||||
/**
|
||||
* @return Unique eventpoint ID
|
||||
*/
|
||||
public int getID();
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 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: IntegerWatchpoint.java,v 1.1 2007/08/21 14:39:58 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.chakana.eventpoints;
|
||||
|
||||
import se.sics.cooja.Mote;
|
||||
|
||||
/**
|
||||
* TODO Document
|
||||
*
|
||||
* @author Fredrik Osterlind
|
||||
*/
|
||||
public class IntegerWatchpoint extends VariableWatchpoint {
|
||||
public IntegerWatchpoint(Mote mote, String varName) {
|
||||
super(mote, varName, 4);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 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: RadioMediumEventpoint.java,v 1.1 2007/08/21 14:39:58 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.chakana.eventpoints;
|
||||
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
import se.sics.cooja.RadioMedium;
|
||||
|
||||
/**
|
||||
* Triggers if radio medium changes
|
||||
*
|
||||
* @author Fredrik Osterlind
|
||||
*/
|
||||
public class RadioMediumEventpoint implements Eventpoint {
|
||||
protected boolean shouldBreak = false;
|
||||
private int myID = 0;
|
||||
protected RadioMedium radioMedium;
|
||||
private int count = 1;
|
||||
|
||||
public RadioMediumEventpoint(RadioMedium radioMedium) {
|
||||
if (radioMedium == null) {
|
||||
// TODO Throw exception
|
||||
return;
|
||||
}
|
||||
|
||||
this.radioMedium = radioMedium;
|
||||
|
||||
// Register as radio medium observer
|
||||
radioMedium.addRadioMediumObserver(new Observer() {
|
||||
public void update(Observable obs, Object obj) {
|
||||
handleRadioMediumChange();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public RadioMediumEventpoint(RadioMedium radioMedium, int count) {
|
||||
this(radioMedium);
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
protected void handleRadioMediumChange() {
|
||||
count--;
|
||||
if (count < 1)
|
||||
shouldBreak = true;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return "Radio medium changed";
|
||||
}
|
||||
|
||||
public boolean evaluate() {
|
||||
return shouldBreak;
|
||||
}
|
||||
|
||||
public void setID(int id) {
|
||||
myID = id;
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return myID;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 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: RealTimepoint.java,v 1.1 2007/08/21 14:39:58 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.chakana.eventpoints;
|
||||
|
||||
/**
|
||||
* TODO Document
|
||||
*
|
||||
* @author Fredrik Osterlind
|
||||
*/
|
||||
public class RealTimepoint implements Timepoint {
|
||||
private int myID = 0;
|
||||
private long endTime;
|
||||
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* TODO Document
|
||||
*
|
||||
* TODO Use timer instead, much faster!
|
||||
*
|
||||
* @param time Duration in milliseconds
|
||||
*/
|
||||
public RealTimepoint(long time) {
|
||||
this.endTime = System.currentTimeMillis() + time;
|
||||
}
|
||||
|
||||
public boolean evaluate() {
|
||||
if (System.currentTimeMillis() >= endTime) {
|
||||
message = "Real time = " + System.currentTimeMillis() + " >= " + endTime;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Real timepoint: " + endTime;
|
||||
}
|
||||
|
||||
public void setID(int id) {
|
||||
myID = id;
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return myID;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 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: SimulationTimepoint.java,v 1.1 2007/08/21 14:39:58 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.chakana.eventpoints;
|
||||
|
||||
import se.sics.cooja.Simulation;
|
||||
|
||||
/**
|
||||
* TODO Document
|
||||
*
|
||||
* @author Fredrik Osterlind
|
||||
*/
|
||||
public class SimulationTimepoint implements Timepoint {
|
||||
private int myID = 0;
|
||||
private Simulation simulation;
|
||||
private int time;
|
||||
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* TODO Document
|
||||
*
|
||||
* @param simulation
|
||||
* @param time
|
||||
*/
|
||||
public SimulationTimepoint(Simulation simulation, int time) {
|
||||
this.simulation = simulation;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public boolean evaluate() {
|
||||
if (simulation.getSimulationTime() >= time) {
|
||||
message = "Simulation time = " + simulation.getSimulationTime() + " >= " + time;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Simulation timepoint: " + time;
|
||||
}
|
||||
|
||||
public void setID(int id) {
|
||||
myID = id;
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return myID;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 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: Timepoint.java,v 1.1 2007/08/21 14:39:58 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.chakana.eventpoints;
|
||||
|
||||
/**
|
||||
* A timepoint triggers at and after a given time.
|
||||
*
|
||||
* @author Fredrik Osterlind
|
||||
*/
|
||||
public interface Timepoint extends Eventpoint {
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 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: TransmissionRadioMediumEventpoint.java,v 1.1 2007/08/21 14:39:58 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.chakana.eventpoints;
|
||||
|
||||
import se.sics.cooja.RadioMedium;
|
||||
|
||||
/**
|
||||
* Triggers when a radio medium transmission has been completed
|
||||
*
|
||||
* @author Fredrik Osterlind
|
||||
*/
|
||||
public class TransmissionRadioMediumEventpoint extends RadioMediumEventpoint {
|
||||
private String message = "";
|
||||
private int count = 1;
|
||||
|
||||
public TransmissionRadioMediumEventpoint(RadioMedium radioMedium) {
|
||||
super(radioMedium);
|
||||
}
|
||||
|
||||
public TransmissionRadioMediumEventpoint(RadioMedium radioMedium, int count) {
|
||||
this(radioMedium);
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
protected void handleRadioMediumChange() {
|
||||
if (radioMedium.getLastTickConnections() != null) {
|
||||
count -= radioMedium.getLastTickConnections().length;
|
||||
if (count < 1) {
|
||||
shouldBreak = true;
|
||||
message = radioMedium.getLastTickConnections().length + " transmissions were completed";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 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: VariableWatchpoint.java,v 1.1 2007/08/21 14:39:58 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.chakana.eventpoints;
|
||||
|
||||
import se.sics.cooja.Mote;
|
||||
import se.sics.cooja.SectionMoteMemory;
|
||||
|
||||
/**
|
||||
* TODO Document
|
||||
*
|
||||
* @author Fredrik Osterlind
|
||||
*/
|
||||
public class VariableWatchpoint extends Watchpoint {
|
||||
private Mote mote;
|
||||
private String name;
|
||||
|
||||
private String reason;
|
||||
|
||||
public VariableWatchpoint(Mote mote, String variableName, int size) {
|
||||
super(mote, ((SectionMoteMemory) mote.getMemory())
|
||||
.getVariableAddress(variableName), size);
|
||||
this.mote = mote;
|
||||
this.name = variableName;
|
||||
}
|
||||
|
||||
public boolean evaluate() {
|
||||
boolean shouldBreak = super.evaluate();
|
||||
|
||||
if (shouldBreak) {
|
||||
reason = "Variable '" + name + "' changed";
|
||||
}
|
||||
return shouldBreak;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Variable watchpoint: " + name + " @ " + mote;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 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: Watchpoint.java,v 1.1 2007/08/21 14:39:58 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.chakana.eventpoints;
|
||||
|
||||
import java.util.Arrays;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import se.sics.cooja.Mote;
|
||||
|
||||
/**
|
||||
* A watchpoint watches a memory area, such as a variable, and triggers at changes.
|
||||
*
|
||||
* @author Fredrik Osterlind
|
||||
*/
|
||||
public class Watchpoint implements Eventpoint {
|
||||
private static Logger logger = Logger.getLogger(Watchpoint.class);
|
||||
private int myID = 0;
|
||||
|
||||
private Mote mote;
|
||||
private int address;
|
||||
private int size;
|
||||
byte[] initialMemory;
|
||||
|
||||
private String reason;
|
||||
|
||||
public Watchpoint(Mote mote, int address, int size) {
|
||||
this.mote = mote;
|
||||
this.address = address;
|
||||
this.size = size;
|
||||
|
||||
logger.debug("Fetching initial memory");
|
||||
initialMemory = mote.getMemory().getMemorySegment(address, size);
|
||||
|
||||
// TODO Throw exception if memory area not valid
|
||||
}
|
||||
|
||||
public boolean evaluate() {
|
||||
byte[] currentMemory = mote.getMemory().getMemorySegment(address, size);
|
||||
boolean shouldBreak = !Arrays.equals(initialMemory, currentMemory);
|
||||
|
||||
if (shouldBreak) {
|
||||
reason = "Memory interval " + "0x" + Integer.toHexString(address) + ":" + size + " changed";
|
||||
}
|
||||
return shouldBreak;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Memory change breakpoint: " + "0x" + Integer.toHexString(address) + ":" + size + " @ " + mote;
|
||||
}
|
||||
|
||||
public void setID(int id) {
|
||||
myID = id;
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return myID;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue