libfswatch  1.9.3
kqueue_monitor.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2016 Enrico M. Crisostomo
3  *
4  * This program is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU General Public License as published by the Free Software
6  * Foundation; either version 3, or (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11  * details.
12  *
13  * You should have received a copy of the GNU General Public License along with
14  * this program. If not, see <http://www.gnu.org/licenses/>.
15  */
26 #ifndef FSW_KQUEUE_MONITOR_H
27 # define FSW_KQUEUE_MONITOR_H
28 
29 # include "monitor.hpp"
30 # include <string>
31 # include <vector>
32 # include <sys/stat.h>
33 # include <sys/event.h>
34 
35 namespace fsw
36 {
41  struct kqueue_monitor_load;
42 
48  class kqueue_monitor : public monitor
49  {
50  REGISTER_MONITOR(kqueue_monitor, kqueue_monitor_type);
51 
52  public:
56  kqueue_monitor(std::vector<std::string> paths,
58  void *context = nullptr);
59 
63  virtual ~kqueue_monitor();
64 
65  protected:
73  void run();
74 
75  private:
76  kqueue_monitor(const kqueue_monitor& orig) = delete;
77  kqueue_monitor& operator=(const kqueue_monitor& that) = delete;
78 
79  void initialize_kqueue();
80  void terminate_kqueue();
81  bool scan(const std::string& path, bool is_root_path = true);
82  bool add_watch(const std::string& path, const struct stat& fd_stat);
83  bool is_path_watched(const std::string& path) const;
84  void remove_deleted();
85  void rescan_pending();
86  void scan_root_paths();
87  int wait_for_events(const std::vector<struct kevent>& changes,
88  std::vector<struct kevent>& event_list);
89  void process_events(const std::vector<struct kevent>& changes,
90  const std::vector<struct kevent>& event_list,
91  int event_num);
92 
93  int kq = -1;
94  // initial load
95  kqueue_monitor_load *load;
96  };
97 }
98 
99 #endif /* FSW_KQUEUE_MONITOR_H */
void * context
Pointer to context data that will be passed to the monitor::callback.
Definition: monitor.hpp:553
Base class of all monitors.
Definition: monitor.hpp:146
Main namespace of libfswatch.
Definition: event.cpp:23
Header of the fsw::monitor class.
virtual ~kqueue_monitor()
Destroys an instance of this class.
void run()
Executes the monitor loop.
Definition: cmonitor.h:47
kqueue_monitor(std::vector< std::string > paths, FSW_EVENT_CALLBACK *callback, void *context=nullptr)
Constructs an instance of this class.
Solaris/Illumos monitor.
Definition: kqueue_monitor.hpp:48
std::vector< std::string > paths
List of paths to watch.
Definition: monitor.hpp:533
FSW_EVENT_CALLBACK * callback
Callback to which change events should be notified.
Definition: monitor.hpp:548
void FSW_EVENT_CALLBACK(const std::vector< event > &, void *)
Function definition of an event callback.
Definition: monitor.hpp:60