Fixed whitespace in all files (no tabs)
[senf.git] / Socket / GenericAddressingPolicy.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.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 GenericAddressingPolicy public header
25  */
26
27 #ifndef HH_GenericAddressingPolicy_
28 #define HH_GenericAddressingPolicy_ 1
29
30 // Custom includes
31 #include "SocketHandle.hh"
32 #include "FileHandle.hh"
33 #include "SocketPolicy.hh"
34 #include "CommunicationPolicy.hh"
35
36 //#include "GenericAddressingPolicy.mpp"
37 ///////////////////////////////hh.p////////////////////////////////////////
38
39 namespace senf {
40
41     /// \addtogroup policy_impl_group
42     /// @{
43
44     /** \brief Non-template implemenatation class of GenericAddressingPolicy template
45
46         \internal
47      */
48     struct GenericAddressingPolicy_Base
49     {
50         static void do_local(FileHandle handle, struct sockaddr * addr, unsigned len);
51         static void do_peer(FileHandle handle, struct sockaddr * addr, unsigned len);
52         static void do_bind(FileHandle handle, struct sockaddr const * addr, unsigned len);
53         static void do_connect(FileHandle handle, struct sockaddr const * addr, unsigned len);
54     };
55
56     /** \brief Template for generic AddressingPolicy implementation based on the BSD socket API
57
58         This template provides an implementation template to implement generic addressing policy
59         classes which rely on the standard BSD socket API for their implementation
60         (connect/bind/getsockname/getpeername).
61
62         The \a Address template parameter specifies the address type of the addressing policy. This
63         type must have two members: \c sockaddr_p() and \c sockaddr_len(). The first must return a
64         <tt>struct sockaddr *</tt> to the address, the second must return the size of the address in
65         bytes. The pointer returned by \c sockaddr_p() must be non-const if called on a non-const
66         address. <em>The underlying socket address stored at that pointer might be
67         modified</em>.
68
69         This template class is inherited into addressing policy classes via private
70         inheritance. Then the members supported by the respective addressing policy are made
71         available via \c using declarations (See INet4AddressingPolicy for an Example).
72
73         \idea We could explicitly provide open_sockaddr_p() and close_sockaddr_p()
74         members. sockaddr_p could always return a const * whereas open_sockaddr_p should return a
75         non-const pointer. The close operation would then explicitly signal, that the new value
76         should be incorporated into the class. With our current implementation, the close member
77         would be a no-op, however this ould free us from using the sockaddr values as a direct
78         sotrage representation of the address.
79      */
80     template <class Address>
81     struct GenericAddressingPolicy
82         : private GenericAddressingPolicy_Base
83     {
84         template <class Policy>
85         static void peer(SocketHandle<Policy> handle, Address & addr,
86                          typename IfCommunicationPolicyIs<Policy,ConnectedCommunicationPolicy>::type * = 0);
87                                         ///< Return address of remote peer on connected sockets
88                                         /**< This member is only available if the socket handles
89                                              communication policy is ConnectedCommunicationPolicy.
90
91                                              \param[in] handle socket handle to get peer address of
92                                              \param[out] addr address of remote peer */
93         static void local(FileHandle handle, Address & addr);
94                                         ///< Return local of socket
95                                         /**< \param[in] handle socket handle to check
96                                              \param[out] addr local socket address */
97
98         template <class Policy>
99         static void connect(SocketHandle<Policy> handle, Address const & addr,
100                             typename IfCommunicationPolicyIs<Policy,ConnectedCommunicationPolicy>::type * = 0);
101                                         ///< Connect to remote host
102                                         /**< This member is only available if the socket handles
103                                              communication policy is ConnectedCommunicationPolicy.
104
105                                              \param[in] handle socket handle
106                                              \param[in] address address of remote peer to connect
107                                                  to */
108         static void bind(FileHandle handle, Address const & addr);
109                                         ///< Set local socket address
110                                         /**< \param[in] handle socket handle
111                                              \param[in] addr local socket address */
112     };
113
114     /// @}
115
116 }
117
118 ///////////////////////////////hh.e////////////////////////////////////////
119 //#include "GenericAddressingPolicy.cci"
120 //#include "GenericAddressingPolicy.ct"
121 #include "GenericAddressingPolicy.cti"
122 //#include "GenericAddressingPolicy.mpp"
123 #endif
124
125 \f
126 // Local Variables:
127 // mode: c++
128 // fill-column: 100
129 // c-file-style: "senf"
130 // indent-tabs-mode: nil
131 // ispell-local-dictionary: "american"
132 // End: