summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/osdmodule.cpp
blob: 45664295cfba2504275e3c2465d22c61e61b0a2a (plain) (blame)
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
107
108
109
110
111
112
113
114
115
116
// license:BSD-3-Clause
// copyright-holders:Couriersud
/*
 * osdmodule.c
 *
 */

#include "modules/osdmodule.h"

osd_module_manager::osd_module_manager()
{
	for (int i=0; i<MAX_MODULES; i++)
	{
		m_modules[i]  = nullptr;
		m_selected[i] = nullptr;
	}
}
osd_module_manager::~osd_module_manager()
{
	for (int i = 0; m_modules[i] != nullptr; i++)
	{
		global_free(m_modules[i]);
	}
}

void osd_module_manager::register_module(const module_type &mod_type)
{
	osd_module *module = mod_type();
	if (module->probe())
	{
		osd_printf_verbose("===> registered module %s %s\n", module->name(), module->type());

		int i;
		for (i = 0; i < MAX_MODULES && m_modules[i] != nullptr; i++)
			;

		assert_always(i < MAX_MODULES, "Module registration beyond MAX_MODULES!");
		m_modules[i] = module;
	}
	else
	{
		osd_printf_verbose("===> not supported %s %s\n", module->name(), module->type());
		global_free(module);
	}
}

bool osd_module_manager::type_has_name(const char *type, const char *name) const
{
	return (get_module_index(type, name) >= 0);
}

osd_module *osd_module_manager::get_module_generic(const char *type, const char *name)
{
	int i = get_module_index(type, name);
	if (i>=0)
		return m_modules[i];
	else
		return nullptr;
}

osd_module *osd_module_manager::select_module(const char *type, const char *name)
{
	osd_module *m = get_module_generic(type, name);

	// FIXME: check if already exists!
	int i;
	for (i = 0; m_selected[i] != nullptr; i++)
		;
	m_selected[i] = m;
	return m;
}

void osd_module_manager::init(const osd_options &options)
{
	for (int i = 0; m_selected[i] != nullptr; i++)
	{
		m_selected[i]->init(options);
	}
}

void osd_module_manager::exit()
{
	// Find count
	int cnt;
	for (cnt = 0; m_selected[cnt] != nullptr; cnt++)
		;
	for (int i = cnt - 1; i >= 0; i--)
	{
		m_selected[i]->exit();
		m_selected[i] = nullptr;
	}
}

int osd_module_manager::get_module_index(const char *type, const char *name) const
{
	for (int i = 0; m_modules[i] != nullptr; i++)
	{
		if (strcmp(m_modules[i]->type(), type) == 0 && ((name[0] == 0) || (strcmp(name, m_modules[i]->name())==0)))
			return i;
	}
	return -1;
}

void osd_module_manager::get_module_names(const char *type, const int max, int *num, const char *names[]) const
{
	*num = 0;
	for (int i = 0; m_modules[i] != nullptr; i++)
	{
		if ((strcmp(m_modules[i]->type(), type) == 0) && (*num < max))
		{
			names[*num] = m_modules[i]->name();
			*num = *num + 1;
		}

	}
}