PPI: Add missing TargetDgramWriter doku
[senf.git] / Socket / ClientSocketHandle.hh
index 2b6f425..92635f9 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 //
 // Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-//     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+//     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
     \brief ClientSocketHandle public header
  */
 
-#ifndef HH_ClientSocketHandle_
-#define HH_ClientSocketHandle_ 1
+#ifndef HH_SENF_Socket_ClientSocketHandle_
+#define HH_SENF_Socket_ClientSocketHandle_ 1
 
 // Custom includes
 #include <boost/call_traits.hpp>
 #include <boost/range.hpp>
+#include <boost/utility.hpp>
+#include <boost/type_traits.hpp>
 #include "SocketHandle.hh"
 
 //#include "ClientSocketHandle.mpp"
@@ -40,26 +42,27 @@ namespace senf {
     /// \addtogroup handle_group
     /// @{
 
-    template <class Policy> class ServerSocketHandle;
+    template <class SPolicy> class ServerSocketHandle;
 
     /** \brief Generic SocketHandle with client interface
 
         This class provides the client side policy interface of the socket
         abstraction. ClientSocketHandle defines the complete policy interface. It does not implement
-        any functionality itself however. All calls are forward to the following policy classes:
+        any functionality itself however. The following table shows, to which policy members each
+        group of ClientSocketHandle members is forwardd. The last collumn shows, on which other
+        policies this member-group depends <em>in the default policy classes</em>. If you define
+        your own policy classes, the dependencies are up to you.
 
         <table class="senf">
-        <tr><th>ClientSocketHandle member</th> <th>Policy member</th></tr>
-        <tr><td>read()</td>       <td>ReadPolicy::read (\ref senf::ReadPolicyBase)</td></tr>
-        <tr><td>readfrom()</td>   <td>ReadPolicy::readfrom (\ref senf::ReadPolicyBase)</td></tr>
-        <tr><td>write()</td>      <td>WritePolicy::write (\ref senf::WritePolicyBase)</td></tr>
-        <tr><td>writeto()</td>    <td>WritePolicy::writeto (\ref senf::WritePolicyBase)</td></tr>
-        <tr><td>connect()</td>    <td>AddressingPolicy::connect (\ref senf::AddressingPolicyBase)</td></tr>
-        <tr><td>bind()</td>       <td>AddressingPolicy::bind (\ref senf::AddressingPolicyBase)</td></tr>
-        <tr><td>peer()</td>       <td>AddressingPolicy::peer (\ref senf::AddressingPolicyBase)</td></tr>
-        <tr><td>local()</td>      <td>AddressingPolicy::local (\ref senf::AddressingPolicyBase)</td></tr>
-        <tr><td>rcvbuf()</td>     <td>BufferingPolicy::sndbuf (\ref senf::BufferingPolicyBase)</td></tr>
-        <tr><td>sndbuf()</td>     <td>BufferingPolicy::rcvbuf (\ref senf::BufferingPolicyBase)</td></tr>
+        <tr><th>ClientSocketHandle member</th> <th>Policy member</th> <th>Other policies</th></tr>
+        <tr><td>read()</td>       <td>ReadPolicy::read (\ref senf::ReadPolicyBase)</td>                  <td></td></tr>
+        <tr><td>readfrom()</td>   <td>ReadPolicy::readfrom (\ref senf::ReadPolicyBase)</td>              <td>UnconnectedCommunicationPolicy</td></tr>
+        <tr><td>write()</td>      <td>WritePolicy::write (\ref senf::WritePolicyBase)</td>               <td>ConnectedCommunicationPolicy</td></tr>
+        <tr><td>writeto()</td>    <td>WritePolicy::writeto (\ref senf::WritePolicyBase)</td>             <td>UnconnectedCommunicationPolicy</td></tr>
+        <tr><td>connect()</td>    <td>AddressingPolicy::connect (\ref senf::AddressingPolicyBase)</td>   <td></td></tr>
+        <tr><td>bind()</td>       <td>AddressingPolicy::bind (\ref senf::AddressingPolicyBase)</td>      <td></td></tr>
+        <tr><td>peer()</td>       <td>AddressingPolicy::peer (\ref senf::AddressingPolicyBase)</td>      <td></td></tr>
+        <tr><td>local()</td>      <td>AddressingPolicy::local (\ref senf::AddressingPolicyBase)</td>     <td></td></tr>
         </table>
 
         It is important to note, that not all members are always accessible. Which are depends on
@@ -81,21 +84,17 @@ namespace senf {
 
         \see \ref policy_group \n
              \ref protocol_group
-
-        \fixme Add enable_if conditions so anything convertible to unsigned will not be interpreted
-            as a Range template argument but will use the unsigned variant of
-            read/readfrom/write/writeto.
       */
-    template <class Policy>
+    template <class SPolicy>
     class ClientSocketHandle
-        : public SocketHandle<Policy>
+        : public SocketHandle<SPolicy>
     {
     public:
         ///////////////////////////////////////////////////////////////////////////
         // Types
 
         /// Address type from the addressing policy
-        typedef typename Policy::AddressingPolicy::Address Address;
+        typedef typename SPolicy::AddressingPolicy::Address Address;
         /// 'Best' type for passing address as parameter
         /** Depending on the type of \c Address, this will be either <tt>Address</tt> or <tt>Address
             const &</tt>. See <a
@@ -107,7 +106,7 @@ namespace senf {
         /** This class will probably only be usable, if the \c CommunicationPolicy is \c
             ConnectedCommunicationPolicy and the \c AddressingPolicy is not \c
             NoAddressingPolicy. */
-        typedef ServerSocketHandle<Policy> ServerSocketHandle;
+        typedef ServerSocketHandle<SPolicy> ServerHandle;
 
         ///////////////////////////////////////////////////////////////////////////
         ///\name Structors and default members
@@ -122,13 +121,22 @@ namespace senf {
         ClientSocketHandle();
 
         // conversion constructors
+#       ifndef DOXYGEN
         template <class OtherPolicy>
         ClientSocketHandle(ClientSocketHandle<OtherPolicy> other,
-                           typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type * = 0);
+                           typename SocketHandle<SPolicy>::template IsCompatible<OtherPolicy>::type * = 0);
+#       else
+        ClientSocketHandle(ClientSocketHandle<OtherPolicy> other);
+#       endif
 
+#       ifndef DOXYGEN
         template <class OtherPolicy>
-        typename SocketHandle<Policy>::template IsCompatible<OtherPolicy>::type const &
+        typename SocketHandle<SPolicy>::template IsCompatible<OtherPolicy>::type const &
         operator=(ClientSocketHandle<OtherPolicy> other);
+#       else
+        template <class OtherPolicy>
+        ClientSocketHandle<OtherPolicy> const & operator=(ClientSocketHandle<OtherPolicy> other);
+#       endif        
 
         ///@}
         ///////////////////////////////////////////////////////////////////////////
@@ -169,6 +177,11 @@ namespace senf {
         */
         std::string  read         (unsigned limit=0);
         template <class ForwardWritableRange>
+#       ifndef DOXYGEN
+        typename boost::range_iterator<ForwardWritableRange>::type
+                     read         (ForwardWritableRange const & range,
+                                   typename boost::disable_if< boost::is_convertible<ForwardWritableRange,unsigned> >::type * = 0);
+#       else
         typename boost::range_iterator<ForwardWritableRange>::type
                      read         (ForwardWritableRange const & range);
                                         ///< Read data into range
@@ -183,6 +196,13 @@ namespace senf {
                                                  last read character 
                                              \see \ref read() \n
                                                   <a href="http://www.boost.org/libs/range/index.html">Boost.Range</a> */
+#       endif
+#       ifndef DOXYGEN
+        template <class ForwardWritableRange>
+        typename boost::range_iterator<ForwardWritableRange>::type
+                     read         (ForwardWritableRange & range,
+                                   typename boost::disable_if< boost::is_convertible<ForwardWritableRange,unsigned> >::type * = 0);
+#       else
         template <class ForwardWritableRange>
         typename boost::range_iterator<ForwardWritableRange>::type
                      read         (ForwardWritableRange & range);
@@ -190,6 +210,7 @@ namespace senf {
                                         /**< \see read(ForwardWritableRange const &) \n
                                                   read() \n
                                                   <a href="http://www.boost.org/libs/range/index.html">Boost.Range</a>  */
+#       endif
         template <class Sequence>
         void         read         (Sequence & container, unsigned limit);
                                         ///< Read data into container
@@ -353,18 +374,18 @@ namespace senf {
 
             \throws senf::SystemException
          */
-        void         connect      (AddressParam addr);
+        void         connect      (AddressParam addr) const;
 
         /** \brief Set local address
 
             For addressable protocols (AddressingPolicy is not NoAddressingPolicy), bind() will set
             the local address of the socket.
 
-            \param[in] addr Local socket address to asign
+            \param[in] addr Local socket address to assign
 
             \throws senf::SystemException
          */
-        void         bind         (AddressParam addr);
+        void         bind         (AddressParam addr) const;
 
         /** \brief Query remote address
 
@@ -377,8 +398,8 @@ namespace senf {
 
             \throws senf::SystemException
          */
-        Address      peer         ();
-        void         peer         (Address & addr);
+        Address      peer         () const;
+        void         peer         (Address & addr) const;
                                         ///< Query remote address
                                         /**< \see \ref peer() */
 
@@ -392,31 +413,13 @@ namespace senf {
 
             \throws senf::SystemException
          */
-        Address      local        ();
-        void         local        (Address & addr);
+        Address      local        () const;
+        void         local        (Address & addr) const;
                                         ///< Query local address
                                         /**< \see \ref local() */
 
         ///@}
 
-        ///////////////////////////////////////////////////////////////////////////
-        ///\name Buffering
-        ///@{
-
-        unsigned     rcvbuf      ();    ///< Check size of receive buffer
-                                        /**< \returns size of receive buffer in bytes */
-        void         rcvbuf      (unsigned size);
-                                        ///< Set size of receive buffer
-                                        /**< \param[in] size size of receive buffer in bytes */
-
-        unsigned     sndbuf      ();    ///< Check size of send buffer
-                                        /**< \returns size of send buffer in bytes */
-        void         sndbuf      (unsigned size);
-                                        ///< Set size of send buffer
-                                        /**< \param[in] size size of send buffer in bytes */
-
-        ///@}
-
         static ClientSocketHandle cast_static(FileHandle handle);
         static ClientSocketHandle cast_dynamic(FileHandle handle);
 
@@ -424,15 +427,14 @@ namespace senf {
         void state(SocketStateMap & map, unsigned lod=0);
         std::string dumpState(unsigned lod=0);
 
+        unsigned available();
+
     protected:
         ClientSocketHandle(FileHandle other, bool isChecked);
-        explicit ClientSocketHandle(std::auto_ptr<SocketProtocol> protocol,
-                                    int fd = -1);
+        explicit ClientSocketHandle(std::auto_ptr<SocketBody> body);
 
     private:
-        unsigned available();
-
-        friend class senf::ServerSocketHandle<Policy>;
+        friend class senf::ServerSocketHandle<SPolicy>;
     };
 
     /// @}