aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/common/subsystem.hpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-01-12 21:48:33 +0800
committerchai <chaifix@163.com>2019-01-12 21:48:33 +0800
commit8b00d67febf133e89f6a0bfabc41feed555dc4a9 (patch)
treefe48ef17c250afa40c2588300fcdb5920dba6951 /src/libjin/common/subsystem.hpp
parenta907c39756ef6b368d06643afa491c49a9044a8e (diff)
*去掉文件前缀je_
Diffstat (limited to 'src/libjin/common/subsystem.hpp')
-rw-r--r--src/libjin/common/subsystem.hpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/libjin/common/subsystem.hpp b/src/libjin/common/subsystem.hpp
new file mode 100644
index 0000000..9828c40
--- /dev/null
+++ b/src/libjin/common/subsystem.hpp
@@ -0,0 +1,74 @@
+#ifndef __JE_COMMON_SUBSYSTEM_H__
+#define __JE_COMMON_SUBSYSTEM_H__
+
+#include "../utils/macros.h"
+
+#include "singleton.hpp"
+
+namespace JinEngine
+{
+
+ ///
+ /// Subsystem class.
+ ///
+ template<class System>
+ class Subsystem : public Singleton<System>
+ {
+ public:
+ ///
+ /// Subsystem setting.
+ ///
+ struct Setting
+ {
+ };
+
+ typedef Setting SettingBase;
+
+ ///
+ /// Initialize subsystem.
+ ///
+ /// @param setting Subsystem setting.
+ /// @return True if initialize sucessful, otherwise return false.
+ ///
+ bool start(const SettingBase* setting = nullptr)
+ {
+ static bool success = startSystem(setting);
+ return success;
+ }
+
+ ///
+ /// Quit subsystem.
+ ///
+ void quit()
+ {
+ // Call only once.
+ static char __dummy__ = (quitSystem(), 1);
+ Singleton<System>::destroy();
+ }
+
+ ///
+ /// Subsystem constructor.
+ ///
+ Subsystem() {};
+
+ ///
+ /// Subsystem destructor.
+ ///
+ virtual ~Subsystem() {}
+
+ protected:
+ ///
+ /// Initializer callback.
+ ///
+ virtual bool startSystem(const Setting* setting) = 0;
+
+ ///
+ /// Quit subsystem callback.
+ ///
+ virtual void quitSystem() = 0;
+
+ };
+
+} // namespace JinEngine
+
+#endif \ No newline at end of file