More refactoring, make operator << compile properly.
authorbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 17 Jan 2014 18:22:55 +0000 (18:22 +0000)
committerbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 17 Jan 2014 18:22:55 +0000 (18:22 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1367 01035d8c-6547-0410-b346-abe4f91aad63

12 files changed:
freedv-server/CMakeLists.txt
freedv-server/source/audio_sink.cpp
freedv-server/source/big_main.cpp
freedv-server/source/blank_panel.cpp
freedv-server/source/codec_noop.cpp
freedv-server/source/driver_manager.cpp
freedv-server/source/drivers.h
freedv-server/source/keying_sink.cpp
freedv-server/source/modem_noop.cpp
freedv-server/source/ptt_constant.cpp
freedv-server/source/text_constant.cpp
freedv-server/source/tone.cpp

index 401ae5d8083a7708700f4ae62a8806eadadd45e8..5734a7aba29b277496c71bf4e364ee7709caee4d 100644 (file)
@@ -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
index c1aeabc8fa7e6f9edff4a36a9e1aa2a959723fd6..a8f8b1e2b45a5a4650a8ae3ff5be451182b41137 100644 (file)
@@ -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();
index 3915e48dcf5f588fab94430d072087f019364252..5820b32d1116500f901a22d6608dca6804e835ea 100644 (file)
@@ -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;
       }
index 8a6941722a0f0331b7b346c2be4fc6620cd1f06c..a9444fdf76802e936dc064fae89d388310f72ec1 100644 (file)
@@ -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();
index 954efe5fc2115b3de483d46dae4010efe518965a..99c8a5526ded629d347171eb101ee4f027b29963 100644 (file)
@@ -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();
index 428e4da0cbd4d69b22a6453f0b8884bee037148c..8dc7959960cba76999db367b7d51798299a2d3c5 100644 (file)
@@ -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.
index 340189b185934f30fba0565dd7db6b347ffc2800..22e5c9812ae2c15bf3b830d73b4c9fb004ace5e0 100644 (file)
@@ -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;
index b24d54d503751890a66c6fb1b29e109b9fb673af..69805bb5808ede89d52ab2470137d6f6ca953cc1 100644 (file)
@@ -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();
index 1e5a6bacc62e9c9c0155465e877a1dc4ec8ba855..7f019657d65ca260ef5ef326c58e8e333c8031d2 100644 (file)
@@ -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();
index 7dfe1de787057b8517a6712c2b372060e86455a7..474d376b3790d87b794b43a020f046a80960f5e8 100644 (file)
@@ -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();
index 02bb75f23357eae685c75f71ccc74c0756dbee2f..adee5063558c39867ecf7d573dc203a85b5f9c1c 100644 (file)
@@ -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();
index 342d4434272760066a27a17526276eb9372b8101..6b84d7c7c6ef96d23fee75b5556b901ca006cddb 100644 (file)
@@ -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();