@Override public LKey addWatch(String path) throws IOException { // what if the file doesn't exist? int id = IMPL.inotify_add_watch(fd, path, InotifyImpl.IN_CREATE | InotifyImpl.IN_MOVED_TO | InotifyImpl.IN_DELETE | InotifyImpl.IN_MOVED_FROM | InotifyImpl.IN_MODIFY | InotifyImpl.IN_ATTRIB); //XXX handle error return value (-1) LOG.log(Level.FINEST, "addWatch{0} res: {1}", new Object[]{path, id}); if (id <= 0) { // 28 == EINOSPC int errno = NativeLibrary.getInstance("c").getFunction("errno").getInt(0); // NOI18N throw new IOException("addWatch on " + path + " errno: " + errno); // NOI18N } LKey newKey = map.get(id); if (newKey == null) { newKey = new LKey(id, path); map.put(id, newKey); } return newKey; }
public Saitek(File... libraryPath) { // try paths individually for (File f : libraryPath) { String path = f.toString(); if (path.length() > 0) { // System.out.println("Using jna.library.path " + path); System.setProperty("jna.library.path", path); } try { NativeLibrary.getInstance(DirectOutputLibrary.JNA_LIBRARY_NAME); dol = (DirectOutputLibrary) Native.loadLibrary(DirectOutputLibrary.JNA_LIBRARY_NAME, DirectOutputLibrary.class); } catch (UnsatisfiedLinkError err) { System.err.println("Unable to load DirectOutput.dll from " + f + " (running on " + System.getProperty("os.name") + "-" + System.getProperty("os.version") + "-" + System.getProperty("os.arch") + "\nContinuuing..."); continue; } System.out.println("Loaded library from " + f); break; } if (dol == null) { throw new IllegalArgumentException("Unable to load DirectOutput.dll from the paths provided"); } executor = Executors.newSingleThreadExecutor(); executor.submit(this::init); }
private static NativeLibrary loadLibraryWithTiming(String name) { String successName = String.format("mr4c.loadlib.%s.success", name); String failureName = String.format("mr4c.loadlib.%s.failure", name); StatsTimer timer = new StatsTimer( MR4CStats.getClient(), successName, failureName ); boolean success = false; try { NativeLibrary result = doLoadLibrary(name); success = true; return result; } finally { timer.done(success); } }
protected void loadNativeLibraries() { s_log.info("Begin loading native libraries"); s_log.info("jna.library.path={}", System.getProperty("jna.library.path")); s_log.info("jna.platform.library.path={}", System.getProperty("jna.platform.library.path")); s_log.info("LD_LIBRARY_PATH={}", System.getenv("LD_LIBRARY_PATH")); s_log.info("MR4C native library found at [{}]", Mr4cLibrary.JNA_NATIVE_LIB.getFile().getAbsolutePath()); String libName = getAlgorithmConfig().getArtifact(); s_log.info("Loading native algorithm library [{}]", libName); m_lib = JnaUtils.loadLibrary(libName); s_log.info("Native algorithm library found at [{}]", m_lib.getFile().getAbsolutePath()); for ( String name : getAlgorithmConfig().getExtras() ) { s_log.info("Loading extra native library [{}]", name); NativeLibrary lib = JnaUtils.loadLibrary(name); s_log.info("Extra native library found at [{}]", lib.getFile().getAbsolutePath()); m_extras.add(lib); } s_log.info("End loading native libraries"); }
@Override public void initialize(IWorkbenchConfigurer configurer) { super.initialize(configurer); org.eclipse.ui.ide.IDE.registerAdapters(); declareWorkbenchImages(); boolean found = false; String vlcLib = ManagementFactory.getRuntimeMXBean().getSystemProperties().get("vlc"); if (vlcLib != null) { found = true; NativeLibrary.addSearchPath("vlc", vlcLib); } if (!found) { found = new NativeDiscovery().discover(); } if (!found) { MessageDialog.openError(PlatformUI.getWorkbench().getDisplay().getActiveShell(), "Error", "Cannot play videos. VLC is either not installed or located in an unexpected directory. " + "If VLC is installed in an unexpected directory you can provide the path to its library. " + "Find SynergyView.ini and add a line to the end (if not already there) starting with " + "-Dvlc= followed by the path to an installation instance of VLC's lib folder."); } }
private static NativeLibrary getWin32NativeLibrary(String name) { // // gstreamer on win32 names the dll files one of foo.dll, libfoo.dll and libfoo-0.dll // String[] nameFormats = { "%s", "lib%s", "lib%s-0", }; for (int i = 0; i < nameFormats.length; ++i) { try { return NativeLibrary.getInstance(String.format(nameFormats[i], name)); } catch (UnsatisfiedLinkError ex) { continue; } } throw new UnsatisfiedLinkError("Could not load library " + name); }
public static boolean isAeroEnabled(){ if( HearthHelper.getOSName().equals("win") && DWM == null){ try{ DWM = NativeLibrary.getInstance("dwmapi"); } catch(Throwable e) {} } boolean dwmEnabled = false; if(DWM != null){ boolean[] bool = { false }; Object[] args = { bool }; Function DwmIsCompositionEnabled = DWM.getFunction("DwmIsCompositionEnabled"); HRESULT result = (HRESULT) DwmIsCompositionEnabled.invoke(HRESULT.class, args); boolean success = result.intValue()==0; if(success && bool[0]){ dwmEnabled = true; } } return dwmEnabled; }
@Override public void startup() throws PluginException { try { LOGGER.info("Initializing Praat library"); final String praatSearchFolder = PrefHelper.get(PRAAT_SEARCH_FOLDER, null); if(praatSearchFolder != null) { NativeLibrary.addSearchPath("praat", praatSearchFolder); } Praat.INSTANCE.praat_lib_init(); final PraatVersion praatVersion = PraatVersion.getVersion(); // print version information to log final StringBuilder sb = new StringBuilder(); sb.append("Praat version: ").append(praatVersion.versionStr); sb.append(" ").append(praatVersion.day).append('-').append(praatVersion.month).append('-').append(praatVersion.year); LOGGER.info(sb.toString()); } catch (UnsatisfiedLinkError e) { LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); } }
public static void loadVlc() { // String os = System.getProperty("os.name").toLowerCase(); // boolean is64bit = "64".equals(System.getProperty("sun.arch.data.model")); if (Config.isWindows()) { // windows if (Config.is64bit()) { System.out.println("Loading 64 bit Windows Libraries."); NativeLibrary.addSearchPath("libvlc", Config.VLC_URL + "windows" + File.separator + "x64" + File.separator); } else { System.out.println("Loading 32 bit Windows Libraries."); NativeLibrary.addSearchPath("libvlc", Config.VLC_URL + "windows" + File.separator + "x86" + File.separator); } } else if (Config.isMac()) { // mac } else if (Config.isLinux()) { // linus } else if (Config.isSolaris()) { // solaris } }
public static WinscardLibInfo openLib() { String libraryName = Platform.isWindows() ? WINDOWS_PATH : Platform.isMac() ? MAC_PATH : PCSC_PATH; HashMap<String, Object> options = new HashMap<String, Object>(); if (Platform.isWindows()) { options.put(Library.OPTION_FUNCTION_MAPPER, new WindowsFunctionMapper()); } else if (Platform.isMac()) { options.put(Library.OPTION_FUNCTION_MAPPER, new MacFunctionMapper()); } WinscardLibrary lib = (WinscardLibrary) Native.loadLibrary(libraryName, WinscardLibrary.class, options); NativeLibrary nativeLibrary = NativeLibrary.getInstance(libraryName); // SCARD_PCI_* is #defined to the following symbols (both pcsclite and winscard) ScardIoRequest SCARD_PCI_T0 = new ScardIoRequest(nativeLibrary.getGlobalVariableAddress("g_rgSCardT0Pci")); ScardIoRequest SCARD_PCI_T1 = new ScardIoRequest(nativeLibrary.getGlobalVariableAddress("g_rgSCardT1Pci")); ScardIoRequest SCARD_PCI_RAW = new ScardIoRequest(nativeLibrary.getGlobalVariableAddress("g_rgSCardRawPci")); SCARD_PCI_T0.read(); SCARD_PCI_T1.read(); SCARD_PCI_RAW.read(); SCARD_PCI_T0.setAutoSynch(false); SCARD_PCI_T1.setAutoSynch(false); SCARD_PCI_RAW.setAutoSynch(false); return new WinscardLibInfo(lib, SCARD_PCI_T0, SCARD_PCI_T1, SCARD_PCI_RAW); }
/** * Ensures that the vlcj Lib is properly loaded */ public synchronized static void ensureVLCLib(){ if(!vlcjLoaded && !vlcjLoadError) { String vlclibName = RuntimeUtil.getLibVlcLibraryName(); List<String> libPaths = VLCUtil.getVLCLibPaths(); logger.info("jni loading: " + vlclibName); for (String libPath : libPaths) { logger.debug("adding search path: " + libPath); NativeLibrary.addSearchPath(vlclibName, libPath); } try{ Native.loadLibrary(vlclibName, LibVlc.class); vlcjLoaded = true; }catch(UnsatisfiedLinkError e){ vlcjLoadError = true; logger.error(e); } } }
@Override public void initVideoImportEngine(Optional<String> pathToLibrary) { if (pathToLibrary.isPresent()) { log.debug("Path to library {}", pathToLibrary); NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), pathToLibrary.get()); Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class); log.debug("Library loaded"); } }
public int getStdOutNo() { try { return CLibrary.INSTANCE.fileno(NativeLibrary.getInstance("c") .getFunction(getStdOutName()).getPointer(0)); } catch (Throwable ex) { log("error getting stdout no -> return default. " + ex.getMessage()); } return 1; }
public int getStdErrNo() { try { return CLibrary.INSTANCE.fileno(NativeLibrary.getInstance("c") .getFunction(getStdErrName()).getPointer(0)); } catch (Throwable ex) { log("error getting stderr no -> return default. " + ex.getMessage()); } return 2; }
public int getStdInNo() { try { return CLibrary.INSTANCE.fileno(NativeLibrary.getInstance("c") .getFunction(getStdInName()).getPointer(0)); } catch (Throwable ex) { log("error getting stdin no -> return default. " + ex.getMessage()); } return 0; }
public static void main(String[] args) { // TODO code application logic here NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), NATIVE_LIBRARY_SEARCH_PATH); System.out.println(LibVlc.INSTANCE.libvlc_get_version()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new JSTPlay(); } }); }
public void create(String filepath) throws Error { camera = new OrthographicCamera(); camera.setToOrtho(false, w, h); camera.update(); LibXUtil.initialise(); NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), vlcpath); Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class); image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration() .createCompatibleImage((int) w, (int) h); image.setAccelerationPriority(1.0f); String[] args = null; if ((System.getProperty("os.name").toLowerCase().indexOf("mac") >= 0)) { String pluginpath = vlcpath.substring(0, vlcpath.lastIndexOf('/')) + "/plugins"; System.out.println(pluginpath); uk.co.caprica.vlcj.binding.LibC.INSTANCE.setenv("VLC_PLUGIN_PATH", pluginpath, 1); args = new String[] { "--no-video-title-show", "--verbose=3", "--vout=macosx" }; } else { args = new String[] { "--no-video-title-show", "--verbose=3" }; } factory = new MediaPlayerFactory(args); mediaPlayer = factory.newDirectMediaPlayer(new TestBufferFormatCallback(), new TestRenderCallback()); mediaPlayer.prepareMedia(filepath); mediaPlayer.start(); mediaPlayer.pause(); System.out.println(LibVlc.INSTANCE.libvlc_get_version()); }
public static void setupNatives() { if (!checkIsOSSupported()) { JOptionPane.showMessageDialog(null, "Sorry, " + getArchType() + " " + System.getProperty("os.name") + " is not supported!", "Unsupported OS", JOptionPane.ERROR_MESSAGE); System.exit(0); } String nativesFolder = File.separator + "natives" + File.separator; String suffix = Platform.is64Bit() ? "x64" : "x86"; switch(Platform.getOSType()) { case Platform.WINDOWS: nativesFolder += "windows"; break; case Platform.MAC: nativesFolder += "mac"; break; case Platform.LINUX: nativesFolder += "linux"; break; case Platform.FREEBSD: nativesFolder += "freebsd"; break; case Platform.OPENBSD: nativesFolder += "openbsd"; break; } nativesFolder += File.separator + suffix + File.separator; String nativesFolderPath = (new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile()).getPath() + nativesFolder; //System.out.println((new File(Main.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile()).getPath() + nativesFolder); if(!new File(nativesFolderPath).exists()) { //JOptionPane.showMessageDialog(null, "Could not find natives folder: " + nativesFolder, "No Natives Found", JOptionPane.ERROR_MESSAGE); //System.exit(0); } NativeLibrary.addSearchPath("leveldb", nativesFolderPath); }
public MyVideoPanel() { NativeLibrary.addSearchPath("libvlc", vlcWhere.getAbsolutePath()); EmbeddedMediaPlayerComponent videoCanvas = new EmbeddedMediaPlayerComponent(); setLayout(new BorderLayout()); add(videoCanvas, BorderLayout.CENTER); player = videoCanvas.getMediaPlayer(); }
public static synchronized NativeLibrary getNativeLibrary(String name) { if (!Platform.isWindows()) return NativeLibrary.getInstance(name); for (String format : windowsNameFormats) try { return NativeLibrary.getInstance(String.format(format, name)); } catch (UnsatisfiedLinkError ex) { continue; } throw new UnsatisfiedLinkError("Could not load library: " + name); }
public String getFunctionName(NativeLibrary library, Method method) { String name = method.getName(); for (String prefix : stripPrefixes) { if (name.startsWith(prefix)) { return name.substring(prefix.length()); } } // Default to just returning the name return name; }
public static NativeLibrary loadLibrary(String library) { try { return NativeLibrary.getInstance(saveLibrary(library)); } catch (IOException e) { return NativeLibrary.getInstance(library); } }
public static synchronized NativeLibrary getNativeLibrary(String name) { for (String format : nameFormats) try { return NativeLibrary.getInstance(String.format(format, name)); } catch (UnsatisfiedLinkError ex) { continue; } throw new UnsatisfiedLinkError("Could not load library: " + name); }
public synchronized static NativeLibrary loadLibrary(String name) { NativeLibrary lib = s_loadedLibs.get(name); if ( lib==null ) { lib = loadLibraryWithTiming(name); s_loadedLibs.put(name,lib); } return lib; }
public Collection<File> getRequiredFiles() { List<File> files = new ArrayList(); files.add(Mr4cLibrary.JNA_NATIVE_LIB.getFile()); files.add( m_lib.getFile()); for ( NativeLibrary lib : m_extras ) { files.add(lib.getFile()); } return files; }
/** * Loads the native libs creating the native wrapper. * * @param nativeLibPath the path to add or <code>null</code>. * @param libName the lib name or <code>null</code>, in which case "las_c" is used. * @return <code>null</code>, if the lib could be loaded, the error string else. */ public static String loadNativeLibrary( String nativeLibPath, String libName ) { try { String name = "las_c"; if (libName == null) libName = name; if (nativeLibPath != null) { NativeLibrary.addSearchPath(libName, nativeLibPath); } WRAPPER = (LiblasJNALibrary) Native.loadLibrary(libName, LiblasJNALibrary.class); } catch (UnsatisfiedLinkError e) { return e.getLocalizedMessage(); } return null; }
/** * Contructor for the {@link EpanetWrapper}. * * <p>This also takes care to load the native library, if needed. * * @param lib the name of the library (ex. "epanet2_64bit"). * @param nativeLibPath the path in which to search the native library. * If the native library is already in the java library path * this is not needed and may be <code>null</code> * @throws Exception if the library could not be loaded. */ public EpanetWrapper( String lib, String nativeLibPath ) throws Exception { if (epanet == null) { try { if (nativeLibPath != null) NativeLibrary.addSearchPath(lib, nativeLibPath); epanet = (EpanetNativeFunctions) Native.loadLibrary(lib, EpanetNativeFunctions.class); } catch (Exception e) { throw new Exception("An error occurred while trying to load the epanet library.", e); } } }
@Primitive("dyn.load") public static ListVector dynLoad(String libraryPath, SEXP local, SEXP now, SEXP dllPath) { NativeLibrary library = NativeLibrary.getInstance(libraryPath); ListVector.NamedBuilder result = new ListVector.NamedBuilder(); result.add("name", library.getName()); result.add("path", libraryPath); result.add("dynamicLookup", LogicalVector.TRUE); result.add("handle", new ExternalExp<NativeLibrary>(library)); result.add("info", "something here"); result.setAttribute(Symbols.CLASS, StringVector.valueOf("DLLInfo")); return result.build(); }
public static synchronized void init() { NativeLibrary libcLibrary = NativeLibrary.getInstance(Platform.C_LIBRARY_NAME); // We kill subprocesses by sending SIGHUP to our process group; we want our subprocesses to die // on SIGHUP while we ourselves stay around. We can't just set SIGHUP to SIG_IGN, because // subprocesses would inherit the SIG_IGN signal disposition and be immune to the SIGHUP we // direct toward the process group. We need _some_ signal handler that does nothing --- i.e., // acts like SIG_IGN --- but that doesn't kill its host process. When we spawn a subprocess, // the kernel replaces any signal handler that is not SIG_IGN with SIG_DFL, automatically // creating the signal handler configuration we want. // // getpid might seem like a strange choice of signal handler, but consider the following: // // 1) on all supported ABIs, calling a function that returns int as if it returned void is // harmless --- the return value is stuffed into a register (for example, EAX on x86 // 32-bit) that the caller ignores (EAX is caller-saved), // // 2) on all supported ABIs, calling a function with extra arguments is safe --- the callee // ignores the extra arguments, which are passed either in caller-saved registers or in // stack locations that the caller [1] cleans up upon return, // // 3) getpid is void(*)(int); signal handlers are void(*)(int), and // // 4) getpid is async-signal-safe according to POSIX. // // Therefore, it is safe to set getpid _as_ a signal handler. It does nothing, exactly as we // want, and gets reset to SIG_DFL in subprocesses. If we were a C program, we'd just define a // no-op function of the correct signature to use as a handler, but we're using JNA, and while // JNA does have the ability to C function pointer to a Java function, it cannot create an // async-signal-safe C function, since calls into Java are inherently signal-unsafe. // // [1] Win32 32-bit x86 stdcall is an exception to this general rule --- because the callee // cleans up its stack --- but we don't run this code on Windows. // Libc.INSTANCE.signal(Libc.Constants.SIGHUP, libcLibrary.getFunction("getpid")); initialized = true; }
public JnaNativeLibrary(JnaNativeInterface nativeInterface, String name, Map<String, Object> options) { this.nativeInterface = nativeInterface; // this is a kludge - but i can't ask for the searchpaths already // registered for (Iterator<String> it = nativeInterface.getSearchPaths().iterator(); it .hasNext();) { String path = it.next(); NativeLibrary.addSearchPath(name, path); } library = NativeLibrary.getInstance(name, options); }
private static UnsatisfiedLinkError attemptLib() { try { String lib = "compileEGMf"; //$NON-NLS-1$ NativeLibrary.addSearchPath(lib,"."); //$NON-NLS-1$ NativeLibrary.addSearchPath(lib,LGM.workDir.getParent()); DRIVER = (EnigmaDriver) Native.loadLibrary(lib,EnigmaDriver.class); return null; } catch (UnsatisfiedLinkError e) { return e; } }
public static void onWindows() { // Windows taskbar fix: provideAppUserModelID try { NativeLibrary lib = NativeLibrary.getInstance("shell32"); Function function = lib.getFunction("SetCurrentProcessExplicitAppUserModelID"); Object[] args = {new WString(APPID)}; function.invokeInt(args); } catch (Error e) { return; } catch (Exception x) { return; } }
public ScreenRecorder() { NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), System.getProperty("user.dir")+"/lib"); System.setProperty("VLC_PLUGIN_PATH", System.getProperty("user.dir")+"/lib/plugins"); mediaPlayerFactory = new MediaPlayerFactory(OPTIONS); mediaPlayer = mediaPlayerFactory.newHeadlessMediaPlayer(); }
private void initPlayer() { boolean found = new NativeDiscovery().discover(); if (!found) { NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), NATIVE_LIBRARY_SEARCH_PATH); } }
@Override public String getFunctionName(NativeLibrary lib, Method method) { // MediaInfo_New(), MediaInfo_Open() ... return "MediaInfo_" + method.getName(); }
public GlobalPointerType(NativeLibrary library, Class<T> type, String... symbols) { super(library, type, symbols); indirected = true; }
public GlobalInt(NativeLibrary library, String... symbols) { super(library, IntByReference.class, symbols); }
public GlobalFloat(NativeLibrary library, String... symbols) { super(library, FloatByReference.class, symbols); }
public GlobalLong(NativeLibrary library, String... symbols) { super(library, LongByReference.class, symbols); }