Search in sources :

Example 71 with PointerByReference

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

the class X11Test method testXGetWMProtocols.

public void testXGetWMProtocols() {
    X11.Atom[] sentAtoms = new X11.Atom[] { X11.INSTANCE.XInternAtom(display, "WM_DELETE_WINDOW", false), X11.INSTANCE.XInternAtom(display, "WM_TAKE_FOCUS", false) };
    X11.INSTANCE.XSetWMProtocols(display, root, sentAtoms, sentAtoms.length);
    PointerByReference protocols = new PointerByReference();
    IntByReference count = new IntByReference();
    int status = X11.INSTANCE.XGetWMProtocols(display, root, protocols, count);
    X11.Atom[] receivedAtoms = new X11.Atom[count.getValue()];
    for (int i = count.getValue() - 1; i >= 0; i--) {
        receivedAtoms[i] = new X11.Atom(protocols.getValue().getLong(X11.Atom.SIZE * i));
    }
    X11.INSTANCE.XFree(protocols.getValue());
    Assert.assertNotEquals("Bad status for XGetWMProtocols", 0, status);
    Assert.assertEquals("Wrong number of protocols returned for XGetWMProtocols", sentAtoms.length, receivedAtoms.length);
    Assert.assertArrayEquals("Sent protocols were not equal to returned procols for XGetWMProtocols", sentAtoms, receivedAtoms);
}
Also used : IntByReference(com.sun.jna.ptr.IntByReference) PointerByReference(com.sun.jna.ptr.PointerByReference)

Example 72 with PointerByReference

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

the class RunningObjectTable_Test method Register.

@Test
public void Register() {
    PointerByReference pprot = new PointerByReference();
    HRESULT hr = Ole32.INSTANCE.GetRunningObjectTable(new DWORD(0), pprot);
    COMUtils.checkRC(hr);
    IRunningObjectTable rot = new RunningObjectTable(pprot.getValue());
//Can't yet be tested as IMoniker is not fully implemented
//rot.Register(grfFlags, punkObject, pmkObjectName, pdwRegister);
}
Also used : HRESULT(com.sun.jna.platform.win32.WinNT.HRESULT) PointerByReference(com.sun.jna.ptr.PointerByReference) DWORD(com.sun.jna.platform.win32.WinDef.DWORD) Test(org.junit.Test)

Example 73 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project elasticsearch by elastic.

the class SystemCallFilter method macImpl.

/** try to install our custom rule profile into sandbox_init() to block execution */
private static void macImpl(Path tmpFile) throws IOException {
    // first be defensive: we can give nice errors this way, at the very least.
    boolean supported = Constants.MAC_OS_X;
    if (supported == false) {
        throw new IllegalStateException("bug: should not be trying to initialize seatbelt for an unsupported OS");
    }
    // we couldn't link methods, could be some really ancient OS X (< Leopard) or some bug
    if (libc_mac == null) {
        throw new UnsupportedOperationException("seatbelt unavailable: could not link methods. requires Leopard or above.");
    }
    // write rules to a temporary file, which will be passed to sandbox_init()
    Path rules = Files.createTempFile(tmpFile, "es", "sb");
    Files.write(rules, Collections.singleton(SANDBOX_RULES));
    boolean success = false;
    try {
        PointerByReference errorRef = new PointerByReference();
        int ret = libc_mac.sandbox_init(rules.toAbsolutePath().toString(), SANDBOX_NAMED, errorRef);
        // if sandbox_init() fails, add the message from the OS (e.g. syntax error) and free the buffer
        if (ret != 0) {
            Pointer errorBuf = errorRef.getValue();
            RuntimeException e = new UnsupportedOperationException("sandbox_init(): " + errorBuf.getString(0));
            libc_mac.sandbox_free_error(errorBuf);
            throw e;
        }
        logger.debug("OS X seatbelt initialization successful");
        success = true;
    } finally {
        if (success) {
            Files.delete(rules);
        } else {
            IOUtils.deleteFilesIgnoringExceptions(rules);
        }
    }
}
Also used : Path(java.nio.file.Path) PointerByReference(com.sun.jna.ptr.PointerByReference) Pointer(com.sun.jna.Pointer)

Example 74 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jmonkeyengine by jMonkeyEngine.

the class OSVR method initialize.

@Override
public boolean initialize() {
    logger.config("Initialize OSVR system.");
    hmdPose.setAutoSynch(false);
    context = OsvrClientKitLibrary.osvrClientInit(defaultJString, 0);
    VRinput = new OSVRInput(environment);
    initSuccess = context != null && VRinput.init();
    if (initSuccess) {
        PointerByReference grabDisplay = new PointerByReference();
        byte retval = OsvrDisplayLibrary.osvrClientGetDisplay(context, grabDisplay);
        if (retval != 0) {
            System.out.println("OSVR Get Display Error: " + retval);
            initSuccess = false;
            return false;
        }
        displayConfig = new OSVR_DisplayConfig(grabDisplay.getValue());
        System.out.println("Waiting for the display to fully start up, including receiving initial pose update...");
        int i = 400;
        while (OsvrDisplayLibrary.osvrClientCheckDisplayStartup(displayConfig) != 0) {
            if (i-- < 0) {
                System.out.println("Couldn't get display startup update in time, continuing anyway...");
                break;
            }
            OsvrClientKitLibrary.osvrClientUpdate(context);
            try {
                Thread.sleep(5);
            } catch (Exception e) {
            }
        }
        System.out.println("OK, display startup status is good!");
    }
    return initSuccess;
}
Also used : PointerByReference(com.sun.jna.ptr.PointerByReference) OSVR_DisplayConfig(com.jme3.system.osvr.osvrdisplay.OsvrDisplayLibrary.OSVR_DisplayConfig)

Example 75 with PointerByReference

use of com.sun.jna.ptr.PointerByReference in project jmonkeyengine by jMonkeyEngine.

the class OSVRInput method getInterface.

private OSVR_ClientInterface getInterface(byte[] str) {
    PointerByReference pbr = new PointerByReference();
    OsvrClientKitLibrary.osvrClientGetInterface((OsvrClientKitLibrary.OSVR_ClientContext) environment.getVRHardware().getVRSystem(), str, pbr);
    return new OSVR_ClientInterface(pbr.getValue());
}
Also used : PointerByReference(com.sun.jna.ptr.PointerByReference) OsvrClientKitLibrary(com.jme3.system.osvr.osvrclientkit.OsvrClientKitLibrary) OSVR_ClientInterface(com.jme3.system.osvr.osvrclientkit.OsvrClientKitLibrary.OSVR_ClientInterface)

Aggregations

PointerByReference (com.sun.jna.ptr.PointerByReference)128 HRESULT (com.sun.jna.platform.win32.WinNT.HRESULT)54 IntByReference (com.sun.jna.ptr.IntByReference)35 Pointer (com.sun.jna.Pointer)20 Test (org.junit.Test)19 DWORD (com.sun.jna.platform.win32.WinDef.DWORD)18 REFIID (com.sun.jna.platform.win32.Guid.REFIID)13 File (java.io.File)13 ULONG (com.sun.jna.platform.win32.WinDef.ULONG)10 PSID (com.sun.jna.platform.win32.WinNT.PSID)10 Memory (com.sun.jna.Memory)8 WString (com.sun.jna.WString)8 Dispatch (com.sun.jna.platform.win32.COM.Dispatch)7 ULONGByReference (com.sun.jna.platform.win32.WinDef.ULONGByReference)7 WinNT (com.sun.jna.platform.win32.WinNT)7 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)7 IID (com.sun.jna.platform.win32.Guid.IID)6 ArrayList (java.util.ArrayList)6 IDispatch (com.sun.jna.platform.win32.COM.IDispatch)5 UINT (com.sun.jna.platform.win32.WinDef.UINT)5