22e16712022e5b0e59c7ebc10a47a2e46531cf11
[senf.git] / Socket / Protocols / UN / UNAddressing.hh
1 // Copyright (C) 2007 
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum NETwork research (NET)
4 //     David Wagner <david.wagner@fokus.fraunhofer.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 /** \file
22     \brief UNAddressing public header */
23
24 #ifndef HH_UNAddressing_
25 #define HH_UNAddressing_ 1
26
27 // Custom includes
28 #include <iostream>
29 #include <string>
30 #include <sys/socket.h>
31 #include <sys/un.h>
32 #include <boost/cstdint.hpp>
33 #include <boost/operators.hpp>
34 #include "../../../Socket/SocketPolicy.hh"
35 #include "../../../Socket/ClientSocketHandle.hh"
36 #include "../../../Socket/CommunicationPolicy.hh"
37 #include "../../../Socket/Protocols/GenericAddressingPolicy.hh"
38 #include "../../../Utils/safe_bool.hh"
39
40 //#include "UNAddressing.mpp"
41 ///////////////////////////////hh.p////////////////////////////////////////
42
43 namespace senf {
44
45     /** \brief Unix domain socket address
46
47         UNSocketAddress wraps the standard sockaddr_un datatype. It provides simple accessor methods
48         to access the path. 
49         
50         \implementation This implementation is based on sockaddr_un.
51
52         \ingroup addr_group
53
54         \fixme Why both std::string constructor and from_string member ?
55      */
56     class UNSocketAddress
57         : public comparable_safe_bool<UNSocketAddress>
58     {
59     public:
60         UNSocketAddress(); 
61         explicit UNSocketAddress(std::string p);
62                                         ///< Construct an address constant from given path
63         static UNSocketAddress from_string(std::string const s); 
64                                         ///< Create UNSocketAddress from string
65
66         bool operator==(UNSocketAddress const & other) const;
67                                         ///< Compare UNSocketAddress for equality
68
69         std::string path() const ;      ///< Return path as string
70
71         bool boolean_test() const;      ///< \c true, if address is not empty
72         
73         void clear();                   ///< Clear address
74
75         struct sockaddr * sockaddr_p() ;
76         struct sockaddr const * sockaddr_p() const;
77         unsigned sockaddr_len() const;
78
79     private:
80         struct sockaddr_un addr_;
81     };
82
83     /** \brief Write path to os
84
85         \related UNSocketAddress
86      */
87     std::ostream & operator<<(std::ostream & os, UNSocketAddress const & addr);
88
89     /// \addtogroup policy_impl_group
90     /// @{
91
92     /** \brief Addressing policy supporting unix domain addressing
93
94         \par Address Type:
95             UNAddress
96
97         This addressing policy implements addressing using unix domain
98         addresses.
99
100         The various members are directly imported from
101         GenericAddressingPolicy which see for a detailed
102         documentation.
103      */
104     struct UNAddressingPolicy
105         : public AddressingPolicyBase,
106           private GenericAddressingPolicy<UNSocketAddress>
107     {
108         typedef UNSocketAddress Address;
109
110         using GenericAddressingPolicy<UNSocketAddress>::peer;
111         using GenericAddressingPolicy<UNSocketAddress>::local;
112         using GenericAddressingPolicy<UNSocketAddress>::connect;
113         using GenericAddressingPolicy<UNSocketAddress>::bind;
114     };
115
116     ///@}
117 }
118
119 ///////////////////////////////hh.e////////////////////////////////////////
120 //#include "UNAddressing.cci"
121 //#include "UNAddressing.ct"
122 //#include "UNAddressing.cti"
123 #endif
124
125 \f
126 // Local Variables:
127 // mode: c++
128 // fill-column: 100
129 // comment-column: 40
130 // c-file-style: "senf"
131 // indent-tabs-mode: nil
132 // ispell-local-dictionary: "american"
133 // compile-command: "scons -u test"
134 // End: