X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/0907aa4037b12b6b88ee24495d4577a064d4f8db..2196a3a0cdc5384c082febb7f4aa5994cc7d80db:/projects/stargazer/plugins/capture/cap_nf/cap_nf.h?ds=inline diff --git a/projects/stargazer/plugins/capture/cap_nf/cap_nf.h b/projects/stargazer/plugins/capture/cap_nf/cap_nf.h index b9f45c55..ed07bd59 100644 --- a/projects/stargazer/plugins/capture/cap_nf/cap_nf.h +++ b/projects/stargazer/plugins/capture/cap_nf/cap_nf.h @@ -34,9 +34,12 @@ $Author: faust $ #include "stg/logger.h" #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" +#include +#pragma GCC diagnostic pop #include -#include #include // close #define VERSION "cap_nf v. 0.4" @@ -46,58 +49,57 @@ $Author: faust $ namespace STG { -struct Users; -struct Tariffs; +class Users; +class Tariffs; struct Admins; struct TraffCounter; struct Store; struct Settings; -} - -class NF_CAP : public STG::Plugin { -public: - NF_CAP(); - - void SetTraffcounter(STG::TraffCounter * tc) override { traffCnt = tc; } - void SetSettings(const STG::ModuleSettings & s) override { settings = s; } - int ParseSettings() override; - - int Start() override; - int Stop() override; - int Reload(const STG::ModuleSettings & /*ms*/) override { return 0; } - - bool IsRunning() override { return runningTCP || runningUDP; } - const std::string & GetStrError() const override { return errorStr; } - std::string GetVersion() const override { return VERSION; } - uint16_t GetStartPosition() const override { return START_POS; } - uint16_t GetStopPosition() const override { return STOP_POS; } - -private: - NF_CAP(const NF_CAP & rvalue); - NF_CAP & operator=(const NF_CAP & rvalue); - - STG::TraffCounter * traffCnt; - STG::ModuleSettings settings; - pthread_t tidTCP; - pthread_t tidUDP; - bool runningTCP; - bool runningUDP; - bool stoppedTCP; - bool stoppedUDP; - uint16_t portT; - uint16_t portU; - int sockTCP; - int sockUDP; - mutable std::string errorStr; - STG::PluginLogger logger; - - static void * RunUDP(void *); - static void * RunTCP(void *); - void ParseBuffer(uint8_t * buf, ssize_t size); - - bool OpenTCP(); - bool OpenUDP(); - void CloseTCP() { close(sockTCP); } - void CloseUDP() { close(sockUDP); } +class NF_CAP : public Plugin +{ + public: + NF_CAP(); + + void SetTraffcounter(TraffCounter * tc) override { traffCnt = tc; } + void SetSettings(const ModuleSettings & s) override { settings = s; } + int ParseSettings() override; + + int Start() override; + int Stop() override; + int Reload(const ModuleSettings & /*ms*/) override { return 0; } + + bool IsRunning() override { return m_threadTCP.joinable() || m_threadUDP.joinable(); } + const std::string & GetStrError() const override { return errorStr; } + std::string GetVersion() const override { return VERSION; } + uint16_t GetStartPosition() const override { return START_POS; } + uint16_t GetStopPosition() const override { return STOP_POS; } + + private: + NF_CAP(const NF_CAP & rvalue); + NF_CAP & operator=(const NF_CAP & rvalue); + + TraffCounter * traffCnt; + ModuleSettings settings; + std::jthread m_threadTCP; + std::jthread m_threadUDP; + bool stoppedTCP; + bool stoppedUDP; + uint16_t portT; + uint16_t portU; + int sockTCP; + int sockUDP; + mutable std::string errorStr; + PluginLogger logger; + + void RunUDP(std::stop_token token) noexcept; + void RunTCP(std::stop_token token) noexcept; + void ParseBuffer(uint8_t * buf, ssize_t size); + + bool OpenTCP(); + bool OpenUDP(); + void CloseTCP() { close(sockTCP); } + void CloseUDP() { close(sockUDP); } }; + +}