2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
15 \brief ProtocolClientSocketHandle inline template
19 // Definition of inline template functions
21 //#include "ProtocolClientSocketHandle.ih"
24 #include <senf/Utils/senfassert.hh>
26 #define prefix_ inline
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
29 template <class SocketProtocol>
30 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>::
31 ProtocolClientSocketHandle(senf::NoInit_t)
34 template <class SocketProtocol>
35 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>::ProtocolClientSocketHandle()
36 : ClientSocketHandle<typename SocketProtocol::Policy>(
37 std::unique_ptr<senf::SocketBody>(new senf::ProtocolSocketBody<SocketProtocol>(false)))
39 this->protocol().init_client();
42 #define BOOST_PP_ITERATION_PARAMS_1 \
43 (4, (1, 9, SENF_ABSOLUTE_INCLUDE_PATH(Socket/ProtocolClientSocketHandle.mpp), 2))
44 #include BOOST_PP_ITERATE()
46 template <class SocketProtocol>
47 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>::
48 ProtocolClientSocketHandle(FileHandle other, bool isChecked)
49 : ClientSocketHandle<typename Protocol::Policy>(other, isChecked)
52 template <class SocketProtocol>
53 prefix_ SocketProtocol &
54 senf::ProtocolClientSocketHandle<SocketProtocol>::protocol()
56 SENF_ASSERT( dynamic_cast<SocketProtocol *>(&this->body().protocol()),
57 "Internal failure: Incompatible protocol class found it's way into this handle");
58 // Need dynamic_cast here, since senf::SocketProtocol is a virtual base
59 return dynamic_cast<SocketProtocol &>(this->body().protocol());
62 template <class SocketProtocol>
63 prefix_ SocketProtocol const &
64 senf::ProtocolClientSocketHandle<SocketProtocol>::protocol()
67 SENF_ASSERT( dynamic_cast<SocketProtocol const *>(&this->body().protocol()),
68 "Internal failure: Incompatible protocol class found it's way into this handle");
69 // Need dynamic_cast here, since senf::SocketProtocol is a virtual base
70 return dynamic_cast<SocketProtocol const &>(this->body().protocol());
73 template <class SocketProtocol>
74 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>
75 senf::ProtocolClientSocketHandle<SocketProtocol>::cast_static(FileHandle handle)
77 return ProtocolClientSocketHandle(handle,true);
80 template <class SocketProtocol>
81 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>
82 senf::ProtocolClientSocketHandle<SocketProtocol>::cast_dynamic(FileHandle handle)
84 ClientSocketHandle<typename SocketProtocol::Policy> h (
85 ClientSocketHandle<typename SocketProtocol::Policy>::cast_dynamic(handle));
86 // throw std::bad_cast if the protocol is invalid
87 IGNORE( dynamic_cast<SocketProtocol const &>(static_cast<SocketBody&>(FileHandle::body(h)).protocol()) );
88 return cast_static(handle);
91 template <class SocketProtocol>
93 senf::ProtocolClientSocketHandle<SocketProtocol>::state(SocketStateMap & map,
96 map["handle"] = prettyName(typeid(*this));
98 map["valid"] << "true";
99 this->body().state(map,lod);
101 map["valid"] << "false";
104 template <class SocketProtocol>
106 senf::ProtocolClientSocketHandle<SocketProtocol>::dumpState(unsigned lod)
110 return detail::dumpState(map);
113 //-/////////////////////////////////////////////////////////////////////////////////////////////////
120 // c-file-style: "senf"
121 // indent-tabs-mode: nil
122 // ispell-local-dictionary: "american"
123 // compile-command: "scons -u test"
124 // comment-column: 40