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{
17 class LicenseHandlerImpl;
18
28 {
29 public:
30
37 static LicenseHandler& instance( bool globalInit = false );
38
42 LicenseHandler( Configuration::ptr_t config = nullptr, LicenseStorage::ptr_t storage = nullptr );
43 LicenseHandler( const LicenseHandler& ) = delete;
47
49 void reconfigure( Configuration::ptr_t config, LicenseStorage::ptr_t storage = nullptr );
52
54 const std::wstring& dataLocation() const;
56 void setDataLocation( const std::wstring& path );
58 const std::wstring& licenseFileName() const;
60 void setLicenseFileName( const std::wstring& name );
62 const std::wstring& licenseFilePath() const;
63
64 // ---------- Requests to the LicenseSpring backend ----------
65
67 bool isOnline() const;
69 ProductDetails::ptr_t getProductDetails( bool includeLatestVersion = false ) const;
72 const std::string& licensePolicy = std::string() ) const;
74 const LicenseID& getTrialLicense( const std::string& userEmail ) const;
76 const std::string& getSSOUrl( const std::string& accountCode = std::string(), bool useAuthCode = true );
78 const std::string& getAirGapActivationCode( const std::string& initializationCode, const std::string& licenseKey );
80 const std::string& getAirGapDeactivationCode( const std::string& initializationCode );
82 void activateAirGapLicense( const std::string& confirmationCode, const std::wstring& activationResponseFile, const std::string& licenseKey, uint32_t policyId );
84 void deactivateAirGapLicense( const std::string& confirmationCode );
86 std::vector<LicenseUser::ptr_t> getLicenseUsers( const Customer& customer );
88 std::vector<LicenseUser::ptr_t> getLicenseUsers( const std::string& customerEmail );
90 std::vector<UserLicensesData::ptr_t> getUserLicenses( const std::string& username, const std::string& password );
92 void activateLicense( const LicenseID& licenseID );
94 void activateLicense( const LicenseID& licenseID, const std::vector<DeviceVariable>& deviceVariables );
96 void activateLicense( const std::string& authData, const std::string& accountCode = std::string(), bool useAuthCode = true );
100 bool changePassword( const std::string& password, const std::string& newPassword,
101 const std::string& user = std::string() );
103 void relinkLicense( DeviceIDAlgorithm deviceIdAlgorithm, const std::string& userPassword = std::string() );
105 InstallationFile::ptr_t checkLicense( const InstallFileFilter& filter = InstallFileFilter(), bool includeExpiredFeatures = false );
107 const std::vector<std::string>& getVersionList( const LicenseID& licenseID = LicenseID(),
108 const InstallFileFilter& filter = InstallFileFilter() );
111 const std::string& version = std::string(),
112 const InstallFileFilter& filter = InstallFileFilter() );
116 std::vector<DeviceVariable> getDeviceVariables( bool getFromBackend = false );
118 void syncConsumption( int32_t requestOverage = -1 );
120 void syncFeatureConsumption( const std::string& featureCode = std::string() );
124 void borrowFloatingLicense( uint32_t hours, uint32_t days = 0 );
126 void borrowFloatingLicense( const std::string& borrowEndDateTime = std::string() );
130 void registerFloatingFeature( const std::string& featureCode, bool addToWatchdog = true );
132 void releaseFloatingFeature( const std::string& featureCode );
133
134 // ------------------------------------------------------------
135
136 // -------- Local license management and helper methods -------
137 bool isInitialized() const;
138 bool isLicenseExists() const;
140 void updateConsumption( int32_t value = 1, bool saveLicense = true );
142 void updateFeatureConsumption( const std::string& featureCode, int32_t value = 1, bool saveLicense = true );
144 void checkLicenseLocal( bool verifySignature = false );
146 void clearLocalStorage(); // remove local license and also all license information from memory
149
151 void addUserData( const CustomField& data, bool saveLicense = true );
153 void removeUserData( const std::string& key = std::string(), bool saveLicense = true );
155 const std::vector<CustomField>& userData();
157 std::string userData( const std::string& key );
158
160 bool isAutoReleaseSet() const;
162 void setAutoRelease( bool autoRelease );
164 void setupLicenseWatchdog( LicenseWatchdogCallback callback, uint32_t timeout = 0 );
170 void setupFeatureWatchdog( LicenseWatchdogCallback callback, uint32_t timeout = 0 );
175
177 void addDeviceVariable( const std::string& name, const std::string& value, bool saveLicense = true );
179 void addDeviceVariable( const DeviceVariable& variable, bool saveLicense = true );
181 void addDeviceVariables( const std::vector<DeviceVariable>& variables );
183 DeviceVariable deviceVariable( const std::string& name ) const;
185 const std::string& deviceVariableValue( const std::string& name ) const;
186 // ------------------------------------------------------------
187
188 // ---------------- Offline license management ----------------
190 const std::wstring& createOfflineActivationFile( const LicenseID& licenseID,
191 const std::wstring& activationRequestFile = std::wstring() );
193 const std::wstring& createOfflineActivationFile( const LicenseID& licenseID,
194 const std::vector<DeviceVariable>& deviceVariables,
195 const std::wstring& activationRequestFile = std::wstring() );
197 void activateLicenseOffline( const std::wstring& activationResponseFile = std::wstring() );
199 const std::wstring& deactivateLicenseOffline( const std::wstring& deactivationRequestFile = std::wstring() );
201 bool updateOffline( const std::wstring& path = std::wstring(), bool resetConsumption = false );
202 // ------------------------------------------------------------
203
204 // ----------------------- License data -----------------------
206 bool isLicenseValid() const;
208 bool isLicenseTrial() const;
210 bool isLicenseAirGapped() const;
212 bool isLicenseActive() const;
214 bool isLicenseEnabled() const;
216 bool isLicenseExpired() const;
222 bool isLicenseFloating() const;
224 bool isLicenseBorrowed() const;
232 bool isLicenseVMAllowed() const;
244 uint32_t getLicenseTrialPeriod() const;
245
247 const LicenseID& getLicenseID() const;
249 const std::string& getLicenseKey() const;
251 const std::string& getLicenseUser() const;
252
254 const uint64_t getLicenseServerId() const;
256 const std::string& getLicenseStatusStr() const;
258 const std::string& getLicenseStartDate() const;
260 const std::string& getLicenseMetadata() const;
262 const std::string& getOrderStoreId() const;
263
266
284 int getDaysRemaining() const;
289
296
298 const Customer& getLicenseOwner() const;
301
302 bool hasLicenseFeatures() const;
304 const LicenseFeature& getLicenseFeature( const std::string& featureCode ) const;
306 const std::vector<LicenseFeature>& getLicenseFeatures() const;
307
310 const std::vector<CustomField>& getLicenseCustomFields() const;
311
313 uint32_t getLicenseTimesActivated() const;
315 uint32_t getLicenseMaxActivations() const;
317 uint32_t getLicenseTransferCount() const;
319 int32_t getLicenseTransferLimit() const;
324
326 uint32_t getLicensePolicyId() const;
327
328 // Meaningful only for Consumption license
334 int32_t getLicenseMaxOverages() const;
337
338 // Meaningful only for Floating license
346 uint32_t getMaxBorrowTime() const;
347 // ------------------------------------------------------------
348
349 // ---------------------- Error handling ----------------------
350 void enableExceptions( bool enable ); // By default this class does not throw exceptions
352 bool wasError() const;
354 const std::string& getLastErrorMsg() const;
358 bool isNoInternetError() const;
359 bool isActivationFailed() const;
363 bool isHardwareIDError() const;
364 bool isGeneralError() const;
366 bool canIgnoreError() const; // No Internet, network timeout and server errors can be ignored
367 // ------------------------------------------------------------
368
369 private:
370 LicenseHandlerImpl* m_impl;
371 };
372
373} // namespace LicenseSpirng
374
375#endif // LS_LICENSE_HANDLER_H
#define LS_API
Macros that expands to dllexport, dllimport or nothing on non Windows platforms or in case of static ...
Definition APIDef.h:22
DeviceIDAlgorithm
Type of Device ID algorithm used by the SDK.
Definition PODTypes.h:108
LSErrorCode
LicenseSpring Error codes enum.
Definition PODTypes.h:48
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)
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:19
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:19
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:29
Helper struct for filtering installation files by environment and channel.