Fix SCons 1.2.0 build failure
[senf.git] / senf / Socket / Protocols / BSDAddressingPolicy.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief BSDAddressingPolicyMixin public header
25  */
26
27 /** \defgroup addr_group Addressing classes
28  */
29
30 #ifndef HH_SENF_Socket_Protocols_BSDAddressingPolicy_
31 #define HH_SENF_Socket_Protocols_BSDAddressingPolicy_ 1
32
33 // Custom includes
34 #include "../SocketHandle.hh"
35 #include "../FileHandle.hh"
36 #include "../SocketPolicy.hh"
37 #include "../CommunicationPolicy.hh"
38 #include "BSDSocketAddress.hh"
39
40 //#include "BSDAddressingPolicy.mpp"
41 ///////////////////////////////hh.p////////////////////////////////////////
42
43 namespace senf {
44
45     /// \addtogroup policy_impl_group
46     /// @{
47
48     /** \brief Non-template implementation class of BSDAddressingPolicyMixin template
49
50         \internal
51      */
52     struct BSDAddressingPolicyMixinBase
53     {
54         static void do_local(FileHandle handle, struct sockaddr * addr, socklen_t * len);
55         static void do_peer(FileHandle handle, struct sockaddr * addr, socklen_t * len);
56         static void do_bind(FileHandle handle, struct sockaddr const * addr, socklen_t len);
57         static void do_connect(FileHandle handle, struct sockaddr const * addr, socklen_t len);
58     };
59
60     /** \brief Template for generic AddressingPolicy implementation based on the BSD socket API
61
62         This template provides an implementation template to implement generic addressing policy
63         classes which rely on the standard BSD socket API for their implementation
64         (connect/bind/getsockname/getpeername).
65
66         The \a Address template parameter specifies the address type of the addressing policy. This
67         type must have two members: \c sockaddr_p() and \c socklen(). The first must return a
68         <tt>struct sockaddr *</tt> to the address, the second must return the size of the address in
69         bytes. The pointer returned by \c sockaddr_p() must be non-const if called on a non-const
70         address. <em>The underlying socket address stored at that pointer might be
71         modified</em>.
72
73         This template class is inherited into addressing policy classes via private
74         inheritance. Then the members supported by the respective addressing policy are made
75         available via \c using declarations (See INet4AddressingPolicy for an Example).
76
77         \idea We could explicitly provide open_sockaddr_p() and close_sockaddr_p()
78         members. sockaddr_p could always return a const * whereas open_sockaddr_p should return a
79         non-const pointer. The close operation would then explicitly signal, that the new value
80         should be incorporated into the class. With our current implementation, the close member
81         would be a no-op, however this should free us from using the sockaddr values as a direct
82         storage representation of the address.
83      */
84     template <class Address>
85     struct BSDAddressingPolicyMixin
86         : private BSDAddressingPolicyMixinBase
87     {
88 #       ifndef DOXYGEN
89         template <class SPolicy>
90         static void peer(SocketHandle<SPolicy> handle, Address & addr,
91                          typename IfCommunicationPolicyIs<SPolicy,ConnectedCommunicationPolicy>::type * = 0);
92 #       else
93         template <class SPolicy>
94         static void peer(SocketHandle<SPolicy> handle, Address & addr);
95                                         ///< Return address of remote peer on connected sockets
96                                         /**< This member is only available if the socket handles
97                                              communication policy is ConnectedCommunicationPolicy.
98
99                                              \param[in] handle socket handle to get peer address of
100                                              \param[out] addr address of remote peer */
101 #       endif
102         static void local(FileHandle handle, Address & addr);
103                                         ///< Return local of socket
104                                         /**< \param[in] handle socket handle to check
105                                              \param[out] addr local socket address */
106
107 #       ifndef DOXYGEN
108         template <class SPolicy>
109         static void connect(SocketHandle<SPolicy> handle, Address const & addr,
110                             typename IfCommunicationPolicyIs<SPolicy,ConnectedCommunicationPolicy>::type * = 0);
111 #       else
112         template <class SPolicy>
113         static void connect(SocketHandle<SPolicy> handle, Address const & addr);
114                                         ///< Connect to remote host
115                                         /**< This member is only available if the socket handles
116                                              communication policy is ConnectedCommunicationPolicy.
117
118                                              \param[in] handle socket handle
119                                              \param[in] addr address of remote peer to connect
120                                                  to */
121 #       endif
122         static void bind(FileHandle handle, Address const & addr);
123                                         ///< Set local socket address
124                                         /**< \param[in] handle socket handle
125                                              \param[in] addr local socket address */
126     };
127
128     /// @}
129
130     struct BSDAddressingPolicy
131         : public AddressingPolicyBase,
132           private BSDAddressingPolicyMixin<GenericBSDSocketAddress>
133     {
134         typedef GenericBSDSocketAddress Address;
135
136         using BSDAddressingPolicyMixin<GenericBSDSocketAddress>::peer;
137         using BSDAddressingPolicyMixin<GenericBSDSocketAddress>::local;
138         using BSDAddressingPolicyMixin<GenericBSDSocketAddress>::connect;
139         using BSDAddressingPolicyMixin<GenericBSDSocketAddress>::bind;
140     };
141
142 }
143
144 ///////////////////////////////hh.e////////////////////////////////////////
145 //#include "BSDAddressingPolicy.cci"
146 //#include "BSDAddressingPolicy.ct"
147 #include "BSDAddressingPolicy.cti"
148 //#include "BSDAddressingPolicy.mpp"
149 #endif
150
151 \f
152 // Local Variables:
153 // mode: c++
154 // fill-column: 100
155 // c-file-style: "senf"
156 // indent-tabs-mode: nil
157 // ispell-local-dictionary: "american"
158 // compile-command: "scons -u ../test"
159 // comment-column: 40
160 // End: