tron@2186: /* $Id$ */ tron@2186: richk@10724: /** @file driver.h Base for all drivers (video, sound, music, etc). */ belugas@6451: tron@2171: #ifndef DRIVER_H tron@2171: #define DRIVER_H tron@2171: richk@6720: #include "debug.h" rubidium@6872: #include "core/enum_type.hpp" rubidium@6872: #include "string_func.h" richk@6720: #include richk@6720: #include tron@2171: richk@6743: bool GetDriverParamBool(const char * const *parm, const char *name); richk@6743: int GetDriverParamInt(const char * const *parm, const char *name, int def); tron@2171: richk@6720: class Driver { richk@6720: public: richk@6720: virtual const char *Start(const char * const *parm) = 0; richk@6720: richk@6720: virtual void Stop() = 0; richk@6720: richk@6720: virtual ~Driver() { } richk@6720: richk@6720: enum Type { richk@6720: DT_BEGIN = 0, richk@6720: DT_SOUND = 0, richk@6720: DT_MUSIC, richk@6720: DT_VIDEO, richk@6720: DT_END, richk@6720: }; richk@6720: }; richk@6720: richk@6720: DECLARE_POSTFIX_INCREMENT(Driver::Type); richk@6720: richk@6720: richk@6720: class DriverFactoryBase { richk@6720: private: richk@6720: Driver::Type type; richk@6720: char *name; richk@6720: int priority; richk@6720: typedef std::map Drivers; richk@6720: richk@6720: static Drivers &GetDrivers() richk@6720: { richk@6720: static Drivers &s_drivers = *new Drivers(); richk@6720: return s_drivers; richk@6720: } richk@6720: richk@6720: static Driver **GetActiveDriver(Driver::Type type) richk@6720: { richk@6720: static Driver *s_driver[3] = { NULL, NULL, NULL }; richk@6720: return &s_driver[type]; richk@6720: } richk@6720: richk@6720: static const char *GetDriverTypeName(Driver::Type type) richk@6720: { richk@6720: static const char *driver_type_name[] = { "sound", "music", "video" }; richk@6720: return driver_type_name[type]; richk@6720: } richk@6720: richk@6720: protected: richk@10184: void RegisterDriver(const char *name, Driver::Type type, int priority); richk@6720: richk@6720: public: richk@6720: DriverFactoryBase() : richk@6720: name(NULL) richk@6720: {} richk@6720: richk@10994: virtual ~DriverFactoryBase(); richk@10724: richk@10724: /** Shuts down all active drivers richk@10724: */ richk@10724: static void ShutdownDrivers() richk@10724: { richk@10724: for (Driver::Type dt = Driver::DT_BEGIN; dt < Driver::DT_END; dt++) { richk@10724: Driver *driver = *GetActiveDriver(dt); richk@10724: if (driver != NULL) driver->Stop(); richk@10724: } richk@10724: } richk@6720: richk@10184: static const Driver *SelectDriver(const char *name, Driver::Type type); richk@10184: static char *GetDriversInfo(char *p, const char *last); richk@6720: richk@6720: /** richk@6720: * Get a nice description of the driver-class. richk@6720: */ richk@6720: virtual const char *GetDescription() = 0; richk@6720: richk@6720: /** richk@6720: * Create an instance of this driver-class. richk@6720: */ richk@6720: virtual Driver *CreateInstance() = 0; richk@6720: }; tron@2171: Darkvater@2436: #endif /* DRIVER_H */