]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugin_runner.h
Move projects back into subfolder.
[stg.git] / projects / stargazer / plugin_runner.h
index 412c51413361d7a7e93cb39b4c9e08749704dffc..1c8bf422bb0b15d8a2381cb60959d9c06923eae3 100644 (file)
 
 /*
  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
+ *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
  */
 
-/*
- $Revision: 1.13 $
- $Date: 2010/03/04 12:22:41 $
- $Author: faust $
- */
-
-#ifndef PLUGIN_RUNNER_H
-#define PLUGIN_RUNNER_H
+#pragma once
 
-#include <string>
-
-#include "stg/module_settings.h"
 #include "stg/plugin.h"
-#include "stg/os_int.h"
 
-class SETTINGS_IMPL;
-class ADMINS_IMPL;
-class TARIFFS_IMPL;
-class USERS_IMPL;
-class TRAFFCOUNTER;
-class STORE;
+#include <string>
+#include <stdexcept>
+#include <cstdint>
+
+namespace STG
+{
+
+struct ModuleSettings;
+struct Settings;
+struct Admins;
+struct Tariffs;
+struct Users;
+struct Services;
+struct Corporations;
+struct TraffCounter;
+struct Store;
 
 //-----------------------------------------------------------------------------
-class PLUGIN_RUNNER {
+class PluginRunner {
 public:
-    PLUGIN_RUNNER(const std::string & pluginFileName,
-                  const MODULE_SETTINGS & ms,
-                  ADMINS_IMPL * admins,
-                  TARIFFS_IMPL * tariffs,
-                  USERS_IMPL * users,
-                  TRAFFCOUNTER * tc,
-                  STORE * store,
-                  const SETTINGS_IMPL * s);
-    PLUGIN_RUNNER(const PLUGIN_RUNNER & rvalue);
-    ~PLUGIN_RUNNER();
-
-    PLUGIN_RUNNER & operator=(const PLUGIN_RUNNER & rvalue);
+    struct Error : public std::runtime_error {
+        explicit Error(const std::string & msg) : runtime_error(msg) {}
+    };
+
+    PluginRunner(const std::string& pluginFileName,
+                 const std::string& pluginName,
+                 const ModuleSettings& ms,
+                 Admins& admins,
+                 Tariffs& tariffs,
+                 Users& users,
+                 Services& services,
+                 Corporations& corporations,
+                 TraffCounter& traffcounter,
+                 Store& store,
+                 const Settings & settings);
+    ~PluginRunner();
 
     int             Start();
     int             Stop();
-    int             Reload();
+    int             Reload(const ModuleSettings& ms);
     int             Restart();
-    bool            IsRunning();
-
-    const std::string & GetStrError() const { return errorStr; }
-    PLUGIN *        GetPlugin();
-    const std::string & GetFileName() const { return pluginFileName; }
+    bool            IsRunning() { return m_plugin.IsRunning(); }
 
-    int             Load();
-    int             Unload();
+    const std::string& GetStrError() const { return errorStr; }
+    Plugin& GetPlugin() { return m_plugin; }
+    const std::string& GetFileName() const { return pluginFileName; }
+    const std::string& GetName() const { return pluginName; }
 
-    uint16_t        GetStartPosition() const { return plugin->GetStartPosition(); }
-    uint16_t        GetStopPosition() const { return plugin->GetStopPosition(); }
+    uint16_t        GetStartPosition() const { return m_plugin.GetStartPosition(); }
+    uint16_t        GetStopPosition() const { return m_plugin.GetStopPosition(); }
 
 private:
-    std::string     pluginFileName;
-    std::string     pluginSettingFileName;
-
-    PLUGIN *        plugin;
-    bool            isPluginLoaded;
-    std::string     errorStr;
-
-    void *          libHandle;
-    bool            isRunning;
-
-    ADMINS_IMPL *   admins;
-    TARIFFS_IMPL *  tariffs;
-    USERS_IMPL *    users;
-    STORE *         store;
-    TRAFFCOUNTER *  traffCnt;
-    const SETTINGS_IMPL * stgSettings;
-    MODULE_SETTINGS modSettings;
+    Plugin & load(const ModuleSettings& ms,
+                  Admins& admins,
+                  Tariffs& tariffs,
+                  Users& users,
+                  Services& services,
+                  Corporations& corporations,
+                  TraffCounter& traffcounter,
+                  Store& store,
+                  const Settings& settings);
+
+    std::string pluginFileName;
+    std::string pluginName;
+    void*       libHandle;
+
+    Plugin&     m_plugin;
+    std::string errorStr;
 };
 //-----------------------------------------------------------------------------
-#endif //PLUGIN_RUNNER_H
+}