cleanup UNAdressing
[senf.git] / Socket / Protocols / UN / UNAddressing.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     David Wagner <dw6@berlios.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 UNAddressing public header */
25
26 #ifndef HH_UNAddressing_
27 #define HH_UNAddressing_ 1
28
29 // Custom includes
30 #include <iostream>
31 #include <string>
32 #include <sys/socket.h>
33 #include <sys/un.h>
34 #include "../../../Socket/Protocols/GenericAddressingPolicy.hh"
35 #include "../../../Utils/safe_bool.hh"
36
37 //#include "UNAddressing.mpp"
38 ///////////////////////////////hh.p////////////////////////////////////////
39
40 namespace senf {
41
42     /** \brief Unix domain socket address
43
44         UNSocketAddress wraps the standard sockaddr_un datatype. It provides simple accessor methods
45         to access the path. 
46         
47         \implementation This implementation is based on sockaddr_un.
48
49         \ingroup addr_group
50      */
51     class UNSocketAddress
52         : public comparable_safe_bool<UNSocketAddress>
53     {
54     public:
55         UNSocketAddress(); 
56         explicit UNSocketAddress(std::string const & path);
57                                         ///< Construct an address constant from given path
58
59         bool operator==(UNSocketAddress const & other) const;
60                                         ///< Compare UNSocketAddress for equality
61
62         std::string path() const ;      ///< Return path as string
63
64         bool boolean_test() const;      ///< \c true, if address is not empty
65         
66         void clear();                   ///< Clear address
67
68         struct sockaddr * sockaddr_p() ;
69         struct sockaddr const * sockaddr_p() const;
70         unsigned sockaddr_len() const;
71
72     private:
73         struct sockaddr_un addr_;
74     };
75
76     /** \brief Write path to os
77
78         \related UNSocketAddress
79      */
80     std::ostream & operator<<(std::ostream & os, UNSocketAddress const & addr);
81
82     /// \addtogroup policy_impl_group
83     /// @{
84
85     /** \brief Addressing policy supporting unix domain addressing
86
87         \par Address Type:
88             UNSocketAddress
89
90         This addressing policy implements addressing using unix domain
91         addresses.
92
93         The various members are directly imported from
94         GenericAddressingPolicy which see for a detailed
95         documentation.
96      */
97     struct UNAddressingPolicy
98         : public AddressingPolicyBase,
99           private GenericAddressingPolicy<UNSocketAddress>
100     {
101         typedef UNSocketAddress Address;
102
103         using GenericAddressingPolicy<UNSocketAddress>::peer;
104         using GenericAddressingPolicy<UNSocketAddress>::local;
105         using GenericAddressingPolicy<UNSocketAddress>::connect;
106         using GenericAddressingPolicy<UNSocketAddress>::bind;
107     };
108
109     ///@}
110 }
111
112 ///////////////////////////////hh.e////////////////////////////////////////
113 //#include "UNAddressing.cci"
114 //#include "UNAddressing.ct"
115 //#include "UNAddressing.cti"
116 #endif
117
118 \f
119 // Local Variables:
120 // mode: c++
121 // fill-column: 100
122 // comment-column: 40
123 // c-file-style: "senf"
124 // indent-tabs-mode: nil
125 // ispell-local-dictionary: "american"
126 // compile-command: "scons -u test"
127 // End: