File: ModuleRegistry.h

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (106 lines) | stat: -rw-r--r-- 3,293 bytes parent folder | download | duplicates (3)
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
103
104
105
106
#pragma once

#include <map>
#include <list>
#include "imodule.h"

namespace module 
{

class ModuleLoader;

/** 
 * greebo: Implementation of the IModuleRegistry interface defined in imodule.h.
 * It stores and manages the lifecycle of all modules in DarkRadiant.
 * 
 * Use the registerModule() method to add new modules, which will be initialised
 * during the startup phase, resolving the module dependencies on the go.
 */
class ModuleRegistry :
	public IModuleRegistry
{
private:
	// application context
	const IApplicationContext& _context;

    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;

	// 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;
	sigc::signal<void> _sigModulesUnloading;
	sigc::signal<void> _sigModulesUninitialising;
	ProgressSignal _sigModuleInitialisationProgress;

	// Dynamic library loader
	std::unique_ptr<ModuleLoader> _loader;

public:
	ModuleRegistry(const IApplicationContext& ctx);

    ~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 IApplicationContext& getApplicationContext() const override;

	applog::ILogWriter& getApplicationLogWriter() override;

    sigc::signal<void>& signal_allModulesInitialised() override;
	ProgressSignal& signal_moduleInitialisationProgress() override;
    sigc::signal<void>& signal_modulesUninitialising() override;
    sigc::signal<void>& signal_allModulesUninitialised() override;
    sigc::signal<void>& signal_modulesUnloading() override;

	std::size_t getCompatibilityLevel() const override;

	// Returns a list of modules
	std::string getModuleList(const std::string& separator = "\n");

	// Special handling for the radiant core module which we want to be
	// ready and initialised by the time it is created.
	void initialiseCoreModule();

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