switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Socket / ProtocolClientSocketHandle.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 ProtocolClientSocketHandle inline template
30         implementation
31  */
32
33 // Definition of inline template functions
34
35 //#include "ProtocolClientSocketHandle.ih"
36
37 // Custom includes
38 #include <senf/Utils/senfassert.hh>
39
40 #define prefix_ inline
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42
43 template <class SocketProtocol>
44 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>::
45 ProtocolClientSocketHandle(senf::NoInit_t)
46 {}
47
48 template <class SocketProtocol>
49 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>::ProtocolClientSocketHandle()
50     : ClientSocketHandle<typename SocketProtocol::Policy>(
51         std::auto_ptr<senf::SocketBody>(new senf::ProtocolSocketBody<SocketProtocol>(false)))
52 {
53     this->protocol().init_client();
54 }
55
56 #define BOOST_PP_ITERATION_PARAMS_1 \
57     (4, (1, 9, SENF_ABSOLUTE_INCLUDE_PATH(Socket/ProtocolClientSocketHandle.mpp), 2))
58 #include BOOST_PP_ITERATE()
59
60 template <class SocketProtocol>
61 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>::
62 ProtocolClientSocketHandle(FileHandle other, bool isChecked)
63     : ClientSocketHandle<typename Protocol::Policy>(other, isChecked)
64 {}
65
66 template <class SocketProtocol>
67 prefix_ SocketProtocol &
68 senf::ProtocolClientSocketHandle<SocketProtocol>::protocol()
69 {
70     SENF_ASSERT( dynamic_cast<SocketProtocol *>(&this->body().protocol()),
71                  "Internal failure: Incompatible protocol class found it's way into this handle");
72     // Need dynamic_cast here, since senf::SocketProtocol is a
73     // virtual base
74     return dynamic_cast<SocketProtocol &>(this->body().protocol());
75 }
76
77 template <class SocketProtocol>
78 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>
79 senf::ProtocolClientSocketHandle<SocketProtocol>::cast_static(FileHandle handle)
80 {
81     return ProtocolClientSocketHandle(handle,true);
82 }
83
84 template <class SocketProtocol>
85 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>
86 senf::ProtocolClientSocketHandle<SocketProtocol>::cast_dynamic(FileHandle handle)
87 {
88     ClientSocketHandle<typename SocketProtocol::Policy> h(
89         ClientSocketHandle<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::ProtocolClientSocketHandle<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::ProtocolClientSocketHandle<SocketProtocol>::dumpState(unsigned lod)
111 {
112     SocketStateMap map;
113     state(map,lod);
114     return detail::dumpState(map);
115 }
116
117 //-/////////////////////////////////////////////////////////////////////////////////////////////////
118 #undef prefix_
119
120 \f
121 // Local Variables:
122 // mode: c++
123 // fill-column: 100
124 // c-file-style: "senf"
125 // indent-tabs-mode: nil
126 // ispell-local-dictionary: "american"
127 // compile-command: "scons -u test"
128 // comment-column: 40
129 // End: