LicenseSpring C++ SDK
Easily add Software Licensing to your application
LicenseFileStorage.h
Go to the documentation of this file.
1#ifndef LS_LICENSE_FILE_STORAGE_H
2#define LS_LICENSE_FILE_STORAGE_H
3
4#ifdef _MSC_VER
5#pragma once
6#pragma warning(push)
7#pragma warning(disable : 4251)
8#endif
9
10#include <mutex>
11#include <string>
12#include "LicenseStorage.h"
13
14namespace boost
15{
16namespace interprocess
17{
18class permissions;
19}
20} // namespace boost
21
22namespace LicenseSpring
23{
28{
29public:
30 using ptr_t = std::shared_ptr<LicenseFileStorageBase>;
31
37 static ptr_t create(const std::wstring &licensePath = std::wstring());
38
41 LicenseFileStorageBase(const std::wstring &licensePath = std::wstring());
42
45 void saveLicense(const std::string &data) override;
46
49 std::string loadLicense() override;
50
52 void clear() override;
53
57 void setLicenseFileName(const std::wstring &name);
58
61 void setLicenseFolderPath(const std::wstring &path);
62
66 const std::wstring &licenseFileName() const;
67
70 const std::wstring &licenseFolderPath() const;
71
74 std::wstring licenseFilePath() const;
75
76protected:
77 std::wstring m_folderPath;
78 std::wstring m_fileName;
79
82 std::wstring prepareRead() const;
83
87 std::wstring prepareWrite() const;
88
92 std::string readLicense(const std::wstring &filePath) const;
93
97 void writeLicense(const std::wstring &filePath, const std::string &data) const;
98};
99
103{
104public:
105 using ptr_t = std::shared_ptr<LicenseFileStorage>;
106
112 static ptr_t create(const std::wstring &licensePath = std::wstring());
113
116 LicenseFileStorage(const std::wstring &licensePath = std::wstring());
117
120 void saveLicense(const std::string &data) override;
121
124 std::string loadLicense() override;
125
127 void clear() override;
128
129private:
130 std::mutex m_mutex;
131};
132
138{
139public:
140 using ptr_t = std::shared_ptr<LicenseFileStorageEx>;
141
148 static ptr_t create(
149 const std::string &appName, const std::wstring &licensePath = std::wstring());
150
155 const std::string &appName, const std::wstring &licensePath = std::wstring());
156
159
162 void saveLicense(const std::string &data) override;
163
166 std::string loadLicense() override;
167
169 void clear() override;
170
171 //-------- Named mutex management --------
172
175 void setPermissionsUnix(int permissions);
176
181 void setPermissionsWin(void *permissions);
182
185
190
195 uint32_t lockTimeout() const;
196
199 void setLockTimeout(uint32_t timeout);
200
201private:
202 std::string m_name;
203 uint32_t m_lockTimeout;
204 boost::interprocess::permissions *m_perm;
205};
206
212{
213public:
214 using ptr_t = std::shared_ptr<FileStorageWithLock>;
215
221 static ptr_t create(const std::wstring &licensePath = std::wstring());
222
225 FileStorageWithLock(const std::wstring &licensePath = std::wstring());
226
229 void saveLicense(const std::string &data) override;
230
233 std::string loadLicense() override;
234
236 void clear() override;
237
241 uint32_t attemptsCount() const;
242
245 void setAttemptsCount(uint32_t count);
246
250 uint32_t waitTimeout() const;
251
254 void setWaitTimeout(uint32_t timeout);
255
256private:
257 uint32_t m_attemptsCount;
258 uint32_t m_waitTimeout;
259};
260} // namespace LicenseSpring
261
262#ifdef _MSC_VER
263#pragma warning(pop)
264#endif
265
266#endif // LS_LICENSE_FILE_STORAGE_H
#define LS_API
Definition: APIDef.h:23
Class that saves license in a file, derived from LicenseFileStorageBase class.
void setAttemptsCount(uint32_t count)
Set file lock operation attempts count.
static ptr_t create(const std::wstring &licensePath=std::wstring())
Allocates and constructs a FileStorageWithLock object and passes args to FileStorageWithLock().
void setWaitTimeout(uint32_t timeout)
Set timeout in milliseconds between file lock attempts.
uint32_t waitTimeout() const
Get timeout in milliseconds between file lock attempts.
void clear() override
Removes local license file.
FileStorageWithLock(const std::wstring &licensePath=std::wstring())
FileStorageWithLock constructor.
void saveLicense(const std::string &data) override
Saves given license data string to the file.
std::string loadLicense() override
Load license from file.
uint32_t attemptsCount() const
Get file lock operation attempts count.
Base class that saves license in a file, implements ILicenseStorage interface.
static ptr_t create(const std::wstring &licensePath=std::wstring())
Allocates and constructs a LicenseFileStorageBase object and passes args to LicenseFileStorageBase().
void clear() override
Removes local license file.
std::string loadLicense() override
Load license from file.
const std::wstring & licenseFolderPath() const
Getter for folder path where License file is being stored.
std::string readLicense(const std::wstring &filePath) const
Reads license from file.
void setLicenseFileName(const std::wstring &name)
Setter for license filename with extension (optional). Default filename is License....
const std::wstring & licenseFileName() const
Getter for license filename with extension (optional).
LicenseFileStorageBase(const std::wstring &licensePath=std::wstring())
Constructor for LicenseFileStorageBase object.
void saveLicense(const std::string &data) override
Saves given license data string to the file.
void setLicenseFolderPath(const std::wstring &path)
Setter for folder path where License file is being stored.
std::wstring licenseFilePath() const
Getter for path to the license file.
std::shared_ptr< LicenseFileStorageBase > ptr_t
void writeLicense(const std::wstring &filePath, const std::string &data) const
Writes given license data string to the file.
std::wstring prepareWrite() const
Prepare to write license file.
std::wstring prepareRead() const
Prepare to read license file.
Class that saves license in a file, derived from LicenseFileStorageBase class.
void setLockTimeout(uint32_t timeout)
Set timeout in milliseconds for trylock.
void setPermissionsUnrestricted()
Sets permissions to unrestricted access: null DACL for windows or 0666 for UNIX.
void setPermissionsUnix(int permissions)
Set platform dependent permission (Unix like systems).
void saveLicense(const std::string &data) override
Saves given license data string to the file.
uint32_t lockTimeout() const
Get trylock timeout in milliseconds.
static ptr_t create(const std::string &appName, const std::wstring &licensePath=std::wstring())
Allocates and constructs a LicenseFileStorageEx object and passes args to LicenseFileStorageEx().
void clear() override
Removes local license file.
void setPermissionsDefault()
Sets permissions to default values: null security attributes pointer for Windows or 0644 for UNIX.
void setPermissionsWin(void *permissions)
Set platform dependent permission (Windows).
std::string loadLicense() override
Load license from file.
~LicenseFileStorageEx() override
Destructor for LicenseFileStorageEx object.
LicenseFileStorageEx(const std::string &appName, const std::wstring &licensePath=std::wstring())
LicenseFileStorageEx constructor.
Class that saves license in a file, derived from LicenseFileStorageBase class.
LicenseFileStorage(const std::wstring &licensePath=std::wstring())
Constructor for LicenseFileStorage object.
void saveLicense(const std::string &data) override
Saves given license data string to the file.
std::string loadLicense() override
Load license from file.
static ptr_t create(const std::wstring &licensePath=std::wstring())
Allocates and constructs a LicenseFileStorage object and passes args to LicenseFileStorage().
void clear() override
Removes local license file.
LicenseStorage interface.