diff options
author | Josh Blum | 2011-03-09 12:31:28 -0800 |
---|---|---|
committer | Josh Blum | 2011-03-09 12:31:28 -0800 |
commit | 0ac77af7db957f8746282b60d57e04d65f7d9054 (patch) | |
tree | 20628bbfb30038fbd221b2173f45f79590cf9684 /gr-audio/lib/gr_audio_registry.cc | |
parent | 0644b009591f4c63ed05a8095a0c54c1501bac71 (diff) | |
download | gnuradio-0ac77af7db957f8746282b60d57e04d65f7d9054.tar.gz gnuradio-0ac77af7db957f8746282b60d57e04d65f7d9054.tar.bz2 gnuradio-0ac77af7db957f8746282b60d57e04d65f7d9054.zip |
audio: use conf files to specify default arch
Diffstat (limited to 'gr-audio/lib/gr_audio_registry.cc')
-rw-r--r-- | gr-audio/lib/gr_audio_registry.cc | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/gr-audio/lib/gr_audio_registry.cc b/gr-audio/lib/gr_audio_registry.cc index be1337101..7be652807 100644 --- a/gr-audio/lib/gr_audio_registry.cc +++ b/gr-audio/lib/gr_audio_registry.cc @@ -20,20 +20,25 @@ */ #include "gr_audio_registry.h" +#include <boost/foreach.hpp> +#include <gr_prefs.h> #include <stdexcept> #include <vector> #include <utility> +#include <iostream> /*********************************************************************** * Create registries **********************************************************************/ -static std::vector<std::pair<std::string, source_factory_t> > &get_source_registry(void){ - static std::vector<std::pair<std::string, source_factory_t> > _registry; +typedef std::pair<std::string, source_factory_t> source_pair_t; +static std::vector<source_pair_t> &get_source_registry(void){ + static std::vector<source_pair_t> _registry; return _registry; } -static std::vector<std::pair<std::string, sink_factory_t> > &get_sink_registry(void){ - static std::vector<std::pair<std::string, sink_factory_t> > _registry; +typedef std::pair<std::string, sink_factory_t> sink_pair_t; +static std::vector<sink_pair_t> &get_sink_registry(void){ + static std::vector<sink_pair_t> _registry; return _registry; } @@ -51,15 +56,30 @@ void audio_register_sink(const std::string &name, sink_factory_t sink){ /*********************************************************************** * Factory functions **********************************************************************/ +static std::string default_arch_name(void){ + return gr_prefs::singleton()->get_string("audio", "default_arch", ""); +} + +static void do_arch_warning(const std::string &arch){ + std::cerr << "Could not find audio architecture \"" << arch << "\" in registry." << std::endl; + std::cerr << " Defaulting to the first available architecture..." << std::endl; +} + audio_source::sptr audio_make_source( int sampling_rate, const std::string device_name, bool ok_to_block ){ if (get_source_registry().empty()){ - throw std::runtime_error("no available audio factories"); + throw std::runtime_error("no available audio source factories"); + } + std::string arch = default_arch_name(); + BOOST_FOREACH(const source_pair_t &e, get_source_registry()){ + if (arch.empty() || arch == e.first){ + return e.second(sampling_rate, device_name, ok_to_block); + } } - //TODO we may prefer to use a specific entry in the registry + do_arch_warning(arch); return get_source_registry().front().second(sampling_rate, device_name, ok_to_block); } @@ -69,9 +89,15 @@ audio_sink::sptr audio_make_sink( bool ok_to_block ){ if (get_sink_registry().empty()){ - throw std::runtime_error("no available audio factories"); + throw std::runtime_error("no available audio sink factories"); + } + std::string arch = default_arch_name(); + BOOST_FOREACH(const sink_pair_t &e, get_sink_registry()){ + if (arch.empty() || arch == e.first){ + return e.second(sampling_rate, device_name, ok_to_block); + } } - //TODO we may prefer to use a specific entry in the registry + do_arch_warning(arch); return get_sink_registry().front().second(sampling_rate, device_name, ok_to_block); } |