Skip to content

Commit ba7c88f

Browse files
authored
Merge pull request #21 from cryptlex/ahmad/unlimited-syntax
Unlimited syntax
2 parents 84ea24e + 190dfb6 commit ba7c88f

3 files changed

Lines changed: 33 additions & 11 deletions

File tree

src/main/java/com/cryptlex/lexfloatclient/HostLicenseMeterAttribute.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
package com.cryptlex.lexfloatclient;
2+
import java.math.BigInteger;
23

34
public class HostLicenseMeterAttribute {
45

6+
/**
7+
* The name of the meter attribute.
8+
*/
59
public String name;
610

7-
public int allowedUses;
11+
/**
12+
* The allowed uses of the meter attribute. A value of -1 indicates unlimited allowed uses.
13+
*/
14+
public long allowedUses;
815

9-
public int totalUses;
16+
/**
17+
* The total uses of the meter attribute.
18+
*/
19+
public BigInteger totalUses;
1020

11-
public int grossUses;
21+
/**
22+
* The gross uses of the meter attribute.
23+
*/
24+
public BigInteger grossUses;
1225

13-
public HostLicenseMeterAttribute(String name, int allowedUses, int totalUses, int grossUses) {
26+
public HostLicenseMeterAttribute(String name, long allowedUses, BigInteger totalUses, BigInteger grossUses) {
1427
this.name = name;
1528
this.allowedUses = allowedUses;
1629
this.totalUses = totalUses;

src/main/java/com/cryptlex/lexfloatclient/LexFloatClient.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.nio.CharBuffer;
77
import java.io.UnsupportedEncodingException;
88
import com.sun.jna.ptr.IntByReference;
9+
import com.sun.jna.ptr.LongByReference;
10+
import java.math.BigInteger;
911
import com.fasterxml.jackson.databind.ObjectMapper;
1012
import com.fasterxml.jackson.core.JsonProcessingException;
1113
import java.util.ArrayList;
@@ -26,6 +28,11 @@ public class LexFloatClient {
2628
*/
2729
public static final int LF_FAIL = 1;
2830

31+
// Convert long to BigInteger to correctly handle unsigned 64-bit values
32+
private static BigInteger toUnsignedBigInteger(long value) {
33+
return BigInteger.valueOf(value).and(BigInteger.valueOf(0xFFFFFFFFFFFFFFFFL));
34+
}
35+
2936
/**
3037
* Sets the product id of your application
3138
*
@@ -372,19 +379,20 @@ public static String GetFloatingClientMetadata(String key) throws LexFloatClient
372379
*/
373380
public static HostLicenseMeterAttribute GetHostLicenseMeterAttribute(String name) throws LexFloatClientException, UnsupportedEncodingException {
374381
int status;
375-
IntByReference allowedUses = new IntByReference(0);
376-
IntByReference totalUses = new IntByReference(0);
377-
IntByReference grossUses = new IntByReference(0);
382+
LongByReference allowedUses = new LongByReference(0);
383+
// These references can still hold the uint64_t values populated by the native function
384+
LongByReference totalUses = new LongByReference(0);
385+
LongByReference grossUses = new LongByReference(0);
378386

379387
if (Platform.isWindows()) {
380388
status = LexFloatClientNative.GetHostLicenseMeterAttribute(new WString(name), allowedUses, totalUses, grossUses);
381389
if (LF_OK == status) {
382-
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), totalUses.getValue(), grossUses.getValue());
390+
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedBigInteger(totalUses.getValue()), toUnsignedBigInteger(grossUses.getValue()));
383391
}
384392
} else {
385393
status = LexFloatClientNative.GetHostLicenseMeterAttribute(name, allowedUses, totalUses, grossUses);
386394
if (LF_OK == status) {
387-
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), totalUses.getValue(), grossUses.getValue());
395+
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedBigInteger(totalUses.getValue()), toUnsignedBigInteger(grossUses.getValue()));
388396
}
389397
}
390398
throw new LexFloatClientException(status);

src/main/java/com/cryptlex/lexfloatclient/LexFloatClientNative.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.nio.CharBuffer;
99
import java.nio.ByteBuffer;
1010
import com.sun.jna.ptr.IntByReference;
11+
import com.sun.jna.ptr.LongByReference;
1112
import com.sun.jna.Callback;
1213
import java.io.File;
1314

@@ -66,9 +67,9 @@ public interface CallbackType extends Callback {
6667

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

69-
public static native int GetHostLicenseMeterAttribute(String name, IntByReference allowedUses, IntByReference totalUses, IntByReference grossUses);
70+
public static native int GetHostLicenseMeterAttribute(String name, LongByReference allowedUses, LongByReference totalUses, LongByReference grossUses);
7071

71-
public static native int GetHostLicenseMeterAttribute(WString name, IntByReference allowedUses, IntByReference totalUses, IntByReference grossUses);
72+
public static native int GetHostLicenseMeterAttribute(WString name, LongByReference allowedUses, LongByReference totalUses, LongByReference grossUses);
7273

7374
public static native int GetHostLicenseExpiryDate(IntByReference expiryDate);
7475

0 commit comments

Comments
 (0)