(svn r10471) -Codechange: implement driver probing priority so that 'preferred' drivers are loaded first

This commit is contained in:
peter1138 2007-07-07 20:31:23 +00:00
parent 855e9d0751
commit 2723db2884
21 changed files with 39 additions and 55 deletions

View File

@ -16,8 +16,6 @@ int GetDriverParamInt(const char* const* parm, const char* name, int def);
class Driver {
public:
virtual bool CanProbe() = 0;
virtual const char *Start(const char * const *parm) = 0;
virtual void Stop() = 0;
@ -40,6 +38,7 @@ class DriverFactoryBase {
private:
Driver::Type type;
char *name;
int priority;
typedef std::map<std::string, DriverFactoryBase *> Drivers;
static Drivers &GetDrivers()
@ -66,13 +65,14 @@ protected:
* @param name the name of the driver.
* @note an assert() will be trigger if 2 driver with the same name try to register.
*/
void RegisterDriver(const char *name, Driver::Type type)
void RegisterDriver(const char *name, Driver::Type type, int priority)
{
/* Don't register nameless Drivers */
if (name == NULL) return;
this->name = strdup(name);
this->type = type;
this->priority = priority;
/* Prefix the name with driver type to make it unique */
char buf[32];
@ -101,17 +101,16 @@ public:
if (*name == '\0') {
/* Probe for this driver */
Drivers::iterator it = GetDrivers().begin();
for (; it != GetDrivers().end(); ++it) {
DriverFactoryBase *d = (*it).second;
for (int priority = 10; priority >= 0; priority--) {
Drivers::iterator it = GetDrivers().begin();
for (; it != GetDrivers().end(); ++it) {
DriverFactoryBase *d = (*it).second;
/* Check driver type */
if (d->type != type) continue;
/* Check driver type */
if (d->type != type) continue;
if (d->priority != priority) continue;
Driver *newd = d->CreateInstance();
if (!newd->CanProbe()) {
DEBUG(driver, 1, "Skipping probe of driver '%s'", d->name);
} else {
Driver *newd = d->CreateInstance();
const char *err = newd->Start(NULL);
if (err == NULL) {
DEBUG(driver, 1, "Successfully probed %s driver '%s'", GetDriverTypeName(type), d->name);
@ -121,9 +120,8 @@ public:
}
DEBUG(driver, 1, "Probing %s driver '%s' failed with error: %s", GetDriverTypeName(type), d->name, err);
delete newd;
}
delete newd;
}
error("Couldn't find any suitable %s driver", GetDriverTypeName(type));
} else {
@ -185,10 +183,14 @@ public:
for (Driver::Type type = Driver::DT_BEGIN; type != Driver::DT_END; type++) {
p += snprintf(p, last - p, "List of %s drivers:\n", GetDriverTypeName(type));
Drivers::iterator it = GetDrivers().begin();
for (; it != GetDrivers().end(); it++) {
DriverFactoryBase *d = (*it).second;
if (d->type == type) p += snprintf(p, last - p, "%18s: %s\n", d->name, d->GetDescription());
for (int priority = 10; priority >= 0; priority--) {
Drivers::iterator it = GetDrivers().begin();
for (; it != GetDrivers().end(); it++) {
DriverFactoryBase *d = (*it).second;
if (d->type != type) continue;
if (d->priority != priority) continue;
p += snprintf(p, last - p, "%18s: %s\n", d->name, d->GetDescription());
}
}
p += snprintf(p, last - p, "\n");

View File

@ -7,8 +7,6 @@
class MusicDriver_BeMidi: public MusicDriver {
public:
/* virtual */ bool CanProbe() { return true; }
/* virtual */ const char *Start(const char * const *param);
/* virtual */ void Stop();
@ -24,6 +22,7 @@ public:
class FMusicDriver_BeMidi: public MusicDriverFactory<FMusicDriver_BeMidi> {
public:
static const int priority = 10;
/* virtual */ const char *GetName() { return "bemidi"; }
/* virtual */ const char *GetDescription() { return "BeOS MIDI Driver"; }
/* virtual */ Driver *CreateInstance() { return new MusicDriver_BeMidi(); }

View File

@ -7,8 +7,6 @@
class MusicDriver_DMusic: public MusicDriver {
public:
/* virtual */ bool CanProbe() { return true; }
/* virtual */ const char *Start(const char * const *param);
/* virtual */ void Stop();
@ -24,6 +22,7 @@ public:
class FMusicDriver_DMusic: public MusicDriverFactory<FMusicDriver_DMusic> {
public:
static const int priorty = 10;
/* virtual */ const char *GetName() { return "dmusic"; }
/* virtual */ const char *GetDescription() { return "DirectMusic MIDI Driver"; }
/* virtual */ Driver *CreateInstance() { return new MusicDriver_DMusic(); }

View File

@ -14,8 +14,6 @@ private:
void DoStop();
public:
/* virtual */ bool CanProbe() { return true; }
/* virtual */ const char *Start(const char * const *param);
/* virtual */ void Stop();
@ -31,6 +29,7 @@ public:
class FMusicDriver_ExtMidi: public MusicDriverFactory<FMusicDriver_ExtMidi> {
public:
static const int priority = 1;
/* virtual */ const char *GetName() { return "extmidi"; }
/* virtual */ const char *GetDescription() { return "External MIDI Driver"; }
/* virtual */ Driver *CreateInstance() { return new MusicDriver_ExtMidi(); }

View File

@ -7,8 +7,6 @@
class MusicDriver_LibTimidity: public MusicDriver {
public:
/* virtual */ bool CanProbe() { return true; }
/* virtual */ const char *Start(const char * const *param);
/* virtual */ void Stop();
@ -24,6 +22,7 @@ public:
class FMusicDriver_LibTimidity: public MusicDriverFactory<FMusicDriver_LibTimidity> {
public:
static const int priority = 5;
/* virtual */ const char *GetName() { return "libtimidity"; }
/* virtual */ const char *GetDescription() { return "LibTimidity MIDI Driver"; }
/* virtual */ Driver *CreateInstance() { return new MusicDriver_LibTimidity(); }

View File

@ -22,7 +22,7 @@ class MusicDriverFactoryBase: public DriverFactoryBase {
template <class T>
class MusicDriverFactory: public MusicDriverFactoryBase {
public:
MusicDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_MUSIC); }
MusicDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_MUSIC, ((T *)this)->priority); }
/**
* Get the long, human readable, name for the Driver-class.

View File

@ -7,8 +7,6 @@
class MusicDriver_Null: public MusicDriver {
public:
/* virtual */ bool CanProbe() { return false; }
/* virtual */ const char *Start(const char * const *param) { return NULL; }
/* virtual */ void Stop() { }
@ -24,6 +22,7 @@ public:
class FMusicDriver_Null: public MusicDriverFactory<FMusicDriver_Null> {
public:
static const int priority = 0;
/* virtual */ const char *GetName() { return "null"; }
/* virtual */ const char *GetDescription() { return "Null Music Driver"; }
/* virtual */ Driver *CreateInstance() { return new MusicDriver_Null(); }

View File

@ -7,8 +7,6 @@
class MusicDriver_OS2: public MusicDriver {
public:
/* virtual */ bool CanProbe() { return true; }
/* virtual */ const char *Start(const char * const *param);
/* virtual */ void Stop();
@ -24,6 +22,7 @@ public:
class FMusicDriver_OS2: public MusicDriverFactory<FMusicDriver_OS2> {
public:
static const int priority = 10;
/* virtual */ const char *GetName() { return "os2"; }
/* virtual */ const char *GetDescription() { return "OS/2 Music Driver"; }
/* virtual */ Driver *CreateInstance() { return new MusicDriver_OS2(); }

View File

@ -7,8 +7,6 @@
class MusicDriver_QtMidi: public MusicDriver {
public:
/* virtual */ bool CanProbe() { return true; }
/* virtual */ const char *Start(const char * const *param);
/* virtual */ void Stop();
@ -24,6 +22,7 @@ public:
class FMusicDriver_QtMidi: public MusicDriverFactory<FMusicDriver_QtMidi> {
public:
static const int priorty = 10;
/* virtual */ const char *GetName() { return "qt"; }
/* virtual */ const char *GetDescription() { return "QuickTime MIDI Driver"; }
/* virtual */ Driver *CreateInstance() { return new MusicDriver_QtMidi(); }

View File

@ -7,8 +7,6 @@
class MusicDriver_Win32: public MusicDriver {
public:
/* virtual */ bool CanProbe() { return true; }
/* virtual */ const char *Start(const char * const *param);
/* virtual */ void Stop();
@ -24,6 +22,7 @@ public:
class FMusicDriver_Win32: public MusicDriverFactory<FMusicDriver_Win32> {
public:
static const int priorty = 5;
/* virtual */ const char *GetName() { return "win32"; }
/* virtual */ const char *GetDescription() { return "Win32 Music Driver"; }
/* virtual */ Driver *CreateInstance() { return new MusicDriver_Win32(); }

View File

@ -7,8 +7,6 @@
class SoundDriver_Cocoa: public SoundDriver {
public:
/* virtual */ bool CanProbe() { return true; }
/* virtual */ const char *Start(const char * const *param);
/* virtual */ void Stop();
@ -16,6 +14,7 @@ public:
class FSoundDriver_Cocoa: public SoundDriverFactory<FSoundDriver_Cocoa> {
public:
static const int priority = 10;
/* virtual */ const char *GetName() { return "cocoa"; }
/* virtual */ const char *GetDescription() { return "Cocoa Sound Driver"; }
/* virtual */ Driver *CreateInstance() { return new SoundDriver_Cocoa(); }

View File

@ -7,8 +7,6 @@
class SoundDriver_Null: public SoundDriver {
public:
/* virtual */ bool CanProbe() { return false; }
/* virtual */ const char *Start(const char * const *param) { return NULL; }
/* virtual */ void Stop() { }
@ -16,6 +14,7 @@ public:
class FSoundDriver_Null: public SoundDriverFactory<FSoundDriver_Null> {
public:
static const int priority = 0;
/* virtual */ const char *GetName() { return "null"; }
/* virtual */ const char *GetDescription() { return "Null Sound Driver"; }
/* virtual */ Driver *CreateInstance() { return new SoundDriver_Null(); }

View File

@ -7,8 +7,6 @@
class SoundDriver_SDL: public SoundDriver {
public:
/* virtual */ bool CanProbe() { return true; }
/* virtual */ const char *Start(const char * const *param);
/* virtual */ void Stop();
@ -16,6 +14,7 @@ public:
class FSoundDriver_SDL: public SoundDriverFactory<FSoundDriver_SDL> {
public:
static const int priority = 5;
/* virtual */ const char *GetName() { return "sdl"; }
/* virtual */ const char *GetDescription() { return "SDL Sound Driver"; }
/* virtual */ Driver *CreateInstance() { return new SoundDriver_SDL(); }

View File

@ -14,7 +14,7 @@ class SoundDriverFactoryBase: public DriverFactoryBase {
template <class T>
class SoundDriverFactory: public SoundDriverFactoryBase {
public:
SoundDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_SOUND); }
SoundDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_SOUND, ((T *)this)->priority); }
/**
* Get the long, human readable, name for the Driver-class.

View File

@ -7,8 +7,6 @@
class SoundDriver_Win32: public SoundDriver {
public:
/* virtual */ bool CanProbe() { return true; }
/* virtual */ const char *Start(const char * const *param);
/* virtual */ void Stop();
@ -16,6 +14,7 @@ public:
class FSoundDriver_Win32: public SoundDriverFactory<FSoundDriver_Win32> {
public:
static const int priority = 10;
/* virtual */ const char *GetName() { return "win32"; }
/* virtual */ const char *GetDescription() { return "Win32 WaveOut Driver"; }
/* virtual */ Driver *CreateInstance() { return new SoundDriver_Win32(); }

View File

@ -7,8 +7,6 @@
class VideoDriver_Cocoa: public VideoDriver {
public:
/* virtual */ bool CanProbe() { return true; }
/* virtual */ const char *Start(const char * const *param);
/* virtual */ void Stop();
@ -24,6 +22,7 @@ public:
class FVideoDriver_Cocoa: public VideoDriverFactory<FVideoDriver_Cocoa> {
public:
static const int priority = 10;
/* virtual */ const char *GetName() { return "cocoa"; }
/* virtual */ const char *GetDescription() { return "Cocoa Video Driver"; }
/* virtual */ Driver *CreateInstance() { return new VideoDriver_Cocoa(); }

View File

@ -7,8 +7,6 @@
class VideoDriver_Dedicated: public VideoDriver {
public:
/* virtual */ bool CanProbe() { return false; }
/* virtual */ const char *Start(const char * const *param);
/* virtual */ void Stop();
@ -24,6 +22,7 @@ public:
class FVideoDriver_Dedicated: public VideoDriverFactory<FVideoDriver_Dedicated> {
public:
static const int priority = 0;
/* virtual */ const char *GetName() { return "dedicated"; }
/* virtual */ const char *GetDescription() { return "Dedicated Video Driver"; }
/* virtual */ Driver *CreateInstance() { return new VideoDriver_Dedicated(); }

View File

@ -7,8 +7,6 @@
class VideoDriver_Null: public VideoDriver {
public:
/* virtual */ bool CanProbe() { return false; }
/* virtual */ const char *Start(const char * const *param);
/* virtual */ void Stop();
@ -24,6 +22,7 @@ public:
class FVideoDriver_Null: public VideoDriverFactory<FVideoDriver_Null> {
public:
static const int priority = 1;
/* virtual */ const char *GetName() { return "null"; }
/* virtual */ const char *GetDescription() { return "Null Video Driver"; }
/* virtual */ Driver *CreateInstance() { return new VideoDriver_Null(); }

View File

@ -7,8 +7,6 @@
class VideoDriver_SDL: public VideoDriver {
public:
/* virtual */ bool CanProbe() { return true; }
/* virtual */ const char *Start(const char * const *param);
/* virtual */ void Stop();
@ -24,6 +22,7 @@ public:
class FVideoDriver_SDL: public VideoDriverFactory<FVideoDriver_SDL> {
public:
static const int priority = 5;
/* virtual */ const char *GetName() { return "sdl"; }
/* virtual */ const char *GetDescription() { return "SDL Video Driver"; }
/* virtual */ Driver *CreateInstance() { return new VideoDriver_SDL(); }

View File

@ -22,7 +22,7 @@ class VideoDriverFactoryBase: public DriverFactoryBase {
template <class T>
class VideoDriverFactory: public VideoDriverFactoryBase {
public:
VideoDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_VIDEO); }
VideoDriverFactory() { this->RegisterDriver(((T *)this)->GetName(), Driver::DT_VIDEO, ((T *)this)->priority); }
/**
* Get the long, human readable, name for the Driver-class.

View File

@ -7,8 +7,6 @@
class VideoDriver_Win32: public VideoDriver {
public:
/* virtual */ bool CanProbe() { return true; }
/* virtual */ const char *Start(const char * const *param);
/* virtual */ void Stop();