]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/other/smux/smux.h
More subscriptions, less notifiers.
[stg.git] / projects / stargazer / plugins / other / smux / smux.h
index f45beffcdfbf31f8851f79da1c110359962ab1eb..3e708e2b70342da1a45a70be6c2d3acd77dd3e48 100644 (file)
@@ -1,28 +1,28 @@
-#ifndef __SMUX_H__
-#define __SMUX_H__
+#pragma once
 
-#include <string>
-#include <map>
-#include <list>
-#include <mutex>
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wshadow"
-#include <jthread.hpp>
-#pragma GCC diagnostic pop
-#include <cstdint>
+#include "sensors.h"
+#include "tables.h"
+#include "types.h"
 
 #include "stg/SMUX-PDUs.h"
 #include "stg/ObjectSyntax.h"
 
 #include "stg/plugin.h"
 #include "stg/module_settings.h"
+#include "stg/subscriptions.h"
 #include "stg/notifer.h"
 #include "stg/noncopyable.h"
 #include "stg/logger.h"
 
-#include "sensors.h"
-#include "tables.h"
-#include "types.h"
+#include <string>
+#include <map>
+#include <list>
+#include <mutex>
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wshadow"
+#include <jthread.hpp>
+#pragma GCC diagnostic pop
+#include <cstdint>
 
 namespace STG
 {
@@ -81,34 +81,6 @@ private:
     UserPtr userPtr;
 };
 //-----------------------------------------------------------------------------
-class ADD_DEL_TARIFF_NOTIFIER : public STG::NotifierBase<STG::TariffData> {
-public:
-    explicit ADD_DEL_TARIFF_NOTIFIER(SMUX & s)
-             : STG::NotifierBase<STG::TariffData>(), smux(s) {}
-    void notify(const STG::TariffData &) override;
-
-private:
-    SMUX & smux;
-};
-//-----------------------------------------------------------------------------
-class ADD_USER_NOTIFIER : public STG::NotifierBase<UserPtr> {
-public:
-    explicit ADD_USER_NOTIFIER(SMUX & s) : STG::NotifierBase<STG::User*>(), smux(s) {}
-    void notify(const UserPtr &) override;
-
-private:
-    SMUX & smux;
-};
-//-----------------------------------------------------------------------------
-class DEL_USER_NOTIFIER : public STG::NotifierBase<UserPtr> {
-public:
-    explicit DEL_USER_NOTIFIER(SMUX & s) : STG::NotifierBase<UserPtr>(), smux(s) {}
-    void notify(const UserPtr &) override;
-
-private:
-    SMUX & smux;
-};
-//-----------------------------------------------------------------------------
 class SMUX : public STG::Plugin {
 public:
     SMUX();
@@ -186,10 +158,12 @@ private:
     Sensors sensors;
     Tables tables;
 
+    STG::ScopedConnection m_onAddUserConn;
+    STG::ScopedConnection m_onDelUserConn;
+    STG::ScopedConnection m_onAddTariffConn;
+    STG::ScopedConnection m_onDelTariffConn;
+
     std::list<CHG_AFTER_NOTIFIER> notifiers;
-    ADD_USER_NOTIFIER addUserNotifier;
-    DEL_USER_NOTIFIER delUserNotifier;
-    ADD_DEL_TARIFF_NOTIFIER addDelTariffNotifier;
 
     STG::PluginLogger logger;
 };
@@ -200,25 +174,3 @@ void CHG_AFTER_NOTIFIER::notify(const std::string &, const std::string &)
 {
 smux.UpdateTables();
 }
-
-inline
-void ADD_DEL_TARIFF_NOTIFIER::notify(const STG::TariffData &)
-{
-smux.UpdateTables();
-}
-
-inline
-void ADD_USER_NOTIFIER::notify(const UserPtr & userPtr)
-{
-smux.SetNotifier(userPtr);
-smux.UpdateTables();
-}
-
-inline
-void DEL_USER_NOTIFIER::notify(const UserPtr & userPtr)
-{
-smux.UnsetNotifier(userPtr);
-smux.UpdateTables();
-}
-
-#endif