Further documentation (mainly SocketPolicy)
[senf.git] / Socket / SocketProtocol.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 /** \file
24  */
25
26 /** \defgroup protocol_group The Protocol Classes
27
28     \image html Protocols.png
29
30     The socket handle classes and templates only implement the most
31     important socket API methods using the policy framework. To access
32     the complete API, the protocol interface is provided. Access to
33     the protocol interface is only possible via
34     senf::ProtocolClientSocketHandle and
35     senf::ProtocolServerSocketHandle which have the necessary \c
36     protocol() member. This member returns a reference to the protocol
37     class instance which contains members covering all the API
38     functions (mostly setsockopt/getsockopt related calls but there
39     may be more, this is completely up to the implementor of the
40     protocol class) not found in the SocketHandle interface. The
41     protocol interface is specific to the protocol. It's
42     implementation is quite free. The standard protocols are
43     implemented using a simple multiple-inheritance hierarchy as shown
44     above.
45
46     Since the protocol class is protocol specific (how intelligent
47     ...), the protocol class also defines the complete socket policy
48     to be used with it's protocol. Complete meaning, that every policy
49     axis must be assigned it's the most specific (that is derived)
50     policy class to be used with the protocol.
51  */
52
53 #ifndef HH_SocketProtocol_
54 #define HH_SocketProtocol_ 1
55
56 // Custom includes
57 #include <boost/utility.hpp>
58 /** \fixme this is not nice. The includes and predefs should be restructured */
59 #include "SocketHandle.ih"
60
61 //#include "SocketProtocol.mpp"
62 ///////////////////////////////hh.p////////////////////////////////////////
63
64 namespace senf {
65
66     /// \addtogroup protocol_group
67     /// @{
68
69     class SocketPolicyBase;
70
71     class SocketProtocol : boost::noncopyable
72     {
73     public:
74         ///////////////////////////////////////////////////////////////////////////
75         // Types
76
77         ///////////////////////////////////////////////////////////////////////////
78         ///\name Structors and default members
79         ///@{
80
81         SocketProtocol();
82         virtual ~SocketProtocol() = 0;
83
84         // default default constructor
85         // no copy
86         // no conversion constructors
87
88         ///@}
89         ///////////////////////////////////////////////////////////////////////////
90
91         SocketBody & body() const;
92         virtual SocketPolicyBase const & policy() const = 0;
93         
94         ///////////////////////////////////////////////////////////////////////////
95         // Virtual interface
96
97         virtual std::auto_ptr<SocketProtocol> clone() const = 0;
98         virtual unsigned available() const = 0;
99         virtual bool eof() const = 0;
100         virtual void state(SocketStateMap & map, unsigned lod) const;
101
102     protected:
103
104     private:
105         // backpointer to owning SocketBody instance
106         SocketBody * body_;
107         friend class SocketBody; 
108    };
109
110     template <class SocketPolicy>
111     class ConcreteSocketProtocol
112         : public virtual SocketProtocol
113     {
114     public:
115         ///////////////////////////////////////////////////////////////////////////
116         // Types
117
118         typedef SocketPolicy Policy;
119
120         ///////////////////////////////////////////////////////////////////////////
121         ///\name Structors and default members
122         ///@{
123
124         ~ConcreteSocketProtocol() = 0;
125
126         // no default constructor
127         // no copy
128         // no conversion constructors
129
130         ///@}
131         ///////////////////////////////////////////////////////////////////////////
132
133         Policy const & policy() const;
134
135     protected:
136
137     private:
138         Policy policy_;
139
140     };
141
142     /// @}
143 }
144
145 ///////////////////////////////hh.e////////////////////////////////////////
146 #include "SocketProtocol.cci"
147 //#include "SocketProtocol.ct"
148 #include "SocketProtocol.cti"
149 #endif
150
151 \f
152 // Local Variables:
153 // mode: c++
154 // c-file-style: "senf"
155 // End: