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);
}
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);
}
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);
}
}
}
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;
}
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());
}
Aggregations