throwing exceptions when trying to access the library initially

This commit is contained in:
fros4943 2007-04-03 16:18:04 +00:00
parent e2165bc38b
commit 2a216122b3
3 changed files with 31 additions and 19 deletions

View file

@ -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: CoreComm.java,v 1.5 2007/03/24 00:41:10 fros4943 Exp $ * $Id: CoreComm.java,v 1.6 2007/04/03 16:18:44 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -34,6 +34,8 @@ import java.lang.reflect.*;
import java.net.*; import java.net.*;
import java.util.Vector; import java.util.Vector;
import se.sics.cooja.MoteType.MoteTypeCreationException;
/** /**
* The purpose of corecomm's is communicating with a compiled Contiki system * The purpose of corecomm's is communicating with a compiled Contiki system
* using Java Native Interface (JNI). Each implemented class (named Lib[number]), * using Java Native Interface (JNI). Each implemented class (named Lib[number]),
@ -207,15 +209,15 @@ public abstract class CoreComm {
p = Runtime.getRuntime().exec(cmd, null, null); p = Runtime.getRuntime().exec(cmd, null, null);
p.waitFor(); p.waitFor();
if (classFile.exists())
return true;
} catch (IOException e) { } catch (IOException e) {
return false; return false;
} catch (InterruptedException e) { } catch (InterruptedException e) {
return false; return false;
} }
if (classFile.exists())
return true;
return false; return false;
} }
@ -250,16 +252,17 @@ public abstract class CoreComm {
* Native library file * Native library file
* @return Core Communicator * @return Core Communicator
*/ */
public static CoreComm createCoreComm(String className, File libFile) { public static CoreComm createCoreComm(String className, File libFile)
throws MoteTypeCreationException {
if (!generateLibSourceFile(className)) if (!generateLibSourceFile(className))
return null; throw new MoteTypeCreationException("Could not generate library source file: " + className);
if (!compileSourceFile(className)) if (!compileSourceFile(className))
return null; throw new MoteTypeCreationException("Could not compile library: " + className);
Class newCoreCommClass = loadClassFile(className); Class newCoreCommClass = loadClassFile(className);
if (newCoreCommClass == null) if (newCoreCommClass == null)
return null; throw new MoteTypeCreationException("Could not load library class file: " + className);
try { try {
Constructor constr = newCoreCommClass.getConstructor(new Class[] { File.class }); Constructor constr = newCoreCommClass.getConstructor(new Class[] { File.class });
@ -271,13 +274,13 @@ public abstract class CoreComm {
return newCoreComm; return newCoreComm;
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
return null; throw new MoteTypeCreationException("Error when creating library instance: " + className);
} catch (InstantiationException e) { } catch (InstantiationException e) {
return null; throw new MoteTypeCreationException("Error when creating library instance: " + className);
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
return null; throw new MoteTypeCreationException("Error when creating library instance: " + className);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
return null; throw new MoteTypeCreationException("Error when creating library instance: " + className);
} }
} }

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: ContikiMoteType.java,v 1.10 2007/04/02 12:45:19 fros4943 Exp $ * $Id: ContikiMoteType.java,v 1.11 2007/04/03 16:18:05 fros4943 Exp $
*/ */
package se.sics.cooja.contikimote; package se.sics.cooja.contikimote;
@ -280,9 +280,13 @@ public class ContikiMoteType implements MoteType {
throw new MoteTypeCreationException("Variable name to addresses mappings could not be created"); throw new MoteTypeCreationException("Variable name to addresses mappings could not be created");
} }
try {
// Get offset between relative and absolute addresses // Get offset between relative and absolute addresses
offsetRelToAbs = getReferenceAbsAddr() offsetRelToAbs = getReferenceAbsAddr()
- getRelVarAddr(mapFileData, "referenceVar"); - getRelVarAddr(mapFileData, "referenceVar");
} catch (Exception e) {
throw new MoteTypeCreationException("JNI call error: " + e.getMessage());
}
// Parse addresses of data and BSS memory sections // Parse addresses of data and BSS memory sections
int relDataSectionAddr = loadRelDataSectionAddr(mapFileData); int relDataSectionAddr = loadRelDataSectionAddr(mapFileData);

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: MantisMoteType.java,v 1.3 2007/03/23 23:34:33 fros4943 Exp $ * $Id: MantisMoteType.java,v 1.4 2007/04/03 16:18:04 fros4943 Exp $
*/ */
package se.sics.cooja.mantismote; package se.sics.cooja.mantismote;
@ -134,7 +134,12 @@ public class MantisMoteType implements MoteType {
// Allocate core communicator class // Allocate core communicator class
libraryClassName = CoreComm.getAvailableClassName(); libraryClassName = CoreComm.getAvailableClassName();
try {
myCoreComm = CoreComm.createCoreComm(libraryClassName, libFile); myCoreComm = CoreComm.createCoreComm(libraryClassName, libFile);
} catch (MoteTypeCreationException e) {
logger.fatal("Library creation failed: " + e.getMessage());
return false;
}
// Parse variable name to addresses mappings using nm // Parse variable name to addresses mappings using nm
varAddresses.clear(); varAddresses.clear();