2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Helge Norberg, helge.norberg@svt.se
27 #include <boost/filesystem.hpp>
28 #include <boost/noncopyable.hpp>
31 #include "future_fwd.h"
32 #include "enum_class.h"
37 * A handle to an active filesystem monitor. Will stop scanning when destroyed.
39 class filesystem_monitor : boost::noncopyable
42 typedef spl::shared_ptr<filesystem_monitor> ptr;
44 virtual ~filesystem_monitor() {}
47 * @return a future made available when the initially available files have been
50 virtual std::future<void> initial_files_processed() = 0;
53 * Reemmit the already known files as MODIFIED events.
55 virtual void reemmit_all() = 0;
58 * Reemmit a specific file as a MODIFIED event.
60 * @param file The file to reemmit.
62 virtual void reemmit(const boost::filesystem::wpath& file) = 0;
66 * The possible filesystem events.
68 enum class filesystem_event
73 // Only used for describing a bitmask where all events are wanted. Never used when calling a handler.
76 ENUM_ENABLE_BITWISE(filesystem_event);
79 * Handles filesystem events.
81 * Will always be called from the same thread each time it is called.
83 * @param event Can be CREATED, REMOVED or MODIFIED.
84 * @param file The file affected.
86 typedef std::function<void (filesystem_event event, const boost::filesystem::wpath& file)> filesystem_monitor_handler;
89 * Called when the initially available files has been found.
91 * Will be called from the same thread as filesystem_monitor_handler is called.
93 * @param initial_files The files that were initially available.
95 typedef std::function<void (const std::set<boost::filesystem::wpath>& initial_files)> initial_files_handler;
98 * Factory for creating filesystem monitors.
100 class filesystem_monitor_factory : boost::noncopyable
103 virtual ~filesystem_monitor_factory() {}
106 * Create a new monitor.
108 * @param folder_to_watch The folder to recursively watch.
109 * @param events_of_interest_mask A bitmask of the events to prenumerate on.
110 * @param report_already_existing Whether to initially report all files in
111 * the folder as CREATED or to only care
113 * @param handler The handler to call each time a change is
114 * detected (only events defined by
115 * events_of_interest_mask).
116 * @param initial_files_handler The optional handler to call when the
117 * initially available files has been
120 * @return The filesystem monitor handle.
122 virtual filesystem_monitor::ptr create(
123 const boost::filesystem::wpath& folder_to_watch,
124 filesystem_event events_of_interest_mask,
125 bool report_already_existing,
126 const filesystem_monitor_handler& handler,
127 const initial_files_handler& initial_files_handler =
128 [] (const std::set<boost::filesystem::wpath>&) { }) = 0;