Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: unlimited implementation for host meter attributes #12

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
package com.cryptlex.android.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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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 java.util.ArrayList;
import java.util.List;

Expand All @@ -23,6 +25,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 @@ -212,13 +219,14 @@ public static String GetHostLicenseMetadata(String key) throws LexFloatClientExc
*/
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);

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 @@ -39,7 +40,7 @@ public interface CallbackType extends Callback {

public static native int GetHostLicenseMetadata(String key, ByteBuffer 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 GetHostLicenseExpiryDate(IntByReference expiryDate);

Expand Down