5b02eae8abcd614cbab2005045e804f80a3964e1
[senf.git] / senf / Socket / ProtocolServerSocketHandle.cti
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief ProtocolServerSocketHandle inline template implementation
30  */
31
32 // Definition of inline template functions
33
34 //#include "ProtocolServerSocketHandle.ih"
35
36 // Custom includes
37 #include <senf/Utils/senfassert.hh>
38 #include "ProtocolClientSocketHandle.hh"
39
40 #define prefix_ inline
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42
43 template <class SocketProtocol>
44 prefix_ senf::ProtocolServerSocketHandle<SocketProtocol>::
45 ProtocolServerSocketHandle(senf::NoInit_t)
46 {}
47
48 template <class SocketProtocol>
49 prefix_ senf::ProtocolServerSocketHandle<SocketProtocol>::ProtocolServerSocketHandle()
50     : ServerSocketHandle<typename SocketProtocol::Policy>(
51         std::auto_ptr<senf::SocketBody>(new ProtocolSocketBody<SocketProtocol>(true)))
52 {}
53
54 #define BOOST_PP_ITERATION_PARAMS_1 \
55     (4, (1, 9, SENF_ABSOLUTE_INCLUDE_PATH(Socket/ProtocolServerSocketHandle.mpp), 2))
56 #include BOOST_PP_ITERATE()
57
58 template <class SocketProtocol>
59 prefix_ SocketProtocol &
60 senf::ProtocolServerSocketHandle<SocketProtocol>::protocol()
61 {
62     SENF_ASSERT( dynamic_cast<SocketProtocol const *>(&this->body().protocol()),
63                  "Internal failure: Incompatible protocol class fount it's way into this handle");
64     // Need dynamic_cast here, since senf::SocketProtocol is a
65     // virtual base
66     return dynamic_cast<SocketProtocol &>(this->body().protocol());
67 }
68
69 template <class SocketProtocol>
70 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>
71 senf::ProtocolServerSocketHandle<SocketProtocol>::accept()
72 {
73     return ProtocolClientSocketHandle<SocketProtocol>(
74         FileHandle(this->ServerSocketHandle<typename SocketProtocol::Policy>::accept()),true);
75 }
76
77 template <class SocketProtocol>
78 prefix_ senf::ProtocolServerSocketHandle<SocketProtocol>
79 senf::ProtocolServerSocketHandle<SocketProtocol>::cast_static(FileHandle handle)
80 {
81     return ProtocolServerSocketHandle(handle,true);
82 }
83
84 template <class SocketProtocol>
85 prefix_ senf::ProtocolServerSocketHandle<SocketProtocol>
86 senf::ProtocolServerSocketHandle<SocketProtocol>::cast_dynamic(FileHandle handle)
87 {
88     ServerSocketHandle<typename SocketProtocol::Policy> h(
89         ServerSocketHandle<typename SocketProtocol::Policy>::cast_dynamic(handle));
90     // throw std::bad_cast if the protocol is invalid
91     dynamic_cast<SocketProtocol const &>(static_cast<SocketBody&>(FileHandle::body(h)).protocol());
92     return cast_static(handle);
93 }
94
95 template <class SocketProtocol>
96 prefix_ void
97 senf::ProtocolServerSocketHandle<SocketProtocol>::state(SocketStateMap & map,
98                                                                unsigned lod)
99 {
100     map["handle"] = prettyName(typeid(*this));
101     if (this->valid()) {
102         map["valid"] << "true";
103         this->body().state(map,lod);
104     } else
105         map["valid"] << "false";
106 }
107
108 template <class SocketProtocol>
109 prefix_ std::string
110 senf::ProtocolServerSocketHandle<SocketProtocol>::dumpState(unsigned lod)
111 {
112     SocketStateMap map;
113     state(map,lod);
114     return detail::dumpState(map);
115 }
116
117 template <class SocketProtocol>
118 prefix_ senf::ProtocolServerSocketHandle<SocketProtocol>::
119 ProtocolServerSocketHandle(FileHandle other, bool isChecked)
120     : ServerSocketHandle<typename SocketProtocol::Policy>(other,isChecked)
121 {}
122
123 //-/////////////////////////////////////////////////////////////////////////////////////////////////
124 #undef prefix_
125
126 \f
127 // Local Variables:
128 // mode: c++
129 // fill-column: 100
130 // c-file-style: "senf"
131 // indent-tabs-mode: nil
132 // ispell-local-dictionary: "american"
133 // compile-command: "scons -u test"
134 // comment-column: 40
135 // End: