git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@129 270642c3-0616-0410...
[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 #ifndef HH_SocketHandle_
27 #define HH_SocketHandle_ 1
28
29 // Custom includes
30 #include <memory> // std::auto_ptr
31 #include "FileHandle.hh"
32 #include "SocketPolicy.hh"
33
34 //#include "SocketHandle.mpp"
35 #include "SocketHandle.ih"
36 ///////////////////////////////hh.p////////////////////////////////////////
37 #include "SocketHandle.ih"
38
39 namespace satcom {
40 namespace lib {
41
42     /** \brief
43       */
44     template <class SocketPolicy>
45     class SocketHandle
46         : public FileHandle
47     {
48     public:
49         ///////////////////////////////////////////////////////////////////////////
50         // Types
51
52         typedef SocketPolicy Policy;
53
54         template <class OtherPolicy>
55         struct IsCompatible
56             : public boost::enable_if< SocketPolicyIsBaseOf<SocketPolicy,OtherPolicy>,
57                                        SocketHandle >
58         {};
59
60         ///////////////////////////////////////////////////////////////////////////
61         ///\name Structors and default members
62         ///@{
63
64         // default copy constructor
65         // default copy assignment
66         // default destructor
67
68         // conversion constructors
69         template <class OtherPolicy>
70         SocketHandle(SocketHandle<OtherPolicy> other, 
71                      typename IsCompatible<OtherPolicy>::type * = 0);
72
73         ///@}
74         ///////////////////////////////////////////////////////////////////////////
75
76         template <class OtherPolicy>
77         typename IsCompatible<OtherPolicy>::type const & operator=(SocketHandle<OtherPolicy> other);
78
79         static SocketHandle cast_static(FileHandle handle);
80         static SocketHandle cast_dynamic(FileHandle handle);
81
82         void state(SocketStateMap & map, unsigned lod=0);
83         std::string dumpState(unsigned lod=0);
84
85     protected:
86         explicit SocketHandle(std::auto_ptr<SocketProtocol> protocol, bool isServer);
87         SocketHandle(FileHandle other, bool isChecked);
88         
89         SocketBody & body();
90         SocketBody const & body() const;
91         SocketProtocol const & protocol() const;
92
93         void assign(FileHandle other);
94
95     private:
96
97     };
98
99     template <class Policy>
100     std::ostream & operator<<(std::ostream & os, SocketHandle<Policy> handle);
101
102     template <class Target, class Source>
103     Target static_socket_cast(Source handle);
104
105     template <class Target, class Source>
106     Target dynamic_socket_cast(Source handle);
107
108     template <class Target, class Source>
109     bool check_socket_cast(Source handle);
110 }}
111
112 ///////////////////////////////hh.e////////////////////////////////////////
113 #include "SocketHandle.cci"
114 #include "SocketHandle.ct"
115 #include "SocketHandle.cti"
116 #endif
117
118 \f
119 // Local Variables:
120 // mode: c++
121 // c-file-style: "satcom"
122 // End: