prefix_ Packet senf::ppi::DgramReader<Packet,MaxSize>::operator()(Handle handle)
{
Packet packet (Packet::create(senf::noinit));
- handle.read(packet.data(),MaxSize);
+ handle.read(packet.data(), MaxSize);
return packet;
}
route(event_, output);
}
+///////////////////////////////////////////////////////////////////////////
+// senf::ppi::module::ActiveBurstSocketSource<Reader>
+
+template <class Reader>
+prefix_ senf::ppi::module::ActiveBurstSocketSource<Reader>::ActiveBurstSocketSource(unsigned max_burst)
+ : maxBurst_(max_burst)
+{
+ registerEvent( event_, &ActiveBurstSocketSource::read );
+ route(event_, output);
+}
+
+template <class Reader>
+prefix_ senf::ppi::module::ActiveBurstSocketSource<Reader>::ActiveBurstSocketSource(Reader reader, unsigned max_burst)
+ : reader_(reader), maxBurst_(maxBurst)
+{
+ registerEvent( event_, &ActiveBurstSocketSource::read );
+ route(event_, output);
+}
+
+template <class Reader>
+prefix_ senf::ppi::module::ActiveBurstSocketSource<Reader>::ActiveBurstSocketSource(Handle handle, unsigned max_burst)
+ : handle_(handle), event_(handle_, IOEvent::Read), maxBurst_(max_burst)
+{
+ registerEvent( event_, &ActiveBurstSocketSource::read );
+ route(event_, output);
+}
+
+template <class Reader>
+prefix_ senf::ppi::module::ActiveBurstSocketSource<Reader>::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 <class Reader>
+prefix_ void senf::ppi::module::ActiveBurstSocketSource<Reader>::maxBurst(unsigned max_burst)
+{
+ maxBurst_ = max_burst;
+}
+
+template <class Reader>
+prefix_ unsigned senf::ppi::module::ActiveBurstSocketSource<Reader>::maxBurst()
+ const
+{
+ return maxBurst_;
+}
+
+template <class Reader>
+prefix_ void senf::ppi::module::ActiveBurstSocketSource<Reader>::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_
event_.set(handle_, IOEvent::Read);
}
-////////////////////////////////////////
-// private members
-
template <class Reader>
prefix_ void senf::ppi::module::ActiveSocketSource<Reader>::read()
{
output(reader_(handle_));
}
+///////////////////////////////////////////////////////////////////////////
+// senf::ppi::module::ActiveBurstSocketSource<Reader>
+
+template <class Reader>
+prefix_ Reader & senf::ppi::module::ActiveBurstSocketSource<Reader>::reader()
+{
+ return reader_;
+}
+
+template <class Reader>
+prefix_ typename senf::ppi::module::ActiveBurstSocketSource<Reader>::Handle
+senf::ppi::module::ActiveBurstSocketSource<Reader>::handle()
+{
+ return handle_;
+}
+
+template <class Reader>
+prefix_ void senf::ppi::module::ActiveBurstSocketSource<Reader>::handle(Handle handle)
+{
+ handle_ = handle;
+ event_.set(handle_, IOEvent::Read);
+}
+
///////////////////////////////cti.e///////////////////////////////////////
#undef prefix_
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 Reader=DgramReader<> >
+ class ActiveBurstSocketSource
+ : public Module
+ {
+ SENF_PPI_MODULE(ActiveBurstSocketSource);
+
+ public:
+ typedef typename Reader::Handle Handle; ///< Handle type requested by the reader
+ connector::ActiveOutput<typename Reader::PacketType> 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();
};
}}}