1 /* 2 * Copyright (C) 2014, 2015 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 28 #ifdef _WIN32 29 # include "winwatchtowerdriver.h" 30 #elif defined(__APPLE__) 31 # include "kqueuewatchtowerdriver.h" 32 #else 33 # include "inotifywatchtowerdriver.h" 34 #endif 35 36 #include "watchtower.h" 37 38 class INotifyWatchTower; 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 // Set the polling interval (0 means disabled) 55 void setPollingInterval( uint32_t interval_ms ); 56 57 signals: 58 void fileChanged( const QString& ); 59 60 private: 61 #ifdef _WIN32 62 # ifdef HAS_TEMPLATE_ALIASES 63 using PlatformWatchTower = WatchTower<WinWatchTowerDriver>; 64 # else 65 typedef WatchTower<WinWatchTowerDriver> PlatformWatchTower; 66 # endif 67 #elif defined(__APPLE__) 68 using PlatformWatchTower = WatchTower<KQueueWatchTowerDriver>; 69 #else 70 # ifdef HAS_TEMPLATE_ALIASES 71 using PlatformWatchTower = WatchTower<INotifyWatchTowerDriver>; 72 # else 73 typedef WatchTower<INotifyWatchTowerDriver> PlatformWatchTower; 74 # endif 75 #endif 76 77 // The following variables are protected by watched_files_mutex_ 78 QString watched_file_name_; 79 80 // Reference to the (unique) watchtower. 81 static std::shared_ptr<PlatformWatchTower> watch_tower_; 82 83 std::shared_ptr<Registration> notification_; 84 }; 85 86 #endif 87