Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: ae78260d06d86dbcf252b1f8c2b6f5232b2e7566 (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
88
89
90
91
92
93
/*
   core/module.cc
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#include "core/module.h"
#include "sys/sys.h"

namespace core
{

/*-- static functions ----------------------------------------------*/

Module *Module::module_preload = 0;
Module::Registry Module::module_registry;

Module *Module::find(std::string const &name)
{
	Registry::iterator it = module_registry.find(name);
	if (it == module_registry.end())
		return 0;
	else
		return (*it).second;
}

Module *Module::find(const char *name)
{
	return(find(std::string(name)));
}

Module *Module::add(const char *name, Module *module)
{
	Module *m = find(name);
	if (m) {
		con_warn << "module '" << name << "' already loaded!" << std::endl;
		delete module;
		return 0;
	}
	module_registry[std::string(name)] = module;
	module->module_label.assign(name);
	if (!module_preload) {
		module_preload = module;
		con_debug << "  " << name << " " << module->name() << std::endl;
	}
	return module;
}

Module *Module::load(const char *name)
{
	Module *module = find(name);
	if (!module) {
		con_warn << "could not find module '" << name << "'" << std::endl;
		return 0;
	}

	con_debug << "  " << name << " " << module->name() << std::endl;
	module_preload = module;
	return module;
}

void Module::clear()
{
	for (Registry::iterator it = module_registry.begin(); it != module_registry.end(); it++) {
		Module *module = (*it).second;
		delete module;
	}
	
	module_registry.clear();
	module_preload = 0;
}

/*-- instance functions --------------------------------------------*/

Module::Module(const char *name) :
	module_name(name)
{
	module_running = false;
	module_interactive = true;
}

Module::~Module()
{
	module_running = false;
	module_name.clear();
}

void Module::abort()
{
	module_running = false;
}

}