com.sun.jna.Library Java Examples
The following examples show how to use
com.sun.jna.Library.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FbClientFeatureAccessHandler.java From jaybird with GNU Lesser General Public License v2.1 | 5 votes |
private static InvocationHandler syncWrapIfNecessary(final FbClientLibrary clientLibrary, final Library.Handler originalHandler) { if (JaybirdSystemProperties.isSyncWrapNativeLibrary()) { // Mimics com.sun.jna.Native.synchronizedLibrary(..) with creating a proxy return new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { synchronized (originalHandler.getNativeLibrary()) { return originalHandler.invoke(clientLibrary, method, args); } } }; } return originalHandler; }
Example #2
Source File: k8055Binding.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
protected boolean connect() { try { if (sysLibrary == null) { logger.debug("Loading native code library..."); sysLibrary = (LibK8055) Native .synchronizedLibrary((Library) Native.loadLibrary("k8055", LibK8055.class)); logger.debug("Done loading native code library"); } if (!connected) { if (sysLibrary.OpenDevice(boardNo) == boardNo) { connected = true; // We don't really know the existing state - so this results // in the state of all inputs being republished lastDigitalInputs = -1; logger.info("K8055: Connect to board: " + boardNo + " succeeeded."); } else { logger.error("K8055: Connect to board: " + boardNo + " failed."); } } ; } catch (Exception e) { logger.error( "Failed to load K8055 native library. Please check the libk8055 and jna native libraries are in the Java library path. ", e); } return connected; }
Example #3
Source File: NativeLibraryTools.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
public static < L extends Library > L loadNativeLibrary( final Class< L > library ) { final ArrayList< String > names = new ArrayList< String >(); return loadNativeLibrary( names, library ); }
Example #4
Source File: NativeLibraryTools.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
public static < L extends Library > L loadNativeLibrary( final String potentialName, final Class< L > library ) { final ArrayList< String > names = new ArrayList< String >(); names.add( potentialName ); return loadNativeLibrary( names, library ); }
Example #5
Source File: FbClientFeatureAccessHandler.java From jaybird with GNU Lesser General Public License v2.1 | 2 votes |
/** * Creates a {@code FbClientLibrary} proxy implementing {@link FbClientFeatureAccess}. * * @param library * The original {@code FbClientLibrary} proxy object * @return New proxy for {@code library} that implements {@link FbClientFeatureAccess} * @throws IllegalArgumentException * if {@code library} is not a proxy with {@link Library.Handler} as its invocation handler */ static FbClientLibrary decorateWithFeatureAccess(FbClientLibrary library) { Class<?> libraryClass = library.getClass(); if (!Proxy.isProxyClass(libraryClass)) { throw new IllegalArgumentException( "Could not decorate client library with FbClientFeatureAccess: not a proxy"); } InvocationHandler ih = Proxy.getInvocationHandler(library); if (!(ih instanceof Library.Handler)) { throw new IllegalArgumentException("Could not decorate client library with FbClientFeatureAccess: " + "unexpected invocation handler type " + ih.getClass()); } Library.Handler originalHandler = (Library.Handler) ih; NativeLibrary nativeLibrary = originalHandler.getNativeLibrary(); Set<FbClientFeature> clientFeatures = determineClientFeatures(nativeLibrary); InvocationHandler delegatedHandler = syncWrapIfNecessary(library, originalHandler); FbClientFeatureAccessHandler fbClientFeatureAccessHandler = new FbClientFeatureAccessHandler(library, nativeLibrary, clientFeatures, delegatedHandler); Class<?> interfaceClass = originalHandler.getInterfaceClass(); ClassLoader loader = interfaceClass.getClassLoader(); Object proxy = Proxy.newProxyInstance(loader, new Class[] { interfaceClass, FbClientFeatureAccess.class }, fbClientFeatureAccessHandler); return (FbClientLibrary) proxy; }