Search in sources :

Example 1 with NativeLong

use of com.sun.jna.NativeLong in project jna by java-native-access.

the class W32StdCallTest method testStdCallCallbackStackAlignment.

public void testStdCallCallbackStackAlignment() {
    final boolean[] called = { false };
    TestLibrary.ManyArgsStdCallCallback cb = new TestLibrary.ManyArgsStdCallCallback() {

        @Override
        public void callback(NativeLong arg1, int arg2, double arg3, String arg4, String arg5, double arg6, NativeLong arg7, double arg8, NativeLong arg9, NativeLong arg10, NativeLong arg11) {
            called[0] = true;
        }
    };
    int value = testlib.callManyArgsStdCallCallback(cb, new NativeLong(1), 2, 3, "four", "five", 6, new NativeLong(7), 8, new NativeLong(9), new NativeLong(10), new NativeLong(11));
    assertTrue("stdcall callback not called", called[0]);
    if (value == -1) {
        fail("stdcall callback did not restore the stack pointer");
    }
}
Also used : NativeLong(com.sun.jna.NativeLong)

Example 2 with NativeLong

use of com.sun.jna.NativeLong in project jna by java-native-access.

the class AlphaMaskDemo method updateX11.

private void updateX11(boolean a, boolean i) {
    X11 x11 = X11.INSTANCE;
    X11.Window win = X11.Window.None;
    Display dpy = x11.XOpenDisplay(null);
    try {
        if (!alphaWindow.isDisplayable()) {
            alphaWindow.pack();
            if (System.getProperty("java.version").matches("^1\\.4\\..*"))
                alphaWindow.setVisible(true);
            win = new X11.Window((int) Native.getWindowID(alphaWindow));
            Window parent = alphaWindow.getOwner();
            Point where = parent.getLocationOnScreen();
            where.translate(parent.getWidth(), 0);
            alphaWindow.removeAll();
            alphaWindow.setLocation(where);
            alphaWindow.setBackground(new Color(0, 0, 0, 0));
        } else {
            win = new X11.Window((int) Native.getWindowID(alphaWindow));
        }
        if (i) {
            int w = image.getWidth(null);
            int h = image.getHeight(null);
            alphaWindow.setSize(w, h);
            if (buffer == null || buffer.size() != w * h * 4) {
                buffer = new com.sun.jna.Memory(w * h * 4);
                pixels = new int[w * h];
            }
            BufferedImage buf = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
            Graphics g = buf.getGraphics();
            g.drawImage(image, 0, 0, w, h, null);
            long start = System.currentTimeMillis();
            long blitTime, putImageTime, write;
            GC gc = x11.XCreateGC(dpy, win, new NativeLong(0), null);
            long gcTime = System.currentTimeMillis();
            try {
                Raster raster = buf.getData();
                int[] pixel = new int[4];
                for (int y = 0; y < h; y++) {
                    for (int x = 0; x < w; x++) {
                        raster.getPixel(x, y, pixel);
                        int alpha = (pixel[3] & 0xFF) << 24;
                        int red = (pixel[2] & 0xFF);
                        int green = (pixel[1] & 0xFF) << 8;
                        int blue = (pixel[0] & 0xFF) << 16;
                        pixels[y * w + x] = alpha | red | green | blue;
                    }
                }
                blitTime = System.currentTimeMillis();
                X11.XWindowAttributes xwa = new X11.XWindowAttributes();
                x11.XGetWindowAttributes(dpy, win, xwa);
                X11.XImage image = x11.XCreateImage(dpy, xwa.visual, 32, X11.ZPixmap, 0, buffer, w, h, 32, w * 4);
                buffer.write(0, pixels, 0, pixels.length);
                write = System.currentTimeMillis();
                x11.XPutImage(dpy, win, gc, image, 0, 0, 0, 0, w, h);
                x11.XFree(image.getPointer());
                putImageTime = System.currentTimeMillis();
            } finally {
                if (gc != null)
                    x11.XFreeGC(dpy, gc);
            }
            long end = System.currentTimeMillis();
        //System.out.println("gc: " + (gcTime-start) + "ms");
        //System.out.println("blit: " + (blitTime-gcTime) + "ms");
        //System.out.println("write: " + (write-blitTime) + "ms");
        //System.out.println("put image: " + (putImageTime-write) + "ms");
        //System.out.println("total: " + (end-start) + "ms");
        }
    } finally {
        if (dpy != null)
            x11.XCloseDisplay(dpy);
    }
    if (a)
        WindowUtils.setWindowAlpha(alphaWindow, alpha);
    if (!alphaWindow.isVisible()) {
        alphaWindow.setVisible(true);
        // hack for initial refresh (X11)
        update(true, true);
    }
}
Also used : Window(java.awt.Window) JWindow(javax.swing.JWindow) Color(java.awt.Color) NativeLong(com.sun.jna.NativeLong) Raster(java.awt.image.Raster) Point(java.awt.Point) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) Graphics(java.awt.Graphics) X11(com.sun.jna.platform.unix.X11) GC(com.sun.jna.platform.unix.X11.GC) Display(com.sun.jna.platform.unix.X11.Display)

Example 3 with NativeLong

use of com.sun.jna.NativeLong in project hudson-2.x by hudson.

the class Util method resolveSymlink.

/**
     * Resolves symlink, if the given file is a symlink. Otherwise return null.
     * <p>
     * If the resolution fails, report an error.
     *
     * @param listener
     *      If we rely on an external command to resolve symlink, this is it.
     *      (TODO: try readlink(1) available on some platforms)
     */
public static String resolveSymlink(File link, TaskListener listener) throws InterruptedException, IOException {
    if (Functions.isWindows())
        return null;
    String filename = link.getAbsolutePath();
    try {
        for (int sz = 512; sz < 65536; sz *= 2) {
            Memory m = new Memory(sz);
            int r = LIBC.readlink(filename, m, new NativeLong(sz));
            if (r < 0) {
                int err = Native.getLastError();
                if (err == 22)
                    /*EINVAL --- but is this really portable?*/
                    return // this means it's not a symlink
                    null;
                throw new IOException("Failed to readlink " + link + " error=" + err + " " + LIBC.strerror(err));
            }
            if (r == sz)
                // buffer too small
                continue;
            byte[] buf = new byte[r];
            m.read(0, buf, 0, r);
            return new String(buf);
        }
        // something is wrong. It can't be this long!
        throw new IOException("Symlink too long: " + link);
    } catch (LinkageError e) {
        // we still prefer to try JNA first as PosixAPI supports even smaller platforms.
        return PosixAPI.get().readlink(filename);
    }
}
Also used : Memory(com.sun.jna.Memory) NativeLong(com.sun.jna.NativeLong) IOException(java.io.IOException)

Example 4 with NativeLong

use of com.sun.jna.NativeLong in project jna by java-native-access.

the class XTestDemo method typeKey.

private void typeKey(int keyCode) {
    if (keyCode == -1)
        return;
    // press key
    X11.XTest.INSTANCE.XTestFakeKeyEvent(display.getX11Display(), keyCode, true, new NativeLong(DELAY));
    X11.INSTANCE.XFlush(display.getX11Display());
    // release key
    X11.XTest.INSTANCE.XTestFakeKeyEvent(display.getX11Display(), keyCode, false, new NativeLong(DELAY));
    X11.INSTANCE.XFlush(display.getX11Display());
}
Also used : NativeLong(com.sun.jna.NativeLong)

Example 5 with NativeLong

use of com.sun.jna.NativeLong in project voldemort by voldemort.

the class mman method mmap.

/* Changes are private. */
// http://linux.die.net/man/2/mmap
// http://www.opengroup.org/sud/sud1/xsh/mmap.htm
// http://linux.die.net/include/sys/mman.h
// http://linux.die.net/include/bits/mman.h
// off_t = 8
// size_t = 8
/**
     * Map the given region of the given file descriptor into memory.
     * Returns a Pointer to the newly mapped memory throws an
     * IOException on error.
     */
public static Pointer mmap(long len, int prot, int flags, int fildes, long off) throws IOException {
    // we don't really have a need to change the recommended pointer.
    Pointer addr = new Pointer(0);
    Pointer result = Delegate.mmap(addr, new NativeLong(len), prot, flags, fildes, new NativeLong(off));
    if (Pointer.nativeValue(result) == -1) {
        if (logger.isDebugEnabled())
            logger.debug(errno.strerror());
        throw new IOException("mmap failed: " + errno.strerror());
    }
    return result;
}
Also used : NativeLong(com.sun.jna.NativeLong) Pointer(com.sun.jna.Pointer) IOException(java.io.IOException)

Aggregations

NativeLong (com.sun.jna.NativeLong)5 IOException (java.io.IOException)2 Memory (com.sun.jna.Memory)1 Pointer (com.sun.jna.Pointer)1 X11 (com.sun.jna.platform.unix.X11)1 Display (com.sun.jna.platform.unix.X11.Display)1 GC (com.sun.jna.platform.unix.X11.GC)1 Color (java.awt.Color)1 Graphics (java.awt.Graphics)1 Point (java.awt.Point)1 Window (java.awt.Window)1 BufferedImage (java.awt.image.BufferedImage)1 Raster (java.awt.image.Raster)1 JWindow (javax.swing.JWindow)1