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 implemenatation 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 \idea We could explicitly provide open_sockaddr_p() and close_sockaddr_p()
70 members. sockaddr_p could always return a const * whereas open_sockaddr_p should return a
71 non-const pointer. The close operation would then explicitly signal, that the new value
72 should be incorporated into the class. With our current implementation, the close member
73 would be a no-op, however this ould free us from using the sockaddr values as a direct
74 sotrage representation of the address.
76 template <class Address>
77 struct GenericAddressingPolicy
78 : private GenericAddressingPolicy_Base
80 template <class Policy>
81 static void peer(SocketHandle<Policy> handle, Address & addr,
82 typename IfCommunicationPolicyIs<Policy,ConnectedCommunicationPolicy>::type * = 0);
83 ///< Return address of remote peer on connected sockets
84 /**< This member is only available if the socket handles
85 communication policy is ConnectedCommunicationPolicy.
87 \param[in] handle socket handle to get peer address of
88 \param[out] addr address of remote peer */
89 static void local(FileHandle handle, Address & addr);
90 ///< Return local of socket
91 /**< \param[in] handle socket handle to check
92 \param[out] addr local socket address */
94 template <class Policy>
95 static void connect(SocketHandle<Policy> handle, Address const & addr,
96 typename IfCommunicationPolicyIs<Policy,ConnectedCommunicationPolicy>::type * = 0);
97 ///< Connect to remote host
98 /**< This member is only available if the socket handles
99 communication policy is ConnectedCommunicationPolicy.
101 \param[in] handle socket handle
102 \param[in] address address of remote peer to connect
104 static void bind(FileHandle handle, Address const & addr);
105 ///< Set local socket address
106 /**< \param[in] handle socket handle
107 \param[in] addr local socket address */
114 ///////////////////////////////hh.e////////////////////////////////////////
115 //#include "GenericAddressingPolicy.cci"
116 //#include "GenericAddressingPolicy.ct"
117 #include "GenericAddressingPolicy.cti"
118 //#include "GenericAddressingPolicy.mpp"
124 // c-file-style: "senf"