Skip to content

Commit 728e11f

Browse files
authored
Merge pull request #12 from cryptlex/ahmad/unlimited-implementation
feat: unlimited implementation for host meter attribute
2 parents ac11888 + 6c09fe2 commit 728e11f

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 java.util.ArrayList;
1012
import java.util.List;
1113

@@ -24,6 +26,11 @@ public class LexFloatClient {
2426
*/
2527
public static final int LF_FAIL = 1;
2628

29+
// Convert long to BigInteger to correctly handle unsigned 64-bit values
30+
private static BigInteger toUnsignedBigInteger(long value) {
31+
return BigInteger.valueOf(value).and(BigInteger.valueOf(0xFFFFFFFFFFFFFFFFL));
32+
}
33+
2734
/**
2835
* Sets the product id of your application
2936
*
@@ -257,19 +264,20 @@ public static String GetHostLicenseMetadata(String key) throws LexFloatClientExc
257264
*/
258265
public static HostLicenseMeterAttribute GetHostLicenseMeterAttribute(String name) throws LexFloatClientException, UnsupportedEncodingException {
259266
int status;
260-
IntByReference allowedUses = new IntByReference(0);
261-
IntByReference totalUses = new IntByReference(0);
262-
IntByReference grossUses = new IntByReference(0);
267+
LongByReference allowedUses = new LongByReference(0);
268+
// These references can still hold the uint64_t values populated by the native function
269+
LongByReference totalUses = new LongByReference(0);
270+
LongByReference grossUses = new LongByReference(0);
263271

264272
if (Platform.isWindows()) {
265273
status = LexFloatClientNative.GetHostLicenseMeterAttribute(new WString(name), allowedUses, totalUses, grossUses);
266274
if (LF_OK == status) {
267-
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), totalUses.getValue(), grossUses.getValue());
275+
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedBigInteger(totalUses.getValue()), toUnsignedBigInteger(grossUses.getValue()));
268276
}
269277
} else {
270278
status = LexFloatClientNative.GetHostLicenseMeterAttribute(name, allowedUses, totalUses, grossUses);
271279
if (LF_OK == status) {
272-
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), totalUses.getValue(), grossUses.getValue());
280+
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedBigInteger(totalUses.getValue()), toUnsignedBigInteger(grossUses.getValue()));
273281
}
274282
}
275283
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

@@ -55,9 +56,9 @@ public interface CallbackType extends Callback {
5556

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

58-
public static native int GetHostLicenseMeterAttribute(String name, IntByReference allowedUses, IntByReference totalUses, IntByReference grossUses);
59+
public static native int GetHostLicenseMeterAttribute(String name, LongByReference allowedUses, LongByReference totalUses, LongByReference grossUses);
5960

60-
public static native int GetHostLicenseMeterAttribute(WString name, IntByReference allowedUses, IntByReference totalUses, IntByReference grossUses);
61+
public static native int GetHostLicenseMeterAttribute(WString name, LongByReference allowedUses, LongByReference totalUses, LongByReference grossUses);
6162

6263
public static native int GetHostLicenseExpiryDate(IntByReference expiryDate);
6364

0 commit comments

Comments
 (0)