79d6f18e5fc4bf2524291839a0569fd5b82f121f
[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 "boost/filesystem/path.hpp"
35 #include "../../../Socket/SocketPolicy.hh"
36 #include "../../../Socket/ClientSocketHandle.hh"
37 #include "../../../Socket/CommunicationPolicy.hh"
38 #include "../../../Socket/Protocols/GenericAddressingPolicy.hh"
39 #include "UNAddress.hh"
40
41 //#include "UNAddressing.mpp"
42 ///////////////////////////////hh.p////////////////////////////////////////
43 namespace senf {
44     /** \brief Unix domain socket address
45
46         UNSocketAddress wraps the standard sockaddr_un datatype. It provides simple accessor methods
47         to access the path. 
48         
49         \implementation This implementation is based on sockaddr_un.
50
51         \ingroup addr_group
52      */
53     class UNSocketAddress
54         : public ComparableSafeBool<UNSocketAddress>
55     {
56     public:
57
58         //UNSocketAddress(); 
59         explicit UNSocketAddress(boost::filesystem::path p);
60                                         ///< Construct an address constant from given path
61         static UNSocketAddress from_string(std::string const s); ///< Create UNSocketAddress from string
62         static UNSocketAddress from_path(boost::filesystem::path const p); ///< Create UNSocketAddress from path
63         std::string path() const ;  ///< Return path as string
64         struct sockaddr_un sockaddr(); 
65         struct sockaddr * sockaddr_p() ;
66         struct sockaddr const * sockaddr_p() const;
67         unsigned sockaddr_len();
68     private:
69         struct sockaddr_un sockAddr;
70     };
71
72     /** \brief Write path  os
73
74         \related UNSocketAddress
75      */
76     std::ostream & operator<<(std::ostream & os, UNSocketAddress const & addr);
77
78     /// \addtogroup policy_impl_group
79     /// @{
80
81     /** \brief Addressing policy supporting unix domain addressing
82
83         \par Address Type:
84             UNAddress
85
86         This addressing policy implements addressing using unix domain
87         addresses.
88
89         The various members are directly imported from
90         GenericAddressingPolicy which see for a detailed
91         documentation.
92      */
93
94     struct UNAddressingPolicy
95         : public AddressingPolicyBase,
96           private GenericAddressingPolicy<UNSocketAddress>
97     {
98         typedef UNSocketAddress Address;
99
100         using GenericAddressingPolicy<UNSocketAddress>::peer;
101         using GenericAddressingPolicy<UNSocketAddress>::local;
102         using GenericAddressingPolicy<UNSocketAddress>::connect;
103         using GenericAddressingPolicy<UNSocketAddress>::bind;
104     };
105 }
106 ///////////////////////////////hh.e////////////////////////////////////////
107 //#include "UNAddressing.cci"
108 //#include "UNAddressing.ct"
109 //#include "UNAddressing.cti"
110 #endif
111
112 \f
113 // Local Variables:
114 // mode: c++
115 // fill-column: 100
116 // comment-column: 40
117 // c-file-style: "senf"
118 // indent-tabs-mode: nil
119 // ispell-local-dictionary: "american"
120 // compile-command: "scons -u test"
121 // End: