FdEvent.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 
17 #ifndef HH_SENF_Scheduler_FdEvent_
18 #define HH_SENF_Scheduler_FdEvent_ 1
19 
20 // Custom includes
21 #include <boost/intrusive/set_hook.hpp>
22 #include <senf/Utils/Exception.hh>
23 #include "FdManager.hh"
24 #include "FIFORunner.hh"
25 
26 //#include "FdEvent.mpp"
27 //-/////////////////////////////////////////////////////////////////////////////////////////////////
28 
29 namespace senf {
30 namespace scheduler {
31 
32  namespace detail {
33  struct FdSetTag;
34  typedef boost::intrusive::set_base_hook< boost::intrusive::tag<FdSetTag> > FdSetBase;
35  struct FdSetCompare;
36  class FdDispatcher;
37  class FileDispatcher;
38  }
39 
72  class FdEvent
74  public detail::FdSetBase,
76  {
77  public:
78  //-////////////////////////////////////////////////////////////////////////
79  // Types
80 
81  typedef boost::function<void (int)> Callback;
82 
83  enum Events {
84  EV_NULL = 0
93  };
94 
95  //-////////////////////////////////////////////////////////////////////////
97  //\{
98 
99  template <class Handle>
100  FdEvent(std::string const & name, Callback const & cb, Handle const & handle, int events,
101  bool initiallyEnabled = true);
103 
114  FdEvent(std::string const & name, Callback const & cb);
116 
124  ~FdEvent();
125 
126  //\}
127  //-////////////////////////////////////////////////////////////////////////
128 
129  void disable();
130  void enable();
131 
132  FdEvent & action(Callback const & cb);
133 
134  FdEvent & events(int events);
135  FdEvent & addEvents(int events);
136  FdEvent & removeEvents(int events);
137  int events();
138 
139  template <class Handle>
140  FdEvent & handle(Handle const & handle);
141 
143  { DuplicateEventRegistrationException() : Exception("duplicate fd event registration") {} };
144 
145  protected:
146 
147  private:
148  virtual void signal(int events);
149  virtual void v_run();
150  virtual char const * v_type() const;
151  virtual std::string v_info() const;
152 
153  Callback cb_;
154  int fd_;
155  bool pollable_;
156  int events_;
157  int signaledEvents_;
158 
159  friend struct detail::FdSetCompare;
160  friend class detail::FdDispatcher;
161  friend class detail::FileDispatcher;
162  };
163 
170  template <class Handle>
171  int get_descriptor(Handle const & handle);
172 }}
173 
174 //-/////////////////////////////////////////////////////////////////////////////////////////////////
175 #include "FdEvent.cci"
176 #include "FdEvent.ct"
177 #include "FdEvent.cti"
178 #endif
179 
180 
181 // Local Variables:
182 // mode: c++
183 // fill-column: 100
184 // comment-column: 40
185 // c-file-style: "senf"
186 // indent-tabs-mode: nil
187 // ispell-local-dictionary: "american"
188 // compile-command: "scons -u test"
189 // End:
FIFORunner public header.
int get_descriptor(Handle const &handle)
Get file descriptor from handle object.
boost::function< void(int)> Callback
Definition: FdEvent.hh:81
File descriptor event.
Definition: FdEvent.hh:72
StatsDataCollectorKernel signal
FdManager public header.
boost::intrusive::set_base_hook< boost::intrusive::tag< FdSetTag > > FdSetBase
Definition: FdEvent.hh:33