⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 autorun.java

📁 传感器网络中的嵌入式操作系统源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// $Id: AutoRun.java,v 1.10.2.4 2003/09/18 22:29:43 mdwelsh Exp $/*									tab:2 * * "Copyright (c) 2000 and The Regents of the University  * of California.  All rights reserved. * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose, without fee, and without written * agreement is hereby granted, provided that the above copyright * notice and the following two paragraphs appear in all copies of * this software. *  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, * UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * */package net.tinyos.sim;import java.util.*;import java.io.*;import net.tinyos.sim.event.*;public class AutoRun implements SimConst {  private TinyViz tv;  private Thread runThread;  private autoRunThread arThread;  private autoRunPlugin arPlugin;  private arConfig cur_arc;  private int stopstringall_count = 0;  boolean visible_flag = true;  private static final int STOPMODE_EXIT = 0;  private static final int STOPMODE_PAUSE = 1;  private Vector configs = new Vector(1);  class arConfig {    String executable;    int numMotes;    String logfile;    String dbgflags;    long numsec;    String screenshot;    String stopstring;    boolean stopstringall;    int stopmode;    boolean pauseatstart;    Vector plugins;    Hashtable options;    String precmd;    String postcmd;    int niceval;    arConfig() {      this.executable = null;      this.numMotes = 0;      this.logfile = null;      this.dbgflags = null;      this.numsec = 0;      this.screenshot = null;      this.stopstring = null;      this.stopstringall = false;      this.stopmode = STOPMODE_EXIT;      this.pauseatstart = false;      this.precmd = null;      this.postcmd = null;      this.options = new Hashtable();      this.plugins = new Vector(1);      this.niceval = 0;    }    arConfig(arConfig parent) {      this.executable = parent.executable;      this.numMotes = parent.numMotes;      this.logfile = parent.logfile;      this.dbgflags = parent.dbgflags;      this.numsec = parent.numsec;      this.screenshot = parent.screenshot;      this.stopstring = parent.stopstring;      this.stopstringall = parent.stopstringall;      this.stopmode = parent.stopmode;      this.pauseatstart = parent.pauseatstart;      this.precmd = parent.precmd;      this.postcmd = parent.postcmd;      this.niceval = parent.niceval;      try {	this.options = (Hashtable)parent.options.clone();	this.plugins = (Vector)parent.plugins.clone();      } catch (Exception e) {	this.options = parent.options;	this.plugins = parent.plugins;      }    }  }  public AutoRun(TinyViz tv, String configFile) throws IOException {    this.tv = tv;    if (configFile != null) parseConfig(configFile);  }  public AutoRun(TinyViz tv, String executable, int numMotes) {    this.tv = tv;    arConfig arc = new arConfig();    arc.executable = executable;    arc.numMotes = numMotes;    addConfig(arc);  }  private void addConfig(arConfig arc) {    configs.addElement(arc);  }  private void parseConfig(String configFile) throws IOException {    FileReader fr = new FileReader(configFile);    LineNumberReader lnr = new LineNumberReader(fr);    String line;    arConfig arc = new arConfig();    boolean seenkey = false;    try {      while ((line = lnr.readLine()) != null) {	if (line.indexOf('#') == 0) continue;	if (line.equals("")) {	  if (seenkey) {	    addConfig(arc);	    arc = new arConfig(arc);	    seenkey = false;	  }	  continue;	}	StringTokenizer st = new StringTokenizer(line);	String key = st.nextToken();	String value = st.nextToken("").substring(1);	seenkey = true;	if (key.equals("executable")) {	  arc.executable = value;	} else if (key.equals("nummotes")) {	  arc.numMotes = Integer.parseInt(value);	} else if (key.equals("logfile")) {	  arc.logfile = value;	} else if (key.equals("dbg")) {	  arc.dbgflags = value;	} else if (key.equals("numsec")) {	  arc.numsec = Long.parseLong(value);	} else if (key.equals("screenshot")) {	  arc.screenshot = value;	} else if (key.equals("precmd")) {	  arc.precmd = value;	} else if (key.equals("postcmd")) {	  arc.postcmd = value;	} else if (key.equals("stopstring")) {	  arc.stopstring = value;	} else if (key.equals("stopmode")) {	  if (value.equals("pause")) arc.stopmode = STOPMODE_PAUSE;	  else if (value.equals("exit")) arc.stopmode = STOPMODE_EXIT;	  else throw new IOException("Bad value for stopmode option: "+value);	} else if (key.equals("stopstringall")) {	  if (value.equals("true")) arc.stopstringall = true;	  else if (value.equals("false")) arc.stopstringall = false;	  else throw new IOException("Bad value for stopstringall option: "+value);	} else if (key.equals("pause")) {	  if (value.equals("true")) arc.pauseatstart = true;	  else if (value.equals("false")) arc.pauseatstart = false;	  else throw new IOException("Bad value for pause option: "+value);	} else if (key.equals("visible")) {	  if (value.equals("true")) visible_flag = true;	  else if (value.equals("false")) visible_flag = false;	  else throw new IOException("Bad value for visible option: "+value);	} else if (key.equals("plugin")) {	  arc.plugins.addElement(value);	} else if (key.equals("niceval")) {	  arc.niceval = Integer.parseInt(value);	} else {	  arc.options.put(key, value);	}      }      if (seenkey) {	addConfig(arc);	arc = new arConfig(arc);      }    } catch (Exception e) {      e.printStackTrace();      throw new IOException("Cannot parse configuration file: "+e);    }  }  public void run() {    arThread = new autoRunThread();    runThread = new Thread(arThread);    synchronized (runThread) {      runThread.start();      try {	runThread.wait();      } catch (InterruptedException e) {	// Ignore      }    }  }  public void stop() {    System.err.println("AUTORUN: Stopping simulation.");    if (arThread != null) {      arThread.stopProcess = true;      try {	runThread.interrupt();      } catch (Exception e) {	System.err.println("Cannot interrupt runThread: "+e);      }    }  }  public void log(String msg) {    if (arPlugin != null) arPlugin.log(msg);  }  class autoRunThread implements Runnable {    Process simProcess;    boolean stopProcess = false;    boolean exited = false;    public void run() {      arPlugin = new autoRunPlugin();      tv.getPluginPanel().addPlugin(arPlugin);      tv.getPluginPanel().register(arPlugin);      Enumeration e = configs.elements();      while (e.hasMoreElements() /* && !timeToQuit */) {	System.err.println("AUTORUN: Initializing simulation.");	cur_arc = (arConfig)e.nextElement();	/* Register all plugins that match name */	Plugin parr[] = tv.getPluginPanel().plugins();	Enumeration pe = cur_arc.plugins.elements();	while (pe.hasMoreElements()) {	  String pname = (String)pe.nextElement();	  for (int n = 0; n < parr.length; n++) {	    if (parr[n].getClass().getName().indexOf(pname) != -1) {	      tv.getPluginPanel().register(parr[n]);	    }	  }	}		/* Set options */	Enumeration oe = cur_arc.options.keys();	while (oe.hasMoreElements()) {	  String option = (String)oe.nextElement();	  tv.setOption(option, (String)cur_arc.options.get(option));	}	/* Wait for options to be processed */	try {	  tv.getEventBus().processAll();	} catch (InterruptedException ie) {	  // Ignore	}	/* Set up logging */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -