From 7d5f055547e70fa93ee9ac944e62f8d657b9dc55 Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 19 Oct 2018 08:36:44 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libjin/Common/je_subsystem.hpp | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/libjin/Common/je_subsystem.hpp (limited to 'src/libjin/Common/je_subsystem.hpp') diff --git a/src/libjin/Common/je_subsystem.hpp b/src/libjin/Common/je_subsystem.hpp new file mode 100644 index 0000000..2875058 --- /dev/null +++ b/src/libjin/Common/je_subsystem.hpp @@ -0,0 +1,44 @@ +#ifndef __LIBJIN_COMMON_SUBSYSTEM_H +#define __LIBJIN_COMMON_SUBSYSTEM_H + +#include "../utils/je_macros.h" + +#include "je_singleton.hpp" + +namespace jin +{ + + template + class Subsystem : public Singleton + { + public: + struct Setting {}; + typedef Setting SettingBase; + + bool init(const SettingBase* setting = nullptr) + { + static bool success = initSystem(setting); + return success; + } + + void quit() + { + /*call only once*/ + static char __dummy__ = (quitSystem(), 1); + Singleton::destroy(); + } + + protected: + singleton(System); + + Subsystem() {}; + virtual ~Subsystem() {}; + + /*onlyonce*/ virtual bool initSystem(const Setting* setting) = 0; + /*onlyonce*/ virtual void quitSystem() = 0; + + }; + +} // namespace jin + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0