e9db8daee63acb2c19a0b8e127df306cdfc26bfe
[senf.git] / senf / Socket / ProtocolClientSocketHandle.cti
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.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     \brief ProtocolClientSocketHandle inline template
25         implementation
26  */
27
28 // Definition of inline template functions
29
30 //#include "ProtocolClientSocketHandle.ih"
31
32 // Custom includes
33 #include <senf/Utils/senfassert.hh>
34
35 #define prefix_ inline
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
37
38 template <class SocketProtocol>
39 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>::
40 ProtocolClientSocketHandle(senf::NoInit_t)
41 {}
42
43 template <class SocketProtocol>
44 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>::ProtocolClientSocketHandle()
45     : ClientSocketHandle<typename SocketProtocol::Policy>(
46         std::auto_ptr<senf::SocketBody>(new senf::ProtocolSocketBody<SocketProtocol>(false)))
47 {
48     this->protocol().init_client();
49 }
50
51 #define BOOST_PP_ITERATION_PARAMS_1 \
52     (4, (1, 9, SENF_ABSOLUTE_INCLUDE_PATH(Socket/ProtocolClientSocketHandle.mpp), 2))
53 #include BOOST_PP_ITERATE()
54
55 template <class SocketProtocol>
56 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>::
57 ProtocolClientSocketHandle(FileHandle other, bool isChecked)
58     : ClientSocketHandle<typename Protocol::Policy>(other, isChecked)
59 {}
60
61 template <class SocketProtocol>
62 prefix_ SocketProtocol &
63 senf::ProtocolClientSocketHandle<SocketProtocol>::protocol()
64 {
65     SENF_ASSERT( dynamic_cast<SocketProtocol *>(&this->body().protocol()),
66                  "Internal failure: Incompatible protocol class found it's way into this handle");
67     // Need dynamic_cast here, since senf::SocketProtocol is a
68     // virtual base
69     return dynamic_cast<SocketProtocol &>(this->body().protocol());
70 }
71
72 template <class SocketProtocol>
73 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>
74 senf::ProtocolClientSocketHandle<SocketProtocol>::cast_static(FileHandle handle)
75 {
76     return ProtocolClientSocketHandle(handle,true);
77 }
78
79 template <class SocketProtocol>
80 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>
81 senf::ProtocolClientSocketHandle<SocketProtocol>::cast_dynamic(FileHandle handle)
82 {
83     ClientSocketHandle<typename SocketProtocol::Policy> h(
84         ClientSocketHandle<typename SocketProtocol::Policy>::cast_dynamic(handle));
85     // throw std::bad_cast if the protocol is invalid
86     dynamic_cast<SocketProtocol const &>(static_cast<SocketBody&>(FileHandle::body(h)).protocol());
87     return cast_static(handle);
88 }
89
90 template <class SocketProtocol>
91 prefix_ void
92 senf::ProtocolClientSocketHandle<SocketProtocol>::state(SocketStateMap & map,
93                                                                unsigned lod)
94 {
95     map["handle"] = prettyName(typeid(*this));
96     if (this->valid()) {
97         map["valid"] << "true";
98         this->body().state(map,lod);
99     } else
100         map["valid"] << "false";
101 }
102
103 template <class SocketProtocol>
104 prefix_ std::string
105 senf::ProtocolClientSocketHandle<SocketProtocol>::dumpState(unsigned lod)
106 {
107     SocketStateMap map;
108     state(map,lod);
109     return detail::dumpState(map);
110 }
111
112 //-/////////////////////////////////////////////////////////////////////////////////////////////////
113 #undef prefix_
114
115 \f
116 // Local Variables:
117 // mode: c++
118 // fill-column: 100
119 // c-file-style: "senf"
120 // indent-tabs-mode: nil
121 // ispell-local-dictionary: "american"
122 // compile-command: "scons -u test"
123 // comment-column: 40
124 // End: