Skip to content

Commit

Permalink
Merge pull request #21 from cryptlex/ahmad/unlimited-syntax
Browse files Browse the repository at this point in the history
Unlimited syntax
  • Loading branch information
ahmad-kemsan authored Aug 6, 2024
2 parents 84ea24e + 190dfb6 commit ba7c88f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
package com.cryptlex.lexfloatclient;
import java.math.BigInteger;

public class HostLicenseMeterAttribute {

/**
* The name of the meter attribute.
*/
public String name;

public int allowedUses;
/**
* The allowed uses of the meter attribute. A value of -1 indicates unlimited allowed uses.
*/
public long allowedUses;

public int totalUses;
/**
* The total uses of the meter attribute.
*/
public BigInteger totalUses;

public int grossUses;
/**
* The gross uses of the meter attribute.
*/
public BigInteger grossUses;

public HostLicenseMeterAttribute(String name, int allowedUses, int totalUses, int grossUses) {
public HostLicenseMeterAttribute(String name, long allowedUses, BigInteger totalUses, BigInteger grossUses) {
this.name = name;
this.allowedUses = allowedUses;
this.totalUses = totalUses;
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/com/cryptlex/lexfloatclient/LexFloatClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.nio.CharBuffer;
import java.io.UnsupportedEncodingException;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.LongByReference;
import java.math.BigInteger;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.ArrayList;
Expand All @@ -26,6 +28,11 @@ public class LexFloatClient {
*/
public static final int LF_FAIL = 1;

// Convert long to BigInteger to correctly handle unsigned 64-bit values
private static BigInteger toUnsignedBigInteger(long value) {
return BigInteger.valueOf(value).and(BigInteger.valueOf(0xFFFFFFFFFFFFFFFFL));
}

/**
* Sets the product id of your application
*
Expand Down Expand Up @@ -372,19 +379,20 @@ public static String GetFloatingClientMetadata(String key) throws LexFloatClient
*/
public static HostLicenseMeterAttribute GetHostLicenseMeterAttribute(String name) throws LexFloatClientException, UnsupportedEncodingException {
int status;
IntByReference allowedUses = new IntByReference(0);
IntByReference totalUses = new IntByReference(0);
IntByReference grossUses = new IntByReference(0);
LongByReference allowedUses = new LongByReference(0);
// These references can still hold the uint64_t values populated by the native function
LongByReference totalUses = new LongByReference(0);
LongByReference grossUses = new LongByReference(0);

if (Platform.isWindows()) {
status = LexFloatClientNative.GetHostLicenseMeterAttribute(new WString(name), allowedUses, totalUses, grossUses);
if (LF_OK == status) {
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), totalUses.getValue(), grossUses.getValue());
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedBigInteger(totalUses.getValue()), toUnsignedBigInteger(grossUses.getValue()));
}
} else {
status = LexFloatClientNative.GetHostLicenseMeterAttribute(name, allowedUses, totalUses, grossUses);
if (LF_OK == status) {
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), totalUses.getValue(), grossUses.getValue());
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedBigInteger(totalUses.getValue()), toUnsignedBigInteger(grossUses.getValue()));
}
}
throw new LexFloatClientException(status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.nio.CharBuffer;
import java.nio.ByteBuffer;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.LongByReference;
import com.sun.jna.Callback;
import java.io.File;

Expand Down Expand Up @@ -66,9 +67,9 @@ public interface CallbackType extends Callback {

public static native int GetHostLicenseMetadata(WString key, CharBuffer value, int length);

public static native int GetHostLicenseMeterAttribute(String name, IntByReference allowedUses, IntByReference totalUses, IntByReference grossUses);
public static native int GetHostLicenseMeterAttribute(String name, LongByReference allowedUses, LongByReference totalUses, LongByReference grossUses);

public static native int GetHostLicenseMeterAttribute(WString name, IntByReference allowedUses, IntByReference totalUses, IntByReference grossUses);
public static native int GetHostLicenseMeterAttribute(WString name, LongByReference allowedUses, LongByReference totalUses, LongByReference grossUses);

public static native int GetHostLicenseExpiryDate(IntByReference expiryDate);

Expand Down

0 comments on commit ba7c88f

Please sign in to comment.