xref: /glogg/src/watchtower.h (revision 87e056522fcbb3c5f21f5154425e1df944f6954c) !
1*87e05652SNicolas Bonnefon #include <memory>
2*87e05652SNicolas Bonnefon #include <functional>
3*87e05652SNicolas Bonnefon #include <string>
4*87e05652SNicolas Bonnefon 
5*87e05652SNicolas Bonnefon class WatchTower {
6*87e05652SNicolas Bonnefon   public:
7*87e05652SNicolas Bonnefon     // Registration object to implement RAII
8*87e05652SNicolas Bonnefon     using Registration = std::shared_ptr<void>;
9*87e05652SNicolas Bonnefon 
10*87e05652SNicolas Bonnefon     // Create an empty watchtower
11*87e05652SNicolas Bonnefon     WatchTower() {};
12*87e05652SNicolas Bonnefon     // Destroy the object
13*87e05652SNicolas Bonnefon     virtual ~WatchTower() {};
14*87e05652SNicolas Bonnefon 
15*87e05652SNicolas Bonnefon     // Add a file to the notification list. notification will be called when
16*87e05652SNicolas Bonnefon     // the file is modified, moved or deleted.
17*87e05652SNicolas Bonnefon     // Lifetime of the notification is tied to the Registration object returned.
18*87e05652SNicolas Bonnefon     // Note the notification function is called with a mutex held and in a
19*87e05652SNicolas Bonnefon     // third party thread, beware of races!
20*87e05652SNicolas Bonnefon     virtual Registration addFile( const std::string& file_name,
21*87e05652SNicolas Bonnefon             std::function<void()> notification ) = 0;
22*87e05652SNicolas Bonnefon };
23