src/driver.cpp
author convert-repo
Mon, 07 Apr 2008 16:21:55 +0000
changeset 10076 dfd70e42c4ae
parent 9340 a59cd2c7e548
child 10429 1b99254f9607
permissions -rw-r--r--
update tags
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2171
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2171
diff changeset
     2
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6360
diff changeset
     3
/** @file driver.cpp */
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6360
diff changeset
     4
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     5
#include "stdafx.h"
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     6
#include "openttd.h"
2210
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
     7
#include "debug.h"
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     8
#include "driver.h"
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
     9
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7541
diff changeset
    10
#include "sound/sound_driver.hpp"
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7541
diff changeset
    11
#include "music/music_driver.hpp"
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7541
diff changeset
    12
#include "video/video_driver.hpp"
2222
d227c0207a02 (svn r2740) MSCV doesn't seem to like forward declared static arrays
tron
parents: 2219
diff changeset
    13
8771
f7ad4dba14bf (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8710
diff changeset
    14
VideoDriver *_video_driver;
f7ad4dba14bf (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8710
diff changeset
    15
char _ini_videodriver[32];
f7ad4dba14bf (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8710
diff changeset
    16
int _num_resolutions;
f7ad4dba14bf (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8710
diff changeset
    17
uint16 _resolutions[32][2];
f7ad4dba14bf (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8710
diff changeset
    18
uint16 _cur_resolution[2];
f7ad4dba14bf (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8710
diff changeset
    19
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7541
diff changeset
    20
SoundDriver *_sound_driver;
8771
f7ad4dba14bf (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8710
diff changeset
    21
char _ini_sounddriver[32];
f7ad4dba14bf (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8710
diff changeset
    22
7666
a5fccd76176a (svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents: 7541
diff changeset
    23
MusicDriver *_music_driver;
8771
f7ad4dba14bf (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8710
diff changeset
    24
char _ini_musicdriver[32];
f7ad4dba14bf (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8710
diff changeset
    25
f7ad4dba14bf (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8710
diff changeset
    26
char _ini_blitter[32];
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    27
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    28
static const char* GetDriverParam(const char* const* parm, const char* name)
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    29
{
2458
c95808cd2ac9 (svn r2984) Use adequate types, this should aid portability a bit
tron
parents: 2303
diff changeset
    30
	size_t len;
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    31
2224
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    32
	if (parm == NULL) return NULL;
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    33
e210db34b7ec (svn r2742) Get rid of some void pointers plus a few minor changes, like 0 -> '\0'
tron
parents: 2222
diff changeset
    34
	len = strlen(name);
2171
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    35
	for (; *parm != NULL; parm++) {
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    36
		const char* p = *parm;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    37
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    38
		if (strncmp(p, name, len) == 0) {
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    39
			if (p[len] == '=')  return p + len + 1;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    40
			if (p[len] == '\0') return p + len;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    41
		}
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    42
	}
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    43
	return NULL;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    44
}
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    45
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    46
bool GetDriverParamBool(const char* const* parm, const char* name)
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    47
{
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    48
	return GetDriverParam(parm, name) != NULL;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    49
}
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    50
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    51
int GetDriverParamInt(const char* const* parm, const char* name, int def)
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    52
{
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    53
	const char* p = GetDriverParam(parm, name);
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    54
	return p != NULL ? atoi(p) : def;
008122046f7f (svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
diff changeset
    55
}
9340
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    56
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    57
/**
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    58
 * Find the requested driver and return its class.
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    59
 * @param name the driver to select.
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    60
 * @post Sets the driver so GetCurrentDriver() returns it too.
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    61
 */
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    62
const Driver *DriverFactoryBase::SelectDriver(const char *name, Driver::Type type)
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    63
{
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    64
	if (GetDrivers().size() == 0) return NULL;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    65
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    66
	if (*name == '\0') {
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    67
		/* Probe for this driver */
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    68
		for (int priority = 10; priority >= 0; priority--) {
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    69
			Drivers::iterator it = GetDrivers().begin();
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    70
			for (; it != GetDrivers().end(); ++it) {
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    71
				DriverFactoryBase *d = (*it).second;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    72
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    73
				/* Check driver type */
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    74
				if (d->type != type) continue;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    75
				if (d->priority != priority) continue;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    76
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    77
				Driver *newd = d->CreateInstance();
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    78
				const char *err = newd->Start(NULL);
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    79
				if (err == NULL) {
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    80
					DEBUG(driver, 1, "Successfully probed %s driver '%s'", GetDriverTypeName(type), d->name);
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    81
					delete *GetActiveDriver(type);
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    82
					*GetActiveDriver(type) = newd;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    83
					return newd;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    84
				}
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    85
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    86
				DEBUG(driver, 1, "Probing %s driver '%s' failed with error: %s", GetDriverTypeName(type), d->name, err);
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    87
				delete newd;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    88
			}
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    89
		}
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    90
		error("Couldn't find any suitable %s driver", GetDriverTypeName(type));
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    91
	} else {
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    92
		char *parm;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    93
		char buffer[256];
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    94
		const char *parms[32];
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    95
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    96
		/* Extract the driver name and put parameter list in parm */
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    97
		strecpy(buffer, name, lastof(buffer));
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    98
		parm = strchr(buffer, ':');
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
    99
		parms[0] = NULL;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   100
		if (parm != NULL) {
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   101
			uint np = 0;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   102
			/* Tokenize the parm. */
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   103
			do {
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   104
				*parm++ = '\0';
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   105
				if (np < lengthof(parms) - 1) parms[np++] = parm;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   106
				while (*parm != '\0' && *parm != ',') parm++;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   107
			} while (*parm == ',');
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   108
			parms[np] = NULL;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   109
		}
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   110
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   111
		/* Find this driver */
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   112
		Drivers::iterator it = GetDrivers().begin();
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   113
		for (; it != GetDrivers().end(); ++it) {
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   114
			DriverFactoryBase *d = (*it).second;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   115
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   116
			/* Check driver type */
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   117
			if (d->type != type) continue;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   118
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   119
			/* Check driver name */
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   120
			if (strcasecmp(buffer, d->name) != 0) continue;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   121
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   122
			/* Found our driver, let's try it */
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   123
			Driver *newd = d->CreateInstance();
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   124
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   125
			const char *err = newd->Start(parms);
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   126
			if (err != NULL) {
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   127
				delete newd;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   128
				error("Unable to load driver '%s'. The error was: %s", d->name, err);
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   129
			}
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   130
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   131
			DEBUG(driver, 1, "Successfully loaded %s driver '%s'", GetDriverTypeName(type), d->name);
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   132
			delete *GetActiveDriver(type);
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   133
			*GetActiveDriver(type) = newd;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   134
			return newd;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   135
		}
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   136
		error("No such %s driver: %s\n", GetDriverTypeName(type), buffer);
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   137
	}
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   138
}
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   139
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   140
/**
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   141
 * Register a driver internally, based on its name.
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   142
 * @param name the name of the driver.
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   143
 * @note an assert() will be trigger if 2 driver with the same name try to register.
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   144
 */
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   145
void DriverFactoryBase::RegisterDriver(const char *name, Driver::Type type, int priority)
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   146
{
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   147
	/* Don't register nameless Drivers */
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   148
	if (name == NULL) return;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   149
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   150
	this->name = strdup(name);
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   151
	this->type = type;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   152
	this->priority = priority;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   153
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   154
	/* Prefix the name with driver type to make it unique */
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   155
	char buf[32];
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   156
	strecpy(buf, GetDriverTypeName(type), lastof(buf));
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   157
	strecpy(buf + 5, name, lastof(buf));
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   158
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   159
#if !defined(NDEBUG) || defined(WITH_ASSERT)
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   160
	/* NDEBUG disables asserts and gives a warning: unused variable 'P' */
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   161
	std::pair<Drivers::iterator, bool> P =
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   162
#endif /* !NDEBUG */
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   163
	GetDrivers().insert(Drivers::value_type(buf, this));
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   164
	assert(P.second);
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   165
}
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   166
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   167
/**
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   168
 * Build a human readable list of available drivers, grouped by type.
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   169
 */
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   170
char *DriverFactoryBase::GetDriversInfo(char *p, const char *last)
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   171
{
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   172
	for (Driver::Type type = Driver::DT_BEGIN; type != Driver::DT_END; type++) {
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   173
		p += snprintf(p, last - p, "List of %s drivers:\n", GetDriverTypeName(type));
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   174
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   175
		for (int priority = 10; priority >= 0; priority--) {
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   176
			Drivers::iterator it = GetDrivers().begin();
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   177
			for (; it != GetDrivers().end(); it++) {
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   178
				DriverFactoryBase *d = (*it).second;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   179
				if (d->type != type) continue;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   180
				if (d->priority != priority) continue;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   181
				p += snprintf(p, last - p, "%18s: %s\n", d->name, d->GetDescription());
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   182
			}
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   183
		}
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   184
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   185
		p += snprintf(p, last - p, "\n");
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   186
	}
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   187
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   188
	return p;
a59cd2c7e548 (svn r12594) -Codechange: move large functions from driver.h to driver.cpp to reduce binary size and compile time
smatz
parents: 8771
diff changeset
   189
}