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