4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.de>
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.
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.
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.
24 \brief GenericAddressingPolicy public header
27 #ifndef HH_GenericAddressingPolicy_
28 #define HH_GenericAddressingPolicy_ 1
31 #include "SocketHandle.hh"
32 #include "FileHandle.hh"
33 #include "SocketPolicy.hh"
34 #include "CommunicationPolicy.hh"
36 //#include "GenericAddressingPolicy.mpp"
37 ///////////////////////////////hh.p////////////////////////////////////////
41 /// \addtogroup policy_impl_group
44 /** \brief Non-template implementation class of GenericAddressingPolicy template
48 struct GenericAddressingPolicy_Base
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);
56 /** \brief Template for generic AddressingPolicy implementation based on the BSD socket API
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).
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
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).
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.
80 template <class Address>
81 struct GenericAddressingPolicy
82 : private GenericAddressingPolicy_Base
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.
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 */
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.
105 \param[in] handle socket handle
106 \param[in] addr address of remote peer to connect
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 */
118 ///////////////////////////////hh.e////////////////////////////////////////
119 //#include "GenericAddressingPolicy.cci"
120 //#include "GenericAddressingPolicy.ct"
121 #include "GenericAddressingPolicy.cti"
122 //#include "GenericAddressingPolicy.mpp"
129 // c-file-style: "senf"
130 // indent-tabs-mode: nil
131 // ispell-local-dictionary: "american"