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 #ifdef _WIN32 28 # include "winwatchtowerdriver.h" 29 #else 30 # include "inotifywatchtowerdriver.h" 31 #endif 32 33 #include "watchtower.h" 34 35 class INotifyWatchTower; 36 37 // An implementation of FileWatcher, as an adapter to INotifyWatchTower. 38 // This is Linux only, and require a recent version of the kernel. 39 40 // Please note that due to the implementation of the constructor 41 // this class is not thread safe and shall always be used from the main UI thread. 42 class PlatformFileWatcher : public FileWatcher { 43 Q_OBJECT 44 45 public: 46 // Create the empty object 47 PlatformFileWatcher(); 48 // Destroy the object 49 ~PlatformFileWatcher(); 50 51 void addFile( const QString& fileName ); 52 void removeFile( const QString& fileName ); 53 54 signals: 55 void fileChanged( const QString& ); 56 57 private: 58 #ifdef _WIN32 59 # if __GNUC_MINOR__ < 7 60 typedef WatchTower<WinWatchTowerDriver> PlatformWatchTower; 61 # else 62 using PlatformWatchTower = WatchTower<WinWatchTowerDriver>; 63 # endif 64 #else 65 # if __GNUC_MINOR__ < 7 66 typedef WatchTower<INotifyWatchTowerDriver> PlatformWatchTower; 67 # else 68 using PlatformWatchTower = WatchTower<INotifyWatchTowerDriver>; 69 # endif 70 #endif 71 72 // The following variables are protected by watched_files_mutex_ 73 QString watched_file_name_; 74 75 // Reference to the (unique) watchtower. 76 static std::shared_ptr<PlatformWatchTower> watch_tower_; 77 78 std::shared_ptr<Registration> notification_; 79 }; 80 81 #endif 82