namespace STG
{
-template <typename T>
-struct PropertyNotifierBase
-{
- virtual ~PropertyNotifierBase() = default;
-
- virtual void Notify(const T& oldValue, const T& newValue) = 0;
-};
-
-template <typename T>
+template <typename... Ts>
struct NotifierBase
{
virtual ~NotifierBase() = default;
- virtual void Notify(const T& value) = 0;
+ virtual void notify(const Ts&... values) = 0;
};
+template <typename T>
+using PropertyNotifierBase = NotifierBase<T, T>;
+
}
auto ni = beforeNotifiers.begin();
while (ni != beforeNotifiers.end())
- (*ni++)->Notify(oldVal, rvalue);
+ (*ni++)->notify(oldVal, rvalue);
value = rvalue;
modificationTime = time(NULL);
ni = afterNotifiers.begin();
while (ni != afterNotifiers.end())
- (*ni++)->Notify(oldVal, rvalue);
+ (*ni++)->notify(oldVal, rvalue);
}
//-----------------------------------------------------------------------------
template <typename T>
}
//-----------------------------------------------------------------------------
template <typename varParamType>
-void CHG_BEFORE_NOTIFIER<varParamType>::Notify(const varParamType &, const varParamType &)
+void CHG_BEFORE_NOTIFIER<varParamType>::notify(const varParamType &, const varParamType &)
{
//EVENT_LOOP_SINGLETON::GetInstance().Enqueue(auth, &AUTH_AO::Unauthorize, user);
if (user->IsAuthorizedBy(&auth))
}
//-----------------------------------------------------------------------------
template <typename varParamType>
-void CHG_AFTER_NOTIFIER<varParamType>::Notify(const varParamType &, const varParamType &)
+void CHG_AFTER_NOTIFIER<varParamType>::notify(const varParamType &, const varParamType &)
{
//EVENT_LOOP_SINGLETON::GetInstance().Enqueue(auth, &AUTH_AO::UpdateUserAuthorization, user);
auth.UpdateUserAuthorization(user);
: user(u), auth(a) {}
CHG_BEFORE_NOTIFIER(const CHG_BEFORE_NOTIFIER<T> & rvalue)
: user(rvalue.user), auth(rvalue.auth) {}
- void Notify(const T & oldValue, const T & newValue);
+ void notify(const T & oldValue, const T & newValue) override;
UserPtr GetUser() const { return user; }
private:
: user(u), auth(a) {}
CHG_AFTER_NOTIFIER(const CHG_AFTER_NOTIFIER<T> & rvalue)
: user(rvalue.user), auth(rvalue.auth) {}
- void Notify(const T & oldValue, const T & newValue);
+ void notify(const T & oldValue, const T & newValue) override;
UserPtr GetUser() const { return user; }
private:
public:
explicit ADD_USER_NONIFIER(AUTH_AO & a) : auth(a) {}
virtual ~ADD_USER_NONIFIER() {}
- void Notify(const UserPtr & user) { auth.AddUser(user); }
+ void notify(const UserPtr & user) override { auth.AddUser(user); }
private:
ADD_USER_NONIFIER(const ADD_USER_NONIFIER & rvalue);
public:
explicit DEL_USER_NONIFIER(AUTH_AO & a) : auth(a) {}
virtual ~DEL_USER_NONIFIER() {}
- void Notify(const UserPtr & user) { auth.DelUser(user); }
+ void notify(const UserPtr & user) override { auth.DelUser(user); }
private:
DEL_USER_NONIFIER(const DEL_USER_NONIFIER & rvalue);
explicit DEL_USER_NOTIFIER(AUTH_IA & a) : auth(a) {}
virtual ~DEL_USER_NOTIFIER() {}
- void Notify(const UserPtr & user);
+ void notify(const UserPtr & user) override;
private:
DEL_USER_NOTIFIER(const DEL_USER_NOTIFIER & rvalue);
DEL_USER_NOTIFIER & operator=(const DEL_USER_NOTIFIER & rvalue);
};
//-----------------------------------------------------------------------------
inline
-void DEL_USER_NOTIFIER::Notify(const UserPtr & user)
+void DEL_USER_NOTIFIER::notify(const UserPtr & user)
{
auth.DelUser(user);
}
}
}
//-----------------------------------------------------------------------------
-void CHG_CURRIP_NOTIFIER_PING::Notify(const uint32_t & oldIP, const uint32_t & newIP)
+void CHG_CURRIP_NOTIFIER_PING::notify(const uint32_t & oldIP, const uint32_t & newIP)
{
ping.pinger.DelIP(oldIP);
if (newIP != 0)
ping.pinger.AddIP(newIP);
}
//-----------------------------------------------------------------------------
-void CHG_IPS_NOTIFIER_PING::Notify(const STG::UserIPs & oldIPS, const STG::UserIPs & newIPS)
+void CHG_IPS_NOTIFIER_PING::notify(const STG::UserIPs & oldIPS, const STG::UserIPs & newIPS)
{
if (oldIPS.onlyOneIP())
ping.pinger.DelIP(oldIPS[0].ip);
ping.pinger.AddIP(newIPS[0].ip);
}
//-----------------------------------------------------------------------------
-void ADD_USER_NONIFIER_PING::Notify(const UserPtr & user)
+void ADD_USER_NONIFIER_PING::notify(const UserPtr & user)
{
ping.AddUser(user);
}
//-----------------------------------------------------------------------------
-void DEL_USER_NONIFIER_PING::Notify(const UserPtr & user)
+void DEL_USER_NONIFIER_PING::notify(const UserPtr & user)
{
ping.DelUser(user);
}
public:
CHG_CURRIP_NOTIFIER_PING(const PING & p, UserPtr u)
: user(u), ping(p) {}
- void Notify(const uint32_t & oldIP, const uint32_t & newIP);
+ void notify(const uint32_t & oldIP, const uint32_t & newIP) override;
UserPtr GetUser() const { return user; }
private:
public:
CHG_IPS_NOTIFIER_PING(const PING & p, UserPtr u)
: user(u), ping(p) {}
- void Notify(const STG::UserIPs & oldIPS, const STG::UserIPs & newIPS);
+ void notify(const STG::UserIPs & oldIPS, const STG::UserIPs & newIPS) override;
UserPtr GetUser() const { return user; }
private:
class ADD_USER_NONIFIER_PING: public STG::NotifierBase<UserPtr> {
public:
explicit ADD_USER_NONIFIER_PING(PING & p) : ping(p) {}
- void Notify(const UserPtr & user);
+ void notify(const UserPtr & user) override;
private:
ADD_USER_NONIFIER_PING(const ADD_USER_NONIFIER_PING &);
class DEL_USER_NONIFIER_PING: public STG::NotifierBase<UserPtr> {
public:
explicit DEL_USER_NONIFIER_PING(PING & p) : ping(p) {}
- void Notify(const UserPtr & user);
+ void notify(const UserPtr & user) override;
private:
DEL_USER_NONIFIER_PING(const DEL_USER_NONIFIER_PING &);
}*/
}
//-----------------------------------------------------------------------------
-void RS::IP_NOTIFIER::Notify(const uint32_t & /*oldValue*/, const uint32_t & newValue)
+void RS::IP_NOTIFIER::notify(const uint32_t & /*oldValue*/, const uint32_t & newValue)
{
if (newValue != 0)
rs.AddRSU(user);
rs.DelRSU(user);
}
//-----------------------------------------------------------------------------
-void RS::CONNECTED_NOTIFIER::Notify(const bool & /*oldValue*/, const bool & newValue)
+void RS::CONNECTED_NOTIFIER::notify(const bool & /*oldValue*/, const bool & newValue)
{
if (newValue)
rs.AddRSU(user);
public:
explicit ADD_USER_NONIFIER(REMOTE_SCRIPT & r)
: rs(r) {}
- void Notify(const UserPtr & user);
+ void notify(const UserPtr & user) override;
private:
ADD_USER_NONIFIER(const ADD_USER_NONIFIER & rhs);
public:
explicit DEL_USER_NONIFIER(REMOTE_SCRIPT & r)
: rs(r) {}
- void Notify(const UserPtr & user);
+ void notify(const UserPtr & user) override;
private:
DEL_USER_NONIFIER(const DEL_USER_NONIFIER & rhs);
return *this;
}
- void Notify(const uint32_t & oldValue, const uint32_t & newValue);
+ void notify(const uint32_t & oldValue, const uint32_t & newValue) override;
UserPtr GetUser() const { return user; }
private:
return *this;
}
- void Notify(const bool & oldValue, const bool & newValue);
+ void notify(const bool & oldValue, const bool & newValue) override;
UserPtr GetUser() const { return user; }
private:
REMOTE_SCRIPT & rscript;
};
//-----------------------------------------------------------------------------
-inline void ADD_USER_NONIFIER::Notify(const UserPtr & user)
+inline void ADD_USER_NONIFIER::notify(const UserPtr & user)
{
rs.AddUser(user);
}
//-----------------------------------------------------------------------------
-inline void DEL_USER_NONIFIER::Notify(const UserPtr & user)
+inline void DEL_USER_NONIFIER::notify(const UserPtr & user)
{
rs.DelUser(user);
}
CHG_AFTER_NOTIFIER(const CHG_AFTER_NOTIFIER & rvalue)
: STG::PropertyNotifierBase<std::string>(),
smux(rvalue.smux), userPtr(rvalue.userPtr) {}
- void Notify(const std::string &, const std::string &);
+ void notify(const std::string &, const std::string &) override;
UserPtr GetUserPtr() const { return userPtr; }
public:
explicit ADD_DEL_TARIFF_NOTIFIER(SMUX & s)
: STG::NotifierBase<STG::TariffData>(), smux(s) {}
- void Notify(const STG::TariffData &);
+ void notify(const STG::TariffData &) override;
private:
SMUX & smux;
class ADD_USER_NOTIFIER : public STG::NotifierBase<UserPtr> {
public:
explicit ADD_USER_NOTIFIER(SMUX & s) : STG::NotifierBase<STG::User*>(), smux(s) {}
- void Notify(const UserPtr &);
+ void notify(const UserPtr &) override;
private:
SMUX & smux;
class DEL_USER_NOTIFIER : public STG::NotifierBase<UserPtr> {
public:
explicit DEL_USER_NOTIFIER(SMUX & s) : STG::NotifierBase<UserPtr>(), smux(s) {}
- void Notify(const UserPtr &);
+ void notify(const UserPtr &) override;
private:
SMUX & smux;
//-----------------------------------------------------------------------------
inline
-void CHG_AFTER_NOTIFIER::Notify(const std::string &, const std::string &)
+void CHG_AFTER_NOTIFIER::notify(const std::string &, const std::string &)
{
smux.UpdateTables();
}
inline
-void ADD_DEL_TARIFF_NOTIFIER::Notify(const STG::TariffData &)
+void ADD_DEL_TARIFF_NOTIFIER::notify(const STG::TariffData &)
{
smux.UpdateTables();
}
inline
-void ADD_USER_NOTIFIER::Notify(const UserPtr & userPtr)
+void ADD_USER_NOTIFIER::notify(const UserPtr & userPtr)
{
smux.SetNotifier(userPtr);
smux.UpdateTables();
}
inline
-void DEL_USER_NOTIFIER::Notify(const UserPtr & userPtr)
+void DEL_USER_NOTIFIER::notify(const UserPtr & userPtr)
{
smux.UnsetNotifier(userPtr);
smux.UpdateTables();
auto ni = onDelNotifiers.begin();
while (ni != onDelNotifiers.end())
{
- (*ni)->Notify(td);
+ (*ni)->notify(td);
++ni;
}
auto ni = onAddNotifiers.begin();
while (ni != onAddNotifiers.end())
{
- (*ni)->Notify(tariffs.back().GetTariffData());
+ (*ni)->notify(tariffs.back().GetTariffData());
++ni;
}
traffCnt(rvalue.traffCnt),
user(rvalue.user)
{}
- void Notify(const uint32_t & oldValue, const uint32_t & newValue);
+ void notify(const uint32_t & oldValue, const uint32_t & newValue) override;
void SetUser(UserImpl * u) { user = u; }
UserImpl * GetUser() const { return user; }
traffCnt(rvalue.traffCnt),
user(rvalue.user)
{}
- void Notify(const uint32_t & oldValue, const uint32_t & newValue);
+ void notify(const uint32_t & oldValue, const uint32_t & newValue) override;
void SetUser(UserImpl * u) { user = u; }
UserImpl * GetUser() const { return user; }
private:
traffCnt(t)
{}
virtual ~ADD_USER_NONIFIER() {}
- void Notify(const UserImplPtr & user);
+ void notify(const UserImplPtr & user) override;
private:
ADD_USER_NONIFIER(const ADD_USER_NONIFIER & rvalue);
traffCnt(t)
{}
virtual ~DEL_USER_NONIFIER() {}
- void Notify(const UserImplPtr & user);
+ void notify(const UserImplPtr & user) override;
private:
DEL_USER_NONIFIER(const DEL_USER_NONIFIER & rvalue);
};
//-----------------------------------------------------------------------------
inline
-void TRF_IP_BEFORE::Notify(const uint32_t & oldValue, const uint32_t &)
+void TRF_IP_BEFORE::notify(const uint32_t & oldValue, const uint32_t &)
{
// User changes his address. Remove old IP
if (!oldValue)
}
//-----------------------------------------------------------------------------
inline
-void TRF_IP_AFTER::Notify(const uint32_t &, const uint32_t & newValue)
+void TRF_IP_AFTER::notify(const uint32_t &, const uint32_t & newValue)
{
// User changes his address. Add new IP
if (!newValue)
}
//-----------------------------------------------------------------------------
inline
-void ADD_USER_NONIFIER::Notify(const UserImplPtr & user)
+void ADD_USER_NONIFIER::notify(const UserImplPtr & user)
{
EVENT_LOOP::instance().Enqueue(traffCnt, &TraffCounterImpl::SetUserNotifiers, user);
}
//-----------------------------------------------------------------------------
inline
-void DEL_USER_NONIFIER::Notify(const UserImplPtr & user)
+void DEL_USER_NONIFIER::notify(const UserImplPtr & user)
{
EVENT_LOOP::instance().Enqueue(traffCnt, &TraffCounterImpl::UnSetUserNotifiers, user);
EVENT_LOOP::instance().Enqueue(traffCnt, &TraffCounterImpl::DelUser, user->GetCurrIP());
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
-void STG::CHG_PASSIVE_NOTIFIER::Notify(const int & oldPassive, const int & newPassive)
+void STG::CHG_PASSIVE_NOTIFIER::notify(const int & oldPassive, const int & newPassive)
{
if (newPassive && !oldPassive && user->tariff != NULL)
user->properties.cash.Set(user->cash - user->tariff->GetPassiveCost(),
"Freeze");
}
//-----------------------------------------------------------------------------
-void STG::CHG_DISABLED_NOTIFIER::Notify(const int & oldValue, const int & newValue)
+void STG::CHG_DISABLED_NOTIFIER::notify(const int & oldValue, const int & newValue)
{
if (oldValue && !newValue && user->GetConnected())
user->Disconnect(false, "disabled");
user->Connect(false);
}
//-----------------------------------------------------------------------------
-void STG::CHG_TARIFF_NOTIFIER::Notify(const std::string &, const std::string & newTariff)
+void STG::CHG_TARIFF_NOTIFIER::notify(const std::string &, const std::string & newTariff)
{
STG_LOCKER lock(&user->mutex);
if (user->settings->GetReconnectOnTariffChange() && user->connected)
}
}
//-----------------------------------------------------------------------------
-void STG::CHG_CASH_NOTIFIER::Notify(const double & oldCash, const double & newCash)
+void STG::CHG_CASH_NOTIFIER::notify(const double & oldCash, const double & newCash)
{
user->lastCashAddTime = *const_cast<time_t *>(&stgTime);
user->lastCashAdd = newCash - oldCash;
}
//-----------------------------------------------------------------------------
-void STG::CHG_IPS_NOTIFIER::Notify(const UserIPs & from, const UserIPs & to)
+void STG::CHG_IPS_NOTIFIER::notify(const UserIPs & from, const UserIPs & to)
{
printfd(__FILE__, "Change IP from '%s' to '%s'\n", from.toString().c_str(), to.toString().c_str());
if (user->connected)
class CHG_PASSIVE_NOTIFIER : public PropertyNotifierBase<int> {
public:
explicit CHG_PASSIVE_NOTIFIER(UserImpl * u) : user(u) {}
- void Notify(const int & oldPassive, const int & newPassive);
+ void notify(const int & oldPassive, const int & newPassive) override;
private:
UserImpl * user;
class CHG_DISABLED_NOTIFIER : public PropertyNotifierBase<int> {
public:
explicit CHG_DISABLED_NOTIFIER(UserImpl * u) : user(u) {}
- void Notify(const int & oldValue, const int & newValue);
+ void notify(const int & oldValue, const int & newValue) override;
private:
UserImpl * user;
class CHG_TARIFF_NOTIFIER : public PropertyNotifierBase<std::string> {
public:
explicit CHG_TARIFF_NOTIFIER(UserImpl * u) : user(u) {}
- void Notify(const std::string & oldTariff, const std::string & newTariff);
+ void notify(const std::string & oldTariff, const std::string & newTariff) override;
private:
UserImpl * user;
class CHG_CASH_NOTIFIER : public PropertyNotifierBase<double> {
public:
explicit CHG_CASH_NOTIFIER(UserImpl * u) : user(u) {}
- void Notify(const double & oldCash, const double & newCash);
+ void notify(const double & oldCash, const double & newCash) override;
private:
UserImpl * user;
class CHG_IPS_NOTIFIER : public PropertyNotifierBase<UserIPs> {
public:
explicit CHG_IPS_NOTIFIER(UserImpl * u) : user(u) {}
- void Notify(const UserIPs & oldIPs, const UserIPs & newIPs);
+ void notify(const UserIPs & oldIPs, const UserIPs & newIPs) override;
private:
UserImpl * user;
auto ni = onAddNotifiers.begin();
while (ni != onAddNotifiers.end())
{
- (*ni)->Notify(&users.front());
+ (*ni)->notify(&users.front());
++ni;
}
}
auto ni = onAddNotifiersImpl.begin();
while (ni != onAddNotifiersImpl.end())
{
- (*ni)->Notify(&users.front());
+ (*ni)->notify(&users.front());
++ni;
}
}
auto ni = onDelNotifiers.begin();
while (ni != onDelNotifiers.end())
{
- (*ni)->Notify(&(*u));
+ (*ni)->notify(&(*u));
++ni;
}
}
auto ni = onDelNotifiersImpl.begin();
while (ni != onDelNotifiersImpl.end())
{
- (*ni)->Notify(&(*u));
+ (*ni)->notify(&(*u));
++ni;
}
}
m_disconnects(0)
{}
- void Notify(const bool& oldValue, const bool& newValue) override
+ void notify(const bool& oldValue, const bool& newValue) override
{
if (!oldValue && newValue)
++m_connects;