fdff6b718c568f0a08713e7760e948e47fe4c34b
[senf.git] / senf / 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_SENF_Socket_Protocols_UN_UNAddressing_
27 #define HH_SENF_Socket_Protocols_UN_UNAddressing_ 1
28
29 // Custom includes
30 #include <iostream>
31 #include <string>
32 #include <sys/socket.h>
33 #include <sys/un.h>
34 #include <senf/Socket/Protocols/BSDAddressingPolicy.hh>
35 #include <senf/Socket/Protocols/BSDSocketAddress.hh>
36
37 //#include "UNAddressing.mpp"
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
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 BSDSocketAddress
53     {
54     public:
55         static short const addressFamily = AF_UNIX;
56
57         UNSocketAddress();
58
59         explicit UNSocketAddress(std::string const & path);
60                                         ///< Construct an address constant from given path
61
62         UNSocketAddress(const UNSocketAddress& other);
63         UNSocketAddress& operator=(const UNSocketAddress& other);
64
65         std::string path() const ;      ///< Return path as string
66         void path(std::string const & path);
67
68         using BSDSocketAddress::sockaddr_p;
69         using BSDSocketAddress::socklen_p;
70
71     private:
72         struct sockaddr_un addr_;
73     };
74
75     /** \brief Write path to os
76
77         \related UNSocketAddress
78      */
79     std::ostream & operator<<(std::ostream & os, UNSocketAddress const & addr);
80
81     /// \addtogroup policy_impl_group
82     //\{
83
84     /** \brief Addressing policy supporting unix domain addressing
85
86         \par Address Type:
87             UNSocketAddress
88
89         This addressing policy implements addressing using unix domain
90         addresses.
91
92         The various members are directly imported from
93         BSDAddressingPolicyMixin which see for a detailed
94         documentation.
95      */
96     struct UNAddressingPolicy
97         : public BSDAddressingPolicy,
98           private BSDAddressingPolicyMixin<UNSocketAddress>
99     {
100         typedef UNSocketAddress Address;
101
102         using BSDAddressingPolicyMixin<UNSocketAddress>::peer;
103         using BSDAddressingPolicyMixin<UNSocketAddress>::local;
104         using BSDAddressingPolicyMixin<UNSocketAddress>::connect;
105         using BSDAddressingPolicyMixin<UNSocketAddress>::bind;
106     };
107
108     //\}
109 }
110
111 //-/////////////////////////////////////////////////////////////////////////////////////////////////
112 #include "UNAddressing.cci"
113 //#include "UNAddressing.ct"
114 //#include "UNAddressing.cti"
115 #endif
116
117 \f
118 // Local Variables:
119 // mode: c++
120 // fill-column: 100
121 // comment-column: 40
122 // c-file-style: "senf"
123 // indent-tabs-mode: nil
124 // ispell-local-dictionary: "american"
125 // compile-command: "scons -u test"
126 // End: