First definition of driver classes.
authorbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 12 Dec 2013 21:21:58 +0000 (21:21 +0000)
committerbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 12 Dec 2013 21:21:58 +0000 (21:21 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1338 01035d8c-6547-0410-b346-abe4f91aad63

freedv-server/source/audio_input.cpp [new file with mode: 0644]
freedv-server/source/audio_output.cpp [new file with mode: 0644]
freedv-server/source/driver_manager.cpp [new file with mode: 0644]
freedv-server/source/drivers.h
freedv-server/source/keying.cpp [new file with mode: 0644]
freedv-server/source/main.cpp
freedv-server/source/ptt_input.cpp [new file with mode: 0644]
freedv-server/source/text_input.cpp [new file with mode: 0644]
freedv-server/source/tone.cpp [new file with mode: 0644]
freedv-server/source/user_interface.cpp [new file with mode: 0644]

diff --git a/freedv-server/source/audio_input.cpp b/freedv-server/source/audio_input.cpp
new file mode 100644 (file)
index 0000000..9a2704d
--- /dev/null
@@ -0,0 +1,18 @@
+#include "drivers.h"
+#include <iostream>
+
+namespace FreeDV {
+  AudioInput::AudioInput()
+  {
+  }
+
+  AudioInput::~AudioInput()
+  {
+  }
+
+  bool
+  AudioInput::captive()
+  {
+    return false;
+  }
+};
diff --git a/freedv-server/source/audio_output.cpp b/freedv-server/source/audio_output.cpp
new file mode 100644 (file)
index 0000000..47c79a6
--- /dev/null
@@ -0,0 +1,18 @@
+#include "drivers.h"
+#include <iostream>
+
+namespace FreeDV {
+  AudioOutput::AudioOutput()
+  {
+  }
+
+  AudioOutput::~AudioOutput()
+  {
+  }
+
+  bool
+  AudioOutput::captive()
+  {
+    return false;
+  }
+};
diff --git a/freedv-server/source/driver_manager.cpp b/freedv-server/source/driver_manager.cpp
new file mode 100644 (file)
index 0000000..11e991d
--- /dev/null
@@ -0,0 +1,91 @@
+#include <iostream>
+#include "drivers.h"
+
+using namespace std;
+
+namespace FreeDV {
+  // Global instance of the driver manager used to register
+  // drivers and to create driver instances.
+  DriverManager        driver_manager;
+  DriverManager::DriverManager()
+  {
+  }
+
+  DriverManager::~DriverManager()
+  {
+  }
+
+  AudioInput *
+  DriverManager::audio_input(const char * driver, const char * parameter)
+  {
+    return 0;
+  }
+  AudioOutput *
+  DriverManager::audio_output(const char * driver, const char * parameter)
+  {
+    return 0;
+  }
+  Keying *
+  DriverManager::keying(const char * driver, const char * parameter)
+  {
+    return 0;
+  }
+  PTTInput *
+  DriverManager::ptt_input(const char * driver, const char * parameter)
+  {
+    return 0;
+  }
+  TextInput *
+  DriverManager::text_input(const char * driver, const char * parameter)
+  {
+    return 0;
+  }
+  UserInterface *
+  DriverManager::user_interface(const char * driver, const char * parameter)
+  {
+    return 0;
+  }
+
+  void
+  DriverManager::register_audio_input(const char * driver, AudioInput * (*creator)(const char *))
+  {
+    clog << "Registered audio input driver \"" << driver << "\"." << endl;
+  }
+
+  void
+  DriverManager::register_audio_output(const char * driver, AudioOutput * (*creator)(const char *))
+  {
+    clog << "Registered audio output driver \"" << driver << "\"." << endl;
+  }
+
+  void
+  DriverManager::register_keying(const char * driver, Keying * (*creator)(const char *))
+  {
+    clog << "Registered keying driver \"" << driver << "\"." << endl;
+  }
+
+  void
+  DriverManager::register_ptt_input(const char * driver, PTTInput * (*creator)(const char *))
+  {
+    clog << "Registered PTT driver \"" << driver << "\"." << endl;
+  }
+
+
+  void
+  DriverManager::register_text_input(const char * driver, TextInput * (*creator)(const char *))
+  {
+    clog << "Registered text input driver \"" << driver << "\"." << endl;
+  }
+
+  void
+  DriverManager::register_user_interface(const char * driver, UserInterface * (*creator)(const char *))
+  {
+    clog << "Registered user interface driver \"" << driver << "\"." << endl;
+  }
+};
index bf30ae86fb8a846ed19149c3778838c6d3a8527c..90084d097bed832dc80a006252ae27572a4d547f 100644 (file)
  * FreeDV driver interface definitions.
  */
 
+#include <stdlib.h>
+
 namespace FreeDV {
   class AudioInput {
+  protected:
+       // Create an AudioInput device instance.
+
+       // What shall we do about the audio rate?
+
+                       AudioInput();
+       virtual         ~AudioInput() = 0;
+
+  public:
+       // Return true if this object is owned by a UserInterface object, in which case we should not
+       // destroy it separately.
+       virtual bool    captive();
+
+       // Get the current audio level, normalized to the range of 0.0 to 1.0.
+       virtual float   level() = 0;
+
+       // Set the current audio level within the range of 0.0 to 1.0.
+       virtual float   level(float value) = 0;
+
+        // Read audio into the "short" type.
+       virtual size_t  read_short(short * array, size_t length) = 0;
   };
 
   class AudioOutput {
+  protected:
+       // Create an AudioOutput device instance.
+
+       // What shall we do about the audio rate?
+
+                       AudioOutput();
+       virtual         ~AudioOutput() = 0;
+
+  public:
+       // Return true if this object is owned by a UserInterface object, in which case we should not
+       // destroy it separately.
+       virtual bool    captive();
+
+       // Get the current audio level, normalized to the range of 0.0 to 1.0.
+       virtual float   level() = 0;
+
+       // Set the current audio level within the range of 0.0 to 1.0.
+       virtual float   level(float value) = 0;
+
+        // Write audio into the "short" type.
+       virtual size_t  write_short(short * array, size_t length) = 0;
   };
 
   class Keying {
+  protected:
+       // Create an radio keying device instance.
+
+                       Keying();
+       virtual         ~Keying() = 0;
+
+  public:
+       // If true, key the transmitter. If false, unkey.
+       virtual void    key(bool value) = 0;
   };
 
   class PTTInput {
+  protected:
+       // The driver calls this member to inform FreeDV that the PTT switch value has changed.
+       // the value is true for key-down, false for key-up.
+       void            changed(bool value);
+
+       // Create a push-to-talk switch instance.
+
+                       PTTInput();
+       virtual         ~PTTInput() = 0;
+
+  public:
+       // Return true if this object is owned by a UserInterface object, in which case we should not
+       // destroy it separately.
+       virtual bool    captive();
+
   };
 
   class TextInput {
+  protected:
+       // The driver calls this member to set the text.
+       void            set(const char * text);
+
+       // Type for the text message source function. This is mostly used to set the text to a constant value.
+       // Create a push-to-talk switch instance.
+
+                       TextInput();
+       virtual         ~TextInput() = 0;
+
+  public:
+       // Return true if this object is owned by a UserInterface object, in which case we should not
+       // destroy it separately.
+       virtual bool    captive();
+
   };
 
   class UserInterface {
+       // Generic interface to user interfaces. They may be graphical, they may be server-client interfaces,
+       // they may be specialized hardware devices, especially if this software is embedded.
+       // There must be inputs and callbacks for many things here.
+       // UserInterfaces may provide their own drivers for microphone, loudspeaker, TextInput, and PTT.
+
+  protected:
+       // All of the callbacks from the user interface are implemented in the base class and declared here.
+
+                               UserInterface();
+       virtual                 ~UserInterface() = 0;
+
+  public:
+       // If this interface prodvides its own microphone driver, return it. Otherwise return 0.
+       // This is guaranteed to return the same object every time, for the lifetime of this object.
+       virtual AudioInput *    microphone() = 0;
+
+       // If this interface prodvides its own loudspeaker driver, return it. Otherwise return 0.
+       // This is guaranteed to return the same object every time, for the lifetime of this object.
+       virtual AudioOutput *   loudspeaker() = 0;
+
+       // If this interface prodvides its own text input driver, return it. Otherwise return 0.
+       // This is guaranteed to return the same object every time, for the lifetime of this object.
+       virtual TextInput *     text_input() = 0;
+
+       // If this interface prodvides its own push-to-talk input driver, return it. Otherwise return 0.
+       // This is guaranteed to return the same object every time, for the lifetime of this object.
+       virtual PTTInput *      ptt_input() = 0;
+  };
+
+  class DriverManager {
+  public:
+                       DriverManager();
+                       ~DriverManager();
+
+       AudioInput *    audio_input(const char * driver, const char * parameter);
+       AudioOutput *   audio_output(const char * driver, const char * parameter);
+       Keying *        keying(const char * driver, const char * parameter);
+       PTTInput *      ptt_input(const char * driver, const char * parameter);
+       TextInput *     text_input(const char * driver, const char * parameter);
+       UserInterface * user_interface(const char * driver, const char * parameter);
+
+       void            register_audio_input(const char * driver, AudioInput * (*creator)(const char *));
+       void            register_audio_output(const char * driver, AudioOutput * (*creator)(const char *));
+       void            register_keying(const char * driver, Keying * (*creator)(const char *));
+       void            register_ptt_input(const char * driver, PTTInput * (*creator)(const char *));
+       void            register_text_input(const char * driver, TextInput * (*creator)(const char *));
+       void            register_user_interface(const char * driver, UserInterface * (*creator)(const char *));
   };
+
+  extern DriverManager driver_manager;
 };
diff --git a/freedv-server/source/keying.cpp b/freedv-server/source/keying.cpp
new file mode 100644 (file)
index 0000000..5174881
--- /dev/null
@@ -0,0 +1,12 @@
+#include "drivers.h"
+#include <iostream>
+
+namespace FreeDV {
+  Keying::Keying()
+  {
+  }
+
+  Keying::~Keying()
+  {
+  }
+};
index f558c3c62172c88990e8ede0166dbbbf406d1be4..3cc9b5794d8b6310bdbf90798f9915e242b3e4f3 100644 (file)
@@ -39,11 +39,11 @@ static void help(const char * name)
     "\n\tLong flags with parameters are in the form of --<flag>=<parameter>\n"
     "\tShort flags with parameters are in the form of -<letter> <parameter>\n"
     "\n\tFor example, both of these flags have the same effect:\n"
-    "\t\t-m 1600\n"
+    "\t\t-n 1600\n"
     "\t\t--mode=1600\n"
     "\n\tMode may be one of:\n"
-    "\t\t--mode=1600\t\tNormal 1600 bit-per-second in 1.275 kHz RF bandwidth.\n"
-    "\t\t--mode=1600-wide\t1600 bit-per-second in 2.125 kHz, wider guard-bands for improved\n"
+    "\t\t1600\t\tNormal 1600 bit-per-second in 1.275 kHz RF bandwidth.\n"
+    "\t\t1600-wide\t1600 bit-per-second in 2.125 kHz, wider guard-bands for improved\n"
     "\t\t\t\t\tDX performance.\n"
     "\n\tFlags used to select devices must have a \"<driver>:<parameter>\" argument\n"
     "\twhere <driver> is the name of a device driver for the selected input/output device,\n"
@@ -66,6 +66,17 @@ struct parameters {
        const char * * transmitter;
 };
 
+struct interfaces {
+       UserInterface * interface;
+       Keying *        keying;
+       AudioOutput *   loudspeaker;
+       AudioInput *    microphone;
+       PTTInput *      ptt;
+       AudioInput *    receiver;
+       TextInput *     text;
+       AudioOutput *   transmitter;
+};
+
 static int run(struct parameters * p)
 {
   return 0;
diff --git a/freedv-server/source/ptt_input.cpp b/freedv-server/source/ptt_input.cpp
new file mode 100644 (file)
index 0000000..f5a050b
--- /dev/null
@@ -0,0 +1,18 @@
+#include "drivers.h"
+#include <iostream>
+
+namespace FreeDV {
+  PTTInput::PTTInput()
+  {
+  }
+
+  PTTInput::~PTTInput()
+  {
+  }
+
+  bool
+  PTTInput::captive()
+  {
+    return false;
+  }
+};
diff --git a/freedv-server/source/text_input.cpp b/freedv-server/source/text_input.cpp
new file mode 100644 (file)
index 0000000..bffc9fa
--- /dev/null
@@ -0,0 +1,23 @@
+#include "drivers.h"
+#include <iostream>
+
+namespace FreeDV {
+  TextInput::TextInput()
+  {
+  }
+
+  TextInput::~TextInput()
+  {
+  }
+
+  bool
+  TextInput::captive()
+  {
+    return false;
+  }
+
+  void
+  TextInput::set(const char *)
+  {
+  }
+};
diff --git a/freedv-server/source/tone.cpp b/freedv-server/source/tone.cpp
new file mode 100644 (file)
index 0000000..703f03f
--- /dev/null
@@ -0,0 +1,60 @@
+#include "drivers.h"
+#include <iostream>
+
+// This is a test driver that provides tones.
+namespace FreeDV {
+  class Tone : public AudioInput {
+  public:
+                       Tone(const char * parameter);
+    virtual            ~Tone();
+    
+    // Get the current audio level, normalized to the range of 0.0 to 1.0.
+    virtual float      level();
+    
+    // Set the current audio level within the range of 0.0 to 1.0.
+    virtual float      level(float value);
+    
+    // Read audio into the "short" type.
+    virtual size_t     read_short(short * array, size_t length);
+  };
+
+  Tone::Tone(const char * parameter)
+  {
+  }
+
+  Tone::~Tone()
+  {
+  }
+
+  float
+  Tone::level()
+  {
+    return 0;
+  }
+
+  float
+  Tone::level(float value)
+  {
+    return value;
+  }
+
+  size_t
+  Tone::read_short(short * array, size_t length)
+  {
+    return 0;
+  }
+
+  static AudioInput *
+  creator(const char * parameter)
+  {
+    return new Tone(parameter);
+  }
+
+  static bool
+  initializer()
+  {
+    driver_manager.register_audio_input("tone", creator);
+    return true;
+  }
+  static const bool initialized = initializer();
+};
diff --git a/freedv-server/source/user_interface.cpp b/freedv-server/source/user_interface.cpp
new file mode 100644 (file)
index 0000000..c39b658
--- /dev/null
@@ -0,0 +1,12 @@
+#include "drivers.h"
+#include <iostream>
+
+namespace FreeDV {
+  UserInterface::UserInterface()
+  {
+  }
+
+  UserInterface::~UserInterface()
+  {
+  }
+};