]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h
Start replacing notifiers with subscriptions.
[stg.git] / projects / stargazer / plugins / capture / ether_freebsd / ether_cap.h
index 7097c28009a1dca621e5e00adc40d9fdc1efd434..a416727401f0ba8517bdd5fa360cf654ccf4fe78 100644 (file)
 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
 */
 
 * Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
 */
 
-#ifndef ETHER_CAP_H
-#define ETHER_CAP_H
+#pragma once
 
 
-#include <pthread.h>
+#include "stg/plugin.h"
+#include "stg/module_settings.h"
+#include "stg/logger.h"
 
 #include <string>
 #include <vector>
 
 #include <string>
 #include <vector>
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wshadow"
+#include <jthread.hpp>
+#pragma GCC diagnostic pop
+#include <cstdint>
 
 
-#ifdef FREE_BSD5
-#include <inttypes.h>
-#endif
-
-#ifdef FREE_BSD
-#include <sys/inttypes.h>
-#endif
-
-#include "plugin.h"
-#include "module_settings.h"
-#include "../../../traffcounter.h"
-
-extern "C" PLUGIN * GetPlugin();
+#include <sys/poll.h>
 
 #define BUFF_LEN (128)
 
 
 #define BUFF_LEN (128)
 
+namespace STG
+{
+struct TraffCounter;
+}
+
 //-----------------------------------------------------------------------------
 struct BPF_DATA {
     BPF_DATA()
 //-----------------------------------------------------------------------------
 struct BPF_DATA {
     BPF_DATA()
@@ -74,21 +73,20 @@ struct BPF_DATA {
         iface = bd.iface;
         };
 
         iface = bd.iface;
         };
 
-int             fd;
-uint8_t *       p;
-int             r;
-int             sum;
-uint8_t         buffer[BUFF_LEN];
+int              fd;
+uint8_t *        p;
+int              r;
+int              sum;
+uint8_t          buffer[BUFF_LEN];
 struct bpf_hdr * bh;
 struct bpf_hdr * bh;
-int             canRead;
-std::string     iface;
+int              canRead;
+std::string      iface;
 };
 //-----------------------------------------------------------------------------
 class BPF_CAP_SETTINGS {
 public:
 };
 //-----------------------------------------------------------------------------
 class BPF_CAP_SETTINGS {
 public:
-    virtual         ~BPF_CAP_SETTINGS() {}
     const std::string & GetStrError() const { return errorStr; }
     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:
     std::string     GetIface(unsigned int num);
 
 private:
@@ -96,33 +94,30 @@ private:
     mutable std::string errorStr;
 };
 //-----------------------------------------------------------------------------
     mutable std::string errorStr;
 };
 //-----------------------------------------------------------------------------
-class BPF_CAP : public PLUGIN {
+class BPF_CAP : public STG::Plugin {
 public:
                         BPF_CAP();
 public:
                         BPF_CAP();
-    virtual             ~BPF_CAP() {}
 
 
-    void                SetUsers(USERS *) {}
-    void                SetTariffs(TARIFFS *) {}
-    void                SetAdmins(ADMINS *) {}
-    void                SetTraffcounter(TRAFFCOUNTER * 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();
+    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);
-    int                 ParseSettings();
+    void                SetSettings(const STG::ModuleSettings & s) override { settings = s; }
+    int                 ParseSettings() override;
 
 
-    const std::string & GetStrError() const;
-    const std::string   GetVersion() const;
-    uint16_t            GetStartPosition() const;
-    uint16_t            GetStopPosition() const;
+    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:
 
 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();
     int                 BPFCapOpen();
     int                 BPFCapOpen(BPF_DATA * bd);
     int                 BPFCapClose();
@@ -136,14 +131,12 @@ private:
     std::vector<BPF_DATA> bpfData;
     std::vector<pollfd>   polld;
 
     std::vector<BPF_DATA> bpfData;
     std::vector<pollfd>   polld;
 
-    pthread_t             thread;
-    bool                  nonstop;
+    std::jthread          m_thread;
     bool                  isRunning;
     int                   capSock;
     bool                  isRunning;
     int                   capSock;
-    MODULE_SETTINGS       settings;
+    STG::ModuleSettings       settings;
 
 
-    TRAFFCOUNTER *        traffCnt;
-};
-//-----------------------------------------------------------------------------
+    STG::TraffCounter *        traffCnt;
 
 
-#endif
+    STG::PluginLogger         logger;
+};