From: bruceperens Date: Thu, 12 Dec 2013 21:21:58 +0000 (+0000) Subject: First definition of driver classes. X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=c1d8083739ef21f14b4548f8c4ac32b80aee4c67;p=freetel-svn-tracking.git First definition of driver classes. git-svn-id: https://svn.code.sf.net/p/freetel/code@1338 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/freedv-server/source/audio_input.cpp b/freedv-server/source/audio_input.cpp new file mode 100644 index 00000000..9a2704d7 --- /dev/null +++ b/freedv-server/source/audio_input.cpp @@ -0,0 +1,18 @@ +#include "drivers.h" +#include + +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 index 00000000..47c79a6b --- /dev/null +++ b/freedv-server/source/audio_output.cpp @@ -0,0 +1,18 @@ +#include "drivers.h" +#include + +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 index 00000000..11e991dc --- /dev/null +++ b/freedv-server/source/driver_manager.cpp @@ -0,0 +1,91 @@ +#include +#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; + } +}; diff --git a/freedv-server/source/drivers.h b/freedv-server/source/drivers.h index bf30ae86..90084d09 100644 --- a/freedv-server/source/drivers.h +++ b/freedv-server/source/drivers.h @@ -2,22 +2,154 @@ * FreeDV driver interface definitions. */ +#include + 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 index 00000000..51748810 --- /dev/null +++ b/freedv-server/source/keying.cpp @@ -0,0 +1,12 @@ +#include "drivers.h" +#include + +namespace FreeDV { + Keying::Keying() + { + } + + Keying::~Keying() + { + } +}; diff --git a/freedv-server/source/main.cpp b/freedv-server/source/main.cpp index f558c3c6..3cc9b579 100644 --- a/freedv-server/source/main.cpp +++ b/freedv-server/source/main.cpp @@ -39,11 +39,11 @@ static void help(const char * name) "\n\tLong flags with parameters are in the form of --=\n" "\tShort flags with parameters are in the form of - \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 \":\" argument\n" "\twhere 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 index 00000000..f5a050b3 --- /dev/null +++ b/freedv-server/source/ptt_input.cpp @@ -0,0 +1,18 @@ +#include "drivers.h" +#include + +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 index 00000000..bffc9fa3 --- /dev/null +++ b/freedv-server/source/text_input.cpp @@ -0,0 +1,23 @@ +#include "drivers.h" +#include + +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 index 00000000..703f03f7 --- /dev/null +++ b/freedv-server/source/tone.cpp @@ -0,0 +1,60 @@ +#include "drivers.h" +#include + +// 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 index 00000000..c39b6584 --- /dev/null +++ b/freedv-server/source/user_interface.cpp @@ -0,0 +1,12 @@ +#include "drivers.h" +#include + +namespace FreeDV { + UserInterface::UserInterface() + { + } + + UserInterface::~UserInterface() + { + } +};