added additional error handling when loading and reloading simulations
This commit is contained in:
parent
c1bb9ce207
commit
4e8631a034
4 changed files with 94 additions and 70 deletions
|
@ -24,7 +24,7 @@
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: GUI.java,v 1.37 2007/03/26 16:31:09 fros4943 Exp $
|
* $Id: GUI.java,v 1.38 2007/04/02 12:45:19 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja;
|
package se.sics.cooja;
|
||||||
|
@ -1683,7 +1683,13 @@ public class GUI {
|
||||||
newMoteType = moteTypeClass.newInstance();
|
newMoteType = moteTypeClass.newInstance();
|
||||||
moteTypeOK = newMoteType.configureAndInit(frame, mySimulation,
|
moteTypeOK = newMoteType.configureAndInit(frame, mySimulation,
|
||||||
isVisualized());
|
isVisualized());
|
||||||
} catch (Exception e) {
|
} catch (InstantiationException e) {
|
||||||
|
logger.fatal("Exception when creating mote type: " + e);
|
||||||
|
return;
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
logger.fatal("Exception when creating mote type: " + e);
|
||||||
|
return;
|
||||||
|
} catch (MoteTypeCreationException e) {
|
||||||
logger.fatal("Exception when creating mote type: " + e);
|
logger.fatal("Exception when creating mote type: " + e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1827,7 +1833,20 @@ public class GUI {
|
||||||
progressDialog.dispose();
|
progressDialog.dispose();
|
||||||
}
|
}
|
||||||
} catch (UnsatisfiedLinkError e) {
|
} catch (UnsatisfiedLinkError e) {
|
||||||
logger.warn("Could not reopen libraries: " + e.getMessage());
|
JOptionPane.showMessageDialog(frame,
|
||||||
|
e.getMessage(),
|
||||||
|
"Simulation load error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
|
||||||
|
if (progressDialog != null && progressDialog.isDisplayable())
|
||||||
|
progressDialog.dispose();
|
||||||
|
newSim = null;
|
||||||
|
} catch (SimulationCreationException e) {
|
||||||
|
JOptionPane.showMessageDialog(frame,
|
||||||
|
e.getMessage(),
|
||||||
|
"Simulation load error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
|
||||||
if (progressDialog != null && progressDialog.isDisplayable())
|
if (progressDialog != null && progressDialog.isDisplayable())
|
||||||
progressDialog.dispose();
|
progressDialog.dispose();
|
||||||
newSim = null;
|
newSim = null;
|
||||||
|
@ -1880,6 +1899,11 @@ public class GUI {
|
||||||
* This may include recompiling libraries and renaming mote type identifiers.
|
* This may include recompiling libraries and renaming mote type identifiers.
|
||||||
*/
|
*/
|
||||||
private void reloadCurrentSimulation() {
|
private void reloadCurrentSimulation() {
|
||||||
|
if (getSimulation() == null) {
|
||||||
|
logger.fatal("No simulation to reload");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final JDialog progressDialog = new JDialog(frame, "Reloading", true);
|
final JDialog progressDialog = new JDialog(frame, "Reloading", true);
|
||||||
final Thread loadThread = new Thread(new Runnable() {
|
final Thread loadThread = new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -1948,30 +1972,36 @@ public class GUI {
|
||||||
configXML = configXML.replaceAll(">" + oldName + "<", ">" + moteTypeNames.get(oldName) + "<");
|
configXML = configXML.replaceAll(">" + oldName + "<", ">" + moteTypeNames.get(oldName) + "<");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove current simulation
|
|
||||||
doRemoveSimulation(false);
|
|
||||||
|
|
||||||
// Reload altered simulation config
|
// Reload altered simulation config
|
||||||
Simulation newSim = null;
|
|
||||||
try {
|
try {
|
||||||
newSim = loadSimulationConfig(new StringReader(configXML), true);
|
myGUI.doRemoveSimulation(false);
|
||||||
if (progressDialog != null && progressDialog.isDisplayable()) {
|
Simulation newSim = loadSimulationConfig(new StringReader(configXML), true);
|
||||||
progressDialog.dispose();
|
|
||||||
}
|
|
||||||
} catch (UnsatisfiedLinkError e) {
|
|
||||||
logger.fatal("Could not reopen libraries: " + e.getMessage());
|
|
||||||
if (progressDialog != null && progressDialog.isDisplayable()) {
|
|
||||||
progressDialog.dispose();
|
|
||||||
}
|
|
||||||
newSim = null;
|
|
||||||
}
|
|
||||||
if (newSim != null) {
|
|
||||||
myGUI.setSimulation(newSim);
|
myGUI.setSimulation(newSim);
|
||||||
|
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
logger.fatal("Could not load libraries: " + e.getMessage());
|
||||||
|
|
||||||
|
JOptionPane.showMessageDialog(frame,
|
||||||
|
e.getMessage(),
|
||||||
|
"Simulation reload error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
|
||||||
|
myGUI.doRemoveSimulation(false);
|
||||||
|
} catch (SimulationCreationException e) {
|
||||||
|
logger.fatal("Could not reopen simulation: " + e.getMessage());
|
||||||
|
|
||||||
|
JOptionPane.showMessageDialog(frame,
|
||||||
|
e.getMessage(),
|
||||||
|
"Simulation reload error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
|
||||||
|
myGUI.doRemoveSimulation(false);
|
||||||
|
} finally {
|
||||||
|
if (progressDialog != null && progressDialog.isDisplayable()) {
|
||||||
|
progressDialog.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (progressDialog != null && progressDialog.isDisplayable()) {
|
|
||||||
progressDialog.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2636,7 +2666,7 @@ public class GUI {
|
||||||
* If associated libraries could not be loaded
|
* If associated libraries could not be loaded
|
||||||
*/
|
*/
|
||||||
public Simulation loadSimulationConfig(File file, boolean quick)
|
public Simulation loadSimulationConfig(File file, boolean quick)
|
||||||
throws UnsatisfiedLinkError {
|
throws UnsatisfiedLinkError, SimulationCreationException {
|
||||||
try {
|
try {
|
||||||
SAXBuilder builder = new SAXBuilder();
|
SAXBuilder builder = new SAXBuilder();
|
||||||
Document doc = builder.build(file);
|
Document doc = builder.build(file);
|
||||||
|
@ -2652,7 +2682,8 @@ public class GUI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Simulation loadSimulationConfig(StringReader stringReader, boolean quick) {
|
private Simulation loadSimulationConfig(StringReader stringReader, boolean quick)
|
||||||
|
throws SimulationCreationException {
|
||||||
try {
|
try {
|
||||||
SAXBuilder builder = new SAXBuilder();
|
SAXBuilder builder = new SAXBuilder();
|
||||||
Document doc = builder.build(stringReader);
|
Document doc = builder.build(stringReader);
|
||||||
|
@ -2660,15 +2691,14 @@ public class GUI {
|
||||||
|
|
||||||
return loadSimulationConfig(root, quick);
|
return loadSimulationConfig(root, quick);
|
||||||
} catch (JDOMException e) {
|
} catch (JDOMException e) {
|
||||||
logger.fatal("Config not wellformed: " + e.getMessage());
|
throw new SimulationCreationException("Configuration file not wellformed: " + e.getMessage());
|
||||||
return null;
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.fatal("IOException: " + e.getMessage());
|
throw new SimulationCreationException("IO Exception: " + e.getMessage());
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Simulation loadSimulationConfig(Element root, boolean quick) {
|
private Simulation loadSimulationConfig(Element root, boolean quick)
|
||||||
|
throws SimulationCreationException {
|
||||||
Simulation newSim = null;
|
Simulation newSim = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -2695,15 +2725,11 @@ public class GUI {
|
||||||
setPluginsConfigXML(root.getChildren(), newSim, !quick);
|
setPluginsConfigXML(root.getChildren(), newSim, !quick);
|
||||||
|
|
||||||
} catch (JDOMException e) {
|
} catch (JDOMException e) {
|
||||||
logger.fatal("File not wellformed: " + e.getMessage());
|
throw new SimulationCreationException("Configuration file not wellformed: " + e.getMessage());
|
||||||
return null;
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.fatal("No access to file: " + e.getMessage());
|
throw new SimulationCreationException("No access to configuration file: " + e.getMessage());
|
||||||
return null;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.fatal("Exception when loading file: " + e);
|
throw new SimulationCreationException("Unknown error: " + e.getMessage());
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return newSim;
|
return newSim;
|
||||||
|
@ -2935,4 +2961,11 @@ public class GUI {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SimulationCreationException extends Exception {
|
||||||
|
public SimulationCreationException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: MoteType.java,v 1.5 2007/03/26 16:31:09 fros4943 Exp $
|
* $Id: MoteType.java,v 1.6 2007/04/02 12:45:20 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja;
|
package se.sics.cooja;
|
||||||
|
@ -149,6 +149,9 @@ public interface MoteType {
|
||||||
Collection<Element> configXML, boolean visAvailable) throws MoteTypeCreationException;
|
Collection<Element> configXML, boolean visAvailable) throws MoteTypeCreationException;
|
||||||
|
|
||||||
public class MoteTypeCreationException extends Exception {
|
public class MoteTypeCreationException extends Exception {
|
||||||
|
public MoteTypeCreationException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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: ContikiMoteType.java,v 1.9 2007/03/26 16:30:29 fros4943 Exp $
|
* $Id: ContikiMoteType.java,v 1.10 2007/04/02 12:45:19 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.contikimote;
|
package se.sics.cooja.contikimote;
|
||||||
|
@ -165,9 +165,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
if (!ContikiMoteType.tempOutputDirectory.exists())
|
if (!ContikiMoteType.tempOutputDirectory.exists())
|
||||||
ContikiMoteType.tempOutputDirectory.mkdir();
|
ContikiMoteType.tempOutputDirectory.mkdir();
|
||||||
if (!ContikiMoteType.tempOutputDirectory.exists()) {
|
if (!ContikiMoteType.tempOutputDirectory.exists()) {
|
||||||
logger.fatal(">> Could not create output directory: "
|
throw new MoteTypeCreationException("Could not create output directory: " + ContikiMoteType.tempOutputDirectory);
|
||||||
+ ContikiMoteType.tempOutputDirectory);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete output files
|
// Delete output files
|
||||||
|
@ -184,24 +182,20 @@ public class ContikiMoteType implements MoteType {
|
||||||
if (mapFile.exists())
|
if (mapFile.exists())
|
||||||
mapFile.delete();
|
mapFile.delete();
|
||||||
if (libFile.exists()) {
|
if (libFile.exists()) {
|
||||||
logger.fatal(">> Can't delete output file, aborting: " + libFile);
|
throw new MoteTypeCreationException("Could not delete output file: " + libFile);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (depFile.exists()) {
|
if (depFile.exists()) {
|
||||||
logger.fatal(">> Can't delete output file, aborting: " + depFile);
|
throw new MoteTypeCreationException("Could not delete output file: " + depFile);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (mapFile.exists()) {
|
if (mapFile.exists()) {
|
||||||
logger.fatal(">> Can't delete output file, aborting: " + mapFile);
|
throw new MoteTypeCreationException("Could not delete output file: " + mapFile);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate Contiki main source file
|
// Generate Contiki main source file
|
||||||
try {
|
try {
|
||||||
ContikiMoteTypeDialog.generateSourceFile(identifier, sensors, coreInterfaces, processes);
|
ContikiMoteTypeDialog.generateSourceFile(identifier, sensors, coreInterfaces, processes);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.fatal(">> Error during file generation, aborting: " + e.getMessage());
|
throw new MoteTypeCreationException("Error during main source file generation: " + e.getMessage());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile library
|
// Compile library
|
||||||
|
@ -216,14 +210,13 @@ public class ContikiMoteType implements MoteType {
|
||||||
compilationSucceded = false;
|
compilationSucceded = false;
|
||||||
|
|
||||||
if (!compilationSucceded) {
|
if (!compilationSucceded) {
|
||||||
logger.fatal(">> Error during compilation, aborting");
|
throw new MoteTypeCreationException("Error during compilation");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load compiled library
|
// Load compiled library
|
||||||
boolean loadingSucceded = doInit(identifier);
|
doInit(identifier);
|
||||||
|
|
||||||
return loadingSucceded;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,15 +233,12 @@ public class ContikiMoteType implements MoteType {
|
||||||
*
|
*
|
||||||
* @param identifier
|
* @param identifier
|
||||||
* Mote type identifier
|
* Mote type identifier
|
||||||
* @return True if initialization ok, false otherwise
|
|
||||||
*/
|
*/
|
||||||
protected boolean doInit(String identifier) throws MoteTypeCreationException {
|
protected void doInit(String identifier) throws MoteTypeCreationException {
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
|
|
||||||
if (myCoreComm != null) {
|
if (myCoreComm != null) {
|
||||||
logger
|
throw new MoteTypeCreationException("Core communicator already used: " + myCoreComm.getClass().getName());
|
||||||
.fatal("Core communicator not null. Is library already loaded? Aborting");
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
File libFile = new File(ContikiMoteType.tempOutputDirectory,
|
File libFile = new File(ContikiMoteType.tempOutputDirectory,
|
||||||
|
@ -258,14 +248,12 @@ public class ContikiMoteType implements MoteType {
|
||||||
|
|
||||||
// Check that library file exists
|
// Check that library file exists
|
||||||
if (!libFile.exists()) {
|
if (!libFile.exists()) {
|
||||||
logger.fatal("Library file could not be found: " + libFile);
|
throw new MoteTypeCreationException("Library file could not be found: " + libFile);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that map file exists
|
// Check that map file exists
|
||||||
if (!mapFile.exists()) {
|
if (!mapFile.exists()) {
|
||||||
logger.fatal("Map file could not be found: " + mapFile);
|
throw new MoteTypeCreationException("Map file could not be found: " + mapFile);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate core communicator class
|
// Allocate core communicator class
|
||||||
|
@ -289,8 +277,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (varAddresses.size() == 0) {
|
if (varAddresses.size() == 0) {
|
||||||
logger.fatal("Variable name to addresses mappings could not be created");
|
throw new MoteTypeCreationException("Variable name to addresses mappings could not be created");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get offset between relative and absolute addresses
|
// Get offset between relative and absolute addresses
|
||||||
|
@ -305,8 +292,7 @@ public class ContikiMoteType implements MoteType {
|
||||||
|
|
||||||
if (relDataSectionAddr <= 0 || dataSectionSize <= 0
|
if (relDataSectionAddr <= 0 || dataSectionSize <= 0
|
||||||
|| relBssSectionAddr <= 0 || bssSectionSize <= 0) {
|
|| relBssSectionAddr <= 0 || bssSectionSize <= 0) {
|
||||||
logger.fatal("Could not parse section addresses correctly");
|
throw new MoteTypeCreationException("Could not parse section addresses correctly");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create initial memory
|
// Create initial memory
|
||||||
|
@ -319,8 +305,6 @@ public class ContikiMoteType implements MoteType {
|
||||||
initialMemory = new SectionMoteMemory(varAddresses);
|
initialMemory = new SectionMoteMemory(varAddresses);
|
||||||
initialMemory.setMemorySegment(relDataSectionAddr, initialDataSection);
|
initialMemory.setMemorySegment(relDataSectionAddr, initialDataSection);
|
||||||
initialMemory.setMemorySegment(relBssSectionAddr, initialBssSection);
|
initialMemory.setMemorySegment(relBssSectionAddr, initialBssSection);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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: ContikiMoteTypeDialog.java,v 1.25 2007/03/26 16:30:29 fros4943 Exp $
|
* $Id: ContikiMoteTypeDialog.java,v 1.26 2007/04/02 12:45:19 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.contikimote;
|
package se.sics.cooja.contikimote;
|
||||||
|
@ -2059,7 +2059,11 @@ public class ContikiMoteTypeDialog extends JDialog {
|
||||||
try {
|
try {
|
||||||
myMoteType.doInit(textID.getText());
|
myMoteType.doInit(textID.getText());
|
||||||
} catch (MoteTypeCreationException ex) {
|
} catch (MoteTypeCreationException ex) {
|
||||||
logger.fatal("Exception when loading library: " + ex);
|
JOptionPane.showMessageDialog(myDialog,
|
||||||
|
ex.getMessage(),
|
||||||
|
"Mote type creation error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
myMoteType.setDescription(textDescription.getText());
|
myMoteType.setDescription(textDescription.getText());
|
||||||
myMoteType.setContikiBaseDir(textContikiDir.getText());
|
myMoteType.setContikiBaseDir(textContikiDir.getText());
|
||||||
|
|
Loading…
Reference in a new issue