Skip to content

Commit

Permalink
Merge pull request #69 from oci-labs/master
Browse files Browse the repository at this point in the history
JARs for Communication fix (Windows Overlapped I/O)
  • Loading branch information
nyholku authored Feb 16, 2020
2 parents 19c22fa + f98da3a commit f769fcd
Show file tree
Hide file tree
Showing 22 changed files with 137 additions and 825 deletions.
Binary file modified bin/purejavahidapi-src.jar
Binary file not shown.
Binary file modified bin/purejavahidapi.jar
Binary file not shown.
6 changes: 4 additions & 2 deletions build-jars.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
<mkdir dir="${class.example}"/>

<path id="compile">
<pathelement location="lib/jna-4.0.0.jar"/>
<pathelement location="lib/jna-5.5.0.jar"/>
<pathelement location="lib/jna-platform-5.5.0.jar"/>
</path>

<path id="examples">
<pathelement location="lib/jna-4.0.0.jar"/>
<pathelement location="lib/jna-5.5.0.jar"/>
<pathelement location="lib/jna-platform-5.5.0.jar"/>
<pathelement location="${class}"/>
</path>

Expand Down
Binary file removed lib/jna-4.0.0.jar
Binary file not shown.
Binary file added lib/jna-5.5.0.jar
Binary file not shown.
Binary file added lib/jna-platform-5.5.0.jar
Binary file not shown.
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,15 @@
</build>

<dependencies>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.0.0</version>
<version>5.5.0</version>
</dependency>
</dependencies>
</project>
2 changes: 1 addition & 1 deletion src/purejavahidapi/linux/CLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.sun.jna.Structure;

public class CLibrary {
static CLibraryInterface INSTANCE = (CLibraryInterface) Native.loadLibrary("c", CLibraryInterface.class);
static CLibraryInterface INSTANCE = (CLibraryInterface) Native.load("c", CLibraryInterface.class);

public static short POLLIN = 0x0001;

Expand Down
2 changes: 1 addition & 1 deletion src/purejavahidapi/linux/UdevLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class UdevLibrary {

// OBSOLETE class: hid_device

static UdevInterface INSTANCE = (UdevInterface) Native.loadLibrary("udev", UdevInterface.class);
static UdevInterface INSTANCE = (UdevInterface) Native.load("udev", UdevInterface.class);

public final static int BUS_USB = 0x03;
public final static int BUS_BLUETOOTH = 0x05;
Expand Down
2 changes: 1 addition & 1 deletion src/purejavahidapi/macosx/CoreFoundationLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

public class CoreFoundationLibrary {
private static String m_NativeLibName = "CoreFoundation";
private static CoreFoundationLibraryInterface INSTANCE = (CoreFoundationLibraryInterface) Native.loadLibrary(m_NativeLibName, CoreFoundationLibraryInterface.class);
private static CoreFoundationLibraryInterface INSTANCE = (CoreFoundationLibraryInterface) Native.load(m_NativeLibName, CoreFoundationLibraryInterface.class);
private static NativeLibrary NINSTANCE = NativeLibrary.getInstance(m_NativeLibName);

// --------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/purejavahidapi/macosx/IOHIDManagerLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import com.sun.jna.*;

public class IOHIDManagerLibrary {
private static IOHIDManagerLib INSTANCE = (IOHIDManagerLib) Native.loadLibrary("IOKit", IOHIDManagerLib.class);
private static IOHIDManagerLib INSTANCE = (IOHIDManagerLib) Native.load("IOKit", IOHIDManagerLib.class);

public static final int kIOHIDOptionsTypeNone = 0;
public static final int kIOHIDOptionsTypeSeizeDevice = 1;
Expand Down
61 changes: 0 additions & 61 deletions src/purejavahidapi/windows/CfgmgrLibrary.java

This file was deleted.

54 changes: 31 additions & 23 deletions src/purejavahidapi/windows/DeviceRemovalHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,24 @@
*/
package purejavahidapi.windows;

import static com.sun.jna.platform.win32.DBT.*;
import static com.sun.jna.platform.win32.Kernel32.INSTANCE;
import static com.sun.jna.platform.win32.User32.DEVICE_NOTIFY_WINDOW_HANDLE;
import static com.sun.jna.platform.win32.User32.WS_EX_TOPMOST;
import static com.sun.jna.platform.win32.WinBase.INVALID_HANDLE_VALUE;
import static com.sun.jna.platform.win32.WinUser.WM_DESTROY;
import static com.sun.jna.platform.win32.WinUser.WM_DEVICECHANGE;
import static com.sun.jna.platform.win32.Wtsapi32.NOTIFY_FOR_THIS_SESSION;
import static purejavahidapi.windows.SetupApiLibrary.*;

import com.sun.jna.WString;
import com.sun.jna.platform.win32.DBT.*;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinUser.*;
import com.sun.jna.platform.win32.WinDef.*;


import com.sun.jna.platform.win32.Wtsapi32;
import purejavahidapi.shared.SyncPoint;
import purejavahidapi.windows.WinDef.*;
import static purejavahidapi.windows.WinDef.*;
import static purejavahidapi.windows.Kernel32Library.*;
import static purejavahidapi.windows.User32Library.*;
import static purejavahidapi.windows.WtsApi32Library.*;
import static purejavahidapi.windows.WindowsBackend.reportLastError;

public class DeviceRemovalHandler implements WindowProc {
Expand All @@ -50,8 +58,8 @@ public DeviceRemovalHandler(WindowsBackend windowsBackend) {
m_StartupSync = new SyncPoint(2);
Runnable threadRunnable = new Runnable() {
public void run() {
WString wndClassName = new WString("WindowClass");
HMODULE hInst = GetModuleHandle(null);
String wndClassName = new String("WindowClass");
HMODULE hInst = INSTANCE.GetModuleHandle(null);
if (hInst == null)
reportLastError();

Expand All @@ -60,45 +68,45 @@ public void run() {
wndClassEx.lpfnWndProc = DeviceRemovalHandler.this;
wndClassEx.lpszClassName = wndClassName;

ATOM wndClassRef = RegisterClassEx(wndClassEx);
ATOM wndClassRef = User32.INSTANCE.RegisterClassEx(wndClassEx);
if (wndClassRef == null)
reportLastError();

HWND hWnd = CreateWindowEx(WS_EX_TOPMOST, "WindowClass", "", 0, 0, 0, 0, 0, null, null, hInst, null);
HWND hWnd = User32.INSTANCE.CreateWindowEx(WS_EX_TOPMOST, "WindowClass", "", 0, 0, 0, 0, 0, null, null, hInst, null);

if (hWnd == null)
reportLastError();

if (!WTSRegisterSessionNotification(hWnd, NOTIFY_FOR_THIS_SESSION))
if (!Wtsapi32.INSTANCE.WTSRegisterSessionNotification(hWnd, NOTIFY_FOR_THIS_SESSION))
reportLastError();

DEV_BROADCAST_DEVICEINTERFACE notificationFilter = new DEV_BROADCAST_DEVICEINTERFACE();
notificationFilter.dbcc_size = notificationFilter.size();
notificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
notificationFilter.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;

HDEVNOTIFY hDevNotify = RegisterDeviceNotification(hWnd, notificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE);
HDEVNOTIFY hDevNotify = User32.INSTANCE.RegisterDeviceNotification(hWnd, notificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE);
if (hDevNotify == null)
reportLastError();

m_StartupSync.waitAndSync();

MSG msg = new MSG();
while (GetMessage(msg, hWnd, 0, 0) != 0) {
TranslateMessage(msg);
DispatchMessage(msg);
while (User32.INSTANCE.GetMessage(msg, hWnd, 0, 0) != 0) {
User32.INSTANCE.TranslateMessage(msg);
User32.INSTANCE.DispatchMessage(msg);
}

if (!UnregisterDeviceNotification(hDevNotify))
if (!User32.INSTANCE.UnregisterDeviceNotification(hDevNotify))
reportLastError();

if (!WTSUnRegisterSessionNotification(hWnd))
if (!Wtsapi32.INSTANCE.WTSUnRegisterSessionNotification(hWnd))
reportLastError();

if (!UnregisterClass(wndClassRef /* "WindowClass" */, hInst))
if (!User32.INSTANCE.UnregisterClass(wndClassRef.toString() /* "WindowClass" */, hInst))
reportLastError();

if (!DestroyWindow(hWnd))
if (!User32.INSTANCE.DestroyWindow(hWnd))
reportLastError();
}
};
Expand All @@ -111,15 +119,15 @@ public void run() {
public LRESULT callback(HWND hwnd, int uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_DESTROY: {
PostQuitMessage(0);
User32.INSTANCE.PostQuitMessage(0);
return new LRESULT(0);
}
case WM_DEVICECHANGE: {
LRESULT lResult = this.onDeviceChange(wParam, lParam);
return lResult != null ? lResult : DefWindowProc(hwnd, uMsg, wParam, lParam);
return lResult != null ? lResult : User32.INSTANCE.DefWindowProc(hwnd, uMsg, wParam, lParam);
}
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
return User32.INSTANCE.DefWindowProc(hwnd, uMsg, wParam, lParam);
}
}

Expand Down Expand Up @@ -162,7 +170,7 @@ protected LRESULT onDeviceChangeArrivalOrRemoveComplete(LPARAM lParam, String ac
switch (bhdr.dbch_devicetype) {
case DBT_DEVTYP_DEVICEINTERFACE: {
DEV_BROADCAST_DEVICEINTERFACE bdif = new DEV_BROADCAST_DEVICEINTERFACE(bhdr.getPointer());
handleDeviceRemoval(bdif.get_dbcc_name());
handleDeviceRemoval(bdif.getDbcc_name());
break;
}
default:
Expand Down
Loading

0 comments on commit f769fcd

Please sign in to comment.