X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/f930e6a6429d8b95504c58cdee9e0f01db5be618..ee1709cd231588fe672d0bd2546ef69ee87ff88c:/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h diff --git a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h index 05357212..a4167274 100644 --- a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h +++ b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h @@ -24,23 +24,28 @@ * Author : Boris Mikhailenko */ -#ifndef ETHER_CAP_H -#define ETHER_CAP_H +#pragma once -#include +#include "stg/plugin.h" +#include "stg/module_settings.h" +#include "stg/logger.h" #include #include +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" +#include +#pragma GCC diagnostic pop +#include -#include "stg/os_int.h" -#include "stg/plugin.h" -#include "stg/module_settings.h" - -extern "C" PLUGIN * GetPlugin(); +#include #define BUFF_LEN (128) -class TRAFFCOUNTER; +namespace STG +{ +struct TraffCounter; +} //----------------------------------------------------------------------------- struct BPF_DATA { @@ -80,9 +85,8 @@ std::string iface; //----------------------------------------------------------------------------- class BPF_CAP_SETTINGS { public: - virtual ~BPF_CAP_SETTINGS() {} const std::string & GetStrError() const { return errorStr; } - int ParseSettings(const MODULE_SETTINGS & s); + int ParseSettings(const STG::ModuleSettings & s); std::string GetIface(unsigned int num); private: @@ -90,33 +94,30 @@ private: mutable std::string errorStr; }; //----------------------------------------------------------------------------- -class BPF_CAP : public PLUGIN { +class BPF_CAP : public STG::Plugin { public: BPF_CAP(); - virtual ~BPF_CAP() {} - void SetUsers(USERS *) {} - void SetTariffs(TARIFFS *) {} - void SetAdmins(ADMINS *) {} - void SetTraffcounter(TRAFFCOUNTER * tc) { traffCnt = tc; } - void SetStore(STORE *) {} - void SetStgSettings(const SETTINGS *) {} + void SetTraffcounter(STG::TraffCounter * tc) override { traffCnt = tc; } - int Start(); - int Stop(); - int Reload() { return 0; } - bool IsRunning() { return isRunning; } + int Start() override; + int Stop() override; + int Reload(const STG::ModuleSettings & /*ms*/) override { return 0; } + bool IsRunning() override { return isRunning; } - void SetSettings(const MODULE_SETTINGS & s) { settings = s; } - int ParseSettings(); + void SetSettings(const STG::ModuleSettings & s) override { settings = s; } + int ParseSettings() override; - const std::string & GetStrError() const { return errorStr; } - const std::string GetVersion() const; - uint16_t GetStartPosition() const { return 10; } - uint16_t GetStopPosition() const { return 10; } + const std::string & GetStrError() const override { return errorStr; } + std::string GetVersion() const override; + uint16_t GetStartPosition() const override { return 40; } + uint16_t GetStopPosition() const override { return 40; } private: - static void * Run(void *); + BPF_CAP(const BPF_CAP & rvalue); + BPF_CAP & operator=(const BPF_CAP & rvalue); + + void Run(std::stop_token token); int BPFCapOpen(); int BPFCapOpen(BPF_DATA * bd); int BPFCapClose(); @@ -130,14 +131,12 @@ private: std::vector bpfData; std::vector polld; - pthread_t thread; - bool nonstop; + std::jthread m_thread; bool isRunning; int capSock; - MODULE_SETTINGS settings; + STG::ModuleSettings settings; - TRAFFCOUNTER * traffCnt; -}; -//----------------------------------------------------------------------------- + STG::TraffCounter * traffCnt; -#endif + STG::PluginLogger logger; +};