3 #include "stg/plugin.h"
 
   4 #include "stg/module_settings.h"
 
   5 #include "stg/notifer.h"
 
   6 #include "stg/subscriptions.h"
 
   7 #include "stg/user_ips.h"
 
   8 #include "stg/pinger.h"
 
  10 #include "stg/logger.h"
 
  15 #pragma GCC diagnostic push
 
  16 #pragma GCC diagnostic ignored "-Wshadow"
 
  17 #include <jthread.hpp>
 
  18 #pragma GCC diagnostic pop
 
  29 using UserPtr = STG::User*;
 
  30 //-----------------------------------------------------------------------------*/
 
  31 class CHG_CURRIP_NOTIFIER_PING: public STG::PropertyNotifierBase<uint32_t> {
 
  33     CHG_CURRIP_NOTIFIER_PING(const PING & p, UserPtr u)
 
  35     void notify(const uint32_t & oldIP, const uint32_t & newIP) override;
 
  36     UserPtr GetUser() const { return user; }
 
  39     CHG_CURRIP_NOTIFIER_PING & operator=(const CHG_CURRIP_NOTIFIER_PING &);
 
  44 //-----------------------------------------------------------------------------
 
  45 class CHG_IPS_NOTIFIER_PING: public STG::PropertyNotifierBase<STG::UserIPs> {
 
  47     CHG_IPS_NOTIFIER_PING(const PING & p, UserPtr u)
 
  49     void notify(const STG::UserIPs & oldIPS, const STG::UserIPs & newIPS) override;
 
  50     UserPtr GetUser() const { return user; }
 
  53     CHG_IPS_NOTIFIER_PING & operator=(const CHG_IPS_NOTIFIER_PING &);
 
  58 //-----------------------------------------------------------------------------
 
  61     PING_SETTINGS() : pingDelay(0) {}
 
  62     const std::string & GetStrError() const { return errorStr; }
 
  63     int ParseSettings(const STG::ModuleSettings & s);
 
  64     int GetPingDelay() const { return pingDelay; }
 
  67     mutable std::string errorStr;
 
  69 //-----------------------------------------------------------------------------
 
  70 class PING : public STG::Plugin {
 
  71 friend class CHG_CURRIP_NOTIFIER_PING;
 
  72 friend class CHG_IPS_NOTIFIER_PING;
 
  76     void SetUsers(STG::Users * u) override { users = u; }
 
  77     void SetSettings(const STG::ModuleSettings & s) override { settings = s; }
 
  78     int ParseSettings() override;
 
  82     int Reload(const STG::ModuleSettings & /*ms*/) override { return 0; }
 
  83     bool IsRunning() override;
 
  85     const std::string & GetStrError() const override { return errorStr; }
 
  86     std::string GetVersion() const override { return "Pinger v.1.01"; }
 
  87     uint16_t GetStartPosition() const override { return 10; }
 
  88     uint16_t GetStopPosition() const override { return 10; }
 
  90     void AddUser(UserPtr u);
 
  91     void DelUser(UserPtr u);
 
  94     explicit PING(const PING & rvalue);
 
  95     PING & operator=(const PING & rvalue);
 
  98     void SetUserNotifiers(UserPtr u);
 
  99     void UnSetUserNotifiers(UserPtr u);
 
 100     void Run(std::stop_token token);
 
 102     mutable std::string errorStr;
 
 103     PING_SETTINGS pingSettings;
 
 104     STG::ModuleSettings settings;
 
 106     std::list<UserPtr> usersList;
 
 108     std::jthread m_thread;
 
 111     mutable STG_PINGER pinger;
 
 113     std::list<CHG_CURRIP_NOTIFIER_PING> ChgCurrIPNotifierList;
 
 114     std::list<CHG_IPS_NOTIFIER_PING> ChgIPNotifierList;
 
 116     STG::ScopedConnection m_onAddUserConn;
 
 117     STG::ScopedConnection m_onDelUserConn;
 
 119     STG::PluginLogger logger;