throwing exceptions when trying to access the library initially
This commit is contained in:
parent
e2165bc38b
commit
2a216122b3
|
@ -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: 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;
|
||||
|
@ -34,6 +34,8 @@ import java.lang.reflect.*;
|
|||
import java.net.*;
|
||||
import java.util.Vector;
|
||||
|
||||
import se.sics.cooja.MoteType.MoteTypeCreationException;
|
||||
|
||||
/**
|
||||
* The purpose of corecomm's is communicating with a compiled Contiki system
|
||||
* 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.waitFor();
|
||||
|
||||
if (classFile.exists())
|
||||
return true;
|
||||
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
} catch (InterruptedException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (classFile.exists())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -250,16 +252,17 @@ public abstract class CoreComm {
|
|||
* Native library file
|
||||
* @return Core Communicator
|
||||
*/
|
||||
public static CoreComm createCoreComm(String className, File libFile) {
|
||||
public static CoreComm createCoreComm(String className, File libFile)
|
||||
throws MoteTypeCreationException {
|
||||
if (!generateLibSourceFile(className))
|
||||
return null;
|
||||
throw new MoteTypeCreationException("Could not generate library source file: " + className);
|
||||
|
||||
if (!compileSourceFile(className))
|
||||
return null;
|
||||
throw new MoteTypeCreationException("Could not compile library: " + className);
|
||||
|
||||
Class newCoreCommClass = loadClassFile(className);
|
||||
if (newCoreCommClass == null)
|
||||
return null;
|
||||
throw new MoteTypeCreationException("Could not load library class file: " + className);
|
||||
|
||||
try {
|
||||
Constructor constr = newCoreCommClass.getConstructor(new Class[] { File.class });
|
||||
|
@ -271,13 +274,13 @@ public abstract class CoreComm {
|
|||
|
||||
return newCoreComm;
|
||||
} catch (NoSuchMethodException e) {
|
||||
return null;
|
||||
throw new MoteTypeCreationException("Error when creating library instance: " + className);
|
||||
} catch (InstantiationException e) {
|
||||
return null;
|
||||
throw new MoteTypeCreationException("Error when creating library instance: " + className);
|
||||
} catch (InvocationTargetException e) {
|
||||
return null;
|
||||
throw new MoteTypeCreationException("Error when creating library instance: " + className);
|
||||
} catch (IllegalAccessException e) {
|
||||
return null;
|
||||
throw new MoteTypeCreationException("Error when creating library instance: " + className);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.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;
|
||||
|
@ -280,9 +280,13 @@ public class ContikiMoteType implements MoteType {
|
|||
throw new MoteTypeCreationException("Variable name to addresses mappings could not be created");
|
||||
}
|
||||
|
||||
// Get offset between relative and absolute addresses
|
||||
offsetRelToAbs = getReferenceAbsAddr()
|
||||
- getRelVarAddr(mapFileData, "referenceVar");
|
||||
try {
|
||||
// Get offset between relative and absolute addresses
|
||||
offsetRelToAbs = getReferenceAbsAddr()
|
||||
- getRelVarAddr(mapFileData, "referenceVar");
|
||||
} catch (Exception e) {
|
||||
throw new MoteTypeCreationException("JNI call error: " + e.getMessage());
|
||||
}
|
||||
|
||||
// Parse addresses of data and BSS memory sections
|
||||
int relDataSectionAddr = loadRelDataSectionAddr(mapFileData);
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* 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;
|
||||
|
@ -134,8 +134,13 @@ public class MantisMoteType implements MoteType {
|
|||
|
||||
// Allocate core communicator class
|
||||
libraryClassName = CoreComm.getAvailableClassName();
|
||||
myCoreComm = CoreComm.createCoreComm(libraryClassName, libFile);
|
||||
|
||||
try {
|
||||
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
|
||||
varAddresses.clear();
|
||||
Vector<String> nmData = ContikiMoteType.loadNmData(libFile);
|
||||
|
|
Loading…
Reference in a new issue