Howtos/NewPacket: Small fixes
g0dil [Fri, 8 Feb 2008 09:38:57 +0000 (09:38 +0000)]
PPI: Add missing unit-test for typed connectors and fix typed connectors implementation
Socket: Remove left-over log message

git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@672 270642c3-0616-0410-b53a-bc976706d245

HowTos/NewPacket/Mainpage.dox
PPI/Connectors.cti
PPI/Connectors.hh
PPI/Connectors.test.cc
Socket/SocketProtocol.test.hh

index c6f5cce..8769831 100644 (file)
@@ -76,7 +76,7 @@
     \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()
 
index c00d0c7..b8f5bf3 100644 (file)
@@ -37,14 +37,15 @@ template <class Self, class PacketType>
 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();
 }
 
 ///////////////////////////////////////////////////////////////////////////
index d96a0d7..68a0ea4 100644 (file)
@@ -460,6 +460,8 @@ namespace connector {
         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                                \
@@ -485,7 +487,7 @@ namespace connector {
         \see GenericActiveInput \n
             senf::ppi::connector
      */
-    template <class PacketType>
+    template <class PacketType=Packet>
     class ActiveInput : public GenericActiveInput
     {
     public:
@@ -526,12 +528,12 @@ namespace connector {
         \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
@@ -543,12 +545,12 @@ namespace connector {
         \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
index 8202b3b..639f58b 100644 (file)
@@ -284,6 +284,71 @@ BOOST_AUTO_UNIT_TEST(activeOutput)
     // 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_
index c5073f3..68a6466 100644 (file)
@@ -27,7 +27,6 @@
 #include "SocketProtocol.hh"
 #include "SocketPolicy.test.hh"
 #include "ProtocolClientSocketHandle.hh"
-#include "../Utils/Logger/SenfLog.hh"
 
 //#include "SocketProtocol.test.mpp"
 ///////////////////////////////hh.p////////////////////////////////////////
@@ -50,7 +49,6 @@ namespace test {
             { return false; }
 
         virtual void close() const {
-            SENF_LOG(( "Closing socket ..." ));
             closeCount(1);
         }