LicenseSpring C++ SDK  7.27.0
Easily add Software Licensing to your application
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 "License.h"
11 #include "LicenseStorage.h"
12 #include "CryptoProvider.h"
13 
14 namespace LicenseSpring
15 {
16  class LicenseHandlerImpl;
17 
27  {
28  public:
29 
36  static LicenseHandler& instance( bool globalInit = false );
37 
41  LicenseHandler( Configuration::ptr_t config = nullptr, LicenseStorage::ptr_t storage = nullptr );
42  LicenseHandler( const LicenseHandler& ) = delete;
46 
48  void reconfigure( Configuration::ptr_t config, LicenseStorage::ptr_t storage = nullptr );
51 
53  const std::wstring& dataLocation() const;
55  void setDataLocation( const std::wstring& path );
57  std::wstring licenseFileName() const;
59  void setLicenseFileName( const std::wstring& name );
61  std::wstring licenseFilePath() const;
62 
63  // ---------- Requests to the LicenseSpring backend ----------
64 
66  bool isOnline() const;
70  const LicenseID& getTrialLicense( Customer::ptr_t user = nullptr,
71  const std::string& licensePolicy = std::string() ) const;
73  const LicenseID& getTrialLicense( const std::string& userEmail ) const;
75  const std::string& getSSOUrl( const std::string& accountCode = std::string(), bool useAuthCode = true );
77  const std::string& getAirGapActivationCode( const std::string& initializationCode, const std::string& licenseKey );
79  const std::string& getAirGapDeactivationCode( const std::string& initializationCode );
81  void activateAirGapLicense( const std::string& confirmationCode, const std::wstring& activationResponseFile, const std::string& licenseKey, uint32_t policyId );
83  void deactivateAirGapLicense( const std::string& confirmationCode );
85  std::vector<LicenseUser::ptr_t> getLicenseUsers( const Customer& customer );
87  std::vector<LicenseUser::ptr_t> getLicenseUsers( const std::string& customerEmail );
89  void activateLicense( const LicenseID& licenseID );
91  void activateLicense( const std::string& authData, const std::string& accountCode = std::string(), bool useAuthCode = true );
95  bool changePassword( const std::string& password, const std::string& newPassword,
96  const std::string& user = std::string() );
98  void relinkLicense( DeviceIDAlgorithm deviceIdAlgorithm, const std::string& userPassword = std::string() );
102  const std::vector<std::string>& getVersionList( const LicenseID& licenseID = LicenseID(),
103  const InstallFileFilter& filter = InstallFileFilter() );
106  const std::string& version = std::string(),
107  const InstallFileFilter& filter = InstallFileFilter() );
111  std::vector<DeviceVariable> getDeviceVariables( bool getFromBackend = false );
113  void syncConsumption( int32_t requestOverage = -1 );
115  void syncFeatureConsumption( const std::string& featureCode = std::string() );
119  void borrowFloatingLicense( uint32_t hours, uint32_t days = 0 );
121  void borrowFloatingLicense( const std::string& borrowEndDateTime = std::string() );
124  // ------------------------------------------------------------
125 
126  // -------- Local license management and helper methods -------
127  bool isInitialized() const;
128  bool isLicenseExists() const;
130  void updateConsumption( int32_t value = 1, bool saveLicense = true );
132  void updateFeatureConsumption( const std::string& featureCode, int32_t value = 1, bool saveLicense = true );
136  void clearLocalStorage(); // remove local license and also all license information from memory
137 
139  void addUserData( const CustomField& data, bool saveLicense = true );
141  void removeUserData( const std::string& key = std::string(), bool saveLicense = true );
143  const std::vector<CustomField>& userData();
145  std::string userData( const std::string& key );
146 
148  bool isAutoReleaseSet() const;
150  void setAutoRelease( bool autoRelease );
152  void setupLicenseWatchdog( LicenseWatchdogCallback callback, uint32_t timeout = 0 );
157 
159  void addDeviceVariable( const std::string& name, const std::string& value, bool saveLicense = true );
161  void addDeviceVariable( const DeviceVariable& variable, bool saveLicense = true );
163  void addDeviceVariables( const std::vector<DeviceVariable>& variables );
165  DeviceVariable deviceVariable( const std::string& name ) const;
167  const std::string& deviceVariableValue( const std::string& name ) const;
168  // ------------------------------------------------------------
169 
170  // ---------------- Offline license management ----------------
172  const std::wstring& createOfflineActivationFile( const LicenseID& licenseID,
173  const std::wstring& activationRequestFile = std::wstring() );
175  void activateLicenseOffline( const std::wstring& activationResponseFile = std::wstring() );
177  const std::wstring& deactivateLicenseOffline( const std::wstring& deactivationRequestFile = std::wstring() );
179  bool updateOffline( const std::wstring& path = std::wstring(), bool resetConsumption = false );
180  // ------------------------------------------------------------
181 
182  // ----------------------- License data -----------------------
184  bool isLicenseValid() const;
186  bool isLicenseTrial() const;
188  bool isLicenseAirGapped() const;
190  bool isLicenseActive() const;
192  bool isLicenseEnabled() const;
194  bool isLicenseExpired() const;
200  bool isLicenseFloating() const;
202  bool isLicenseBorrowed() const;
208  bool isLicenseVMAllowed() const;
212  bool isGracePeriodStarted() const;
219 
221  const LicenseID& getLicenseID() const;
223  const std::string& getLicenseKey() const;
225  const std::string& getLicenseUser() const;
227  const std::string& getLicenseStatusStr() const;
229  const std::string& getLicenseStartDate() const;
231  const std::string& getLicenseMetadata() const;
232 
235 
253  int getDaysRemaining() const;
258 
265 
267  const Customer& getLicenseOwner() const;
270 
271  bool hasLicenseFeatures() const;
273  const LicenseFeature& getLicenseFeature( const std::string& featureCode ) const;
275  const std::vector<LicenseFeature>& getLicenseFeatures() const;
276 
279  const std::vector<CustomField>& getLicenseCustomFields() const;
280 
282  uint32_t getLicenseTimesActivated() const;
284  uint32_t getLicenseMaxActivations() const;
286  uint32_t getLicenseTransferCount() const;
287 
289  uint32_t getLicensePolicyId() const;
290 
291  // Meaningful only for Consumption license
293  int32_t getLicenseTotalConsumption() const;
295  int32_t getLicenseMaxConsumption() const;
297  int32_t getLicenseMaxOverages() const;
300 
301  // Meaningful only for Floating license
303  uint32_t getLicenseFloatingTimeout() const;
307  uint32_t getLicenseMaxFloatingUsers() const;
309  uint32_t getMaxBorrowTime() const;
310  // ------------------------------------------------------------
311 
312  // ---------------------- Error handling ----------------------
313  void enableExceptions( bool enable ); // By default this class does not throw exceptions
314  bool isExceptionsEnabled() const;
315  bool wasError() const;
317  const std::string& getLastErrorMsg() const;
318  bool isInitializationError() const;
319  bool isInternalServerError() const;
320  bool isNetworkTimeoutError() const;
321  bool isNoInternetError() const;
322  bool isActivationFailed() const;
323  bool isLicenseExpiredError() const;
325  bool isLicenseStateError() const;
326  bool isHardwareIDError() const;
327  bool isGeneralError() const;
328  bool isLicenseFeatureError() const;
329  bool canIgnoreError() const; // No Internet, network timeout and server errors can be ignored
330  // ------------------------------------------------------------
331 
332  private:
333  LicenseHandlerImpl* m_impl;
334  };
335 
336 } // namespace LicenseSpirng
337 
338 #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:101
LSErrorCode
LicenseSpring Error codes enum.
Definition: PODTypes.h:48
std::shared_ptr< Configuration > ptr_t
Definition: Configuration.h:20
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. .
static LicenseHandler & instance(bool globalInit=false)
Get singleton object of LicenseHandler.
void removeUserData(const std::string &key=std::string(), bool saveLicense=true)
const std::string & getLicenseMetadata() const
tm getLicenseFloatingEndDateTimeUtc() const
void syncConsumption(int32_t requestOverage=-1)
const std::string & getLicenseStartDate() const
bool updateOffline(const std::wstring &path=std::wstring(), bool resetConsumption=false)
const LicenseFeature & getLicenseFeature(const std::string &featureCode) const
void syncFeatureConsumption(const std::string &featureCode=std::string())
~LicenseHandler()
Destructor for LicenseHandler.
InstallationFile::ptr_t getInstallFile(const LicenseID &licenseID=LicenseID(), const std::string &version=std::string(), const InstallFileFilter &filter=InstallFileFilter())
void reconfigure(Configuration::ptr_t config, LicenseStorage::ptr_t storage=nullptr)
int32_t getLicenseMaxConsumption() const
int32_t getLicenseMaxOverages() const
uint32_t getLicenseMaxActivations() const
int32_t getLicenseTotalConsumption() const
std::string userData(const std::string &key)
std::wstring licenseFileName() const
std::wstring licenseFilePath() const
void setAutoRelease(bool autoRelease)
const std::string & getLicenseKey() const
ProductDetails::ptr_t getProductDetails() const
void activateLicense(const LicenseID &licenseID)
bool changePassword(const std::string &password, const std::string &newPassword, const std::string &user=std::string())
const Customer & getLicenseOwner() const
std::vector< LicenseUser::ptr_t > getLicenseUsers(const std::string &customerEmail)
bool isLicenseUnlimitedConsumptionAllowed() const
tm getLicenseMaintenancePeriodUtc() const
void relinkLicense(DeviceIDAlgorithm deviceIdAlgorithm, const std::string &userPassword=std::string())
LicenseUser::ptr_t getLicenseUserPtr() const
const LicenseID & getTrialLicense(const std::string &userEmail) const
tm getLicenseFloatingEndDateTime() const
LSErrorCode getLastError() const
void updateFeatureConsumption(const std::string &featureCode, int32_t value=1, bool saveLicense=true)
uint32_t getLicenseTimesActivated() const
bool isResetLicenseConsumptionEnabled() const
void setLicenseFileName(const std::wstring &name)
void activateAirGapLicense(const std::string &confirmationCode, const std::wstring &activationResponseFile, const std::string &licenseKey, uint32_t policyId)
void enableExceptions(bool enable)
const std::wstring & createOfflineActivationFile(const LicenseID &licenseID, const std::wstring &activationRequestFile=std::wstring())
const std::vector< CustomField > & getLicenseCustomFields() const
void addUserData(const CustomField &data, bool saveLicense=true)
const std::vector< CustomField > & userData()
uint32_t getLicenseTransferCount() const
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)
const std::wstring & dataLocation() const
void borrowFloatingLicense(uint32_t hours, uint32_t days=0)
const std::string & getLastErrorMsg() const
const std::string & deviceVariableValue(const std::string &name) const
bool isLicenseOveragesAllowed() const
InstallationFile::ptr_t checkLicense(const InstallFileFilter &filter=InstallFileFilter())
LicenseHandler(const LicenseHandler &)=delete
uint32_t getLicenseFloatingInUseCount() const
const std::string & getLicenseUser() const
void addDeviceVariables(const std::vector< DeviceVariable > &variables)
const LicenseID & getTrialLicense(Customer::ptr_t user=nullptr, const std::string &licensePolicy=std::string()) const
LicenseType getLicenseType() const
Configuration::ptr_t currentConfig() const
void activateLicenseOffline(const std::wstring &activationResponseFile=std::wstring())
ConsumptionPeriod getLicenseConsumptionPeriod() const
const std::string & getLicenseStatusStr() const
DeviceVariable deviceVariable(const std::string &name) const
const LicenseID & getLicenseID() const
LicenseHandler(Configuration::ptr_t config=nullptr, LicenseStorage::ptr_t storage=nullptr)
Constructor for LicenseHandler.
uint32_t getLicenseMaxFloatingUsers() const
int getMaintenanceDaysRemaining() const
const std::string & getSSOUrl(const std::string &accountCode=std::string(), bool useAuthCode=true)
LicenseHandler & operator=(const LicenseHandler &)=delete
const std::vector< LicenseFeature > & getLicenseFeatures() const
const std::string & getAirGapActivationCode(const std::string &initializationCode, const std::string &licenseKey)
bool isLicenseOfflineActivated() const
void deactivateAirGapLicense(const std::string &confirmationCode)
void setDataLocation(const std::wstring &path)
const std::string & getAirGapDeactivationCode(const std::string &initializationCode)
int getDaysPassedSinceLastCheck() const
uint32_t getLicensePolicyId() const
const std::vector< std::string > & getVersionList(const LicenseID &licenseID=LicenseID(), const InstallFileFilter &filter=InstallFileFilter())
bool isLicenseMaintenanceExpired() const
uint32_t getLicenseFloatingTimeout() const
std::vector< LicenseUser::ptr_t > getLicenseUsers(const Customer &customer)
uint32_t getMaxBorrowTime() const
void updateConsumption(int32_t value=1, bool saveLicense=true)
void addDeviceVariable(const std::string &name, const std::string &value, bool saveLicense=true)
std::vector< DeviceVariable > getDeviceVariables(bool getFromBackend=false)
const std::wstring & deactivateLicenseOffline(const std::wstring &deactivationRequestFile=std::wstring())
bool isSubscriptionGracePeriodStarted() 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.