PPI: added ActiveBurstSocketSource for testing
tho [Wed, 28 Jul 2010 13:19:32 +0000 (13:19 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1652 270642c3-0616-0410-b53a-bc976706d245

senf/PPI/SocketSource.ct
senf/PPI/SocketSource.cti
senf/PPI/SocketSource.hh

index 58131fa..6eb9780 100644 (file)
@@ -37,7 +37,7 @@ template <class Packet, unsigned MaxSize>
 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;
 }
 
@@ -76,6 +76,68 @@ prefix_ senf::ppi::module::ActiveSocketSource<Reader>::ActiveSocketSource(Handle
     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_
 
index ffffdd5..08f37bf 100644 (file)
@@ -53,15 +53,35 @@ prefix_ void senf::ppi::module::ActiveSocketSource<Reader>::handle(Handle handle
     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_
 
index 4ae8e8e..c41e314 100644 (file)
@@ -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 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();
     };
 
 }}}