LicenseSpring C++ SDK
Easily add Software Licensing to your application
Loading...
Searching...
No Matches
License.h
Go to the documentation of this file.
1#ifndef LS_LICENSE_H
2#define LS_LICENSE_H
3
4#ifdef _MSC_VER
5#pragma once
6#pragma warning( push )
7#pragma warning( disable : 4251 )
8#endif
9
10#include <vector>
11#include <functional>
12#include "LicenseType.h"
13#include "CustomField.h"
14#include "InstallationFile.h"
15#include "LicenseID.h"
16#include "LicenseFeature.h"
17#include "DeviceVariable.h"
18#include "Customer.h"
19#include "ProductDetails.h"
20#include "LicenseUser.h"
21#include "Exceptions.h"
22
23#pragma push_macro("check") // Workaround for Unreal Engine
24#undef check
25
26namespace LicenseSpring
27{
29 using LicenseWatchdogCallback = std::function<void( const LicenseSpringException& ex )>;
30
34 {
35 public:
36 using ptr_t = std::shared_ptr<License>;
37
39 virtual ~License() {};
40
43 virtual const LicenseID& id() const = 0;
44
47 virtual const std::string& key() const = 0;
48
51 virtual const std::string& user() const = 0;
52
55 virtual const uint64_t serverId() const = 0;
56
59 virtual LicenseType type() const = 0;
60
63 virtual Customer owner() const = 0;
64
68 virtual LicenseUser::ptr_t licenseUser() const = 0;
69
74 virtual ProductDetails productDetails() const = 0;
75
78 virtual std::string status() const = 0;
79
82 virtual bool isActive() const = 0;
83
86 virtual bool isEnabled() const = 0;
87
90 virtual bool isValid() const = 0;
91
94 virtual bool isTrial() const = 0;
95
98 virtual bool isAirGapped() const = 0;
99
103 virtual uint32_t policyId() const = 0;
104
107 virtual bool isOfflineActivated() const = 0;
108
112 virtual bool isVMAllowed() const = 0;
113
116 virtual bool isFloating() const = 0;
117
121 virtual bool isBorrowed() const = 0;
122
126 virtual bool isSubscriptionGracePeriodStarted() const = 0;
127
130 virtual bool isGracePeriodStarted() const = 0;
131
134 virtual tm gracePeriodEndDateTime() const = 0;
135
138 virtual tm gracePeriodEndDateTimeUTC() const = 0;
139
142 virtual int gracePeriodHoursRemaining() const = 0;
143
147 virtual uint32_t trialPeriod() const = 0;
148
152 virtual uint32_t maxFloatingUsers() const = 0;
153
158 virtual uint32_t floatingInUseCount() const = 0;
159
162 virtual uint32_t floatingTimeout() const = 0;
163
167 virtual const std::string& floatingClientId() const = 0;
168
171 virtual tm validityPeriod() const = 0;
172
175 virtual tm validityPeriodUtc() const = 0;
176
180 virtual tm validityWithGracePeriod() const = 0;
181
185 virtual tm validityWithGracePeriodUtc() const = 0;
186
190 virtual uint32_t subscriptionGracePeriod() const = 0;
191
195 virtual uint32_t maxBorrowTime() const = 0;
196
199 virtual tm maintenancePeriod() const = 0;
200
203 virtual tm maintenancePeriodUtc() const = 0;
204
207 virtual tm lastCheckDate() const = 0;
208
211 virtual tm lastCheckDateUtc() const = 0;
212
216 virtual tm floatingEndDateTime() const = 0;
217
221 virtual tm floatingEndDateTimeUtc() const = 0;
222
226 virtual const std::string& startDate() const = 0;
227
230 virtual const std::string& metadata() const = 0;
231
234 virtual const std::string& orderStoreId() const = 0;
235
240 virtual LicenseFeature feature( const std::string& featureCode ) const = 0;
241
244 virtual std::vector<LicenseFeature> features() const = 0;
245
248 virtual std::vector<CustomField> customFields() const = 0;
249
253 virtual const std::vector<CustomField>& userData() const = 0;
254
259 virtual std::string userData( const std::string& key ) const = 0;
260
266 virtual void addUserData( const CustomField& data, bool saveLicense = true ) = 0;
267
271 virtual void removeUserData( const std::string& key = std::string(), bool saveLicense = true ) = 0;
272
275 virtual int32_t totalConsumption() const = 0;
276
279 virtual int32_t maxConsumption() const = 0;
280
283 virtual int32_t maxOverages() const = 0;
284
287 virtual bool isOveragesAllowed() const = 0;
288
291 virtual bool isUnlimitedConsumptionAllowed() const = 0;
292
295 virtual bool isNegativeConsumptionAllowed() const = 0;
296
300
303 virtual bool isResetConsumptionEnabled() const = 0;
304
307 virtual uint32_t timesActivated() const = 0;
308
311 virtual uint32_t maxActivations() const = 0;
312
315 virtual uint32_t transferCount() const = 0;
316
319 virtual int32_t transferLimit() const = 0;
320
323 virtual bool isDeviceTransferAllowed() const = 0;
324
327 virtual bool isDeviceTransferLimited() const = 0;
328
332 virtual bool isAutoReleaseSet() const = 0;
333
336 virtual void setAutoRelease( bool autoRelease ) = 0;
337
343 virtual void updateConsumption( int32_t value = 1, bool saveLicense = true ) = 0;
344
351 virtual void updateFeatureConsumption( const std::string& featureCode, int32_t value = 1, bool saveLicense = true ) = 0;
352
353 // Local checks
357 virtual bool isExpired() const = 0;
358
361 virtual bool isMaintenancePeriodExpired() const = 0;
362
366 virtual int daysRemainingUtc() const = 0;
367
371 virtual int daysRemaining() const = 0;
372
375 virtual int maintenanceDaysRemaining() const = 0;
376
379 static const int MaxDaysRemainingValue;
380
383 virtual int daysPassedSinceLastCheck() const = 0;
384
395 virtual void localCheck( bool verifySignature = false ) = 0;
396
397 // Requests to LicenseSpring server
398
412 virtual bool deactivate( bool removeLocalData = false ) = 0;
413
418 virtual bool changePassword( const std::string& password, const std::string& newPassword ) = 0; // may throw exceptions
419
433 virtual InstallationFile::ptr_t check( const InstallFileFilter& filter = InstallFileFilter(), bool includeExpiredFeatures = false ) = 0;
434
448 virtual bool syncConsumption( int32_t requestOverage = -1 ) = 0;
449
463 virtual bool syncFeatureConsumption( const std::string& featureCode = std::string() ) = 0;
464
474 virtual void addDeviceVariable( const std::string& name, const std::string& value,
475 bool saveLicense = true ) = 0;
476
483 virtual void addDeviceVariable( const DeviceVariable& variable, bool saveLicense = true ) = 0;
484
488 virtual void addDeviceVariables( const std::vector<DeviceVariable>& variables ) = 0;
489
497 virtual bool sendDeviceVariables() = 0;
498
507 virtual std::vector<DeviceVariable> getDeviceVariables( bool getFromBackend = false ) = 0;
508
512 virtual DeviceVariable deviceVariable( const std::string& name ) const = 0;
513
517 virtual const std::string& deviceVariableValue( const std::string& name ) const = 0;
518
524 virtual void setupLicenseWatchdog( LicenseWatchdogCallback callback, uint32_t timeout = 0 ) = 0;
525
529 virtual void resumeLicenseWatchdog() = 0;
530
533 virtual void stopLicenseWatchdog() = 0;
534
539 virtual void setupFeatureWatchdog(LicenseWatchdogCallback callback, uint32_t timeout = 0 ) = 0;
540
544 virtual void resumeFeatureWatchdog() = 0;
545
548 virtual void stopFeatureWatchdog() = 0;
549
555 virtual void registerFloatingLicense() = 0;
556
565 virtual void releaseFloatingLicense( bool throwExceptions = false ) = 0;
566
578 virtual void borrow( uint32_t hours, uint32_t days = 0 ) = 0;
579
590 virtual void borrow( const std::string& borrowEndDateTime = std::string() ) = 0;
591
595 virtual std::wstring deactivateOffline( const std::wstring& deactivationRequestFile = std::wstring() ) = 0;
596
605 virtual bool updateOffline( const std::wstring& path, bool resetConsumption = false ) = 0;
606
611 virtual void unlinkFromDevice() = 0;
612
616 virtual std::string getAirGapDeactivationCode( const std::string& initializationCode ) = 0;
617
621 virtual void deactivateAirGap( const std::string& confirmationCode ) = 0;
622
625 virtual bool isLicenseBelongsToThisDevice( DeviceIDAlgorithm deviceIDAlgorithm ) = 0;
626
629
635 virtual void registerFloatingFeature( const std::string& featureCode, bool addToWatchdog = true ) = 0;
636
643 virtual void releaseFloatingFeature( const std::string& featureCode ) = 0;
644 };
645
647 std::string LS_API TmToString( const tm& dateTime, const std::string& format = std::string( "%d-%m-%Y" ) );
648
649} // namespace LicenseSpring
650
651#pragma pop_macro("check")
652
653#ifdef _MSC_VER
654#pragma warning( pop )
655#endif
656
657#endif // LS_LICENSE_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
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
Class for storing key-value device variable.
std::shared_ptr< InstallationFile > ptr_t
Class that encapsulates information about license feature.
Class that encapsulates license information.
Definition License.h:34
virtual void deactivateAirGap(const std::string &confirmationCode)=0
Verify Confirmation code and deactivate air gap license.
virtual bool isVMAllowed() const =0
Checker for whether the license is allowed to work under virtual machine or not.
virtual tm validityPeriod() const =0
Getter for license validity period in local time.
virtual const std::string & deviceVariableValue(const std::string &name) const =0
Get device variable value by name.
virtual uint32_t subscriptionGracePeriod() const =0
Getter for grace period of the Subscription license in hours.
virtual bool isBorrowed() const =0
Checker for whether the license is borrowed.
virtual Customer owner() const =0
Getter for license owner.
virtual int gracePeriodHoursRemaining() const =0
How many hours remaining till grace period ends.
virtual int32_t totalConsumption() const =0
Returns license current total consumption.
virtual bool checkLicenseBelongsToThisDevice()=0
Checks if license belongs to any of the DeviceIDAlgorithm values.
virtual void releaseFloatingFeature(const std::string &featureCode)=0
Release a floating feature and free a floating slot.
virtual void setupLicenseWatchdog(LicenseWatchdogCallback callback, uint32_t timeout=0)=0
Setup and run license watchdog, a background thread which periodically checks the license.
virtual void borrow(const std::string &borrowEndDateTime=std::string())=0
Borrow floating license till provided end date time.
virtual tm maintenancePeriod() const =0
Getter for license maintenance period in local time.
virtual void registerFloatingFeature(const std::string &featureCode, bool addToWatchdog=true)=0
Register a floating feature and occupy a floating slot.
virtual tm lastCheckDateUtc() const =0
Getter for license last check date in UTC.
std::shared_ptr< License > ptr_t
Definition License.h:36
virtual uint32_t maxBorrowTime() const =0
Maximum borrowing period in hours.
virtual void addDeviceVariable(const std::string &name, const std::string &value, bool saveLicense=true)=0
Add new or update existing device variable to license daata.
virtual tm validityPeriodUtc() const =0
Getter for license validity period in UTC.
virtual void releaseFloatingLicense(bool throwExceptions=false)=0
Revoke floating license, typically should be called at the end of app execution.
virtual bool isMaintenancePeriodExpired() const =0
Compare system date time with maintenance period time.
virtual LicenseUser::ptr_t licenseUser() const =0
Getter for license user, it's a person assigned to the license.
virtual void localCheck(bool verifySignature=false)=0
Check license local without connection to the backend.
virtual uint32_t maxFloatingUsers() const =0
Getter for max simultaneous license users (devices or instances).
virtual bool isActive() const =0
Checker for if the license is active.
virtual tm floatingEndDateTimeUtc() const =0
Floating license validity end date time in UTC.
virtual std::vector< CustomField > customFields() const =0
Getter for list of custom fields associated with the license.
virtual uint32_t floatingTimeout() const =0
Getter for timeout of the floating license in minutes.
virtual const LicenseID & id() const =0
Getter for license ID.
virtual uint32_t maxActivations() const =0
How many times license can be activated.
virtual void updateFeatureConsumption(const std::string &featureCode, int32_t value=1, bool saveLicense=true)=0
Increase or decrease feature consumption by given value.
virtual void updateConsumption(int32_t value=1, bool saveLicense=true)=0
Increase or decrease license consumption by given value.
virtual bool isOveragesAllowed() const =0
Checks if overage is allowed for Consumption license.
virtual bool isDeviceTransferLimited() const =0
Checks if the license allows only limited number of transfers between devices.
virtual void stopFeatureWatchdog()=0
Stops feature watchdog background thread.
virtual ConsumptionPeriod consumptionPeriod() const =0
Returns period of time after which consumption is reset.
virtual bool syncFeatureConsumption(const std::string &featureCode=std::string())=0
Sync Consumption Feature(s) with the backend, if code not provided sync all consumption features.
virtual void unlinkFromDevice()=0
Unlinks license from cuurent device ID.
virtual bool updateOffline(const std::wstring &path, bool resetConsumption=false)=0
Update license data accordingly to provided file.
virtual void addDeviceVariable(const DeviceVariable &variable, bool saveLicense=true)=0
Add new or update existing device variable to license daata.
virtual uint32_t policyId() const =0
Policy id of the license.
virtual void stopLicenseWatchdog()=0
Stops license watchdog background thread.
virtual void setAutoRelease(bool autoRelease)=0
Sets auto release flag. Meaningful only for floating license.
virtual ProductDetails productDetails() const =0
Getter for product details.
virtual tm validityWithGracePeriod() const =0
Getter for license validity period including grace period in local time.
virtual bool isOfflineActivated() const =0
Checker for if license is offline activated.
virtual tm maintenancePeriodUtc() const =0
Getter for license maintenance period in UTC.
virtual bool sendDeviceVariables()=0
Send current device variables list to the backend (see device variables on the platform)
virtual void registerFloatingLicense()=0
Register floating license using floatingClientId.
virtual tm lastCheckDate() const =0
Getter for license last check date in local time.
virtual uint32_t timesActivated() const =0
How many times license already been activated.
virtual const std::string & metadata() const =0
Getter for license metadata.
virtual const std::string & key() const =0
Getter for license key.
virtual std::string getAirGapDeactivationCode(const std::string &initializationCode)=0
Get air gap Deactivation code.
static const int MaxDaysRemainingValue
Maximum value for daysRemaining, e.g. in case of perpetual license.
Definition License.h:379
virtual bool isExpired() const =0
Compare system date time with license validity date time.
virtual int32_t maxConsumption() const =0
Returns license maximum consumption.
virtual bool isEnabled() const =0
Checker for if the license is enabled.
virtual LicenseFeature feature(const std::string &featureCode) const =0
Getter method for license feature.
virtual std::string status() const =0
Getter for license status.
virtual std::wstring deactivateOffline(const std::wstring &deactivationRequestFile=std::wstring())=0
Creates offline deactivation file request.
virtual bool isLicenseBelongsToThisDevice(DeviceIDAlgorithm deviceIDAlgorithm)=0
Checks if license belongs to this DeviceIDAlgorithm.
virtual bool changePassword(const std::string &password, const std::string &newPassword)=0
Change password for user based license.
virtual LicenseType type() const =0
Getter for license type.
virtual bool isSubscriptionGracePeriodStarted() const =0
Check if grace period started for subscription license.
virtual void resumeLicenseWatchdog()=0
Resume background thread, you can call this within your callback in order to resume periodic license ...
virtual bool isGracePeriodStarted() const =0
Check if grace period started for a license.
virtual const std::string & startDate() const =0
Getter method license start date.
virtual std::vector< DeviceVariable > getDeviceVariables(bool getFromBackend=false)=0
Get device variables from the local license or from the backend.
virtual void resumeFeatureWatchdog()=0
Resume background thread, you can call this within your callback in order to resume periodic feature ...
virtual int daysRemaining() const =0
Almost the same as UTC counterpart, but days counter will be changed on local midnight.
virtual uint32_t floatingInUseCount() const =0
Getter for current floatings slots in use count, including this user (instance).
virtual bool isAirGapped() const =0
Checker for if the license is air gapped.
virtual bool isFloating() const =0
Checker for whether the license is floating or not.
virtual tm validityWithGracePeriodUtc() const =0
Getter for license validity period including grace period in UTC.
virtual bool isUnlimitedConsumptionAllowed() const =0
Checks if unlimited consumption is allowed for Consumption license.
virtual bool isNegativeConsumptionAllowed() const =0
Checks if negative consumption is allowed for Consumption license.
virtual int32_t maxOverages() const =0
Returns maximum overage allowed for the license.
virtual int maintenanceDaysRemaining() const =0
How many days remaining till end of maintenance days.
virtual ~License()
Destructor for license.
Definition License.h:39
virtual const uint64_t serverId() const =0
Getter for server-side license id.
virtual int32_t transferLimit() const =0
Maximum number of allowed license transfers between devices.
virtual int daysPassedSinceLastCheck() const =0
How many days passed from last online check.
virtual tm gracePeriodEndDateTime() const =0
Getter for grace period end date time in local time.
virtual bool syncConsumption(int32_t requestOverage=-1)=0
Sync Consumption license with the server.
virtual bool isValid() const =0
Checker for if the license is valid.
virtual void addDeviceVariables(const std::vector< DeviceVariable > &variables)=0
Add new or update existing device variables to license daata.
virtual bool isAutoReleaseSet() const =0
Returns auto release flag. Meaningful only for floating license.
virtual bool isTrial() const =0
Checker for if the license is a trial.
virtual bool isDeviceTransferAllowed() const =0
Checks if license can be transferred between devices.
virtual bool isResetConsumptionEnabled() const =0
Checks if consumption reset is allowed for Consumption license.
virtual const std::string & floatingClientId() const =0
Getter for floating user (client) or instance id.
virtual void borrow(uint32_t hours, uint32_t days=0)=0
Borrow floating license for provided time interval.
virtual tm gracePeriodEndDateTimeUTC() const =0
Getter for grace period end date time in UTC.
virtual void setupFeatureWatchdog(LicenseWatchdogCallback callback, uint32_t timeout=0)=0
Setup and run feature watchdog, a background thread which periodically checks floating license featur...
virtual const std::vector< CustomField > & userData() const =0
Returns user data stored within license object.
virtual void addUserData(const CustomField &data, bool saveLicense=true)=0
Adds user data to the license object. This method allows you to store custom data securely inside lic...
virtual int daysRemainingUtc() const =0
How many days remaining till license expires.
virtual bool deactivate(bool removeLocalData=false)=0
Sends deactivate license request to the backend.
virtual uint32_t trialPeriod() const =0
Trial duration of current license.
virtual void removeUserData(const std::string &key=std::string(), bool saveLicense=true)=0
Removes user data from the license.
virtual tm floatingEndDateTime() const =0
Getter for floating license validity end date time in local time zone.
virtual std::vector< LicenseFeature > features() const =0
Getter for list of license features associated with the license.
virtual uint32_t transferCount() const =0
How many times license has been transferred between devices.
virtual InstallationFile::ptr_t check(const InstallFileFilter &filter=InstallFileFilter(), bool includeExpiredFeatures=false)=0
Online license check, sync the license with the backend, throws exceptions in case of errors.
virtual const std::string & orderStoreId() const =0
Getter for order store ID.
virtual DeviceVariable deviceVariable(const std::string &name) const =0
Get device variable by name.
virtual std::string userData(const std::string &key) const =0
Getter for user data by given key.
virtual const std::string & user() const =0
Getter for user.
Class that represents License identifier.
Definition LicenseID.h:19
Base class for all LicenseSpring exceptions.
Definition Exceptions.h:19
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
Class that encapsulates information about a product.
std::string LS_API TmToString(const tm &dateTime, const std::string &format=std::string("%d-%m-%Y"))
Helper function, converts datetime to string using given format. See strftime reference for format de...
constexpr Char encrypt_character(const Char character, int index)
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.