From: bruceperens Date: Fri, 17 Jan 2014 19:29:37 +0000 (+0000) Subject: Add framework for POSIX event handler. X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=69d4e500f2dc1f8a7fff8af63a8730ae85854cba;p=freetel-svn-tracking.git Add framework for POSIX event handler. git-svn-id: https://svn.code.sf.net/p/freetel/code@1368 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/freedv-server/CMakeLists.txt b/freedv-server/CMakeLists.txt index 5734a7ab..7a4f492c 100644 --- a/freedv-server/CMakeLists.txt +++ b/freedv-server/CMakeLists.txt @@ -95,19 +95,21 @@ set(Compile.sources source/codec.cpp source/codec_noop.cpp source/driver_manager.cpp + source/event_handler.cpp + source/event_posix.cpp source/interfaces.cpp source/keying.cpp source/keying_sink.cpp source/modem.cpp source/modem_noop.cpp - source/ptt_input.cpp source/ptt_constant.cpp + source/ptt_input.cpp source/run.cpp source/text_constant.cpp source/text_input.cpp source/tone.cpp - source/utility.cpp source/user_interface.cpp + source/utility.cpp ) set(Optional.sources diff --git a/freedv-server/source/drivers.h b/freedv-server/source/drivers.h index 22e5c981..e269feb5 100644 --- a/freedv-server/source/drivers.h +++ b/freedv-server/source/drivers.h @@ -430,6 +430,7 @@ namespace FreeDV { AudioInput * Tone(const char * parameter); AudioOutput * AudioSink(const char * parameter); Codec * CodecNoOp(const char * parameter); + EventHandler * EventHandlerPOSIX(const char * parameter); Keying * KeyingSink(const char * parameter); Modem * ModemNoOp(const char * parameter); PTTInput * PTTConstant(const char * parameter); diff --git a/freedv-server/source/event_handler.cpp b/freedv-server/source/event_handler.cpp new file mode 100644 index 00000000..b80799e9 --- /dev/null +++ b/freedv-server/source/event_handler.cpp @@ -0,0 +1,11 @@ +/// The virtual base class for event handlers. + +#include "drivers.h" + +namespace FreeDV { + + EventHandler::~EventHandler() + { + } + +} diff --git a/freedv-server/source/event_posix.cpp b/freedv-server/source/event_posix.cpp new file mode 100644 index 00000000..bb1c964f --- /dev/null +++ b/freedv-server/source/event_posix.cpp @@ -0,0 +1,81 @@ +/// The POSIX event handler, mainly for running without a GUI. + +#include "drivers.h" + +namespace FreeDV { + /// Event handler class for POSIX. + class EventHandlerPOSIX : public EventHandler { + protected: + /// Run one iteration of the event handler. + void iterate(); + + public: + /// Create an event handler instance. + EventHandlerPOSIX(const char * parameters); + + virtual ~EventHandlerPOSIX(); + + /// Monitor a file descriptor in the event loop. Call a function if the + /// file descriptor is ready for I/O. + /// \param fd The file descriptor to monitor. + /// \param type A bit-field of values defined in this class, + /// indicating the kinds of events to listen for. + /// \param private_data Private data to be passed to the event + /// function. + /// \param event A coroutine to call when there is a status change + /// on the file descriptor. The arguments of the coroutine are + /// - fd: The file descriptor that has an event. + /// - type: A bit-field of FDStatus values indicating the events + /// received. + /// - private: The address of opaque data to be passed to the driver. + virtual void monitor(int fd, unsigned int type, void * private_data, + void (*event)(int fd, unsigned int type, void * private_data) + ); + + /// Remove all monitoring of the given file descriptor by the event + /// loop handler. + /// \param fd The file descriptor to be removed from monitoring. + virtual void unmonitor(int fd); + }; + + EventHandlerPOSIX::EventHandlerPOSIX(const char * parameters) + : EventHandler("posix", parameters) + { + } + + EventHandlerPOSIX::~EventHandlerPOSIX() + { + } + + void + EventHandlerPOSIX::iterate() + { + } + + EventHandler * + Driver::EventHandlerPOSIX(const char * parameter) + { + return new ::FreeDV::EventHandlerPOSIX(parameter); + } + + void + EventHandlerPOSIX::monitor(int fd, unsigned int type, void * private_data, + void (*event)(int fd, unsigned int type, void * private_data)) + { + } + + void + EventHandlerPOSIX::unmonitor(int fd) + { + } + +#ifndef NO_INITIALIZERS + static bool + initializer() + { + init_driver_manager().register_codec("no-op", Driver::CodecNoOp); + return true; + } + static const bool initialized = initializer(); +#endif +}