| LicenseSpring C++ SDK 7.32.0 Easily add Software Licensing to your application

Loading...
Searching...
No Matches
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
14 namespace boost { namespace interprocess { class permissions; } }
15
16 namespace LicenseSpring
17{
20 class LS_API LicenseFileStorageBase : public LicenseStorage
21 {
22 public:
23 using ptr_t = std::shared_ptr<LicenseFileStorageBase>;
24
28 static ptr_t create( const std::wstring& licensePath = std::wstring() );
29
32 LicenseFileStorageBase( const std::wstring& licensePath = std::wstring() );
33
36 void saveLicense( const std::string& data ) override;
37
40 std::string loadLicense() override;
41
43 void clear() override;
44
47 void setLicenseFileName( const std::wstring& name );
48
51 void setLicenseFolderPath( const std::wstring& path );
52
56 const std::wstring& licenseFileName() const;
57
60 const std::wstring& licenseFolderPath() const;
61
64 std::wstring licenseFilePath() const;
65
66 protected:
67 std::wstring m_folderPath;
68 std::wstring m_fileName;
69
72 std::wstring prepareRead() const;
73
77 std::wstring prepareWrite() const;
78
82 std::string readLicense( const std::wstring& filePath ) const;
83
87 void writeLicense( const std::wstring& filePath, const std::string& data ) const;
88 };
89
90
93 class LS_API LicenseFileStorage : public LicenseFileStorageBase
94 {
95 public:
96 using ptr_t = std::shared_ptr<LicenseFileStorage>;
97
101 static ptr_t create( const std::wstring& licensePath = std::wstring() );
102
105 LicenseFileStorage( const std::wstring& licensePath = std::wstring() );
106
109 void saveLicense( const std::string& data ) override;
110
113 std::string loadLicense() override;
114
116 void clear() override;
117
118 private:
119 std::mutex m_mutex;
120 };
121
122
126 class LS_API LicenseFileStorageEx : public LicenseFileStorageBase
127 {
128 public:
129 using ptr_t = std::shared_ptr<LicenseFileStorageEx>;
130
135 static ptr_t create( const std::string& appName, const std::wstring& licensePath = std::wstring() );
136
140 LicenseFileStorageEx( const std::string& appName, const std::wstring& licensePath = std::wstring() );
141
143 ~LicenseFileStorageEx() override;
144
147 void saveLicense( const std::string& data ) override;
148
151 std::string loadLicense() override;
152
154 void clear() override;
155
156 //-------- Named mutex management --------
157
160 void setPermissionsUnix( int permissions );
161
165 void setPermissionsWin( void* permissions );
166
168 void setPermissionsUnrestricted();
169
172 void setPermissionsDefault();
173
178 uint32_t lockTimeout() const;
179
182 void setLockTimeout( uint32_t timeout );
183
184 private:
185 std::string m_name;
186 uint32_t m_lockTimeout;
187 boost::interprocess::permissions* m_perm;
188 };
189
190
194 class LS_API FileStorageWithLock : public LicenseFileStorageBase
195 {
196 public:
197 using ptr_t = std::shared_ptr<FileStorageWithLock>;
198
202 static ptr_t create( const std::wstring& licensePath = std::wstring() );
203
206 FileStorageWithLock( const std::wstring& licensePath = std::wstring() );
207
210 void saveLicense( const std::string& data ) override;
211
214 std::string loadLicense() override;
215
217 void clear() override;
218
222 uint32_t attemptsCount() const;
223
226 void setAttemptsCount( uint32_t count );
227
231 uint32_t waitTimeout() const;
232
235 void setWaitTimeout( uint32_t timeout );
236
237 private:
238 uint32_t m_attemptsCount;
239 uint32_t m_waitTimeout;
240 };
241} // namespace LicenseSpirng
242
243#ifdef _MSC_VER
244#pragma warning( pop )
245#endif
246
247#endif // LS_LICENSE_FILE_STORAGE_H
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
LicenseStorage.h
LicenseSpring::FileStorageWithLock
Class that saves license in a file, derived from LicenseFileStorageBase class.
Definition LicenseFileStorage.h:195
LicenseSpring::FileStorageWithLock::setAttemptsCount
void setAttemptsCount(uint32_t count)
Set file lock operation attempts count.
LicenseSpring::FileStorageWithLock::create
static ptr_t create(const std::wstring &licensePath=std::wstring())
Allocates and constructs a FileStorageWithLock object and passes args to FileStorageWithLock().
LicenseSpring::FileStorageWithLock::setWaitTimeout
void setWaitTimeout(uint32_t timeout)
Set timeout in milliseconds between file lock attempts.
LicenseSpring::FileStorageWithLock::waitTimeout
uint32_t waitTimeout() const
Get timeout in milliseconds between file lock attempts.
LicenseSpring::FileStorageWithLock::clear
void clear() override
Removes local license file.
LicenseSpring::FileStorageWithLock::FileStorageWithLock
FileStorageWithLock(const std::wstring &licensePath=std::wstring())
FileStorageWithLock constructor.
LicenseSpring::FileStorageWithLock::saveLicense
void saveLicense(const std::string &data) override
Saves given license data string to the file.
LicenseSpring::FileStorageWithLock::loadLicense
std::string loadLicense() override
Load license from file.
LicenseSpring::FileStorageWithLock::ptr_t
std::shared_ptr< FileStorageWithLock > ptr_t
Definition LicenseFileStorage.h:197
LicenseSpring::FileStorageWithLock::attemptsCount
uint32_t attemptsCount() const
Get file lock operation attempts count.
LicenseSpring::LicenseFileStorageBase
Base class that saves license in a file, implements ILicenseStorage interface.
Definition LicenseFileStorage.h:21
LicenseSpring::LicenseFileStorageBase::m_fileName
std::wstring m_fileName
Definition LicenseFileStorage.h:68
LicenseSpring::LicenseFileStorageBase::create
static ptr_t create(const std::wstring &licensePath=std::wstring())
Allocates and constructs a LicenseFileStorageBase object and passes args to LicenseFileStorageBase().
LicenseSpring::LicenseFileStorageBase::clear
void clear() override
Removes local license file.
LicenseSpring::LicenseFileStorageBase::loadLicense
std::string loadLicense() override
Load license from file.
LicenseSpring::LicenseFileStorageBase::licenseFolderPath
const std::wstring & licenseFolderPath() const
Getter for folder path where License file is being stored.
LicenseSpring::LicenseFileStorageBase::readLicense
std::string readLicense(const std::wstring &filePath) const
Reads license from file.
LicenseSpring::LicenseFileStorageBase::setLicenseFileName
void setLicenseFileName(const std::wstring &name)
Setter for license filename with extension (optional). Default filename is License....
LicenseSpring::LicenseFileStorageBase::licenseFileName
const std::wstring & licenseFileName() const
Getter for license filename with extension (optional).
LicenseSpring::LicenseFileStorageBase::LicenseFileStorageBase
LicenseFileStorageBase(const std::wstring &licensePath=std::wstring())
Constructor for LicenseFileStorageBase object.
LicenseSpring::LicenseFileStorageBase::saveLicense
void saveLicense(const std::string &data) override
Saves given license data string to the file.
LicenseSpring::LicenseFileStorageBase::m_folderPath
std::wstring m_folderPath
Definition LicenseFileStorage.h:67
LicenseSpring::LicenseFileStorageBase::setLicenseFolderPath
void setLicenseFolderPath(const std::wstring &path)
Setter for folder path where License file is being stored.
LicenseSpring::LicenseFileStorageBase::licenseFilePath
std::wstring licenseFilePath() const
Getter for path to the license file.
LicenseSpring::LicenseFileStorageBase::ptr_t
std::shared_ptr< LicenseFileStorageBase > ptr_t
Definition LicenseFileStorage.h:23
LicenseSpring::LicenseFileStorageBase::writeLicense
void writeLicense(const std::wstring &filePath, const std::string &data) const
Writes given license data string to the file.
LicenseSpring::LicenseFileStorageBase::prepareWrite
std::wstring prepareWrite() const
Prepare to write license file.
LicenseSpring::LicenseFileStorageBase::prepareRead
std::wstring prepareRead() const
Prepare to read license file.
LicenseSpring::LicenseFileStorageEx
Class that saves license in a file, derived from LicenseFileStorageBase class.
Definition LicenseFileStorage.h:127
LicenseSpring::LicenseFileStorageEx::ptr_t
std::shared_ptr< LicenseFileStorageEx > ptr_t
Definition LicenseFileStorage.h:129
LicenseSpring::LicenseFileStorageEx::setLockTimeout
void setLockTimeout(uint32_t timeout)
Set timeout in milliseconds for trylock.
LicenseSpring::LicenseFileStorageEx::setPermissionsUnrestricted
void setPermissionsUnrestricted()
Sets permissions to unrestricted access: null DACL for windows or 0666 for UNIX.
LicenseSpring::LicenseFileStorageEx::setPermissionsUnix
void setPermissionsUnix(int permissions)
Set platform dependent permission (Unix like systems).
LicenseSpring::LicenseFileStorageEx::saveLicense
void saveLicense(const std::string &data) override
Saves given license data string to the file.
LicenseSpring::LicenseFileStorageEx::lockTimeout
uint32_t lockTimeout() const
Get trylock timeout in milliseconds.
LicenseSpring::LicenseFileStorageEx::create
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().
LicenseSpring::LicenseFileStorageEx::clear
void clear() override
Removes local license file.
LicenseSpring::LicenseFileStorageEx::setPermissionsDefault
void setPermissionsDefault()
Sets permissions to default values: null security attributes pointer for Windows or 0644 for UNIX.
LicenseSpring::LicenseFileStorageEx::setPermissionsWin
void setPermissionsWin(void *permissions)
Set platform dependent permission (Windows).
LicenseSpring::LicenseFileStorageEx::loadLicense
std::string loadLicense() override
Load license from file.
LicenseSpring::LicenseFileStorageEx::~LicenseFileStorageEx
~LicenseFileStorageEx() override
Destructor for LicenseFileStorageEx object.
LicenseSpring::LicenseFileStorageEx::LicenseFileStorageEx
LicenseFileStorageEx(const std::string &appName, const std::wstring &licensePath=std::wstring())
LicenseFileStorageEx constructor.
LicenseSpring::LicenseFileStorage
Class that saves license in a file, derived from LicenseFileStorageBase class.
Definition LicenseFileStorage.h:94
LicenseSpring::LicenseFileStorage::LicenseFileStorage
LicenseFileStorage(const std::wstring &licensePath=std::wstring())
Constructor for LicenseFileStorage object.
LicenseSpring::LicenseFileStorage::saveLicense
void saveLicense(const std::string &data) override
Saves given license data string to the file.
LicenseSpring::LicenseFileStorage::loadLicense
std::string loadLicense() override
Load license from file.
LicenseSpring::LicenseFileStorage::create
static ptr_t create(const std::wstring &licensePath=std::wstring())
Allocates and constructs a LicenseFileStorage object and passes args to LicenseFileStorage().
LicenseSpring::LicenseFileStorage::clear
void clear() override
Removes local license file.
LicenseSpring::LicenseFileStorage::ptr_t
std::shared_ptr< LicenseFileStorage > ptr_t
Definition LicenseFileStorage.h:96
LicenseSpring::LicenseStorage
LicenseStorage interface.
Definition LicenseStorage.h:17
LicenseSpring
Definition BaseManager.h:16
boost
Definition LicenseFileStorage.h:14