Renamed namespaces satcom::lib and satcom::pkf to senf
[senf.git] / Socket / SocketHandle.hh
1 // $Id$
2 //
3 // Copyright (C) 2006 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.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 // TODO: Create a SocketHandleBase class and move some non-Policy
24 // dependent code there
25
26
27 #ifndef HH_SocketHandle_
28 #define HH_SocketHandle_ 1
29
30 // Custom includes
31 #include <memory> // std::auto_ptr
32 #include "FileHandle.hh"
33 #include "SocketPolicy.hh"
34
35 //#include "SocketHandle.mpp"
36 #include "SocketHandle.ih"
37 ///////////////////////////////hh.p////////////////////////////////////////
38 #include "SocketHandle.ih"
39
40 namespace senf {
41
42
43     /** \brief
44       */
45     template <class SocketPolicy>
46     class SocketHandle
47         : public FileHandle
48     {
49     public:
50         ///////////////////////////////////////////////////////////////////////////
51         // Types
52
53         typedef SocketPolicy Policy;
54
55         template <class OtherPolicy>
56         struct IsCompatible
57             : public boost::enable_if< SocketPolicyIsBaseOf<SocketPolicy,OtherPolicy>,
58                                        SocketHandle >
59         {};
60
61         ///////////////////////////////////////////////////////////////////////////
62         ///\name Structors and default members
63         ///@{
64
65         // default copy constructor
66         // default copy assignment
67         // default destructor
68
69         // conversion constructors
70         template <class OtherPolicy>
71         SocketHandle(SocketHandle<OtherPolicy> other, 
72                      typename IsCompatible<OtherPolicy>::type * = 0);
73
74         ///@}
75         ///////////////////////////////////////////////////////////////////////////
76
77         template <class OtherPolicy>
78         typename IsCompatible<OtherPolicy>::type const & operator=(SocketHandle<OtherPolicy> other);
79
80         static SocketHandle cast_static(FileHandle handle);
81         static SocketHandle cast_dynamic(FileHandle handle);
82
83         void state(SocketStateMap & map, unsigned lod=0);
84         std::string dumpState(unsigned lod=0);
85
86     protected:
87         explicit SocketHandle(std::auto_ptr<SocketProtocol> protocol, bool isServer);
88         SocketHandle(FileHandle other, bool isChecked);
89         
90         SocketBody & body();
91         SocketBody const & body() const;
92         SocketProtocol const & protocol() const;
93
94         void assign(FileHandle other);
95
96     private:
97
98     };
99
100     template <class Policy>
101     std::ostream & operator<<(std::ostream & os, SocketHandle<Policy> handle);
102
103     template <class Target, class Source>
104     Target static_socket_cast(Source handle);
105
106     template <class Target, class Source>
107     Target dynamic_socket_cast(Source handle);
108
109     template <class Target, class Source>
110     bool check_socket_cast(Source handle);
111 }
112
113 ///////////////////////////////hh.e////////////////////////////////////////
114 #include "SocketHandle.cci"
115 #include "SocketHandle.ct"
116 #include "SocketHandle.cti"
117 #endif
118
119 \f
120 // Local Variables:
121 // mode: c++
122 // c-file-style: "senf"
123 // End: