Skip to content

Commit

Permalink
feat: Add GetHostConfig function
Browse files Browse the repository at this point in the history
  • Loading branch information
muneebkq committed Jul 24, 2024
1 parent 7cb9f7b commit 8cf2606
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions lexfloatclient/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ android {

dependencies {
implementation 'net.java.dev.jna:jna:5.8.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.2'
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class HostConfig {
public String maxOfflineLeaseDuration;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.nio.CharBuffer;
import java.io.UnsupportedEncodingException;
import com.sun.jna.ptr.IntByReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -123,7 +125,37 @@ public static String GetFloatingClientLibraryVersion() throws LexFloatClientExce
return new String(buffer.array(), "UTF-8").trim();
}
throw new LexFloatClientException(status);
}
}

/**
* Gets the host configuration.
*
* @return Returns host configuration.
* @throws LexFloatClientException
* @throws UnsupportedEncodingException
*/

public static HostConfig GetHostConfig() throws LexFloatClientException, UnsupportedEncodingException {
int status;
int bufferSize = 1024;

ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
status = LexFloatClientNative.GetHostConfigInternal(buffer, bufferSize);
if (LA_OK == status) {
String hostConfigJson = new String(buffer.array(), "UTF-8").trim();
if (!hostConfigJson.isEmpty()) {
HostConfig hostConfig = null;
ObjectMapper objectMapper = new ObjectMapper();
try {
hostConfig = objectMapper.readValue(hostConfigJson, HostConfig.class);
} catch (JsonProcessingException e) {}
return hostConfig;
} else {
return null;
}
}
throw new LexFloatClientException(status);
}

/**
* Gets the product version name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public interface CallbackType extends Callback {

public static native int SetHostProductId(String productId);

public static native int GetHostConfigInternal(ByteBuffer hostconfig, int length);

public static native int SetHostUrl(String hostUrl);

public static native int SetFloatingLicenseCallback(CallbackType callback);
Expand Down

0 comments on commit 8cf2606

Please sign in to comment.