#include <map>
#include <functional>
#include <utility>
+#include <mutex>
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wshadow"
+#include <jthread.hpp>
+#pragma GCC diagnostic pop
#include <cstdint>
-#include <pthread.h>
-
namespace STG
{
struct Settings;
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:
class REMOTE_SCRIPT : public STG::Plugin {
public:
REMOTE_SCRIPT();
- ~REMOTE_SCRIPT() override;
void SetUsers(STG::Users * u) override { users = u; }
void SetSettings(const STG::ModuleSettings & s) override { settings = s; }
REMOTE_SCRIPT(const REMOTE_SCRIPT & rhs);
REMOTE_SCRIPT & operator=(const REMOTE_SCRIPT & rhs);
- static void * Run(void *);
+ void Run(std::stop_token token);
bool PrepareNet();
bool FinalizeNet();
void SetUserNotifiers(UserPtr u);
void UnSetUserNotifiers(UserPtr u);
- void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password) const;
- void Encrypt(BLOWFISH_CTX * ctx, void * dst, const void * src, size_t len8) const;
+ void InitEncrypt(const std::string & password) const;
+ void Encrypt(void * dst, const void * src, size_t len8) const;
mutable BLOWFISH_CTX ctx;
int sendPeriod;
int halfPeriod;
- bool nonstop;
bool isRunning;
STG::Users * users;
std::vector<NET_ROUTER> netRouters;
- pthread_t thread;
- pthread_mutex_t mutex;
+ std::jthread m_thread;
+ std::mutex m_mutex;
int sock;
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);
}