Packets: Add StringParser ostream operation
[senf.git] / PPI / SocketSink.hh
index 83a1d5f..ee944dd 100644 (file)
@@ -56,6 +56,7 @@ namespace ppi {
                                     senf::DatagramFramingPolicy,
                                     senf::ConnectedCommunicationPolicy>::policy > Handle;
                                         ///< Handle type supported by this writer
+        typedef Packet PacketType;
 
         void operator()(Handle handle, Packet const & packet);
                                         ///< Write \a packet to \a handle
@@ -65,6 +66,37 @@ namespace ppi {
                                              \param[in] packet Packet to write */
     };
 
+    /** \brief Writer sending data with ClientSocketHandle::writeto()
+
+        This writer will send out data using ClientSocketHandle::writeto(). The target address can
+        be specified in the writer constructor and can be adjusted at any time.
+
+        If no target address is set, incoming data will be <em>silently dropped</em>.
+     */
+    template <class HandleType>
+    class TargetDgramWriter
+    {
+    public:
+        typedef HandleType Handle;
+        typedef Packet PacketType;
+
+        TargetDgramWriter();            ///< Create TargetDgramWriter with unset target address
+        TargetDgramWriter(typename Handle::Address const & target);
+                                        ///< Create TargetDgramWriter sending to \a target
+
+        typename Handle::Address target() const; ///< Get current target address
+        void target(typename Handle::Address const & target); ///< Set target address
+
+        void operator()(Handle handle, Packet const & packet); ///< Write \a packet to \a handle
+                                        /**< Write the complete \a packet as a datagram to \a
+                                             handle.
+                                             \param[in] handle Handle to write data to
+                                             \param[in] packet Packet to write */
+
+    private:
+        typename Handle::Address target_;
+    };
+
     class IPv4SourceForcingDgramWriter : ConnectedDgramWriter
     {
     public:
@@ -74,6 +106,7 @@ namespace ppi {
             senf::MakeSocketPolicy< senf::WriteablePolicy,
                                     senf::DatagramFramingPolicy>::policy > Handle;
                                         ///< Handle type supported by this writer
+        typedef Packet PacketType;
 
         void source(senf::INet4Address & source);
         senf::INet4Address source();
@@ -102,6 +135,7 @@ namespace ppi {
             senf::MakeSocketPolicy< senf::WriteablePolicy,
                                     senf::DatagramFramingPolicy>::policy > Handle;
                                         ///< Handle type supported by this writer
+        typedef Packet PacketType;
 
         void source(senf::INet6Address & source);
         senf::INet6Address source();
@@ -145,6 +179,7 @@ namespace module {
           {
           public:
               typedef unspecified Handle;                          // type of handle requested
+              typedef unspecified_type PacketType                  // type of packet read
 
               SomeWriter();                                        // EITHER default constructible OR
               SomeWriter(SomeWriter const & other);                // copy constructible
@@ -164,7 +199,7 @@ namespace module {
     public:
         typedef typename Writer::Handle Handle; ///< Handle type requested by writer
 
-        connector::ActiveInput<> input; ///< Input connector from which data is received
+        connector::ActiveInput<typename Writer::PacketType> input; ///< Input connector from which data is received
 
         ActiveSocketSink();             ///< Create non-connected writer
                                         /**< The writer will be disabled until a socket is set
@@ -220,6 +255,7 @@ namespace module {
           {
           public:
               typedef unspecified Handle;                          // type of handle requested
+              typedef unspecified_type PacketType                  // type of packet read
 
               SomeWriter();                                          // EITHER default constructible
               SomeWriter(SomeWriter const & other);                    // OR copy constructible
@@ -239,7 +275,7 @@ namespace module {
     public:
         typedef typename Writer::Handle Handle; ///< Handle type requested by writer
 
-        connector::PassiveInput<> input; ///< Input connector from which data is received
+        connector::PassiveInput<typename Writer::PacketType> input; ///< Input connector from which data is received
 
         PassiveSocketSink();            ///< Create non-connected writer
                                         /**< The writer will be disabled until a socket is set