FdEvent.ih
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 FdDispatcher internal header */
16 
17 #ifndef IH_SENF_Scheduler_FdEvent_
18 #define IH_SENF_Scheduler_FdEvent_ 1
19 
20 // Custom includes
21 #include <boost/intrusive/set.hpp>
22 
23 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 
25 namespace senf {
26 namespace scheduler {
27 
28  void restart();
29 
30 namespace detail {
31 
32  struct FdSetCompare {
33  bool operator()(FdEvent const & a, FdEvent const & b) const
34  { return a.fd_ < b.fd_; }
35  };
36 
37  class FdDispatcher
38  : public senf::singleton<FdDispatcher>
39  {
40  public:
41  using senf::singleton<FdDispatcher>::instance;
42  using senf::singleton<FdDispatcher>::alive;
43 
44  bool add(FdEvent & event);
45  void remove(FdEvent & event);
46 
47  bool empty() const;
48 
49  protected:
50 
51  private:
52  FdDispatcher();
53  ~FdDispatcher();
54 
55  typedef boost::intrusive::multiset< FdEvent,
56  boost::intrusive::constant_time_size<false>,
57  boost::intrusive::compare<FdSetCompare>,
58  boost::intrusive::base_hook<FdSetBase> > FdSet;
59 
60  FdSet fds_;
61 
62  friend void senf::scheduler::restart();
63  friend class singleton<FdDispatcher>;
64  friend class senf::scheduler::FdEvent;
65  };
66 
67  class FileDispatcher
68  : public senf::singleton<FileDispatcher>
69  {
70  public:
71  using senf::singleton<FileDispatcher>::instance;
72  using senf::singleton<FileDispatcher>::alive;
73 
74  void add(FdEvent & event);
75  void remove(FdEvent & event);
76 
77  void prepareRun();
78 
79  // Called by IdleEventDispatcher
80  void timeout(int t);
81  int timeout() const;
82 
83  bool empty() const;
84 
85  protected:
86 
87  private:
88  FileDispatcher();
89  ~FileDispatcher();
90 
91  // We really only need a list here but we need to use the same event structure used by
92  // the FdEvent.
93  typedef boost::intrusive::multiset< FdEvent,
94  boost::intrusive::constant_time_size<false>,
95  boost::intrusive::compare<FdSetCompare>,
96  boost::intrusive::base_hook<FdSetBase> > FdSet;
97 
98  FdSet fds_;
99  int managerTimeout_;
100 
101  friend void senf::scheduler::restart();
102  friend class singleton<FileDispatcher>;
103  };
104 
105  template <class Handle>
106  int get_descriptor(Handle const & handle);
107 
108  int retrieve_filehandle(int fd);
109 
110 }}}
111 
112 //-/////////////////////////////////////////////////////////////////////////////////////////////////
113 #endif
114 
115 
116 // Local Variables:
117 // mode: c++
118 // fill-column: 100
119 // comment-column: 40
120 // c-file-style: "senf"
121 // indent-tabs-mode: nil
122 // ispell-local-dictionary: "american"
123 // compile-command: "scons -u test"
124 // End: