From: <ni...@us...> - 2008-11-06 00:52:28
|
Revision: 408 http://mspsim.svn.sourceforge.net/mspsim/?rev=408&view=rev Author: nifi Date: 2008-11-06 00:52:24 +0000 (Thu, 06 Nov 2008) Log Message: ----------- added SimEvent for notification about simulation start/stop Modified Paths: -------------- mspsim/se/sics/mspsim/core/MSP430.java mspsim/se/sics/mspsim/ui/ControlUI.java Added Paths: ----------- mspsim/se/sics/mspsim/core/SimEvent.java mspsim/se/sics/mspsim/core/SimEventListener.java Modified: mspsim/se/sics/mspsim/core/MSP430.java =================================================================== --- mspsim/se/sics/mspsim/core/MSP430.java 2008-11-05 23:51:18 UTC (rev 407) +++ mspsim/se/sics/mspsim/core/MSP430.java 2008-11-06 00:52:24 UTC (rev 408) @@ -66,6 +66,8 @@ private MapTable map; private Profiler profiler; + private SimEventListener[] simEventListeners; + /** * Creates a new <code>MSP430</code> instance. * @@ -329,8 +331,18 @@ } } - public boolean setRunning(boolean running) { - return this.running = running; + public void setRunning(boolean running) { + if (this.running != running) { + this.running = running; + SimEventListener[] listeners = this.simEventListeners; + if (listeners != null) { + SimEvent.Type type = running ? SimEvent.Type.START : SimEvent.Type.STOP; + SimEvent event = new SimEvent(type); + for(SimEventListener l : listeners) { + l.simChanged(event); + } + } + } } public boolean isRunning() { @@ -345,4 +357,12 @@ sleepRate = rate; } + public synchronized void addSimEventListener(SimEventListener l) { + simEventListeners = (SimEventListener[]) Utils.add(SimEventListener.class, simEventListeners, l); + } + + public synchronized void removeSimEventListener(SimEventListener l) { + simEventListeners = (SimEventListener[]) Utils.remove(simEventListeners, l); + } + } Added: mspsim/se/sics/mspsim/core/SimEvent.java =================================================================== --- mspsim/se/sics/mspsim/core/SimEvent.java (rev 0) +++ mspsim/se/sics/mspsim/core/SimEvent.java 2008-11-06 00:52:24 UTC (rev 408) @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2008, 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. + * + * This file is part of MSPSim. + * + * $Id$ + * + * ----------------------------------------------------------------- + * + * SimEvent + * + * Authors : Joakim Eriksson, Niclas Finne + * Created : 6 nov 2008 + * Updated : $Date$ + * $Revision$ + */ + +package se.sics.mspsim.core; + +/** + * + */ +public class SimEvent { + + public enum Type { + START, + STOP + }; + + private Type type; + + public SimEvent(Type type) { + this.type = type; + } + + public Type getType() { + return type; + } + +} Property changes on: mspsim/se/sics/mspsim/core/SimEvent.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + LF Added: mspsim/se/sics/mspsim/core/SimEventListener.java =================================================================== --- mspsim/se/sics/mspsim/core/SimEventListener.java (rev 0) +++ mspsim/se/sics/mspsim/core/SimEventListener.java 2008-11-06 00:52:24 UTC (rev 408) @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2008, 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. + * + * This file is part of MSPSim. + * + * $Id$ + * + * ----------------------------------------------------------------- + * + * SimEventListener + * + * Authors : Joakim Eriksson, Niclas Finne + * Created : 6 nov 2008 + * Updated : $Date$ + * $Revision$ + */ + +package se.sics.mspsim.core; + +/** + * + */ +public interface SimEventListener { + + public void simChanged(SimEvent event); + +} Property changes on: mspsim/se/sics/mspsim/core/SimEventListener.java ___________________________________________________________________ Added: svn:keywords + Rev Date Id Added: svn:eol-style + LF Modified: mspsim/se/sics/mspsim/ui/ControlUI.java =================================================================== --- mspsim/se/sics/mspsim/ui/ControlUI.java 2008-11-05 23:51:18 UTC (rev 407) +++ mspsim/se/sics/mspsim/ui/ControlUI.java 2008-11-06 00:52:24 UTC (rev 408) @@ -52,20 +52,25 @@ import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.KeyStroke; - -import se.sics.mspsim.core.*; +import se.sics.mspsim.core.MSP430; +import se.sics.mspsim.core.MSP430Constants; +import se.sics.mspsim.core.SimEvent; +import se.sics.mspsim.core.SimEventListener; import se.sics.mspsim.extutil.jfreechart.DataChart; import se.sics.mspsim.platform.GenericNode; import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.DebugInfo; import se.sics.mspsim.util.ELF; -public class ControlUI extends JPanel implements ActionListener { +public class ControlUI extends JPanel implements ActionListener, SimEventListener { + private static final long serialVersionUID = -2431892192775232653L; + private static final String TITLE = "MSPSim monitor"; private static final boolean USE_STACKUI = false; private JFrame window; + private JButton controlButton; private MSP430 cpu; private GenericNode node; private DebugUI dui; @@ -103,9 +108,11 @@ window.add(dui = new DebugUI(cpu), BorderLayout.CENTER); createButton("Debug On"); - createButton("Stop"); + controlButton = createButton(cpu.isRunning() ? "Stop" : "Run"); stepAction = new AbstractAction("Single Step") { - public void actionPerformed(ActionEvent e) { + private static final long serialVersionUID = 1L; + + public void actionPerformed(ActionEvent e) { ControlUI.this.node.step(); dui.updateRegs(); dui.repaint(); @@ -127,7 +134,7 @@ }; stepAction.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_S)); - stepAction.setEnabled(false); + stepAction.setEnabled(!cpu.isRunning()); JButton stepButton = new JButton(stepAction); add(stepButton); @@ -144,6 +151,8 @@ "cpuStep"); stepButton.getActionMap().put("cpuStep", stepAction); + cpu.addSimEventListener(this); + WindowUtils.restoreWindowBounds("ControlUI", window); WindowUtils.addSaveOnShutdown("ControlUI", window); window.setVisible(true); @@ -153,7 +162,6 @@ sourceViewer = viewer; } - private JButton createButton(String text) { JButton jb = new JButton(text); jb.addActionListener(this); @@ -178,13 +186,9 @@ } else if ("Run".equals(cmd)) { node.start(); - ((JButton) ae.getSource()).setText("Stop"); - stepAction.setEnabled(false); } else if ("Stop".equals(cmd)) { node.stop(); - ((JButton) ae.getSource()).setText("Run"); - stepAction.setEnabled(true); } else if ("Profile Dump".equals(cmd)) { if (cpu.getProfiler() != null) { @@ -196,7 +200,7 @@ // cpu.step(); // dui.repaint(); } else if ("Show Source".equals(cmd)) { - int pc = cpu.readRegister(cpu.PC); + int pc = cpu.readRegister(MSP430Constants.PC); if (elfData != null) { DebugInfo dbg = elfData.getDebugInfo(pc); if (dbg != null) { @@ -218,4 +222,25 @@ } dui.updateRegs(); } -} \ No newline at end of file + + public void simChanged(SimEvent event) { + switch (event.getType()) { + case START: + case STOP: + java.awt.EventQueue.invokeLater(new Runnable() { + + public void run() { + if (cpu.isRunning()) { + controlButton.setText("Stop"); + stepAction.setEnabled(false); + } else { + controlButton.setText("Run"); + stepAction.setEnabled(true); + } + } + + }); + break; + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |