ImFusion SDK 4.3
License System

Interfaces and examples for interacting with the license system.

+ Collaboration diagram for License System:

Interfaces and examples for interacting with the license system.

Programmatically activating a License

Standalone applications using the framework require an active ImFusion license on the system they are running on. The simplest way to achieve this is by leveraging the framework's default behavior for license activation: If no active license is found on the system, the value of the environment variable IMFUSION_LICENSE_KEY is used to activate the license at application startup.

It is possible to change this default behavior by replacing it with your own logic. Do this by setting InitConfig::licenseInitFunction to your own implementation when calling Framework::init:

initConfig.licenseInitFunction = []() {
// Check if there is already an active license to avoid repeated activations.
{
// Activate a license using the given key. You can hard-code a key here or prompt the user for one.
LicenseManagerSDK::setLicenseKey("XXXX-XXXX-XXXX-XXXX");
}
};
Framework::init(std::move(initConfig));
void init(InitConfig &&initializationSettings={})
Performs general initialization of the framework.
int setLicenseKey(std::string_view key)
Set license key An online activation is performed.
bool isActivated()
Check whether a valid license is installed.
Record to configure the initialization of the ImFusion SDK.
Definition Framework.h:35
std::function< void()> licenseInitFunction
Function will be called once during framework initialization just before checking the license state.
Definition Framework.h:74

Gracefully handling license expiration during runtime

In the background the framework regularly checks if the active ImFusion license is still valid. If for some reason this check fails the framework will be forcefully deinitialized after some seconds of grace period. You can use this time to save the current state of your application and shut it down gracefully to avoid data loss for your users and inform them. In order to do this, register your own InitConfig::licenseExpirationHandler.

Note
The InitConfig::licenseExpirationHandler will be called from a separate thread.

Example code for a Qt application:

initConfig.licenseExpirationHandler = [](const std::string& errMsg, int gracePeriodSec) {
QMetaObject::invokeMethod(
qApp,
[errMsg, gracePeriodSec]() {
ss << "License issue! Quitting application gracefully before ImFusion::Framework will be de-initialized in " << gracePeriodSec << " seconds. Details: " << errMsg;
LOG_ERROR(ss.str());
qApp->quit();
},
Qt::QueuedConnection); // put it in the event queue of the main thread because Qt windowing is not thread-safe
};
Framework::init(std::move(initConfig));
#define LOG_ERROR(...)
Emits a log message of Log::Level::Error, optionally with a category.
Definition Log.h:257
T str(T... args)
std::function< void(const std::string &errMsg, int gracePeriodSec)> licenseExpirationHandler
Optional function to handle the case when a license expiration happens during runtime.
Definition Framework.h:77
Search Tab / S to search, Esc to close