aboutsummaryrefslogtreecommitdiff
path: root/src/libparsec/include/e_modulemanager.h
blob: 40b1dbb5fb3f90a2d511523ddab37c226185adf8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef E_MODULEMANAGER_H_
#define E_MODULEMANAGER_H_

// ----------------------------------------------------------------------------
//
#define TheModuleManager (E_ModuleManager::GetModuleManager())

// forward decls --------------------------------------------------------------
//
class E_Module;

// ----------------------------------------------------------------------------
//
typedef UTL_listentry_s<E_Module*>	LE_Module;

// ----------------------------------------------------------------------------
//
class E_ModuleManager {
protected:
	UTL_List<E_Module*>	m_Modules;

protected:
	// register the console commands for managing modules
	void _RegisterConsoleCommand() const;

	E_ModuleManager() 
	{
		_RegisterConsoleCommand();
	};
	~E_ModuleManager() 
	{ 
		KillAllModules(); 
		m_Modules.RemoveAll();
	};

public:
	// SINGLETON access
	static E_ModuleManager* GetModuleManager()
	{
		static E_ModuleManager _TheModuleManager;
		return &_TheModuleManager;
	}

	// register a module
	void RegisterModule( E_Module* pModule );

	// unregister a module
	void UnregisterModule( E_Module* pModule );

	// init all registered modules ( constructor )
	void InitAllModules();

	// kill all registered modules ( destructor )
	void KillAllModules();

	// list all loaded modules in the console
	void ListAll() const;
};

// ----------------------------------------------------------------------------
//
class E_Module 
{
protected:
	char m_szName[ 256 ];
public:
	E_Module( const char* pszName );
	virtual void Init() = 0;
	virtual void Kill() = 0;
	const char* GetName() const { return m_szName; }
};

// module registration macros (automatic module-init/deinit on startup) -------
//
#define REGISTER_MODULE( f )			class E_Module_##f : public E_Module \
										{ public: E_Module_##f( const char* pszName ) : E_Module( pszName ) {}; void Init(); void Kill() {}; } \
										inst_##f( #f ); \
										void E_Module_##f::Init()
										
#define REGISTER_MODULE_INIT( f )		class E_Module_##f : public E_Module \
										{ public: E_Module_##f( const char* pszName ) : E_Module( pszName ) {}; void Init(); void Kill(); } \
										inst_##f( #f ); \
										void E_Module_##f::Init()

#define REGISTER_MODULE_KILL(f)			void E_Module_##f::Kill()

#endif // E_MODULEMANAGER_H_