Skip to content

Commit c43678d

Browse files
committed
feat: unlimited implementation of meter attribute getter
1 parent ac11888 commit c43678d

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,27 @@
22

33
public class HostLicenseMeterAttribute {
44

5+
/**
6+
* The name of the meter attribute.
7+
*/
58
public String name;
69

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

9-
public int totalUses;
15+
/**
16+
* The total uses of the meter attribute.
17+
*/
18+
public long totalUses;
1019

11-
public int grossUses;
20+
/**
21+
* The gross uses of the meter attribute.
22+
*/
23+
public long grossUses;
1224

13-
public HostLicenseMeterAttribute(String name, int allowedUses, int totalUses, int grossUses) {
25+
public HostLicenseMeterAttribute(String name, long allowedUses, long totalUses, long grossUses) {
1426
this.name = name;
1527
this.allowedUses = allowedUses;
1628
this.totalUses = totalUses;

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

Lines changed: 11 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,10 @@ public class LexFloatClient {
2426
*/
2527
public static final int LF_FAIL = 1;
2628

29+
private static long toUnsignedLong(long value) {
30+
return BigInteger.valueOf(value).and(BigInteger.valueOf(0xFFFFFFFFFFFFFFFFL)).longValue();
31+
}
32+
2733
/**
2834
* Sets the product id of your application
2935
*
@@ -257,19 +263,19 @@ public static String GetHostLicenseMetadata(String key) throws LexFloatClientExc
257263
*/
258264
public static HostLicenseMeterAttribute GetHostLicenseMeterAttribute(String name) throws LexFloatClientException, UnsupportedEncodingException {
259265
int status;
260-
IntByReference allowedUses = new IntByReference(0);
261-
IntByReference totalUses = new IntByReference(0);
262-
IntByReference grossUses = new IntByReference(0);
266+
LongByReference allowedUses = new LongByReference(0);
267+
LongByReference totalUses = new LongByReference(0);
268+
LongByReference grossUses = new LongByReference(0);
263269

264270
if (Platform.isWindows()) {
265271
status = LexFloatClientNative.GetHostLicenseMeterAttribute(new WString(name), allowedUses, totalUses, grossUses);
266272
if (LF_OK == status) {
267-
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), totalUses.getValue(), grossUses.getValue());
273+
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedLong(totalUses.getValue()), toUnsignedLong(grossUses.getValue()));
268274
}
269275
} else {
270276
status = LexFloatClientNative.GetHostLicenseMeterAttribute(name, allowedUses, totalUses, grossUses);
271277
if (LF_OK == status) {
272-
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), totalUses.getValue(), grossUses.getValue());
278+
return new HostLicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedLong(totalUses.getValue()), toUnsignedLong(grossUses.getValue()));
273279
}
274280
}
275281
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)