| 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
26 class LS_API LicenseHandler
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;
43 LicenseHandler& operator=( const LicenseHandler& ) = delete;
45 ~LicenseHandler();
46
48 void reconfigure( Configuration::ptr_t config, LicenseStorage::ptr_t storage = nullptr );
50 Configuration::ptr_t currentConfig() const;
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;
68 ProductDetails::ptr_t getProductDetails() 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 );
93 bool deactivateLicense();
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() );
100 InstallationFile::ptr_t checkLicense( const InstallFileFilter& filter = InstallFileFilter() );
102 const std::vector<std::string>& getVersionList( const LicenseID& licenseID = LicenseID(),
103 const InstallFileFilter& filter = InstallFileFilter() );
105 InstallationFile::ptr_t getInstallFile( const LicenseID& licenseID = LicenseID(),
106 const std::string& version = std::string(),
107 const InstallFileFilter& filter = InstallFileFilter() );
109 void sendDeviceVariables();
111 std::vector<DeviceVariable> getDeviceVariables( bool getFromBackend = false );
113 void syncConsumption( int32_t requestOverage = -1 );
115 void syncFeatureConsumption( const std::string& featureCode = std::string() );
117 void registerFloatingLicense();
119 void borrowFloatingLicense( uint32_t hours, uint32_t days = 0 );
121 void borrowFloatingLicense( const std::string& borrowEndDateTime = std::string() );
123 void releaseFloatingLicense();
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 );
134 void checkLicenseLocal();
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 );
154 void resumeLicenseWatchdog();
156 void stopLicenseWatchdog();
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;
196 bool isLicenseMaintenanceExpired() const;
198 bool isLicenseOfflineActivated() const;
200 bool isLicenseFloating() const;
202 bool isLicenseBorrowed() const;
204 bool isLicenseOveragesAllowed() const;
206 bool isLicenseUnlimitedConsumptionAllowed() const;
208 bool isLicenseVMAllowed() const;
210 bool isSubscriptionGracePeriodStarted() const;
212 bool isGracePeriodStarted() const;
214 tm gracePeriodEndDateTime() const;
216 tm gracePeriodEndDateTimeUTC() const;
218 int gracePeriodHoursRemaining() 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
234 LicenseType getLicenseType() const;
235
237 tm getLicenseExpiryDate() const;
239 tm getLicenseExpiryDateUtc() const;
241 tm getLicenseMaintenancePeriod() const;
243 tm getLicenseMaintenancePeriodUtc() const;
245 tm getLicenseLastCheckDate() const;
247 tm getLicenseLastCheckDateUtc() const;
249 tm getLicenseFloatingEndDateTime() const;
251 tm getLicenseFloatingEndDateTimeUtc() const;
253 int getDaysRemaining() const;
255 int getMaintenanceDaysRemaining() const;
257 int getDaysPassedSinceLastCheck() const;
258
260 uint32_t getSubscriptionLicenseGracePeriod() const;
262 tm validityWithGracePeriod() const;
264 tm validityWithGracePeriodUtc() const;
265
267 const Customer& getLicenseOwner() const;
269 LicenseUser::ptr_t getLicenseUserPtr() const;
270
271 bool hasLicenseFeatures() const;
273 const LicenseFeature& getLicenseFeature( const std::string& featureCode ) const;
275 const std::vector<LicenseFeature>& getLicenseFeatures() const;
276
277 bool hasLicenseCustomFields() const;
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;
298 bool isResetLicenseConsumptionEnabled() const;
299 ConsumptionPeriod getLicenseConsumptionPeriod() const;
300
301 // Meaningful only for Floating license
303 uint32_t getLicenseFloatingTimeout() const;
305 uint32_t getLicenseFloatingInUseCount() 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;
316 LSErrorCode getLastError() 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;
324 bool isLicenseNotFoundError() 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
LSErrorCode
LSErrorCode
LicenseSpring Error codes enum.
Definition: PODTypes.h:47
LicenseSpring
Definition: BaseManager.h:15
LicenseSpring::Configuration::ptr_t
std::shared_ptr< Configuration > ptr_t
Definition: Configuration.h:20
LicenseSpring::LicenseStorage::ptr_t
std::shared_ptr< LicenseStorage > ptr_t
Definition: LicenseStorage.h:19
LicenseSpring::DeviceVariable
Class for storing key-value device variable.
Definition: DeviceVariable.h:18
LicenseSpring::ConsumptionPeriod
Class used for encapsulating LSConsumptionPeriod and converting cosumption period to/from string...
Definition: ConsumptionPeriod.h:10
LicenseSpring::CustomField
Class for storing key-value data field.
Definition: CustomField.h:17
LicenseStorage.h
LicenseSpring::LicenseType
Class used for encapsulating the type of license, comparing types of licenses, and converting them to...
Definition: LicenseType.h:18
LicenseSpring::Customer
Class that encapsulates information about a customer.
Definition: Customer.h:17
LicenseSpring::LicenseFeature
Class that encapsulates information about license feature.
Definition: LicenseFeature.h:20
LicenseSpring::LicenseWatchdogCallback
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
LicenseSpring::LicenseUser::ptr_t
std::shared_ptr< LicenseUser > ptr_t
Definition: LicenseUser.h:21
CryptoProvider.h
DeviceIDAlgorithm
DeviceIDAlgorithm
Type of Device ID algorithm used by the SDK.
Definition: PODTypes.h:100
ProductDetails.h
LicenseSpring::ProductDetails::ptr_t
std::shared_ptr< ProductDetails > ptr_t
Definition: ProductDetails.h:22
License.h
LicenseSpring::Customer::ptr_t
std::shared_ptr< Customer > ptr_t
Definition: Customer.h:20
LS_API
#define LS_API
Macros that expands to dllexport, dllimport or nothing on non Windows platforms or in case of static ...
Definition: APIDef.h:22
LicenseSpring::LicenseID
Class that represents License identifier.
Definition: LicenseID.h:18
LicenseSpring::LicenseHandler
This class encapsulates functionality of the both LicenseManager and the License. ...
Definition: LicenseHandler.h:26
Configuration.h
LicenseSpring::InstallationFile::ptr_t
std::shared_ptr< InstallationFile > ptr_t
Definition: InstallationFile.h:54
LicenseSpring::InstallFileFilter
Helper struct for filtering installation files by environment and channel.
Definition: InstallationFile.h:18