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 
14 namespace boost
15 {
16 namespace interprocess
17 {
18 class permissions;
19 }
20 } // namespace boost
21 
22 namespace LicenseSpring
23 {
28 {
29 public:
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 
76 protected:
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 {
104 public:
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 
129 private:
130  std::mutex m_mutex;
131 };
132 
138 {
139 public:
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 
158  ~LicenseFileStorageEx() override;
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 
184  void setPermissionsUnrestricted();
185 
189  void setPermissionsDefault();
190 
195  uint32_t lockTimeout() const;
196 
199  void setLockTimeout(uint32_t timeout);
200 
201 private:
202  std::string m_name;
203  uint32_t m_lockTimeout;
204  boost::interprocess::permissions *m_perm;
205 };
206 
212 {
213 public:
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 
256 private:
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
LicenseSpring::LicenseFileStorage
Class that saves license in a file, derived from LicenseFileStorageBase class.
Definition: LicenseFileStorage.h:102
LicenseSpring::LicenseFileStorageBase
Base class that saves license in a file, implements ILicenseStorage interface.
Definition: LicenseFileStorage.h:27
boost
Definition: LicenseFileStorage.h:14
LicenseSpring
Definition: BaseManager.h:16
LicenseSpring::LicenseFileStorageBase::ptr_t
std::shared_ptr< LicenseFileStorageBase > ptr_t
Definition: LicenseFileStorage.h:30
LicenseSpring::LicenseFileStorageBase::m_folderPath
std::wstring m_folderPath
Definition: LicenseFileStorage.h:77
LicenseSpring::FileStorageWithLock
Class that saves license in a file, derived from LicenseFileStorageBase class.
Definition: LicenseFileStorage.h:211
LS_API
#define LS_API
Definition: APIDef.h:23
LicenseStorage.h
LicenseSpring::LicenseStorage
LicenseStorage interface.
Definition: LicenseStorage.h:17
LicenseSpring::LicenseFileStorageBase::m_fileName
std::wstring m_fileName
Definition: LicenseFileStorage.h:78
LicenseSpring::LicenseFileStorageEx
Class that saves license in a file, derived from LicenseFileStorageBase class.
Definition: LicenseFileStorage.h:137