libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
Licensing.h
Go to the documentation of this file.
1 /* Copyright 2013-2019 Homegear GmbH
2  *
3  * libhomegear-base is free software: you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * libhomegear-base is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with libhomegear-base. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  * In addition, as a special exception, the copyright holders give
18  * permission to link the code of portions of this program with the
19  * OpenSSL library under certain conditions as described in each
20  * individual source file, and distribute linked combinations
21  * including the two.
22  * You must obey the GNU Lesser General Public License in all respects
23  * for all of the code used other than OpenSSL. If you modify
24  * file(s) with this exception, you may extend this exception to your
25  * version of the file(s), but you are not obligated to do so. If you
26  * do not wish to do so, delete this exception statement from your
27  * version. If you delete this exception statement from all source
28  * files in the program, then also delete it here.
29 */
30 
31 #ifndef LICENSING_H_
32 #define LICENSING_H_
33 
34 #include <string>
35 #include <vector>
36 #include <map>
37 #include <memory>
38 #include <mutex>
39 
40 namespace BaseLib
41 {
42 
43 class SharedObjects;
44 
45 namespace Licensing
46 {
47 
48 class Licensing
49 {
50 public:
51  struct DeviceInfo
52  {
53  int32_t moduleId = -1;
54  int32_t familyId = -1;
55  int32_t deviceId = -1;
56  bool state = false;
57  std::string licenseKey;
58  } __attribute__((aligned(64)));
59 
60  typedef std::shared_ptr<DeviceInfo> PDeviceInfo;
61  typedef std::map<int32_t, std::map<int32_t, PDeviceInfo>> DeviceStates;
62 
63  explicit Licensing(BaseLib::SharedObjects* bl);
64  virtual ~Licensing();
65 
66  virtual bool init() = 0;
67  virtual void dispose();
68  virtual void load();
69 
70  virtual int32_t getModuleId() { return _moduleId; }
71 
76  virtual DeviceStates getDeviceStates();
77 
84  virtual bool getDeviceState(int32_t familyId, int32_t deviceId);
85 
94  virtual int32_t checkLicense(int32_t familyId, int32_t deviceId, const std::string& licenseKey = "") = 0;
95 
102  virtual void removeLicense(int32_t familyId, int32_t deviceId);
103 
111  virtual std::string getLicenseKey(int32_t familyId, int32_t deviceId);
112 
120  virtual int64_t getTrialStartTime(int32_t familyId, int32_t deviceId);
121 
122  virtual void decryptScript(const std::vector<char>& input, std::string& output) = 0;
123  virtual void decryptDeviceDescription(const std::vector<char>& input, std::vector<char>& output) = 0;
124 protected:
125  struct LicenseData
126  {
127  std::string licenseKey;
128  std::string activationKey;
129  } __attribute__((aligned(64)));
130 
132  bool _disposed = false;
133  int32_t _moduleId = -1;
134  std::map<uint64_t, uint32_t> _variableDatabaseIds;
135  std::map<uint64_t, LicenseData> _licenseData;
136  std::mutex _devicesMutex;
137  DeviceStates _devices;
138 
139  uint64_t getMapKey(int32_t familyId, int32_t deviceId);
140  virtual void addDevice(int32_t familyId, int32_t deviceId, bool state, std::string licenseKey);
141  virtual void removeDevice(int32_t familyId, int32_t deviceId);
142  virtual void updateDevice(int32_t familyId, int32_t deviceId, bool state, std::string licenseKey);
143  virtual void loadVariables();
144  virtual void saveVariable(uint64_t index, int32_t intValue);
145  virtual void saveVariable(uint64_t index, int64_t intValue);
146  virtual void saveVariable(uint64_t index, std::string& stringValue);
147  virtual void saveVariable(uint64_t index, std::vector<uint8_t>& binaryValue);
148  virtual void saveVariable(uint64_t index, LicenseData& licenseData);
149 };
150 
151 }
152 }
153 
154 #endif
bool _disposed
Definition: Licensing.h:132
BaseLib::SharedObjects * _bl
Definition: Licensing.h:131
This is the base library main class.
Definition: BaseLib.h:95
virtual void addDevice(int32_t familyId, int32_t deviceId, bool state, std::string licenseKey)
Definition: Licensing.cpp:353
std::map< uint64_t, uint32_t > _variableDatabaseIds
Definition: Licensing.h:134
uint64_t getMapKey(int32_t familyId, int32_t deviceId)
Definition: Licensing.cpp:348
Definition: BaseLib.cpp:34
std::map< uint64_t, LicenseData > _licenseData
Definition: Licensing.h:135
struct BaseLib::Licensing::Licensing::DeviceInfo __attribute__((aligned(64)))
virtual void dispose()
Definition: Licensing.cpp:48
DeviceStates _devices
Definition: Licensing.h:137
virtual int64_t getTrialStartTime(int32_t familyId, int32_t deviceId)
Returns the start time of a trial version.
Definition: Licensing.cpp:109
virtual void saveVariable(uint64_t index, int32_t intValue)
Definition: Licensing.cpp:149
virtual void decryptScript(const std::vector< char > &input, std::string &output)=0
std::string activationKey
Definition: Licensing.h:128
std::string licenseKey
Definition: Licensing.h:57
std::mutex _devicesMutex
Definition: Licensing.h:136
Licensing(BaseLib::SharedObjects *bl)
Definition: Licensing.cpp:39
std::shared_ptr< DeviceInfo > PDeviceInfo
Definition: Licensing.h:60
std::string licenseKey
Definition: Licensing.h:127
virtual void loadVariables()
Definition: Licensing.cpp:66
virtual bool getDeviceState(int32_t familyId, int32_t deviceId)
Returns the activation status of a device or family.
Definition: Licensing.cpp:319
virtual int32_t checkLicense(int32_t familyId, int32_t deviceId, const std::string &licenseKey="")=0
Checks if a license key is valid.
int32_t familyId
Definition: Licensing.h:54
virtual void decryptDeviceDescription(const std::vector< char > &input, std::vector< char > &output)=0
int32_t deviceId
Definition: Licensing.h:55
virtual void removeDevice(int32_t familyId, int32_t deviceId)
Definition: Licensing.cpp:378
Definition: Licensing.h:48
virtual ~Licensing()
Definition: Licensing.cpp:44
virtual void removeLicense(int32_t familyId, int32_t deviceId)
Removes a license.
Definition: Licensing.cpp:131
bool state
Definition: Licensing.h:56
virtual void updateDevice(int32_t familyId, int32_t deviceId, bool state, std::string licenseKey)
Definition: Licensing.cpp:373
virtual std::string getLicenseKey(int32_t familyId, int32_t deviceId)
Returns the license key stored in the database.
Definition: Licensing.cpp:90
int32_t moduleId
Definition: Licensing.h:53
virtual int32_t getModuleId()
Definition: Licensing.h:70
virtual DeviceStates getDeviceStates()
Returns a map with all unlicensed devices.
Definition: Licensing.cpp:303
int32_t _moduleId
Definition: Licensing.h:133
virtual void load()
Definition: Licensing.cpp:61
std::map< int32_t, std::map< int32_t, PDeviceInfo > > DeviceStates
Definition: Licensing.h:61