BOOST_AUTO_UNIT_TEST(activeFeeder)
{
- debug::PassivePacketSource source;
- debug::PassivePacketSink sink;
+ debug::PassiveSource source;
+ debug::PassiveSink sink;
module::ActiveFeeder feeder;
ppi::connect(source,feeder);
// It doesn't matter, which type of connectors we use here since they are all based on
// Connector.
- debug::ActivePacketSource source;
- debug::PassivePacketSink target;
+ debug::ActiveSource source;
+ debug::PassiveSink target;
ppi::connect(source.output,target.input);
ppi::init();
BOOST_AUTO_UNIT_TEST(passiveConnector)
{
- debug::ActivePacketSource source;
- debug::PassivePacketSink target;
+ debug::ActiveSource source;
+ debug::PassiveSink target;
ppi::connect(source.output,target.input);
ppi::init();
- // onRequest is implicitly tested within the PassivePacketSink implementation which is tested
+ // onRequest is implicitly tested within the PassiveSink implementation which is tested
// in DebugModules.test.cc
target.input.throttle();
BOOST_AUTO_UNIT_TEST(activeConnector)
{
- debug::ActivePacketSource source;
- debug::PassivePacketSink target;
+ debug::ActiveSource source;
+ debug::PassiveSink target;
ppi::connect(source.output,target.input);
ppi::init();
BOOST_AUTO_UNIT_TEST(inputConnector)
{
- debug::ActivePacketSource source;
- debug::PassivePacketSink target;
+ debug::ActiveSource source;
+ debug::PassiveSink target;
ppi::connect(source.output,target.input);
ppi::init();
- // operator() is implicitly tested within the Active/PassivePacketSink implementation which is
+ // operator() is implicitly tested within the Active/PassiveSink implementation which is
// tested in DebugModules.test.cc
- // peek() is implicitly tested within the Active/PassivePacketSink implementation
+ // peek() is implicitly tested within the Active/PassiveSink implementation
BOOST_CHECK_EQUAL ( & target.input.peer(), & source.output );
BOOST_AUTO_UNIT_TEST(outputConnector)
{
- debug::ActivePacketSource source;
- debug::PassivePacketSink target;
+ debug::ActiveSource source;
+ debug::PassiveSink target;
ppi::connect(source.output,target.input);
ppi::init();
- // operator() is implicitly tested within the Active/PassivePacketSource implementation which is
+ // operator() is implicitly tested within the Active/PassiveSource implementation which is
// tested in DebugModules.test.cc
BOOST_CHECK_EQUAL( & source.output.peer(), & target.input );
BOOST_AUTO_UNIT_TEST(passiveInput)
{
- debug::ActivePacketSource source;
+ debug::ActiveSource source;
PassiveInputTest target;
ppi::connect(source,target);
BOOST_AUTO_UNIT_TEST(passiveOutput)
{
- debug::PassivePacketSource source;
- debug::ActivePacketSink target;
+ debug::PassiveSource source;
+ debug::ActiveSink target;
ppi::connect(source,target);
ppi::init();
BOOST_AUTO_UNIT_TEST(activeInput)
{
- debug::PassivePacketSource source;
- debug::ActivePacketSink target;
+ debug::PassiveSource source;
+ debug::ActiveSink target;
ppi::connect(source,target);
ppi::init();
BOOST_AUTO_UNIT_TEST(activeOutput)
{
- debug::ActivePacketSource source;
- debug::PassivePacketSink target;
+ debug::ActiveSource source;
+ debug::PassiveSink target;
ppi::connect(source,target);
ppi::init();
\brief DebugModules inline non-template implementation */
// Custom includes
+#include "Setup.hh"
#define prefix_ inline
///////////////////////////////cci.p///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
-// senf::ppi::module::debug::ActivePacketSource
+// senf::ppi::module::debug::ActiveSource
-prefix_ senf::ppi::module::debug::ActivePacketSource::ActivePacketSource()
+prefix_ senf::ppi::module::debug::ActiveSource::ActiveSource()
{
noroute(output);
}
-prefix_ void senf::ppi::module::debug::ActivePacketSource::submit(Packet packet)
+prefix_ void senf::ppi::module::debug::ActiveSource::submit(Packet packet)
{
output(packet);
}
-prefix_ bool senf::ppi::module::debug::ActivePacketSource::boolean_test()
+prefix_ bool senf::ppi::module::debug::ActiveSource::boolean_test()
const
{
return output;
}
///////////////////////////////////////////////////////////////////////////
-// senf::ppi::module::debug::PassivePacketSource
+// senf::ppi::module::debug::PassiveSource
-prefix_ senf::ppi::module::debug::PassivePacketSource::PassivePacketSource()
+prefix_ senf::ppi::module::debug::PassiveSource::PassiveSource()
{
noroute(output);
- output.onRequest(&PassivePacketSource::request);
+ output.onRequest(&PassiveSource::request);
}
-prefix_ void senf::ppi::module::debug::PassivePacketSource::submit(Packet packet)
+prefix_ void senf::ppi::module::debug::PassiveSource::submit(Packet packet)
{
packets_.push_back(packet);
output.unthrottle();
}
-prefix_ bool senf::ppi::module::debug::PassivePacketSource::empty()
+prefix_ bool senf::ppi::module::debug::PassiveSource::empty()
{
return packets_.empty();
}
-prefix_ senf::ppi::module::debug::PassivePacketSource::size_type
-senf::ppi::module::debug::PassivePacketSource::size()
+prefix_ senf::ppi::module::debug::PassiveSource::size_type
+senf::ppi::module::debug::PassiveSource::size()
{
return packets_.size();
}
////////////////////////////////////////
// private members
-prefix_ void senf::ppi::module::debug::PassivePacketSource::request()
+prefix_ void senf::ppi::module::debug::PassiveSource::request()
{
BOOST_ASSERT( ! packets_.empty() );
output(packets_.front());
output.throttle();
}
-prefix_ void senf::ppi::module::debug::PassivePacketSource::init()
+prefix_ void senf::ppi::module::debug::PassiveSource::init()
{
if (empty())
output.throttle();
}
///////////////////////////////////////////////////////////////////////////
-// senf::ppi::module::debug::ActivePacketSink
+// senf::ppi::module::debug::ActiveSink
-prefix_ senf::ppi::module::debug::ActivePacketSink::ActivePacketSink()
+prefix_ senf::ppi::module::debug::ActiveSink::ActiveSink()
{
noroute(input);
}
-prefix_ senf::Packet senf::ppi::module::debug::ActivePacketSink::request()
+prefix_ senf::Packet senf::ppi::module::debug::ActiveSink::request()
{
return input();
}
-prefix_ bool senf::ppi::module::debug::ActivePacketSink::boolean_test()
+prefix_ bool senf::ppi::module::debug::ActiveSink::boolean_test()
const
{
return input;
}
///////////////////////////////////////////////////////////////////////////
-// senf::ppi::module::debug::PassivePacketSink
+// senf::ppi::module::debug::PassiveSink
-prefix_ senf::ppi::module::debug::PassivePacketSink::PassivePacketSink()
+prefix_ senf::ppi::module::debug::PassiveSink::PassiveSink()
{
noroute(input);
- input.onRequest(&PassivePacketSink::request);
+ input.onRequest(&PassiveSink::request);
}
-prefix_ bool senf::ppi::module::debug::PassivePacketSink::empty()
+prefix_ bool senf::ppi::module::debug::PassiveSink::empty()
{
return packets_.empty();
}
-prefix_ senf::ppi::module::debug::PassivePacketSink::size_type
-senf::ppi::module::debug::PassivePacketSink::size()
+prefix_ senf::ppi::module::debug::PassiveSink::size_type
+senf::ppi::module::debug::PassiveSink::size()
{
return packets_.size();
}
-prefix_ senf::ppi::module::debug::PassivePacketSink::iterator
-senf::ppi::module::debug::PassivePacketSink::begin()
+prefix_ senf::ppi::module::debug::PassiveSink::iterator
+senf::ppi::module::debug::PassiveSink::begin()
{
return packets_.begin();
}
-prefix_ senf::ppi::module::debug::PassivePacketSink::iterator
-senf::ppi::module::debug::PassivePacketSink::end()
+prefix_ senf::ppi::module::debug::PassiveSink::iterator
+senf::ppi::module::debug::PassiveSink::end()
{
return packets_.end();
}
-prefix_ senf::Packet senf::ppi::module::debug::PassivePacketSink::front()
+prefix_ senf::Packet senf::ppi::module::debug::PassiveSink::front()
{
if (empty())
return Packet();
return packets_.front();
}
-prefix_ senf::Packet senf::ppi::module::debug::PassivePacketSink::pop_front()
+prefix_ senf::Packet senf::ppi::module::debug::PassiveSink::pop_front()
{
Packet p (front());
if (p)
return p;
}
-prefix_ void senf::ppi::module::debug::PassivePacketSink::clear()
+prefix_ void senf::ppi::module::debug::PassiveSink::clear()
{
packets_.erase(packets_.begin(), packets_.end());
}
////////////////////////////////////////
// private members
-prefix_ void senf::ppi::module::debug::PassivePacketSink::request()
+prefix_ void senf::ppi::module::debug::PassiveSink::request()
{
packets_.push_back(input());
}
+///////////////////////////////////////////////////////////////////////////
+// senf::ppi::module::debug::ActiveFeederSource
+
+prefix_ senf::ppi::module::debug::ActiveFeederSource::ActiveFeederSource()
+ : output(feeder.output)
+{
+ ppi::connect(source,feeder);
+}
+
+prefix_ void senf::ppi::module::debug::ActiveFeederSource::submit(Packet packet)
+{
+ source.submit(packet);
+}
+
+prefix_ bool senf::ppi::module::debug::ActiveFeederSource::empty()
+{
+ return source.empty();
+}
+
+prefix_ senf::ppi::module::debug::ActiveFeederSource::size_type
+senf::ppi::module::debug::ActiveFeederSource::size()
+{
+ return source.size();
+}
+
+///////////////////////////////////////////////////////////////////////////
+// senf::ppi::module::debug::ActiveFeederSink
+
+prefix_ senf::ppi::module::debug::ActiveFeederSink::ActiveFeederSink()
+ : input(feeder.input)
+{
+ ppi::connect(feeder, sink);
+}
+
+prefix_ bool senf::ppi::module::debug::ActiveFeederSink::empty()
+{
+ return sink.empty();
+}
+
+prefix_ senf::ppi::module::debug::ActiveFeederSink::size_type
+senf::ppi::module::debug::ActiveFeederSink::size()
+{
+ return sink.size();
+}
+
+prefix_ senf::ppi::module::debug::ActiveFeederSink::iterator
+senf::ppi::module::debug::ActiveFeederSink::begin()
+{
+ return sink.begin();
+}
+
+prefix_ senf::ppi::module::debug::ActiveFeederSink::iterator
+senf::ppi::module::debug::ActiveFeederSink::end()
+{
+ return sink.end();
+}
+
+prefix_ senf::Packet senf::ppi::module::debug::ActiveFeederSink::front()
+{
+ return sink.front();
+}
+
+prefix_ senf::Packet senf::ppi::module::debug::ActiveFeederSink::pop_front()
+{
+ return sink.pop_front();
+}
+
+prefix_ void senf::ppi::module::debug::ActiveFeederSink::clear()
+{
+ sink.clear();
+}
+
///////////////////////////////cci.e///////////////////////////////////////
#undef prefix_
#include "Utils/SafeBool.hh"
#include "Packets/Packets.hh"
#include "Module.hh"
+#include "ActiveFeeder.hh"
//#include "DebugModules.mpp"
///////////////////////////////hh.p////////////////////////////////////////
/** \brief
*/
- class ActivePacketSource
+ class ActiveSource
: public Module,
- public SafeBool<ActivePacketSource>
+ public SafeBool<ActiveSource>
{
- SENF_PPI_MODULE(ActivePacketSource);
+ SENF_PPI_MODULE(ActiveSource);
public:
connector::ActiveOutput output;
- ActivePacketSource();
+ ActiveSource();
void submit(Packet packet);
bool boolean_test() const;
};
- class PassivePacketSource
+ class PassiveSource
: public Module
{
- SENF_PPI_MODULE(PassivePacketSource);
+ SENF_PPI_MODULE(PassiveSource);
typedef std::deque<Packet> Queue;
public:
typedef Queue::size_type size_type;
- PassivePacketSource();
+ PassiveSource();
connector::PassiveOutput output;
Queue packets_;
};
- class ActivePacketSink
+ class ActiveSink
: public Module,
- public SafeBool<ActivePacketSink>
+ public SafeBool<ActiveSink>
{
- SENF_PPI_MODULE(ActivePacketSink);
+ SENF_PPI_MODULE(ActiveSink);
public:
connector::ActiveInput input;
- ActivePacketSink();
+ ActiveSink();
Packet request();
bool boolean_test() const;
};
- class PassivePacketSink
+ class PassiveSink
: public Module
{
- SENF_PPI_MODULE(PassivePacketSink);
+ SENF_PPI_MODULE(PassiveSink);
typedef std::deque<Packet> Queue;
connector::PassiveInput input;
- PassivePacketSink();
+ PassiveSink();
bool empty();
size_type size();
Queue packets_;
};
+ class ActiveFeederSource
+ {
+ private:
+ PassiveSource source;
+ ActiveFeeder feeder;
+
+ public:
+ typedef PassiveSource::size_type size_type;
+
+ connector::ActiveOutput & output;
+
+ ActiveFeederSource();
+
+ void submit(Packet packet);
+ bool empty();
+ size_type size();
+ };
+
+ class ActiveFeederSink
+ {
+ private:
+ PassiveSink sink;
+ ActiveFeeder feeder;
+
+ public:
+ typedef PassiveSink::size_type size_type;
+ typedef PassiveSink::iterator iterator;
+
+ connector::ActiveInput & input;
+
+ ActiveFeederSink();
+
+ bool empty();
+ size_type size();
+ iterator begin();
+ iterator end();
+
+ Packet front();
+ Packet pop_front();
+
+ void clear();
+ };
+
}}}}
///////////////////////////////hh.e////////////////////////////////////////
BOOST_AUTO_UNIT_TEST(debugModules)
{
{
- debug::ActivePacketSource source;
- debug::PassivePacketSink sink;
+ debug::ActiveSource source;
+ debug::PassiveSink sink;
ppi::connect(source, sink);
ppi::init();
BOOST_CHECK_EQUAL( sink.size(), 1u );
BOOST_CHECK( ! sink.empty() );
BOOST_CHECK_EQUAL(
- debug::PassivePacketSink::size_type(std::distance(sink.begin(),sink.end())),
+ debug::PassiveSink::size_type(std::distance(sink.begin(),sink.end())),
sink.size() );
BOOST_CHECK( *sink.begin() == p );
BOOST_CHECK( sink.front() == p );
}
{
- debug::PassivePacketSource source;
- debug::ActivePacketSink sink;
+ debug::PassiveSource source;
+ debug::ActiveSink sink;
ppi::connect(source, sink);
ppi::init();
}
}
+BOOST_AUTO_UNIT_TEST(activeFeederSource)
+{
+ debug::ActiveFeederSource source;
+ debug::PassiveSink sink;
+
+ ppi::connect(source,sink);
+
+ source.submit(senf::DataPacket::create());
+
+ ppi::run();
+
+ BOOST_CHECK( source.empty() );
+ BOOST_CHECK_EQUAL( source.size(), 0u );
+ BOOST_CHECK_EQUAL( sink.size(), 1u );
+}
+
+BOOST_AUTO_UNIT_TEST(activeFeederSink)
+{
+ debug::PassiveSource source;
+ debug::ActiveFeederSink sink;
+
+ ppi::connect(source,sink);
+
+ source.submit(senf::DataPacket::create());
+
+ ppi::run();
+
+ BOOST_CHECK( ! sink.empty() );
+ BOOST_CHECK_EQUAL( sink.size(), 1u );
+ BOOST_CHECK_EQUAL( debug::ActiveFeederSink::size_type(std::distance(sink.begin(), sink.end())),
+ sink.size() );
+ BOOST_CHECK( sink.front().data().empty() );
+ BOOST_CHECK( sink.pop_front().data().empty() );
+ BOOST_CHECK( sink.empty() );
+ BOOST_CHECK( source.empty() );
+}
+
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
BOOST_AUTO_UNIT_TEST(passiveJoin)
{
- debug::ActivePacketSource source1;
- debug::ActivePacketSource source2;
+ debug::ActiveSource source1;
+ debug::ActiveSource source2;
module::PassiveJoin join;
- debug::PassivePacketSink sink;
+ debug::PassiveSink sink;
ppi::connect(source1, join);
ppi::connect(source2, join);
BOOST_AUTO_UNIT_TEST(priorityJoin)
{
- debug::PassivePacketSource source1;
- debug::PassivePacketSource source2;
+ debug::PassiveSource source1;
+ debug::PassiveSource source2;
module::PriorityJoin join;
- debug::ActivePacketSink sink;
+ debug::ActiveSink sink;
ppi::connect(source1, join);
ppi::connect(source2, join);
// route and registerEvent are tested in Route.test.cc
TestModule tester;
- debug::PassivePacketSink sink;
+ debug::PassiveSink sink;
ppi::connect(tester, sink);
ppi::init();
BOOST_AUTO_UNIT_TEST(passiveQueue)
{
- debug::ActivePacketSource source;
+ debug::ActiveSource source;
module::PassiveQueue queue;
- debug::ActivePacketSink sink;
+ debug::ActiveSink sink;
ppi::connect(source,queue);
ppi::connect(queue,sink);
BOOST_AUTO_UNIT_TEST(thresholdQueueing)
{
- debug::ActivePacketSource source;
+ debug::ActiveSource source;
QueueTester tester;
- debug::PassivePacketSink sink;
+ debug::PassiveSink sink;
ppi::connect(source, tester);
ppi::connect(tester, sink);
BOOST_AUTO_UNIT_TEST(route)
{
- debug::PassivePacketSource passiveSource;
- debug::ActivePacketSource activeSource;
- debug::PassivePacketSink passiveSink;
- debug::ActivePacketSink activeSink;
+ debug::PassiveSource passiveSource;
+ debug::ActiveSource activeSource;
+ debug::PassiveSink passiveSink;
+ debug::ActiveSink activeSink;
RouteTester tester;
ppi::connect(passiveSource, tester.activeIn);
#ifndef DOXYGEN
-template <class M, class C>
-prefix_ void
-senf::ppi::connect(M & source, C & target,
- typename boost::enable_if< boost::is_base_of<module::Module, M> >::type *,
- typename boost::enable_if< boost::is_base_of<connector::Connector, C> >::type *)
+template <class T, class C>
+prefix_ void senf::ppi::
+connect(T & source, C & target,
+ typename boost::disable_if< boost::is_base_of<connector::Connector, T> >::type *,
+ typename boost::enable_if< boost::is_base_of<connector::Connector, C> >::type *)
{
connect(source.output, target);
}
-template <class C, class M>
-prefix_ void
-senf::ppi::connect(C & source, M & target,
- typename boost::enable_if< boost::is_base_of<connector::Connector, C> >::type *,
- typename boost::enable_if< boost::is_base_of<module::Module, M> >::type *)
+template <class C, class T>
+prefix_ void senf::ppi::
+connect(C & source, T & target,
+ typename boost::enable_if< boost::is_base_of<connector::Connector, C> >::type *,
+ typename boost::disable_if< boost::is_base_of<connector::Connector,T> >::type *)
{
connect(source, target.input);
}
-template <class M1, class M2>
-prefix_ void
-senf::ppi::connect(M1 & source, M2 & target,
- typename boost::enable_if< boost::is_base_of<module::Module, M1> >::type *,
- typename boost::enable_if< boost::is_base_of<module::Module, M2> >::type *)
+template <class T1, class T2>
+prefix_ void senf::ppi::
+connect(T1 & source, T2 & target,
+ typename boost::disable_if< boost::is_base_of<connector::Connector, T1> >::type *,
+ typename boost::disable_if< boost::is_base_of<connector::Connector, T2> >::type *)
{
connect(source.output, target.input);
}
#define HH_Setup_ 1
// Custom includes
+#include <boost/type_traits.hpp>
+#include <boost/utility/enable_if.hpp>
#include "predecl.hh"
//#include "Setup.mpp"
void connect(connector::ActiveOutput & source, connector::PassiveInput & target);
void connect(connector::PassiveOutput & source, connector::ActiveInput & target);
- template <class M, class C>
- void connect(M & source, C & target,
- typename boost::enable_if< boost::is_base_of<module::Module, M> >::type * = 0,
+ template <class T, class C>
+ void connect(T & source, C & target,
+ typename boost::disable_if< boost::is_base_of<connector::Connector, T> >::type * = 0,
typename boost::enable_if< boost::is_base_of<connector::Connector, C> >::type * = 0);
- template <class C, class M>
- void connect(C & source, M & target,
+ template <class C, class T>
+ void connect(C & source, T & target,
typename boost::enable_if< boost::is_base_of<connector::Connector, C> >::type * = 0,
- typename boost::enable_if< boost::is_base_of<module::Module, M> >::type * = 0);
+ typename boost::disable_if< boost::is_base_of<connector::Connector,T> >::type * = 0);
- template <class M1, class M2>
- void connect(M1 & source, M2 & target,
- typename boost::enable_if< boost::is_base_of<module::Module, M1> >::type * = 0,
- typename boost::enable_if< boost::is_base_of<module::Module, M2> >::type * = 0);
+ template <class T1, class T2>
+ void connect(T1 & source, T2 & target,
+ typename boost::disable_if< boost::is_base_of<connector::Connector, T1> >::type * = 0,
+ typename boost::disable_if< boost::is_base_of<connector::Connector, T2> >::type * = 0);
#else
inputSocket.bind(senf::INet4SocketAddress("localhost:44344"));
inputSocket.blocking(false);
module::ActiveSocketReader<> udpReader(inputSocket);
- debug::PassivePacketSink sink;
+ debug::PassiveSink sink;
ppi::connect(udpReader, sink);
std::string data ("TEST");
senf::ConnectedUDPv4ClientSocketHandle outputSocket (
senf::INet4SocketAddress("localhost:44344"));
module::PassiveSocketWriter<> udpWriter(outputSocket);
- debug::ActivePacketSource source;
+ debug::ActiveSource source;
ppi::connect(source, udpWriter);
std::string data ("TEST");
senf::ConnectedUDPv4ClientSocketHandle outputSocket (
senf::INet4SocketAddress("localhost:44344"));
module::ActiveSocketWriter<> udpWriter(outputSocket);
- debug::PassivePacketSource source;
+ debug::PassiveSource source;
ppi::connect(source, udpWriter);
std::string data ("TEST");
#define HH_predecl_ 1
// Custom includes
-#include <boost/type_traits.hpp>
//#include "predecl.mpp"
///////////////////////////////hh.p////////////////////////////////////////