Move include files in debian packge into 'senf' subdirectory
[senf.git] / Socket / Protocols / 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 "../../Socket/SocketHandle.hh"
32 #include "../../Socket/FileHandle.hh"
33 #include "../../Socket/SocketPolicy.hh"
34 #include "../../Socket/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 implementation 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 should free us from using the sockaddr values as a direct
78         storage representation of the address.
79      */
80     template <class Address>
81     struct GenericAddressingPolicy
82         : private GenericAddressingPolicy_Base
83     {
84 #       ifndef DOXYGEN
85         template <class Policy>
86         static void peer(SocketHandle<Policy> handle, Address & addr,
87                          typename IfCommunicationPolicyIs<Policy,ConnectedCommunicationPolicy>::type * = 0);
88 #       else
89         template <class Policy>
90         static void peer(SocketHandle<Policy> handle, Address & addr);
91                                         ///< Return address of remote peer on connected sockets
92                                         /**< This member is only available if the socket handles
93                                              communication policy is ConnectedCommunicationPolicy.
94
95                                              \param[in] handle socket handle to get peer address of
96                                              \param[out] addr address of remote peer */
97 #       endif
98         static void local(FileHandle handle, Address & addr);
99                                         ///< Return local of socket
100                                         /**< \param[in] handle socket handle to check
101                                              \param[out] addr local socket address */
102
103 #       ifndef DOXYGEN
104         template <class Policy>
105         static void connect(SocketHandle<Policy> handle, Address const & addr,
106                             typename IfCommunicationPolicyIs<Policy,ConnectedCommunicationPolicy>::type * = 0);
107 #       else
108         template <class Policy>
109         static void connect(SocketHandle<Policy> handle, Address const & addr);
110                                         ///< Connect to remote host
111                                         /**< This member is only available if the socket handles
112                                              communication policy is ConnectedCommunicationPolicy.
113
114                                              \param[in] handle socket handle
115                                              \param[in] addr address of remote peer to connect
116                                                  to */
117 #       endif
118         static void bind(FileHandle handle, Address const & addr);
119                                         ///< Set local socket address
120                                         /**< \param[in] handle socket handle
121                                              \param[in] addr local socket address */
122     };
123
124     /// @}
125
126 }
127
128 ///////////////////////////////hh.e////////////////////////////////////////
129 //#include "GenericAddressingPolicy.cci"
130 //#include "GenericAddressingPolicy.ct"
131 #include "GenericAddressingPolicy.cti"
132 //#include "GenericAddressingPolicy.mpp"
133 #endif
134
135 \f
136 // Local Variables:
137 // mode: c++
138 // fill-column: 100
139 // c-file-style: "senf"
140 // indent-tabs-mode: nil
141 // ispell-local-dictionary: "american"
142 // compile-command: "scons -u test"
143 // comment-column: 40
144 // End: