removed some errors, added basic unit tests
[senf.git] / Socket / Protocols / UN / UNAddressing.hh
1 // $Id$
2 //
3 // Copyright (C) 2007 
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the
17 // Free Software Foundation, Inc.,
18 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 /** \file
21     \brief UNAddressing public header */
22
23 #ifndef HH_UNAddressing_
24 #define HH_UNAddressing_ 1
25
26 // Custom includes
27 #include <iostream>
28 #include <string>
29 #include <sys/socket.h>
30 #include <sys/un.h>
31 #include <boost/cstdint.hpp>
32 #include <boost/operators.hpp>
33 #include "boost/filesystem/path.hpp"
34 #include "../../../Socket/SocketPolicy.hh"
35 #include "../../../Socket/ClientSocketHandle.hh"
36 #include "../../../Socket/CommunicationPolicy.hh"
37 #include "../../../Socket/Protocols/GenericAddressingPolicy.hh"
38 #include "UNAddress.hh"
39
40 //#include "UNAddressing.mpp"
41 ///////////////////////////////hh.p////////////////////////////////////////
42 namespace senf {
43     /** \brief Unix domain socket address
44
45         UNSocketAddress wraps the standard sockaddr_un datatype. It provides simple accessor methods
46         to access the path. 
47         
48         \implementation This implementation is based on sockaddr_un.
49
50         \ingroup addr_group
51      */
52     class UNSocketAddress
53         : public ComparableSafeBool<UNSocketAddress>
54     {
55     public:
56
57         //UNSocketAddress(); 
58         explicit UNSocketAddress(boost::filesystem::path p);
59                                         ///< Construct an address constant from given path
60         static UNSocketAddress from_string(std::string const s); ///< Create UNSocketAddress from string
61         static UNSocketAddress from_path(boost::filesystem::path const p); ///< Create UNSocketAddress from path
62         std::string path() const ;  ///< Return path as string
63         struct sockaddr_un sockaddr(); 
64         struct sockaddr * sockaddr_p() ;
65         struct sockaddr const * sockaddr_p() const;
66         unsigned sockaddr_len();
67     private:
68         struct sockaddr_un sockAddr;
69     };
70
71     /** \brief Write path  os
72
73         \related UNSocketAddress
74      */
75     std::ostream & operator<<(std::ostream & os, UNSocketAddress const & addr);
76
77     /// \addtogroup policy_impl_group
78     /// @{
79
80     /** \brief Addressing policy supporting unix domain addressing
81
82         \par Address Type:
83             UNAddress
84
85         This addressing policy implements addressing using unix domain
86         addresses.
87
88         The various members are directly imported from
89         GenericAddressingPolicy which see for a detailed
90         documentation.
91      */
92
93     struct UNAddressingPolicy
94         : public AddressingPolicyBase,
95           private GenericAddressingPolicy<UNSocketAddress>
96     {
97         typedef UNSocketAddress Address;
98
99         using GenericAddressingPolicy<UNSocketAddress>::peer;
100         using GenericAddressingPolicy<UNSocketAddress>::local;
101         using GenericAddressingPolicy<UNSocketAddress>::connect;
102         using GenericAddressingPolicy<UNSocketAddress>::bind;
103     };
104 }
105 ///////////////////////////////hh.e////////////////////////////////////////
106 //#include "UNAddressing.cci"
107 //#include "UNAddressing.ct"
108 //#include "UNAddressing.cti"
109 #endif
110
111 \f
112 // Local Variables:
113 // mode: c++
114 // fill-column: 100
115 // comment-column: 40
116 // c-file-style: "senf"
117 // indent-tabs-mode: nil
118 // ispell-local-dictionary: "american"
119 // compile-command: "scons -u test"
120 // End: