|
8 | 8 | import java.nio.charset.StandardCharsets;
|
9 | 9 | import java.io.UnsupportedEncodingException;
|
10 | 10 | import com.sun.jna.ptr.IntByReference;
|
| 11 | +import com.sun.jna.ptr.LongByReference; |
| 12 | +import java.math.BigInteger; |
11 | 13 | import java.util.ArrayList;
|
12 | 14 | import java.util.List;
|
13 | 15 | import com.fasterxml.jackson.databind.ObjectMapper;
|
@@ -35,6 +37,11 @@ public class LexActivator {
|
35 | 37 | public static final int LA_RELEASES_ALL = 1;
|
36 | 38 | public static final int LA_RELEASES_ALLOWED = 2;
|
37 | 39 |
|
| 40 | + // Convert long to BigInteger to correctly handle unsigned 64-bit values |
| 41 | + private static BigInteger toUnsignedBigInteger(long value) { |
| 42 | + return BigInteger.valueOf(value).and(BigInteger.valueOf(0xFFFFFFFFFFFFFFFFL)); |
| 43 | + } |
| 44 | + |
38 | 45 | /**
|
39 | 46 | * Sets the absolute path of the Product.dat file. This function must be called
|
40 | 47 | * on every start of your program before any other functions are called.
|
@@ -363,13 +370,14 @@ public static void SetReleaseChannel(String releaseChannel) throws LexActivatorE
|
363 | 370 | }
|
364 | 371 |
|
365 | 372 | /**
|
366 |
| - * Sets the lease duration for the activation. |
| 373 | + * Sets the lease duration for the activation. The activation lease duration |
| 374 | + * is honoured when the allow client lease duration property is enabled. |
367 | 375 | *
|
368 |
| - * @param leaseDuration |
| 376 | + * @param leaseDuration value of the lease duration. A value of -1 indicates unlimited lease duration. |
369 | 377 | *
|
370 | 378 | * @throws LexActivatorException
|
371 | 379 | */
|
372 |
| - public static void SetActivationLeaseDuration(int leaseDuration) throws LexActivatorException { |
| 380 | + public static void SetActivationLeaseDuration(long leaseDuration) throws LexActivatorException { |
373 | 381 | int status;
|
374 | 382 | status = LexActivatorNative.SetActivationLeaseDuration(leaseDuration);
|
375 | 383 | if (LA_OK != status) {
|
@@ -601,21 +609,22 @@ public static String GetLicenseMetadata(String key) throws LexActivatorException
|
601 | 609 | public static LicenseMeterAttribute GetLicenseMeterAttribute(String name)
|
602 | 610 | throws LexActivatorException, UnsupportedEncodingException {
|
603 | 611 | int status;
|
604 |
| - IntByReference allowedUses = new IntByReference(0); |
605 |
| - IntByReference totalUses = new IntByReference(0); |
606 |
| - IntByReference grossUses = new IntByReference(0); |
| 612 | + LongByReference allowedUses = new LongByReference(0); |
| 613 | + // These references can still hold the uint64_t values populated by the native function |
| 614 | + LongByReference totalUses = new LongByReference(0); |
| 615 | + LongByReference grossUses = new LongByReference(0); |
607 | 616 |
|
608 | 617 | if (Platform.isWindows()) {
|
609 | 618 | status = LexActivatorNative.GetLicenseMeterAttribute(new WString(name), allowedUses, totalUses, grossUses);
|
610 | 619 | if (LA_OK == status) {
|
611 |
| - return new LicenseMeterAttribute(name, allowedUses.getValue(), totalUses.getValue(), |
612 |
| - grossUses.getValue()); |
| 620 | + return new LicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedBigInteger(totalUses.getValue()), |
| 621 | + toUnsignedBigInteger(grossUses.getValue())); |
613 | 622 | }
|
614 | 623 | } else {
|
615 | 624 | status = LexActivatorNative.GetLicenseMeterAttribute(name, allowedUses, totalUses, grossUses);
|
616 | 625 | if (LA_OK == status) {
|
617 |
| - return new LicenseMeterAttribute(name, allowedUses.getValue(), totalUses.getValue(), |
618 |
| - grossUses.getValue()); |
| 626 | + return new LicenseMeterAttribute(name, allowedUses.getValue(), toUnsignedBigInteger(totalUses.getValue()), |
| 627 | + toUnsignedBigInteger(grossUses.getValue())); |
619 | 628 | }
|
620 | 629 | }
|
621 | 630 | throw new LexActivatorException(status);
|
@@ -652,9 +661,9 @@ public static String GetLicenseKey() throws LexActivatorException, UnsupportedEn
|
652 | 661 | * @return Returns the allowed activations
|
653 | 662 | * @throws LexActivatorException
|
654 | 663 | */
|
655 |
| - public static int GetLicenseAllowedActivations() throws LexActivatorException { |
| 664 | + public static long GetLicenseAllowedActivations() throws LexActivatorException { |
656 | 665 | int status;
|
657 |
| - IntByReference allowedActivations = new IntByReference(0); |
| 666 | + LongByReference allowedActivations = new LongByReference(0); |
658 | 667 | status = LexActivatorNative.GetLicenseAllowedActivations(allowedActivations);
|
659 | 668 | switch (status) {
|
660 | 669 | case LA_OK:
|
@@ -692,9 +701,9 @@ public static int GetLicenseTotalActivations() throws LexActivatorException {
|
692 | 701 | * @return Returns the allowed deactivations
|
693 | 702 | * @throws LexActivatorException
|
694 | 703 | */
|
695 |
| - public static int GetLicenseAllowedDeactivations() throws LexActivatorException { |
| 704 | + public static long GetLicenseAllowedDeactivations() throws LexActivatorException { |
696 | 705 | int status;
|
697 |
| - IntByReference allowedDeactivations = new IntByReference(0); |
| 706 | + LongByReference allowedDeactivations = new LongByReference(0); |
698 | 707 | status = LexActivatorNative.GetLicenseAllowedDeactivations(allowedDeactivations);
|
699 | 708 | switch (status) {
|
700 | 709 | case LA_OK:
|
|
0 commit comments