#5657 Create a global SubscriptionManager instance

This commit is contained in:
Andrew Nelless
2016-10-14 11:28:37 +01:00
parent 743e96f277
commit 540882056f
14 changed files with 117 additions and 248 deletions

View File

@@ -0,0 +1,30 @@
/*
* synergy -- mouse and keyboard sharing utility
* Copyright (C) 2015-2016 Symless Ltd.
*
* This package is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* found in the file LICENSE that should have accompanied this file.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EDITIONTYPE_H
#define EDITIONTYPE_H
/* Do not reorder these! */
enum Edition {
Basic,
Pro,
Trial_DO_NOT_USE_OR_THERE_WILL_BE_PAIN,
Unregistered
};
#endif // EDITIONTYPE_H

View File

@@ -24,11 +24,18 @@
using namespace std;
SerialKey::SerialKey():
m_warnTime(1),
m_expireTime(1),
m_trial(true)
{
}
SerialKey::SerialKey(std::string serial) :
m_userLimit(1),
m_warnTime(0),
m_expireTime(0),
m_edition(kBasic),
m_edition(Edition::Basic),
m_trial(true),
m_valid(false)
{
@@ -39,7 +46,7 @@ SerialKey::SerialKey(std::string serial) :
}
bool
SerialKey::isValid(unsigned long long currentTime) const
SerialKey::isValid(time_t currentTime) const
{
bool result = false;
@@ -58,7 +65,7 @@ SerialKey::isValid(unsigned long long currentTime) const
}
bool
SerialKey::isExpiring(unsigned long long currentTime) const
SerialKey::isExpiring(time_t currentTime) const
{
bool result = false;
@@ -72,7 +79,7 @@ SerialKey::isExpiring(unsigned long long currentTime) const
}
bool
SerialKey::isExpired(unsigned long long currentTime) const
SerialKey::isExpired(time_t currentTime) const
{
bool result = false;
@@ -91,14 +98,14 @@ SerialKey::isTrial() const
return m_trial;
}
int
Edition
SerialKey::edition() const
{
return m_edition;
}
unsigned long long
SerialKey::dayLeft(unsigned long long currentTime) const
time_t
SerialKey::daysLeft(time_t currentTime) const
{
unsigned long long timeLeft = 0;
if (m_expireTime > currentTime) {
@@ -195,9 +202,9 @@ SerialKey::parse(std::string plainSerial)
Edition
SerialKey::getEdition(std::string editionStr)
{
Edition e = kBasic;
Edition e = Edition::Basic;
if (editionStr == "pro") {
e = kPro;
e = Edition::Pro;
}
return e;

View File

@@ -18,31 +18,29 @@
#pragma once
#include <string>
#include <ctime>
#include "EditionType.h"
#ifdef TEST_ENV
#include "gtest/gtest_prod.h"
#endif
enum Edition{
kBasic,
kPro
};
class SerialKey {
public:
SerialKey();
SerialKey(std::string serial);
bool isValid(unsigned long long currentTime) const;
bool isExpiring(unsigned long long currentTime) const;
bool isExpired(unsigned long long currentTime) const;
bool isValid(time_t currentTime) const;
bool isExpiring(time_t currentTime) const;
bool isExpired(time_t currentTime) const;
bool isTrial() const;
int edition() const;
unsigned long long dayLeft(unsigned long long currentTime) const;
time_t daysLeft(time_t currentTime) const;
Edition edition() const;
private:
std::string decode(const std::string& serial) const;
void parse(std::string plainSerial);
Edition getEdition(std::string editionStr);
Edition getEdition(std::string editionStr);
#ifdef TEST_ENV
private:
@@ -59,10 +57,21 @@ private:
std::string m_name;
std::string m_email;
std::string m_company;
int m_userLimit;
unsigned m_userLimit;
unsigned long long m_warnTime;
unsigned long long m_expireTime;
Edition m_edition;
Edition m_edition;
bool m_trial;
bool m_valid;
};
inline bool
operator== (SerialKey const& lhs, SerialKey const& rhs) {
return (lhs.edition() == rhs.edition());
}
inline bool
operator!= (SerialKey const& lhs, SerialKey const& rhs) {
return !(lhs == rhs);
}