xref: /glogg/src/platformfilewatcher.h (revision 84b2179eb3774e43dfb52da96116070d4545d8c7)
1 /*
2  * Copyright (C) 2014 Nicolas Bonnefon and other contributors
3  *
4  * This file is part of glogg.
5  *
6  * glogg 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.
10  *
11  * glogg 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.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with glogg.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef PLATFORMFILEWATCHER_H
21 #define PLATFORMFILEWATCHER_H
22 
23 #include "filewatcher.h"
24 
25 #include <memory>
26 
27 #include "watchtower.h"
28 
29 // An implementation of FileWatcher, as an adapter to INotifyWatchTower.
30 // This is Linux only, and require a recent version of the kernel.
31 
32 // Please note that due to the implementation of the constructor
33 // this class is not thread safe and shall always be used from the main UI thread.
34 class PlatformFileWatcher : public FileWatcher {
35   Q_OBJECT
36 
37   public:
38     // Create the empty object
39     PlatformFileWatcher();
40     // Destroy the object
41     ~PlatformFileWatcher() override;
42 
43     void addFile( const QString& fileName ) override;
44     void removeFile( const QString& fileName ) override;
45 
46   signals:
47     void fileChanged( const QString& );
48 
49   private:
50     // The following variables are protected by watched_files_mutex_
51     QString watched_file_name_;
52 
53     // Reference to the (unique) watchtower.
54     static std::shared_ptr<WatchTower> watch_tower_;
55 
56     std::shared_ptr<WatchTower::Registration> notification_;
57 };
58 
59 #endif
60