2fbc07720e0afbd2acf3ec04c7ce57b18fc83bff
[senf.git] / Socket / ProtocolClientSocketHandle.cti
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     \brief ProtocolClientSocketHandle inline template
25         implementation 
26  */
27
28 // Definition of inline template functions
29
30 //#include "ProtocolClientSocketHandle.ih"
31
32 // Custom includes
33
34 #define prefix_ inline
35 ///////////////////////////////cti.p///////////////////////////////////////
36
37 template <class SocketProtocol>
38 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>::ProtocolClientSocketHandle()
39     : ClientSocketHandle<typename SocketProtocol::Policy>(
40         std::auto_ptr<senf::SocketProtocol>(new SocketProtocol()))
41 {
42     this->protocol().init_client();
43 }
44
45 #define BOOST_PP_ITERATION_PARAMS_1 (4, (1, 9, "Socket/ProtocolClientSocketHandle.mpp", 2))
46 #include BOOST_PP_ITERATE()
47
48 template <class SocketProtocol>
49 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>::
50 ProtocolClientSocketHandle(FileHandle other, bool isChecked)
51     : ClientSocketHandle<typename Protocol::Policy>(other, isChecked)
52 {}
53
54 template <class SocketProtocol>
55 prefix_ SocketProtocol const &
56 senf::ProtocolClientSocketHandle<SocketProtocol>::protocol()
57 {
58     BOOST_ASSERT( dynamic_cast<SocketProtocol const *>(&this->body().protocol()) );
59     // Need dynamic_cast here, since senf::SocketProtocol is a
60     // virtual base
61     return dynamic_cast<SocketProtocol const &>(this->body().protocol());
62 }
63
64 template <class SocketProtocol>
65 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>
66 senf::ProtocolClientSocketHandle<SocketProtocol>::cast_static(FileHandle handle)
67 {
68     return ProtocolClientSocketHandle(handle,true);
69 }
70
71 template <class SocketProtocol>
72 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>
73 senf::ProtocolClientSocketHandle<SocketProtocol>::cast_dynamic(FileHandle handle)
74 {
75     ClientSocketHandle<typename SocketProtocol::Policy> h(
76         ClientSocketHandle<typename SocketProtocol::Policy>::cast_dynamic(handle));
77     // throw std::bad_cast if the protocol is invalid
78     dynamic_cast<SocketProtocol const &>(static_cast<SocketBody&>(FileHandle::body(h)).protocol());
79     return cast_static(handle);
80 }
81
82 template <class SocketProtocol>
83 prefix_ void
84 senf::ProtocolClientSocketHandle<SocketProtocol>::state(SocketStateMap & map,
85                                                                unsigned lod)
86 {
87     map["handle"] = prettyName(typeid(*this));
88     this->body().state(map,lod);
89 }
90
91 template <class SocketProtocol>
92 prefix_ std::string
93 senf::ProtocolClientSocketHandle<SocketProtocol>::dumpState(unsigned lod)
94 {
95     SocketStateMap map;
96     state(map,lod);
97     return detail::dumpState(map);
98 }
99
100 ///////////////////////////////cti.e///////////////////////////////////////
101 #undef prefix_
102
103 \f
104 // Local Variables:
105 // mode: c++
106 // c-file-style: "senf"
107 // End: