1
/* $Id: driver.h 20283 2010-08-01 19:22:34Z frosch $ */
4
* This file is part of OpenTTD.
5
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10
/** @file driver.h Base for all drivers (video, sound, music, etc). */
15
#include "core/enum_type.hpp"
16
#include "core/string_compare_type.hpp"
19
const char *GetDriverParam(const char * const *parm, const char *name);
20
bool GetDriverParamBool(const char * const *parm, const char *name);
21
int GetDriverParamInt(const char * const *parm, const char *name, int def);
25
virtual const char *Start(const char * const *parm) = 0;
27
virtual void Stop() = 0;
31
/** The type of driver */
33
DT_BEGIN = 0, ///< Helper for iteration
34
DT_MUSIC = 0, ///< A music driver, needs to be before sound to properly shut down extmidi forked music players
35
DT_SOUND, ///< A sound driver
36
DT_VIDEO, ///< A video driver
37
DT_END, ///< Helper for iteration
40
virtual const char *GetName() const = 0;
43
DECLARE_POSTFIX_INCREMENT(Driver::Type)
46
class DriverFactoryBase {
52
typedef std::map<const char *, DriverFactoryBase *, StringCompare> Drivers;
54
static Drivers &GetDrivers()
56
static Drivers &s_drivers = *new Drivers();
60
static Driver **GetActiveDriver(Driver::Type type)
62
static Driver *s_driver[3] = { NULL, NULL, NULL };
63
return &s_driver[type];
66
static const char *GetDriverTypeName(Driver::Type type)
68
static const char * const driver_type_name[] = { "music", "sound", "video" };
69
return driver_type_name[type];
73
void RegisterDriver(const char *name, Driver::Type type, int priority);
80
virtual ~DriverFactoryBase();
83
* Shuts down all active drivers
85
static void ShutdownDrivers()
87
for (Driver::Type dt = Driver::DT_BEGIN; dt < Driver::DT_END; dt++) {
88
Driver *driver = *GetActiveDriver(dt);
89
if (driver != NULL) driver->Stop();
93
static Driver *SelectDriver(const char *name, Driver::Type type);
94
static char *GetDriversInfo(char *p, const char *last);
97
* Get a nice description of the driver-class.
99
virtual const char *GetDescription() = 0;
102
* Create an instance of this driver-class.
104
virtual Driver *CreateInstance() = 0;
107
#endif /* DRIVER_H */