From: tho Date: Wed, 28 Jul 2010 13:19:32 +0000 (+0000) Subject: PPI: added ActiveBurstSocketSource for testing X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=7a961d216978e108ff4d0831f53f7b0f9f8823df;p=senf.git PPI: added ActiveBurstSocketSource for testing git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1652 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/PPI/SocketSource.ct b/senf/PPI/SocketSource.ct index 58131fa..6eb9780 100644 --- a/senf/PPI/SocketSource.ct +++ b/senf/PPI/SocketSource.ct @@ -37,7 +37,7 @@ template prefix_ Packet senf::ppi::DgramReader::operator()(Handle handle) { Packet packet (Packet::create(senf::noinit)); - handle.read(packet.data(),MaxSize); + handle.read(packet.data(), MaxSize); return packet; } @@ -76,6 +76,68 @@ prefix_ senf::ppi::module::ActiveSocketSource::ActiveSocketSource(Handle route(event_, output); } +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::ActiveBurstSocketSource + +template +prefix_ senf::ppi::module::ActiveBurstSocketSource::ActiveBurstSocketSource(unsigned max_burst) + : maxBurst_(max_burst) +{ + registerEvent( event_, &ActiveBurstSocketSource::read ); + route(event_, output); +} + +template +prefix_ senf::ppi::module::ActiveBurstSocketSource::ActiveBurstSocketSource(Reader reader, unsigned max_burst) + : reader_(reader), maxBurst_(maxBurst) +{ + registerEvent( event_, &ActiveBurstSocketSource::read ); + route(event_, output); +} + +template +prefix_ senf::ppi::module::ActiveBurstSocketSource::ActiveBurstSocketSource(Handle handle, unsigned max_burst) + : handle_(handle), event_(handle_, IOEvent::Read), maxBurst_(max_burst) +{ + registerEvent( event_, &ActiveBurstSocketSource::read ); + route(event_, output); +} + +template +prefix_ senf::ppi::module::ActiveBurstSocketSource::ActiveBurstSocketSource(Handle handle, + Reader reader, unsigned max_burst) + : handle_(handle), event_(handle_, IOEvent::Read), reader_(reader), maxBurst_(max_burst) +{ + registerEvent( event_, &ActiveBurstSocketSource::read ); + route(event_, output); +} + +template +prefix_ void senf::ppi::module::ActiveBurstSocketSource::maxBurst(unsigned max_burst) +{ + maxBurst_ = max_burst; +} + +template +prefix_ unsigned senf::ppi::module::ActiveBurstSocketSource::maxBurst() + const +{ + return maxBurst_; +} + +template +prefix_ void senf::ppi::module::ActiveBurstSocketSource::read() +{ + output(reader_(handle_)); + for (unsigned int i = 0; i < maxBurst_; ++i) { + typename Reader::PacketType p (reader_(handle_)); + if (p.data().size() > 0) + output( p); + else + break; + } +} + ///////////////////////////////ct.e//////////////////////////////////////// #undef prefix_ diff --git a/senf/PPI/SocketSource.cti b/senf/PPI/SocketSource.cti index ffffdd5..08f37bf 100644 --- a/senf/PPI/SocketSource.cti +++ b/senf/PPI/SocketSource.cti @@ -53,15 +53,35 @@ prefix_ void senf::ppi::module::ActiveSocketSource::handle(Handle handle event_.set(handle_, IOEvent::Read); } -//////////////////////////////////////// -// private members - template prefix_ void senf::ppi::module::ActiveSocketSource::read() { output(reader_(handle_)); } +/////////////////////////////////////////////////////////////////////////// +// senf::ppi::module::ActiveBurstSocketSource + +template +prefix_ Reader & senf::ppi::module::ActiveBurstSocketSource::reader() +{ + return reader_; +} + +template +prefix_ typename senf::ppi::module::ActiveBurstSocketSource::Handle +senf::ppi::module::ActiveBurstSocketSource::handle() +{ + return handle_; +} + +template +prefix_ void senf::ppi::module::ActiveBurstSocketSource::handle(Handle handle) +{ + handle_ = handle; + event_.set(handle_, IOEvent::Read); +} + ///////////////////////////////cti.e/////////////////////////////////////// #undef prefix_ diff --git a/senf/PPI/SocketSource.hh b/senf/PPI/SocketSource.hh index 4ae8e8e..c41e314 100644 --- a/senf/PPI/SocketSource.hh +++ b/senf/PPI/SocketSource.hh @@ -139,13 +139,48 @@ namespace module { void handle(Handle handle); ///< Set handle /**< Assigning an empty or in-valid() handle will disable the module until a new, valid handle is assigned. */ - private: + Handle handle_; + IOEvent event_; + Reader reader_; + void read(); + }; + + + template > + class ActiveBurstSocketSource + : public Module + { + SENF_PPI_MODULE(ActiveBurstSocketSource); + + public: + typedef typename Reader::Handle Handle; ///< Handle type requested by the reader + connector::ActiveOutput output; + ///< Output connector to which the data received is written + + ActiveBurstSocketSource(unsigned max_burst); + explicit ActiveBurstSocketSource(Reader reader, unsigned max_burst); + explicit ActiveBurstSocketSource(Handle handle, unsigned max_burst); + ActiveBurstSocketSource(Handle handle, Reader reader, unsigned max_burst); + + Reader & reader(); ///< Access Reader helper + Handle handle(); ///< Access handle + void handle(Handle handle); ///< Set handle + /**< Assigning an empty or in-valid() handle will disable + the module until a new, valid handle is assigned. */ + + unsigned maxBurst() const; + void maxBurst(unsigned max_burst); + + private: Handle handle_; IOEvent event_; Reader reader_; + unsigned maxBurst_; + + void read(); }; }}}