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
|
||||
* 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;
|
||||
|
@ -1683,7 +1683,13 @@ public class GUI {
|
|||
newMoteType = moteTypeClass.newInstance();
|
||||
moteTypeOK = newMoteType.configureAndInit(frame, mySimulation,
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
@ -1827,7 +1833,20 @@ public class GUI {
|
|||
progressDialog.dispose();
|
||||
}
|
||||
} 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())
|
||||
progressDialog.dispose();
|
||||
newSim = null;
|
||||
|
@ -1880,6 +1899,11 @@ public class GUI {
|
|||
* This may include recompiling libraries and renaming mote type identifiers.
|
||||
*/
|
||||
private void reloadCurrentSimulation() {
|
||||
if (getSimulation() == null) {
|
||||
logger.fatal("No simulation to reload");
|
||||
return;
|
||||
}
|
||||
|
||||
final JDialog progressDialog = new JDialog(frame, "Reloading", true);
|
||||
final Thread loadThread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
|
@ -1948,30 +1972,36 @@ public class GUI {
|
|||
configXML = configXML.replaceAll(">" + oldName + "<", ">" + moteTypeNames.get(oldName) + "<");
|
||||
}
|
||||
|
||||
// Remove current simulation
|
||||
doRemoveSimulation(false);
|
||||
|
||||
// Reload altered simulation config
|
||||
Simulation newSim = null;
|
||||
try {
|
||||
newSim = loadSimulationConfig(new StringReader(configXML), true);
|
||||
if (progressDialog != null && progressDialog.isDisplayable()) {
|
||||
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.doRemoveSimulation(false);
|
||||
Simulation newSim = loadSimulationConfig(new StringReader(configXML), true);
|
||||
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
|
||||
*/
|
||||
public Simulation loadSimulationConfig(File file, boolean quick)
|
||||
throws UnsatisfiedLinkError {
|
||||
throws UnsatisfiedLinkError, SimulationCreationException {
|
||||
try {
|
||||
SAXBuilder builder = new SAXBuilder();
|
||||
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 {
|
||||
SAXBuilder builder = new SAXBuilder();
|
||||
Document doc = builder.build(stringReader);
|
||||
|
@ -2660,15 +2691,14 @@ public class GUI {
|
|||
|
||||
return loadSimulationConfig(root, quick);
|
||||
} catch (JDOMException e) {
|
||||
logger.fatal("Config not wellformed: " + e.getMessage());
|
||||
return null;
|
||||
throw new SimulationCreationException("Configuration file not wellformed: " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
logger.fatal("IOException: " + e.getMessage());
|
||||
return null;
|
||||
throw new SimulationCreationException("IO Exception: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private Simulation loadSimulationConfig(Element root, boolean quick) {
|
||||
private Simulation loadSimulationConfig(Element root, boolean quick)
|
||||
throws SimulationCreationException {
|
||||
Simulation newSim = null;
|
||||
|
||||
try {
|
||||
|
@ -2695,15 +2725,11 @@ public class GUI {
|
|||
setPluginsConfigXML(root.getChildren(), newSim, !quick);
|
||||
|
||||
} catch (JDOMException e) {
|
||||
logger.fatal("File not wellformed: " + e.getMessage());
|
||||
return null;
|
||||
throw new SimulationCreationException("Configuration file not wellformed: " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
logger.fatal("No access to file: " + e.getMessage());
|
||||
return null;
|
||||
throw new SimulationCreationException("No access to configuration file: " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
logger.fatal("Exception when loading file: " + e);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
throw new SimulationCreationException("Unknown error: " + e.getMessage());
|
||||
}
|
||||
|
||||
return newSim;
|
||||
|
@ -2934,5 +2960,12 @@ public class GUI {
|
|||
|
||||
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
|
||||
* 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;
|
||||
|
@ -149,6 +149,9 @@ public interface MoteType {
|
|||
Collection<Element> configXML, boolean visAvailable) throws MoteTypeCreationException;
|
||||
|
||||
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
|
||||
* 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;
|
||||
|
@ -165,9 +165,7 @@ public class ContikiMoteType implements MoteType {
|
|||
if (!ContikiMoteType.tempOutputDirectory.exists())
|
||||
ContikiMoteType.tempOutputDirectory.mkdir();
|
||||
if (!ContikiMoteType.tempOutputDirectory.exists()) {
|
||||
logger.fatal(">> Could not create output directory: "
|
||||
+ ContikiMoteType.tempOutputDirectory);
|
||||
return false;
|
||||
throw new MoteTypeCreationException("Could not create output directory: " + ContikiMoteType.tempOutputDirectory);
|
||||
}
|
||||
|
||||
// Delete output files
|
||||
|
@ -184,24 +182,20 @@ public class ContikiMoteType implements MoteType {
|
|||
if (mapFile.exists())
|
||||
mapFile.delete();
|
||||
if (libFile.exists()) {
|
||||
logger.fatal(">> Can't delete output file, aborting: " + libFile);
|
||||
return false;
|
||||
throw new MoteTypeCreationException("Could not delete output file: " + libFile);
|
||||
}
|
||||
if (depFile.exists()) {
|
||||
logger.fatal(">> Can't delete output file, aborting: " + depFile);
|
||||
return false;
|
||||
throw new MoteTypeCreationException("Could not delete output file: " + depFile);
|
||||
}
|
||||
if (mapFile.exists()) {
|
||||
logger.fatal(">> Can't delete output file, aborting: " + mapFile);
|
||||
return false;
|
||||
throw new MoteTypeCreationException("Could not delete output file: " + mapFile);
|
||||
}
|
||||
|
||||
// Generate Contiki main source file
|
||||
try {
|
||||
ContikiMoteTypeDialog.generateSourceFile(identifier, sensors, coreInterfaces, processes);
|
||||
} catch (Exception e) {
|
||||
logger.fatal(">> Error during file generation, aborting: " + e.getMessage());
|
||||
return false;
|
||||
throw new MoteTypeCreationException("Error during main source file generation: " + e.getMessage());
|
||||
}
|
||||
|
||||
// Compile library
|
||||
|
@ -216,14 +210,13 @@ public class ContikiMoteType implements MoteType {
|
|||
compilationSucceded = false;
|
||||
|
||||
if (!compilationSucceded) {
|
||||
logger.fatal(">> Error during compilation, aborting");
|
||||
return false;
|
||||
throw new MoteTypeCreationException("Error during compilation");
|
||||
}
|
||||
|
||||
// Load compiled library
|
||||
boolean loadingSucceded = doInit(identifier);
|
||||
doInit(identifier);
|
||||
|
||||
return loadingSucceded;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,15 +233,12 @@ public class ContikiMoteType implements MoteType {
|
|||
*
|
||||
* @param 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;
|
||||
|
||||
if (myCoreComm != null) {
|
||||
logger
|
||||
.fatal("Core communicator not null. Is library already loaded? Aborting");
|
||||
return false;
|
||||
throw new MoteTypeCreationException("Core communicator already used: " + myCoreComm.getClass().getName());
|
||||
}
|
||||
|
||||
File libFile = new File(ContikiMoteType.tempOutputDirectory,
|
||||
|
@ -258,14 +248,12 @@ public class ContikiMoteType implements MoteType {
|
|||
|
||||
// Check that library file exists
|
||||
if (!libFile.exists()) {
|
||||
logger.fatal("Library file could not be found: " + libFile);
|
||||
return false;
|
||||
throw new MoteTypeCreationException("Library file could not be found: " + libFile);
|
||||
}
|
||||
|
||||
// Check that map file exists
|
||||
if (!mapFile.exists()) {
|
||||
logger.fatal("Map file could not be found: " + mapFile);
|
||||
return false;
|
||||
throw new MoteTypeCreationException("Map file could not be found: " + mapFile);
|
||||
}
|
||||
|
||||
// Allocate core communicator class
|
||||
|
@ -289,8 +277,7 @@ public class ContikiMoteType implements MoteType {
|
|||
}
|
||||
|
||||
if (varAddresses.size() == 0) {
|
||||
logger.fatal("Variable name to addresses mappings could not be created");
|
||||
return false;
|
||||
throw new MoteTypeCreationException("Variable name to addresses mappings could not be created");
|
||||
}
|
||||
|
||||
// Get offset between relative and absolute addresses
|
||||
|
@ -305,8 +292,7 @@ public class ContikiMoteType implements MoteType {
|
|||
|
||||
if (relDataSectionAddr <= 0 || dataSectionSize <= 0
|
||||
|| relBssSectionAddr <= 0 || bssSectionSize <= 0) {
|
||||
logger.fatal("Could not parse section addresses correctly");
|
||||
return false;
|
||||
throw new MoteTypeCreationException("Could not parse section addresses correctly");
|
||||
}
|
||||
|
||||
// Create initial memory
|
||||
|
@ -319,8 +305,6 @@ public class ContikiMoteType implements MoteType {
|
|||
initialMemory = new SectionMoteMemory(varAddresses);
|
||||
initialMemory.setMemorySegment(relDataSectionAddr, initialDataSection);
|
||||
initialMemory.setMemorySegment(relBssSectionAddr, initialBssSection);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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;
|
||||
|
@ -2059,7 +2059,11 @@ public class ContikiMoteTypeDialog extends JDialog {
|
|||
try {
|
||||
myMoteType.doInit(textID.getText());
|
||||
} 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.setContikiBaseDir(textContikiDir.getText());
|
||||
|
|
Loading…
Reference in a new issue