fswatch 1.20.1
Loading...
Searching...
No Matches
inotify_monitor.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014-2026 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 */
25
26#ifndef FSW_INOTIFY_MONITOR_H
27# define FSW_INOTIFY_MONITOR_H
28
29# include "monitor.hpp"
30# include <sys/inotify.h>
31# include <string>
32# include <vector>
33# include <filesystem>
34# include <functional>
35
36namespace fsw
37{
43
50 class inotify_monitor : public monitor
51 {
52 public:
56 inotify_monitor(std::vector<std::string> paths,
58 void *context = nullptr);
59
63 ~inotify_monitor() override;
64
65 protected:
73 void run() override;
74 void on_stop() override;
75
76 private:
77 inotify_monitor(const inotify_monitor& orig) = delete;
78 inotify_monitor& operator=(const inotify_monitor& that) = delete;
79
80 void scan_root_paths();
81 bool is_watched(const std::string& path) const;
82 void preprocess_dir_event(const struct inotify_event *event);
83 void preprocess_event(const struct inotify_event *event);
84 void preprocess_node_event(const struct inotify_event *event);
85 void scan(const std::filesystem::path& path, const bool accept_non_dirs = true);
86 bool add_watch(const std::string& path);
87 void process_pending_events();
88 void process_synthetic_events();
89 void remove_watch(int fd);
90
91 std::unique_ptr<fsw::inotify_monitor_impl> impl;
92 };
93}
94
95#endif /* FSW_INOTIFY_MONITOR_H */
Type representing a file change event.
Definition event.hpp:65
~inotify_monitor() override
Destroys an instance of this class.
Definition inotify_monitor.cpp:188
inotify_monitor(std::vector< std::string > paths, FSW_EVENT_CALLBACK *callback, void *context=nullptr)
Constructs an instance of this class.
Definition inotify_monitor.cpp:152
void on_stop() override
Execute an implementation-specific stop handler.
Definition inotify_monitor.cpp:524
void run() override
Executes the monitor loop.
Definition inotify_monitor.cpp:542
std::vector< std::string > paths
List of paths to watch.
Definition monitor.hpp:527
void * context
Pointer to context data that will be passed to the monitor::callback.
Definition monitor.hpp:547
FSW_EVENT_CALLBACK * callback
Callback to which change events should be notified.
Definition monitor.hpp:542
monitor(std::vector< std::string > paths, FSW_EVENT_CALLBACK *callback, void *context=nullptr)
Constructs a monitor watching the specified paths.
Definition monitor.cpp:50
Header of the fsw::monitor class.
Main namespace of libfswatch.
Definition event.cpp:24
void FSW_EVENT_CALLBACK(const std::vector< event > &, void *)
Function definition of an event callback.
Definition monitor.hpp:57
Definition inotify_monitor.cpp:49