Skip to content

Commit 64e7b11

Browse files
committed
Don't throw an IOException on the top level API
1 parent 2deb68b commit 64e7b11

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

src/main/java/de/gurkenlabs/input4j/InputDevices.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.awt.*;
44
import java.io.IOException;
5+
import java.util.logging.Level;
56
import java.util.logging.Logger;
67

78
/**
@@ -32,21 +33,19 @@ public static DefaultInputConfiguration configure() {
3233
/**
3334
* Initializes the input device provider with the default platform library.
3435
*
35-
* @return The initialized input device provider.
36-
* @throws IOException if the input device provider cannot be initialized.
36+
* @return The initialized input device provider or null if the initialization fails.
3737
*/
38-
public static InputDevicePlugin init() throws IOException {
38+
public static InputDevicePlugin init() {
3939
return init(null, InputLibrary.PLATFORM_DEFAULT);
4040
}
4141

4242
/**
4343
* Initializes the input device provider with the default platform library and the specified owner.
4444
*
4545
* @param owner The owner to be passed to individual plugins, or null if running in background.
46-
* @return The initialized input device provider.
47-
* @throws IOException if the input device provider cannot be initialized.
46+
* @return The initialized input device provider or null if the initialization fails.
4847
*/
49-
public static InputDevicePlugin init(Frame owner) throws IOException {
48+
public static InputDevicePlugin init(Frame owner) {
5049
return init(owner, InputLibrary.PLATFORM_DEFAULT);
5150
}
5251

@@ -56,10 +55,9 @@ public static InputDevicePlugin init(Frame owner) throws IOException {
5655
* Note: Some controllers don't support background mode which is why it can be necessary to pass a frame owner to the {@link InputDevices#init(Frame, String)} method.
5756
*
5857
* @param library The library to be used.
59-
* @return The initialized input device provider.
60-
* @throws IOException if the input device provider cannot be initialized.
58+
* @return The initialized input device provider or null if the initialization fails.
6159
*/
62-
public static InputDevicePlugin init(InputLibrary library) throws IOException {
60+
public static InputDevicePlugin init(InputLibrary library) {
6361
return init(null, library);
6462
}
6563

@@ -69,10 +67,9 @@ public static InputDevicePlugin init(InputLibrary library) throws IOException {
6967
* Note: Some controllers don't support background mode which is why it can be necessary to pass a frame owner to the {@link InputDevices#init(Frame, String)} method.
7068
*
7169
* @param inputPluginClass The input plugin class to be used.
72-
* @return The initialized input device provider.
73-
* @throws IOException if the input device provider cannot be initialized.
70+
* @return The initialized input device provider or null if the initialization fails.
7471
*/
75-
public static InputDevicePlugin init(String inputPluginClass) throws IOException {
72+
public static InputDevicePlugin init(String inputPluginClass) {
7673
return init(null, inputPluginClass);
7774
}
7875

@@ -81,10 +78,9 @@ public static InputDevicePlugin init(String inputPluginClass) throws IOException
8178
*
8279
* @param owner The owner to be passed to individual plugins, or null if running in background.
8380
* @param library The input library to be used.
84-
* @return The initialized input device provider.
85-
* @throws IOException if the input device provider cannot be initialized.
81+
* @return The initialized input device provider or null if the initialization fails.
8682
*/
87-
public static InputDevicePlugin init(Frame owner, InputLibrary library) throws IOException {
83+
public static InputDevicePlugin init(Frame owner, InputLibrary library) {
8884
return init(owner, library.getPlugin());
8985
}
9086

@@ -99,10 +95,9 @@ public static InputDevicePlugin init(Frame owner, InputLibrary library) throws I
9995
* If the class is not found or cannot be instantiated, an {@link IOException} is thrown.
10096
* The class must have a public no-argument constructor.
10197
* </p>
102-
* @return The initialized input device provider.
103-
* @throws IOException if the input device provider cannot be initialized.
98+
* @return The initialized input device provider or null if the initialization fails.
10499
*/
105-
public static InputDevicePlugin init(Frame owner, String inputPluginClass) throws IOException {
100+
public static InputDevicePlugin init(Frame owner, String inputPluginClass) {
106101
try {
107102
if (inputPluginClass == null) {
108103
inputPluginClass = InputLibrary.PLATFORM_DEFAULT.getPlugin();
@@ -114,7 +109,8 @@ public static InputDevicePlugin init(Frame owner, String inputPluginClass) throw
114109
provider.internalInitDevices(owner);
115110
return provider;
116111
} catch (Exception e) {
117-
throw new IOException("Could not initialize input device provider: " + e.getMessage(), e);
112+
log.log(Level.SEVERE, "Could not initialize input device provider: " + e.getMessage(), e);
113+
return null;
118114
}
119115
}
120116

src/main/java/de/gurkenlabs/input4j/foreign/windows/dinput/DirectInputPlugin.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
import static de.gurkenlabs.input4j.foreign.NativeHelper.downcallHandle;
2121
import static java.lang.foreign.ValueLayout.*;
2222

23-
/**
24-
* TODO: Implement hot swapping controllers
25-
* TODO: handle disconnect or permanent unavailability => retry X times => handle in hotplug thread if a device is unavailable throw it away
26-
*/
2723
public final class DirectInputPlugin extends AbstractInputDevicePlugin {
2824
static final int DI8DEVCLASS_GAMECTRL = 4;
2925

@@ -96,6 +92,7 @@ public void close() {
9692
@Override
9793
protected Collection<InputDevice> refreshInputDevices() {
9894
// TODO: implement refresh support
95+
// TODO: handle disconnect or permanent unavailability => retry X times => handle in hotplug thread if a device is unavailable throw it away
9996
return this.getAll();
10097
}
10198

0 commit comments

Comments
 (0)