2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file driver.h Base for all drivers (video, sound, music, etc). */
|
2007-02-23 18:55:07 +00:00
|
|
|
|
2005-07-23 15:16:57 +00:00
|
|
|
#ifndef DRIVER_H
|
|
|
|
#define DRIVER_H
|
|
|
|
|
2007-12-21 08:34:53 +00:00
|
|
|
#include "core/enum_type.hpp"
|
2009-02-03 18:08:07 +00:00
|
|
|
#include "core/string_compare_type.hpp"
|
2008-01-07 14:23:25 +00:00
|
|
|
#include "string_func.h"
|
2007-07-05 12:23:54 +00:00
|
|
|
#include <map>
|
2005-07-23 15:16:57 +00:00
|
|
|
|
2009-01-08 11:40:42 +00:00
|
|
|
const char *GetDriverParam(const char * const *parm, const char *name);
|
2007-07-24 17:01:23 +00:00
|
|
|
bool GetDriverParamBool(const char * const *parm, const char *name);
|
|
|
|
int GetDriverParamInt(const char * const *parm, const char *name, int def);
|
2005-07-23 15:16:57 +00:00
|
|
|
|
2007-07-05 12:23:54 +00:00
|
|
|
class Driver {
|
|
|
|
public:
|
|
|
|
virtual const char *Start(const char * const *parm) = 0;
|
|
|
|
|
|
|
|
virtual void Stop() = 0;
|
|
|
|
|
|
|
|
virtual ~Driver() { }
|
|
|
|
|
|
|
|
enum Type {
|
|
|
|
DT_BEGIN = 0,
|
|
|
|
DT_SOUND = 0,
|
|
|
|
DT_MUSIC,
|
|
|
|
DT_VIDEO,
|
|
|
|
DT_END,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
DECLARE_POSTFIX_INCREMENT(Driver::Type);
|
|
|
|
|
|
|
|
|
|
|
|
class DriverFactoryBase {
|
|
|
|
private:
|
|
|
|
Driver::Type type;
|
2008-06-24 09:15:45 +00:00
|
|
|
const char *name;
|
2007-07-07 20:31:23 +00:00
|
|
|
int priority;
|
2008-06-24 09:15:45 +00:00
|
|
|
|
|
|
|
typedef std::map<const char *, DriverFactoryBase *, StringCompare> Drivers;
|
2007-07-05 12:23:54 +00:00
|
|
|
|
|
|
|
static Drivers &GetDrivers()
|
|
|
|
{
|
2008-05-16 21:32:10 +00:00
|
|
|
static Drivers &s_drivers = *new Drivers();
|
2007-07-05 12:23:54 +00:00
|
|
|
return s_drivers;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Driver **GetActiveDriver(Driver::Type type)
|
|
|
|
{
|
|
|
|
static Driver *s_driver[3] = { NULL, NULL, NULL };
|
|
|
|
return &s_driver[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *GetDriverTypeName(Driver::Type type)
|
|
|
|
{
|
|
|
|
static const char *driver_type_name[] = { "sound", "music", "video" };
|
|
|
|
return driver_type_name[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2008-04-06 16:49:02 +00:00
|
|
|
void RegisterDriver(const char *name, Driver::Type type, int priority);
|
2007-07-05 12:23:54 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
DriverFactoryBase() :
|
|
|
|
name(NULL)
|
|
|
|
{}
|
|
|
|
|
2008-06-11 12:46:28 +00:00
|
|
|
virtual ~DriverFactoryBase();
|
2008-05-08 23:26:17 +00:00
|
|
|
|
|
|
|
/** Shuts down all active drivers
|
|
|
|
*/
|
|
|
|
static void ShutdownDrivers()
|
|
|
|
{
|
|
|
|
for (Driver::Type dt = Driver::DT_BEGIN; dt < Driver::DT_END; dt++) {
|
|
|
|
Driver *driver = *GetActiveDriver(dt);
|
|
|
|
if (driver != NULL) driver->Stop();
|
|
|
|
}
|
|
|
|
}
|
2007-07-05 12:23:54 +00:00
|
|
|
|
2008-04-06 16:49:02 +00:00
|
|
|
static const Driver *SelectDriver(const char *name, Driver::Type type);
|
|
|
|
static char *GetDriversInfo(char *p, const char *last);
|
2007-07-05 12:23:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a nice description of the driver-class.
|
|
|
|
*/
|
|
|
|
virtual const char *GetDescription() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an instance of this driver-class.
|
|
|
|
*/
|
|
|
|
virtual Driver *CreateInstance() = 0;
|
|
|
|
};
|
2005-07-23 15:16:57 +00:00
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
#endif /* DRIVER_H */
|