src/driver.h
author Tero Marttila <terom@fixme.fi>
Tue, 22 Jul 2008 23:20:33 +0300
changeset 11184 88c967f1422b
parent 11062 19abd15f7cf8
permissions -rw-r--r--
add an empty bin/cache dir
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2171
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2171
diff changeset
     2
10429
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9340
diff changeset
     3
/** @file driver.h Base for all drivers (video, sound, music, etc). */
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5726
diff changeset
     4
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     5
#ifndef DRIVER_H
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     6
#define DRIVER_H
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     7
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
     8
#include "debug.h"
8608
45d77f05d3a3 (svn r11673) -Codechange: move the overflow safe type to a separate file.
rubidium
parents: 8547
diff changeset
     9
#include "core/enum_type.hpp"
8710
52015340050c (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8608
diff changeset
    10
#include "string_func.h"
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    11
#include <map>
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    12
7814
fe643468ad64 (svn r10673) -Cleanup: some assorted style cleanups. Primarily type* var -> type *var.
rubidium
parents: 7750
diff changeset
    13
bool GetDriverParamBool(const char * const *parm, const char *name);
fe643468ad64 (svn r10673) -Cleanup: some assorted style cleanups. Primarily type* var -> type *var.
rubidium
parents: 7750
diff changeset
    14
int GetDriverParamInt(const char * const *parm, const char *name, int def);
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    15
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    16
class Driver {
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    17
public:
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    18
	virtual const char *Start(const char * const *parm) = 0;
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    19
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    20
	virtual void Stop() = 0;
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    21
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    22
	virtual ~Driver() { }
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    23
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    24
	enum Type {
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    25
		DT_BEGIN = 0,
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    26
		DT_SOUND = 0,
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    27
		DT_MUSIC,
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    28
		DT_VIDEO,
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    29
		DT_END,
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    30
	};
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    31
};
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    32
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    33
DECLARE_POSTFIX_INCREMENT(Driver::Type);
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    34
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    35
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    36
class DriverFactoryBase {
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    37
private:
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    38
	Driver::Type type;
11062
19abd15f7cf8 (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 10911
diff changeset
    39
	const char *name;
7689
011afceb33b5 (svn r10471) -Codechange: implement driver probing priority so that 'preferred' drivers are loaded first
peter1138
parents: 7666
diff changeset
    40
	int priority;
11062
19abd15f7cf8 (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 10911
diff changeset
    41
19abd15f7cf8 (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 10911
diff changeset
    42
	struct StringCompare {
19abd15f7cf8 (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 10911
diff changeset
    43
		bool operator () (const char *a, const char *b) const
19abd15f7cf8 (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 10911
diff changeset
    44
		{
19abd15f7cf8 (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 10911
diff changeset
    45
			return strcmp(a, b) < 0;
19abd15f7cf8 (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 10911
diff changeset
    46
		}
19abd15f7cf8 (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 10911
diff changeset
    47
	};
19abd15f7cf8 (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 10911
diff changeset
    48
19abd15f7cf8 (svn r13619) -Codechange: use 'const char *' instead of std::string for blitter and driver names
smatz
parents: 10911
diff changeset
    49
	typedef std::map<const char *, DriverFactoryBase *, StringCompare> Drivers;
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    50
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    51
	static Drivers &GetDrivers()
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    52
	{
10582
412f937a27d9 (svn r13126) -Fix (r13022) [FS#2009, FS#2010]: driver list should be dynamically allocated as static uninitialistion order is undetermined. The list is freed when the latest driver is removed.
glx
parents: 10479
diff changeset
    53
		static Drivers &s_drivers = *new Drivers();
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    54
		return s_drivers;
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    55
	}
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    56
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    57
	static Driver **GetActiveDriver(Driver::Type type)
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    58
	{
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    59
		static Driver *s_driver[3] = { NULL, NULL, NULL };
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    60
		return &s_driver[type];
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    61
	}
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    62
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    63
	static const char *GetDriverTypeName(Driver::Type type)
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    64
	{
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    65
		static const char *driver_type_name[] = { "sound", "music", "video" };
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    66
		return driver_type_name[type];
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    67
	}
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    68
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    69
protected:
9340
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8710
diff changeset
    70
	void RegisterDriver(const char *name, Driver::Type type, int priority);
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    71
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    72
public:
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    73
	DriverFactoryBase() :
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    74
		name(NULL)
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    75
	{}
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    76
10911
dc3cb3bb6113 (svn r13462) -Codechange: move DriverFactoryBase destructor definition from header file (saves ~16kB)
smatz
parents: 10582
diff changeset
    77
	virtual ~DriverFactoryBase();
10479
d1ab1e4b6cf8 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 10429
diff changeset
    78
d1ab1e4b6cf8 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 10429
diff changeset
    79
	/** Shuts down all active drivers
d1ab1e4b6cf8 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 10429
diff changeset
    80
	 */
d1ab1e4b6cf8 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 10429
diff changeset
    81
	static void ShutdownDrivers()
d1ab1e4b6cf8 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 10429
diff changeset
    82
	{
d1ab1e4b6cf8 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 10429
diff changeset
    83
		for (Driver::Type dt = Driver::DT_BEGIN; dt < Driver::DT_END; dt++) {
d1ab1e4b6cf8 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 10429
diff changeset
    84
			Driver *driver = *GetActiveDriver(dt);
d1ab1e4b6cf8 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 10429
diff changeset
    85
			if (driver != NULL) driver->Stop();
d1ab1e4b6cf8 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 10429
diff changeset
    86
		}
d1ab1e4b6cf8 (svn r13022) -Fix: driver list wasn't freed, replace by statically allocated one
smatz
parents: 10429
diff changeset
    87
	}
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    88
9340
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8710
diff changeset
    89
	static const Driver *SelectDriver(const char *name, Driver::Type type);
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8710
diff changeset
    90
	static char *GetDriversInfo(char *p, const char *last);
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    91
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    92
	/**
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    93
	 * Get a nice description of the driver-class.
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    94
	 */
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    95
	virtual const char *GetDescription() = 0;
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    96
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    97
	/**
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    98
	 * Create an instance of this driver-class.
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
    99
	 */
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
   100
	virtual Driver *CreateInstance() = 0;
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 6451
diff changeset
   101
};
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
   102
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2186
diff changeset
   103
#endif /* DRIVER_H */