@Override public void getRenderSize(Vector2f store) { if( vrsystemFunctions == null ) { // 1344x1512 store.x = 1344f; store.y = 1512f; } else { IntByReference x = new IntByReference(); IntByReference y = new IntByReference(); vrsystemFunctions.GetRecommendedRenderTargetSize.apply(x, y); store.x = x.getValue(); store.y = y.getValue(); } } /*
/** * Given the process handle, waits for its completion and returns the exit code. */ public static int waitForExitProcess(Pointer hProcess) throws InterruptedException { while (true) { if (Thread.interrupted()) throw new InterruptedException(); Kernel32.INSTANCE.WaitForSingleObject(hProcess,1000); IntByReference exitCode = new IntByReference(); exitCode.setValue(-1); Kernel32.INSTANCE.GetExitCodeProcess(hProcess,exitCode); int v = exitCode.getValue(); if (v !=Kernel32.STILL_ACTIVE) { return v; } } }
/** * Initialize the VR bounds. * @return <code>true</code> if the initialization is a success and <code>false</code> otherwise. */ public boolean init(OpenVR api) { logger.config("Initialize VR bounds..."); if( vrChaperone == null ) { vrChaperone = new VR_IVRChaperone_FnTable(JOpenVRLibrary.VR_GetGenericInterface(JOpenVRLibrary.IVRChaperone_Version, api.hmdErrorStore).getPointer()); if( vrChaperone != null ) { vrChaperone.setAutoSynch(false); vrChaperone.read(); FloatByReference fbX = new FloatByReference(); FloatByReference fbZ = new FloatByReference(); vrChaperone.GetPlayAreaSize.apply(fbX, fbZ); playSize = new Vector2f(fbX.getValue(), fbZ.getValue()); logger.config("Initialize VR bounds [SUCCESS]"); return true; // init success } logger.warning("Initialize VR bounds [FAILED]."); return false; // failed to init } logger.config("Initialize VR bounds already done."); return true; // already initialized }
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()); }
/** * Initialize the headset camera. * @param allowed <code>true</code> is the use of the headset camera is allowed and <code>false</code> otherwise. */ public void initCamera(boolean allowed) { hmdErrorStore.setValue(0); // clear the error store if( allowed && vrsystemFunctions != null ) { IntByReference intptr = JOpenVRLibrary.VR_GetGenericInterface(JOpenVRLibrary.IVRTrackedCamera_Version, hmdErrorStore); if (intptr != null){ cameraFunctions = new VR_IVRTrackedCamera_FnTable(intptr.getPointer()); if(cameraFunctions != null && hmdErrorStore.getValue() == 0 ){ cameraFunctions.setAutoSynch(false); cameraFunctions.read(); logger.config("OpenVR Camera initialized"); } } } }
@Override protected int setPlatformSocketOption(int sockfd, int level, int optName, TCPSocketOptions opt, Integer optVal, int optSize) throws NativeErrorException { try { return setsockopt(sockfd, level, optName, new IntByReference(optVal.intValue()), optSize); } catch (LastErrorException le) { throw new NativeErrorException(le.getMessage(), le.getErrorCode(), le.getCause()); } }
JOpenVRLibrary.ETrackedDeviceProperty.ETrackedDeviceProperty_Prop_ManufacturerName_String, str1, 128, hmdErrorStore); if( hmdErrorStore.getValue() == 0 ) completeName += str1.getString(0); vrsystemFunctions.GetStringTrackedDeviceProperty.apply(JOpenVRLibrary.k_unTrackedDeviceIndex_Hmd, JOpenVRLibrary.ETrackedDeviceProperty.ETrackedDeviceProperty_Prop_ModelNumber_String, str2, 128, hmdErrorStore); if( hmdErrorStore.getValue() == 0 ) completeName += " " + str2.getString(0); if( completeName.length() > 0 ) { completeName = completeName.toLowerCase(Locale.ENGLISH).trim();
/** * Access to the underlying OSVR structures. * @param leftView the left viewport. * @param rightView the right viewport. * @param leftBuffer the left buffer. * @param rightBuffer the right buffer. * @return <code>true</code> if the structure are accessible and <code>false</code> otherwise. */ public boolean handleRenderBufferPresent(OSVR_ViewportDescription.ByValue leftView, OSVR_ViewportDescription.ByValue rightView, OSVR_RenderBufferOpenGL.ByValue leftBuffer, OSVR_RenderBufferOpenGL.ByValue rightBuffer) { if( eyeLeftInfo == null || eyeRightInfo == null ) return false; byte retval; OsvrRenderManagerOpenGLLibrary.osvrRenderManagerStartPresentRenderBuffers(presentState); getEyeInfo(); OsvrRenderManagerOpenGLLibrary.osvrRenderManagerPresentRenderBufferOpenGL(presentState.getValue(), leftBuffer, eyeLeftInfo, leftView); OsvrRenderManagerOpenGLLibrary.osvrRenderManagerPresentRenderBufferOpenGL(presentState.getValue(), rightBuffer, eyeRightInfo, rightView); retval = OsvrRenderManagerOpenGLLibrary.osvrRenderManagerFinishPresentRenderBuffers(renderManager, presentState.getValue(), renderParams, (byte)0); return retval == 0; // only check the last error, since if something errored above, the last call won't work & all calls will log to syserr }
System.out.println("Active window title: " + Native.toString(buffer)); PointerByReference pointer = new PointerByReference(); GetWindowThreadProcessId(GetForegroundWindow(), pointer); Pointer process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, pointer.getValue());
private byte[] getValue(String valueName) { IntByReference pType, lpcbData; byte[] lpData = new byte[1]; pType = new IntByReference(); lpcbData = new IntByReference(); OUTER: while(true) { int r = Advapi32.INSTANCE.RegQueryValueEx(handle, valueName, null, pType, lpData, lpcbData); switch (r) { case WINERROR.ERROR_MORE_DATA: lpData = new byte[lpcbData.getValue()]; continue OUTER; case WINERROR.ERROR_SUCCESS: return lpData; } throw new JnaException(r); } }
/** * Get all sub keys of a key. * * @return array with all sub key names */ public Collection<String> getSubKeys() { WINBASE.FILETIME lpftLastWriteTime; TreeSet<String> subKeys = new TreeSet<String>(); char[] lpName = new char[256]; IntByReference lpcName = new IntByReference(256); lpftLastWriteTime = new WINBASE.FILETIME(); int dwIndex = 0; while (Advapi32.INSTANCE.RegEnumKeyEx(handle, dwIndex, lpName, lpcName, null, null, null, lpftLastWriteTime) == WINERROR.ERROR_SUCCESS) { subKeys.add(new String(lpName, 0, lpcName.getValue())); lpcName.setValue(256); dwIndex++; } return subKeys; }
/** * Allocates align memory for use with O_DIRECT and returns native byte buffer. * @param fsBlockSize alignment, FS ans OS block size. * @param size capacity. * @return byte buffer, to be released by {@link #free(ByteBuffer)}. */ public static ByteBuffer allocate(int fsBlockSize, int size) { assert fsBlockSize > 0; assert size > 0; PointerByReference refToPtr = new PointerByReference(); int retVal = IgniteNativeIoLib.posix_memalign(refToPtr, new NativeLong(fsBlockSize), new NativeLong(size)); if (retVal != 0) throw new IgniteOutOfMemoryException("Failed to allocate memory: " + IgniteNativeIoLib.strerror(retVal)); return GridUnsafe.wrapPointer(Pointer.nativeValue(refToPtr.getValue()), size); }
@Override protected int setPlatformSocketOption(int sockfd, int level, int optName, TCPSocketOptions opt, Integer optVal, int optSize) throws NativeErrorException { try { switch (optName) { case OPT_TCP_KEEPALIVE_THRESHOLD: // value required is in millis final IntByReference timeout = new IntByReference(optVal.intValue() * 1000); int result = setsockopt(sockfd, level, optName, timeout, optSize); if (result == 0) { // setting ABORT_THRESHOLD to be same as KEEPALIVE_THRESHOLD return setsockopt(sockfd, level, OPT_TCP_KEEPALIVE_ABORT_THRESHOLD, timeout, optSize); } else { return result; } default: throw new UnsupportedOperationException("unsupported option " + opt); } } catch (LastErrorException le) { throw new NativeErrorException(le.getMessage(), le.getErrorCode(), le.getCause()); } }
/** * Register the OSVR OpenGL buffer. * @param buf the OSVR OpenGL buffer. */ private void registerOSVRBuffer(OSVR_RenderBufferOpenGL.ByValue buf) { if (environment != null){ OsvrRenderManagerOpenGLLibrary.osvrRenderManagerStartRegisterRenderBuffers(grabRBS); OsvrRenderManagerOpenGLLibrary.osvrRenderManagerRegisterRenderBufferOpenGL(grabRBS.getValue(), buf); OsvrRenderManagerOpenGLLibrary.osvrRenderManagerFinishRegisterRenderBuffers(((OSVR)environment.getVRHardware()).getCompositor(), grabRBS.getValue(), (byte)0); } else { throw new IllegalStateException("This VR view manager is not attached to any VR environment."); } }
/** * Does a specified value exist? */ public boolean valueExists(String name) { IntByReference pType, lpcbData; byte[] lpData = new byte[1]; pType = new IntByReference(); lpcbData = new IntByReference(); OUTER: while(true) { int r = Advapi32.INSTANCE.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData); switch(r) { case WINERROR.ERROR_MORE_DATA: lpData = new byte[lpcbData.getValue()]; continue OUTER; case WINERROR.ERROR_FILE_NOT_FOUND: return false; case WINERROR.ERROR_SUCCESS: return true; default: throw new JnaException(r); } } }
lpcchValueName = new IntByReference(16384); lpType = new IntByReference(); lpData = new byte[1]; lpcbData = new IntByReference(); lpcbData.setValue(0); lpData = new byte[lpcbData.getValue()]; lpcchValueName = new IntByReference(16384); continue OUTER; name = new String(lpValueName, 0, lpcchValueName.getValue()); switch (lpType.getValue()) { case WINNT.REG_SZ: values.put(name, convertBufferToString(lpData)); lpcbData.setValue(0);
public RegistryKey open(String subKeyName, int access) { IntByReference pHandle = new IntByReference(); check(Advapi32.INSTANCE.RegOpenKeyEx(handle, subKeyName, 0, access, pHandle)); return new RegistryKey(this,subKeyName,pHandle.getValue()); }
public interface Psapi extends StdCallLibrary { Psapi INSTANCE = (Psapi) Native.loadLibrary("Psapi", Psapi.class); WinDef.DWORD GetModuleBaseNameW(Pointer hProcess, Pointer hModule, byte[] lpBaseName, int nSize); } if (Platform.isWindows()) { final int PROCESS_VM_READ=0x0010; final int PROCESS_QUERY_INFORMATION=0x0400; final User32 user32 = User32.INSTANCE; final Kernel32 kernel32=Kernel32.INSTANCE; final Psapi psapi = Psapi.INSTANCE; WinDef.HWND windowHandle=user32.GetForegroundWindow(); IntByReference pid= new IntByReference(); user32.GetWindowThreadProcessId(windowHandle, pid); WinNT.HANDLE processHandle=kernel32.OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, true, pid.getValue()); byte[] filename = new byte[512]; Psapi.INSTANCE.GetModuleBaseNameW(processHandle.getPointer(), Pointer.NULL, filename, filename.length); String name=new String(filename); System.out.println(name); if (name.endsWith("wwahost.exe")) { // Metro App // There is no stable API to get the current Metro app // But you can guestimate the name form the current directory of the process // To query this, see: // http://stackoverflow.com/questions/16110936/read-other-process-current-directory-in-c-sharp }
/** * @see NativeCalls#isProcessActive(int) */ @Override public boolean isProcessActive(final int processId) { try { final Pointer procHandle = Kernel32.OpenProcess(Kernel32.PROCESS_QUERY_INFORMATION, false, processId); final long hval; if (procHandle == null || (hval = Pointer.nativeValue(procHandle)) == Kernel32.INVALID_HANDLE || hval == 0) { return false; } else { final IntByReference status = new IntByReference(); final boolean result = Kernel32.GetExitCodeProcess(procHandle, status) && status.getValue() == Kernel32.STILL_ACTIVE; Kernel32.CloseHandle(procHandle); return result; } } catch (LastErrorException le) { // some problem in getting process status return false; } }
IntByReference spnLength = new IntByReference(2048); char[] spn = new char[spnLength.getValue()]; return new String(spn, 0, spnLength.getValue());