Exemplo n.º 1
0
 private boolean callCppMethodOptionally(
     String moduleTypeName, String cpp, Object... thatAndParams) {
   try {
     NativeType[] types = new NativeType[thatAndParams.length - 1];
     for (int i = 0; i < types.length; i++) {
       types[i] = getNativeTypeForObject(thatAndParams[i + 1]);
     }
     NativeSymbolInfo info = finder.findAnyMethodForParameters(moduleTypeName, cpp, types);
     // System.err.println("FOR: " + moduleTypeName + " " + cpp + " " + Arrays.asList(types) + "
     // -> " + info);
     debug(
         "Mangled cpp method '"
             + moduleTypeName
             + "::"
             + cpp
             + "' as '"
             + (info == null ? "MISSING" : info.mangledName)
             + "'");
     if (info != null) {
       apply(f(info.mangledName), thatAndParams);
       return true;
     }
   } catch (UnsatisfiedLinkError err2) {
     debug("Failed calling on C++ method '" + moduleTypeName + "::" + cpp + "'");
     // swallow exception
   }
   return false;
 }
Exemplo n.º 2
0
  private Bundle getBundle(String bundleName) {
    Bundle bundle = bundles.get(bundleName);
    if (bundle == null) {
      /*
      NativeLibrary.addSearchPath(bundleName, ".");

      String module_path = System.getenv("GSP_MODULES_PATH");
      if (module_path != null && !module_path.isEmpty()) {
          String delims = ":";
          String[] tokens = module_path.split(delims);
          for (int i = 0; i < tokens.length; i++) {
              if(!tokens[i].isEmpty())
                  NativeLibrary.addSearchPath(bundleName, tokens[i]);
          }
      }

      module_path = System.getProperty("gsp.module.path");
      if (module_path != null && !module_path.isEmpty()) {
          String delims = ":";
          String[] tokens = module_path.split(delims);
          for (int i = 0; i < tokens.length; i++) {
              if(!tokens[i].isEmpty())
                  System.err.println("ADDED "+tokens[i]);
                  NativeLibrary.addSearchPath(bundleName, tokens[i]);
          }
      }

      try {
          bundle = new Bundle(NativeLibrary.getInstance(bundleName), NativeFunctionFinder.create(bundleName));
          bundles.put(bundleName, bundle);
      } catch (Exception e) {
          // TODO test NativeFunctionFinder also (add exceptions in it, or in the create or ...)

          // cannot load
          // TODO report
      }*/
      try {
        bundle =
            new Bundle(BridJ.getNativeLibrary(bundleName), NativeFunctionFinder.create(bundleName));
        bundles.put(bundleName, bundle);
        // bundle.jnalibrary = NativeLibrary.getInstance(bundleName);
      } catch (Exception e) {
        throw ex("Could not load native bundle/library with name '" + bundleName + "'", e);
        // TODO test NativeFunctionFinder also (add exceptions in it, or in the create or ...)
        // cannot load
        // TODO report
      }
    }
    return bundle;
  }