Skip to content

Commit

Permalink
Add NoServerException if no Corsair Server is detected.
Browse files Browse the repository at this point in the history
  • Loading branch information
FiercestT committed Feb 22, 2021
1 parent 1580acd commit 9e42e00
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Project exclude paths
/.gradle/
/build/
.idea/
/.idea/*
/gradle/*

/build/classes/java/main/
/build/classes/java/test/
13 changes: 10 additions & 3 deletions src/main/java/ca/fiercest/cuesdk/CueSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,38 @@ 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);
}

/**
* 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);
}

/**
* (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())
{
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/ca/fiercest/cuesdk/NoServerException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ca.fiercest.cuesdk;

public class NoServerException extends Exception {
NoServerException()
{
super("Corsair Service is Not Running, cannot connect.");
}
}
7 changes: 2 additions & 5 deletions src/test/java/TestCueSDK.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
Expand Down

0 comments on commit 9e42e00

Please sign in to comment.