184b2179eSNicolas Bonnefon /* 280bca0a3SNicolas Bonnefon * Copyright (C) 2014, 2015 Nicolas Bonnefon and other contributors 384b2179eSNicolas Bonnefon * 484b2179eSNicolas Bonnefon * This file is part of glogg. 584b2179eSNicolas Bonnefon * 684b2179eSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify 784b2179eSNicolas Bonnefon * it under the terms of the GNU General Public License as published by 884b2179eSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or 984b2179eSNicolas Bonnefon * (at your option) any later version. 1084b2179eSNicolas Bonnefon * 1184b2179eSNicolas Bonnefon * glogg is distributed in the hope that it will be useful, 1284b2179eSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of 1384b2179eSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1484b2179eSNicolas Bonnefon * GNU General Public License for more details. 1584b2179eSNicolas Bonnefon * 1684b2179eSNicolas Bonnefon * You should have received a copy of the GNU General Public License 1784b2179eSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>. 1884b2179eSNicolas Bonnefon */ 1984b2179eSNicolas Bonnefon 2084b2179eSNicolas Bonnefon #ifndef PLATFORMFILEWATCHER_H 2184b2179eSNicolas Bonnefon #define PLATFORMFILEWATCHER_H 2284b2179eSNicolas Bonnefon 2384b2179eSNicolas Bonnefon #include "filewatcher.h" 2484b2179eSNicolas Bonnefon 2584b2179eSNicolas Bonnefon #include <memory> 2684b2179eSNicolas Bonnefon 27*f869e41dSNicolas Bonnefon 28f09fa651SNicolas Bonnefon #ifdef _WIN32 29f09fa651SNicolas Bonnefon # include "winwatchtowerdriver.h" 30*f869e41dSNicolas Bonnefon #elif defined(__APPLE__) 31*f869e41dSNicolas Bonnefon # include "kqueuewatchtowerdriver.h" 32f09fa651SNicolas Bonnefon #else 33f09fa651SNicolas Bonnefon # include "inotifywatchtowerdriver.h" 34f09fa651SNicolas Bonnefon #endif 35f09fa651SNicolas Bonnefon 3684b2179eSNicolas Bonnefon #include "watchtower.h" 3784b2179eSNicolas Bonnefon 3896bde7d5SNicolas Bonnefon class INotifyWatchTower; 3996bde7d5SNicolas Bonnefon 4084b2179eSNicolas Bonnefon // Please note that due to the implementation of the constructor 4184b2179eSNicolas Bonnefon // this class is not thread safe and shall always be used from the main UI thread. 4284b2179eSNicolas Bonnefon class PlatformFileWatcher : public FileWatcher { 4384b2179eSNicolas Bonnefon Q_OBJECT 4484b2179eSNicolas Bonnefon 4584b2179eSNicolas Bonnefon public: 4684b2179eSNicolas Bonnefon // Create the empty object 4784b2179eSNicolas Bonnefon PlatformFileWatcher(); 4884b2179eSNicolas Bonnefon // Destroy the object 49dc7f5916SNicolas Bonnefon ~PlatformFileWatcher(); 5084b2179eSNicolas Bonnefon 51dc7f5916SNicolas Bonnefon void addFile( const QString& fileName ); 52dc7f5916SNicolas Bonnefon void removeFile( const QString& fileName ); 5384b2179eSNicolas Bonnefon 5480bca0a3SNicolas Bonnefon // Set the polling interval (0 means disabled) 5580bca0a3SNicolas Bonnefon void setPollingInterval( uint32_t interval_ms ); 5680bca0a3SNicolas Bonnefon 5784b2179eSNicolas Bonnefon signals: 5884b2179eSNicolas Bonnefon void fileChanged( const QString& ); 5984b2179eSNicolas Bonnefon 6084b2179eSNicolas Bonnefon private: 61f09fa651SNicolas Bonnefon #ifdef _WIN32 6258f443c7SNicolas Bonnefon # ifdef HAS_TEMPLATE_ALIASES 63f09fa651SNicolas Bonnefon using PlatformWatchTower = WatchTower<WinWatchTowerDriver>; 6458f443c7SNicolas Bonnefon # else 6558f443c7SNicolas Bonnefon typedef WatchTower<WinWatchTowerDriver> PlatformWatchTower; 66f09fa651SNicolas Bonnefon # endif 67*f869e41dSNicolas Bonnefon #elif defined(__APPLE__) 68*f869e41dSNicolas Bonnefon using PlatformWatchTower = WatchTower<KQueueWatchTowerDriver>; 69f09fa651SNicolas Bonnefon #else 7058f443c7SNicolas Bonnefon # ifdef HAS_TEMPLATE_ALIASES 7196bde7d5SNicolas Bonnefon using PlatformWatchTower = WatchTower<INotifyWatchTowerDriver>; 7258f443c7SNicolas Bonnefon # else 7358f443c7SNicolas Bonnefon typedef WatchTower<INotifyWatchTowerDriver> PlatformWatchTower; 74dc7f5916SNicolas Bonnefon # endif 75f09fa651SNicolas Bonnefon #endif 7696bde7d5SNicolas Bonnefon 7784b2179eSNicolas Bonnefon // The following variables are protected by watched_files_mutex_ 7884b2179eSNicolas Bonnefon QString watched_file_name_; 7984b2179eSNicolas Bonnefon 8084b2179eSNicolas Bonnefon // Reference to the (unique) watchtower. 8196bde7d5SNicolas Bonnefon static std::shared_ptr<PlatformWatchTower> watch_tower_; 8284b2179eSNicolas Bonnefon 8396bde7d5SNicolas Bonnefon std::shared_ptr<Registration> notification_; 8484b2179eSNicolas Bonnefon }; 8584b2179eSNicolas Bonnefon 8684b2179eSNicolas Bonnefon #endif 87