From: bruceperens Date: Fri, 17 Jan 2014 19:47:39 +0000 (+0000) Subject: Let's try libevent instead of a POSIX event handler. X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=276c178bb792038de757bd5a0a1c8a10676cf9f0;p=freetel-svn-tracking.git Let's try libevent instead of a POSIX event handler. git-svn-id: https://svn.code.sf.net/p/freetel/code@1369 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/freedv-server/CMakeLists.txt b/freedv-server/CMakeLists.txt index 7a4f492c..1d7f491f 100644 --- a/freedv-server/CMakeLists.txt +++ b/freedv-server/CMakeLists.txt @@ -96,10 +96,10 @@ set(Compile.sources 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/libevent.cpp source/modem.cpp source/modem_noop.cpp source/ptt_constant.cpp diff --git a/freedv-server/source/drivers.h b/freedv-server/source/drivers.h index e269feb5..9ac02e28 100644 --- a/freedv-server/source/drivers.h +++ b/freedv-server/source/drivers.h @@ -430,8 +430,8 @@ 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); + EventHandler * LibEvent(const char * parameter); Modem * ModemNoOp(const char * parameter); PTTInput * PTTConstant(const char * parameter); TextInput * TextConstant(const char * parameter); diff --git a/freedv-server/source/event_posix.cpp b/freedv-server/source/event_posix.cpp deleted file mode 100644 index bb1c964f..00000000 --- a/freedv-server/source/event_posix.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/// 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 -} diff --git a/freedv-server/source/libevent.cpp b/freedv-server/source/libevent.cpp new file mode 100644 index 00000000..20cd344c --- /dev/null +++ b/freedv-server/source/libevent.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 LibEvent : public EventHandler { + protected: + /// Run one iteration of the event handler. + void iterate(); + + public: + /// Create an event handler instance. + LibEvent(const char * parameters); + + virtual ~LibEvent(); + + /// 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); + }; + + LibEvent::LibEvent(const char * parameters) + : EventHandler("posix", parameters) + { + } + + LibEvent::~LibEvent() + { + } + + void + LibEvent::iterate() + { + } + + EventHandler * + Driver::LibEvent(const char * parameter) + { + return new ::FreeDV::LibEvent(parameter); + } + + void + LibEvent::monitor(int fd, unsigned int type, void * private_data, + void (*event)(int fd, unsigned int type, void * private_data)) + { + } + + void + LibEvent::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 +}