use of com.sun.jna.Pointer in project buck by facebook.
the class ProcessHelper method windowsProcessId.
@Nullable
private Long windowsProcessId(Object process) {
Class<?> clazz = process.getClass();
if (clazz.getName().equals("java.lang.Win32Process") || clazz.getName().equals("java.lang.ProcessImpl")) {
try {
Field f = clazz.getDeclaredField("handle");
f.setAccessible(true);
long peer = f.getLong(process);
Pointer pointer = Pointer.createConstant(peer);
WinNT.HANDLE handle = new WinNT.HANDLE(pointer);
return (long) Kernel32.INSTANCE.GetProcessId(handle);
} catch (Exception e) {
LOG.warn(e, "Cannot get process id!");
}
}
return null;
}
use of com.sun.jna.Pointer in project buck by facebook.
the class MacWifiSsidFinder method findCurrentSsid.
/**
* Finds the SSID of the default Wi-Fi interface using Mac OS X APIs.
*/
public static Optional<String> findCurrentSsid() {
LOG.debug("Getting current SSID..");
// Grab a handle to the Objective-C runtime.
Client objcClient = Client.getInstance();
// Try the OS X 10.10 and later supported API, then fall
// back to the OS X 10.6 API.
Pointer wifiClientClass = RuntimeUtils.cls("CWWiFiClient");
Optional<Proxy> defaultInterface;
if (wifiClientClass != null) {
LOG.verbose("Getting default interface using +[CWWiFiClient sharedWiFiClient]");
defaultInterface = getDefaultWifiInterface(objcClient, wifiClientClass);
} else {
LOG.verbose("Getting default interface using +[CWInterface defaultInterface]");
// CWInterface *defaultInterface = [CWInterface interface];
defaultInterface = Optional.ofNullable(objcClient.sendProxy("CWInterface", "interface"));
}
return getSsidFromInterface(defaultInterface);
}
use of com.sun.jna.Pointer in project jmonkeyengine by jMonkeyEngine.
the class OSVRInput method init.
@Override
public boolean init() {
logger.config("Initialize OSVR input.");
buttonHandler = new Callback() {
@SuppressWarnings("unused")
public void invoke(Pointer userdata, Pointer timeval, OSVR_ButtonReport report) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < BUTTON_COUNT; j++) {
if (buttons[i][j] == null)
continue;
if (userdata.toString().equals(buttons[i][j].getPointer().toString())) {
buttonState[i][j] = report.state;
return;
}
}
}
}
};
analogHandler = new Callback() {
@SuppressWarnings("unused")
public void invoke(Pointer userdata, Pointer timeval, OSVR_AnalogReport report) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < ANALOG_COUNT; j++) {
for (int k = 0; k < CHANNEL_COUNT; k++) {
if (analogs[i][j][k] == null)
continue;
if (userdata.toString().equals(analogs[i][j][k].getPointer().toString())) {
analogState[i][j][k] = (float) report.state;
return;
}
}
}
}
}
};
buttons = new OSVR_ClientInterface[2][BUTTON_COUNT];
analogs = new OSVR_ClientInterface[2][ANALOG_COUNT][CHANNEL_COUNT];
buttonState = new float[2][BUTTON_COUNT];
analogState = new float[2][ANALOG_COUNT][CHANNEL_COUNT];
hands = new OSVR_ClientInterface[2];
hands[0] = getInterface(leftHand);
hands[1] = getInterface(rightHand);
handState = new OSVR_Pose3[2];
handState[0] = new OSVR_Pose3();
handState[1] = new OSVR_Pose3();
for (int h = 0; h < 2; h++) {
for (int i = 0; i < BUTTON_COUNT - 2; i++) {
buttons[h][i] = getInterface(getButtonString(h == 0, (byte) Integer.toString(i).toCharArray()[0]));
OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[h][i], buttonHandler, buttons[h][i].getPointer());
}
}
buttons[0][BUTTON_COUNT - 2] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 'b', 'u', 'm', 'p', 'e', 'r', (byte) 0 });
OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[0][BUTTON_COUNT - 2], buttonHandler, buttons[0][BUTTON_COUNT - 2].getPointer());
buttons[1][BUTTON_COUNT - 2] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 'b', 'u', 'm', 'p', 'e', 'r', (byte) 0 });
OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[1][BUTTON_COUNT - 2], buttonHandler, buttons[1][BUTTON_COUNT - 2].getPointer());
buttons[0][BUTTON_COUNT - 1] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'b', 'u', 't', 't', 'o', 'n', (byte) 0 });
OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[0][BUTTON_COUNT - 1], buttonHandler, buttons[0][BUTTON_COUNT - 1].getPointer());
buttons[1][BUTTON_COUNT - 1] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'b', 'u', 't', 't', 'o', 'n', (byte) 0 });
OsvrClientKitLibrary.osvrRegisterButtonCallback(buttons[1][BUTTON_COUNT - 1], buttonHandler, buttons[1][BUTTON_COUNT - 1].getPointer());
analogs[0][0][0] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 't', 'r', 'i', 'g', 'g', 'e', 'r', (byte) 0 });
analogs[1][0][0] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 't', 'r', 'i', 'g', 'g', 'e', 'r', (byte) 0 });
OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[0][0][0], analogHandler, analogs[0][0][0].getPointer());
OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[1][0][0], analogHandler, analogs[1][0][0].getPointer());
analogs[0][1][0] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'x', (byte) 0 });
analogs[0][1][1] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'l', 'e', 'f', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'y', (byte) 0 });
OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[0][1][0], analogHandler, analogs[0][1][0].getPointer());
OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[0][1][1], analogHandler, analogs[0][1][1].getPointer());
analogs[1][1][0] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'x', (byte) 0 });
analogs[1][1][1] = getInterface(new byte[] { '/', 'c', 'o', 'n', 't', 'r', 'o', 'l', 'l', 'e', 'r', '/', 'r', 'i', 'g', 'h', 't', '/', 'j', 'o', 'y', 's', 't', 'i', 'c', 'k', '/', 'y', (byte) 0 });
OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[1][1][0], analogHandler, analogs[1][1][0].getPointer());
OsvrClientKitLibrary.osvrRegisterAnalogCallback(analogs[1][1][1], analogHandler, analogs[1][1][1].getPointer());
return true;
}
use of com.sun.jna.Pointer in project jna by java-native-access.
the class AlphaMaskDemo method updateW32.
private void updateW32(boolean a, boolean i) {
User32 user = User32.INSTANCE;
GDI32 gdi = GDI32.INSTANCE;
HWND hWnd = null;
if (!alphaWindow.isDisplayable()) {
alphaWindow.pack();
hWnd = getHwnd(alphaWindow);
int flags = user.GetWindowLong(hWnd, WinUser.GWL_EXSTYLE);
flags |= WinUser.WS_EX_LAYERED;
user.SetWindowLong(hWnd, WinUser.GWL_EXSTYLE, flags);
Window parent = alphaWindow.getOwner();
Point where = parent.getLocationOnScreen();
where.translate(parent.getWidth(), 0);
alphaWindow.setLocation(where);
} else {
hWnd = getHwnd(alphaWindow);
}
if (i) {
int w = image.getWidth(null);
int h = image.getHeight(null);
HDC screenDC = user.GetDC(null);
HDC memDC = gdi.CreateCompatibleDC(screenDC);
HBITMAP hBitmap = null;
HANDLE oldBitmap = null;
try {
BufferedImage buf = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
Graphics g = buf.getGraphics();
g.drawImage(image, 0, 0, w, h, null);
BITMAPINFO bmi = new BITMAPINFO();
bmi.bmiHeader.biWidth = w;
bmi.bmiHeader.biHeight = h;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = WinGDI.BI_RGB;
bmi.bmiHeader.biSizeImage = w * h * 4;
PointerByReference ppbits = new PointerByReference();
hBitmap = gdi.CreateDIBSection(memDC, bmi, WinGDI.DIB_RGB_COLORS, ppbits, null, 0);
oldBitmap = gdi.SelectObject(memDC, hBitmap);
Pointer pbits = ppbits.getValue();
Raster raster = buf.getData();
int[] pixel = new int[4];
int[] bits = new int[w * h];
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
raster.getPixel(x, h - y - 1, pixel);
int alpha = (pixel[3] & 0xFF) << 24;
int red = (pixel[2] & 0xFF);
int green = (pixel[1] & 0xFF) << 8;
int blue = (pixel[0] & 0xFF) << 16;
bits[x + y * w] = alpha | red | green | blue;
}
}
pbits.write(0, bits, 0, bits.length);
SIZE size = new SIZE();
size.cx = w;
size.cy = h;
POINT loc = new POINT();
loc.x = alphaWindow.getX();
loc.y = alphaWindow.getY();
POINT srcLoc = new POINT();
BLENDFUNCTION blend = new BLENDFUNCTION();
blend.SourceConstantAlpha = (byte) (alpha * 255);
blend.AlphaFormat = WinUser.AC_SRC_ALPHA;
user.UpdateLayeredWindow(hWnd, screenDC, loc, size, memDC, srcLoc, 0, blend, WinUser.ULW_ALPHA);
} finally {
user.ReleaseDC(null, screenDC);
if (hBitmap != null) {
gdi.SelectObject(memDC, oldBitmap);
gdi.DeleteObject(hBitmap);
}
gdi.DeleteDC(memDC);
}
} else if (a) {
BLENDFUNCTION blend = new BLENDFUNCTION();
blend.SourceConstantAlpha = (byte) (alpha * 255);
blend.AlphaFormat = WinUser.AC_SRC_ALPHA;
user.UpdateLayeredWindow(hWnd, null, null, null, null, null, 0, blend, WinUser.ULW_ALPHA);
}
if (!alphaWindow.isVisible()) {
alphaWindow.setVisible(true);
}
}
use of com.sun.jna.Pointer in project jna by java-native-access.
the class Advapi32Util method getSecurityDescriptorForObject.
/**
* Get a self relative security descriptor for the given object type. The value is returned in Memory
* @param absoluteObjectPath
* A pointer to a null-terminated string that specifies the name of the object
* from which to retrieve security information. For descriptions of the string
* formats for the different object types, see SE_OBJECT_TYPE in
* {@link AccCtrl.SE_OBJECT_TYPE}
* @param objectType
* Object type referred to by the path. See {@link AccCtrl.SE_OBJECT_TYPE} for valid definitions.
* @param getSACL
* Get SACL of the object. See {@link Advapi32#GetNamedSecurityInfo} for process privilege requirements in getting the SACL.
* @return Memory containing the self relative security descriptor
*/
public static Memory getSecurityDescriptorForObject(final String absoluteObjectPath, int objectType, boolean getSACL) {
int infoType = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION | (getSACL ? SACL_SECURITY_INFORMATION : 0);
PointerByReference ppSecurityDescriptor = new PointerByReference();
int lastError = Advapi32.INSTANCE.GetNamedSecurityInfo(absoluteObjectPath, objectType, infoType, null, null, null, null, ppSecurityDescriptor);
if (lastError != 0) {
throw new Win32Exception(lastError);
}
int nLength = Advapi32.INSTANCE.GetSecurityDescriptorLength(ppSecurityDescriptor.getValue());
Memory memory = new Memory(nLength);
Pointer secValue = ppSecurityDescriptor.getValue();
try {
byte[] data = secValue.getByteArray(0, nLength);
memory.write(0, data, 0, nLength);
return memory;
} finally {
Kernel32Util.freeLocalMemory(secValue);
}
}
Aggregations