-
Notifications
You must be signed in to change notification settings - Fork 47
/
ModuleRegistry.h
102 lines (72 loc) · 2.89 KB
/
ModuleRegistry.h
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#pragma once
#include <map>
#include <list>
#include "imodule.h"
#include "ModuleLoader.h"
namespace module
{
/** greebo: This is the actual implementation of the ModuleRegistry as defined in imodule.h.
* See the imodule.h file for a detailed documentation of the public methods.
*/
class ModuleRegistry :
public IModuleRegistry
{
private:
typedef std::map<std::string, RegisterableModulePtr> ModulesMap;
// This is where the uninitialised modules go after registration
ModulesMap _uninitialisedModules;
// After initialisiation, modules get enlisted here.
ModulesMap _initialisedModules;
// Set to TRUE as soon as initialiseModules() is finished
bool _modulesInitialised;
// Set to TRUE after all modules have been shutdown
bool _modulesShutdown;
// Pointer to the application context
ApplicationContext* _context;
// For progress meter in the splash screen
float _progress;
// Signals fired after ALL modules have been initialised or shut down.
sigc::signal<void> _sigAllModulesInitialised;
sigc::signal<void> _sigAllModulesUninitialised;
ProgressSignal _sigModuleInitialisationProgress;
// Dynamic library loader
ModuleLoader _loader;
// Private constructor
ModuleRegistry();
public:
~ModuleRegistry();
// Registers the given module
void registerModule(const RegisterableModulePtr& module) override;
// Initialise all registered modules
void loadAndInitialiseModules() override;
// Shutdown all modules
void shutdownModules() override;
// Get the module
RegisterableModulePtr getModule(const std::string& name) const override;
// Returns TRUE if the named module exists in the records
bool moduleExists(const std::string& name) const override;
// Get the application context info structure
const ApplicationContext& getApplicationContext() const override;
sigc::signal<void> signal_allModulesInitialised() const override;
ProgressSignal signal_moduleInitialisationProgress() const override;
sigc::signal<void> signal_allModulesUninitialised() const override;
std::size_t getCompatibilityLevel() const override;
/// Invoked by RadiantApp to set the application context
void setContext(ApplicationContext& context)
{
_context = &context;
}
// Contains the singleton instance
static ModuleRegistry& Instance();
// Returns a list of modules
std::string getModuleList(const std::string& separator = "\n");
private:
// greebo: Frees all the allocated RegisterableModules. This MUST happen before
// the main() routine has reached the end of scope, because on some
// systems (Win32) the DLLs get unloaded before the static ModuleRegistry
// is destructed - the shared_ptrs don't work anymore and are causing double-deletes.
void unloadModules();
// Initialises the module (including dependencies, recursively).
void initialiseModuleRecursive(const std::string& name);
}; // class Registry
} // namespace module