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