driver.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef DRIVER_H
00013 #define DRIVER_H
00014
00015 #include "core/enum_type.hpp"
00016 #include "core/string_compare_type.hpp"
00017 #include <map>
00018
00019 const char *GetDriverParam(const char * const *parm, const char *name);
00020 bool GetDriverParamBool(const char * const *parm, const char *name);
00021 int GetDriverParamInt(const char * const *parm, const char *name, int def);
00022
00024 class Driver {
00025 public:
00031 virtual const char *Start(const char * const *parm) = 0;
00032
00036 virtual void Stop() = 0;
00037
00038 virtual ~Driver() { }
00039
00041 enum Type {
00042 DT_BEGIN = 0,
00043 DT_MUSIC = 0,
00044 DT_SOUND,
00045 DT_VIDEO,
00046 DT_END,
00047 };
00048
00053 virtual const char *GetName() const = 0;
00054 };
00055
00056 DECLARE_POSTFIX_INCREMENT(Driver::Type)
00057
00058
00059
00060 class DriverFactoryBase {
00061 private:
00062 Driver::Type type;
00063 const char *name;
00064 int priority;
00065
00066 typedef std::map<const char *, DriverFactoryBase *, StringCompare> Drivers;
00067
00071 static Drivers &GetDrivers()
00072 {
00073 static Drivers &s_drivers = *new Drivers();
00074 return s_drivers;
00075 }
00076
00082 static Driver **GetActiveDriver(Driver::Type type)
00083 {
00084 static Driver *s_driver[3] = { NULL, NULL, NULL };
00085 return &s_driver[type];
00086 }
00087
00093 static const char *GetDriverTypeName(Driver::Type type)
00094 {
00095 static const char * const driver_type_name[] = { "music", "sound", "video" };
00096 return driver_type_name[type];
00097 }
00098
00099 protected:
00100 void RegisterDriver(const char *name, Driver::Type type, int priority);
00101
00102 public:
00103 DriverFactoryBase() :
00104 name(NULL)
00105 {}
00106
00107 virtual ~DriverFactoryBase();
00108
00112 static void ShutdownDrivers()
00113 {
00114 for (Driver::Type dt = Driver::DT_BEGIN; dt < Driver::DT_END; dt++) {
00115 Driver *driver = *GetActiveDriver(dt);
00116 if (driver != NULL) driver->Stop();
00117 }
00118 }
00119
00120 static Driver *SelectDriver(const char *name, Driver::Type type);
00121 static char *GetDriversInfo(char *p, const char *last);
00122
00127 virtual const char *GetDescription() = 0;
00128
00133 virtual Driver *CreateInstance() = 0;
00134 };
00135
00136 #endif