static void setProgress(IdeFrame frame, double value, boolean isOk) { if (!isEnabled()) { return; } WinDef.HWND handle = getHandle(frame); mySetProgressState.invokeInt( new Object[] {myInterfacePointer, handle, isOk ? TBPF_NORMAL : TBPF_ERROR}); mySetProgressValue.invokeInt( new Object[] { myInterfacePointer, handle, new WinDef.ULONGLONG((long) (value * 100)), TOTAL_PROGRESS }); }
static void hideProgress(IdeFrame frame) { if (!isEnabled()) { return; } mySetProgressState.invokeInt( new Object[] {myInterfacePointer, getHandle(frame), TBPF_NOPROGRESS}); }
static void setOverlayIcon(IdeFrame frame, Object icon, boolean dispose) { if (!isEnabled()) { return; } if (icon == null) { icon = Pointer.NULL; } mySetOverlayIcon.invokeInt( new Object[] {myInterfacePointer, getHandle(frame), icon, Pointer.NULL}); if (dispose) { User32.INSTANCE.DestroyIcon((WinDef.HICON) icon); } }
public void testInterceptLastError() { if (!Platform.isWindows()) { return; } NativeLibrary kernel32 = (NativeLibrary) NativeLibrary.getInstance("kernel32", W32APIOptions.DEFAULT_OPTIONS); Function get = kernel32.getFunction("GetLastError"); Function set = kernel32.getFunction("SetLastError"); assertEquals("SetLastError should not be customized", Function.class, set.getClass()); assertTrue( "GetLastError should be a Function", Function.class.isAssignableFrom(get.getClass())); assertTrue("GetLastError should be a customized Function", get.getClass() != Function.class); final int EXPECTED = 42; set.invokeVoid(new Object[] {new Integer(EXPECTED)}); assertEquals("Wrong error", EXPECTED, get.invokeInt(null)); }
public void testFunctionHoldsLibraryReference() throws Exception { NativeLibrary lib = NativeLibrary.getInstance("testlib"); WeakReference ref = new WeakReference(lib); Function f = lib.getFunction("callCount"); lib = null; System.gc(); long start = System.currentTimeMillis(); while (ref.get() != null && System.currentTimeMillis() - start < 2000) { Thread.sleep(10); } assertNotNull("Library GC'd when it should not be", ref.get()); f.invokeInt(new Object[0]); f = null; System.gc(); while (ref.get() != null && System.currentTimeMillis() - start < 5000) { Thread.sleep(10); } assertNull("Library not GC'd", ref.get()); }
public static int sched_getcpu() { final CLibrary lib = CLibrary.INSTANCE; try { final int ret = lib.sched_getcpu(); if (ret < 0) { throw new IllegalStateException("sched_getcpu() failed; errno=" + Native.getLastError()); } return ret; } catch (LastErrorException e) { throw new IllegalStateException("sched_getcpu() failed; errno=" + e.getErrorCode(), e); } catch (UnsatisfiedLinkError ule) { try { final IntByReference cpu = new IntByReference(); final IntByReference node = new IntByReference(); final int ret = lib.syscall(318, cpu, node, null); if (ret != 0) { throw new IllegalStateException("getcpu() failed; errno=" + Native.getLastError()); } return cpu.getValue(); } catch (LastErrorException lee) { if (lee.getErrorCode() == 38 && Platform.is64Bit()) { // unknown call final Pointer getcpuAddr = new Pointer((-10L << 20) + 1024L * 2L); final Function getcpu = Function.getFunction(getcpuAddr, Function.C_CONVENTION); final IntByReference cpu = new IntByReference(); if (getcpu.invokeInt(new Object[] {cpu, null, null}) < 0) { throw new IllegalStateException("getcpu() failed; errno=" + Native.getLastError()); } else { return cpu.getValue(); } } else { throw new IllegalStateException("getcpu() failed; errno=" + lee.getErrorCode(), lee); } } } }