diff --git a/.gitignore b/.gitignore index 7d8aaa1..1585841 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ # Project exclude paths /.gradle/ /build/ -.idea/ +/.idea/* +/gradle/* /build/classes/java/main/ /build/classes/java/test/ \ No newline at end of file diff --git a/src/main/java/ca/fiercest/cuesdk/CueSDK.java b/src/main/java/ca/fiercest/cuesdk/CueSDK.java index 07a2f89..1dbf908 100644 --- a/src/main/java/ca/fiercest/cuesdk/CueSDK.java +++ b/src/main/java/ca/fiercest/cuesdk/CueSDK.java @@ -29,8 +29,9 @@ public class CueSDK //region Constructors /** * Overloaded Constructor that does not use any access mode. + * @throws NoServerException If no Corsair server is connected, this exception will be thrown. */ - public CueSDK() + public CueSDK() throws NoServerException { this(null); } @@ -38,8 +39,9 @@ public CueSDK() /** * Overloaded Constructor that allows for exclusive access mode. * @param exclusiveAccessMode Start the SDK using the {@link CorsairAccessMode#CAM_ExclusiveLightingControl}. + * @throws NoServerException If no Corsair server is connected, this exception will be thrown. */ - public CueSDK(boolean exclusiveAccessMode) + public CueSDK(boolean exclusiveAccessMode) throws NoServerException { this(exclusiveAccessMode ? CorsairAccessMode.CAM_ExclusiveLightingControl : null); } @@ -47,13 +49,18 @@ public CueSDK(boolean exclusiveAccessMode) /** * (Base Constructor) Creates the CueSDK Object with a specific access mode. * @param accessMode The specific access mode will be applied on initialization. + * @throws NoServerException If no Corsair server is connected, this exception will be thrown. */ - public CueSDK(CorsairAccessMode accessMode) + public CueSDK(CorsairAccessMode accessMode) throws NoServerException { protocolDetails = new CorsairProtocolDetails(CueSDKLibrary.INSTANCE.CorsairPerformProtocolHandshake()); if(protocolDetails.getServerProtocolVersion() == 0) + { + if(CorsairError.byOrdinal(CueSDKLibrary.INSTANCE.CorsairGetLastError()) == CorsairError.CE_ServerNotFound) + throw new NoServerException(); PrintError(); + } if (protocolDetails.isBreakingChanges()) { diff --git a/src/main/java/ca/fiercest/cuesdk/NoServerException.java b/src/main/java/ca/fiercest/cuesdk/NoServerException.java new file mode 100644 index 0000000..230c748 --- /dev/null +++ b/src/main/java/ca/fiercest/cuesdk/NoServerException.java @@ -0,0 +1,8 @@ +package ca.fiercest.cuesdk; + +public class NoServerException extends Exception { + NoServerException() + { + super("Corsair Service is Not Running, cannot connect."); + } +} diff --git a/src/test/java/TestCueSDK.java b/src/test/java/TestCueSDK.java index d3bb996..1253d2c 100644 --- a/src/test/java/TestCueSDK.java +++ b/src/test/java/TestCueSDK.java @@ -1,7 +1,4 @@ -import ca.fiercest.cuesdk.Color; -import ca.fiercest.cuesdk.CorsairDevice; -import ca.fiercest.cuesdk.CorsairLedPosition; -import ca.fiercest.cuesdk.CueSDK; +import ca.fiercest.cuesdk.*; import ca.fiercest.cuesdk.enums.CorsairAccessMode; import ca.fiercest.cuesdk.enums.LedId; import org.junit.BeforeClass; @@ -18,7 +15,7 @@ public class TestCueSDK private static CueSDK sdk; @BeforeClass - public static void setUp() + public static void setUp() throws NoServerException { sdk = new CueSDK(true); }