88import com .sun .jna .ptr .IntByReference ;
99import com .sun .jna .ptr .LongByReference ;
1010import java .math .BigInteger ;
11+ import com .fasterxml .jackson .databind .ObjectMapper ;
12+ import com .fasterxml .jackson .core .JsonProcessingException ;
1113import java .util .ArrayList ;
1214import java .util .List ;
1315
@@ -63,6 +65,28 @@ public static void SetHostUrl(String hostUrl) throws LexFloatClientException {
6365 }
6466 }
6567
68+ /**
69+ * Sets the permission flag. This function must be called on every start of your program
70+ * after SetHostProductId() function in case the application allows borrowing of licenses
71+ * or system wide activation.
72+ *
73+ * @param flag depending on your application's requirements, choose one of
74+ * the following values: LF_USER, LF_ALL_USERS.
75+ * <ul>
76+ * <li> LF_USER: This flag indicates that the application does not require admin or root permissions to run.</li>
77+ * <li> LF_ALL_USERS: This flag is specifically designed for Windows and should be used for system-wide activations.</li>
78+ * </ul>
79+ * @throws LexFloatClientException
80+ */
81+ public static void SetPermissionFlag (int flag ) throws LexFloatClientException {
82+ int status ;
83+ status = LexFloatClientNative .SetPermissionFlag (flag )
84+
85+ if (LF_OK != status ) {
86+ throw new LexFloatClientException (status );
87+ }
88+ }
89+
6690 /**
6791 * Sets the renew license callback function.<br>
6892 * Whenever the license lease is about to expire, a renew request is sent to
@@ -120,6 +144,24 @@ public static void SetFloatingClientMetadata(String key, String value) throws Le
120144 }
121145 }
122146
147+ /**
148+ * Gets the lease expiry date timestamp of the floating client.
149+ *
150+ * @return Returns the timestamp
151+ * @throws LexFloatClientException
152+ */
153+ public static int GetFloatingClientLeaseExpiryDate () throws LexFloatClientException {
154+ int status ;
155+ IntByReference expiryDate = new IntByReference (0 );
156+ status = LexFloatClientNative .GetFloatingClientLeaseExpiryDate (expiryDate );
157+ switch (status ) {
158+ case LF_OK :
159+ return expiryDate .getValue ();
160+ default :
161+ throw new LexFloatClientException (status );
162+ }
163+ }
164+
123165 /**
124166 * Gets the version of this library.
125167 *
@@ -145,6 +187,53 @@ public static String GetFloatingClientLibraryVersion() throws LexFloatClientExce
145187 throw new LexFloatClientException (status );
146188 }
147189
190+ /**
191+ * Gets the host configuration.
192+ * This function sends a network request to LexFloatServer to get the configuration details.
193+
194+ * @return Returns host configuration.
195+ * @throws LexFloatClientException
196+ * @throws UnsupportedEncodingException
197+ */
198+ public static HostConfig GetHostConfig () throws LexFloatClientException , UnsupportedEncodingException {
199+ int status ;
200+ int bufferSize = 1024 ;
201+ if (Platform .isWindows ()) {
202+ CharBuffer buffer = CharBuffer .allocate (bufferSize );
203+ status = LexFloatClientNative .GetHostConfigInternal (buffer , bufferSize );
204+ if (LF_OK == status ) {
205+ String hostConfigJson = buffer .toString ().trim ();
206+ if (!hostConfigJson .isEmpty ()) {
207+ HostConfig hostConfig = null ;
208+ ObjectMapper objectMapper = new ObjectMapper ();
209+ try {
210+ hostConfig = objectMapper .readValue (hostConfigJson , HostConfig .class );
211+ } catch (JsonProcessingException e ) {}
212+ return hostConfig ;
213+ } else {
214+ return null ;
215+ }
216+ }
217+ } else {
218+ ByteBuffer buffer = ByteBuffer .allocate (bufferSize );
219+ status = LexFloatClientNative .GetHostConfigInternal (buffer , bufferSize );
220+ if (LF_OK == status ) {
221+ String hostConfigJson = new String (buffer .array (), "UTF-8" ).trim ();
222+ if (!hostConfigJson .isEmpty ()) {
223+ HostConfig hostConfig = null ;
224+ ObjectMapper objectMapper = new ObjectMapper ();
225+ try {
226+ hostConfig = objectMapper .readValue (hostConfigJson , HostConfig .class );
227+ } catch (JsonProcessingException e ) {}
228+ return hostConfig ;
229+ } else {
230+ return null ;
231+ }
232+ }
233+ }
234+ throw new LexFloatClientException (status );
235+ }
236+
148237 /**
149238 * Gets the product version name.
150239 *
@@ -252,6 +341,32 @@ public static String GetHostLicenseMetadata(String key) throws LexFloatClientExc
252341 }
253342 throw new LexFloatClientException (status );
254343 }
344+
345+ /**
346+ * Get the value of the license metadata field associated with the LexFloatServer license.
347+ *
348+ * @param key key of the metadata field whose value you want to get
349+ * @return Returns the metadata key value
350+ * @throws LexFloatClientException
351+ * @throws UnsupportedEncodingException
352+ */
353+ public static String GetFloatingClientMetadata (String key ) throws LexFloatClientException , UnsupportedEncodingException {
354+ int status ;
355+ if (Platform .isWindows ()) {
356+ CharBuffer buffer = CharBuffer .allocate (256 );
357+ status = LexFloatClientNative .GetFloatingClientMetadata (new WString (key ), buffer , 256 );
358+ if (LF_OK == status ) {
359+ return buffer .toString ().trim ();
360+ }
361+ } else {
362+ ByteBuffer buffer = ByteBuffer .allocate (256 );
363+ status = LexFloatClientNative .GetFloatingClientMetadata (key , buffer , 256 );
364+ if (LF_OK == status ) {
365+ return new String (buffer .array (), "UTF-8" );
366+ }
367+ }
368+ throw new LexFloatClientException (status );
369+ }
255370
256371 /**
257372 * Gets the license meter attribute allowed uses and total uses associated
@@ -301,6 +416,31 @@ public static int GetHostLicenseExpiryDate() throws LexFloatClientException {
301416 }
302417 }
303418
419+ /**
420+ * Gets the mode of the floating license (online or offline).
421+ *
422+ * @return mode - Returns the floating license mode.
423+ * @throws LexFloatClientException
424+ * @throws UnsupportedEncodingException
425+ */
426+ public static String GetFloatingLicenseMode () throws LexFloatClientException , UnsupportedEncodingException {
427+ int status ;
428+ if (Platform .isWindows ()) {
429+ CharBuffer buffer = CharBuffer .allocate (256 );
430+ status = LexFloatClientNative .GetFloatingLicenseMode (buffer , 256 );
431+ if (LF_OK == status ) {
432+ return buffer .toString ().trim ();
433+ }
434+ } else {
435+ ByteBuffer buffer = ByteBuffer .allocate (256 );
436+ status = LexFloatClientNative .GetFloatingLicenseMode (buffer , 256 );
437+ if (LF_OK == status ) {
438+ return new String (buffer .array (), "UTF-8" ).trim ();
439+ }
440+ }
441+ throw new LexFloatClientException (status );
442+ }
443+
304444 /**
305445 * Gets the meter attribute uses consumed by the floating client.
306446 *
@@ -326,6 +466,21 @@ public static int GetFloatingClientMeterAttributeUses(String name) throws LexFlo
326466 throw new LexFloatClientException (status );
327467 }
328468
469+ /**
470+ * Sends the request to lease the license from the LexFloatServer for offline usage.
471+ * The maximum value of lease duration is configured in the config.yml of LexFloatServer.
472+ *
473+ * @param leaseDuration value of the lease duration.
474+ * @throws LexFloatClientException
475+ */
476+ public static void RequestOfflineFloatingLicense (int leaseDuration ) throws LexFloatClientException {
477+ int status ;
478+ status = LexFloatClientNative .RequestOfflineFloatingLicense (leaseDuration );
479+ if (LF_OK != status ) {
480+ throw new LexFloatClientException (status );
481+ }
482+ }
483+
329484 /**
330485 * Sends the request to lease the license from the LexFloatServer
331486 *
@@ -368,6 +523,8 @@ public static boolean HasFloatingLicense() throws LexFloatClientException {
368523 return true ;
369524 case LexFloatClientException .LF_E_NO_LICENSE :
370525 return false ;
526+ case LexFloatClientException .LF_FAIL :
527+ return false ;
371528 default :
372529 throw new LexFloatClientException (status );
373530 }
0 commit comments