Oops, some files weren't added to SVN previously. More work on the event
authorbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 21 Jan 2014 03:46:22 +0000 (03:46 +0000)
committerbruceperens <bruceperens@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 21 Jan 2014 03:46:22 +0000 (03:46 +0000)
interface.

git-svn-id: https://svn.code.sf.net/p/freetel/code@1380 01035d8c-6547-0410-b346-abe4f91aad63

freedv-server/source/audio_device.cpp [new file with mode: 0644]
freedv-server/source/base.cpp [new file with mode: 0644]
freedv-server/source/drivers.h
freedv-server/source/interfaces.cpp [new file with mode: 0644]
freedv-server/source/keying_sink.cpp
freedv-server/source/test/keying_sink.cpp
freedv-server/source/utility.cpp [new file with mode: 0644]

diff --git a/freedv-server/source/audio_device.cpp b/freedv-server/source/audio_device.cpp
new file mode 100644 (file)
index 0000000..3ecf7c6
--- /dev/null
@@ -0,0 +1,30 @@
+/// The AudioDevice class.
+
+#include "drivers.h"
+#include <stdexcept>
+
+namespace FreeDV {
+  AudioDevice::AudioDevice(const char * name, const char * parameters)
+  : IODevice(name, parameters), master_amplitude(1.0)
+  {
+  }
+
+  AudioDevice::~AudioDevice()
+  {
+  }
+
+  float
+  AudioDevice::amplitude()
+  {
+    return master_amplitude;
+  }
+
+  void
+  AudioDevice::amplitude(float value)
+  {
+    if ( value < 0.0 || value > 1.0 )
+      throw std::runtime_error(
+       "Amplitude set to value outside of the range 0.0..1.0");
+    master_amplitude = value;
+  }
+}
diff --git a/freedv-server/source/base.cpp b/freedv-server/source/base.cpp
new file mode 100644 (file)
index 0000000..5bb9ab5
--- /dev/null
@@ -0,0 +1,27 @@
+/// The general base class for drivers.
+
+#include "drivers.h"
+
+namespace FreeDV {
+  Base::Base(const char * _name, const char * _parameters)
+  : name(_name), parameters(copy_string(_parameters))
+  {
+  }
+
+  Base::~Base()
+  {
+    delete parameters;
+  }
+
+  bool const
+  Base::captive() const
+  {
+    return false;
+  }
+
+  std::ostream &
+  Base::print(std::ostream & stream) const
+  {
+    return stream << name << ':' << parameters;
+  }
+}
index e7e09f663b8b6ccdc7d451a3995cb4da8aa35798..580066be3c096f37ba90a1b89a2eff0659623414 100644 (file)
@@ -82,11 +82,14 @@ namespace FreeDV {
   }
   
   /// Virtual base class for all drivers that perform non-blocking I/O.
-  /// These are AudioInput and AudioOutput, PTTInput, TextInput, and
-  /// UserInterface.
-  /// Keying is assumed to never need to block.
+  /// These are AudioInput and AudioOutput, PTTInput, TextInput,
+  /// KeyingOutput and UserInterface.
   class IODevice : public ::FreeDV::Base {
   protected:
+    /// Construct an I/O device.
+    /// \param _name Name of the driver. This is expected to be a single
+    ///  constant static string per driver class.
+    /// \param _parameters Driver-specific configuration parameters.
                        IODevice(const char * name, const char * parameters);
 
   public:
@@ -327,6 +330,9 @@ namespace FreeDV {
     /// Key or un-key the transmitter.
     /// \param value If true, key the transmitter. If false, un-key.
     virtual void       key(bool value) = 0;
+
+    /// Return the amount of bytes ready to write.
+    virtual size_t     ready() = 0;
   };
 
   /// Softmodem driver.
diff --git a/freedv-server/source/interfaces.cpp b/freedv-server/source/interfaces.cpp
new file mode 100644 (file)
index 0000000..4315b68
--- /dev/null
@@ -0,0 +1,65 @@
+/// The Interfaces class.
+
+#include "drivers.h"
+
+// Empty string, for convenience in initializing drivers.
+static const char empty[1] = { '\0' };
+
+namespace FreeDV {
+  void
+  Interfaces::fill_in()
+  {
+    if ( !codec )
+      codec = Driver::CodecNoOp(empty);
+
+    if ( !keying_output )
+      keying_output = Driver::KeyingSink(empty);
+
+    if ( !loudspeaker )
+      loudspeaker = Driver::AudioSink(empty);
+
+    if ( !microphone )
+      microphone = Driver::Tone(empty);
+
+    if ( !modem )
+      modem = Driver::ModemNoOp(empty);
+
+    if ( !ptt_input_digital )
+      ptt_input_digital = Driver::PTTConstant(empty);
+
+    if ( !ptt_input_ssb )
+      ptt_input_ssb = Driver::PTTConstant(empty);
+
+    if ( !text_input )
+      text_input = Driver::TextConstant(empty);
+
+    if ( !transmitter )
+      transmitter = Driver::AudioSink(empty);
+
+    if ( !receiver )
+      receiver = Driver::Tone(empty);
+
+    if ( !user_interface )
+      user_interface = Driver::BlankPanel(empty, this);
+  }
+
+  std::ostream &
+  Interfaces::print(std::ostream & stream) const
+  {
+    using namespace std;
+
+    stream << "--codec=" << *codec << endl;
+    stream << "--gui=" << *user_interface << endl;
+    stream << "--keying=" << *keying_output << endl;
+    stream << "--loudspeaker=" << *loudspeaker << endl;
+    stream << "--microphone=" << *microphone << endl;
+    stream << "--modem=" << *modem << endl;
+    stream << "--ptt-digital=" << *ptt_input_digital << endl;
+    stream << "--ptt-ssb=" << *ptt_input_ssb << endl;
+    stream << "--receiver=" << *receiver << endl;
+    stream << "--text=" << *text_input << endl;
+    stream << "--transmitter=" << *transmitter << endl;
+
+    return stream;
+  }
+}
index e005dc37be5f499df2e6734de62fbbd7074d6288..f2616c0cb41e815acf19984a4c2e7174a0328e1f 100644 (file)
@@ -8,13 +8,16 @@ namespace FreeDV {
   /// KeyingOutput output "sink", doesn't key anything. For testing or use with VOX.
   class KeyingSink : public KeyingOutput {
   public:
+    /// Instantiate keying sink driver.
+                       KeyingSink(const char *);
+    virtual            ~KeyingSink();
 
-       /// Instantiate keying sink driver.
-               KeyingSink(const char *);
-       virtual ~KeyingSink();
+    /// If the value is true, transmit. Otherwise receive.
+    void               key(bool value);
 
-       /// If the value is true, transmit. Otherwise receive.
-       void    key(bool value);
+    /// Return the amount of bytes ready for read. In this case, it always
+    /// returns SIZE_MAX.
+    size_t             ready();
   };
 
   KeyingSink::KeyingSink(const char * parameters)
@@ -35,6 +38,12 @@ namespace FreeDV {
       std::cerr << "keying: RECEIVE" << std::endl;
   }
 
+  size_t
+  KeyingSink::ready()
+  {
+    return SIZE_MAX;
+  }
+
   KeyingOutput *
   Driver::KeyingSink(const char * parameter)
   {
index c757e37295d9e828cf9acaf56e8c0a80136a79d0..ce39bb707556e36470b0f88ac8bd277e2f203686 100644 (file)
@@ -23,7 +23,10 @@ protected:
 };
 
 TEST_F(KeyingSinkTest, CanCallKey) {
-
   k->key(true);
   k->key(false);
 }
+
+TEST_F(KeyingSinkTest, AlwaysReady) {
+  EXPECT_EQ(SIZE_MAX, k->ready());
+}
diff --git a/freedv-server/source/utility.cpp b/freedv-server/source/utility.cpp
new file mode 100644 (file)
index 0000000..079a85a
--- /dev/null
@@ -0,0 +1,13 @@
+#include "drivers.h"
+#include <string.h>
+
+namespace FreeDV {
+  char *
+  copy_string(const char * s)
+  {
+    const size_t length(strlen(s) + 1);
+    char * copy = new char[length];
+    memcpy(copy, s, length);
+    return copy;
+  }
+}