switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Socket / Protocols / UN / UNAddressing.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   David Wagner <dw6@berlios.de>
27 /** \file
28     \brief UNAddressing public header */
29
30 #ifndef HH_SENF_Socket_Protocols_UN_UNAddressing_
31 #define HH_SENF_Socket_Protocols_UN_UNAddressing_ 1
32
33 // Custom includes
34 #include <iostream>
35 #include <string>
36 #include <sys/socket.h>
37 #include <sys/un.h>
38 #include <senf/Socket/Protocols/BSDAddressingPolicy.hh>
39 #include <senf/Socket/Protocols/BSDSocketAddress.hh>
40
41 //#include "UNAddressing.mpp"
42 //-/////////////////////////////////////////////////////////////////////////////////////////////////
43
44 namespace senf {
45
46     /** \brief Unix domain socket address
47
48         UNSocketAddress wraps the standard sockaddr_un datatype. It provides simple accessor methods
49         to access the path.
50
51         \implementation This implementation is based on sockaddr_un.
52
53         \ingroup addr_group
54      */
55     class UNSocketAddress
56         : public BSDSocketAddress
57     {
58     public:
59         static short const addressFamily = AF_UNIX;
60
61         UNSocketAddress();
62
63         explicit UNSocketAddress(std::string const & path);
64                                         ///< Construct an address constant from given path
65
66         UNSocketAddress(const UNSocketAddress& other);
67         UNSocketAddress& operator=(const UNSocketAddress& other);
68
69         std::string path() const ;      ///< Return path as string
70         void path(std::string const & path);
71
72         using BSDSocketAddress::sockaddr_p;
73         using BSDSocketAddress::socklen_p;
74
75     private:
76         struct sockaddr_un addr_;
77     };
78
79     /** \brief Write path to os
80
81         \related UNSocketAddress
82      */
83     std::ostream & operator<<(std::ostream & os, UNSocketAddress const & addr);
84
85     /// \addtogroup policy_impl_group
86     //\{
87
88     /** \brief Addressing policy supporting unix domain addressing
89
90         \par Address Type:
91             UNSocketAddress
92
93         This addressing policy implements addressing using unix domain
94         addresses.
95
96         The various members are directly imported from
97         BSDAddressingPolicyMixin which see for a detailed
98         documentation.
99      */
100     struct UNAddressingPolicy
101         : public BSDAddressingPolicy,
102           private BSDAddressingPolicyMixin<UNSocketAddress>
103     {
104         typedef UNSocketAddress Address;
105
106         using BSDAddressingPolicyMixin<UNSocketAddress>::peer;
107         using BSDAddressingPolicyMixin<UNSocketAddress>::local;
108         using BSDAddressingPolicyMixin<UNSocketAddress>::connect;
109         using BSDAddressingPolicyMixin<UNSocketAddress>::bind;
110     };
111
112     //\}
113 }
114
115 //-/////////////////////////////////////////////////////////////////////////////////////////////////
116 #include "UNAddressing.cci"
117 //#include "UNAddressing.ct"
118 //#include "UNAddressing.cti"
119 #endif
120
121 \f
122 // Local Variables:
123 // mode: c++
124 // fill-column: 100
125 // comment-column: 40
126 // c-file-style: "senf"
127 // indent-tabs-mode: nil
128 // ispell-local-dictionary: "american"
129 // compile-command: "scons -u test"
130 // End: