\code
#include <senf/Packets.hh>
- struct GREPacketParser : public senf::PacketParser
+ struct GREPacketParser : public senf::PacketParserBase
{
# include SENF_PARSER()
};
\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
- whether we define a fixed size or a dynamically sized parser. As \c GREPacketParser is dynamically
- sized, we include \ref SENF_PARSER().
+ whether we define a fixed size or a dynamically sized parser. As \c GREPacketParser is
+ 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
the parser definition. This call takes the name of the parser being defined as it's sole
as an optional parser to the GRE header.
\code
- struct GREPacketParser_OptFields : public senf::PacketParser
+ struct GREPacketParser_OptFields : public senf::PacketParserBase
{
# include SENF_FIXED_PARSER()
\code
#include <senf/Packets.hh>
- struct GREPacketParser_OptFields : public senf::PacketParser
+ struct GREPacketParser_OptFields : public senf::PacketParserBase
{
# include SENF_FIXED_PARSER()
SENF_PARSER_FINALIZE(GREPacketParser_OptFields);
};
- struct GREPacketParser : public senf::PacketParser
+ struct GREPacketParser : public senf::PacketParserBase
{
# include SENF_PARSER()
#include <senf/Packets.hh>
- struct GREPacketParser_OptFields : public senf::PacketParser
+ struct GREPacketParser_OptFields : public senf::PacketParserBase
{
# include SENF_FIXED_PARSER()
SENF_PARSER_FINALIZE(GREPacketParser_OptFields);
};
- struct GREPacketParser : public senf::PacketParser
+ struct GREPacketParser : public senf::PacketParserBase
{
# include SENF_PARSER()
prefix_ typename senf::ppi::connector::detail::TypedInputMixin<Self,PacketType>::Type
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>
prefix_ typename senf::ppi::connector::detail::TypedInputMixin<Self,PacketType>::Type
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();
}
///////////////////////////////////////////////////////////////////////////
public: \
using mixin::operator(); \
using mixin::TypedConnector_ ## dir ; \
+ private: \
+ friend class detail::Typed ## dir ## Mixin<type ## dir <PacketType>, PacketType>; \
}; \
template <> \
class type ## dir <Packet> : public Generic ## type ## dir \
\see GenericActiveInput \n
senf::ppi::connector
*/
- template <class PacketType>
+ template <class PacketType=Packet>
class ActiveInput : public GenericActiveInput
{
public:
\see GenericActiveOutput \n
senf::ppi::connector
*/
- template <class PacketType>
+ template <class PacketType=Packet>
class ActiveOutput : public GenericActiveOutput
{
public:
- PacketType operator()();
- PacketType write();
+ operator()(PacketType packet); ///< Send out a packet
+ write(PacketType packet); ///< Alias for operator()
};
/** \brief Connector passively providing packets
\see GenericPassiveOutput \n
senf::ppi::connector
*/
- template <class PacketType>
+ template <class PacketType=Packet>
class PassiveOutput : public GenericPassiveOutput
{
public:
- PacketType operator()();
- PacketType write();
+ operator()(PacketType packet); ///< Send out a packet
+ write(PacketType packet); ///< Alias for operator()
};
#endif
// 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////////////////////////////////////////
#undef prefix_
#include "SocketProtocol.hh"
#include "SocketPolicy.test.hh"
#include "ProtocolClientSocketHandle.hh"
-#include "../Utils/Logger/SenfLog.hh"
//#include "SocketProtocol.test.mpp"
///////////////////////////////hh.p////////////////////////////////////////
{ return false; }
virtual void close() const {
- SENF_LOG(( "Closing socket ..." ));
closeCount(1);
}