From 8e9962f215e5ed3ca5956678d1a34903c936b91a Mon Sep 17 00:00:00 2001 From: bruceperens Date: Fri, 17 Jan 2014 18:22:55 +0000 Subject: [PATCH] More refactoring, make operator << compile properly. git-svn-id: https://svn.code.sf.net/p/freetel/code@1367 01035d8c-6547-0410-b346-abe4f91aad63 --- freedv-server/CMakeLists.txt | 1 + freedv-server/source/audio_sink.cpp | 11 ++-- freedv-server/source/big_main.cpp | 13 ++++- freedv-server/source/blank_panel.cpp | 10 ++-- freedv-server/source/codec_noop.cpp | 10 ++-- freedv-server/source/driver_manager.cpp | 11 +--- freedv-server/source/drivers.h | 76 ++++++++++++++++++------- freedv-server/source/keying_sink.cpp | 10 ++-- freedv-server/source/modem_noop.cpp | 10 ++-- freedv-server/source/ptt_constant.cpp | 10 ++-- freedv-server/source/text_constant.cpp | 10 ++-- freedv-server/source/tone.cpp | 10 ++-- 12 files changed, 114 insertions(+), 68 deletions(-) diff --git a/freedv-server/CMakeLists.txt b/freedv-server/CMakeLists.txt index 401ae5d8..5734a7ab 100644 --- a/freedv-server/CMakeLists.txt +++ b/freedv-server/CMakeLists.txt @@ -95,6 +95,7 @@ set(Compile.sources source/codec.cpp source/codec_noop.cpp source/driver_manager.cpp + source/interfaces.cpp source/keying.cpp source/keying_sink.cpp source/modem.cpp diff --git a/freedv-server/source/audio_sink.cpp b/freedv-server/source/audio_sink.cpp index c1aeabc8..a8f8b1e2 100644 --- a/freedv-server/source/audio_sink.cpp +++ b/freedv-server/source/audio_sink.cpp @@ -51,17 +51,18 @@ namespace FreeDV { return 0; } -#ifndef NO_INITIALIZERS - static AudioOutput * - creator(const char * parameter) + AudioOutput * + Driver::AudioSink(const char * parameter) { - return new AudioSink(parameter); + return new ::FreeDV::AudioSink(parameter); } +#ifndef NO_INITIALIZERS + static bool initializer() { - init_driver_manager().register_audio_output("sink", creator); + init_driver_manager().register_audio_output("sink", Driver::AudioSink); return true; } static const bool initialized = initializer(); diff --git a/freedv-server/source/big_main.cpp b/freedv-server/source/big_main.cpp index 3915e48d..5820b32d 100644 --- a/freedv-server/source/big_main.cpp +++ b/freedv-server/source/big_main.cpp @@ -38,6 +38,7 @@ static void help(const char * name) "\nWhere options are these flags:\n\n" "--codec or -c\t\tSelect the voice codec.\n" "--drivers or -d\t\tPrint a list of the available device drivers.\n" + "--gui or -g\t\tSelect the graphical user interface.\n" "--help or -h\t\tPrint this message.\n" "--interface or -i\tSelect the user-interface (graphical or otherwise).\n" "--keying or -k\t\tSelect the transmitter keying interface.\n" @@ -71,6 +72,7 @@ static void help(const char * name) static const struct option options[] = { { "codec", required_argument, 0, 'c' }, { "drivers", no_argument, 0, 'd' }, + { "gui", required_argument, 0, 'g' }, { "help", no_argument, 0, 'h' }, { "interface", required_argument, 0, 'i' }, { "keying", required_argument, 0, 'k' }, @@ -82,6 +84,7 @@ static const struct option options[] = { { "receiver", required_argument, 0, 'r' }, { "text", required_argument, 0, 'x' }, { "transmitter", required_argument, 0, 't' }, + { "config", no_argument, 0, 'C' }, { 0, 0, 0, 0 } }; @@ -96,6 +99,7 @@ main(int argc, char * * argv) if ( argc > 1 ) { while ((command = getopt_long(argc, argv, "c:dhi:k:l:m:M:n:p:r:t:x:", options, NULL)) != -1) { switch (command) { + case 'g': case 'i': case 'k': case 'l': @@ -125,6 +129,9 @@ main(int argc, char * * argv) drivers(); exit(0); break; + case 'g': + i.user_interface = driver_manager.user_interface(driver, parameter, &i); + break; default: case 'h': help(argv[0]); @@ -155,8 +162,12 @@ main(int argc, char * * argv) i.transmitter = driver_manager.audio_output(driver, parameter); break; case 'x': - i.text = driver_manager.text_input(driver, parameter); + i.text_input = driver_manager.text_input(driver, parameter); break; + case 'C': + i.fill_in(); + // FIX: Operator overload doesn't work here. + i.print(cout) << endl; case 0: break; } diff --git a/freedv-server/source/blank_panel.cpp b/freedv-server/source/blank_panel.cpp index 8a694172..a9444fdf 100644 --- a/freedv-server/source/blank_panel.cpp +++ b/freedv-server/source/blank_panel.cpp @@ -22,17 +22,17 @@ namespace FreeDV { { } -#ifndef NO_INITIALIZERS - static UserInterface * - creator(const char * parameter, Interfaces * interfaces) + UserInterface * + Driver::BlankPanel(const char * parameter, Interfaces * interfaces) { - return new BlankPanel(parameter, interfaces); + return new ::FreeDV::BlankPanel(parameter, interfaces); } +#ifndef NO_INITIALIZERS static bool initializer() { - init_driver_manager().register_user_interface("blank-panel", creator); + init_driver_manager().register_user_interface("blank-panel", Driver::BlankPanel); return true; } static const bool initialized = initializer(); diff --git a/freedv-server/source/codec_noop.cpp b/freedv-server/source/codec_noop.cpp index 954efe5f..99c8a552 100644 --- a/freedv-server/source/codec_noop.cpp +++ b/freedv-server/source/codec_noop.cpp @@ -99,17 +99,17 @@ namespace FreeDV { return 0; } -#ifndef NO_INITIALIZERS - static Codec * - creator(const char * parameter) + Codec * + Driver::CodecNoOp(const char * parameter) { - return new CodecNoOp(parameter); + return new ::FreeDV::CodecNoOp(parameter); } +#ifndef NO_INITIALIZERS static bool initializer() { - init_driver_manager().register_codec("no-op", creator); + init_driver_manager().register_codec("no-op", Driver::CodecNoOp); return true; } static const bool initialized = initializer(); diff --git a/freedv-server/source/driver_manager.cpp b/freedv-server/source/driver_manager.cpp index 428e4da0..8dc79599 100644 --- a/freedv-server/source/driver_manager.cpp +++ b/freedv-server/source/driver_manager.cpp @@ -20,8 +20,8 @@ namespace FreeDV { { } - void - DriverManager::print(ostream & s) + ostream & + DriverManager::print(ostream & s) const { s << "AudioInput: "; for (auto i = audio_input_drivers.begin(); i != audio_input_drivers.end(); i++ ) @@ -55,6 +55,7 @@ namespace FreeDV { for (auto i = user_interface_drivers.begin(); i != user_interface_drivers.end(); i++ ) s << i->first << " "; s << endl; + return s; } AudioInput * @@ -188,12 +189,6 @@ namespace FreeDV { user_interface_drivers[driver] = creator; } - std::ostream & - DriverManager::operator << (std::ostream & stream) const - { - return stream; - } - /// Automatic initializer for the driver manager. /// This has to be a function to get around the static initalization order /// problem. diff --git a/freedv-server/source/drivers.h b/freedv-server/source/drivers.h index 340189b1..22e5c981 100644 --- a/freedv-server/source/drivers.h +++ b/freedv-server/source/drivers.h @@ -59,10 +59,20 @@ namespace FreeDV { /// object information is to be rendered. /// \return A reference to the provided stream, meant for the /// usual successive call paradigm of ostream operator << . - virtual std::ostream & - operator << (std::ostream &) const; + std::ostream & print(std::ostream &) const; }; + /// Write the driver information from the Base object onto a stream, + /// for debugging and dumping the configuration information. + /// \param stream A reference to an instance of ostream upon which the + /// object information is to be rendered. + /// \return A reference to the provided stream, meant for the + /// usual successive call paradigm of ostream operator << . + inline std::ostream & + operator << (std::ostream & stream, const Base & base) { + return base.print(stream); + } + /// Virtual base class for audio input drivers. class AudioInput : public ::FreeDV::Base { protected: @@ -174,7 +184,7 @@ namespace FreeDV { /// Event handler class, indirects the event handler of the particular GUI /// software or POSIX. - class EventHandler { + class EventHandler : public ::FreeDV::Base { private: bool do_exit; @@ -192,8 +202,8 @@ namespace FreeDV { const unsigned int Write = 2; /// Create an event handler instance. - EventHandler() - : do_exit(false) + EventHandler(const char * name, const char * parameters) + : Base(name, parameters), do_exit(false) { } virtual ~EventHandler() = 0; @@ -251,11 +261,6 @@ namespace FreeDV { /// loop handler. /// \param fd The file descriptor to be removed from monitoring. virtual void unmonitor(int fd) = 0; - - /// Write the driver information onto a stream, for debugging and - /// for dumping the configuration information. - /// \param stream A reference to an instance of ostream on which the - std::ostream & operator << (std::ostream &); }; /// Radio device keying driver. @@ -368,7 +373,7 @@ namespace FreeDV { Interfaces() : codec(0), event_handler(0), keying_output(0), loudspeaker(0), microphone(0), modem(0), ptt_input_digital(0), ptt_input_ssb(0), - receiver(0), text(0), transmitter(0), + receiver(0), text_input(0), transmitter(0), user_interface(0) { } @@ -390,7 +395,7 @@ namespace FreeDV { /// The PTT input that indicates the transmission is to be SSB. PTTInput * ptt_input_ssb; /// The text to be transmitted in our text side-channel. - TextInput * text; + TextInput * text_input; /// The audio output that drives the transmitter. AudioOutput * transmitter; /// The audio input from the receiver. @@ -398,11 +403,38 @@ namespace FreeDV { /// The user interface driver. Used for GUIs. UserInterface * user_interface; + /// Fill in default drivers if the user or UserInterface hasn't set any. + void fill_in(); + /// Write the command-line flags necessary to configure the drivers as /// they are presently configured to the stream. This is used to save /// the configuration or debug the program. /// \param stream A reference to an instance of ostream on which the - std::ostream & operator << (std::ostream &) const; + /// \return A reference to the provided stream, meant for the + /// usual successive call paradigm of ostream operator << . + virtual std::ostream & + print(std::ostream &) const; + }; + /// Write the driver information from the Interfaces object onto a stream, + /// for debugging and dumping the configuration information. + /// \param stream A reference to an instance of ostream upon which the + /// object information is to be rendered. + /// \return A reference to the provided stream, meant for the + /// usual successive call paradigm of ostream operator << . + inline std::ostream & + operator << (std::ostream & stream, const Interfaces & interfaces) { + return interfaces.print(stream); + } + + namespace Driver { + AudioInput * Tone(const char * parameter); + AudioOutput * AudioSink(const char * parameter); + Codec * CodecNoOp(const char * parameter); + Keying * KeyingSink(const char * parameter); + Modem * ModemNoOp(const char * parameter); + PTTInput * PTTConstant(const char * parameter); + TextInput * TextConstant(const char * parameter); + UserInterface * BlankPanel(const char * parameter, Interfaces *); }; } @@ -433,7 +465,7 @@ namespace FreeDV { /// Print the available drivers to the argument stream. /// \param stream A reference to an instance of ostream on which the /// information is to be printed. - void print(std::ostream & stream); + std::ostream & print(std::ostream & stream) const; /// Instantiate an AudioInput driver. /// \param driver The name of the driver. @@ -502,12 +534,18 @@ namespace FreeDV { /// \param driver The name of the driver. /// \param creator The coroutine that will instantiate the driver. void register_user_interface(const char * driver, UserInterface * (*creator)(const char *, Interfaces *)); - - /// Print the available drivers to the argument stream. - /// \param stream A reference to an instance of ostream on which the - /// information is to be printed. - std::ostream & operator << (std::ostream &) const; }; + /// Write the driver information from the DriverManager object onto a stream, + /// for debugging and dumping the configuration information. + /// \param stream A reference to an instance of ostream upon which the + /// object information is to be rendered. + /// \return A reference to the provided stream, meant for the + /// usual successive call paradigm of ostream operator << . + inline std::ostream & + operator << (std::ostream & stream, const DriverManager & d) { + return d.print(stream); + } + /// Global reference to the driver manager. extern DriverManager & driver_manager; diff --git a/freedv-server/source/keying_sink.cpp b/freedv-server/source/keying_sink.cpp index b24d54d5..69805bb5 100644 --- a/freedv-server/source/keying_sink.cpp +++ b/freedv-server/source/keying_sink.cpp @@ -31,17 +31,17 @@ namespace FreeDV { { } -#ifndef NO_INITIALIZERS - static Keying * - creator(const char * parameter) + Keying * + Driver::KeyingSink(const char * parameter) { - return new KeyingSink(parameter); + return new ::FreeDV::KeyingSink(parameter); } +#ifndef NO_INITIALIZERS static bool initializer() { - init_driver_manager().register_keying_output("sink", creator); + init_driver_manager().register_keying_output("sink", Driver::KeyingSink); return true; } static const bool initialized = initializer(); diff --git a/freedv-server/source/modem_noop.cpp b/freedv-server/source/modem_noop.cpp index 1e5a6bac..7f019657 100644 --- a/freedv-server/source/modem_noop.cpp +++ b/freedv-server/source/modem_noop.cpp @@ -22,17 +22,17 @@ namespace FreeDV { { } -#ifndef NO_INITIALIZERS - static Modem * - creator(const char * parameter) + Modem * + Driver::ModemNoOp(const char * parameter) { - return new ModemNoOp(parameter); + return new ::FreeDV::ModemNoOp(parameter); } +#ifndef NO_INITIALIZERS static bool initializer() { - init_driver_manager().register_modem("no-op", creator); + init_driver_manager().register_modem("no-op", Driver::ModemNoOp); return true; } static const bool initialized = initializer(); diff --git a/freedv-server/source/ptt_constant.cpp b/freedv-server/source/ptt_constant.cpp index 7dfe1de7..474d376b 100644 --- a/freedv-server/source/ptt_constant.cpp +++ b/freedv-server/source/ptt_constant.cpp @@ -21,17 +21,17 @@ namespace FreeDV { { } -#ifndef NO_INITIALIZERS - static PTTInput * - creator(const char * parameter) + PTTInput * + Driver::PTTConstant(const char * parameter) { - return new PTTConstant(parameter); + return new ::FreeDV::PTTConstant(parameter); } +#ifndef NO_INITIALIZERS static bool initializer() { - init_driver_manager().register_ptt_input("constant", creator); + init_driver_manager().register_ptt_input("constant", Driver::PTTConstant); return true; } static const bool initialized = initializer(); diff --git a/freedv-server/source/text_constant.cpp b/freedv-server/source/text_constant.cpp index 02bb75f2..adee5063 100644 --- a/freedv-server/source/text_constant.cpp +++ b/freedv-server/source/text_constant.cpp @@ -21,17 +21,17 @@ namespace FreeDV { { } -#ifndef NO_INITIALIZERS - static TextInput * - creator(const char * parameter) + TextInput * + Driver::TextConstant(const char * parameter) { - return new TextConstant(parameter); + return new ::FreeDV::TextConstant(parameter); } +#ifndef NO_INITIALIZERS static bool initializer() { - init_driver_manager().register_text_input("constant", creator); + init_driver_manager().register_text_input("constant", Driver::TextConstant); return true; } static const bool initialized = initializer(); diff --git a/freedv-server/source/tone.cpp b/freedv-server/source/tone.cpp index 342d4434..6b84d7c7 100644 --- a/freedv-server/source/tone.cpp +++ b/freedv-server/source/tone.cpp @@ -46,17 +46,17 @@ namespace FreeDV { return 0; } -#ifndef NO_INITIALIZERS - static AudioInput * - creator(const char * parameter) + AudioInput * + Driver::Tone(const char * parameter) { - return new Tone(parameter); + return new ::FreeDV::Tone(parameter); } +#ifndef NO_INITIALIZERS static bool initializer() { - init_driver_manager().register_audio_input("tone", creator); + init_driver_manager().register_audio_input("tone", Driver::Tone); return true; } static const bool initialized = initializer(); -- 2.25.1