ProtocolClientSocketHandle.cti
Go to the documentation of this file.
1 //
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
6 //
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
11 //
12 
13 
14 /** \file
15  \brief ProtocolClientSocketHandle inline template
16  implementation
17  */
18 
19 // Definition of inline template functions
20 
21 //#include "ProtocolClientSocketHandle.ih"
22 
23 // Custom includes
24 #include <senf/Utils/senfassert.hh>
25 
26 #define prefix_ inline
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
28 
29 template <class SocketProtocol>
30 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>::
31 ProtocolClientSocketHandle(senf::NoInit_t)
32 {}
33 
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)))
38 {
39  this->protocol().init_client();
40 }
41 
42 #define BOOST_PP_ITERATION_PARAMS_1 \
43  (4, (1, 9, SENF_ABSOLUTE_INCLUDE_PATH(Socket/ProtocolClientSocketHandle.mpp), 2))
44 #include BOOST_PP_ITERATE()
45 
46 template <class SocketProtocol>
47 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>::
48 ProtocolClientSocketHandle(FileHandle other, bool isChecked)
49  : ClientSocketHandle<typename Protocol::Policy>(other, isChecked)
50 {}
51 
52 template <class SocketProtocol>
53 prefix_ SocketProtocol &
54 senf::ProtocolClientSocketHandle<SocketProtocol>::protocol()
55 {
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());
60 }
61 
62 template <class SocketProtocol>
63 prefix_ SocketProtocol const &
64 senf::ProtocolClientSocketHandle<SocketProtocol>::protocol()
65  const
66 {
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());
71 }
72 
73 template <class SocketProtocol>
74 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>
75 senf::ProtocolClientSocketHandle<SocketProtocol>::cast_static(FileHandle handle)
76 {
77  return ProtocolClientSocketHandle(handle,true);
78 }
79 
80 template <class SocketProtocol>
81 prefix_ senf::ProtocolClientSocketHandle<SocketProtocol>
82 senf::ProtocolClientSocketHandle<SocketProtocol>::cast_dynamic(FileHandle handle)
83 {
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);
89 }
90 
91 template <class SocketProtocol>
92 prefix_ void
93 senf::ProtocolClientSocketHandle<SocketProtocol>::state(SocketStateMap & map,
94  unsigned lod)
95 {
96  map["handle"] = prettyName(typeid(*this));
97  if (this->valid()) {
98  map["valid"] << "true";
99  this->body().state(map,lod);
100  } else
101  map["valid"] << "false";
102 }
103 
104 template <class SocketProtocol>
105 prefix_ std::string
106 senf::ProtocolClientSocketHandle<SocketProtocol>::dumpState(unsigned lod)
107 {
108  SocketStateMap map;
109  state(map,lod);
110  return detail::dumpState(map);
111 }
112 
113 //-/////////////////////////////////////////////////////////////////////////////////////////////////
114 #undef prefix_
115 
116 
117 // Local Variables:
118 // mode: c++
119 // fill-column: 100
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
125 // End: