SocketHandle.hh
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 
18 #ifndef HH_SENF_Socket_SocketHandle_
19 #define HH_SENF_Socket_SocketHandle_ 1
20 
21 //#include "SocketHandle.mpp"
22 #include "SocketHandle.ih"
23 
24 // Custom includes
25 #include <senf/Utils/Cpp11Support/smart_ptr.hh>
26 #include "FileHandle.hh"
27 #include "SocketPolicy.hh"
28 
29 //-/////////////////////////////////////////////////////////////////////////////////////////////////
30 
31 namespace senf {
32 
34  //\{
35 
59  template <class SPolicy>
61  : public FileHandle
62  {
63  public:
64  //-////////////////////////////////////////////////////////////////////////
65  // Types
66 
67  typedef SPolicy Policy;
68 
75  template <class OtherPolicy>
76  struct IsCompatible
77  : public boost::enable_if< SocketPolicyIsBaseOf<Policy,OtherPolicy>, SocketHandle >
78  {};
79 
80  //-////////////////////////////////////////////////////////////////////////
82  //\{
83 
84  // default default constructor
85  // default copy constructor
86  // default copy assignment
87  // default destructor
88 
89  // here to implement
90  SocketHandle();
91 
92  // conversion constructors
93 
94  template <class OtherPolicy>
96  typename IsCompatible<OtherPolicy>::type * = 0);
99 
100  //\}
101  //-////////////////////////////////////////////////////////////////////////
102 
103  template <class OtherPolicy>
107 
108  void state(SocketStateMap & map, unsigned lod=0);
110 
129  std::string dumpState(unsigned lod=0);
131 
141  template <class Facet>
142  Facet & facet();
143 
151  protected:
152  explicit SocketHandle(std::unique_ptr<SocketBody> body);
154 
158  SocketHandle(FileHandle other, bool isChecked);
161 
176  SocketBody & body();
177 
180  SocketBody const & body() const;
181 
184  SocketProtocol & protocol() const;
186 
187  void assign(FileHandle other);
189  public:
190  static SocketHandle cast_static(FileHandle handle);
192  static SocketHandle cast_dynamic(FileHandle handle);
195  private:
196 
197  };
198 
205  template <class SPolicy>
206  std::ostream & operator<<(std::ostream & os, SocketHandle<SPolicy> handle);
207 
225  template <class Target, class Source>
226  Target static_socket_cast(Source handle);
227 
237  template <class Target, class Source>
238  Target dynamic_socket_cast(Source handle);
239 
250  template <class Target, class Source>
251  bool check_socket_cast(Source handle);
252 
253  //\}
254 }
255 
256 //-/////////////////////////////////////////////////////////////////////////////////////////////////
257 #include "SocketHandle.cci"
258 #include "SocketHandle.ct"
259 #include "SocketHandle.cti"
260 #endif
261 
262 
263 // Local Variables:
264 // mode: c++
265 // fill-column: 100
266 // c-file-style: "senf"
267 // indent-tabs-mode: nil
268 // ispell-local-dictionary: "american"
269 // compile-command: "scons -u test"
270 // comment-column: 40
271 // End:
Facet & facet()
Access a protocol facet.
static SocketHandle cast_static(FileHandle handle)
bool check_socket_cast(Source handle)
dynamically check cast validity
Policy Framework public header.
Socket Protocol base class.
Basic file handle wrapper.
Definition: FileHandle.hh:102
IsCompatible< OtherPolicy >::type const & operator=(SocketHandle< OtherPolicy > other)
Assign from other socket handle checking policy compatibility.
std::string dumpState(unsigned lod=0)
Format complete state information as string.
basic SocketHandle supporting protocol and policy abstraction
Definition: SocketHandle.hh:60
SocketBody & body()
Access socket body.
Target dynamic_socket_cast(Source handle)
dynamic socket (down-)cast
SocketProtocol & protocol() const
Access protocol class.
FileHandle public header.
Check policy compatibility.
Definition: SocketHandle.hh:76
void assign(FileHandle other)
Target static_socket_cast(Source handle)
static socket (down-)cast
static SocketHandle cast_dynamic(FileHandle handle)
void state(SocketStateMap &map, unsigned lod=0)
Inquire state information of socket handle.