From b4a7762f4d4e098aa73dd64235884977d5205cdb Mon Sep 17 00:00:00 2001 From: Muneeb Khurshid Date: Tue, 7 May 2024 11:58:22 +0530 Subject: [PATCH 1/4] feat: add setCacheMode function --- src/lexactivator.ts | 20 +++++++++++++++++++- src/native/LexActivator.h | 16 ++++++++++++++++ src/native/main.cpp | 16 ++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/lexactivator.ts b/src/lexactivator.ts index 59a33d2..63b6323 100644 --- a/src/lexactivator.ts +++ b/src/lexactivator.ts @@ -2,7 +2,7 @@ import { LexActivatorNative } from "./lexactivator-native.js"; import { LexStatusCodes } from "./lexstatus-codes.js"; import { LexActivatorException } from "./lexactivator-exception.js"; import { arrayToString } from "./lexactivator-native.js"; -import { Release } from "./release.js" +import { Release } from "./release.js"; /** * @class LicenseMeterAttribute @@ -214,6 +214,24 @@ export class LexActivator { } } + /** + * Enables or disables in-memory caching + * PURPOSE: Enables or disables in-memory caching for LexActivator. This function is designed to control caching + * behavior to suit specific application requirements. Caching is enabled by default to enhance performance. + * Disabling caching is recommended in environments where multiple processes access the same license on a + * single machine and require real-time updates to the license state. + * RETURN CODES: LA_OK, LA_E_PRODUCT_ID + * @param enable true or false to enable or disable in-memory caching respectively. + */ + + static SetCacheMode(enable:boolean):void{ + const status = LexActivatorNative.SetCacheMode(enable); + if (LexStatusCodes.LA_OK != status) { + throw new LexActivatorException(status); + } + + } + /** * In case you don't want to use the LexActivator's advanced * device fingerprinting algorithm, this function can be used to set a custom diff --git a/src/native/LexActivator.h b/src/native/LexActivator.h index f9bcc47..dd77f3e 100644 --- a/src/native/LexActivator.h +++ b/src/native/LexActivator.h @@ -184,6 +184,22 @@ LEXACTIVATOR_API int LA_CC SetDataDirectory(CSTRTYPE directoryPath); */ LEXACTIVATOR_API int LA_CC SetDebugMode(uint32_t enable); +/* + FUNCTION: SetCacheMode() + + PURPOSE: Enables or disables in-memory caching for LexActivator. This function is designed to control caching + behavior to suit specific application requirements. Caching is enabled by default to enhance performance. + + Disabling caching is recommended in environments where multiple processes access the same license on a + single machine and require real-time updates to the license state. + + * enable - 0 or 1 to disable or enable in-memory caching. + + RETURN CODES: LA_OK, LA_E_PRODUCT_ID +*/ + +LEXACTIVATOR_API int LA_CC SetCacheMode(uint32_t enable); + /* FUNCTION: SetCustomDeviceFingerprint() diff --git a/src/native/main.cpp b/src/native/main.cpp index 8d0365a..f98d9b3 100644 --- a/src/native/main.cpp +++ b/src/native/main.cpp @@ -163,6 +163,21 @@ Napi::Value setDebugMode(const Napi::CallbackInfo &info) return Napi::Number::New(env, SetDebugMode(arg0)); } +Napi::Value setCacheMode(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + if (info.Length() < 1) + { + Napi::TypeError::New(env, MISSING_ARGUMENTS).ThrowAsJavaScriptException(); + return env.Null(); + } + if (!info[0].IsBoolean()) { + Napi::TypeError::New(env, INVALID_ARGUMENT_TYPE).ThrowAsJavaScriptException(); + return env.Null(); + } + uint32_t arg0 = info[0].As().Value(); + return Napi::Number::New(env, SetCacheMode(arg0)); +} + Napi::Value setCustomDeviceFingerprint(const Napi::CallbackInfo &info) { Napi::Env env = info.Env(); @@ -1521,6 +1536,7 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) exports["SetProductData"] = Napi::Function::New(env, setProductData); exports["SetDataDirectory"] = Napi::Function::New(env, setDataDirectory); exports["SetDebugMode"] = Napi::Function::New(env, setDebugMode); + exports["SetCacheMode"] = Napi::Function::New(env, setCacheMode); exports["SetCustomDeviceFingerprint"] = Napi::Function::New(env, setCustomDeviceFingerprint); exports["SetProductId"] = Napi::Function::New(env, setProductId); exports["SetLicenseKey"] = Napi::Function::New(env, setLicenseKey); From 4b6af90a9d0168579e068e221f92d938796ff827 Mon Sep 17 00:00:00 2001 From: muneebkq Date: Thu, 23 May 2024 14:01:14 +0530 Subject: [PATCH 2/4] refactor: jsdoc --- src/lexactivator.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/lexactivator.ts b/src/lexactivator.ts index 63b6323..18e9d37 100644 --- a/src/lexactivator.ts +++ b/src/lexactivator.ts @@ -215,13 +215,16 @@ export class LexActivator { } /** - * Enables or disables in-memory caching - * PURPOSE: Enables or disables in-memory caching for LexActivator. This function is designed to control caching - * behavior to suit specific application requirements. Caching is enabled by default to enhance performance. - * Disabling caching is recommended in environments where multiple processes access the same license on a + * Enables or disables in-memory caching for LexActivator. + * + * This function is designed to control caching behavior to suit specific application requirements. + * Caching is enabled by default to enhance performance. + * + * Disabling caching is recommended in environments where multiple processes access the same license on a * single machine and require real-time updates to the license state. - * RETURN CODES: LA_OK, LA_E_PRODUCT_ID - * @param enable true or false to enable or disable in-memory caching respectively. + * + * @param {enable} true or false to enable or disable in-memory caching. + * @throws {LexActivatorException} */ static SetCacheMode(enable:boolean):void{ @@ -229,7 +232,6 @@ export class LexActivator { if (LexStatusCodes.LA_OK != status) { throw new LexActivatorException(status); } - } /** From e5b5450189e851b450c556b96133e70dc1f61c75 Mon Sep 17 00:00:00 2001 From: muneebkq Date: Thu, 23 May 2024 17:08:25 +0530 Subject: [PATCH 3/4] fix: add ternary operator --- src/lexactivator.ts | 11 +++++++++-- src/native/main.cpp | 5 +++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lexactivator.ts b/src/lexactivator.ts index 18e9d37..4d84f7e 100644 --- a/src/lexactivator.ts +++ b/src/lexactivator.ts @@ -227,8 +227,15 @@ export class LexActivator { * @throws {LexActivatorException} */ - static SetCacheMode(enable:boolean):void{ - const status = LexActivatorNative.SetCacheMode(enable); + static SetCacheMode(enable: boolean):void{ + let enableFlag; + if(enable){ + enableFlag = 1; + } + else{ + enableFlag = 0; + } + const status = LexActivatorNative.SetCacheMode(enableFlag); if (LexStatusCodes.LA_OK != status) { throw new LexActivatorException(status); } diff --git a/src/native/main.cpp b/src/native/main.cpp index f98d9b3..04891ff 100644 --- a/src/native/main.cpp +++ b/src/native/main.cpp @@ -170,11 +170,12 @@ Napi::Value setCacheMode(const Napi::CallbackInfo& info) { Napi::TypeError::New(env, MISSING_ARGUMENTS).ThrowAsJavaScriptException(); return env.Null(); } - if (!info[0].IsBoolean()) { + if (!info[0].IsNumber()) + { Napi::TypeError::New(env, INVALID_ARGUMENT_TYPE).ThrowAsJavaScriptException(); return env.Null(); } - uint32_t arg0 = info[0].As().Value(); + uint32_t arg0 = info[0].As().Uint32Value(); return Napi::Number::New(env, SetCacheMode(arg0)); } From 53ca5620a2aa4ae1d9462429a22c415ef33aa316 Mon Sep 17 00:00:00 2001 From: muneebkq Date: Thu, 23 May 2024 17:11:11 +0530 Subject: [PATCH 4/4] refactor: jsdoc --- src/lexactivator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lexactivator.ts b/src/lexactivator.ts index 4d84f7e..d0b0c6a 100644 --- a/src/lexactivator.ts +++ b/src/lexactivator.ts @@ -227,7 +227,7 @@ export class LexActivator { * @throws {LexActivatorException} */ - static SetCacheMode(enable: boolean):void{ + static SetCacheMode(enable: boolean): void{ let enableFlag; if(enable){ enableFlag = 1;