Skip to content
Snippets Groups Projects
Commit 24c74f49 authored by g0dil's avatar g0dil
Browse files

Howtos/NewPacket: Small fixes

PPI: Add missing unit-test for typed connectors and fix typed connectors implementation
Socket: Remove left-over log message
parent 393340e2
No related branches found
No related tags found
No related merge requests found
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
\code \code
#include <senf/Packets.hh> #include <senf/Packets.hh>
struct GREPacketParser : public senf::PacketParser struct GREPacketParser : public senf::PacketParserBase
{ {
# include SENF_PARSER() # include SENF_PARSER()
...@@ -86,10 +86,10 @@ ...@@ -86,10 +86,10 @@
}; };
\endcode \endcode
This is the standard skeleton of any parser class: We need to inherit senf::PacketParser and This is the standard skeleton of any parser class: We need to inherit senf::PacketParserBase and
start out by including either \ref SENF_PARSER() or \ref SENF_FIXED_PARSER(). Which, depends on start out by including either \ref SENF_PARSER() or \ref SENF_FIXED_PARSER(). Which, depends on
whether we define a fixed size or a dynamically sized parser. As \c GREPacketParser is dynamically whether we define a fixed size or a dynamically sized parser. As \c GREPacketParser is
sized, we include \ref SENF_PARSER(). dynamically sized, we include \ref SENF_PARSER().
After the fields are defined, we need to call the \ref SENF_PARSER_FINALIZE() macro to close of After the fields are defined, we need to call the \ref SENF_PARSER_FINALIZE() macro to close of
the parser definition. This call takes the name of the parser being defined as it's sole the parser definition. This call takes the name of the parser being defined as it's sole
...@@ -152,7 +152,7 @@ ...@@ -152,7 +152,7 @@
as an optional parser to the GRE header. as an optional parser to the GRE header.
\code \code
struct GREPacketParser_OptFields : public senf::PacketParser struct GREPacketParser_OptFields : public senf::PacketParserBase
{ {
# include SENF_FIXED_PARSER() # include SENF_FIXED_PARSER()
...@@ -313,7 +313,7 @@ ...@@ -313,7 +313,7 @@
\code \code
#include <senf/Packets.hh> #include <senf/Packets.hh>
struct GREPacketParser_OptFields : public senf::PacketParser struct GREPacketParser_OptFields : public senf::PacketParserBase
{ {
# include SENF_FIXED_PARSER() # include SENF_FIXED_PARSER()
...@@ -323,7 +323,7 @@ ...@@ -323,7 +323,7 @@
SENF_PARSER_FINALIZE(GREPacketParser_OptFields); SENF_PARSER_FINALIZE(GREPacketParser_OptFields);
}; };
struct GREPacketParser : public senf::PacketParser struct GREPacketParser : public senf::PacketParserBase
{ {
# include SENF_PARSER() # include SENF_PARSER()
...@@ -720,7 +720,7 @@ ...@@ -720,7 +720,7 @@
#include <senf/Packets.hh> #include <senf/Packets.hh>
struct GREPacketParser_OptFields : public senf::PacketParser struct GREPacketParser_OptFields : public senf::PacketParserBase
{ {
# include SENF_FIXED_PARSER() # include SENF_FIXED_PARSER()
...@@ -730,7 +730,7 @@ ...@@ -730,7 +730,7 @@
SENF_PARSER_FINALIZE(GREPacketParser_OptFields); SENF_PARSER_FINALIZE(GREPacketParser_OptFields);
}; };
struct GREPacketParser : public senf::PacketParser struct GREPacketParser : public senf::PacketParserBase
{ {
# include SENF_PARSER() # include SENF_PARSER()
......
...@@ -37,14 +37,15 @@ template <class Self, class PacketType> ...@@ -37,14 +37,15 @@ template <class Self, class PacketType>
prefix_ typename senf::ppi::connector::detail::TypedInputMixin<Self,PacketType>::Type prefix_ typename senf::ppi::connector::detail::TypedInputMixin<Self,PacketType>::Type
senf::ppi::connector::detail::TypedInputMixin<Self,PacketType>::operator()() senf::ppi::connector::detail::TypedInputMixin<Self,PacketType>::operator()()
{ {
return static_cast<Self*>(this)->InputConnector::operator()().template as<Type>(); return read();
} }
template <class Self, class PacketType> template <class Self, class PacketType>
prefix_ typename senf::ppi::connector::detail::TypedInputMixin<Self,PacketType>::Type prefix_ typename senf::ppi::connector::detail::TypedInputMixin<Self,PacketType>::Type
senf::ppi::connector::detail::TypedInputMixin<Self,PacketType>::read() senf::ppi::connector::detail::TypedInputMixin<Self,PacketType>::read()
{ {
return static_cast<Self*>(this)->InputConnector::read().template as<Type>(); Packet p (static_cast<Self*>(this)->InputConnector::read());
return p ? p.as<Type>() : Type();
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
......
...@@ -460,6 +460,8 @@ namespace connector { ...@@ -460,6 +460,8 @@ namespace connector {
public: \ public: \
using mixin::operator(); \ using mixin::operator(); \
using mixin::TypedConnector_ ## dir ; \ using mixin::TypedConnector_ ## dir ; \
private: \
friend class detail::Typed ## dir ## Mixin<type ## dir <PacketType>, PacketType>; \
}; \ }; \
template <> \ template <> \
class type ## dir <Packet> : public Generic ## type ## dir \ class type ## dir <Packet> : public Generic ## type ## dir \
...@@ -485,7 +487,7 @@ namespace connector { ...@@ -485,7 +487,7 @@ namespace connector {
\see GenericActiveInput \n \see GenericActiveInput \n
senf::ppi::connector senf::ppi::connector
*/ */
template <class PacketType> template <class PacketType=Packet>
class ActiveInput : public GenericActiveInput class ActiveInput : public GenericActiveInput
{ {
public: public:
...@@ -526,12 +528,12 @@ namespace connector { ...@@ -526,12 +528,12 @@ namespace connector {
\see GenericActiveOutput \n \see GenericActiveOutput \n
senf::ppi::connector senf::ppi::connector
*/ */
template <class PacketType> template <class PacketType=Packet>
class ActiveOutput : public GenericActiveOutput class ActiveOutput : public GenericActiveOutput
{ {
public: public:
PacketType operator()(); operator()(PacketType packet); ///< Send out a packet
PacketType write(); write(PacketType packet); ///< Alias for operator()
}; };
/** \brief Connector passively providing packets /** \brief Connector passively providing packets
...@@ -543,12 +545,12 @@ namespace connector { ...@@ -543,12 +545,12 @@ namespace connector {
\see GenericPassiveOutput \n \see GenericPassiveOutput \n
senf::ppi::connector senf::ppi::connector
*/ */
template <class PacketType> template <class PacketType=Packet>
class PassiveOutput : public GenericPassiveOutput class PassiveOutput : public GenericPassiveOutput
{ {
public: public:
PacketType operator()(); operator()(PacketType packet); ///< Send out a packet
PacketType write(); write(PacketType packet); ///< Alias for operator()
}; };
#endif #endif
......
...@@ -284,6 +284,71 @@ BOOST_AUTO_UNIT_TEST(activeOutput) ...@@ -284,6 +284,71 @@ BOOST_AUTO_UNIT_TEST(activeOutput)
// connect() is tested indirectly via ppi::connect // connect() is tested indirectly via ppi::connect
} }
namespace {
class TypedInputTest
: public ppi::module::Module
{
SENF_PPI_MODULE(TypedInputTest);
public:
ppi::connector::PassiveInput<senf::DataPacket> input;
TypedInputTest() {
noroute(input);
input.onRequest(&TypedInputTest::request);
}
void request() {
(void) input();
(void) input.read();
}
};
class TypedOutputTest
: public ppi::module::Module
{
SENF_PPI_MODULE(TypedOutputTest);
public:
ppi::connector::PassiveOutput<senf::DataPacket> output;
TypedOutputTest() {
noroute(output);
output.onRequest(&TypedOutputTest::request);
}
void request() {
senf::DataPacket pkg (senf::DataPacket::create());
output(pkg);
output.write(pkg);
}
};
}
BOOST_AUTO_UNIT_TEST(typedInput)
{
debug::ActiveSource source;
TypedInputTest target;
ppi::connect(source,target);
ppi::init();
senf::Packet p (senf::DataPacket::create());
source.submit(p);
}
BOOST_AUTO_UNIT_TEST(tyepdOutput)
{
TypedOutputTest source;
debug::ActiveSink target;
ppi::connect(source,target);
ppi::init();
(void) target.request();
}
///////////////////////////////cc.e//////////////////////////////////////// ///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_ #undef prefix_
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include "SocketProtocol.hh" #include "SocketProtocol.hh"
#include "SocketPolicy.test.hh" #include "SocketPolicy.test.hh"
#include "ProtocolClientSocketHandle.hh" #include "ProtocolClientSocketHandle.hh"
#include "../Utils/Logger/SenfLog.hh"
//#include "SocketProtocol.test.mpp" //#include "SocketProtocol.test.mpp"
///////////////////////////////hh.p//////////////////////////////////////// ///////////////////////////////hh.p////////////////////////////////////////
...@@ -50,7 +49,6 @@ namespace test { ...@@ -50,7 +49,6 @@ namespace test {
{ return false; } { return false; }
virtual void close() const { virtual void close() const {
SENF_LOG(( "Closing socket ..." ));
closeCount(1); closeCount(1);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment