Added warning if the plugin fails to start the CollectView application

This commit is contained in:
nifi 2010-10-12 16:48:43 +00:00
parent d2f7f62a34
commit af3f4ae679

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: CollectView.java,v 1.1 2010/10/11 09:29:05 nifi Exp $ * $Id: CollectView.java,v 1.2 2010/10/12 16:48:43 nifi Exp $
*/ */
package se.sics.cooja.plugins.collectview; package se.sics.cooja.plugins.collectview;
import java.awt.BorderLayout; import java.awt.BorderLayout;
@ -35,6 +35,7 @@ import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.Collection; import java.util.Collection;
@ -42,6 +43,7 @@ import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel; import javax.swing.JPanel;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -49,6 +51,7 @@ import org.jdom.Element;
import se.sics.cooja.ClassDescription; import se.sics.cooja.ClassDescription;
import se.sics.cooja.GUI; import se.sics.cooja.GUI;
import se.sics.cooja.GUI.HasQuickHelp;
import se.sics.cooja.Mote; import se.sics.cooja.Mote;
import se.sics.cooja.MotePlugin; import se.sics.cooja.MotePlugin;
import se.sics.cooja.PluginType; import se.sics.cooja.PluginType;
@ -63,7 +66,7 @@ import se.sics.cooja.interfaces.SerialPort;
*/ */
@ClassDescription("Collect View") @ClassDescription("Collect View")
@PluginType(PluginType.MOTE_PLUGIN) @PluginType(PluginType.MOTE_PLUGIN)
public class CollectView extends VisPlugin implements MotePlugin { public class CollectView extends VisPlugin implements MotePlugin, HasQuickHelp {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static Logger logger = Logger.getLogger(CollectView.class); private static Logger logger = Logger.getLogger(CollectView.class);
@ -91,8 +94,8 @@ public class CollectView extends VisPlugin implements MotePlugin {
/* GUI components */ /* GUI components */
if (GUI.isVisualized()) { if (GUI.isVisualized()) {
inLabel = new JLabel("0 bytes", JLabel.RIGHT); inLabel = new JLabel(" 0 bytes", JLabel.RIGHT);
outLabel = new JLabel("0 bytes", JLabel.RIGHT); outLabel = new JLabel(" 0 bytes", JLabel.RIGHT);
JPanel panel = new JPanel(new GridBagLayout()); JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c = new GridBagConstraints();
@ -112,13 +115,28 @@ public class CollectView extends VisPlugin implements MotePlugin {
pack(); pack();
} }
String contikiPath = GUI.getExternalToolsSetting("PATH_CONTIKI", "../../..");
String jarFile = contikiPath + "/examples/sky-shell/dist/collect-demo.jar";
if (!new File(jarFile).canRead()) {
logger.fatal("Could not find the CollectView application:" + jarFile);
if (GUI.isVisualized()) {
JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
"Could not find the CollectView application:\n" +
jarFile + "\n\nPlease try to recompile it!",
"CollectView application not found", JOptionPane.ERROR_MESSAGE);
}
// Could not find the CollectView application
cleanup();
return;
}
try { try {
String contikiPath = GUI.getExternalToolsSetting("PATH_CONTIKI", "../../..");
String[] cmd = new String[] { String[] cmd = new String[] {
"java", "-jar", contikiPath + "/examples/sky-shell/dist/collect-demo.jar", "java", "-jar", jarFile,
"-n", "-f" "-n", "-f"
}; };
isRunning = true;
commandProcess = Runtime.getRuntime().exec(cmd); commandProcess = Runtime.getRuntime().exec(cmd);
final BufferedReader input = new BufferedReader(new InputStreamReader(commandProcess.getInputStream())); final BufferedReader input = new BufferedReader(new InputStreamReader(commandProcess.getInputStream()));
final BufferedReader err = new BufferedReader(new InputStreamReader(commandProcess.getErrorStream())); final BufferedReader err = new BufferedReader(new InputStreamReader(commandProcess.getErrorStream()));
@ -145,8 +163,7 @@ public class CollectView extends VisPlugin implements MotePlugin {
input.close(); input.close();
} catch (IOException e) { } catch (IOException e) {
if (isRunning) { if (isRunning) {
isRunning = false; logger.error("The CollectView application died!", e);
logger.error("CollectView died", e);
} }
} finally { } finally {
cleanup(); cleanup();
@ -165,8 +182,7 @@ public class CollectView extends VisPlugin implements MotePlugin {
err.close(); err.close();
} catch (IOException e) { } catch (IOException e) {
if (isRunning) { if (isRunning) {
isRunning = false; logger.error("The CollectView application died!", e);
logger.error("CollectView died", e);
} }
} }
} }
@ -213,8 +229,18 @@ public class CollectView extends VisPlugin implements MotePlugin {
} }
private void cleanup() { private void cleanup() {
serialPort.deleteSerialDataObserver(serialDataObserver); if (serialDataObserver != null) {
serialPort.deleteSerialDataObserver(serialDataObserver);
serialDataObserver = null;
}
if (isRunning) {
logger.fatal("The CollectView application died!");
if (GUI.isVisualized()) {
JOptionPane.showMessageDialog(this, "The CollectView application died!",
"CollectView died!", JOptionPane.ERROR_MESSAGE);
}
}
isRunning = false; isRunning = false;
if (commandProcess != null) { if (commandProcess != null) {
commandProcess.destroy(); commandProcess.destroy();
@ -228,14 +254,19 @@ public class CollectView extends VisPlugin implements MotePlugin {
} }
} }
EventQueue.invokeLater(new Runnable() { if (GUI.isVisualized()) {
public void run() { EventQueue.invokeLater(new Runnable() {
setTitle(getTitle() + " *DISCONNECTED*"); public void run() {
} setTitle(getTitle() + " *DISCONNECTED*");
}); inLabel.setEnabled(false);
outLabel.setEnabled(false);
}
});
}
} }
public void closePlugin() { public void closePlugin() {
isRunning = false;
cleanup(); cleanup();
} }
@ -243,4 +274,12 @@ public class CollectView extends VisPlugin implements MotePlugin {
return mote; return mote;
} }
public String getQuickHelp() {
return "<b>CollectView</b><p>" +
"The CollectView plugin starts an instance of the CollectView application and " +
"connects it to the serial port of a specific mote. " +
"The CollectView application can then interact with the simulated network in " +
"exactly the same way as it would interact with a network of real motes.";
}
} }