LicenseSpring C++ SDK
Easily add Software Licensing to your application
Loading...
Searching...
No Matches
LicenseHandler.h
Go to the documentation of this file.
1#ifndef LS_LICENSE_HANDLER_H
2#define LS_LICENSE_HANDLER_H
3
4#ifdef _MSC_VER
5#pragma once
6#endif
7
8#include "Configuration.h"
9#include "ProductDetails.h"
10#include "UserLicensesData.h"
11#include "License.h"
12#include "LicenseStorage.h"
13#include "CryptoProvider.h"
14
15namespace LicenseSpring
16{
17class LicenseHandlerImpl;
18
28{
29public:
38 static LicenseHandler &instance(bool globalInit = false);
39
43 LicenseHandler(Configuration::ptr_t config = nullptr, LicenseStorage::ptr_t storage = nullptr);
44 LicenseHandler(const LicenseHandler &) = delete;
48
53
55 const std::wstring &dataLocation() const;
57 void setDataLocation(const std::wstring &path);
59 const std::wstring &licenseFileName() const;
61 void setLicenseFileName(const std::wstring &name);
63 const std::wstring &licenseFilePath() const;
64
65 // ---------- Requests to the LicenseSpring backend ----------
66
68 bool isOnline() const;
70 ProductDetails::ptr_t getProductDetails(bool includeLatestVersion = false) const;
73 bool includeLatestVersion, bool includeCustomFields, const std::string &env) const;
76 Customer::ptr_t user = nullptr, const std::string &licensePolicy = std::string()) const;
78 const LicenseID &getTrialLicense(const std::string &userEmail) const;
80 const std::string &getSSOUrl(
81 const std::string &accountCode = std::string(), bool useAuthCode = true);
83 const std::string &getAirGapActivationCode(
84 const std::string &initializationCode, const std::string &licenseKey);
86 const std::string &getAirGapDeactivationCode(const std::string &initializationCode);
88 void activateAirGapLicense(const std::string &confirmationCode,
89 const std::wstring &activationResponseFile, const std::string &licenseKey,
90 uint32_t policyId);
92 void deactivateAirGapLicense(const std::string &confirmationCode);
94 std::vector<LicenseUser::ptr_t> getLicenseUsers(const Customer &customer);
96 std::vector<LicenseUser::ptr_t> getLicenseUsers(const std::string &customerEmail);
98 std::vector<UserLicensesData::ptr_t> getUserLicenses(
99 const std::string &username, const std::string &password);
101 void activateLicense(const LicenseID &licenseID);
104 const LicenseID &licenseID, const std::vector<DeviceVariable> &deviceVariables);
106 void activateLicense(const std::string &authData,
107 const std::string &accountCode = std::string(), bool useAuthCode = true);
111 bool changePassword(const std::string &password, const std::string &newPassword,
112 const std::string &user = std::string());
115 DeviceIDAlgorithm deviceIdAlgorithm, const std::string &userPassword = std::string());
118 const InstallFileFilter &filter = InstallFileFilter(), bool includeExpiredFeatures = false);
120 const std::vector<std::string> &getVersionList(const LicenseID &licenseID = LicenseID(),
121 const InstallFileFilter &filter = InstallFileFilter());
124 const std::string &version = std::string(),
125 const InstallFileFilter &filter = InstallFileFilter());
129 std::vector<DeviceVariable> getDeviceVariables(bool getFromBackend = false);
131 void syncConsumption(int32_t requestOverage = -1);
133 void syncFeatureConsumption(const std::string &featureCode = std::string());
137 void borrowFloatingLicense(uint32_t hours, uint32_t days = 0);
139 void borrowFloatingLicense(const std::string &borrowEndDateTime = std::string());
143 void registerFloatingFeature(const std::string &featureCode, bool addToWatchdog = true);
145 void releaseFloatingFeature(const std::string &featureCode);
146
147 // ------------------------------------------------------------
148
149 // -------- Local license management and helper methods -------
150 bool isInitialized() const;
151 bool isLicenseExists() const;
153 void updateConsumption(int32_t value = 1, bool saveLicense = true);
156 const std::string &featureCode, int32_t value = 1, bool saveLicense = true);
158 void checkLicenseLocal(bool verifySignature = false);
160 void clearLocalStorage(); // remove local license and also all license information from memory
163
165 void addUserData(const CustomField &data, bool saveLicense = true);
167 void removeUserData(const std::string &key = std::string(), bool saveLicense = true);
169 const std::vector<CustomField> &userData();
171 std::string userData(const std::string &key);
172
174 bool isAutoReleaseSet() const;
176 void setAutoRelease(bool autoRelease);
178 void setupLicenseWatchdog(LicenseWatchdogCallback callback, uint32_t timeout = 0);
184 void setupFeatureWatchdog(LicenseWatchdogCallback callback, uint32_t timeout = 0);
189
192 const std::string &name, const std::string &value, bool saveLicense = true);
194 void addDeviceVariable(const DeviceVariable &variable, bool saveLicense = true);
196 void addDeviceVariables(const std::vector<DeviceVariable> &variables);
198 DeviceVariable deviceVariable(const std::string &name) const;
200 const std::string &deviceVariableValue(const std::string &name) const;
201 // ------------------------------------------------------------
202
203 // ---------------- Offline license management ----------------
205 const std::wstring &createOfflineActivationFile(
206 const LicenseID &licenseID, const std::wstring &activationRequestFile = std::wstring());
208 const std::wstring &createOfflineActivationFile(const LicenseID &licenseID,
209 const std::vector<DeviceVariable> &deviceVariables,
210 const std::wstring &activationRequestFile = std::wstring());
212 void activateLicenseOffline(const std::wstring &activationResponseFile = std::wstring());
214 const std::wstring &deactivateLicenseOffline(
215 const std::wstring &deactivationRequestFile = std::wstring());
217 bool updateOffline(const std::wstring &path = std::wstring(), bool resetConsumption = false);
218 // ------------------------------------------------------------
219
220 // ----------------------- License data -----------------------
222 bool isLicenseValid() const;
224 bool isLicenseTrial() const;
226 bool isLicenseAirGapped() const;
228 bool isLicenseActive() const;
230 bool isLicenseEnabled() const;
232 bool isLicenseExpired() const;
238 bool isLicenseFloating() const;
240 bool isLicenseBorrowed() const;
248 bool isLicenseVMAllowed() const;
260 uint32_t getLicenseTrialPeriod() const;
261
263 const LicenseID &getLicenseID() const;
265 const std::string &getLicenseKey() const;
267 const std::string &getLicenseUser() const;
268
270 const uint64_t getLicenseServerId() const;
272 const std::string &getLicenseStatusStr() const;
274 const std::string &getLicenseStartDate() const;
276 const std::string &getLicenseMetadata() const;
278 const std::string &getOrderStoreId() const;
279
282
300 int getDaysRemaining() const;
305
312
314 const Customer &getLicenseOwner() const;
317
318 bool hasLicenseFeatures() const;
320 const LicenseFeature &getLicenseFeature(const std::string &featureCode) const;
322 const std::vector<LicenseFeature> &getLicenseFeatures() const;
323
326 const std::vector<CustomField> &getLicenseCustomFields() const;
327
329 uint32_t getLicenseTimesActivated() const;
331 uint32_t getLicenseMaxActivations() const;
333 uint32_t getLicenseTransferCount() const;
335 int32_t getLicenseTransferLimit() const;
340
342 uint32_t getLicensePolicyId() const;
343
344 // Meaningful only for Consumption license
350 int32_t getLicenseMaxOverages() const;
353
354 // Meaningful only for Floating license
362 uint32_t getMaxBorrowTime() const;
363 // ------------------------------------------------------------
364
365 // ---------------------- Error handling ----------------------
366 void enableExceptions(bool enable); // By default this class does not throw exceptions
368 bool wasError() const;
370 const std::string &getLastErrorMsg() const;
374 bool isNoInternetError() const;
375 bool isActivationFailed() const;
379 bool isHardwareIDError() const;
380 bool isGeneralError() const;
382 bool canIgnoreError() const; // No Internet, network timeout and server errors can be ignored
383 // ------------------------------------------------------------
384
385private:
386 LicenseHandlerImpl *m_impl;
387};
388
389} // namespace LicenseSpring
390
391#endif // LS_LICENSE_HANDLER_H
#define LS_API
Definition APIDef.h:23
DeviceIDAlgorithm
Type of Device ID algorithm used by the SDK.
Definition PODTypes.h:115
LSErrorCode
LicenseSpring Error codes enum.
Definition PODTypes.h:46
std::shared_ptr< Configuration > ptr_t
Class used for encapsulating LSConsumptionPeriod and converting cosumption period to/from string.
Class for storing key-value data field.
Definition CustomField.h:18
Class that encapsulates information about a customer.
Definition Customer.h:18
std::shared_ptr< Customer > ptr_t
Definition Customer.h:20
Class for storing key-value device variable.
std::shared_ptr< InstallationFile > ptr_t
Class that encapsulates information about license feature.
This class encapsulates functionality of the both LicenseManager and the License. .
void removeUserData(const std::string &key=std::string(), bool saveLicense=true)
const std::string & getAirGapDeactivationCode(const std::string &initializationCode)
tm getLicenseFloatingEndDateTimeUtc() const
const std::string & getLastErrorMsg() const
int32_t getLicenseTransferLimit() const
void syncConsumption(int32_t requestOverage=-1)
bool updateOffline(const std::wstring &path=std::wstring(), bool resetConsumption=false)
void syncFeatureConsumption(const std::string &featureCode=std::string())
~LicenseHandler()
Destructor for LicenseHandler.
InstallationFile::ptr_t checkLicense(const InstallFileFilter &filter=InstallFileFilter(), bool includeExpiredFeatures=false)
InstallationFile::ptr_t getInstallFile(const LicenseID &licenseID=LicenseID(), const std::string &version=std::string(), const InstallFileFilter &filter=InstallFileFilter())
const std::vector< CustomField > & userData()
std::vector< DeviceVariable > getDeviceVariables(bool getFromBackend=false)
void reconfigure(Configuration::ptr_t config, LicenseStorage::ptr_t storage=nullptr)
int32_t getLicenseMaxConsumption() const
const std::string & getLicenseMetadata() const
int32_t getLicenseMaxOverages() const
std::vector< UserLicensesData::ptr_t > getUserLicenses(const std::string &username, const std::string &password)
const std::string & getLicenseStartDate() const
const std::string & getSSOUrl(const std::string &accountCode=std::string(), bool useAuthCode=true)
uint32_t getLicenseMaxActivations() const
static LicenseHandler & instance(bool globalInit=false)
Get singleton object of LicenseHandler.
int32_t getLicenseTotalConsumption() const
bool isDeviceTransferLimited() const
std::string userData(const std::string &key)
void setAutoRelease(bool autoRelease)
ProductDetails::ptr_t getProductDetails(bool includeLatestVersion, bool includeCustomFields, const std::string &env) const
void releaseFloatingFeature(const std::string &featureCode)
void activateLicense(const LicenseID &licenseID)
bool changePassword(const std::string &password, const std::string &newPassword, const std::string &user=std::string())
const LicenseID & getTrialLicense(const std::string &userEmail) const
const std::wstring & licenseFilePath() const
const std::wstring & deactivateLicenseOffline(const std::wstring &deactivationRequestFile=std::wstring())
bool isLicenseUnlimitedConsumptionAllowed() const
tm getLicenseMaintenancePeriodUtc() const
void relinkLicense(DeviceIDAlgorithm deviceIdAlgorithm, const std::string &userPassword=std::string())
LicenseUser::ptr_t getLicenseUserPtr() const
tm getLicenseFloatingEndDateTime() const
LSErrorCode getLastError() const
void updateFeatureConsumption(const std::string &featureCode, int32_t value=1, bool saveLicense=true)
uint32_t getLicenseTimesActivated() const
std::vector< LicenseUser::ptr_t > getLicenseUsers(const Customer &customer)
void setupFeatureWatchdog(LicenseWatchdogCallback callback, uint32_t timeout=0)
bool isResetLicenseConsumptionEnabled() const
void setLicenseFileName(const std::wstring &name)
const std::vector< std::string > & getVersionList(const LicenseID &licenseID=LicenseID(), const InstallFileFilter &filter=InstallFileFilter())
void activateAirGapLicense(const std::string &confirmationCode, const std::wstring &activationResponseFile, const std::string &licenseKey, uint32_t policyId)
const std::string & getLicenseStatusStr() const
void enableExceptions(bool enable)
void addUserData(const CustomField &data, bool saveLicense=true)
uint32_t getLicenseTransferCount() const
void registerFloatingFeature(const std::string &featureCode, bool addToWatchdog=true)
uint32_t getSubscriptionLicenseGracePeriod() const
void setupLicenseWatchdog(LicenseWatchdogCallback callback, uint32_t timeout=0)
void activateLicense(const std::string &authData, const std::string &accountCode=std::string(), bool useAuthCode=true)
void borrowFloatingLicense(uint32_t hours, uint32_t days=0)
bool isDeviceTransferAllowed() const
bool isLicenseNegativeConsumptionAllowed() const
ProductDetails::ptr_t getProductDetails(bool includeLatestVersion=false) const
bool isLicenseOveragesAllowed() const
const std::string & getAirGapActivationCode(const std::string &initializationCode, const std::string &licenseKey)
LicenseHandler(const LicenseHandler &)=delete
uint32_t getLicenseFloatingInUseCount() const
const std::wstring & createOfflineActivationFile(const LicenseID &licenseID, const std::vector< DeviceVariable > &deviceVariables, const std::wstring &activationRequestFile=std::wstring())
void addDeviceVariables(const std::vector< DeviceVariable > &variables)
const std::string & deviceVariableValue(const std::string &name) const
const Customer & getLicenseOwner() const
const std::vector< LicenseFeature > & getLicenseFeatures() const
LicenseType getLicenseType() const
Configuration::ptr_t currentConfig() const
void activateLicenseOffline(const std::wstring &activationResponseFile=std::wstring())
ConsumptionPeriod getLicenseConsumptionPeriod() const
DeviceVariable deviceVariable(const std::string &name) const
const std::wstring & licenseFileName() const
const uint64_t getLicenseServerId() const
const std::string & getLicenseUser() const
void activateLicense(const LicenseID &licenseID, const std::vector< DeviceVariable > &deviceVariables)
const LicenseID & getTrialLicense(Customer::ptr_t user=nullptr, const std::string &licensePolicy=std::string()) const
LicenseHandler(Configuration::ptr_t config=nullptr, LicenseStorage::ptr_t storage=nullptr)
Constructor for LicenseHandler.
uint32_t getLicenseMaxFloatingUsers() const
const std::string & getOrderStoreId() const
const LicenseFeature & getLicenseFeature(const std::string &featureCode) const
int getMaintenanceDaysRemaining() const
void checkLicenseLocal(bool verifySignature=false)
const std::wstring & createOfflineActivationFile(const LicenseID &licenseID, const std::wstring &activationRequestFile=std::wstring())
bool isLicenseOfflineActivated() const
const std::string & getLicenseKey() const
const std::wstring & dataLocation() const
void deactivateAirGapLicense(const std::string &confirmationCode)
LicenseHandler & operator=(const LicenseHandler &)=delete
void setDataLocation(const std::wstring &path)
int getDaysPassedSinceLastCheck() const
uint32_t getLicensePolicyId() const
bool isLicenseMaintenanceExpired() const
uint32_t getLicenseFloatingTimeout() const
uint32_t getMaxBorrowTime() const
uint32_t getLicenseTrialPeriod() const
void updateConsumption(int32_t value=1, bool saveLicense=true)
std::vector< LicenseUser::ptr_t > getLicenseUsers(const std::string &customerEmail)
void addDeviceVariable(const std::string &name, const std::string &value, bool saveLicense=true)
const std::vector< CustomField > & getLicenseCustomFields() const
bool isSubscriptionGracePeriodStarted() const
const LicenseID & getLicenseID() const
void addDeviceVariable(const DeviceVariable &variable, bool saveLicense=true)
void borrowFloatingLicense(const std::string &borrowEndDateTime=std::string())
Class that represents License identifier.
Definition LicenseID.h:21
std::shared_ptr< LicenseStorage > ptr_t
Class used for encapsulating the type of license, comparing types of licenses, and converting them to...
Definition LicenseType.h:20
std::shared_ptr< LicenseUser > ptr_t
Definition LicenseUser.h:21
std::shared_ptr< ProductDetails > ptr_t
std::function< void(const LicenseSpringException &ex)> LicenseWatchdogCallback
Callback function which being called in case of error in background thread (watchdog thread).
Definition License.h:30
Helper struct for filtering installation files by environment and channel.