From 41ca0a3051e17042635486f4f272b70d4232182f Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Mon, 21 Jan 2013 13:52:26 +0200 Subject: [PATCH] Audio drivers: Use weak functions --- include/core/audioapi.hpp | 22 ++++++---- src/{dummy/sound.cpp => core/dummysound.cpp} | 1 + src/platform/Makefile | 7 +--- src/platform/dummy/Makefile | 19 --------- src/platform/dummy/sound.cpp | 43 -------------------- 5 files changed, 16 insertions(+), 76 deletions(-) rename src/{dummy/sound.cpp => core/dummysound.cpp} (97%) delete mode 100644 src/platform/dummy/Makefile delete mode 100644 src/platform/dummy/sound.cpp diff --git a/include/core/audioapi.hpp b/include/core/audioapi.hpp index 8882cd34..8a6ae03e 100644 --- a/include/core/audioapi.hpp +++ b/include/core/audioapi.hpp @@ -1,6 +1,12 @@ #ifndef _audioapi__hpp__included__ #define _audioapi__hpp__included__ +#ifdef AUDIO_WEAK +#define AUDIOAPI_DRV_ATTRIBUTE __attribute__((weak)) +#else +#define AUDIOAPI_DRV_ATTRIBUTE +#endif + #include #include #include @@ -224,26 +230,26 @@ void audioapi_voice_rate(unsigned rate); /** * Initialize the driver. */ -void audioapi_driver_init() throw(); +void audioapi_driver_init() throw() AUDIOAPI_DRV_ATTRIBUTE ; /** * Deinitialize the driver. */ -void audioapi_driver_quit() throw(); +void audioapi_driver_quit() throw() AUDIOAPI_DRV_ATTRIBUTE ; /** * Enable or disable sound. * * parameter enable: Enable sounds if true, otherwise disable sounds. */ -void audioapi_driver_enable(bool enable) throw(); +void audioapi_driver_enable(bool enable) throw() AUDIOAPI_DRV_ATTRIBUTE ; /** * Has the sound system been successfully initialized? * * Returns: True if sound system has successfully initialized, false otherwise. */ -bool audioapi_driver_initialized(); +bool audioapi_driver_initialized() AUDIOAPI_DRV_ATTRIBUTE ; /** * Set sound device. @@ -252,25 +258,25 @@ bool audioapi_driver_initialized(); * * Parameter dev: The new sound device. */ -void audioapi_driver_set_device(const std::string& dev) throw(std::bad_alloc, std::runtime_error); +void audioapi_driver_set_device(const std::string& dev) throw(std::bad_alloc, std::runtime_error) AUDIOAPI_DRV_ATTRIBUTE ; /** * Get current sound device. * * Returns: The current sound device. */ -std::string audioapi_driver_get_device() throw(std::bad_alloc); +std::string audioapi_driver_get_device() throw(std::bad_alloc) AUDIOAPI_DRV_ATTRIBUTE ; /** * Get available sound devices. * * Returns: The map of devices. Keyed by name of the device, values are human-readable names for devices. */ -std::map audioapi_driver_get_devices() throw(std::bad_alloc); +std::map audioapi_driver_get_devices() throw(std::bad_alloc) AUDIOAPI_DRV_ATTRIBUTE ; /** * Identification for sound plugin. */ -extern const char* audioapi_driver_name; +extern const char* audioapi_driver_name AUDIOAPI_DRV_ATTRIBUTE ; #endif diff --git a/src/dummy/sound.cpp b/src/core/dummysound.cpp similarity index 97% rename from src/dummy/sound.cpp rename to src/core/dummysound.cpp index 7e2e2061..f223c2e5 100644 --- a/src/dummy/sound.cpp +++ b/src/core/dummysound.cpp @@ -1,3 +1,4 @@ +#define AUDIO_WEAK #include "core/command.hpp" #include "core/audioapi.hpp" diff --git a/src/platform/Makefile b/src/platform/Makefile index c4b17707..c9aa6a3a 100644 --- a/src/platform/Makefile +++ b/src/platform/Makefile @@ -1,4 +1,4 @@ -PLATFORMS=dummy evdev portaudio wxwidgets win32mm libao +PLATFORMS=evdev portaudio wxwidgets win32mm libao ALLFILES=__all__.files ALLFLAGS=__all__.ldflags PLATFORMS_FILES=$(patsubst %,%/$(ALLFILES),$(PLATFORMS)) @@ -8,9 +8,6 @@ $(ALLFILES): $(PLATFORMS_FILES) $(OBJECTS) lua ../genfilelist.lua $^ >$@ cat $(PLATFORMS_FLAGS) >$(ALLFLAGS) -dummy/$(ALLFILES): forcelook - $(MAKE) -C dummy - evdev/$(ALLFILES): forcelook $(MAKE) -C evdev @@ -30,7 +27,6 @@ wxwidgets/$(ALLFILES): forcelook .PRECIOUS: %.$(OBJECT_SUFFIX) *.files precheck: - $(MAKE) -C dummy precheck $(MAKE) -C evdev precheck $(MAKE) -C win32mm precheck $(MAKE) -C portaudio precheck @@ -39,7 +35,6 @@ precheck: clean: rm -f *.$(OBJECT_SUFFIX) __all__.ldflags __all__.files - $(MAKE) -C dummy clean $(MAKE) -C evdev clean $(MAKE) -C win32mm clean $(MAKE) -C portaudio clean diff --git a/src/platform/dummy/Makefile b/src/platform/dummy/Makefile deleted file mode 100644 index 231bc2f5..00000000 --- a/src/platform/dummy/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -OBJECTS= -ifeq ($(SOUND),DUMMY) -OBJECTS += sound.$(OBJECT_SUFFIX) -endif - -.PRECIOUS: %.$(OBJECT_SUFFIX) %.files - -__all__.files: $(OBJECTS) - lua ../../genfilelist.lua $^ >$@ - touch __all__.ldflags - -%.$(OBJECT_SUFFIX): %.cpp - $(REALCC) -c -o $@ $< -I../../../include $(CFLAGS) - -precheck: - @true - -clean: - rm -f *.$(OBJECT_SUFFIX) __all__.ldflags __all__.files diff --git a/src/platform/dummy/sound.cpp b/src/platform/dummy/sound.cpp deleted file mode 100644 index 7e2e2061..00000000 --- a/src/platform/dummy/sound.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "core/command.hpp" -#include "core/audioapi.hpp" - -#include -#include - -void audioapi_driver_init() throw() -{ - audioapi_set_dummy_cb(true); -} - -void audioapi_driver_quit() throw() -{ -} - -void audioapi_driver_enable(bool enable) throw() -{ -} - -bool audioapi_driver_initialized() -{ - return true; -} - -void audioapi_driver_set_device(const std::string& dev) throw(std::bad_alloc, std::runtime_error) -{ - if(dev != "null") - throw std::runtime_error("Bad sound device '" + dev + "'"); -} - -std::string audioapi_driver_get_device() throw(std::bad_alloc) -{ - return "null"; -} - -std::map audioapi_driver_get_devices() throw(std::bad_alloc) -{ - std::map ret; - ret["null"] = "NULL sound output"; - return ret; -} - -const char* audioapi_driver_name = "Dummy sound plugin";